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