Log In  

Im creates jump function in my game, but im dont know how to stop program.

This is the _jump() function code:

function _jump()
y-=5
y+=5

In comment, please tell me how to do this.
Im dont want to use "flip()".
This command doesnt stops program, only frames.

P#71908 2020-01-13 17:57

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

VERY THX!!!

P#71943 2020-01-14 19:10

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-01-22 13:31 | 0.009s | 4194k | Q:13