Created
April 30, 2020 12:34
-
-
Save RyanParsley/dbfa3803e7dfd4f3558a4b404c99e2a0 to your computer and use it in GitHub Desktop.
Stubbing out a game per the specs of my 4 year old.
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
pico-8 cartridge // http://www.pico-8.com | |
version 18 | |
__lua__ | |
--stormtrooper bear | |
--ryan parsley | |
function _init() | |
t = 0 | |
game_win=false | |
game_over=false | |
// xy change per button val | |
dirx = {-1,1,0,0} | |
diry = {0,0,-1,1} | |
tiles={ | |
wall=0, | |
door=1, | |
key=2, | |
enemy=3, | |
food=4, | |
goal=7 | |
} | |
draw = draw_game | |
make_player() | |
end | |
function _update60() | |
t+=1 | |
if (not game_over) then | |
check_win_lose() | |
move_player() | |
else | |
if (btnp(❎)) extcmd("reset") | |
end | |
end | |
function _draw() | |
cls() | |
draw() | |
end | |
function draw_game() | |
cls() | |
draw_map() | |
draw_player(p.direction == 'west') | |
end | |
-->8 | |
--map | |
function draw_map() | |
mapx=flr(p.x/16)*16 | |
mapy=flr(p.y/16)*16 | |
camera(mapx*8,mapy*8) | |
map(0,0,0,0,128,64) | |
end | |
function is_tile(tile_type,x,y) | |
tile=mget(x,y) | |
has_flag=fget(tile, tile_type) | |
return has_flag | |
end | |
function can_move(x,y) | |
return not is_tile(tiles.wall,x,y) | |
end | |
function swap_tile(x,y) | |
tile=mget(x,y) | |
mset(x,y,tile+1) | |
end | |
function unswap_tile(x,y) | |
tile=mget(x,y) | |
mset(x,y,tile-1) | |
end | |
function get_key(x,y) | |
p.keys+=1 | |
swap_tile(x,y) | |
sfx(2) | |
end | |
function open_door(x,y) | |
p.keys-=1 | |
swap_tile(x,y) | |
sfx(1) | |
end | |
-->8 | |
--player | |
function make_player() | |
p={ | |
x = 3, | |
y = 5, | |
x_offset = 0, // smooths transitions | |
y_offset = 0, | |
keys = 0, | |
sprite = 1, | |
animation = {2,2,3,5}, | |
direction = 'east' | |
} | |
end | |
function draw_player(flip) | |
spr(get_frame(p.animation),p.x*8,p.y*8, 1, 1, flip) | |
end | |
function get_frame(frames) | |
return frames[flr(t/15)%#frames+1] | |
end | |
function move_player() | |
// copy pending validation | |
newx=p.x | |
newy=p.y | |
// loop over button values | |
for i=0,3 do | |
if btnp(i) then | |
newx+=dirx[i+1] | |
newy+=diry[i+1] | |
if (newx < p.x) p.direction = 'west' | |
if (newx > p.x) p.direction = 'east' | |
p.x_offset=-dirx[i+1]*8 | |
p.y_offset=-diry[i+1]*8 | |
end | |
end | |
interact(newx,newy) | |
if (can_move(newx,newy)) then | |
p.x=mid(0,newx,127) | |
p.y=mid(0,newy,63) | |
else | |
sfx(0) | |
end | |
end | |
function interact(x,y) | |
if (is_tile(tiles.key,x,y)) then | |
get_key(x,y) | |
end | |
if (is_tile(tiles.door,x,y) and p.keys>0) then | |
open_door(x,y) | |
end | |
end | |
-->8 | |
--win/lose code | |
function check_win_lose() | |
if (is_tile(tiles.goal,p.x,p.y)) then | |
game_win=true | |
game_over=true | |
draw=draw_win_lose | |
end | |
if (is_tile(tiles.enemy,p.x,p.y)) then | |
game_win=false | |
game_over=true | |
draw=draw_win_lose | |
end | |
end | |
function draw_win_lose() | |
camera() | |
if (game_win) then | |
print("★ you win! ★",37,64,7) | |
else | |
print("game over! :(",38,64,7) | |
end | |
print("press ❎ to play again",20,72,5) | |
end | |
__gfx__ | |
00000000040004000040400000000000004040000000000000777000000760000000000000077000000000000000000000000000000000000000000000000000 | |
00000000044444000044440000404000004444000040400007777600007776000007700000777600000770000000000000000000000000000000000000000000 | |
00700700041414000044140000444400004414000044440007171600007716000077760000771600007776000000000000000000000000000000000000000000 | |
00077000044e440000444e000044140000444e000044140007777600007776000077160000777600007716000000000000000000000000000000000000000000 | |
00077000444444404444444000444e004444444000444e0057757650667775600077760066777560007776000000000000000000000000000000000000000000 | |
00700700044444000044400044444000004440004444400006666600006666006666650000666600666665000000000000000000000000000000000000000000 | |
00000000004040000020400000442000004020000024400000505000005060000066500000605000005660000000000000000000000000000000000000000000 | |
00000000004040000020400000400200004020000020040000505000005060000060050000605000005006000000000000000000000000000000000000000000 | |
00454000040000000000000000000000000005550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
05454500440000000000000000000000000666650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
4545454044000000aaa0000000000000000055550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
4545454044000000a0aaaaaa00000000066666550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
4545414044000000a0a00a0a00000000005555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
4545454044000000aaa0000000000000666665550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
45454540455555500000000000000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
bbbbbbb0bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
b3bbbbb0bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
bbbbb3b0bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
bb3bbb30bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
b3bbbb30bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
b3bb3bb0bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
bbbb3bb0bbbbbbb00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
51111150577777750000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
15111510766666650000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
11515110666666550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
11151110555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
11515110777557770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
15111510666576660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
51111150665576660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
00000000555555550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
__gff__ | |
0000000000000808080808000000000003000400800000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
__map__ | |
3131313131313131313131313131313131313131313131313131313131313131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120202020202020202020123106303030303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120202020202020212020203130303131303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120202021202121212121203130303131303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120202120202020212020203110103131303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120212021202020202020212121213131303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3120202020202020202020202121213131303030303030303030303030303031000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3131313120203131313131313131313131303030313131303030303030301431000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
3131313131313131313131313131313131313131313131313131313131313131000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
__sfx__ | |
000400000d03000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 | |
000200000022000220002200023005240172502b25031250372003820039200002000020000200002000020000200002000020000200002000020000200002000020000200002000020000200002000020000200 | |
0008000014020190201d03021030250302905030060390700c0003a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment