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}} the_line = 64 spr_frame = 1 floor = 0 jump_time = 0 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() -- left side cls(0) draw_side(false) spr(spr_frame, the_line-8, 120-floor, 1, 1, false) rectfill(the_line, 0, 128, 128, LIGHT) -- right side draw_side(true) pal({[LIGHT]=DARK}) spr(spr_frame, the_line, 120-floor, 1, 1, true) pal() -- 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() end function update_level() spr_frame += .1 if spr_frame >= 4 then spr_frame = 1 end floor += 0.2 -- 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 < 1 then dx += 0.25 end end the_line += dx 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__ 00000000000060000000600000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700000060060000600600006006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000000666660006666600066666000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00077000000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00700700000666000006660000066600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000606000006060000060600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000600600006060000600600000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000