A real-time strategy game with vector-based graphics inspired by classic games like Asteroids and StarCraft 2.
- Vector-based graphics for all game elements
- Resource gathering with worker units (squares)
- Base building and unit production
- Multiple unit types with different abilities:
- Workers (squares): Gather resources and build structures
- Fast units (dots/circles): Quick melee attackers
- Heavy units (triangles): Slower ranged attackers with higher damage
- Building types:
- Command Center: Main building, collects resources, produces workers
- Unit Buildings: Produces combat units (dots and triangles)
- Physics-based movement with unit-specific properties
- Standardized, physics-based movement across all behaviors
- Collision detection and realistic unit interactions
- Formation movement for unit groups
- Enemy AI with resource gathering and combat behavior
- Debug visualization features
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the game:
python main.py
- Left-click to select units or buildings
- Right-click to:
- Move selected units to a location
- Gather resources (when clicking on a mineral patch with workers)
- Attack enemy units or buildings (when clicking on enemies with combat units)
- Set rally points (when clicking with a building selected)
- Drag with left mouse button to select multiple units
- B: Enter build mode to construct a Unit Building (requires 150 resources)
- A: Toggle attack-move mode (units will attack enemies encountered on their way)
- P: Toggle patrol mode for combat units (units will patrol between current position and clicked location)
- H: Order selected units to hold position (will attack enemies in range without moving)
- S: Stop all selected units (change to idle behavior)
- D: Toggle debug visualization (shows slots, paths, and collision info)
- Escape: Cancel current build/attack mode
- Implemented unified movement logic across all unit behaviors
- Added physics-based movement with momentum, inertia, and deceleration
- Created unit-specific physics properties for distinctive movement styles
- Fixed oscillation and jittering issues at movement destinations
- Optimized resource gathering with improved collision handling
- Enhanced patrol mode with dedicated 'P' key and visual indicator
- Fixed the patrol feature to work properly with combat units
- Improved selection box rendering for better unit selection
- Updated renderer to handle delta time for animations
- Fixed issues with coordinate systems in the UI
- Enhanced combat behavior to properly detect and attack enemies during patrol
The goal is to build an army and destroy the enemy command center. Start by gathering minerals using "square" worker units, then build a unit production facility to create combat units (dots and triangles). Use these combat units to attack and destroy the enemy base.
The game is structured using the following main components:
main.py
: Entry point that initializes the game and runs the main loopgame.py
: Main game class that manages game state, entities, and user inputentities.py
: Entity classes for units, buildings, and resourcesbehaviors.py
: Behavior classes that implement unit AI (movement, gathering, attacking)renderer.py
: Handles rendering game elementsutils.py
: Utility functions and constantsconfig.py
: Centralized configuration for all game parameters
Entity
: Base class for all game objectsUnit
: Base class for all movable unitsSquare
: Worker unit (gathers resources)Dot
: Fast melee combat unitTriangle
: Slower ranged combat unit
Building
: Base class for structuresCommandCenter
: Main building, produces workersUnitBuilding
: Produces combat units
Resource
: Mineral patches for gathering
Units use a behavior-based AI system where each unit can have one active behavior:
Behavior
: Base class with standardized movement method used by all behaviorsIdleBehavior
: Default when not doing anythingMoveBehavior
: Moving to a position with physics-based momentumGatherBehavior
: Gathering resources (moving, harvesting, returning, depositing)AttackBehavior
: Attacking a targetHoldPositionBehavior
: Staying in place but attacking enemies in rangeAttackMoveBehavior
: Moving to a position while attacking enemies encounteredPatrolBehavior
: Patrolling between two points and attacking enemies in range
The game uses a physics-based movement system:
_standardized_move_toward
: Common movement method in the base Behavior class- Each unit type has custom physics properties:
- Mass: Controls momentum and collision response
- Friction: Affects how quickly units slow down
- Restitution: Controls bouncing during collisions
- Steering Force: Influences turning ability and acceleration
- The game uses simple vector graphics for efficient rendering
- Collision detection uses rectangles and spatial partitioning
- Formation movement with steering behaviors for smooth unit movement
- Error handling for robustness during extended gameplay
- Physics optimizations with delta time clamping and velocity cutoff
-
Unit Mass: Controls momentum and collision impact
- Square (Worker): 1.3x size
- Dot (Melee): 1.4x size
- Triangle (Ranged): 3.0x size
-
Friction: Higher values stop faster
- Square: 0.96
- Dot: 0.95
- Triangle: 0.97
-
Target Reached Thresholds: Distance at which to consider target reached
- Square: 25.0
- Dot: 35.0
- Triangle: 45.0
_standardized_move_toward
: The core movement method that all behaviors use- Inside an arrival threshold, units will gradually slow down
- Deceleration is smooth and proportional to distance from target
- If window loses focus, physics may behave erratically (added dt clamping to mitigate)
- Large groups of units may slow down the game due to collision calculations
- Very large maps might require spatial partitioning optimization
Potential features for future development:
- Additional unit types with unique abilities
- Technology upgrades and research system
- Multiple resource types
- Larger maps with terrain features
- Improved pathfinding using A* algorithm
- Fog of war system
- Multiplayer support
- Map editor
Contributions are welcome! Here are some guidelines:
- Fork the repository
- Create a feature branch
- Add your changes
- Ensure all game features still work
- Submit a pull request