6cf990bc1d
Aplicada la directiva "res llegacy" abans d'arrencar la migracio a fisica vectorial + SDL3 GPU. Cada bossa de cruft que arrossegava el port de Pascal queda eliminada. Borrats (huerfanos): - source/core/rendering/primitives.hpp/.cpp (modul/diferencia/angle_punt/ crear_poligon_regular) - source/core/rendering/polygon_renderer.hpp/.cpp (rota_tri/rota_pol) - core::types::Triangle, Poligon, IPunt - Defaults::Entities::MAX_IPUNTS i alias a constants.hpp - EscenaJoc::chatarra_cosmica_ (mai usat) - Bresenham comentat dins de Rendering::linea() Simplificat (parametre 'dibuixar' llegacy que sempre era true): - Rendering::linea(...): treta la signatura bool dibuixar, retorn void - Rendering::render_shape(...): treta la signatura bool dibuixar - 11 callsites de linea() actualitzats (escena_joc, debris_manager) - 12 callsites de render_shape() actualitzats Modernitzats: - 5 fitxers .shp netejats de comentaris polar->cartesia historics - types.hpp queda nomes amb Punt (l'unica coordenada del joc) - debris_manager.hpp afegit include explicit de defaults.hpp Net: 452 linies eliminades, 56 afegides. Compila i enllaca correctament. 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/bala.hpp"
|
|
#include "game/entities/enemic.hpp"
|
|
#include "game/entities/nau.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 inicialitzar();
|
|
void actualitzar(float delta_time);
|
|
void dibuixar();
|
|
|
|
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<Nau, 2> naus_; // [0]=P1, [1]=P2
|
|
std::array<Enemic, Constants::MAX_ORNIS> orni_;
|
|
std::array<Bala, 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
|
|
Punt 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]] Punt 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]] Punt 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
|