Below is a simplified PICO-8 version of the classic Atari game "Adventure." This implementation captures the core elements of the original game: exploring a maze, collecting items (like a sword and chalice), avoiding or defeating enemies (dragons), and reaching a win condition. Due to PICO-8's limitations (e.g., 128x128 pixel screen, 8192 token code limit), I've kept it basic while making it fun and playable.
Key Features:
Map: A small 16x16 tile maze (you can expand it in the PICO-8 editor). Tiles: 0 = floor (walkable), 1 = wall.
Player: A simple square that moves with arrow keys. It can pick up items and use the sword to defeat enemies.
Items: Sword (for defeating enemies) and Chalice (for winning).
Enemies: Dragons that move randomly and can "eat" the player if you're not armed.
Win Condition: Collect the chalice and return to the starting area.
Gameplay Loop: Explore, collect, fight, and escape.
How to Use:
Copy the code below into a new PICO-8 cartridge.
In the PICO-8 editor:
Use the sprite editor to draw simple sprites:
Sprite 0: Player (e.g., a square).
Sprite 1: Sword (e.g., a small blade).
Sprite 2: Chalice (e.g., a cup).
Sprite 3: Dragon (e.g., a simple monster shape).
Use the map editor to design a maze:
Place tile 0 (floor) for walkable areas.
Place tile 1 (wall) for obstacles.
Start with a simple layout: Player at (8,8), Sword at (12,12), Chalice at (4,4), Dragons at (10,10) and (6,6).
Run the game and use the arrow keys to move.
Here's the full PICO-8 code:
lua
-- title: pico adventure
-- author: ai assistant
-- desc: A simplified PICO-8 version of Atari's Adventure
-- script: lua
-- Game constants
player_spr = 0 -- Sprite for player
sword_spr = 1 -- Sprite for sword
chalice_spr = 2 -- Sprite for chalice
dragon_spr = 3 -- Sprite for dragon
floor_tile = 0 -- Walkable tile
wall_tile = 1 -- Non-walkable tile
tile_size = 8 -- Each tile is 8x8 pixels
-- Game state variables
player_x = 64 -- Starting position (in pixels)
player_y = 64
has_sword = false
has_chalice = false
enemies = {} -- Table for enemies: {x, y}
items = {} -- Table for items: {x, y, type} (1=sword, 2=chalice)
function _init()
-- Initialize player, items, and enemies
player_x = 64 -- Center of map roughly
player_y = 64
has_sword = false
has_chalice = false
-- Place items (in pixels, assuming map coordinates)
items = {
{x=96, y=96, type=1}, -- Sword at (12*8, 12*8)
{x=32, y=32, type=2} -- Chalice at (4*8, 4*8)
}
-- Place enemies (simple dragons)
enemies = {
{x=80, y=80}, -- Dragon 1
{x=48, y=48} -- Dragon 2
}
end
function _update()
-- Handle player movement with collision checks
local dx = 0
local dy = 0
if btn(0) then dx = -1 end -- Left
if btn(1) then dx = 1 end -- Right
if btn(2) then dy = -1 end -- Up
if btn(3) then dy = 1 end -- Down
if dx != 0 or dy != 0 then
local new_x = player_x + dx * 2 -- Move 2 pixels per frame for speed
local new_y = player_y + dy * 2
-- Convert to tile coordinates and check for walls
local tile_x = flr(new_x / tile_size)
local tile_y = flr(new_y / tile_size)
if mget(tile_x, tile_y) == floor_tile then -- Only move if tile is walkable
player_x = new_x
player_y = new_y
end
end
-- Check for item pickups
for item in all(items) do
if dist(player_x, player_y, item.x, item.y) < 8 then -- Close enough to pick up
if item.type == 1 then -- Sword
has_sword = true
elseif item.type == 2 then -- Chalice
has_chalice = true
end
del(items, item) -- Remove the item
end
end
-- Update enemies (random movement)
for enemy in all(enemies) do
enemy.x += rnd(3) - 1.5 -- Random walk (-1.5 to 1.5 pixels)
enemy.y += rnd(3) - 1.5
enemy.x = mid(0, enemy.x, 127) -- Keep on screen
enemy.y = mid(0, enemy.y, 127)
-- Check for enemy-player collision
if dist(player_x, player_y, enemy.x, enemy.y) < 8 then
if has_sword then
del(enemies, enemy) -- Kill the enemy with sword
else
-- Game over: Reset the game
_init()
end
end
end
-- Win condition: Have chalice and return to starting area (e.g., bottom-right)
if has_chalice and player_x > 100 and player_y > 100 then
print("You win!", 50, 50, 7) -- Display win message
sfx(0) -- Play a sound if you add one
-- Optionally, reset after a few seconds: wait for input or loop
end
end
function _draw()
cls(0) -- Clear screen with black
-- Draw the map (assuming a 16x16 tile map starting at 0,0)
map(0, 0, 0, 0, 16, 16) -- Draw only a portion to fit the screen
-- Draw player
spr(player_spr, player_x, player_y)
-- Draw items
for item in all(items) do
spr(item.type, item.x, item.y) -- Use sprite based on type
end
-- Draw enemies
for enemy in all(enemies) do
spr(dragon_spr, enemy.x, enemy.y)
end
-- HUD: Show status
print("Sword: " .. (has_sword and "Yes" or "No"), 5, 5, 7)
print("Chalice: " .. (has_chalice and "Yes" or "No"), 5, 15, 7)
end
-- Helper function for distance
function dist(x1, y1, x2, y2)
return sqrt((x1 - x2)^2 + (y1 - y2)^2)
end
Notes:
Customization: This is a starting point. You can enhance it by:
Adding more items, enemies, or levels using PICO-8's map and sprite editors.
Implementing sound effects with sfx() (e.g., for picking up items or winning).
Adding animation for enemies by cycling sprites in _update().
Limitations: The game uses simple collision detection and random enemy movement to stay within PICO-8's token limit. The original Adventure has more complex mazes and puzzles, but this fits PICO-8's constraints.
Testing: In PICO-8, run the code and test movement. If enemies are too aggressive, adjust their speed in _update().
Inspiration: This draws directly from the Atari version but simplifies it for PICO-8. If you want additions like multiple levels or better AI, let me know, and I can refine it!