Files
orni-attack/source/game/scenes/game_scene.hpp
T
JailDesigner 5871d29d48 Fase 1c: rename d'escenes i sistema d'escenes
Tots els tipus, fitxers, namespace, enums i metodes relacionats amb
les escenes passen del catala a l'angles seguint el .clang-tidy:

Fitxers (renames git):
- source/game/escenes/escena_joc.{hpp,cpp} -> game/scenes/game_scene.{hpp,cpp}
- source/game/escenes/escena_titol.{hpp,cpp} -> game/scenes/title_scene.{hpp,cpp}
- source/game/escenes/escena_logo.{hpp,cpp} -> game/scenes/logo_scene.{hpp,cpp}
- source/core/system/context_escenes.hpp -> core/system/scene_context.hpp
- Carpeta game/escenes/ -> game/scenes/

Tipus (CamelCase):
- EscenaJoc -> GameScene
- EscenaTitol -> TitleScene
- EscenaLogo -> LogoScene
- ContextEscenes -> SceneContext
- Escena (enum class) -> SceneType
- Opcio -> Option
- EstatGameOver -> GameOverState
- EstatTitol -> TitleState
- EstatAnimacio -> AnimationState
- ConfigPartida -> MatchConfig

Namespace:
- GestorEscenes -> SceneManager

Valors d'enum SceneType:
- TITOL -> TITLE
- JOC -> GAME
- EIXIR -> EXIT
(LOGO mantingut)

Metodes (camelBack):
- executar -> run
- canviar_escena -> setNextScene
- escena_desti -> nextScene
- opcio (getter) -> option
- consumir_opcio -> consumeOption
- reset_opcio -> resetOption
- set_config_partida -> setMatchConfig
- get_config_partida -> getMatchConfig

Camps privats (lower_case_):
- escena_desti_ -> next_scene_
- opcio_ -> option_
- config_partida_ -> match_config_

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-19 11:41:11 +02:00

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/scene_context.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 GameOverState {
NONE, // Normal gameplay
CONTINUE, // Continue countdown screen (9→0)
GAME_OVER // Final game over (returning to title)
};
// Classe principal del joc (escena)
class GameScene {
public:
explicit GameScene(SDLManager& sdl, SceneManager::SceneContext& context);
~GameScene() = default;
void run(); // Bucle principal de l'escena
void init();
void update(float delta_time);
void draw();
private:
SDLManager& sdl_;
SceneManager::SceneContext& context_;
GameConfig::MatchConfig match_config_; // 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
GameOverState 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