Page 2 of 5 FirstFirst 1234 ... LastLast
Results 11 to 20 of 42

Thread: Making a platform game - few questions

  1. #11

    Making a platform game - few questions

    Jeremy, is your file correct? I've tried it but all I see is a black environment with a few tiles, nothing more...

  2. #12

    Making a platform game - few questions

    There seems to be a problem with my OpenGL libraries I compiled with. If you ran from the batch file thats about all you see . I've updated the zip and removed the batch file. Try just running ss.exe and see what happens.

    You might also try building in Lazarus with your OpenGL libraries and see if that makes things work better. Guess one of these days I will have to find the updated OpenGL libraries for FPC LOL

  3. #13

    Making a platform game - few questions

    Okay, this is just part of the code which involves jumping. It's not finished yet (as there's no floor detection yet, because I'm still working on a map system ).

    [pascal]
    acceleration:= 6;

    if pressed_space (*this is pseudo code, as you all know what happens here *) then begin
    if jump = false then begin
    velocity:= 50;
    jump:= true;
    end;
    end;

    (*this is not pseudo any more *)
    if jump = true then begin
    player.y:= player.y - velocity;
    velocity:= velocity - acceleration;

    if player_y_beforejump - player.y < 0 then begin
    player.y := player_y_beforejump;
    jump := false;
    end;[/pascal]

    And then it blits the player sprite with the destination rectangle of "player".

    The thing is that the player jumps and falls too fast. I tried speeding up the movement and then delaying the whole thing, but it doesn't look smooth.

    Also, as I said, I'm working on a map system.
    I'm thinking of doing the same thing as jdarling - tiles through text files.
    But I need a little help with this too.
    I tried examining your side scroller code, but I really can't figure half of it out. I have a hard time understanding other peoples' codes.
    So, I'll try this - reading characters from a text file. If it reads out ' ' then dstrect.x increases by the width of a tile. If it reads out eoln, then dstrect.x becomes 0, and dstrect.y increases by the height of a tile.
    When it reads out '1', or '2' or something like that, it blits a tile (which kind - depending on which number it reads out) to dstrect onto the screen surface.

    Haven't tried it yet (haven't had time), but theoretically, I see only one problem - how to scroll those tiles?
    Or am I completely wrong here?

  4. #14

    Making a platform game - few questions

    For tiles, you can have them fixed size and forget special ruling if want to keep it simple. Found this with google:
    http://www.savware.net/images/RPG_Tiles_01.png
    Combining base blocks you can create any forms of structures. If you want to make a building that is size 2x3 tiles, have those 6 tiles be in texture but make editor put all 6 as a group same time.

    Physics loop might look something like this (assuming floor is at 0 and sky is in positive side of numbers):
    [pascal]uses math... // maybe need for Min() Max() unless make them yourself

    with player do begin
    oldX:=x; // These may be useful in collision though
    oldY:=y; // they are not needed in this example yet
    speedX:=speedX*0.95; // closer to 1 movement decelerates slower
    speedY:=speedY-gravity;
    if pressLeft then speedX:=max(-2,speedX-0.5);
    if pressRight then speedX:=min(2,speedX+0.5);
    if pressJump and TouchGround then begin // EDIT: oops forgot the key
    TouchGround:=false;
    speedY:=2; // Whatever jumpspeed is
    end;
    x:=x+speedX;
    y:=y+speedY;

    TouchGround:=false;
    if y<FloorLevel then begin
    Touchground:=true;
    y:=FloorLevel;
    speedY:=0;
    end;
    end;[/pascal]

  5. #15

    Making a platform game - few questions

    If you don't mind.
    Download the rar file from the last post.
    http://www.pascalgamedevelopment.com...pic.php?t=5547

    That engine contains large numbers of example.Include map,scrolling,sprites,jump,collision....etc.

  6. #16
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    Making a platform game - few questions

    If you would like, I could email you my cyber-crisis source. I used JEDI-SDL for my controls and other things and OpenGL for my graphics routines. I had all the code in to allow the player to run, jump and fall with varying gravity levels. I also added in platforms which you could jump down off of and ladders. I have no major plans for it now, but it could be of use to you if you want to check it out?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  7. #17

    Making a platform game - few questions

    Quote Originally Posted by jdarling
    There seems to be a problem with my OpenGL libraries I compiled with. If you ran from the batch file thats about all you see . I've updated the zip and removed the batch file. Try just running ss.exe and see what happens.

    You might also try building in Lazarus with your OpenGL libraries and see if that makes things work better. Guess one of these days I will have to find the updated OpenGL libraries for FPC LOL
    Hi Jeremy :-)
    I downloaded your updated side scroller example with APE and it works nicely :-)
    I opened it up in Lazarus, built all, and ran it...and voila!

    I know it is only an example, but I noticed that the character 'bounces' a bit vertically and can only jump when he has settled vertically.

    cheers,
    Paul
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

  8. #18

    Making a platform game - few questions

    The bounce comes straight from the physics engine itself. I started cleaning this up in the latest version (not posted yet), but the truth is that its difficult to figure out when a character has quit jumping when your using a 3rd party physics engine . Now I'm basically checking for 3 frames to see if your Y vector has changed, if it hasn't then you can jump again.

    You could lower the bounce by raising the rigidity of the map and player objects.

  9. #19

    Making a platform game - few questions

    I think that my only problem now is collision detection. How to detect floor while jumping etc...
    To help you out with giving advice, my map system is like this:
    I'm using tiles. There is a BMP file with all the tiles' textures in it, and I have a variable "tile" that's array of TSDL_Rect (one "tile" = one tile).
    When reading out the map from a text file, I do it like this - if it finds ' ', then it just increases the x coordinate of destination rect (and there is an array of destination rect, one for each tile). If it finds '1', then it blits that tile to the map surface at destination rect and so on.

    So how do I detect the floor? I think that checking every frame if player y coordinate is the same as tiles' (and if it is, then if x coordinates fit) is a really bad idea.

  10. #20

    Making a platform game - few questions

    Quote Originally Posted by Ixy
    I think that my only problem now is collision detection. How to detect floor while jumping etc...
    To help you out with giving advice, my map system is like this:
    I'm using tiles. There is a BMP file with all the tiles' textures in it, and I have a variable "tile" that's array of TSDL_Rect (one "tile" = one tile).
    When reading out the map from a text file, I do it like this - if it finds ' ', then it just increases the x coordinate of destination rect (and there is an array of destination rect, one for each tile). If it finds '1', then it blits that tile to the map surface at destination rect and so on.

    So how do I detect the floor? I think that checking every frame if player y coordinate is the same as tiles' (and if it is, then if x coordinates fit) is a really bad idea.
    I do it this way.

    My tiles are in a 2d array, and the top left corner of the map is (0,0)

    What I do is each update I check the character's position and velocity.

    Below is some code I typed in off the top of my head. Untested but you should get the idea :-)

    It doesn't add acceleration due to gravity to the vertical velocity (vy) and doesn't include the x direction checks but you should be able to work it out.

    [pascal]Const
    {................................................. .............................}
    cMapWidth = 50;
    cMapHeight = 25;
    cTileWidth = 32;
    cTileHeight = 32;
    {................................................. .............................}

    Type
    {................................................. .............................}
    TTile = Record
    id : Integer;
    IsSolid : Boolean;
    End;
    {................................................. .............................}

    {................................................. .............................}
    TPlayer = Class
    x : Single;
    y : Single;
    vx : Single;
    vy : Single;
    w : Integer;
    h : Integer;
    Procedure Update(Const ATimeSlice : Single);
    End;
    {................................................. .............................}

    Var
    Tiles : Array[0..cMapHeight - 1,0..cMapWidth - 1] Of TTile;
    {................................................. .............................}

    {................................................. .............................}
    Function SolidTileAt(Const x,y : Single) : Boolean;
    Var
    tx : Integer;
    ty : Integer;
    Begin
    Result := True;
    tx := Floor(x / cTileWidth);
    ty := Floor(y / cTileHeight);
    If tx LESS_THAN 0 Then Exit;
    If ty LESS_THAN 0 Then Exit;
    If tx >= cMapWidth Then Exit;
    If ty >= cMapHeight Then Exit;
    Result := Tiles[ty,tx].IsSolid;
    End;
    {................................................. .............................}

    {................................................. .............................}
    Procedure TPlayer.Update(Const ATimeSlice : Single);
    Var
    SolidUL : Boolean; // upper left player corner tile is solid (wall)
    SolidUR : Boolean; // upper right player corner tile is solid (wall)
    SolidDL : Boolean; // lower left player corner tile is solid (wall)
    SolidDR : Boolean; // lower right player corner tile is solid (wall)
    ty : Integer; // tile y coordinate in tile array
    ny : Single; // new y pos including current vertical velocity, vy
    Begin
    If vy LESS_THAN 0 Then
    //moving up
    Begin
    ny := y + vy * ATimeSlice;
    SolidUL := SolidTileAt(x - w/2,ny);
    SolidUR := SolidTileAt(x + w/2,ny);
    If SolidUL Or SolidUR Then
    // set y to bottom of tile
    Begin
    ty := Floor(ny);
    y := ty * cTileHeight + cTileHeight;
    End
    Else
    y := y + vy;
    End
    Else
    If vy > 0 Then
    //moving down
    Begin
    ny := y + vy * ATimeSlice;
    SolidDL := SolidTileAt(x - w/2,ny);
    SolidDR := SolidTileAt(x + w/2,ny);
    If SolidDL Or SolidDR Then
    // set y to top of tile + player height
    Begin
    ty := Floor(ny);
    y := ty * cTileHeight + h / 2;
    End
    Else
    y := y + vy;
    End;
    // add gravity to vy here and cap to max velocity so not faster than tile height;
    End;
    {................................................. .............................}

    {................................................. .............................}
    [/pascal]

    cheers,
    Paul
    Games:
    Seafox


    Pages:
    Syntax Error Software itch.io page

    Online Chess
    http://gameknot.com/#paul_nicholls

Page 2 of 5 FirstFirst 1234 ... LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •