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
- Start: Player begins with limited gold (default: 150)
- Planning Phase: Survey the map and plan tower positions
- Building: Click on valid grid tiles to place towers (costs 100 gold per tower)
- Defense: Towers automatically target and fire at enemies within range
- Wave Progression: Enemies spawn in increasingly difficult waves
- Spawn rate accelerates over time
- Enemy health scales up based on difficulty curves
- Economy: Earn gold by defeating enemies (15 gold per enemy)
- 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
- 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
-
Clone the repository:
git clone https://github.com/chrisjcc/UTDG.git cd UTDG
-
Open in Godot:
- Launch Godot Engine
- Click "Import"
- Navigate to the cloned directory and select
project.godot - Click "Import & Edit"
-
Play the game:
- Press F5 or click the "Play" button in the top-right corner
- The game will launch with
base_level.tscnas the main scene
-
Test in the editor:
- Open
base_level.tscnfrom the FileSystem dock - Press F6 or click "Play Scene" to test the current scene
- Open
Building an Executable (Optional)
- Go to Project โ Export
- Add your target platform (Windows, Linux, macOS, etc.)
- Configure export settings
- 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:
- Trigger: Push a git tag matching
v*.*.*(e.g.,v1.0.0,v1.2.3) - 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
.appbundle atbuilds/UTDG.app - Compresses the bundle into
UTDG-macos.zip
- 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:
- Go to the repository's Actions tab
- Click on the latest workflow run for your tag
- Download the
UTDG-macosartifact from the artifacts section - Extract
UTDG-macos.zipand runUTDG.appon 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 spawnenemy_health_curve: Scales enemy health over timegame_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
- Curve-Based (
- Fully backward compatible with existing gameplay
- Supports RL environment integration
- See
SpawningStrategy/README.mdfor 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
- Create a new scene inheriting from
Tower(Towers/tower.gd) - Customize the exported variables:
projectile: Assign a projectile scenetower_range: Set the detection radius
- 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:
-
Add SpawningStrategyManager to your scene (optional - game works without it):
- Instantiate
SpawningStrategy/spawning_strategy_manager.tscnin your level - Set
active_strategy_typeto your desired strategy (CURVE_BASED, WAVE_BASED, or TIMED) - Assign
difficulty_managerandenemy_managerreferences - Set the
spawning_strategy_managerreference in your EnemyManager node
- Instantiate
-
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
-
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.mdfor detailed configuration options
Adjusting Difficulty
Open base_level.tscn and select the DifficultyManager node:
- Adjust
game_lengthto change game duration - Edit
spawn_time_curveto control enemy spawn rates - Modify
enemy_health_curveto balance enemy strength progression
Or use the SpawningStrategyManager for more control over spawning patterns.
Creating New Enemy Types
- Extend
Enemyclass (Enemy/enemy.gd) - Adjust exported properties:
speed: Movement speedmax_hitpoints: Starting healthgold_value: Reward for defeating the enemy
- Customize appearance and add special abilities
๐ Links
-
GitHub Repository: chrisjcc/utdg
-
Python Environment: Available as
utdg-gympackage 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file utdg_env-0.3.2.tar.gz.
File metadata
- Download URL: utdg_env-0.3.2.tar.gz
- Upload date:
- Size: 60.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
829c403196b502631af152641c1ecb99cce054c3a7af47747232846a49e0ab6d
|
|
| MD5 |
6cdfb598e2eda9cf268da41be2b94d91
|
|
| BLAKE2b-256 |
ba34765353cf6785efc4af72ddf7e4aced095a82e0e7458860d7638916a8e589
|
File details
Details for the file utdg_env-0.3.2-py3-none-any.whl.
File metadata
- Download URL: utdg_env-0.3.2-py3-none-any.whl
- Upload date:
- Size: 70.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc0f906e7b96c62c7f25f641ad8035541a66432915c320965c978d571895ff9b
|
|
| MD5 |
77db5e8f4b4b57b474a3ef0754a110fb
|
|
| BLAKE2b-256 |
9c7fa85a8b4d94fca7159354a7e0b26a902bcde7bac443779d33b2d66cc4435e
|