Skip to main content

Gymnasium environment for Untitled Tower Defense Game

Project description


title: Untitled Tower Defense Game emoji: ๐Ÿ“ˆ colorFrom: green colorTo: indigo sdk: docker secrets:

  • GITHUB_TOKEN app_file: app.py app_port: 7860 pinned: false license: eupl-1.2 short_description: UTDG is a tower defense game custom_headers: cross-origin-embedder-policy: require-corp cross-origin-opener-policy: same-origin cross-origin-resource-policy: cross-origin

Untitled Tower Defense Game (UTDG)

A modular 2D tower defense game built with Godot Engine 4.5. Itโ€™s designed to be easy to experiment with, extend, and plug into machine-learning workflows. Your goal is simple: defend your base against waves of enemies by placing towers in smart locations.

๐ŸŽฏ About

UTDG doubles as a reinforcement learning environment. This Space provides the playable web version of the game, so you can try it directly in the browser or connect it to an RL training loop.

Overview

In UTDG, enemies attempt to steal cargo and escape the map. You place towers to intercept them, manage resources, and react to changing enemy patterns. The game includes flexible tower mechanics and a layout that encourages strategic planning and experimentation.

The codebase follows clean, modular coding practices that separate game logic, UI, and environment setup, making it ideal for:

  • Learning game development concepts in Godot
  • Experimenting with tower defense mechanics
  • Extending with custom towers, enemies, and abilities

Key Features

Core Gameplay Systems

  • Modular Tower Management: Build towers on valid grid positions
  • Player Resource System: Gold-based economy for tower placement and upgrades
  • Dynamic Difficulty Manager: Configurable enemy spawn rates and health scaling over time using curve-based progression
  • Base Defense: Health system with visual feedback and defeat conditions
  • Victory Conditions: Win by surviving all enemy waves

Technical Highlights

  • 2D GridMap-based building system for tower placement
  • Ray-casting camera controller with WASD movement and Q/E rotation
  • Organized scene structure with reusable components
  • Signal-based communication between game systems

Project Structure

UTDG/
โ”œโ”€โ”€ base_level.tscn              # Main game scene (entry point)
โ”œโ”€โ”€ project.godot               # Godot project configuration
โ”œโ”€โ”€ export_presets.cfg          # Export configuration for builds
โ”‚
โ”œโ”€โ”€ .github/                    # GitHub configuration
โ”‚   โ””โ”€โ”€ workflows/              # CI/CD workflows
โ”‚       โ”œโ”€โ”€ claude.yml          # Claude AI integration
โ”‚       โ””โ”€โ”€ build-macos.yml     # macOS build automation
โ”‚
โ”œโ”€โ”€ Assets/                     # Game assets (fonts, textures)
โ”‚   โ””โ”€โ”€ Asap/                   # Font files
โ”‚
โ”œโ”€โ”€ Base/                       # Player base and economy
โ”‚   โ”œโ”€โ”€ bank.gd                 # Gold/resource management
โ”‚   โ””โ”€โ”€ base.gd                 # Base health and damage handling
โ”‚
โ”œโ”€โ”€ builds/                     # Build output directory (gitignored)
โ”‚   โ””โ”€โ”€ UTDG.app                # macOS application bundle
โ”‚
โ”œโ”€โ”€ DifficultyManager/          # Game progression system
โ”‚   โ”œโ”€โ”€ difficulty_manager.gd  # Spawn rate and enemy health curves
โ”‚   โ””โ”€โ”€ difficulty_manager.tscn
โ”‚
โ”œโ”€โ”€ Enemy/                      # Enemy behavior and spawning
โ”‚   โ”œโ”€โ”€ enemy.gd                # Enemy AI with navigation
โ”‚   โ”œโ”€โ”€ enemy_manager.gd        # Wave spawning controller
โ”‚   โ””โ”€โ”€ enemy.tscn
โ”‚
โ”œโ”€โ”€ EnemyEntrypoint/            # Enemy spawn point
โ”‚   โ”œโ”€โ”€ enemy_entrypoint.gd
โ”‚   โ””โ”€โ”€ enemy_entrypoint.tscn
โ”‚
โ”œโ”€โ”€ SpawningStrategy/           # Modular spawning system
โ”‚   โ”œโ”€โ”€ spawning_strategy_base.gd        # Base strategy interface
โ”‚   โ”œโ”€โ”€ spawning_strategy_manager.gd     # Strategy coordinator
โ”‚   โ”œโ”€โ”€ curve_based_strategy.gd          # Original curve-based spawning
โ”‚   โ”œโ”€โ”€ wave_based_strategy.gd           # Wave-based spawning
โ”‚   โ”œโ”€โ”€ timed_strategy.gd                # Fixed/variable interval spawning
โ”‚   โ”œโ”€โ”€ spawning_strategy_manager.tscn   # Manager scene
โ”‚   โ””โ”€โ”€ README.md                         # Spawning strategy documentation
โ”‚
โ”œโ”€โ”€ Towers/                     # Tower system
โ”‚   โ”œโ”€โ”€ tower_manager.gd         # Tower placement and building
โ”‚   โ”œโ”€โ”€ tower.gd                # Base tower logic and targeting
โ”‚   โ”œโ”€โ”€ turret.gd               # Turret variant
โ”‚   โ”œโ”€โ”€ projectile.gd           # Projectile behavior
โ”‚   โ”œโ”€โ”€ tower.tscn
โ”‚   โ”œโ”€โ”€ turret.tscn
โ”‚   โ”œโ”€โ”€ cannon_tower.tscn
โ”‚   โ””โ”€โ”€ projectile.tscn
โ”‚
โ”œโ”€โ”€ RayPickerCamera/            # Camera and input handling
โ”‚   โ”œโ”€โ”€ ray_picker_camera.gd   # Raycasting for tower placement
โ”‚   โ””โ”€โ”€ ray_picker_camera.tscn
โ”‚
โ”œโ”€โ”€ UserInterface/              # UI elements
โ”‚   โ”œโ”€โ”€ victory_layer.gd        # Victory/defeat screens
โ”‚   โ””โ”€โ”€ victory_layer.tscn
โ”‚
โ”œโ”€โ”€ MeshLibraries/              # 3D mesh libraries for GridMap
โ”‚   โ””โ”€โ”€ SpaceLibrary.tscn
โ”‚
โ””โ”€โ”€ addons/                     # Third-party plugins
    โ””โ”€โ”€ radial_menu/            # Radial menu addon

Gameplay Loop

  1. Start: Player begins with limited gold (default: 150)
  2. Planning Phase: Survey the map and plan tower positions
  3. Building: Click on valid grid tiles to place towers (costs 100 gold per tower)
  4. Defense: Towers automatically target and fire at enemies within range
  5. Wave Progression: Enemies spawn in increasingly difficult waves
    • Spawn rate accelerates over time
    • Enemy health scales up based on difficulty curves
  6. Economy: Earn gold by defeating enemies (15 gold per enemy)
  7. Base Defense: Protect your base from enemies attempting to deliver cargo
    • Base has limited health (default: 10 HP)
    • Each enemy that reaches the base deals 1 damage
  8. Victory/Defeat:
    • Victory: Survive until the difficulty timer expires and defeat all remaining enemies
    • Defeat: Base health reaches zero

A tower defense game built with Godot, playable directly in your browser!

๐ŸŽฎ How to Play

  • WASD or Arrow Keys: Move camera
  • Q/E: Rotate camera
  • Left Mouse Button: Place tower (when hovering over valid grid tile with sufficient gold)

Getting Started

Prerequisites

  • Godot Engine 4.5 or later (uses Forward Plus rendering)
  • Download from godotengine.org

