afegida progresió
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
#include "core/system/gestor_escenes.hpp"
|
||||
#include "core/system/global_events.hpp"
|
||||
#include "game/stage_system/stage_loader.hpp"
|
||||
|
||||
EscenaJoc::EscenaJoc(SDLManager& sdl)
|
||||
: sdl_(sdl),
|
||||
@@ -105,6 +106,19 @@ void EscenaJoc::inicialitzar() {
|
||||
// Basat en el codi Pascal original: line 376
|
||||
std::srand(static_cast<unsigned>(std::time(nullptr)));
|
||||
|
||||
// [NEW] Load stage configuration (only once)
|
||||
if (!stage_config_) {
|
||||
stage_config_ = StageSystem::StageLoader::carregar("data/stages/stages.yaml");
|
||||
if (!stage_config_) {
|
||||
std::cerr << "[EscenaJoc] Error: no s'ha pogut carregar stages.yaml" << std::endl;
|
||||
// Continue without stage system (will crash, but helps debugging)
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Initialize stage manager
|
||||
stage_manager_ = std::make_unique<StageSystem::StageManager>(stage_config_.get());
|
||||
stage_manager_->inicialitzar();
|
||||
|
||||
// Inicialitzar estat de col·lisió
|
||||
itocado_ = 0;
|
||||
|
||||
@@ -119,22 +133,11 @@ void EscenaJoc::inicialitzar() {
|
||||
// Inicialitzar nau
|
||||
nau_.inicialitzar();
|
||||
|
||||
// Inicialitzar enemics (ORNIs) amb tipus aleatoris
|
||||
// [MODIFIED] Initialize enemies as inactive (stage system will spawn them)
|
||||
for (auto& enemy : orni_) {
|
||||
// Random type distribution: ~40% Pentagon, ~30% Quadrat, ~30% Molinillo
|
||||
int rand_val = std::rand() % 10;
|
||||
TipusEnemic tipus;
|
||||
|
||||
if (rand_val < 4) {
|
||||
tipus = TipusEnemic::PENTAGON;
|
||||
} else if (rand_val < 7) {
|
||||
tipus = TipusEnemic::QUADRAT;
|
||||
} else {
|
||||
tipus = TipusEnemic::MOLINILLO;
|
||||
}
|
||||
|
||||
enemy.inicialitzar(tipus);
|
||||
enemy = Enemic(sdl_.obte_renderer());
|
||||
enemy.set_ship_position(&nau_.get_centre()); // Set ship reference for tracking
|
||||
// DON'T call enemy.inicialitzar() here - stage system handles spawning
|
||||
}
|
||||
|
||||
// Inicialitzar bales
|
||||
@@ -210,28 +213,53 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
return;
|
||||
}
|
||||
|
||||
// *** NORMAL GAMEPLAY ***
|
||||
// *** STAGE SYSTEM STATE MACHINE ***
|
||||
|
||||
// Update ship (input + physics)
|
||||
nau_.processar_input(delta_time);
|
||||
nau_.actualitzar(delta_time);
|
||||
StageSystem::EstatStage estat = stage_manager_->get_estat();
|
||||
|
||||
// Update enemy movement and rotation
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
switch (estat) {
|
||||
case StageSystem::EstatStage::LEVEL_START:
|
||||
// Frozen gameplay, countdown timer only
|
||||
stage_manager_->actualitzar(delta_time);
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::PLAYING: {
|
||||
// [NEW] Update stage manager (spawns enemies, pass pause flag)
|
||||
bool pausar_spawn = (itocado_ > 0.0f); // Pause during death animation
|
||||
stage_manager_->get_spawn_controller().actualitzar(delta_time, orni_, pausar_spawn);
|
||||
|
||||
// [NEW] Check stage completion (only when not in death sequence)
|
||||
if (itocado_ == 0.0f) {
|
||||
auto& spawn_ctrl = stage_manager_->get_spawn_controller();
|
||||
if (spawn_ctrl.tots_enemics_destruits(orni_)) {
|
||||
stage_manager_->stage_completat();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// [EXISTING] Normal gameplay
|
||||
nau_.processar_input(delta_time);
|
||||
nau_.actualitzar(delta_time);
|
||||
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
}
|
||||
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
}
|
||||
|
||||
detectar_col·lisions_bales_enemics();
|
||||
detectar_col·lisio_nau_enemics();
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_COMPLETED:
|
||||
// Frozen gameplay, countdown timer only
|
||||
stage_manager_->actualitzar(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
// Update bullet movement
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
}
|
||||
|
||||
// Detect collisions
|
||||
detectar_col·lisions_bales_enemics();
|
||||
detectar_col·lisio_nau_enemics(); // New collision check
|
||||
|
||||
// Update debris
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
}
|
||||
|
||||
void EscenaJoc::dibuixar() {
|
||||
@@ -270,26 +298,38 @@ void EscenaJoc::dibuixar() {
|
||||
return;
|
||||
}
|
||||
|
||||
// During death sequence, don't draw ship (debris draws automatically)
|
||||
if (itocado_ == 0.0f) {
|
||||
nau_.dibuixar();
|
||||
// [NEW] Stage state rendering
|
||||
StageSystem::EstatStage estat = stage_manager_->get_estat();
|
||||
|
||||
switch (estat) {
|
||||
case StageSystem::EstatStage::LEVEL_START:
|
||||
dibuixar_missatge_stage(StageSystem::Constants::MISSATGE_LEVEL_START);
|
||||
dibuixar_marcador();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::PLAYING:
|
||||
// [EXISTING] Normal rendering
|
||||
if (itocado_ == 0.0f) {
|
||||
nau_.dibuixar();
|
||||
}
|
||||
|
||||
for (const auto& enemy : orni_) {
|
||||
enemy.dibuixar();
|
||||
}
|
||||
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
}
|
||||
|
||||
debris_manager_.dibuixar();
|
||||
dibuixar_marcador();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_COMPLETED:
|
||||
dibuixar_missatge_stage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
dibuixar_marcador();
|
||||
break;
|
||||
}
|
||||
|
||||
// Draw enemies (always)
|
||||
for (const auto& enemy : orni_) {
|
||||
enemy.dibuixar();
|
||||
}
|
||||
|
||||
// Draw bullets (always)
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
}
|
||||
|
||||
// Draw debris
|
||||
debris_manager_.dibuixar();
|
||||
|
||||
// Draw scoreboard
|
||||
dibuixar_marcador();
|
||||
}
|
||||
|
||||
void EscenaJoc::processar_input(const SDL_Event& event) {
|
||||
@@ -399,8 +439,13 @@ void EscenaJoc::dibuixar_marges() const {
|
||||
}
|
||||
|
||||
void EscenaJoc::dibuixar_marcador() {
|
||||
// Display actual lives count (user requested "LIFES" plural English)
|
||||
std::string text = "SCORE: 01000 LIFES: " + std::to_string(num_vides_) + " LEVEL: 01";
|
||||
// [MODIFIED] Display current stage number from stage manager
|
||||
uint8_t stage_num = stage_manager_->get_stage_actual();
|
||||
std::string stage_str = (stage_num < 10) ? "0" + std::to_string(stage_num)
|
||||
: std::to_string(stage_num);
|
||||
|
||||
std::string text = "SCORE: 01000 LIFES: " + std::to_string(num_vides_) +
|
||||
" LEVEL: " + stage_str;
|
||||
|
||||
// Paràmetres de renderització
|
||||
const float escala = 0.85f;
|
||||
@@ -513,3 +558,20 @@ void EscenaJoc::detectar_col·lisio_nau_enemics() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Stage system helper methods
|
||||
|
||||
void EscenaJoc::dibuixar_missatge_stage(const std::string& missatge) {
|
||||
constexpr float escala = 1.5f;
|
||||
constexpr float spacing = 3.0f;
|
||||
|
||||
float text_width = text_.get_text_width(missatge, escala, spacing);
|
||||
float text_height = text_.get_text_height(escala);
|
||||
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
float x = play_area.x + (play_area.w - text_width) / 2.0f;
|
||||
float y = play_area.y + (play_area.h - text_height) / 2.0f;
|
||||
|
||||
Punt pos = {static_cast<float>(x), static_cast<float>(y)};
|
||||
text_.render(missatge, pos, escala, spacing);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user