233 lines
14 KiB
Lua
233 lines
14 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
||
version 32
|
||
__lua__
|
||
-- game code
|
||
|
||
-- player states enum
|
||
walk = 0
|
||
stand = 1
|
||
fly = 2
|
||
glide = 3
|
||
|
||
function init_world()
|
||
player = {
|
||
x = 60,
|
||
y = 112,
|
||
vy = 0,
|
||
flipx = false,
|
||
spr = 0,
|
||
state = stand,
|
||
time = 0
|
||
}
|
||
end
|
||
|
||
function _init()
|
||
-- disable btnp autorepeat
|
||
poke(0x5f5c, 255)
|
||
|
||
-- set peach as bg color
|
||
-- instead of black
|
||
palt(black, false)
|
||
palt(peach, true)
|
||
|
||
init_world()
|
||
end
|
||
|
||
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)
|
||
camera(camera_x, 0)
|
||
draw_bg()
|
||
draw_player()
|
||
camera(0, 0)
|
||
print_ctr("b o r b",8,yellow)
|
||
--print(player.state.." "..player.time)
|
||
end
|
||
|
||
function draw_bg()
|
||
map(0, 0, 0, 0, 128, 16)
|
||
end
|
||
|
||
function update_player()
|
||
if (btnp(🅾️)) then
|
||
player.vy = -5
|
||
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.vy > 0 and btn(🅾️) and player.state >= fly then
|
||
if player.state == fly then
|
||
set_state(glide)
|
||
end
|
||
player.vy = 0.2
|
||
end
|
||
if (player.y > 112) then
|
||
player.y = 112
|
||
player.vy = 0
|
||
if player.state >= fly then
|
||
set_state(stand)
|
||
end
|
||
end
|
||
|
||
terrain = mget((player.x+4)/8,(player.y+8)/8)
|
||
if player.vy > 0 and fget(terrain, 0) then
|
||
player.y = ((player.y + 1)\ 8) * 8
|
||
player.vy = 0
|
||
if player.state >= fly then
|
||
set_state(stand)
|
||
end
|
||
end
|
||
|
||
player.x = mid(0, player.x, 1016)
|
||
|
||
-- update sprite
|
||
if player.state == stand then
|
||
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
|
||
player.spr = (player.time / 2) % 2 + 1
|
||
else
|
||
player.spr = (player.time / 2) % 3 + 1
|
||
end
|
||
|
||
player.time += 1
|
||
end
|
||
|
||
function draw_player()
|
||
spr(player.spr,player.x,player.y,1,1,player.flipx)
|
||
end
|
||
|
||
-->8
|
||
-- library
|
||
|
||
black = 0
|
||
dark_blue = 1
|
||
dark_purple = 2
|
||
dark_green = 3
|
||
brown = 4
|
||
dark_gray = 5
|
||
light_gray = 6
|
||
white = 7
|
||
red = 8
|
||
orange = 9
|
||
yellow = 10
|
||
green = 11
|
||
blue = 12
|
||
indigo = 13
|
||
pink = 14
|
||
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
|
||
00000000fff08008fff0800800008008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000ff08888fff08888ff888888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000f088888ff088888fff88888f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000088888ff088888fffff888ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000fff4f4ffff4f4ffffff4f4ff000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
4444444444444444ff4444ffff4444fffffff33ff33ff33ff33fffff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
4444444444444444ff4444ffff4444fffff333333333333333333fff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1444444144444411ff4444ffff4444ffff33333333333333333333ff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1114411111441111ff4444ffff4444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1111111111111111ff4444ffff4444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1111111111111111f444444fff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1111111111111111f444444fff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
1111111111111111f444444fff4444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff0444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff0444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444ff333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
000000000000000000000000ff4444fff3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000f3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000333333333333333333333333000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000f3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000f3333333333333333333333f000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000ff33333333333333333333ff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000fff333333333333333333fff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
00000000000000000000000000000000fffff33ff334433ff33fffff000000000000000000000000000000000000000000000000000000000000000000000000
|
||
__gff__
|
||
0000000000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000000010101000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
__map__
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000004445460000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000005455560000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003
|
||
0000000000000000006465660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003
|
||
0000000000000000000043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000053000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
0000000000000000000042000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||
4040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040404040
|