Syntax Cache
BlogMethodFeaturesHow It WorksBuild a Game
All Games
  1. Home
  2. GDScript
  3. Build a Game
  4. Roguelike
  5. Part 2: Every Turn Has Teeth

Roguelike: Part 2: Every Turn Has Teeth

Add turn-based combat with attack calculations, enemy AI that chases the player, health tracking, and damage signals in GDScript.

No login required.

Chapter 1

Turn Management

Every roguelike alternates between player and enemy turns. The code is now split across main.gd (coordinator + input), player.gd (position/HP), and enemy.gd (AI). You'll add turn state tracking and the turn switch.

Turn management controls who can act and when. That is what makes a game turn-based.

Loading game...

Click the game window to interact with it

What You'll Build

You will add enemies that take turns after the player moves. Enemies chase the player using simple AI (move toward target), attack when adjacent, and take damage from the player. Health tracking, damage calculation, and death handling turn the dungeon into an actual game with stakes.

Learning Goals

  • ✓Turn sequencing: player acts, then all enemies act
  • ✓Vector math for distance checks and chase direction
  • ✓Signal-based health and damage communication
  • ✓Enemy AI with pathfinding toward the player
  • ✓Death handling with queue_free() and state cleanup

GDScript Concepts in This Part

GDScript Timers & Signals PracticeLearn Godot 4 signals + timers in GDScript: Signal.connect(), Callable.bind(), await create_timer(), Timer cooldowns, safe connect/disconnect, and copy-paste recipes.GDScript Collisions PracticeFix body_entered not firing, understand monitoring vs monitorable, configure collision layers/masks, and debug with Visible Collision Shapes. RigidBody2D contact_monitor explained.GDScript Vector Math PracticeVector2 recipes for Godot 4: dot() for FOV, distance_squared_to() for performance, bounce()/reflect()/slide() for collisions, from_angle() for spreads. The complete toolbox.

Tips

  • ✨Process enemies in a for loop after the player's turn — this keeps the turn order deterministic and easy to debug.
  • ✨Use sign() on direction vectors to snap enemy movement to cardinal directions on the grid.
Syntax Cache

Build syntax muscle memory with spaced repetition.

Product

  • Pricing
  • Our Method
  • Daily Practice
  • Design Patterns
  • Interview Prep

Resources

  • Blog
  • Compare
  • Cheat Sheets
  • Vibe Coding
  • Muscle Memory

Languages

  • Python
  • JavaScript
  • TypeScript
  • Rust
  • SQL
  • GDScript

Legal

  • Terms
  • Privacy
  • Contact

© 2026 Syntax Cache

Cancel anytime in 2 clicks. Keep access until the end of your billing period.

No refunds for partial billing periods.