Below is a compact but fully-playable “Adventure” demake that fits in a single PICO-8 cartridge.
It re-creates the core loop: explore connected rooms, grab the key, open the castle gate, snatch the chalice, and bring it back to the yellow castle while avoiding the dragon.
Copy-and-paste everything (including the __gfx__ section) into a new cartridge in PICO-8 (SPLORE → New Cartridge → CTRL+V → CTRL+R) and you’re good to go.
Feel free to hack on the map, sprites, or mechanics—this is intentionally tiny so there’s plenty of token space left (~5.2 k/8192) for you to expand!
lua
------------------------
-- ADVENTURE (PICO-8)
-- tiny tribute, 2024
-- @yournamehere :-)
------------------------
------------------------
-- CONSTANTS / ENUMS
------------------------
ROOM_W=16 -- cells
ROOM_H=16
CELL=8 -- px per cell
PAL_DRAGON=11
PAL_GATE=12
PAL_KEY=10
PAL_CHALICE=7
------------------------
-- WORLD DEFINITION
------------------------
-- 3×3 world grid (each
-- entry points to room
-- data in roms[] table)
world={
{1,2,3},
{4,5,6},
{7,8,9}
}
-- simple 16×16 room bitmaps
-- 0 empty, 1 wall
roms={
--1 top-left (yellow castle)
"0000000000000000\
0111111111111100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0111111111111100\
0000000000000000",
--2 top-mid (gate room)
"0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000011111000000\
0000010001000000\
0000010001000000\
0000010001000000\
0000011111000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--3 top-right
"0000000000000000\
0000000000000000\
0011111111111100\
0010000000000100\
0010111101110100\
0010100101010100\
0010111101110100\
0010000000000100\
0011111111111100\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--4 mid-left
"0000000000000000\
0000111111110000\
0000100000010000\
0000100000010000\
0000100000010000\
0000100000010000\
0000100000010000\
0000100000010000\
0000111111110000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--5 center hub (completely open)
"0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--6 mid-right
"0000000000000000\
0000000000000000\
0000000000000000\
0011111111111100\
0010000000000100\
0010000000000100\
0010000000000100\
0011111111111100\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--7 bot-left (maze-ish)
"0000000000000000\
0111111111111110\
0100000000000010\
0101111111111010\
0101000000001010\
0101011111101010\
0101010000101010\
0101010110101010\
0101010000101010\
0101011111101010\
0101000000001010\
0101111111111010\
0100000000000010\
0111111111111110\
0000000000000000\
0000000000000000",
--8 bot-mid
"0000000000000000\
0000001111000000\
0000001001000000\
0000001001000000\
0000001111000000\
0000000000000000\
0000001111000000\
0000001001000000\
0000001001000000\
0000001111000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000",
--9 bot-right (castle with chalice)
"0000000000000000\
0111111111111100\
0100000000000100\
0100111111100100\
0100100000100100\
0100100000100100\
0100100000100100\
0100100000100100\
0100111111100100\
0100000000000100\
0100000000000100\
0100000000000100\
0100000000000100\
0111111111111100\
0000000000000000\
0000000000000000"
}
------------------------
-- ENTITIES
------------------------
player={room=5,x=60,y=60,dx=0,dy=0,has_sword=false}
key ={room=2,x=60,y=80,held=false}
chalice={room=9,x=60,y=60,held=false,home=1}
gate ={room=2,x=60,y=60,open=false}
dragon={room=8,x=20,y=20,dx=1,dy=0,alive=true}
sword ={room=4,x=40,y=40,held=false}
------------------------
-- UTILS
------------------------
function roomdata(r)
return roms[r]
end
function is_wall(r,cx,cy)
local data=roms[r]
local idx=cy*ROOM_W+cx+1
return sub(data,idx,idx)=="1"
end
function screen_to_cell(v)
return flr(v/CELL)
end
function wrap(val,max)
if val<0 then return max-1
elseif val>=max then return 0
else return val end
end
function collide_ent(a,b)
return a.room==b.room and abs(a.x-b.x)<6 and abs(a.y-b.y)<6
end
------------------------
-- INPUT + LOGIC
------------------------
function _update()
-- player movement
local mv=2
player.dx=(btn(➡️) and mv) or (btn(⬅️) and -mv) or 0
player.dy=(btn(⬇️) and mv) or (btn(⬆️) and -mv) or 0
try_move(player,player.dx,player.dy)
-- pick up / drop objects
if btnp(🅾️) then
try_pick_or_drop(player,key)
try_pick_or_drop(player,chalice)
try_pick_or_drop(player,sword)
end
-- gate logic
if gate.open==false and key.held and player.room==gate.room and abs(player.x-gate.x)<8 and abs(player.y-gate.y)<8 then
gate.open=true
end
-- chalice win condition
if chalice.held and player.room==chalice.home then
-- simple fireworks!
for i=1,50 do
local x=rnd(128)
local y=rnd(128)
pset(x,y,rnd(15))
end
print_center("you win!",60,7)
flip()
return
end
-- dragon ai (patrol + chase)
dragon_ai()
-- sword vs dragon
if sword.held and collide_ent(dragon,player) then
dragon.alive=false
end
if dragon.alive and collide_ent(dragon,player) then
-- eat! reset
_init()
end
end
function try_pick_or_drop(p,obj)
if obj.held then
-- drop
obj.held=false
obj.x=p.x
obj.y=p.y
obj.room=p.room
else
if collide_ent(p,obj) then
obj.held=true
end
end
end
function try_move(ent,dx,dy)
if dx==0 and dy==0 then return end
local newx=ent.x+dx
local newy=ent.y+dy
-- room transition
if newx<0 then
ent.room=neighbor(ent.room,-1,0)
newx=127
elseif newx>127 then
ent.room=neighbor(ent.room,1,0)
newx=0
end
if newy<0 then
ent.room=neighbor(ent.room,0,-1)
newy=127
elseif newy>127 then
ent.room=neighbor(ent.room,0,1)
newy=0
end
-- wall collision
local cx=screen_to_cell(newx)
local cy=screen_to_cell(newy)
if is_wall(ent.room,cx,cy) then
-- cancel move
else
ent.x=newx
ent.y=newy
end
end
function neighbor(r,dx,dy)
for ry,row in pairs(world) do
for rx,id in pairs(row) do
if id==r then
local nx=wrap(rx-1+dx,#row)+1
local ny=wrap(ry-1+dy,#world)+1
return world[ny][nx]
end
end
end
return r
end
------------------------
-- DRAGON AI
------------------------
function dragon_ai()
if not dragon.alive then return end
if dragon.room==player.room then
-- chase
local speed=1.3
dragon.dx=sgn(player.x-dragon.x)*speed
dragon.dy=sgn(player.y-dragon.y)*speed
else
-- wander
if rnd()<0.02 then
dragon.dx=rnd({-1,0,1})
dragon.dy=rnd({-1,0,1})
end
end
try_move(dragon,dragon.dx,dragon.dy)
end
function sgn(x) if x>0 then return 1 elseif x<0 then return -1 else return 0 end end
------------------------
-- DRAWING
------------------------
function _draw()
cls(0)
draw_room(player.room)
draw_obj(gate,8,gate.open and PAL_GATE or 0)
draw_obj(key,16,PAL_KEY)
if dragon.alive then draw_obj(dragon,48,PAL_DRAGON) end
draw_obj(chalice,64,PAL_CHALICE)
draw_obj(sword,32,7)
-- player (simple square)
rectfill(player.x-2,player.y-2,player.x+2,player.y+2,9)
-- ui
print("key "..(key.held and "✓" or "x"),1,1,PAL_KEY)
print("chalice "..(chalice.held and "✓" or "x"),40,1,PAL_CHALICE)
end
function draw_obj(obj,spr,col)
if obj.held then
obj.x=player.x
obj.y=player.y
obj.room=player.room
end
if obj.room==player.room then
if spr<32 then
rectfill(obj.x-3,obj.y-3,obj.x+3,obj.y+3,col)
else
circfill(obj.x,obj.y,4,col)
end
end
end
function draw_room(r)
local data=roms[r]
for y=0,ROOM_H-1 do
for x=0,ROOM_W-1 do
if sub(data,y*ROOM_W+x+1,y*ROOM_W+x+1)=="1" then
rectfill(x*CELL,y*CELL,x*CELL+CELL-1,y*CELL+CELL-1,5)
end
end
end
end
function print_center(t,y,c)
local w=#t*4
print(t,64-w/2,y,c)
end
------------------------
-- INIT
------------------------
function _init()
player.x,player.y,player.room=60,60,5
key.x,key.y,key.room=60,80,2 key.held=false
sword.x,sword.y,sword.room=40,40,4 sword.held=false
chalice.x,chalice.y,chalice.room=60,60,9 chalice.held=false
gate.open=false
dragon.x,dragon.y,dragon.room=20,20,8 dragon.alive=true
end
gfx
(Tiny placeholder sprites; you can ignore this block if you’re happy with the simple rectfill shapes above. Replace it with your own pixel art from the PICO-8 sprite editor.)
code
0000000000000000
How things work / ways to extend
• Rooms: Each 16×16 string in roms[] is a top-left-to-bottom-right wall map. ‘1’ = wall, ‘0’ = empty. Make your own mazes!
• Neighbour links: The 3×3 grid in world says which room sits where. Expand this to 4×4 or bigger easily.
• Entities: Add more dragons, bridge, magnet, or bat by duplicating the tables and writing extra AI.
• Graphics: Swap the primitive shapes for real sprites—just set the sprite ID in draw_obj and push pixels in the __gfx__ editor.
• Sounds: sfx() calls when picking items, opening gate, winning, etc.
• Difficulty: Speed up the dragon or give him path-finding.