You need to look at "game states" and some conditions to switch between states.
The code below demonstrates the key concepts:
- game state
- condition to return to "idle" state
-- is player "flying" on_air=false -- height y=0 -- jump force dy=0 function _update() -- not yet jumping? if on_air==falseand btn(4) then -- jumping on_air=true -- jump "force" dy=8 end -- gravity y+=-1.2 -- jump force (if any) y+=dy -- gravity drag dy*=0.8 -- on ground? if y<0 then y=0 -- reset state dy=0 on_air=false end end function _draw() cls() -- jumping "hi"! print("hi",64,122-y,7) -- ground line(0,127,127,127,3) end |
Look at the Jelpi sample for a more complete example.
P#71912 2020-01-13 20:38
[Please log in to post a comment]