Skip to content

About

Atomic SQL Game Engine, a Python-based framework for managing 3D spatial data in real-time applications such as games or simulations. The engine leverages a unique coordinate system backed by SQLite for persistence and querying, making it ideal for applications requiring durable storage and spatial analysis.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

ย 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

AtomicGameEngine v1.0.0 ๐ŸŽฎ

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. ๐Ÿš€

Table of Contents ๐Ÿ“œ

Atomic Game Engine Overview

Overview ๐ŸŒŸ

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

Project Structure ๐Ÿ“‚

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/.

Key Components ๐Ÿ”ง

  • 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 with value: 10). ๐Ÿ“‹
  • APISummarizer: Generates summaries of the projectโ€™s API for documentation. ๐Ÿ“

Setup Instructions โš™๏ธ

  1. Clone the Repository ๐Ÿ“ฅ:

    git clone https://github.com/username/AtomicGameEngine.git
    cd AtomicGameEngine
  2. Install Dependencies ๐Ÿ› ๏ธ: Ensure Python 3.8+ is installed. Install required packages:

    pip install -r requirements.txt

    โ„น๏ธ Note: Create a requirements.txt with dependencies like pygame>=2.5.2, sqlite3 (built-in with Python), etc., if not already present.

  3. Run the Demo ๐ŸŽ‰: Launch the game demo:

    python gamedemo.py
  4. Run Tests โœ…: Execute the test suite:

    python -m unittest discover Tests

Testing โœ…

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 Tests

API Reference ๐Ÿ“š

Below is a summary of the key classes and their methods to help developers integrate AtomicGameEngine into their applications.

JsonConfigManager ๐Ÿ“‹

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). Raises FileNotFoundError if the file is missing or ValueError if 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'])

APISummarizer ๐Ÿ“

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

Config โš™๏ธ

Handles configuration settings for the game engine.

  • Constructor:
    Config()
    Initializes configuration settings.

CoordinateSystemPersistence ๐Ÿ’พ

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

HexUtils ๐Ÿ”ข

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

CombatSystem โš”๏ธ

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

Unit ๐Ÿ‘ท

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

Entity ๐Ÿง‘

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

Pathfinding ๐Ÿ›ค๏ธ

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

CodeEnumerator ๐Ÿ”Ž

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

CoordinateSystemDML ๐Ÿ”

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

ResourceType ๐Ÿช™

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

Game ๐ŸŽฎ

Main game class for demo.

  • Constructor:

    Game()

    Initializes the game.

  • Methods:

    end_turn()  # Ends current turn

City ๐Ÿฐ

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

CoordinateSystem ๐Ÿ—บ๏ธ

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

HexMap ๐ŸŒ

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

TerrainType โ›ฐ๏ธ

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

Contributing ๐Ÿค

Contributions are welcome! ๐ŸŽ‰ Please follow these steps:

  1. Fork the repository. ๐Ÿด
  2. Create a feature branch (git checkout -b feature-name). ๐ŸŒฟ
  3. Commit changes (git commit -m "Add feature"). ๐Ÿ’พ
  4. Push to the branch (git push origin feature-name). ๐Ÿš€
  5. Open a pull request. ๐Ÿ“ฌ

License ๐Ÿ“

This project is licensed under the MIT License. See the LICENSE file for details. โœ…

About

Atomic SQL Game Engine, a Python-based framework for managing 3D spatial data in real-time applications such as games or simulations. The engine leverages a unique coordinate system backed by SQLite for persistence and querying, making it ideal for applications requiring durable storage and spatial analysis.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages