pico-8 cartridge // http://www.pico-8.com version 29 __lua__ -- amico8 demo -- a simple game to test -- your amico8 setup -- player px=60 py=60 ps=2 pc=7 pr=3 -- stars stars={} for i=1,40 do add(stars,{ x=rnd(128), y=rnd(128), s=rnd(2)+0.5, c=rnd(1)>0.5 and 7 or 6 }) end -- bullets buls={} bul_t=0 -- enemies ens={} en_t=0 score=0 hi=0 lives=3 shake=0 dead=false dead_t=0 function _init() music(0) end function _update() if dead then dead_t-=1 if dead_t<0 then if lives>0 then dead=false px=60 py=60 end end return end -- move if btn(0) then px-=ps end if btn(1) then px+=ps end if btn(2) then py-=ps end if btn(3) then py+=ps end px=mid(4,px,120) py=mid(4,py,120) -- shoot bul_t-=1 if btn(4) and bul_t<0 then add(buls,{x=px,y=py-4,dy=-4}) bul_t=4 sfx(0) end -- spawn enemies en_t-=1 if en_t<0 then add(ens,{ x=rnd(120)+4, y=-8, dy=rnd(1)+0.5, hp=1, c=8+flr(rnd(7)), r=3+rnd(2) }) en_t=20+rnd(30) end -- update bullets for b in all(buls) do b.y+=b.dy if b.y<-4 then del(buls,b) end end -- update enemies for e in all(ens) do e.y+=e.dy if e.y>134 then del(ens,e) end -- hit player if not dead and abs(e.x-px)<6 and abs(e.y-py)<6 then lives-=1 dead=true dead_t=30 shake=10 sfx(2) end end -- bullet vs enemy for b in all(buls) do for e in all(ens) do if abs(b.x-e.x)hi then hi=score end shake=3 sfx(1) end end end end -- shake if shake>0 then shake-=1 end end function _draw() -- camera shake local sx=0 local sy=0 if shake>0 then sx=rnd(4)-2 sy=rnd(4)-2 end camera(sx,sy) cls(0) -- stars for s in all(stars) do s.y+=s.s if s.y>128 then s.y=0 s.x=rnd(128) end pset(s.x,s.y,s.c) end -- bullets for b in all(buls) do rectfill(b.x-1,b.y-2,b.x+1,b.y+2,10) end -- enemies for e in all(ens) do circfill(e.x,e.y,e.r,e.c) circfill(e.x-1,e.y-1,1,7) end -- player if not dead then -- body circfill(px,py,pr,pc) -- cockpit circfill(px,py-1,1,12) -- wings line(px-pr-2,py+2,px-1,py,pc) line(px+pr+2,py+2,px+1,py,pc) -- flame if rnd(1)>0.3 then local fh=2+rnd(3) line(px-1,py+pr,px,py+pr+fh,9) line(px+1,py+pr,px,py+pr+fh,10) end end -- hud camera(0,0) print("score:"..score,2,2,7) print("hi:"..hi,70,2,6) for i=1,lives do circfill(8*i,122,2,8) end if dead and lives<=0 then print("game over",42,56,8) print("press z to restart",28,66,6) if btn(4) then score=0 lives=3 ens={} buls={} dead=false px=60 py=60 end elseif dead then print("ouch!",50,56,8) end end __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __sfx__ 000200001805018050180001800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000400002405024050240002400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 000800000c0500c0500c0000c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 __music__ 00 01424344