Installation and Running

  1. Clone the repository:

    git clone https://github.com/chrisjcc/UTDG.git
    cd UTDG
    
  2. Open in Godot:

    • Launch Godot Engine
    • Click "Import"
    • Navigate to the cloned directory and select project.godot
    • Click "Import & Edit"
  3. Play the game:

    • Press F5 or click the "Play" button in the top-right corner
    • The game will launch with base_level.tscn as the main scene
  4. Test in the editor:

    • Open base_level.tscn from the FileSystem dock
    • Press F6 or click "Play Scene" to test the current scene

Building an Executable (Optional)

  1. Go to Project โ†’ Export
  2. Add your target platform (Windows, Linux, macOS, etc.)
  3. Configure export settings
  4. Click "Export Project" and choose a destination

Build Workflow Overview

The project includes an automated GitHub Actions workflow for building macOS releases:

Automated macOS Builds

The .github/workflows/build-macos.yml workflow automatically builds the game for macOS (Apple Silicon arm64) when you create a new version tag.

How it works:

  1. Trigger: Push a git tag matching v*.*.* (e.g., v1.0.0, v1.2.3)
  2. Process:
    • Downloads the official Godot 4.5.1 binary for macOS
    • Exports the game using the "macOS" preset from export_presets.cfg
    • Creates a complete .app bundle at builds/UTDG.app
    • Compresses the bundle into UTDG-macos.zip
  3. Output: The zipped artifact is uploaded to GitHub Actions artifacts for download

Creating a release:

# Tag your commit with a version number
git tag v1.0.0
git push origin v1.0.0

# The workflow will automatically run and build the macOS artifact

Downloading the build:

  1. Go to the repository's Actions tab
  2. Click on the latest workflow run for your tag
  3. Download the UTDG-macos artifact from the artifacts section
  4. Extract UTDG-macos.zip and run UTDG.app on macOS

Export Configuration

The export_presets.cfg file defines the export settings:

  • Platform: macOS (arm64 - Apple Silicon)
  • Bundle Identifier: com.chrisjcc.utdg
  • Minimum macOS Version: 10.13 (High Sierra)
  • Output Path: builds/UTDG.app

The workflow uses the --headless --export-release "macOS" command to build without requiring the Godot editor UI, making it suitable for CI/CD automation.

Game Architecture

Core Systems

Bank System (Base/bank.gd)

Manages the player's gold resources. Gold is earned by defeating enemies and spent on building towers.

Base (Base/base.gd)

Handles the player's base health with visual feedback. The game reloads when health reaches zero.

Difficulty Manager (DifficultyManager/difficulty_manager.gd)

Controls game progression using exportable curves:

  • spawn_time_curve: Controls how quickly enemies spawn
  • enemy_health_curve: Scales enemy health over time
  • game_length: Duration of the game in seconds (default: 30s)

Enemy System

  • Enemy AI (Enemy/enemy.gd): NavigationAgent3D-based pathfinding with cargo delivery mechanics
  • Enemy Manager (Enemy/enemy_manager.gd): Handles wave spawning and victory detection

Spawning Strategy System (SpawningStrategy/)

Provides a modular, configurable approach to enemy spawning:

  • SpawningStrategyManager (spawning_strategy_manager.gd): Coordinates spawning by delegating to selected strategy
  • Strategy Types:
    • Curve-Based (curve_based_strategy.gd): Original UTDG behavior using time curves
    • Wave-Based (wave_based_strategy.gd): Discrete waves with breaks between them
    • Timed (timed_strategy.gd): Fixed or variable interval spawning
  • Fully backward compatible with existing gameplay
  • Supports RL environment integration
  • See SpawningStrategy/README.md for detailed documentation

Tower System

  • TowerManager (Towers/tower_manager.gd): Instantiates towers and updates navigation mesh
  • Tower (Towers/tower.gd): Base tower class with automatic targeting and projectile firing
  • Towers find the nearest enemy within range and rotate to face them

Camera Controller (RayPickerCamera/ray_picker_camera.gd)

