experiments-pico8/games/against.p8

147 lines
3.7 KiB
Plaintext
Raw Normal View History

2023-05-03 05:09:50 +00:00
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,10}, {25,30}, {38,44}}
walls[40]={{5,15}, {20,25}, {40,50}}
walls[50]={{5,10}, {20,30}, {45,55}}
walls[60]={{5,15}, {20,25}, {40,50}}
walls[70]={{0,10}, {20,30}, {44,55}}
walls[80]={{5,15}, {20,25}, {40,50}}
walls[90]={{0,10}, {25,30}, {38,44}}
2023-05-03 05:23:59 +00:00
the_line = 64
spr_frame = 1
2023-05-03 05:55:51 +00:00
floor = 0
jump_time = 0
2023-05-03 05:09:50 +00:00
end
function draw_side(right)
for y, platforms in pairs(walls) do
for plat in all(platforms) do
if right then
line(128-plat[1], y, 128-plat[2], y, DARK)
else
line(plat[1], y, plat[2], y, LIGHT)
end
end
end
end
function draw_level()
2023-05-03 05:55:51 +00:00
-- left side
2023-05-03 05:09:50 +00:00
cls(0)
draw_side(false)
2023-05-03 05:55:51 +00:00
spr(spr_frame, the_line-8, 120-floor, 1, 1, false)
2023-05-03 05:23:59 +00:00
rectfill(the_line, 0, 128, 128, LIGHT)
2023-05-03 05:55:51 +00:00
-- right side
2023-05-03 05:09:50 +00:00
draw_side(true)
pal({[LIGHT]=DARK})
2023-05-03 05:55:51 +00:00
spr(spr_frame, the_line, 120-floor, 1, 1, true)
2023-05-03 05:09:50 +00:00
pal()
2023-05-03 05:55:51 +00:00
-- 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()
2023-05-03 05:09:50 +00:00
end
function update_level()
2023-05-03 05:23:59 +00:00
spr_frame += .1
if spr_frame >= 4 then
spr_frame = 1
end
2023-05-03 05:55:51 +00:00
floor += 0.2
-- No button pressed: <
-- Right button pressed: |
-- Jump: <<
-- Jump & Right: >
local dx = -0.25
if btnp(4) then
jump_time = t()
2023-05-03 05:23:59 +00:00
end
if btn(1) then
2023-05-03 05:55:51 +00:00
dx += 0.25
if t() - jump_time < 1 then
dx += 0.25
end
2023-05-03 05:23:59 +00:00
end
2023-05-03 05:55:51 +00:00
the_line += dx
2023-05-03 05:09:50 +00:00
end
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__
2023-05-03 05:23:59 +00:00
00000000000060000000600000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000060060000600600006006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000666660006666600066666000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00077000000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00700700000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000606000006060000060600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000600600006060000600600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000