$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-genre-tower-defenseExpert blueprint for tower defense games (Bloons TD, Kingdom Rush, Fieldrunners) covering wave management, tower targeting logic, path algorithms, economy balance, and mazing mechanics. Use when building TD, lane defense, or tower placement strategy games. Keywords tower defense,
| 1 | ## Godot 4.7 Baseline |
| 2 | |
| 3 | - Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18). |
| 4 | - Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6. |
| 5 | - **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes. |
| 6 | |
| 7 | # Genre: Tower Defense |
| 8 | |
| 9 | Strategic placement, resource management, and escalating difficulty define tower defense. |
| 10 | |
| 11 | ## Core Loop |
| 12 | 1. **Prepare**: Build/upgrade towers with available currency |
| 13 | 2. **Wave**: Enemies spawn and traverse path toward goal |
| 14 | 3. **Defend**: Towers auto-target and damage enemies |
| 15 | 4. **Reward**: Kills grant currency |
| 16 | 5. **Escalate**: Waves increase in difficulty/complexity |
| 17 | |
| 18 | ## NEVER Do (Expert Anti-Patterns) |
| 19 | |
| 20 | ### Design & Strategy |
| 21 | - NEVER make all towers have the same niche; strictly ensure distinct specialties: **Aura Slow**, **Armor Piercing**, **Anti-Air**, **Burst Sniper**, and **Splash Damage**. |
| 22 | - NEVER allow a "Death Spiral" with no exit; strictly provide small **comeback bonuses** or interest on saved gold to prevent early inevitable failure. |
| 23 | - NEVER make early waves feel like busywork; strictly provide an **"Early Call" bonus** to skip wait times and accelerate engagement. |
| 24 | - NEVER trust client-side economy updates; strictly require the **authoritative server** to validate currency addition and tower purchases in co-op. |
| 25 | |
| 26 | ### Pathing & Placement |
| 27 | - NEVER allow the player to "Seal" the exit in mazing games; strictly validate path existence with **`NavigationServer2D.map_get_path()`** before finalizing tower placement. |
| 28 | - NEVER use synchronous `bake_navigation_polygon()` for mazing; strictly offload to a **worker thread** to prevent 100ms+ frame hitches during placement. |
| 29 | - NEVER use global coordinates for grid logic; strictly convert to **Vector2i/Vector3i** to ensure pixel-perfect tower alignment. |
| 30 | |
| 31 | ### Performance & Systems |
| 32 | - NEVER call `get_overlapping_bodies()` every frame; strictly use **signals** (`body_entered`/`body_exited`) to maintain a local target cache. |
| 33 | - NEVER use `_process()` for projectile movement if count > 500; strictly use the **PhysicsServer2D/3D** directly for high-performance bullet-hell tiers. |
| 34 | - NEVER spawn hundreds of projectiles as full Nodes; strictly use **Object Pooling** to reuse resources and avoid garbage collection stutters. |
| 35 | - NEVER use standard Strings for priorities; strictly use `StringName` (&"first", &"strongest") for O(1) hash comparisons in targeting loops. |
| 36 | - NEVER ignore the `progress` property on PathFollow nodes; strictly use it as the O(1) way to identify the **target closest to exit**. |
| 37 | - NEVER process tower search logic every frame; strictly **throttle ACQUIRE searches** (e.g., every 5-10 frames) to save significant CPU cycles. |
| 38 | - NEVER scale Tower `CollisionShape` non-uniformly; strictly adjust the radius property of the Shape resource to preserve collision math. |
| 39 | - NEVER delete enemies immediately on death; strictly use **set_deferred("disabled", true)** and wait one frame to prevent physics server crashes. |
| 40 | - NEVER hardcode waves in huge switch statements; strictly use **Custom Resources (.tres)** for clean balancing and sequence editing. |
| 41 | |
| 42 | --- |
| 43 | |
| 44 | ## 🛠 Expert Components (scripts/) |
| 45 | |
| 46 | ### Original Expert Patterns |
| 47 | - [wave_manager.gd](scripts/wave_manager.gd) - Professional wave orchestrator with Resource-based enemy composition and cleanup. |
| 48 | - [tower.gd](scripts/tower.gd) - Base turret class with FSM state management and firing logic. |
| 49 | - [tower_targeting_system.gd](scripts/tower_targeting_system.gd) - Autonomous priority logic (First/Last/Strongest/Weakest) for efficient targeting. |
| 50 | |
| 51 | ### Modular Components |
| 52 | - [tower_defense_patterns.gd](scripts/tower_defense_patterns.gd) - Collection of patterns for furthest-target logic and PhysicsServer projectile optimization. |
| 53 | |
| 54 | --- |
| 55 | |
| 56 | | Phase | Skills | Purpose | |
| 57 | |-------|--------|---------| |
| 58 | | 1. Grid/Path | `godot-tilemap-mastery`, `navigation-2d` | Defining where enemies walk and towers build | |
| 59 | | 2. Towers | `math-geometry`, `area-2d` | Range checks, rotation, projectile prediction | |
| 60 | | 3. Enemies | `path-following`, `steering-behaviors` | Movement along paths | |
| 61 | | 4. Management | `state-machines`, `loop-management` | Wave spawning logic, game phases | |
| 62 | | 5. UI | `ui-system`, `drag-and-drop` | Building towers, inspecting stats | |
| 63 | |
| 64 | ## Architecture Overview |
| 65 | |
| 66 | ### 1. Wave Manager |
| 67 | Handles the timing and godot-composition of enemy waves. |
| 68 | |
| 69 | ```gdscript |
| 70 | # wave_manager.gd |
| 71 | extends Node |
| 72 | |
| 73 | signal wave_started(wave_index: int) |
| 74 | signal wave_c |