How to make a survival game with AI
A survival game is four or five timers quietly fighting the player. Ask for them all at once and you get a mess. Ask for one, make it hurt, then add the next.
Jump to a section
Ask for one pressure, not a world. Start with sixty seconds of staying alive, add hunger when that works, then night, then gathering, and save the game last. Every step has to be playable on its own before the next one arrives.
A platformer with a broken jump is obviously broken. A survival game with four half working systems feels vaguely bad, and no single thing is wrong enough to point at. That is much harder to fix, and it is what one large prompt produces.
Add one pressure at a time#
Survival is not a setting, it is arithmetic. Something drains, something refills it, and the refill is guarded by a risk. Each pressure you add is another instance of that shape, and they only feel good once they start arguing with each other.
The order matters because each step tests the one before it. Hunger is meaningless until the map is worth crossing. Night is meaningless until hunger makes you leave the safe corner. Crafting is meaningless until night is dangerous enough to want a wall.
The first prompt, and the four that follow#
Build the first slice of a survival game as ONE self-contained .html
file. This is step one of several, so keep it small and keep it readable.
WORLD: a square map seen from above, about three screens wide, with grass,
rocks and trees drawn as flat canvas shapes. The view follows the player.
PLAYER: moves with W, A, S, D. One health bar.
THREAT: wolves wander the map. Touching one takes health. They are slow
enough to outrun and there are never more than four.
GOAL: survive 60 seconds. Then a results screen with the time survived,
the best time, and a key to play again.
FOOD: berries scattered about restore a little health when walked over,
and do not come back.
ART: canvas shapes and flat colour only. No image files.
Base movement on seconds between frames, capped at 0.05. Put every number
I might want to tune into one CONFIG object at the top of the script.
Do not add hunger, crafting, day and night, or an inventory. I will ask
for those one at a time.
That last paragraph does more work than anything else in the prompt. Without it you get all five pressures half built, which is the exact outcome this guide exists to avoid.
Play it. If sixty seconds is boring, nothing you add later will fix it. Change the wolves or the map rather than piling a crafting system on top. When it holds your attention, the next four prompts are each one sentence.
- Hunger. Add a hunger bar that empties over about three minutes. At zero it drains health. Berries fill it. Show it next to health.
- Night. Every 90 seconds the screen darkens and the wolves get faster and more numerous. Dawn resets them.
- Gathering. Trees and rocks give wood and stone when stood next to. Five wood builds a wall segment, ten builds a fire that holds the wolves back.
- Saving. Keep the world, the inventory and the clock in localStorage, and restore them on load.
The numbers that decide whether it is fun#
Survival games are tuned, not designed. The same code is tedious or tense depending on four or five values, which is exactly why the prompt asks for one CONFIG object. These are reasonable places to start and none of them is correct.
| Number | Start at | What goes wrong at each end |
|---|---|---|
| Hunger bar empties in | 3 minutes | Faster and the player does nothing but eat. Slower and hunger is decoration. |
| Day length | 90 seconds | Shorter and nothing can be built. Longer and night stops being a threat. |
| Food per screen | 2 or 3 items | More and there is no scarcity. Less and the game is unwinnable by luck. |
| Threats at night | Double the day count | Less is not noticed. More and a careful player still dies, which reads as unfair. |
| Wall cost | 5 wood | Cheaper and there is no decision. Dearer and nobody ever sees a wall. |
Starting values for the prompts above. Change one, play two rounds, then change the next.
Ask for the change by its effect rather than its value. Hunger runs out too fast to explore gets a better result than set hungerPerSecond to 0.004, because the model can see the whole config and you cannot.
What breaks in a survival game#
These four turn up again and again, and none of them looks like a bug while you are building. They look like the game being slightly dull.
- The infinite corner. Resources respawn where the player is standing, so the best strategy is to stand still. Ask for spawns away from the player and a cap per area.
- Death with no explanation. A bar reaches zero off the edge of the screen and the player has no idea what killed them. Flash the bar that caused it and name the cause on the results screen.
- The unwinnable seed. A random map sometimes starts a player in a corner with no food. Ask for a guaranteed cluster near the start point.
- The save that loads a broken world. Half the state restores and the rest is a fresh game, so wolves are hunting a player who already died. Save and load the whole state object, never the fields one at a time.
🪵Survival games written by AI
Common questions#
Can AI make a survival game?
Yes, as long as you ask for it in stages. A model will happily write hunger, crafting, day and night and saving in one answer, and all four will roughly work and none will feel right. Asking for one pressure at a time gets a game you can actually play.
What is the simplest survival game to start with?
Stay alive for sixty seconds on a map with one threat and a little food. That is a complete game, it takes one prompt, and it tells you whether the movement and the map are worth building anything on top of.
How do I add hunger without making the game annoying?
Start with a bar that empties in about three minutes and only drains health once it is empty. Hunger should push the player out of a safe corner, not interrupt them. If they are eating more often than they are exploring, it is too fast.
Should a browser survival game save progress?
Add it last. Saving the whole state to localStorage on a timer is a single prompt. Doing it early means every later change has to be migrated into existing saves, including your own from an hour ago.
How long does a survival game take to build with AI?
The first playable slice is about ten minutes. The games on this site that people finish averaged hours spread over several sessions, and survival is at the slower end because tuning takes more rounds than building does.
How big should the map be?
About three screens wide for a first build. Big enough that crossing it is a decision, small enough that the player is never lost and that you are not asked to write a minimap in the first prompt.
Where to go next#
When a round of it is genuinely tense, publish it. The page it gets records the model, the prompt and the tokens behind it, and anybody can play without an account.
The method behind the staged prompts is in how to make a game with AI. Ready prompts for the faults above are in the prompt guide, and the drawing and movement side is covered in the 2D guide. For ideas, the survival games here are the biggest category on the site.
Built something? Put it on Agent Games.
Publishing takes a file and a minute. Your game gets its own page listing the model, the prompt and the token count, and anyone can play it without signing up.
Read next