ae5cc1cfb4
Tots els tipus d'entitat passen del catala a l'angles seguint el
.clang-tidy del projecte (tipus en CamelCase, metodes en camelBack,
membres en lower_case amb sufix _).
Renames de tipus:
- Entitat -> Entity (core/entities/entity.hpp)
- Nau -> Ship (game/entities/ship.{hpp,cpp})
- Enemic -> Enemy (game/entities/enemy.{hpp,cpp})
- Bala -> Bullet (game/entities/bullet.{hpp,cpp})
- TipusEnemic -> EnemyType
- AnimacioEnemic -> EnemyAnimation
Metodes virtuals (s'aplica a tot el codi, no nomes a entitats):
- actualitzar -> update
- dibuixar -> draw
- inicialitzar -> init
- processar_input -> processInput
- esta_actiu -> isActive
- es_collidable -> isCollidable
- get_collision_radius -> getCollisionRadius
Getters comuns:
- get_centre -> getCenter
- get_angle -> getAngle
- get_brightness -> getBrightness
- get_forma -> getShape
Metodes especifics:
- esta_viva -> isAlive
- esta_tocada -> isHit
- es_invulnerable -> isInvulnerable
- get_velocitat_vector -> getVelocityVector
- set_centre -> setCenter
- marcar_tocada -> markHit
- aplicar_fisica -> applyPhysics
- get_tipus -> getType
Camps privats:
- centre_ -> center_
- velocitat_ -> velocity_
- forma_ -> shape_
- esta_tocada_ -> is_hit_
- tipus_ -> type_
L'import d'audio/input d'AEEA quedara coherent (mateix estil).
Diff net: 30 fitxers, +437/-437 (la majoria es renames simetrics).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
113 lines
5.1 KiB
C++
113 lines
5.1 KiB
C++
// escena_joc.hpp - Lògica principal del joc
|
|
// © 1999 Visente i Sergi (versió Pascal)
|
|
// © 2025 Port a C++20 amb SDL3
|
|
|
|
#ifndef ESCENA_JOC_HPP
|
|
#define ESCENA_JOC_HPP
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "core/graphics/vector_text.hpp"
|
|
#include "core/rendering/sdl_manager.hpp"
|
|
#include "core/system/context_escenes.hpp"
|
|
#include "core/system/game_config.hpp"
|
|
#include "core/types.hpp"
|
|
#include "game/constants.hpp"
|
|
#include "game/effects/debris_manager.hpp"
|
|
#include "game/effects/gestor_puntuacio_flotant.hpp"
|
|
#include "game/entities/bullet.hpp"
|
|
#include "game/entities/enemy.hpp"
|
|
#include "game/entities/ship.hpp"
|
|
#include "game/stage_system/stage_config.hpp"
|
|
#include "game/stage_system/stage_manager.hpp"
|
|
|
|
// Game over state machine
|
|
enum class EstatGameOver {
|
|
NONE, // Normal gameplay
|
|
CONTINUE, // Continue countdown screen (9→0)
|
|
GAME_OVER // Final game over (returning to title)
|
|
};
|
|
|
|
// Classe principal del joc (escena)
|
|
class EscenaJoc {
|
|
public:
|
|
explicit EscenaJoc(SDLManager& sdl, GestorEscenes::ContextEscenes& context);
|
|
~EscenaJoc() = default;
|
|
|
|
void executar(); // Bucle principal de l'escena
|
|
void init();
|
|
void update(float delta_time);
|
|
void draw();
|
|
|
|
private:
|
|
SDLManager& sdl_;
|
|
GestorEscenes::ContextEscenes& context_;
|
|
GameConfig::ConfigPartida config_partida_; // Configuració de jugadors actius
|
|
|
|
// Efectes visuals
|
|
Effects::DebrisManager debris_manager_;
|
|
Effects::GestorPuntuacioFlotant gestor_puntuacio_;
|
|
|
|
// Estat del joc
|
|
std::array<Ship, 2> naus_; // [0]=P1, [1]=P2
|
|
std::array<Enemy, Constants::MAX_ORNIS> orni_;
|
|
std::array<Bullet, Constants::MAX_BALES * 2> bales_; // 6 balas: P1=[0,1,2], P2=[3,4,5]
|
|
std::array<float, 2> itocado_per_jugador_; // Death timers per player (seconds)
|
|
|
|
// Lives and game over system
|
|
std::array<int, 2> vides_per_jugador_; // [0]=P1, [1]=P2
|
|
EstatGameOver estat_game_over_; // Game over state machine (NONE, CONTINUE, GAME_OVER)
|
|
int continue_counter_; // Continue countdown (9→0)
|
|
float continue_tick_timer_; // Timer for countdown tick (1.0s)
|
|
int continues_usados_; // Continues used this game (0-3 max)
|
|
float game_over_timer_; // Final GAME OVER timer before title screen
|
|
Vec2 punt_mort_; // Death position (for respawn)
|
|
std::array<int, 2> puntuacio_per_jugador_; // [0]=P1, [1]=P2
|
|
|
|
// Text vectorial
|
|
Graphics::VectorText text_;
|
|
|
|
// [NEW] Stage system
|
|
std::unique_ptr<StageSystem::ConfigSistemaStages> stage_config_;
|
|
std::unique_ptr<StageSystem::StageManager> stage_manager_;
|
|
|
|
// Control de sons d'animació INIT_HUD
|
|
bool init_hud_rect_sound_played_; // Flag para evitar repetir sonido del rectángulo
|
|
|
|
// Funcions privades
|
|
void tocado(uint8_t player_id);
|
|
void detectar_col·lisions_bales_enemics(); // Col·lisions bala-enemic
|
|
void detectar_col·lisio_naus_enemics(); // Ship-enemy collision detection (plural)
|
|
void detectar_col·lisions_bales_jugadors(); // Bullet-player collision detection (friendly fire)
|
|
void dibuixar_marges() const; // Dibuixar vores de la zona de joc
|
|
void dibuixar_marcador(); // Dibuixar marcador de puntuació
|
|
void disparar_bala(uint8_t player_id); // Shoot bullet from player
|
|
[[nodiscard]] Vec2 obtenir_punt_spawn(uint8_t player_id) const; // Get spawn position for player
|
|
|
|
// [NEW] Continue & Join system
|
|
void unir_jugador(uint8_t player_id); // Join inactive player mid-game
|
|
void processar_input_continue(); // Handle input during continue screen
|
|
void actualitzar_continue(float delta_time); // Update continue countdown
|
|
void check_and_apply_continue_timeout(); // Check if continue timed out and transition to GAME_OVER
|
|
void dibuixar_continue(); // Draw continue screen
|
|
|
|
// [NEW] Stage system helpers
|
|
void dibuixar_missatge_stage(const std::string& missatge);
|
|
|
|
// [NEW] Funcions d'animació per INIT_HUD
|
|
void dibuixar_marges_animat(float progress) const; // Rectangle amb creixement uniforme
|
|
void dibuixar_marcador_animat(float progress); // Marcador que puja des de baix
|
|
[[nodiscard]] Vec2 calcular_posicio_nau_init_hud(float progress, uint8_t player_id) const; // Posició animada de la nau
|
|
|
|
// [NEW] Función helper del sistema de animación INIT_HUD
|
|
[[nodiscard]] float calcular_progress_rango(float global_progress, float ratio_init, float ratio_end) const;
|
|
|
|
// [NEW] Funció helper del marcador
|
|
[[nodiscard]] std::string construir_marcador() const;
|
|
};
|
|
|
|
#endif // ESCENA_JOC_HPP
|