AtomicGameEngine is a Python-based game engine for creating hexagonal grid-based strategy games. It provides a robust framework for managing game entities, combat, pathfinding, and coordinate systems with persistence. ๐
- Overview ๐
- Project Structure ๐
- Key Components ๐ง
- Setup Instructions โ๏ธ
- Testing โ
- API Reference ๐
- Contributing ๐ค
- License ๐
AtomicGameEngine is designed to facilitate the development of turn-based strategy games with a focus on hexagonal grid systems. It includes features such as:
- ๐บ๏ธ Hexagonal coordinate system management
- ๐ฅ Entity and unit management
- โ๏ธ Combat system with status effects
- ๐ค๏ธ Pathfinding using A* algorithm
- ๐พ Persistence layer for saving game states
- โฐ๏ธ Terrain and resource management
- ๐ API summarization for code documentation
The project includes a root directory with Python files, configuration files, and nested directories for tests, documentation, and assets:
AtomicGameEngine/
|-- APISummarizer.py # ๐ Summarizes project APIs
|-- City.py # ๐ฐ City entity management
|-- CombatSystem.py # โ๏ธ Handles combat mechanics
|-- Config.py # โ๏ธ Configuration settings
|-- CoordinateSystem.py # ๐บ๏ธ Manages hex grid coordinates
|-- CoordinateSystemDML.py # ๐ Data manipulation for coordinates
|-- CoordinateSystemInfo.md # ๐ Coordinate system documentation
|-- CoordinateSystemPersistence.py # ๐พ Persists coordinate data
|-- CoordinateSystemVersion.md # ๐ Version info for coordinate system
|-- CodeEnumerator.py # ๐ Codebase analysis tool
|-- Entity.py # ๐ง Base entity class
|-- gamedemo.py # ๐ฎ Game demo implementation
|-- HexMap.py # ๐ Hex map generation and management
|-- HexUtils.py # ๐ข Hex grid utilities
|-- JsonConfigManager.py # ๐ Manages JSON configuration data
|-- Pathfinding.py # ๐ค๏ธ A* pathfinding implementation
|-- ResourceType.py # ๐ช Resource type definitions
|-- terrain_config.json # โฐ๏ธ Terrain configuration file
|-- resource_config.json # ๐ช Resource configuration file
|-- TerrainType.py # โฐ๏ธ Terrain type definitions
|-- Unit.py # ๐ท Unit entity management
|-- Tests/ # โ
Test suites
| |-- TestCoordinateSystem.py
| |-- TestCoordinateSystemDML.py
| |-- TestCoordinateSystemPersistence.py
| |-- TestEntity.py
| |-- Unit_test_CombatSystem.py
|-- Addendum/ # ๐ Additional documentation
|-- assets/ # ๐จ Game assets
|-- images/ # ๐ผ๏ธ Image resources
Note: Total files: 29 (25 Python, 2 Markdown, 2 JSON). New file JsonConfigManager.py enhances configuration management, alongside APISummarizer.py and CodeEnumerator.py. Test files are in Tests/, documentation in Addendum/, and images in assets/images/.
- CoordinateSystem: Manages entities and static geometry on a hexagonal grid, supporting up to 1000x1000 hexes with axial coordinates (q, r). ๐บ๏ธ
- HexUtils: Provides utilities for converting between hex and cartesian coordinates, and rendering hex-based visuals. ๐ข
- CombatSystem: Handles combat mechanics, including health, attack, defense, and status effects. โ๏ธ
- Pathfinding: Implements A* algorithm for efficient pathfinding on hex grids. ๐ค๏ธ
- CoordinateSystemPersistence: Saves and loads game state to/from a database, supporting up to 10,000 entities by default. ๐พ
- Entity/Unit/City: Core classes for game objects with position and behavior management. ๐ฅ๐ฐ
- HexMap: Generates and manages the game world map with terrain rules, defaulting to 100x100 hexes. ๐
- JsonConfigManager: Loads and validates JSON configuration data, such as 5 terrain types (e.g., desert with
move_cost: 2) and 3 resource types (e.g., wood withvalue: 10). ๐ - APISummarizer: Generates summaries of the projectโs API for documentation. ๐
-
Clone the Repository ๐ฅ:
git clone https://github.com/username/AtomicGameEngine.git cd AtomicGameEngine -
Install Dependencies ๐ ๏ธ: Ensure Python 3.8+ is installed. Install required packages:
pip install -r requirements.txt
โน๏ธ Note: Create a
requirements.txtwith dependencies likepygame>=2.5.2,sqlite3(built-in with Python), etc., if not already present. -
Run the Demo ๐: Launch the game demo:
python gamedemo.py
-
Run Tests โ : Execute the test suite:
python -m unittest discover Tests
The project includes 5 unit test files in the Tests/ directory, covering approximately 50 test cases (estimated). Key test files include:
TestCoordinateSystem.py: Tests coordinate system functionality. ๐บ๏ธTestCoordinateSystemPersistence.py: Tests persistence layer. ๐พUnit_test_CombatSystem.py: Tests combat mechanics. โ๏ธTestEntity.py: Tests entity behaviors. ๐ฅTestCoordinateSystemDML.py: Tests data manipulation layer. ๐
Run tests using:
python -m unittest discover TestsBelow is a summary of the key classes and their methods to help developers integrate AtomicGameEngine into their applications.
Manages JSON configuration data, such as 5 terrain types (e.g., desert with move_cost: 2) and 3 resource types (e.g., wood with value: 10), with validation for numerical fields.
-
Constructor:
JsonConfigManager(config_path)
Initializes with path to JSON config file (e.g.,
terrain_config.json). RaisesFileNotFoundErrorif the file is missing orValueErrorif not JSON. -
Methods:
load_config() # Loads and returns JSON data as a dictionary (up to 1MB) validate_config(schema) # Validates JSON against a schema (e.g., move_cost > 0, color list length 3) get_config(key) # Retrieves config data for a key (e.g., 'desert') get_all_keys() # Returns list of all top-level keys (e.g., ['desert', 'swamp', 'forest', 'mountain', 'plains'])
Manages API summarization for project documentation.
-
Constructor:
APISummarizer(root, output_file)
Initializes with the root directory and output file path.
-
Methods:
summarize() # Generates API summary _generate_tree() # Builds project directory tree _summarize_python_files() # Summarizes Python files _summarize_ast(path, node) # Analyzes AST for a file _format_function_signature(func) # Formats function signatures _write_output(tree, summary) # Writes summary to output file
Handles configuration settings for the game engine.
- Constructor:
Initializes configuration settings.
Config()
Persists coordinate system data to a database, supporting up to 10,000 entities by default.
-
Constructor:
CoordinateSystemPersistence(db_name)
Initializes with database name.
-
Methods:
init_tables() # Creates database tables save_coordinate_system(cs) # Saves coordinate system state load_coordinate_system() # Loads coordinate system state
Provides utilities for hexagonal grid operations.
- Methods (static):
hex_to_cartesian(q, r, size) # Converts hex to cartesian coordinates cartesian_to_hex(x, y, size) # Converts cartesian to hex coordinates hex_to_pixel(pos, offset) # Converts hex to pixel coordinates pixel_to_hex(x, y, size, offset) # Converts pixel to hex coordinates get_hex_vertices(q, r, size) # Returns vertices for a hex draw_hex(surface, pos, size, terrain, offset) # Draws a hex tile draw_unit(surface, pos, size, unit, offset) # Draws a unit draw_city(surface, pos, size, city, offset) # Draws a city draw_resource(surface, pos, size, resource, offset) # Draws a resource
Manages combat mechanics and status effects, with a default attack range of 3 hexes.
-
Constructor:
CombatSystem(cs, dml, persistence)
Initializes with coordinate system, data manipulation layer, and persistence.
-
Methods:
init_combat_table() # Initializes combat database table update_combat_attributes(entity_id, health, attack_power, defense, status_effects) # Updates combat attributes get_combat_attributes(entity_id) # Retrieves combat attributes find_targets_in_range(attacker_id, attack_range) # Finds targets within range (default: 3 hexes) resolve_combat(attacker_id, defender_id) # Resolves combat outcome initiate_combat(attacker_id, target_id) # Starts combat apply_status_effect(entity_id, effect, duration) # Applies status effect update_status_effects(entity_id) # Updates active status effects
Represents a game unit with position and behavior.
-
Constructor:
Unit(entity_id, position, cs, dml, persistence, name)
Initializes with entity ID, position, coordinate system, data manipulation layer, persistence, and name.
-
Methods:
update() # Updates unit state
Base class for game entities.
-
Constructor:
Entity(entity_id, position, coordinate_system, dml, persistence)
Initializes with entity ID, position, coordinate system, data manipulation layer, and persistence.
-
Methods:
entity_id() # Returns entity ID position() # Returns current position update_position(new_position) # Updates entity position remove() # Removes entity get_nearby_entities(min_coords, max_coords) # Lists nearby entities find_nearest_entity(type_prefix) # Finds nearest entity by type is_near_geometry(category, max_distance) # Checks proximity to geometry save_state() # Saves entity state update() # Updates entity state __str__() # Returns string representation
Implements A* pathfinding for hex grids.
- Methods (static):
hex_distance(a, b) # Calculates hex distance get_neighbors(pos, cs, dml) # Returns neighboring hexes a_star(start, goal, cs, dml) # Computes A* path
Analyzes codebase for documentation.
-
Constructor:
CodeEnumerator(root_dir, additional_types)
Initializes with root directory and additional types.
-
Methods:
_load_gitignore() # Loads gitignore patterns _is_ignored(path) # Checks if path is ignored get_relevant_files(filter_string) # Returns relevant files build_tree() # Builds directory tree print_tree(node, indent) # Prints directory tree get_code_blocks() # Extracts code blocks generate_output() # Generates output
Handles data manipulation for coordinate systems.
-
Constructor:
CoordinateSystemDML(conn)
Initializes with database connection.
-
Methods:
count_entities(type_prefix) # Counts entities by type list_entities_in_bounding_box(min_coords, max_coords) # Lists entities in area find_nearest_entity(point, type_prefix, max_distance) # Finds nearest entity list_geometry_by_category(category) # Lists geometry by category is_entity_near_geometry(entity_id, category, max_distance) # Checks proximity
Manages resource type definitions, using JsonConfigManager for 3 default types (e.g., wood with value: 10).
- Methods (static):
load_config(config_path) # Loads resource config via JsonConfigManager init_sprites() # Initializes resource sprites
Main game class for demo.
-
Constructor:
Game()Initializes the game.
-
Methods:
end_turn() # Ends current turn
Represents a city entity.
-
Constructor:
City(entity_id, position, cs, dml, persistence, name)
Initializes with entity ID, position, coordinate system, data manipulation layer, persistence, and name.
-
Methods:
update() # Updates city state
Manages entities and geometry on a hex grid, supporting up to 1000x1000 hexes.
-
Constructor:
CoordinateSystem()Initializes the coordinate system.
-
Methods:
add_entity(entity_id, position) # Adds an entity remove_entity(entity_id) # Removes an entity update_entity_position(entity_id, new_position) # Updates entity position get_entity_position(entity_id) # Returns entity position get_all_entity_positions() # Returns all entity positions add_static_polygon(geometry_id, vertices, category) # Adds static geometry get_static_geometry(geometry_id) # Returns geometry list_static_geometry_by_category(category) # Lists geometry by category list_all_static_geometry() # Lists all geometry
Generates and manages hex-based game maps, defaulting to 100x100 hexes.
-
Constructor:
HexMap(width, height, cs, persistence)
Initializes with map width, height, coordinate system, and persistence.
-
Methods:
get_neighbors(q, r) # Returns neighboring hexes apply_terrain_rules(q, r, terrain) # Applies terrain rules generate_map() # Generates the map
Manages terrain type definitions, using JsonConfigManager for 5 default types (e.g., desert with move_cost: 2).
- Methods (static):
load_config(config_path) # Loads terrain config via JsonConfigManager init_sprites() # Initializes terrain sprites
Contributions are welcome! ๐ Please follow these steps:
- Fork the repository. ๐ด
- Create a feature branch (
git checkout -b feature-name). ๐ฟ - Commit changes (
git commit -m "Add feature"). ๐พ - Push to the branch (
git push origin feature-name). ๐ - Open a pull request. ๐ฌ
This project is licensed under the MIT License. See the LICENSE file for details. โ
