91 lines
3.5 KiB
C++
91 lines
3.5 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 <SDL3/SDL.h>
|
|
|
|
#include <array>
|
|
#include <cstdint>
|
|
|
|
#include "../constants.hpp"
|
|
#include "../effects/debris_manager.hpp"
|
|
#include "../effects/gestor_puntuacio_flotant.hpp"
|
|
#include "../entities/bala.hpp"
|
|
#include "../entities/enemic.hpp"
|
|
#include "../entities/nau.hpp"
|
|
#include "../stage_system/stage_manager.hpp"
|
|
#include "core/graphics/vector_text.hpp"
|
|
#include "core/rendering/sdl_manager.hpp"
|
|
#include "core/system/context_escenes.hpp"
|
|
#include "core/types.hpp"
|
|
|
|
#include <memory>
|
|
|
|
// 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();
|
|
void processar_input(const SDL_Event& event);
|
|
|
|
private:
|
|
SDLManager& sdl_;
|
|
GestorEscenes::ContextEscenes& context_;
|
|
|
|
// 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]
|
|
Poligon chatarra_cosmica_;
|
|
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
|
|
bool game_over_; // Game over state flag
|
|
float game_over_timer_; // Countdown timer for auto-return (seconds)
|
|
Punt punt_spawn_; // Configurable spawn point (legacy)
|
|
Punt punt_mort_; // Death position (for respawn, legacy)
|
|
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_;
|
|
|
|
// 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 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
|
|
Punt obtenir_punt_spawn(uint8_t player_id) const; // Get spawn position for player
|
|
|
|
// [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
|
|
Punt calcular_posicio_nau_init_hud(float progress) const; // Posició animada de la nau
|
|
|
|
// [NEW] Funció helper del marcador
|
|
std::string construir_marcador() const;
|
|
};
|
|
|
|
#endif // ESCENA_JOC_HPP
|