This is how i've done it
Code:
var VertSpeed: Single;
Procedure GameLoop;
begin
VertSpeed:=VertSpeed - 1;
IF (VK_UP in keys) and (Player.StandsOnGround) then VertSpeed:=20;
Player.Position.Y:=Player.Position.Y + VertSpeed;
IF Player.ColisionWithLevel then begin
VertSpeed:=0;
Player.PutOnGround;
end;
end;
Some explanation about the functions:
Player.ColisionWithLevel <- Tests if the player is coliding with the level at its current position.
Player.StandsOnGround <- Tests if the player is standing on a tile instead of free-falling.
Player.PutOnGround <- Puts the player on the top of the tile it colides with
Bookmarks