204 lines
5.2 KiB
Lua
204 lines
5.2 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 41
|
|
__lua__
|
|
--
|
|
function _init()
|
|
--start_scene("title")
|
|
start_scene("level")
|
|
end
|
|
|
|
function _update()
|
|
if _scene and _scene.update then
|
|
_scene.update()
|
|
end
|
|
end
|
|
|
|
function _draw()
|
|
if _scene and _scene.draw then
|
|
_scene.draw()
|
|
end
|
|
end
|
|
|
|
function start_scene(name)
|
|
_scene = _scenes[name]
|
|
_scene_start = time()
|
|
if _scene.start then
|
|
_scene.start()
|
|
end
|
|
end
|
|
|
|
function scene_time()
|
|
return time() - _scene_start
|
|
end
|
|
|
|
_scene = nil
|
|
_scenes = {}
|
|
_scene_start = 0
|
|
|
|
function draw_title()
|
|
cls()
|
|
print("title " .. scene_time())
|
|
end
|
|
|
|
function update_title()
|
|
if scene_time() > 2 then
|
|
start_scene("menu")
|
|
end
|
|
end
|
|
|
|
function draw_menu()
|
|
cls()
|
|
print("menu " .. scene_time())
|
|
end
|
|
|
|
function update_menu()
|
|
end
|
|
|
|
|
|
function start_level()
|
|
walls = {}
|
|
walls[30]={{0,20}}
|
|
walls[50]={{20,60}}
|
|
walls[70]={{90, 120}}
|
|
walls[90]={{10, 40}, {80, 100}}
|
|
the_line = 64
|
|
spr_frame = 1
|
|
opp_frame = 1
|
|
floor = 0
|
|
jump_time = 0
|
|
end
|
|
|
|
function draw_platforms()
|
|
for y, platforms in pairs(walls) do
|
|
for plat in all(platforms) do
|
|
if plat[2] < the_line then
|
|
line(plat[1], y, plat[2], y, LIGHT)
|
|
elseif plat[1] > the_line then
|
|
line(plat[1], y, plat[2], y, DARK)
|
|
else
|
|
line(plat[1], y, the_line, y, LIGHT)
|
|
line(the_line, y, plat[2], y, DARK)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function collide_platforms()
|
|
local left = the_line - 6
|
|
local right = the_line + 6
|
|
local py = 128-floor
|
|
for y, platforms in pairs(walls) do
|
|
for plat in all(platforms) do
|
|
-- check if there's a platform at this level
|
|
if py > y and py - y < 8 then
|
|
-- check if either edge of player+opp is between edges
|
|
if (left > plat[1] and left < plat[2]) or (right > plat[1] and right < plat[2]) then
|
|
printh("xcol "..(the_line-6).." "..plat[1].."-"..plat[2])
|
|
crush_line = y
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function draw_player()
|
|
if crush_line then
|
|
local squash_h = 8-(crush_line - (120-floor))
|
|
printh(crush_line.." "..(120-floor))
|
|
sspr(40, 0, 8, 8, the_line-8, crush_line, 8, squash_h, false)
|
|
pal({[LIGHT]=DARK})
|
|
sspr(40, 0, 8, 8, the_line, crush_line, 8, squash_h, true)
|
|
pal()
|
|
else
|
|
spr(spr_frame, the_line-8, 120-floor, 1, 1, false)
|
|
pal({[LIGHT]=DARK})
|
|
spr(opp_frame, the_line, 120-floor, 1, 1, true)
|
|
pal()
|
|
end
|
|
end
|
|
|
|
function draw_level()
|
|
-- left side
|
|
cls(0)
|
|
rectfill(the_line, -128, 128, 128, LIGHT)
|
|
draw_platforms()
|
|
draw_player()
|
|
-- floor
|
|
rectfill(0, 128-floor, the_line, 129-floor, LIGHT)
|
|
rectfill(the_line, 128-floor, 128, 129-floor, DARK)
|
|
fillp(0b1000010000100001)
|
|
rectfill(0, 130-floor, the_line, 128, LIGHT)
|
|
fillp(0b0111101111011110)
|
|
rectfill(the_line, 130-floor, 128, 128, LIGHT)
|
|
fillp()
|
|
|
|
if floor > 120 then
|
|
camera(0, -(floor-120)*16)
|
|
if floor > 128 then
|
|
floor = 0
|
|
camera(0, 0)
|
|
end
|
|
end
|
|
end
|
|
|
|
function update_level()
|
|
floor += floor_speed
|
|
|
|
-- No button pressed: <
|
|
-- Right button pressed: |
|
|
-- Jump: <<
|
|
-- Jump & Right: >
|
|
|
|
local dx = -0.25
|
|
if btnp(4) then
|
|
jump_time = t()
|
|
end
|
|
if btn(1) then
|
|
dx += 0.25
|
|
if t() - jump_time < 0.5 then
|
|
dx += 0.25
|
|
end
|
|
end
|
|
the_line += dx
|
|
|
|
-- collision
|
|
if not crush_line then
|
|
collide_platforms()
|
|
end
|
|
|
|
-- player frames:
|
|
-- still: 1
|
|
-- walking: 1, 2
|
|
-- back slide: 3, 4
|
|
-- cramped: 5
|
|
local mod = (t()*4) % 2
|
|
if dx == 0 then
|
|
spr_frame = 3
|
|
opp_frame = 3
|
|
elseif dx < 0 then
|
|
spr_frame = 4
|
|
opp_frame = 1 + mod
|
|
else
|
|
spr_frame = 1 + (t() % 2)
|
|
opp_frame = 3
|
|
end
|
|
end
|
|
|
|
floor_speed = 0.4
|
|
LIGHT = 6
|
|
DARK = 0
|
|
_scenes.title = {start=nil, draw=draw_title, update=update_title}
|
|
_scenes.menu = {start=nil, draw=draw_menu, update=nil}
|
|
_scenes.level = {start=start_level, draw=draw_level, update=update_level}
|
|
|
|
|
|
__gfx__
|
|
00000000000060000000600000006000000060000000600000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000666000006660000066600000666000006660000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000060060000600600006006000060060600600600000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000666660006666600066666000666660666666600000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000666000006660000066600000666000006660000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000666000006660000066600000666000006660000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000606000006060000060600000606000006060000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000606000006006000600600006000600060006000000000000000000000000000000000000000000000000000000000000000000000000000000000
|