Files
PICO-8/pyras.p8

170 lines
3.8 KiB
Lua
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

pico-8 cartridge // http://www.pico-8.com
version 33
__lua__
-- escape the pyras
-- by djib
function _init()
initgame()
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()) guy.x=max(0,guy.x-guy.speed)
if (btn()) guy.x=min(127,guy.x+guy.speed)
if (btn()) guy.y=max(0,guy.y-guy.speed)
if (btn()) 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
repeat
pyras[i]={
x=flr(rnd(128)),
y=flr(rnd(128))
}
until abs(pyras[i].x-guy.x)>5
or abs(pyras[i].y-guy.y)>5
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 drawandeatpyras()
for index,pyra in ipairs(pyras) do
if pget(pyra.x,pyra.y)==8 then
sfx(0)
deli(pyras,index)
else
pset(pyra.x,pyra.y,8)
end
end
end
-->8
-- game
game={
level=7,
slowdown=0.1
}
function initgame()
game.state=0
game.tick=0
game.nbpyras=flr(40*1.25^game.level)
initguy()
initpyras()
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)
print("l:"..game.level,1,1,7)
end
function waitormove()
if game.tick>min(30,game.slowdown*#pyras) then
moveguy()
movepyras()
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()
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()
drawandeatpyras()
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