Adding game states
This commit is contained in:
103
pyras.p8
103
pyras.p8
@ -1,32 +1,32 @@
|
||||
pico-8 cartridge // http://www.pico-8.com
|
||||
version 33
|
||||
__lua__
|
||||
-- pyras
|
||||
-- by: djib
|
||||
-- escape the pyras
|
||||
-- by djib
|
||||
|
||||
function _init()
|
||||
initpyras()
|
||||
t=0
|
||||
initgame()
|
||||
initguy()
|
||||
initpyras()
|
||||
end
|
||||
|
||||
function _update()
|
||||
waitandmove()
|
||||
eatpyras()
|
||||
updategame()
|
||||
end
|
||||
|
||||
function _draw()
|
||||
cls()
|
||||
drawbg()
|
||||
drawguy()
|
||||
drawpyras()
|
||||
drawgame()
|
||||
end
|
||||
-->8
|
||||
-- guy
|
||||
guy={
|
||||
x=64,
|
||||
y=64,
|
||||
speed=4
|
||||
}
|
||||
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)
|
||||
@ -48,10 +48,10 @@ function drawguy()
|
||||
pset(guy.x+guy.speed,guy.y+guy.speed,6)
|
||||
end
|
||||
-->8
|
||||
pyras={}
|
||||
|
||||
-- pyras
|
||||
function initpyras()
|
||||
for i=1,200 do
|
||||
pyras={}
|
||||
for i=1,game.nbpyras do
|
||||
pyras[i]={
|
||||
x=flr(rnd(128)),
|
||||
y=flr(rnd(128))
|
||||
@ -71,6 +71,10 @@ function movepyras()
|
||||
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
|
||||
|
||||
@ -89,6 +93,17 @@ function eatpyras()
|
||||
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
|
||||
@ -97,13 +112,53 @@ function drawbg()
|
||||
print(#pyras,128-4*offset,1,7)
|
||||
end
|
||||
|
||||
function waitandmove()
|
||||
if t>0.05*#pyras then
|
||||
function waitormove()
|
||||
if game.tick>0.05*#pyras then
|
||||
movepyras()
|
||||
moveguy()
|
||||
t=0
|
||||
else
|
||||
t+=1
|
||||
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__
|
||||
@ -115,3 +170,5 @@ __gfx__
|
||||
00700700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
__sfx__
|
||||
000100002e05000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
9d0800000215000000000001910018100021500000000000021500000002150000000000014100131000515000000121000415000000041500000011100021500000002150000000010001150000000215000100
|
||||
000d00000c150000000f1500f1501315100000000001115000000000000c15000000000000000000000000000000000000000000a15000000000000c150000000000000000000000000000000000000000000000
|
||||
|
Reference in New Issue
Block a user