Handles player input for camera movement and tower placement using raycasting to detect valid grid positions.

Extending the Game

Adding a New Tower Type

  1. Create a new scene inheriting from Tower (Towers/tower.gd)
  2. Customize the exported variables:
    • projectile: Assign a projectile scene
    • tower_range: Set the detection radius
  3. Modify the appearance and add custom behavior as needed

Configuring Enemy Spawning Strategy

The game now supports multiple spawning strategies that can be configured without code changes:

  1. Add SpawningStrategyManager to your scene (optional - game works without it):

    • Instantiate SpawningStrategy/spawning_strategy_manager.tscn in your level
    • Set active_strategy_type to your desired strategy (CURVE_BASED, WAVE_BASED, or TIMED)
    • Assign difficulty_manager and enemy_manager references
    • Set the spawning_strategy_manager reference in your EnemyManager node
  2. Strategy types:

    • CURVE_BASED (default): Uses curves for smooth difficulty progression (original behavior)
    • WAVE_BASED: Spawns enemies in discrete waves with breaks
    • TIMED: Fixed or variable interval spawning for survival-style gameplay
  3. Configuration example (Wave-Based):

    • Initial wave size: 1-3 enemies
    • Wave size growth: 1.2 (20% increase per wave)
    • Wave break duration: 5 seconds
    • See SpawningStrategy/README.md for detailed configuration options

Adjusting Difficulty

Open base_level.tscn and select the DifficultyManager node:

  • Adjust game_length to change game duration
  • Edit spawn_time_curve to control enemy spawn rates
  • Modify enemy_health_curve to balance enemy strength progression

Or use the SpawningStrategyManager for more control over spawning patterns.

Creating New Enemy Types

  1. Extend Enemy class (Enemy/enemy.gd)
  2. Adjust exported properties:
    • speed: Movement speed
    • max_hitpoints: Starting health
    • gold_value: Reward for defeating the enemy
  3. Customize appearance and add special abilities

๐Ÿ”— Links

  • GitHub Repository: chrisjcc/utdg

  • Python Environment: Available as utdg-gym package for RL training

    ๐Ÿ› ๏ธ Technical Details

  • Engine: Godot 4.x

  • Version: v0.0.3

  • SDK: Docker (HTML5 game export)

For AI agent integration and training, check out the GitHub repository!

Contributing

Contributions are welcome! This project follows clean coding practices:

  • Use meaningful variable names
  • Export configuration values for easy tuning
  • Keep systems modular and loosely coupled
  • Document complex behaviors with comments

License

This project is provided as-is for educational and experimental purposes. Please check the repository for specific license information.

Acknowledgments

  • Built with Godot Engine
  • Uses the Radial Menu addon (included in addons/radial_menu/)

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utdg_env-0.2.2.tar.gz (59.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

utdg_env-0.2.2-py3-none-any.whl (69.9 kB view details)

Uploaded Python 3

File details

Details for the file utdg_env-0.2.2.tar.gz.

File metadata

  • Download URL: utdg_env-0.2.2.tar.gz
  • Upload date:
  • Size: 59.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for utdg_env-0.2.2.tar.gz
Algorithm Hash digest
SHA256 d918926f79579d1459a8419f0c6c291e5f1ec485fa7bf995865cc03e24d86f5e
MD5 e29b49cf06a454ecf140783172c81135
BLAKE2b-256 9a5caa2ed47e4cfc8a1c0ffec3633fbf7a86f55154194662c8f569d4b7e71ed0

See more details on using hashes here.

File details

Details for the file utdg_env-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: utdg_env-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 69.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for utdg_env-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0ecedf40db5a787a8f1202c009a37a47d6e859adcbbd67d55bd1878edfbf0cc0
MD5 7e352f4e5763308138036427935485a3
BLAKE2b-256 b25fb9c492c52310f5d5dee947260bc734399c417388d81118b36da0c5e27056

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page