Last active
November 15, 2018 10:53
-
-
Save tobiasvl/4367f00e67cb5c90a6e5c9846be04c89 to your computer and use it in GitHub Desktop.
Patrick's Picochallenge
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
poke(24364,3)x="웃"v="▥"h="▤"b={}for i=1,36 do b[i]=i%9<2 and""or"█"end for i in all{"⬆️","➡️",h,"⬅️","⬇️",v,x}do repeat f=1+flr(rnd(36))until b[f]!=""b[f]=i | |
if(i==x)p=f | |
end::_::t=btnp cls()for i=0,35 do | |
k=b[i+1] | |
?k,i%9*8,6*flr(i/9)+20,k==x and 11 or 7 | |
end b[p]=""q=p | |
if(t(0))q-=1 | |
if(t(1))q+=1 | |
if(t(2))q-=9 | |
if(t(3))q+=9 | |
if(b[q]and#b[q]>0)p=q t=b[p] | |
if(t=="⬆️"or t==v)b[p-10]=""b[p-9]=""b[p-8]="" | |
if(t=="⬇️"or t==v)b[p+10]=""b[p+9]=""b[p+8]="" | |
if(t=="⬅️"or t==h)b[p-10]=""b[p-1]=""b[p+8]="" | |
if(t=="➡️"or t==h)b[p+10]=""b[p+1]=""b[p-8]="" | |
b[p]=x flip()goto _ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--patrick's picochallenge | |
--by tobiasvl | |
--use 64x64 resolution | |
poke(0x5f2c,3) | |
--generate a blank board of | |
--empty █ tiles | |
board={} | |
--the board is 7x4, but we | |
--represent it as a one- | |
--dimensional table. we also | |
--represent it as 36 tiles, ie | |
--a 9x4 grid, with two columns | |
--of "" on each end, so ⬅️➡️▤▥ | |
--tiles don't wrap around when | |
--they destroy adjacent tiles. | |
for i=1,36 do | |
if i%9<2 then | |
--first and last column | |
board[i]="" | |
else | |
board[i]="█" | |
end | |
end | |
--populate the board with tiles | |
--and the player's starting tile | |
tiles={"⬆️","➡️","▤","⬅️","⬇️","▥","웃"} | |
for i in all(tiles) do | |
--find a random tile which is | |
--not in the "invisible" outer | |
--columns | |
repeat | |
position=1+flr(rnd(36)) | |
until board[position]!="" | |
board[position]=i | |
--remember the player | |
if (i=="웃") player=position | |
end | |
--game loop | |
::_:: | |
cls() | |
--print the board | |
--here's the only obfuscation i | |
--left in: here i loop from | |
--0 to 35, instead of 1 to 36, | |
--because then i only need to | |
--do i+1 once instead of i-1 | |
--twice. | |
for i=0,35 do | |
local tile=board[i+1] | |
--the player is green | |
if tile=="웃" then | |
color(11) | |
else | |
color(7) | |
end | |
--properly centering the board | |
--takes up too many characters | |
--so just an approximation | |
print(tile,i%9*8,6*flr(i/9)+20) | |
end | |
--erase the player character | |
--and destroy the tile | |
board[player]="" | |
--remember the player's position | |
new_player=player | |
--move the player's position if | |
--an arrow key is pressed | |
if (btnp(⬅️)) new_player-=1 | |
if (btnp(➡️)) new_player+=1 | |
if (btnp(⬆️)) new_player-=9 | |
if (btnp(⬇️)) new_player+=9 | |
--if we're still inside the | |
--board proper, ie the tile isn't | |
--nil (outside the board) or "" | |
--(the border columns), make | |
--that the new position. | |
if board[new_player] and board[new_player]!="" then | |
player=new_player | |
tile=board[player] | |
end | |
--if the player lands on one of | |
--the special tiles, destroy | |
--adjacent tiles | |
if tile=="⬆️" or tile=="▥" then | |
--destroy three tiles above | |
board[player-10]="" | |
board[player-9]="" | |
board[player-8]="" | |
end | |
if tile=="⬇️" or tile=="▥" then | |
--destroy three tiles below | |
board[player+10]="" | |
board[player+9]="" | |
board[player+8]="" | |
end | |
if tile=="⬅️" or tile=="▤" then | |
--destroy three tiles left | |
board[player-10]="" | |
board[player-1]="" | |
board[player+8]="" | |
end | |
if tile=="➡️" or tile=="▤" then | |
--destroy three tiles right | |
board[player+10]="" | |
board[player+1]="" | |
board[player-8]="" | |
end | |
--put the player in the new | |
--(or old!) position | |
board[player]="웃" | |
--loop | |
flip() | |
goto _ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment