πŸ—οΈ Arquitectura del Juego πŸ—οΈ Game Architecture

DiseΓ±o modular y patrones de arquitectura para un cΓ³digo mantenible Modular design and architecture patterns for maintainable code

VisiΓ³n General de la Arquitectura Architecture Overview

El juego sigue una arquitectura modular basada en managers que separa las responsabilidades y promueve la mantenibilidad. El sistema estΓ‘ construido alrededor del concepto de managers especializados que manejan diferentes aspectos del juego. The game follows a modular manager-based architecture that separates responsibilities and promotes maintainability. The system is built around the concept of specialized managers that handle different aspects of the game.

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Game Manager  │────│  State Manager  │────│ Tutorial Managerβ”‚
β”‚   (Coordinador) β”‚    β”‚   (Flujo Juego) β”‚    β”‚   (Aprendizaje) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Entity Manager  β”‚    β”‚Collision Managerβ”‚    β”‚   UI Manager    β”‚
β”‚   (Entidades)   β”‚    β”‚    (FΓ­sica)     β”‚    β”‚  (Interfaz)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                       β”‚                       β”‚
         β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Level Manager  β”‚    β”‚ Firebase Managerβ”‚    β”‚  Sound Manager  β”‚
β”‚    (Niveles)    β”‚    β”‚  (Datos Nube)   β”‚    β”‚     (Audio)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Componentes Principales Main Components

1. Game Manager (src/game/game_manager.py) 1. Game Manager (src/game/game_manager.py)

PropΓ³sito: Coordinador central que orquesta todos los sistemas del juego. Purpose: Central coordinator that orchestrates all game systems.

Responsabilidades: Responsibilities:

def run(self):
    """Bucle principal del juego""""""Main game loop"""
    while self.running:
        self.handle_events()
        self.update()
        self.render()
        self.clock.tick(self.config.FPS)

def handle_events(self):
    """Delega eventos a los managers apropiados""""""Delegates events to appropriate managers"""
    
def update(self):
    """Actualiza todos los sistemas del juego""""""Updates all game systems"""
    
def render(self):
    """Renderiza todos los elementos visuales""""""Renders all visual elements"""

2. Entity Manager (src/managers/entity_manager.py) 2. Entity Manager (src/managers/entity_manager.py)

PropΓ³sito: Gestiona todas las entidades del juego (jugador, enemigos, coleccionables, proyectiles). Purpose: Manages all game entities (player, enemies, collectibles, projectiles).

Responsabilidades: Responsibilities:

class EntityManager:
    def __init__(self, config):
        self.player = None
        self.enemies = []
        self.collectibles = []
        self.projectiles = []
        
        # Control de spawn# Spawn control
        self.spawn_timer = 0
        self.monster_spawn_timer = 0
        self.monsters_spawned = 0

3. Game State Manager (src/managers/game_state_manager.py) 3. Game State Manager (src/managers/game_state_manager.py)

PropΓ³sito: Gestiona los estados del juego y las transiciones. Purpose: Manages game states and transitions.

Estados: States:

def set_state(self, new_state):
    """TransiciΓ³n segura de estado con validaciΓ³n""""""Safe state transition with validation"""
    
def is_playing(self):
    """Verifica si estΓ‘ en estados de gameplay activo""""""Checks if in active gameplay states"""
    return self.state in ["PLAYING", "TUTORIAL"]

Sistema de Entidades Entity System

JerarquΓ­a de Entidades Entity Hierarchy

Entity (Base)
β”œβ”€β”€ Player
β”‚   β”œβ”€β”€ Sistema de Movimiento
β”‚   β”œβ”€β”€ Sistema de AnimaciΓ³n
β”‚   └── Sistema de Inventario
β”œβ”€β”€ Enemy
β”‚   β”œβ”€β”€ Barrel (Dirigido por IA)
β”‚   └── Monster (MΓ‘quina de estados)
β”œβ”€β”€ Collectible
β”‚   └── Star (Valores de puntos: 10, 20, 50)
└── Projectile
    └── Banana (Explosivo)Entity (Base)
β”œβ”€β”€ Player
β”‚   β”œβ”€β”€ Movement System
β”‚   β”œβ”€β”€ Animation System
β”‚   └── Inventory System
β”œβ”€β”€ Enemy
β”‚   β”œβ”€β”€ Barrel (AI-driven)
β”‚   └── Monster (State machine)
β”œβ”€β”€ Collectible
β”‚   └── Star (Point values: 10, 20, 50)
└── Projectile
    └── Banana (Explosive)

Sistema del Jugador (src/entities/player.py) Player System (src/entities/player.py)

CaracterΓ­sticas: Features:

def update_animation(self):
    """Maneja la animaciΓ³n de sprites basada en el estado""""""Handles sprite animation based on state"""
    if not self.on_ground and self.sprites['jump']:
        # Reproduce secuencia de animaciΓ³n de salto# Play jump animation sequence
        if not self.is_jumping_animation:
            self.is_jumping_animation = True
            self.jump_frame = 0

Arquitectura de IA AI Architecture

Sistema de IA HΓ­brido Hybrid AI System

El juego implementa un sofisticado sistema de IA que combina mΓΊltiples enfoques: The game implements a sophisticated AI system that combines multiple approaches:

  1. Capa de DecisiΓ³n Primaria: LΓ³gica basada en reglas para comportamiento confiable Primary Decision Layer: Rule-based logic for reliable behavior
  2. Capa de ValidaciΓ³n: Q-Learning para refinamiento de comportamiento Validation Layer: Q-Learning for behavior refinement
  3. Capa de Seguridad: Mecanismos anti-atasco y de respaldo Safety Layer: Anti-stuck and fallback mechanisms
def barrel_movement(self, platforms, player_rect=None):
    # 1. DecisiΓ³n primaria basada en reglas# 1. Primary rule-based decision
    primary_action = self.decide_primary_action(dx, dy, current_platform, player_platform)
    
    # 2. ValidaciΓ³n Q-Learning# 2. Q-Learning validation
    if hasattr(self, 'ai_agent'):
        q_action = self.ai_agent.choose_action(state)
        if self.should_override_action(primary_action, q_action, dx, dy):
            primary_action = q_action
    
    # 3. Ejecutar decisiΓ³n# 3. Execute decision
    self.execute_action_decision(primary_action, current_platform, dx)

GestiΓ³n de Datos Data Management

IntegraciΓ³n con Firebase (src/managers/firebase_manager.py) Firebase Integration (src/managers/firebase_manager.py)

Servicios Utilizados: Services Used:

ConclusiΓ³n Conclusion

Esta arquitectura proporciona una base sΓ³lida para un juego mantenible, extensible y de alto rendimiento, manteniendo una separaciΓ³n limpia de responsabilidades y un manejo robusto de errores. El patrΓ³n de managers permite una fΓ‘cil extensiΓ³n y modificaciΓ³n de funcionalidades sin afectar otros sistemas. This architecture provides a solid foundation for a maintainable, extensible, and high-performance game, maintaining clean separation of concerns and robust error handling. The manager pattern allows for easy extension and modification of functionality without affecting other systems.