Computer monitor showing a pixel-art style tower defense game scene, with a keyboard and notebook on the desk
A game development desk with a pixel-art tower defense scene on screen.
2024 Game Development GitHub Profile ↗

Overview

Depot Gato in play: rats and armored rats on a dirt road, cats on the grass, and the depot at the end of the road
Wave 6: rats and armored rats on the road, Tabbies, Siamese snipers and a Yarn bomber guarding it.

Depot Gato is a 2D pixel-art tower defense game built in Godot 4 with GDScript. Waves of mice and rats walk a winding dirt road toward a depot, and you place cats on the grass beside the road to stop them. Three cats, three enemies, eight waves, one map.

It was built to learn Godot properly: composing scenes and instancing them at runtime, steering enemies with NavigationAgent2D, decoupling the HUD with signals and an autoload, and keeping game balance in data files instead of code.

It is also tested like software. A headless test scene runs 28 checks, three of which are complete games played by the test itself as fast as the CPU allows: with no towers the depot must fall, with a sensible build plan all eight waves must be held, and with only three basic cats the defence must fall mid-game, which proves the waves really escalate.

The source code is on GitHub at TYFSADIK/depot-gato. The project dates from 2024; the code was rebuilt and published in 2026 on Godot 4.7, with the tests and the screenshot tool.

Gameplay

You start with 120 coins and 20 lives. Pick a cat in the top bar (or press 1, 2 or 3), and a ghost follows the mouse showing the cat's range: green where you can build, red where you cannot (the road, a rock, an occupied tile, or not enough coins). Right-click a cat to sell it for 70% of its price. Kills pay coins, and every cleared wave pays a bonus.

CatCostRangeFire rateDamageShot
Tabby5044 pxevery 0.45 s4Kibble, single target
Siamese sniper85100 pxevery 1.5 s24Fish, fast and heavy
Yarn bomber12052 pxevery 1.3 s10Yarn ball, splash radius 22 px
EnemyHealthSpeedRewardLives lost
Mouse1434 px/s41
Rat4522 px/s82
Armored rat16015 px/s255
Enemy health at wave strengthBase health from enemy.gd times each wave's health scale, for the toughest appearance of each enemy. These are the game's own numbers.Mouse, wave 114 HP, speed 34Mouse, wave 825.2 HP, 14 x 1.8Rat, wave 345 HP, speed 22Rat, wave 867.5 HP, 45 x 1.5Armored rat, wave 6160 HP, speed 15Armored rat, wave 8208 HP, 160 x 1.3
Each wave scales enemy health, so late mice are almost twice as tough as early ones.

Architecture

Scene tree and signalsmain.tscn holds the level, the containers for towers, enemies and projectiles, the placement and wave nodes, and the HUD. Enemies, towers and projectiles are separate scenes instanced at runtime. GameState is an autoload; the HUD only listens to its signals.LevelTileMapLayer built from the ASCII map, navigation on path tilesTowerPlacementghost, build, sellWaveManagerreads WaveData, spawns,countsHUDCanvasLayer, labels andpaletteProjectileskibble, fish, yarnTowersinstanced tower scenesEnemiesinstanced enemy scenesGameState autoloadcoins, lives, wave; currency_changed, lives_changed,wave_changed, game_overMAIN.TSCNinstanceinstancedied, reached depotsignals
Gameplay nodes report to GameState; the HUD only listens.

Every gameplay entity is its own scene: enemy.tscn with three inherited variants (mouse, rat, armored rat), three tower scenes sharing one script, and three projectile scenes. main.tscn holds empty Towers, Enemies and Projectiles nodes that the runtime fills, which also fixes the drawing order.

GameState is an autoload that owns coins, lives and the wave number and emits currency_changed, lives_changed, wave_changed, countdown_changed and game_over. The HUD connects to those signals and to nothing else, so no gameplay node holds a reference to the HUD and the HUD never reads a gameplay node.

Physics layerUsed byDetects
1, enemiesEnemy bodiesnothing (mask 0, so enemies never block each other)
2, towersTower range Area2Denemies only
3, projectilesProjectile Area2D and the yarn blastenemies only

Build Process

1
A map that is also a navigation mesh

The map is 15 rows of text. level.gd builds a TileSet in code, gives the path tile a full-square navigation polygon, and fills a TileMapLayer from the text. Neighbouring path squares share edges, so the navigation map joins them into one corridor, and every enemy's NavigationAgent2D follows it. Godot 4.3 replaced TileMap with TileMapLayer, which is what this uses.

const MAP := [
	"..............................",
	"S#########..............x.....",
	".........#....................",
	".....x...#....########.......x",
	# ...
	"...#..........#......#....##D.",
]

var nav := NavigationPolygon.new()
nav.vertices = PackedVector2Array([Vector2(-h, -h), Vector2(h, -h), Vector2(h, h), Vector2(-h, h)])
nav.add_polygon(PackedInt32Array([0, 1, 2, 3]))
source.get_tile_data(PATH, 0).set_navigation_polygon(0, nav)
2
Enemies that wait for the map

The navigation map only syncs on the physics frame after the tiles register. An enemy that asks for a path on its first frame gets an empty one and would count as having arrived. So enemies start in IDLE and only set their target once the map has an iteration ID; arrival is a distance check against the depot.

func _physics_process(_delta: float) -> void:
	match state:
		State.IDLE:
			if NavigationServer2D.map_get_iteration_id(agent.get_navigation_map()) == 0:
				return
			agent.target_position = depot_position
			state = State.WALKING
			anim.play("walk")
		State.WALKING:
			if global_position.distance_to(depot_position) < 6.0:
				_reach_depot()
				return
			var next := agent.get_next_path_position()
			velocity = global_position.direction_to(next) * speed
			sprite.flip_h = velocity.x < -0.1
			move_and_slide()
3
Towers that pick the right target

A tower's range is an Area2D that keeps a live list of enemies inside it. On each cooldown tick the tower shoots the enemy with the shortest remaining path to the depot, worked out by summing the rest of the agent's path. Anything freed, dying or queued for deletion is skipped, so two towers never waste shots on a corpse.

func pick_target() -> Enemy:
	var best: Enemy = null
	var best_left := INF
	for enemy in targets_in_range:
		if not is_instance_valid(enemy) or enemy.is_queued_for_deletion() or not enemy.is_alive():
			continue
		var left := enemy.remaining_distance()
		if left < best_left:
			best_left = left
			best = enemy
	return best
4
Splash damage with its own Area2D

The yarn ball carries a second Area2D, the blast. When the ball touches an enemy, every enemy overlapping the blast takes damage, not only the one it hit.

func hit(enemy: Enemy) -> void:
	var hit_any := false
	for body in blast.get_overlapping_bodies():
		if body is Enemy and body.is_alive():
			body.take_damage(damage)
			hit_any = hit_any or body == enemy
	if not hit_any and enemy.is_alive():
		enemy.take_damage(damage)
5
Waves as data

Each wave is a WaveData resource in data/waves/: a list of entries, each naming an enemy scene, a count, a spawn interval and a health scale, plus a clear bonus. The wave manager reads whatever files are there, so rebalancing or adding a wave never touches code.

[resource]
script = ExtResource("1_wave")
entries = Array[Dictionary]([
  {"enemy": "res://scenes/enemies/mouse.tscn", "count": 8, "interval": 0.7, "hp_scale": 1.2},
  {"enemy": "res://scenes/enemies/rat.tscn", "count": 4, "interval": 1.6, "hp_scale": 1.0}])
clear_bonus = 30
6
Animations built on an AnimationPlayer

Each enemy builds three animations at startup: walk flips between two sprite frames, hurt flashes red and then queues walk again, and death fades and shrinks before the enemy frees itself.

7
Pixel art written in code

Every sprite is a few lines of text in art.gd, one character per pixel and one palette letter per colour. The cats share one mirrored template in three colourways, and the enemies share one two-frame walk cycle. Textures are built and cached at startup; nearest-neighbour filtering and pixel snapping keep them crisp at any window size.

# The Tabby's head, rows 1 to 9 of 16. k outline, o orange, O dark orange,
# e green eye, n pupil, w white muzzle, p pink nose, . transparent.
"..k..........k..",
".kOk........kOk.",
".koOk......kOok.",
".koookkkkkkoook.",
".koooooOOoooook.",
".kooooooooooook.",
".kooenooooneook.",
".koooowppwooook.",
"..koowwwwwwook..",

Enemy State Machine

Enemy state machineEach enemy waits in IDLE until the navigation map has synced, walks the path in WALKING, and leaves either through ATTACKING (it reached the depot and costs lives) or DEAD (it pays its reward and plays the death animation).IDLEspawned; wait for thenavigation map to syncWALKINGfollow NavigationAgent2D, walk animation loopsATTACKINGreached the depot: lose lives,freeDEADreward paid, death animation, freemap readywithin 6 px of depothp reaches 0
Four states; only WALKING moves.

The state gates both movement and animation. is_alive() is false in ATTACKING and DEAD, so towers and projectiles stop treating an enemy as a target the moment it reaches the depot or dies, even before it is freed.

Game Loop

