Build log · Games
How I built AgentVille
My portfolio as a Pokemon Red-style RPG, with live AI agents walking around as NPCs

1.Why I built it
AgentVille started as an 8-bit mode for my portfolio: a top-down world in the style of Pokemon Red where NPCs in a laboratory, a garden and a castle tell you about my work, and you learn attacks named after things like README.md and Code Review to battle bugs.
Later I connected it to AgentTower, my control room for Claude Code and Codex sessions. A hidden terminal in the world spawns one NPC per real or recent agent session, and you can talk to them. After that I added a Bug Dungeon that is generated fresh every visit and built out of my career history, with an AI oracle and AI-agent security threats as bosses.
2.How it works
A tile engine on one canvas
The world is drawn on a single canvas from 16 pixel tiles scaled 3x to 48 pixels, with a 14 by 11 tile viewport. Many textures are drawn procedurally into small offscreen canvases one pixel at a time, then reused as stamps. Movement is grid based: a step takes 150 ms and the renderer interpolates the player between tiles, with the camera centred on the interpolated position and offset by the sub-tile pixels for smooth scrolling.
The game loop lives in a useGameLoop hook running on requestAnimationFrame. Callbacks and flags change identity on every React render, so the hook keeps them in refs. That lets the loop start once instead of being torn down and restarted whenever state changes. Progress, captured bugs and achievements are saved to localStorage.
Live agents as NPCs
The in-world terminal logs in through the same AgentTower proxy routes the portfolio's Terminal app uses, then lists recent sessions. Each session becomes an NPC dropped on a free floor tile, cycling round-robin through every room so the whole world fills up, not one room. Talking to an agent NPC sends your message into that real session.
While a reply is pending the NPC shows a "..." bubble. When the reply lands, the NPC switches to seeking: every 250 to 400 ms it steps one tile along whichever axis has the larger distance to the player, checking walls, objects and other NPCs, and once adjacent it calls out the reply. So you can send a message, walk away, and the agent comes to find you.
Generating the Bug Dungeon
The dungeon generator starts with a random walk on a coarse grid, which builds the room tree and a planar drawing of it at the same time, since edges between grid neighbours can never cross. A pacing pass then assigns types: the root is the spawn, the deepest leaf is the boss, other far leaves become treasure, and a mid-depth room that is not the boss's parent becomes the oracle shrine. The walk is re-rolled until the boss is deep enough.
Rooms are sized by type and placed on the grid, with spacing grown until every pair keeps a minimum gap. Then a compression pass moves every room one tile toward spawn, nearest rooms first. Any step that collides with another room or corridor, or breaks the axis alignment a straight corridor needs, is undone for just that room, so the layout is valid after every step and never needs repair. A seeded mulberry32 PRNG makes each layout reproducible from its seed.
Enemy AI and atmosphere
Each bug has three states. Idle bugs shuffle around their home room. When the player enters the home room or comes within a few tiles by path, the bug switches to chase and follows a BFS path toward the player. If the path gets too long it switches to return and BFS-walks home. Bosses only guard their own room, and a bug you ran from is dazed long enough for you to slip past.
Difficulty scales with depth from spawn. Floors follow my career with the newest job at the top, and each nest guards a shard of one of my real projects. Unvisited rooms stay dark until you enter them, the minimap reveals the generator's room graph as you explore, and neighbouring rooms show as outlines.
AI flavour text with a fallback
On entry the game asks /api/ai, which calls the OpenAI API, for a dungeon title, a short intro and a boss taunt. The prompt includes the career floors and the boss's security theme (prompt injection, a rogue agent, a leaked key, tool poisoning) and asks for JSON only with character limits. The response is stripped of code fences, parsed, and each field is clipped to length.
If the request fails or any field is missing, the run keeps its procedurally written lore, so the dungeon never waits on the network. The oracle shrine uses the same route as a chat, sending a fresh snapshot of the dungeon state along with my bio each time you ask a question.
3.Try it
Move with the arrow keys or WASD (or the on-screen D-pad on mobile), and press Space or Enter next to an NPC or object to talk or interact.


