add "glide" state
This commit is contained in:
parent
5022dfbe5a
commit
5d600463ca
18
borb.p8
18
borb.p8
@ -7,6 +7,7 @@ __lua__
|
|||||||
walk = 0
|
walk = 0
|
||||||
stand = 1
|
stand = 1
|
||||||
fly = 2
|
fly = 2
|
||||||
|
glide = 3
|
||||||
|
|
||||||
function init_world()
|
function init_world()
|
||||||
player = {
|
player = {
|
||||||
@ -50,6 +51,7 @@ function _draw()
|
|||||||
draw_player()
|
draw_player()
|
||||||
camera(0, 0)
|
camera(0, 0)
|
||||||
print_ctr("b o r b",8,yellow)
|
print_ctr("b o r b",8,yellow)
|
||||||
|
--print(player.state.." "..player.time)
|
||||||
end
|
end
|
||||||
|
|
||||||
function draw_bg()
|
function draw_bg()
|
||||||
@ -64,7 +66,7 @@ function update_player()
|
|||||||
|
|
||||||
dx = bool2int(btn(1)) - bool2int(btn(0))
|
dx = bool2int(btn(1)) - bool2int(btn(0))
|
||||||
if (dx != 0) then
|
if (dx != 0) then
|
||||||
if player.state == fly then
|
if player.state >= fly then
|
||||||
dx *= 2
|
dx *= 2
|
||||||
end
|
end
|
||||||
player.x += dx
|
player.x += dx
|
||||||
@ -77,10 +79,16 @@ function update_player()
|
|||||||
end
|
end
|
||||||
player.y += player.vy
|
player.y += player.vy
|
||||||
player.vy += 0.5
|
player.vy += 0.5
|
||||||
|
if player.vy > 0 and btn(🅾️) then
|
||||||
|
if player.state == fly then
|
||||||
|
set_state(glide)
|
||||||
|
end
|
||||||
|
player.vy = 0.2
|
||||||
|
end
|
||||||
if (player.y > 112) then
|
if (player.y > 112) then
|
||||||
player.y = 112
|
player.y = 112
|
||||||
player.vy = 0
|
player.vy = 0
|
||||||
if player.state == fly then
|
if player.state >= fly then
|
||||||
set_state(stand)
|
set_state(stand)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -90,6 +98,12 @@ function update_player()
|
|||||||
-- update sprite
|
-- update sprite
|
||||||
if player.state == stand then
|
if player.state == stand then
|
||||||
player.spr = 1
|
player.spr = 1
|
||||||
|
elseif player.state == glide then
|
||||||
|
if player.time % 16 >= 14 then
|
||||||
|
player.spr = 1
|
||||||
|
else
|
||||||
|
player.spr = 3
|
||||||
|
end
|
||||||
elseif player.state == walk then
|
elseif player.state == walk then
|
||||||
player.spr = (player.time / 2) % 2 + 1
|
player.spr = (player.time / 2) % 2 + 1
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user