diff --git a/games/boybomb.p8 b/games/boybomb.p8 index 44b57b5..f07042b 100644 --- a/games/boybomb.p8 +++ b/games/boybomb.p8 @@ -2,7 +2,12 @@ pico-8 cartridge // http://www.pico-8.com version 41 __lua__ -- + +#include sprites.lua + function _init() + palt(11, true) + palt(0, false) start_scene("explainer") end @@ -47,25 +52,66 @@ end _scenes.title = {start=nil, draw=draw_title, update=update_title} -function draw_explainer() +function draw_dusk() cls() + fillp(0b1010010110100101) + rectfill(0, 0, 128, 12, 2) + fillp(0) + rectfill(0, 12, 128, 64, 2) + -- trick: make other fill transparent + fillp(0b1010010110100101.1) + rectfill(0, 50, 128, 60, 9) +end + +function draw_explainer() + draw_dusk() + map(0, 0, 0, 16, 16, 8) local st = scene_time() - print("in 1978, eddie boyman was \ninvolved in an accident") + local bcolors = {8, 9, 10} + local bcolor = bcolors[flr(5*t()%3)+1] + print("in 1978, eddie boyman was \n involved in an accident.", 0, 80, 7) if st > 2 then - print("as a result of a failed NASA experiment") + print("\nas a bystander of a \n failed nasa experiment") end if st > 6 then - print("he became...") + print("he became...", 10, 118) end if st > 7 then - print("a bomb") + print("a bomb", 60, 118, bcolor) end + + draw_sprite(exp_spr) end function update_explainer() + update_sprite(exp_spr) + if exp_spr.speed == 0 then + if exp_phase == "boy" then + exp_spr = make_sprite(50, 50, "boy_bomb", 0.4) + exp_phase = "boy_bomb" + elseif exp_phase == "boy_bomb" then + exp_spr = make_sprite(50, 50, "bomb_s", 0.1) + exp_phase = "bomb_s" + elseif exp_phase == "bomb_s" then + exp_spr = make_sprite(50, 50, "bomb_m", 0.1) + exp_phase = "bomb_m" + end + end end -_scenes.explainer = {start=nil, draw=draw_explainer, update=update_explainer} +function start_explainer() + exp_spr = make_sprite(20, 20, "boy_walk", 0.2) + exp_phase = "boy" +end + +_scenes.explainer = {start=start_explainer, draw=draw_explainer, update=update_explainer} + +animations = { + boy_walk={frames={[0]=2, 0, 4, 0}, w=2, h=2}, + boy_bomb={frames={[0]=32, 34, 36, 38, 40, 42, 44, 46}, w=2, h=2}, + bomb_s={frames={[0]=64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76}, w=1, h=1}, + bomb_m={frames={[0]=80, 82, 84, 86, 88, 90, 92}, w=2, h=2} +} -- globals @@ -112,22 +158,22 @@ bb000bbbbb000bbbbb000bbbbb000bbbbb000bbbbb999bbbbbb999bbbb999bbbbb999bbbbb888b00 0000000b0000000b0000000b0000000b0000000b0000000bb00000000009000b0aa9a00ba998900b9998909b09989a9b99989a9b000000000000000000000000 0000000b0000000b0000000b0000000b0000000b0000000bb00000000000000b0000000b0aa9000b0a99090baa99a9abaa99a9ab000000000000000000000000 bb000bbbbb000bbbbb000bbbbb000bbbbb000bbbbb000bbbbbb000bbbb000bbbbb000bbbbb000bbbbb000bbb0b99abb0bb99abbb000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8bbbbbbbbb8bbbbb8bbbbbbbbb8bbbbb8bbbbbbb00000000000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8bbbbbbbbb8bbbbb8bbbbb8bbb8bbbbbbbbbbb8bbbb00000000000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbbbb88bb8bbbbbbbbbbb88bb8bbbb8bbbbbbbbbb8bbbb8bbbbbbbbbbbbb8b8bbbbbbbbbbbbbb00000000000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbb8888b8bbbbbbbbbb8888b8b8bbbbbbbb88b8b8b8bbbbbbbb8bb8bbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbbb898bbbbbbbbbbbbb898bbbbbbbbbbbbb898bbbbbbbbbbbbb8bbbbbbbbbbbbbbb8bbbbbbbb00000000000000000000000000000000 -bbbbbbbbbbbbbbbbbbbbbbbb98bbbbbbbbbbbbbb98bbbbbbbb9bbbbbbbbbbbbbbb9bbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -bbbb8bbbbabbbbbbbbbb8bbb99bbbbbbbbbb899b99bb8bbbbbbb899b99bb8bbbbbbbbbbbb9bbbbbbbbbbbbbbb9bbbbbb00000000000000000000000000000000 -bbb88bbb88bbbbbb8bb88bbb99bbbbbbbbb999b999abbbbbb8b999b999abbbbbb8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -bbbb999889bbb8bb88bb999899bbbbbbbbb99aaaa9998bbbbbb99bbbbbb98bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -bbbb98aa9999b888b8bb99aaa999bbb8bbb99abbbaa99bb8b9b9bbbbbbb99bb8b9bbbbbbbbbbbbb8bbbbbbbbbbbbbbb800000000000000000000000000000000 -899b999aa999bb98889b98aa9999bb98bb999abab9a99998bb99bbbbb9b99998bbbbbbbbbbb9b9b8bbbbbbbbbbbbbbbb00000000000000000000000000000000 -b88a98998abbbbbb888a99a8a9bbbbbbbb899abba9abb99bbb89bbbbbbbbb99bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -baa998aaa99998bbb8a9998aa89998bbbba99abbaaa9989bbba99bbbbbb9989bbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 -bbb99988a9bbb88bbbb9988aa9bbb88bbbb99aaaa9bbb99bb9b99bbba9bbb99bb9bbbbbbbbbbbbbb8bbbbbbbbbbbbbbb00000000000000000000000000000000 -bbb8899a9abbbb9bbbb8899a9abbbb8bbbb899999999998bbbb89bbb9999998bbbbbbbbbbbbbbbbb8bbbbbbbbbbbbbbb00000000000000000000000000000000 -bbbb899abbbbbbbbbbbb899abbbbbbbbbbbb899abbbbbbbbbbbb899abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb00000000000000000000000000000000 +bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8bbbbbbbbb8bbbbb8bbbbbbbbb8bbbbb8bbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb8bbbbbbbbb8bbbbb8bbbbb8bbb8bbbbbbbbbbb8bbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbbbbbbbbbbbbbbbbbbbbbb88bb8bbbbbbbbbbb88bb8bbbb8bbbbbbbbbb8bbbb8bbbbbbbbbbbbb8b8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbbbbbbbbbbbbbbbbbbbb8888b8bbbbbbbbbb8888b8b8bbbbbbbb88b8b8b8bbbbbbbb8bb8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbbbbbbbbbbbbbbbbbbbbb898bbbbbbbbbbbbb898bbbbbbbbbbbbb898bbbbbbbbbbbbb8bbbbbbbbbbbbbbb8bbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbbbbbbbbbbbbbbbbbbbbbb98bbbbbbbbbbbbbb98bbbbbbbb9bbbbbbbbbbbbbbb9bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbb8bbbbabbbbbbbbbb8bbb99bbbbbbbbbb899b99bb8bbbbbbb899b99bb8bbbbbbbbbbbb9bbbbbbbbbbbbbbb9bbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbb88bbb88bbbbbb8bb88bbb99bbbbbbbbb999b999abbbbbb8b999b999abbbbbb8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbb999889bbb8bb88bb999899bbbbbbbbb99aaaa9998bbbbbb99bbbbbb98bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbb98aa9999b888b8bb99aaa999bbb8bbb99abbbaa99bb8b9b9bbbbbbb99bb8b9bbbbbbbbbbbbb8bbbbbbbbbbbbbbb8bbbbbbbbbbbbbbbb0000000000000000 +899b999aa999bb98889b98aa9999bb98bb999abab9a99998bb99bbbbb9b99998bbbbbbbbbbb9b9b8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +b88a98998abbbbbb888a99a8a9bbbbbbbb899abba9abb99bbb89bbbbbbbbb99bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +baa998aaa99998bbb8a9998aa89998bbbba99abbaaa9989bbba99bbbbbb9989bbbabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbb99988a9bbb88bbbb9988aa9bbb88bbbb99aaaa9bbb99bb9b99bbba9bbb99bb9bbbbbbbbbbbbbb8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbb8899a9abbbb9bbbb8899a9abbbb8bbbb899999999998bbbb89bbb9999998bbbbbbbbbbbbbbbbb8bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 +bbbb899abbbbbbbbbbbb899abbbbbbbbbbbb899abbbbbbbbbbbb899abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb0000000000000000 77cc77ccbbbb55555555bbbbbbbbbbbb555555556b5555b65577775577cc77cc77cc77cc77cc77cc788c88cc77cc77cc7555555c000000000000000000000000 77cc77ccbbbb55555555bbbbbbbbbbbb55555555b556655b554444557444444c7555555c7555555c783c38cc7444444c55555555000000000000000000000000 cc77cc77bbbb55555555bbbbbbbbbbbb555555555555555555cc7755c4ffff47c5665657c5a78357cc333c77c438684755555555000000000000000000000000 @@ -169,13 +215,13 @@ bb6666666666666666666666666666bbbb66c6c6c646c6c66c6c6c646c6c66bb0000000000000000 33333333353353330000000000000000000000000000000000000000000000006666666600000000000000000000000000000000000000000000000000000000 33333333353353330000000000000000000000000000000000000000000000003333333300000000000000000000000000000000000000000000000000000000 __map__ -0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000008081828300000000000000848586870000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000009091929300000000000000909192930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000009091929300000000000000909192930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -0000009091929300000000000000909192930000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -b0b0b0b0b0b0b0b0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000008081828300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000009091929300000000000000000000000000000084858687000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000009091929300000000000000000000000000000090919293000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000009091929300000000000000000000000000000090919293000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +0000009091929300000000000000000000000000000090919293000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +b8b8b8b8b8b8b8b8b8b8b8b8b8b8b8b80000000000b8b8b8b8b8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b00000000000b0b0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 diff --git a/games/sprites.lua b/games/sprites.lua new file mode 100644 index 0000000..d867fed --- /dev/null +++ b/games/sprites.lua @@ -0,0 +1,34 @@ +function make_sprite(x, y, anim, speed) + s = { + x=x, y=y, anim=animations[anim], speed=speed, + frame=0, last_update=t(), + flip_x=false, flip_y=false, loop=false, + } + return s +end + +function update_sprite(s) + local now = t() + if s.last_update == 0 then + s.last_update = now + return + end + if s.speed != 0 then + if now - s.last_update > s.speed then + s.frame += 1 + s.last_update = now + if s.frame > #s.anim.frames then + if s.loop then + s.frame = 0 + else + s.speed = 0 + s.frame = #s.anim.frames + end + end + end + end +end + +function draw_sprite(s) + spr(s.anim.frames[s.frame], s.x, s.y, s.anim.w, s.anim.h, s.flip_x, s.flip_y) +end \ No newline at end of file