Files
pico8/pushbox-2.p8
2025-07-26 16:33:08 +02:00

278 lines
9.4 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 42
__lua__
function _init()
initmap()
win=false
hint=false
timer=60
end
function _update()
updateplayer()
check_win()
if btnp() then
reload()
_init()
end
end
function _draw()
cls()
camera(-20,-20)
map()
drawboxes()
drawplayer()
if hint==true and timer>0 then
timer-=1
print("can you hear it",10,25,7)
end
if win==true then
rectfill(24,19,55,25,10)
print("you win!",25,20,8)
end
end
-->8
function initmap()
m={
w=9,
h=8,
wallmap={},
boxmap={}
}
boxes={}
box_i=1
box_words={
[5]="s",[6]="i",
[21]="l",[22]="e",
[37]="n",[38]="t"
} --number on box
box_target={"l","i","s","t","e","n"}
player={
x=0, --position
y=0,
dir=1,
--1 right 2 left 3 down 4 up
image={3,4,19,35}
}
last_move={
x=0,
y=0,
b=0
}
---map
for i=0,m.w do
m.wallmap[i]={}
m.boxmap[i]={}
for j=0,m.h do
m.boxmap[i][j]=0
local f=fget(mget(i,j))
if f==2 then
m.wallmap[i][j]=1 --wall
else
m.wallmap[i][j]=0 --void
---player
if f==4 then
player.x=i
player.y=j
mset(i,j,17)
---boxes
elseif f==8 then
local box={
x0=i,
y0=j,
x=i, --position
y=j,
image=mget(i,j),
letter=0
}
box.letter=box_words[box.image]
boxes[box_i]=box
m.boxmap[i][j]=box_i
box_i+=1
mset(i,j,17)
end
end
end
end
end
--new word order
function check_win()
local this_letter,next_letter
local this_x,this_y=-1,-1
local next_x,next_y=-2,-2
local success=true
for i=1,5 do
this_letter=box_target[i]
next_letter=box_target[i+1]
for b in all(boxes) do
if b.letter==this_letter then
this_x=b.x
this_y=b.y
elseif b.letter==next_letter then
next_x=b.x
next_y=b.y
end
end
if not(this_x+1==next_x and this_y==next_y) then
success=false
break
end
end
win=success
end
function drawboxes()
for b in all(boxes) do
spr(b.image,b.x*8,b.y*8)
end
end
-->8
function updateplayer()
if hint==false then
if btnp() or btnp() or btnp() or btnp() then
hint=true
end
else
if btnp() then
player.dir=1
try_move(1,0)
elseif btnp() then
player.dir=2
try_move(-1,0)
elseif btnp() then
player.dir=3
try_move(0,1)
elseif btnp() then
player.dir=4
try_move(0,-1)
elseif btnp(🅾) then
undo()
end
end
end
function try_move(dx,dy)
--void + move
if m.boxmap[player.x+dx][player.y+dy]==0 and
m.wallmap[player.x+dx][player.y+dy]==0 then
player.x+=dx
player.y+=dy
last_move.x=dx
last_move.y=dy
last_move.b=0
--box + push
elseif inbounds(player.x+dx*2,player.y+dy*2)==true then
if m.boxmap[player.x+dx][player.y+dy]!=0 and
m.boxmap[player.x+dx*2][player.y+dy*2]==0 and
m.wallmap[player.x+dx*2][player.y+dy*2]==0 then
--box update
local bi=m.boxmap[player.x+dx][player.y+dy]
m.boxmap[player.x+dx][player.y+dy]=0
m.boxmap[player.x+dx*2][player.y+dy*2]=bi
boxes[bi].x+=dx
boxes[bi].y+=dy
player.x+=dx
player.y+=dy
last_move.x=dx
last_move.y=dy
last_move.b=bi
end
end
end
function undo()
local lx=last_move.x
local ly=last_move.y
local bi=last_move.b
player.x-=lx
player.y-=ly
--box undo
if bi>0 then
m.boxmap[boxes[bi].x][boxes[bi].y]=0
boxes[bi].x-=lx
boxes[bi].y-=ly
m.boxmap[boxes[bi].x][boxes[bi].y]=bi
end
last_move={
x=0,
y=0,
b=0
}
end
function inbounds(x,y)
if x>=0 and x<m.w
and y>=0 and y<m.h then
return true
else return false
end
end
function drawplayer()
spr(player.image[player.dir],player.x*8,player.y*8)
end
__gfx__
0000000033333333554994550dddddd00dddddd00ee777700ee77770000000000000000000000000000000000000000000000000000000000000000000000000
000000003b333333544494450ddfffd00dfffdd06f1111e26fe11ee200ccccc00ee0000000000000000000000000000000000000000000000000000000000000
0070070033b33333349999430df1f1d00d1f1fd06f1eeef26ffe1ef200c000c00e00000000000000000000000000000000000000000000000000000000000000
000770003333333354494445ddffef000dfeffdd6f1111f26fff1ff200c000c00e00000000000000000000000000000000000000000000000000000000000000
0007700033333333549999450d999a9999a999d06ffef1f26ffe1ff200c000c00e00000000000000000000000000000000000000000000000000000000000000
00700700333333b35444944300aaaa0000aaaa006feee1f26fee1ff200c000c00e00000000000000000000000000000000000000000000000000000000000000
0000000033333b335499994500aaaa0000aaaa006e1111f26ee11ef20cc00cc00ee0000000000000000000000000000000000000000000000000000000000000
00000000333333335549445500900900009009000ddddee00ddddee0000000000000000000000000000000000000000000000000000000000000000000000000
0000000033333333535555550dddddd0000000000ee777700ee77770000000000000000000000000000000000000000000000000000000000000000000000000
0000000033333333544444450dffffd0000000006f1eeee26f1111e2000000000000000000000000000000000000000000000000000000000000000000000000
0000000033333333494949440d1ff1d0000000006f1eeef26f1eeef2000000000000000000000000000000000000000000000000000000000000000000000000
00000000333333b399499949ddfeefdd000000006f1feff26f1111f2000000000000000000000000000000000000000000000000000000000000000000000000
000000003333333349994999009aa900000000006f1efff26f1efff2000000000000000000000000000000000000000000000000000000000000000000000000
000000003b33333349494944009aa900000000006f1eeff26f1eeff2000000000000000000000000000000000000000000000000000000000000000000000000
00000000333333335444444500aaaa00000000006e1111f26e1111f2000000000000000000000000000000000000000000000000000000000000000000000000
00000000333333335535535500900900000000000ddddee00ddddee0000000000000000000000000000000000000000000000000000000000000000000000000
00000000555535555544945300dddd00000000000ee777700ee77770000000000000000000000000000000000000000000000000000000000000000000000000
0000000034494445344994450dddddd0000000006f1eee12611111e2000000000000000000000000000000000000000000000000000000000000000000000000
0000000054994943449949440dddddd0000000006f11ee126ff1eef2000000000000000000000000000000000000000000000000000000000000000000000000
000000005494999594499999dddddddd000000006f1f1f126ff1eff2000000000000000000000000000000000000000000000000000000000000000000000000
00000000599494459999494909dddd90000000006f1e1f126ff1fff2000000000000000000000000000000000000000000000000000000000000000000000000
00000000549999454494494409aaaa90000000006f1ee1126fe1eff2000000000000000000000000000000000000000000000000000000000000000000000000
00000000544494455449944500aaaa00000000006e1eee126ee1eef2000000000000000000000000000000000000000000000000000000000000000000000000
00000000355355555349445500900900000000000ddddee00ddddee0000000000000000000000000000000000000000000000000000000000000000000000000
__gff__
0001020404080800000000000000000000010204000808000000000000000000000202040008080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
2212121212121212122200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0201011101010201010200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0211210101111111010200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0201111111110111010200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0211050615162526110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0201011111110112110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0211112101030111110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0211010111111101110200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
2212121212121212122200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000