One roundThe player builds between waves. A wave spawns its entries one by one; towers shoot what is in range; each enemy either dies (coins) or reaches the depot (lives). When the last enemy of a wave is gone, a bonus is paid and a six-second countdown starts the next wave, until the eighth is held or the lives run out.Buildspend coins on catsWave spawnsentries from WaveDataTowers firetarget closest to the depotEach enemydies: coins / gets through:livesLives at 0The depot fellWave clearedbonus, then a 6 s countdownback to BuildWave 8 heldDepot savedafter wave 8
Build, defend, collect, repeat for eight waves.
Enemies per waveCounted from data/waves/*.tres. Waves 6 to 8 add armored rats, which cost 5 lives each if they get through.Wave 18 enemies: mice onlyWave 212 enemies: mice onlyWave 312 enemies: 8 mice, 4 ratsWave 410 enemies: rats onlyWave 522 enemies: 16 mice, 6 ratsWave 612 enemies: 2 armored, 10 ratsWave 730 enemies: 20 mice, 8 rats, 2 armoredWave 837 enemies: 12 rats, 5 armored, 20 mice
Wave sizes from the data files.

Testing

The tests are a Godot scene, run headless with a fixed frame rate so that a whole game simulates in seconds:

$ godot --headless --fixed-fps 60 res://tests/run_tests.tscn
Depot Gato tests
  ok    every sprite is rectangular and uses palette colours only
  ok    the path connects the spawn to the depot
  ok    eight waves load from data/waves
  ok    the first mouse is walking
  ok    it moves along the navigation path toward the depot
  ok    it stays on path tiles
  ok    with no towers the depot falls (after 4457 frames)
  ok    cannot build on the path
  ok    selling refunds 70%
  ok    with towers all 8 waves are held (20 lives left, 15 towers built)
  ok    a thin defence of three Tabbies falls (on wave 4)
  ...
28 passed, 0 failed
  • Units: sprites, the economy and its signals, the map's connectivity, and that every wave entry points at a real enemy scene
  • Navigation: the first mouse walks, gets more than 50 pixels closer to the depot along the path within two seconds, and stays on path tiles
  • Rules: no building on the road, on rocks or twice on one tile; selling refunds 70% and frees the tile
  • Three full games: no towers (the depot falls), a 16-step build plan bought as coins allow (all eight waves held), and three Tabbies only (falls on wave 4)

The full-game tests caught a real bug: the road loops back past some tiles, so an enemy can leave a cat's range and walk into it again, and the tower then tried to connect the same signal twice. The fix checks for an existing connection and an existing entry before adding either.

A second scene, tools/capture.tscn, plays a scripted game and saves the screenshots on this page at three times the game's 480 by 270 resolution, with nearest-neighbour scaling.

Challenges and Lessons Learned

Navigation timing is a frame-order problem. Asking for a path before the navigation map has synced returns nothing. Waiting for the map's iteration ID, instead of guessing with a timer, makes spawning reliable.

Loops in the path break simple assumptions. A tower assumed an enemy enters its range once. The winding road disproved that, and the simulation found it.

Balance is data, and it can be tested. Because waves and stats live in data, the tests can play real games and assert that a strong defence wins and a weak one loses. That turns "feels too easy" into a failing test.

Autoloads and test scripts. Godot does not register autoloads for a script run with -s, so code that uses GameState fails to compile there. Running the tests as an ordinary scene gives them the same environment as the game.

Pixel art needs nearest filtering everywhere. The project-wide texture filter, pixel snapping and integer window scaling together keep 16-pixel sprites sharp at 1440 by 810.

What I Learned

  • Godot 4 scene composition: separate scenes, inherited scenes and runtime instancing
  • TileMapLayer, tile sets built in code, and navigation polygons on tiles
  • NavigationAgent2D path following, and when the navigation map is actually ready
  • Signals and an autoload as a data bus between gameplay and UI
  • Area2D detection with physics layers and masks
  • Resources as game data, and automated play-testing to keep the balance honest

What You Need

CategoryItemNotes
EngineGodot 4.4 or laterBuilt and tested on 4.7; uses TileMapLayer and ResourceLoader.list_directory
HardwareAny computer that runs GodotThe game renders at 480 by 270
SkillGDScript basicsVariables, functions, signals
Skill2D game conceptsScenes, physics layers, the game loop

What Is Next

  • Upgrades for placed cats, and a fourth cat that slows enemies
  • More maps, chosen from a menu
  • Sound effects and music
  • A web build on itch.io
  • A melee rat that attacks the nearest cat, using the reserved attacking state
Godot 4 GDScript Tower Defense Pixel Art NavigationAgent2D TileMapLayer Automated Testing