175 lines
3.8 KiB
Lua
175 lines
3.8 KiB
Lua
pico-8 cartridge // http://www.pico-8.com
|
|
version 33
|
|
__lua__
|
|
-- escape the pyras
|
|
-- by djib
|
|
|
|
function _init()
|
|
initgame()
|
|
initguy()
|
|
initpyras()
|
|
end
|
|
|
|
function _update()
|
|
updategame()
|
|
end
|
|
|
|
function _draw()
|
|
drawgame()
|
|
end
|
|
-->8
|
|
-- guy
|
|
function initguy()
|
|
guy={
|
|
x=64,
|
|
y=64,
|
|
speed=4,
|
|
dead=false
|
|
}
|
|
end
|
|
|
|
function moveguy()
|
|
if (btn(0)) guy.x=max(0,guy.x-guy.speed)
|
|
if (btn(1)) guy.x=min(127,guy.x+guy.speed)
|
|
if (btn(2)) guy.y=max(0,guy.y-guy.speed)
|
|
if (btn(3)) guy.y=min(127,guy.y+guy.speed)
|
|
end
|
|
|
|
function drawguy()
|
|
pset(guy.x,guy.y,11)
|
|
-- guides
|
|
pset(guy.x-guy.speed,guy.y-guy.speed,6)
|
|
pset(guy.x,guy.y-guy.speed,6)
|
|
pset(guy.x+guy.speed,guy.y-guy.speed,6)
|
|
pset(guy.x-guy.speed,guy.y,6)
|
|
pset(guy.x+guy.speed,guy.y,6)
|
|
pset(guy.x-guy.speed,guy.y+guy.speed,6)
|
|
pset(guy.x,guy.y+guy.speed,6)
|
|
pset(guy.x+guy.speed,guy.y+guy.speed,6)
|
|
end
|
|
-->8
|
|
-- pyras
|
|
function initpyras()
|
|
pyras={}
|
|
for i=1,game.nbpyras do
|
|
pyras[i]={
|
|
x=flr(rnd(128)),
|
|
y=flr(rnd(128))
|
|
}
|
|
end
|
|
end
|
|
|
|
function drawpyras()
|
|
for pyra in all(pyras) do
|
|
pset(pyra.x,pyra.y,8)
|
|
end
|
|
end
|
|
|
|
function movepyras()
|
|
for pyra in all(pyras) do
|
|
if (pyra.x>guy.x) pyra.x-=1
|
|
if (pyra.x<guy.x) pyra.x+=1
|
|
if (pyra.y>guy.y) pyra.y-=1
|
|
if (pyra.y<guy.y) pyra.y+=1
|
|
if pyra.x==guy.x and
|
|
pyra.y==guy.y then
|
|
guy.dead=true
|
|
end
|
|
end
|
|
end
|
|
|
|
function eatpyras()
|
|
local toeat={}
|
|
for i,pyra in ipairs(pyras) do
|
|
for j=i+1,#pyras do
|
|
if pyra.x==pyras[j].x and pyra.y==pyras[j].y then
|
|
add(toeat,j)
|
|
end
|
|
end
|
|
end
|
|
for index in all(toeat) do
|
|
sfx(0)
|
|
deli(pyras,index)
|
|
end
|
|
end
|
|
-->8
|
|
-- game
|
|
game={
|
|
level=4
|
|
}
|
|
|
|
function initgame()
|
|
game.state=0
|
|
game.tick=0
|
|
game.nbpyras=flr(40*1.25^game.level)
|
|
end
|
|
|
|
function drawbg()
|
|
local offset=1
|
|
if(#pyras>9)offset+=1
|
|
if(#pyras>99)offset+=1
|
|
rectfill(0,0,127,127,1)
|
|
print(#pyras,128-4*offset,1,7)
|
|
end
|
|
|
|
function waitormove()
|
|
if game.tick>0.05*#pyras then
|
|
movepyras()
|
|
moveguy()
|
|
game.tick=0
|
|
end
|
|
end
|
|
|
|
function updategame()
|
|
game.tick+=1
|
|
if game.state==0 then
|
|
if(btnp(❎))game.state=1
|
|
elseif game.state==1 then
|
|
waitormove()
|
|
eatpyras()
|
|
if guy.dead then
|
|
game.state=3
|
|
game.level=max(0,game.level-1)
|
|
sfx(1)
|
|
elseif #pyras==1 then
|
|
game.state=2
|
|
game.level+=1
|
|
sfx(2)
|
|
end
|
|
elseif game.tick>60 then
|
|
_init()
|
|
end
|
|
end
|
|
|
|
function drawgame()
|
|
cls()
|
|
drawbg()
|
|
drawguy()
|
|
drawpyras()
|
|
if game.state==0 then
|
|
cursor(48,61,7)
|
|
print "press ❎"
|
|
print "to start"
|
|
elseif game.state>1 then
|
|
cursor(46,61,7)
|
|
print "game over"
|
|
if game.state==2 then
|
|
print "you won!!"
|
|
end
|
|
if game.state==3 then
|
|
print "you lost!"
|
|
end
|
|
end
|
|
end
|
|
__gfx__
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00077000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
__sfx__
|
|
000100002e05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
|
9d0800000215000000000001910018100021500000000000021500000002150000000000014100131000515000000121000415000000041500000011100021500000002150000000010001150000000215000100
|
|
000d00000c150000000f1500f1501315100000000001115000000000000c15000000000000000000000000000000000000000000a15000000000000c150000000000000000000000000000000000000000000000
|