|
|
@ -3,14 +3,21 @@ version 32 |
|
|
|
__lua__ |
|
|
|
-- game code |
|
|
|
|
|
|
|
-- player states enum |
|
|
|
walk = 0 |
|
|
|
stand = 1 |
|
|
|
fly = 2 |
|
|
|
|
|
|
|
function init_world() |
|
|
|
player = {} |
|
|
|
player.x = 60 |
|
|
|
player.y = 112 |
|
|
|
player.vy = 0 |
|
|
|
player.flipx = false |
|
|
|
player.spr = 0 |
|
|
|
player.moves = 0 |
|
|
|
player = { |
|
|
|
x = 60, |
|
|
|
y = 112, |
|
|
|
vy = 0, |
|
|
|
flipx = false, |
|
|
|
spr = 0, |
|
|
|
state = stand, |
|
|
|
time = 0 |
|
|
|
} |
|
|
|
end |
|
|
|
|
|
|
|
function _init() |
|
|
@ -29,6 +36,12 @@ function _update() |
|
|
|
update_player() |
|
|
|
end |
|
|
|
|
|
|
|
function set_state(state) |
|
|
|
if (player.state == state) return |
|
|
|
player.state = state |
|
|
|
player.time = 0 |
|
|
|
end |
|
|
|
|
|
|
|
function _draw() |
|
|
|
cls(12) |
|
|
|
camera_x = mid(0, 896, player.x - 64) |
|
|
@ -44,30 +57,46 @@ function draw_bg() |
|
|
|
end |
|
|
|
|
|
|
|
function update_player() |
|
|
|
if (btn(0)) then |
|
|
|
player.x -= 1 |
|
|
|
player.moves += 1 |
|
|
|
player.flipx = true |
|
|
|
end |
|
|
|
if (btn(1)) then |
|
|
|
player.x += 1 |
|
|
|
player.moves += 1 |
|
|
|
player.flipx = false |
|
|
|
end |
|
|
|
if (btnp(🅾️)) then |
|
|
|
player.vy = -5 |
|
|
|
player.jumping = true |
|
|
|
set_state(fly) |
|
|
|
end |
|
|
|
|
|
|
|
dx = bool2int(btn(1)) - bool2int(btn(0)) |
|
|
|
if (dx != 0) then |
|
|
|
if player.state == fly then |
|
|
|
dx *= 2 |
|
|
|
end |
|
|
|
player.x += dx |
|
|
|
player.flipx = dx < 0 |
|
|
|
if player.state == stand then |
|
|
|
set_state(walk) |
|
|
|
end |
|
|
|
elseif player.state == walk then |
|
|
|
set_state(stand) |
|
|
|
end |
|
|
|
player.y += player.vy |
|
|
|
player.vy += 0.5 |
|
|
|
if (player.y > 112) then |
|
|
|
player.y = 112 |
|
|
|
player.vy = 0 |
|
|
|
player.jumping = false |
|
|
|
if player.state == fly then |
|
|
|
set_state(stand) |
|
|
|
end |
|
|
|
end |
|
|
|
player.spr = (player.moves / 3) % 3 + 1 |
|
|
|
if (player.x < 0) player.x = 0 |
|
|
|
if (player.x > 1016) player.x = 1016 |
|
|
|
|
|
|
|
player.x = mid(0, player.x, 1016) |
|
|
|
|
|
|
|
-- update sprite |
|
|
|
if player.state == stand then |
|
|
|
player.spr = 1 |
|
|
|
elseif player.state == walk then |
|
|
|
player.spr = (player.time / 2) % 2 + 1 |
|
|
|
else |
|
|
|
player.spr = (player.time / 2) % 3 + 1 |
|
|
|
end |
|
|
|
|
|
|
|
player.time += 1 |
|
|
|
end |
|
|
|
|
|
|
|
function draw_player() |
|
|
@ -97,15 +126,19 @@ peach = 15 |
|
|
|
function print_ctr(s,y,c) |
|
|
|
print(s,64 - #s * 2,y,c) |
|
|
|
end |
|
|
|
|
|
|
|
function bool2int(b) |
|
|
|
return b and 1 or 0 |
|
|
|
end |
|
|
|
__gfx__ |
|
|
|
00000000ffff00ffffff00ffffff00ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000fff0880ffff0880ffff0880f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000ffff800fffff800fffff800f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000fff0800800008008fff08008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000ff08888ff888888fff08888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000f088888fff88888ff088888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000088888fffff888ff088888ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000fff4f4fffff4f4ffff4f4fff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000fff08008fff0800800008008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000ff08888fff08888ff888888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000f088888ff088888fff88888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000088888ff088888fffff888ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000fff4f4ffff4f4ffffff4f4ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
|
|
|