ASCII Roguelike Map
Build a program in Lua that generates a dungeon map for a roguelike game and draws it with ASCII characters: # for walls, . for floors, @ for the player's start, > for the stairs, and a few symbols for items. It places random rooms that don't overlap, connects them with corridors, and checks that every room can be reached. The same seed always gives the same map. At the end you'll serve the map in a web browser using OpenResty. It's a fun first Lua project: you'll practice tables, loops, functions, random numbers and modules, and see a classic game-development technique in action.
- Estimate
- ~10.5h
- Steps
- 7
- Completed by
- 0
- Proposed by
- codeseed.app
LuaRocks · OpenResty
Project roadmap
- 01
Set up the project
~1hInstall Lua 5.4 (or LuaJIT) and LuaRocks. Create map.lua as a module that returns a table of functions, and main.lua that requires it and prints Hello. Install the busted test framework with luarocks install busted. Done when: lua main.lua prints Hello and busted --version works.
- 02
Create the grid
~1hIn map.lua, write new_map(width, height), which returns a 2D table (a table of rows) filled with # walls, and render(map), which joins each row into a string and returns the whole map as text. Read the width, height and an optional seed from the command line (defaults 60, 20 and the current time), and call math.randomseed(seed). Done when: lua main.lua prints a solid rectangle of # characters.
- 03
Place rooms
~2hTry to place up to 10 rooms with random sizes (4 to 10 wide, 3 to 6 tall) at random positions. Keep a room only if it doesn't overlap any existing room, leaving at least one wall between rooms, and carve its inside into . floors. Store each room's position and size in a list. Done when: the map shows several separate rectangular rooms.
- 04
Connect rooms with corridors
~2hConnect each room to the next one in the list with an L-shaped corridor: from the center of one room, go horizontally, then vertically, to the center of the next, carving . floors along the way. Randomly choose whether the corridor goes horizontal-first or vertical-first. Done when: every room is joined to the others by corridors.
- 05
Add the player, stairs and items
~1.5hPlace @ in the center of the first room and > in the last room, then scatter 5 items on random floor cells ($ for gold, ! for a potion), never on the player, the stairs or each other. Write a flood-fill function that starts at @ and checks that the stairs and every item can be reached by walking on floors. Done when: the map shows all symbols, and the reachability check returns true.
- 06
Serve the map with OpenResty
~1.5hInstall OpenResty and create an nginx.conf with a location / that uses content_by_lua_block to require your map module, generate a map (using a seed from the ?seed= query parameter when given) and return it inside an HTML <pre> tag. Add the steps to run it in the README. Done when: opening http://localhost:8080/?seed=42 shows the same map as lua main.lua with seed 42.
- 07
Write tests
~1.5hWrite busted tests in spec/map_spec.lua checking that: the same seed gives the same map, rooms never overlap, the map has the requested width and height, and everything is reachable from @ for 20 different seeds. Done when: busted passes.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack