About › How maps and missions are made
How maps and missions are made in City Defense
Every game of City Defense is a mission: a place on the map, a defended area, enemy spawn points and a set of rules. The map is neither downloaded in advance nor drawn by hand – the game takes streets and buildings on the fly from the OpenStreetMap tiles it loads to display the map. That is why a mission can be set up almost anywhere in the world.
City Defense is free to play in your browser – no download, no sign-up. First mission: Brno, náměstí Svobody.
Play freeWhat a mission is
- Play area
- a circle around a chosen center, 300 to 1,000 m in radius (Brno: 600 m)
- Defended area
- a polygon enemies must not reach – in Brno a 30 m circle in the middle of náměstí Svobody
- Spawn points
- places on the edge of the play area where enemies come from; each has a weight
- Rules
- money, lives, number of waves, difficulty, enemy types and bosses
- Look
- default theme, a “historic center” preset (cobblestones) and the regional look of the city
A mission stores only coordinates and rules, not the map. Streets and buildings are rebuilt from current map data every time the mission starts.
From map tiles to a street network
When you open a mission, this is what happens in your browser:
- The map zooms to the play area and waits for the OpenFreeMap vector tiles to load (OpenMapTiles schema, OpenStreetMap data).
- The game pulls streets and buildings out of the tiles it has already loaded – it downloads nothing extra and runs no map server of its own.
- It clips the streets to the circle and repairs gaps. Lines that only nearly meet in the data are joined; points closer than 2.5 m are merged into one node.
- It builds a street graph weighted by road class: roads 1.0, pedestrian zones and footways 1.1, service roads 1.3, tracks and other paths 1.5. Enemies therefore prefer roads, but will take a shortcut along a sidewalk or through a passage.
- It turns the defended area into gates. Every street segment that crosses the edge of the area is split at the crossing, and that point becomes a gate. Nodes inside the area are removed from pathfinding.
- It computes shortest paths from all gates at once (multi-source Dijkstra). Every point of the network then knows the way to the nearest gate.
- It snaps spawn points to the network (within 30 m), or proposes them itself.
A regression test runs this pipeline on four real map tiles of Brno: if a code change makes the network worse, the test fails.
How the game proposes spawn points
Candidates are the points where a street crosses the edge of the play area and from which a gate can be reached. The circle is split into five sectors, and in each sector the candidate with the smallest detour wins – main roads get a small bonus. Routes that would move more than 5 m away from the defended area along the way are ruled out. In the editor you can then move, add or delete spawn points.
A spawn point's weight sets how many enemies come from it. Each spawn point has its own stream of enemies, so more spawn points or higher weights mean more enemies in roughly the same time.
Buildings and their heights
Buildings come from the same tiles: the footprint and the render_height value from OpenMapTiles. The game stitches back together buildings that were cut at tile edges and turns the heights into a height map with 1 m cells, which it uses for tower line of sight and projectile paths. Only the play area plus 60 m is drawn in 3D – about 1,100 buildings in Brno. For more on where the heights come from, see map data and credits.
The mission editor: a map for anyone
There is one built-in mission so far (Brno – náměstí Svobody). Anyone can create more in the mission editor inside the game, with no account:
- Place – search for an address, use “My location” or click the map, then drag the center if you like; play area 300–1,000 m.
- Area and spawns – the game proposes a defended area with 4 to 8 entrances (the nearest pedestrian area around the center; a large square is cut down by a circle) and spawn points; you adjust them by dragging.
- Difficulty and look – an Easy, Normal or Hard preset, the bosses and the waves they arrive in, or your own numbers, plus a name and description.
- Test and save – play the mission (between waves you can edit its spawn points there; after going back to the editor the paused game waits and “Continue game” resumes it), have a bot test it, save it to “My missions” and share it as a link.
Checks run as you edit: the game flags missing gates, invalid spawn points or a street network that doesn't reach the defended area. The full walkthrough is in Tower defense in your own city.
Sharing by link and bot testing
A shared link carries the whole mission, compressed after the # in the address. That part of a URL is never sent to the server, so the mission isn't stored anywhere. The recipient sees a card with the name, author and description and can play the mission or edit their own copy.
The bot test plays the mission with two computer players – one builds towers, the other also upgrades them. It runs in Web Workers in the background, so the editor stays usable. Depending on how the bots do, the mission is labeled Easy, Normal, Hard or Very hard. The bots first work out how many enemies will come from each spawn point and put towers where the defense is still missing. The Brno mission comes out as Normal. Its test takes about 35–40 s on a fast computer with four or more cores, longer on slower computers and up to 1.5–2.5 minutes on a phone; missions with many waves take longer still, because the bots play every wave they survive.
Known limitations
- The game is only as good as the OpenStreetMap data. A missing street or building height shows up in the game too.
- Enemies only walk along mapped lines. They don't cut diagonally across open squares.
- A shared mission is rebuilt from the recipient's current tiles. If the OSM data has changed in the meantime, it may look slightly different.
- A large play area (close to 1,000 m) may not fit a small window; the game warns you.
Frequently asked questions
What are gates and spawn points?
A spawn point is a place on the edge of the play area where enemies come from. A gate is a point where a street or footpath crosses the edge of the defended area – an enemy that reaches it costs you a life.
Why can the same mission look different for someone else?
A mission only carries coordinates and rules. The street network and buildings are rebuilt for each player from current OpenStreetMap data, so changes to the map show up in the game too.