Fase 1b: rename d'entitats i metodes virtuals a CamelCase/camelBack
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>
This commit is contained in:
+109
-109
@@ -12,7 +12,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/entities/entity.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/input/mouse.hpp"
|
||||
#include "core/math/easing.hpp"
|
||||
@@ -49,17 +49,17 @@ EscenaJoc::EscenaJoc(SDLManager& sdl, ContextEscenes& context)
|
||||
(void)opcio; // Suprimir warning de variable no usada
|
||||
|
||||
// Inicialitzar naus amb renderer (P1=ship.shp, P2=ship2.shp)
|
||||
naus_[0] = Nau(sdl.obte_renderer(), "ship.shp"); // Jugador 1: nave estàndar
|
||||
naus_[1] = Nau(sdl.obte_renderer(), "ship2.shp"); // Jugador 2: interceptor amb ales
|
||||
naus_[0] = Ship(sdl.obte_renderer(), "ship.shp"); // Jugador 1: nave estàndar
|
||||
naus_[1] = Ship(sdl.obte_renderer(), "ship2.shp"); // Jugador 2: interceptor amb ales
|
||||
|
||||
// Inicialitzar bales amb renderer
|
||||
for (auto& bala : bales_) {
|
||||
bala = Bala(sdl.obte_renderer());
|
||||
bala = Bullet(sdl.obte_renderer());
|
||||
}
|
||||
|
||||
// Inicialitzar enemics amb renderer
|
||||
for (auto& enemy : orni_) {
|
||||
enemy = Enemic(sdl.obte_renderer());
|
||||
enemy = Enemy(sdl.obte_renderer());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ void EscenaJoc::executar() {
|
||||
std::cout << "Escena Joc: Inicialitzant...\n";
|
||||
|
||||
// Inicialitzar estat del joc
|
||||
inicialitzar();
|
||||
init();
|
||||
|
||||
SDL_Event event;
|
||||
Uint64 last_time = SDL_GetTicks();
|
||||
@@ -102,7 +102,7 @@ void EscenaJoc::executar() {
|
||||
}
|
||||
|
||||
// Actualitzar física del joc amb delta_time real
|
||||
actualitzar(delta_time);
|
||||
update(delta_time);
|
||||
|
||||
// Actualitzar sistema d'audio
|
||||
Audio::update();
|
||||
@@ -117,7 +117,7 @@ void EscenaJoc::executar() {
|
||||
sdl_.updateRenderingContext();
|
||||
|
||||
// Dibuixar joc
|
||||
dibuixar();
|
||||
draw();
|
||||
|
||||
// Presentar renderer (swap buffers)
|
||||
sdl_.presenta();
|
||||
@@ -126,7 +126,7 @@ void EscenaJoc::executar() {
|
||||
std::cout << "Escena Joc: Finalitzant...\n";
|
||||
}
|
||||
|
||||
void EscenaJoc::inicialitzar() {
|
||||
void EscenaJoc::init() {
|
||||
// Inicialitzar generador de números aleatoris
|
||||
// Basat en el codi Pascal original: line 376
|
||||
std::srand(static_cast<unsigned>(std::time(nullptr)));
|
||||
@@ -142,10 +142,10 @@ void EscenaJoc::inicialitzar() {
|
||||
|
||||
// [NEW] Initialize stage manager
|
||||
stage_manager_ = std::make_unique<StageSystem::StageManager>(stage_config_.get());
|
||||
stage_manager_->inicialitzar();
|
||||
stage_manager_->init();
|
||||
|
||||
// [NEW] Set ship position reference for safe spawn (P1 for now, TODO: dual tracking)
|
||||
stage_manager_->get_spawn_controller().set_ship_position(&naus_[0].get_centre());
|
||||
stage_manager_->get_spawn_controller().set_ship_position(&naus_[0].getCenter());
|
||||
|
||||
// Inicialitzar timers de muerte per jugador
|
||||
itocado_per_jugador_[0] = 0.0F;
|
||||
@@ -175,13 +175,13 @@ void EscenaJoc::inicialitzar() {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
|
||||
if (jugador_actiu) {
|
||||
// Jugador actiu: inicialitzar normalment
|
||||
// Jugador actiu: init normalment
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(i);
|
||||
naus_[i].inicialitzar(&spawn_pos, false); // No invulnerability at start
|
||||
naus_[i].init(&spawn_pos, false); // No invulnerability at start
|
||||
std::cout << "[EscenaJoc] Jugador " << (i + 1) << " inicialitzat\n";
|
||||
} else {
|
||||
// Jugador inactiu: marcar com a mort permanent
|
||||
naus_[i].marcar_tocada();
|
||||
naus_[i].markHit();
|
||||
itocado_per_jugador_[i] = 999.0F; // Valor sentinella (permanent inactiu)
|
||||
vides_per_jugador_[i] = 0; // Sense vides
|
||||
std::cout << "[EscenaJoc] Jugador " << (i + 1) << " inactiu\n";
|
||||
@@ -190,14 +190,14 @@ void EscenaJoc::inicialitzar() {
|
||||
|
||||
// [MODIFIED] Initialize enemies as inactive (stage system will spawn them)
|
||||
for (auto& enemy : orni_) {
|
||||
enemy = Enemic(sdl_.obte_renderer());
|
||||
enemy.set_ship_position(&naus_[0].get_centre()); // Set ship reference (P1 for now)
|
||||
// DON'T call enemy.inicialitzar() here - stage system handles spawning
|
||||
enemy = Enemy(sdl_.obte_renderer());
|
||||
enemy.set_ship_position(&naus_[0].getCenter()); // Set ship reference (P1 for now)
|
||||
// DON'T call enemy.init() here - stage system handles spawning
|
||||
}
|
||||
|
||||
// Inicialitzar bales (now 6 instead of 3)
|
||||
for (auto& bala : bales_) {
|
||||
bala.inicialitzar();
|
||||
bala.init();
|
||||
}
|
||||
|
||||
// [ELIMINAT] Iniciar música de joc (ara es gestiona en stage_manager)
|
||||
@@ -208,7 +208,7 @@ void EscenaJoc::inicialitzar() {
|
||||
init_hud_rect_sound_played_ = false;
|
||||
}
|
||||
|
||||
void EscenaJoc::actualitzar(float delta_time) {
|
||||
void EscenaJoc::update(float delta_time) {
|
||||
// Processar disparos (state-based, no event-based)
|
||||
if (estat_game_over_ == EstatGameOver::NONE) {
|
||||
auto* input = Input::get();
|
||||
@@ -271,13 +271,13 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
|
||||
// Still update enemies, bullets, and effects during continue screen
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
enemy.update(delta_time);
|
||||
}
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
gestor_puntuacio_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
gestor_puntuacio_.update(delta_time);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -297,15 +297,15 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
|
||||
// Enemies and bullets continue moving during game over
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
enemy.update(delta_time);
|
||||
}
|
||||
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
gestor_puntuacio_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
gestor_puntuacio_.update(delta_time);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
if (vides_per_jugador_[i] > 0) {
|
||||
// Respawn ship en spawn position con invulnerabilidad
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(i);
|
||||
naus_[i].inicialitzar(&spawn_pos, true);
|
||||
naus_[i].init(&spawn_pos, true);
|
||||
itocado_per_jugador_[i] = 0.0F;
|
||||
} else {
|
||||
// Player is permanently dead (out of lives)
|
||||
@@ -352,15 +352,15 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
if (algun_jugador_mort) {
|
||||
// Enemies and bullets continue moving during death sequence
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
enemy.update(delta_time);
|
||||
}
|
||||
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
gestor_puntuacio_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
gestor_puntuacio_.update(delta_time);
|
||||
|
||||
// Don't return - allow alive players to continue playing
|
||||
}
|
||||
@@ -372,9 +372,9 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
switch (estat) {
|
||||
case StageSystem::EstatStage::INIT_HUD: {
|
||||
// Update stage manager timer (pot canviar l'estat!)
|
||||
stage_manager_->actualitzar(delta_time);
|
||||
stage_manager_->update(delta_time);
|
||||
|
||||
// [FIX] Si l'estat ha canviat durant actualitzar(), sortir immediatament
|
||||
// [FIX] Si l'estat ha canviat durant update(), sortir immediatament
|
||||
// per evitar recalcular la posició de la nau amb el nou timer
|
||||
if (stage_manager_->get_estat() != StageSystem::EstatStage::INIT_HUD) {
|
||||
break;
|
||||
@@ -398,12 +398,12 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
// [MODIFICAT] Animar AMBAS naus con sus progress respectivos
|
||||
if (config_partida_.jugador1_actiu && ship1_progress < 1.0F) {
|
||||
Vec2 pos_p1 = calcular_posicio_nau_init_hud(ship1_progress, 0);
|
||||
naus_[0].set_centre(pos_p1);
|
||||
naus_[0].setCenter(pos_p1);
|
||||
}
|
||||
|
||||
if (config_partida_.jugador2_actiu && ship2_progress < 1.0F) {
|
||||
Vec2 pos_p2 = calcular_posicio_nau_init_hud(ship2_progress, 1);
|
||||
naus_[1].set_centre(pos_p2);
|
||||
naus_[1].setCenter(pos_p2);
|
||||
}
|
||||
|
||||
// Una vegada l'animació acaba, permetre control normal
|
||||
@@ -416,36 +416,36 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
// [DEBUG] Log entrada a LEVEL_START
|
||||
static bool first_entry = true;
|
||||
if (first_entry) {
|
||||
std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << naus_[0].get_centre().y << '\n';
|
||||
std::cout << "[LEVEL_START] ENTERED with P1 pos.y=" << naus_[0].getCenter().y << '\n';
|
||||
first_entry = false;
|
||||
}
|
||||
|
||||
// Update countdown timer
|
||||
stage_manager_->actualitzar(delta_time);
|
||||
stage_manager_->update(delta_time);
|
||||
|
||||
// [NEW] Allow both ships movement and shooting during intro
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players
|
||||
naus_[i].processar_input(delta_time, i);
|
||||
naus_[i].actualitzar(delta_time);
|
||||
naus_[i].processInput(delta_time, i);
|
||||
naus_[i].update(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Update bullets
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
|
||||
// [NEW] Update debris
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
case StageSystem::EstatStage::PLAYING: {
|
||||
// [NEW] Update stage manager (spawns enemies, pause if BOTH dead)
|
||||
bool pausar_spawn = (itocado_per_jugador_[0] > 0.0F && itocado_per_jugador_[1] > 0.0F);
|
||||
stage_manager_->get_spawn_controller().actualitzar(delta_time, orni_, pausar_spawn);
|
||||
stage_manager_->get_spawn_controller().update(delta_time, orni_, pausar_spawn);
|
||||
|
||||
// [NEW] Check stage completion (only when at least one player alive)
|
||||
bool algun_jugador_viu = (itocado_per_jugador_[0] == 0.0F || itocado_per_jugador_[1] == 0.0F);
|
||||
@@ -462,68 +462,68 @@ void EscenaJoc::actualitzar(float delta_time) {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players
|
||||
naus_[i].processar_input(delta_time, i);
|
||||
naus_[i].actualitzar(delta_time);
|
||||
naus_[i].processInput(delta_time, i);
|
||||
naus_[i].update(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& enemy : orni_) {
|
||||
enemy.actualitzar(delta_time);
|
||||
enemy.update(delta_time);
|
||||
}
|
||||
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
|
||||
detectar_col·lisions_bales_enemics();
|
||||
detectar_col·lisio_naus_enemics();
|
||||
detectar_col·lisions_bales_jugadors();
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
gestor_puntuacio_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
gestor_puntuacio_.update(delta_time);
|
||||
break;
|
||||
}
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_COMPLETED:
|
||||
// Update countdown timer
|
||||
stage_manager_->actualitzar(delta_time);
|
||||
stage_manager_->update(delta_time);
|
||||
|
||||
// [NEW] Allow both ships movement and shooting during outro
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) { // Only active, alive players
|
||||
naus_[i].processar_input(delta_time, i);
|
||||
naus_[i].actualitzar(delta_time);
|
||||
naus_[i].processInput(delta_time, i);
|
||||
naus_[i].update(delta_time);
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Update bullets (allow last shots to continue)
|
||||
for (auto& bala : bales_) {
|
||||
bala.actualitzar(delta_time);
|
||||
bala.update(delta_time);
|
||||
}
|
||||
|
||||
// [NEW] Update debris (from last destroyed enemies)
|
||||
debris_manager_.actualitzar(delta_time);
|
||||
gestor_puntuacio_.actualitzar(delta_time);
|
||||
debris_manager_.update(delta_time);
|
||||
gestor_puntuacio_.update(delta_time);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void EscenaJoc::dibuixar() {
|
||||
void EscenaJoc::draw() {
|
||||
// Handle CONTINUE screen
|
||||
if (estat_game_over_ == EstatGameOver::CONTINUE) {
|
||||
// Draw game background elements first
|
||||
dibuixar_marges();
|
||||
|
||||
for (const auto& enemy : orni_) {
|
||||
enemy.dibuixar();
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
bala.draw();
|
||||
}
|
||||
|
||||
debris_manager_.dibuixar();
|
||||
gestor_puntuacio_.dibuixar();
|
||||
debris_manager_.draw();
|
||||
gestor_puntuacio_.draw();
|
||||
dibuixar_marcador();
|
||||
|
||||
// Draw CONTINUE screen overlay
|
||||
@@ -537,15 +537,15 @@ void EscenaJoc::dibuixar() {
|
||||
dibuixar_marges();
|
||||
|
||||
for (const auto& enemy : orni_) {
|
||||
enemy.dibuixar();
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
bala.draw();
|
||||
}
|
||||
|
||||
debris_manager_.dibuixar();
|
||||
gestor_puntuacio_.dibuixar();
|
||||
debris_manager_.draw();
|
||||
gestor_puntuacio_.draw();
|
||||
|
||||
// Draw centered "GAME OVER" text
|
||||
const std::string game_over_text = "GAME OVER";
|
||||
@@ -610,12 +610,12 @@ void EscenaJoc::dibuixar() {
|
||||
}
|
||||
|
||||
// [MODIFICAT] Dibuixar naus amb progress independent
|
||||
if (ship1_progress > 0.0F && config_partida_.jugador1_actiu && !naus_[0].esta_tocada()) {
|
||||
naus_[0].dibuixar();
|
||||
if (ship1_progress > 0.0F && config_partida_.jugador1_actiu && !naus_[0].isHit()) {
|
||||
naus_[0].draw();
|
||||
}
|
||||
|
||||
if (ship2_progress > 0.0F && config_partida_.jugador2_actiu && !naus_[1].esta_tocada()) {
|
||||
naus_[1].dibuixar();
|
||||
if (ship2_progress > 0.0F && config_partida_.jugador2_actiu && !naus_[1].isHit()) {
|
||||
naus_[1].draw();
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -627,18 +627,18 @@ void EscenaJoc::dibuixar() {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) {
|
||||
naus_[i].dibuixar();
|
||||
naus_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
bala.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris
|
||||
debris_manager_.dibuixar();
|
||||
gestor_puntuacio_.dibuixar();
|
||||
debris_manager_.draw();
|
||||
gestor_puntuacio_.draw();
|
||||
|
||||
// [EXISTING] Draw intro message and score
|
||||
dibuixar_missatge_stage(stage_manager_->get_missatge_level_start());
|
||||
@@ -652,20 +652,20 @@ void EscenaJoc::dibuixar() {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) {
|
||||
naus_[i].dibuixar();
|
||||
naus_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& enemy : orni_) {
|
||||
enemy.dibuixar();
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
bala.draw();
|
||||
}
|
||||
|
||||
debris_manager_.dibuixar();
|
||||
gestor_puntuacio_.dibuixar();
|
||||
debris_manager_.draw();
|
||||
gestor_puntuacio_.draw();
|
||||
dibuixar_marcador();
|
||||
break;
|
||||
|
||||
@@ -675,18 +675,18 @@ void EscenaJoc::dibuixar() {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? config_partida_.jugador1_actiu : config_partida_.jugador2_actiu;
|
||||
if (jugador_actiu && itocado_per_jugador_[i] == 0.0F) {
|
||||
naus_[i].dibuixar();
|
||||
naus_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets (allow last shots to be visible)
|
||||
for (const auto& bala : bales_) {
|
||||
bala.dibuixar();
|
||||
bala.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris (from last destroyed enemies)
|
||||
debris_manager_.dibuixar();
|
||||
gestor_puntuacio_.dibuixar();
|
||||
debris_manager_.draw();
|
||||
gestor_puntuacio_.draw();
|
||||
|
||||
// [EXISTING] Draw completion message and score
|
||||
dibuixar_missatge_stage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
@@ -699,28 +699,28 @@ void EscenaJoc::tocado(uint8_t player_id) {
|
||||
// Death sequence: 3 phases
|
||||
// Phase 1: First call (itocado_per_jugador_[player_id] == 0) - trigger explosion
|
||||
// Phase 2: Animation (0 < itocado_ < 3.0s) - debris animation
|
||||
// Phase 3: Respawn or game over (itocado_ >= 3.0s) - handled in actualitzar()
|
||||
// Phase 3: Respawn or game over (itocado_ >= 3.0s) - handled in update()
|
||||
|
||||
if (itocado_per_jugador_[player_id] == 0.0F) {
|
||||
// *** PHASE 1: TRIGGER DEATH ***
|
||||
|
||||
// Mark ship as dead (stops rendering and input)
|
||||
naus_[player_id].marcar_tocada();
|
||||
naus_[player_id].markHit();
|
||||
|
||||
// Create ship explosion
|
||||
const Vec2& ship_pos = naus_[player_id].get_centre();
|
||||
float ship_angle = naus_[player_id].get_angle();
|
||||
Vec2 vel_nau = naus_[player_id].get_velocitat_vector();
|
||||
const Vec2& ship_pos = naus_[player_id].getCenter();
|
||||
float ship_angle = naus_[player_id].getAngle();
|
||||
Vec2 vel_nau = naus_[player_id].getVelocityVector();
|
||||
// Reduir a 80% la velocitat heretada per la nau (més realista)
|
||||
Vec2 vel_nau_80 = {.x = vel_nau.x * 0.8F, .y = vel_nau.y * 0.8F};
|
||||
|
||||
debris_manager_.explotar(
|
||||
naus_[player_id].get_forma(), // Ship shape (3 lines)
|
||||
naus_[player_id].getShape(), // Ship shape (3 lines)
|
||||
ship_pos, // Center position
|
||||
ship_angle, // Ship orientation
|
||||
1.0F, // Normal scale
|
||||
Defaults::Physics::Debris::VELOCITAT_BASE, // 80 px/s
|
||||
naus_[player_id].get_brightness(), // Heredar brightness
|
||||
naus_[player_id].getBrightness(), // Heredar brightness
|
||||
vel_nau_80, // Heredar 80% velocitat
|
||||
0.0F, // Nave: trayectorias rectas (sin drotacio)
|
||||
0.0F, // Sin herencia visual (rotación aleatoria)
|
||||
@@ -730,8 +730,8 @@ void EscenaJoc::tocado(uint8_t player_id) {
|
||||
// Start death timer (non-zero to avoid re-triggering)
|
||||
itocado_per_jugador_[player_id] = 0.001F;
|
||||
}
|
||||
// Phase 2 is automatic (debris updates in actualitzar())
|
||||
// Phase 3 is handled in actualitzar() when itocado_per_jugador_ >= DEATH_DURATION
|
||||
// Phase 2 is automatic (debris updates in update())
|
||||
// Phase 3 is handled in update() when itocado_per_jugador_ >= DEATH_DURATION
|
||||
}
|
||||
|
||||
void EscenaJoc::dibuixar_marges() const {
|
||||
@@ -957,18 +957,18 @@ void EscenaJoc::detectar_col·lisions_bales_enemics() {
|
||||
if (Physics::check_collision(bala, enemic, AMPLIFIER)) {
|
||||
// *** COL·LISIÓ DETECTADA ***
|
||||
|
||||
const Vec2& pos_enemic = enemic.get_centre();
|
||||
const Vec2& pos_enemic = enemic.getCenter();
|
||||
|
||||
// 1. Calculate score for enemy type
|
||||
int punts = 0;
|
||||
switch (enemic.get_tipus()) {
|
||||
case TipusEnemic::PENTAGON:
|
||||
switch (enemic.getType()) {
|
||||
case EnemyType::PENTAGON:
|
||||
punts = Defaults::Enemies::Scoring::PENTAGON_SCORE;
|
||||
break;
|
||||
case TipusEnemic::QUADRAT:
|
||||
case EnemyType::QUADRAT:
|
||||
punts = Defaults::Enemies::Scoring::QUADRAT_SCORE;
|
||||
break;
|
||||
case TipusEnemic::MOLINILLO:
|
||||
case EnemyType::MOLINILLO:
|
||||
punts = Defaults::Enemies::Scoring::MOLINILLO_SCORE;
|
||||
break;
|
||||
}
|
||||
@@ -984,14 +984,14 @@ void EscenaJoc::detectar_col·lisions_bales_enemics() {
|
||||
enemic.destruir();
|
||||
|
||||
// 2. Crear explosió de fragments
|
||||
Vec2 vel_enemic = enemic.get_velocitat_vector();
|
||||
Vec2 vel_enemic = enemic.getVelocityVector();
|
||||
debris_manager_.explotar(
|
||||
enemic.get_forma(), // Forma vectorial del pentàgon
|
||||
enemic.getShape(), // Forma vectorial del pentàgon
|
||||
pos_enemic, // Posició central
|
||||
0.0F, // Angle (enemic té rotació interna)
|
||||
1.0F, // Escala normal
|
||||
VELOCITAT_EXPLOSIO, // 50 px/s (explosió suau)
|
||||
enemic.get_brightness(), // Heredar brightness
|
||||
enemic.getBrightness(), // Heredar brightness
|
||||
vel_enemic, // Heredar velocitat
|
||||
enemic.get_drotacio(), // Heredar velocitat angular (trayectorias curvas)
|
||||
0.0F // Sin herencia visual (rotación aleatoria)
|
||||
@@ -1017,17 +1017,17 @@ void EscenaJoc::detectar_col·lisio_naus_enemics() {
|
||||
if (itocado_per_jugador_[i] > 0.0F) {
|
||||
continue;
|
||||
}
|
||||
if (!naus_[i].esta_viva()) {
|
||||
if (!naus_[i].isAlive()) {
|
||||
continue;
|
||||
}
|
||||
if (naus_[i].es_invulnerable()) {
|
||||
if (naus_[i].isInvulnerable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check collision with all active enemies
|
||||
for (const auto& enemic : orni_) {
|
||||
// Skip collision if enemy is invulnerable
|
||||
if (enemic.es_invulnerable()) {
|
||||
if (enemic.isInvulnerable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1068,10 +1068,10 @@ void EscenaJoc::detectar_col·lisions_bales_jugadors() {
|
||||
if (itocado_per_jugador_[player_id] > 0.0F) {
|
||||
continue;
|
||||
}
|
||||
if (!naus_[player_id].esta_viva()) {
|
||||
if (!naus_[player_id].isAlive()) {
|
||||
continue;
|
||||
}
|
||||
if (naus_[player_id].es_invulnerable()) {
|
||||
if (naus_[player_id].isInvulnerable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -1206,13 +1206,13 @@ void EscenaJoc::disparar_bala(uint8_t player_id) {
|
||||
if (itocado_per_jugador_[player_id] > 0.0F) {
|
||||
return;
|
||||
}
|
||||
if (!naus_[player_id].esta_viva()) {
|
||||
if (!naus_[player_id].isAlive()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Calcular posición en la punta de la nave
|
||||
const Vec2& ship_centre = naus_[player_id].get_centre();
|
||||
float ship_angle = naus_[player_id].get_angle();
|
||||
const Vec2& ship_centre = naus_[player_id].getCenter();
|
||||
float ship_angle = naus_[player_id].getAngle();
|
||||
|
||||
constexpr float LOCAL_TIP_X = 0.0F;
|
||||
constexpr float LOCAL_TIP_Y = -12.0F;
|
||||
@@ -1296,7 +1296,7 @@ void EscenaJoc::processar_input_continue() {
|
||||
|
||||
// Spawn with invulnerability
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(player_to_revive);
|
||||
naus_[player_to_revive].inicialitzar(&spawn_pos, true);
|
||||
naus_[player_to_revive].init(&spawn_pos, true);
|
||||
|
||||
// Check if other player wants to continue too
|
||||
if (p1_start && p2_start) {
|
||||
@@ -1306,7 +1306,7 @@ void EscenaJoc::processar_input_continue() {
|
||||
itocado_per_jugador_[other_player] = 0.0F;
|
||||
config_partida_.jugador2_actiu = true;
|
||||
Vec2 spawn_pos2 = obtenir_punt_spawn(other_player);
|
||||
naus_[other_player].inicialitzar(&spawn_pos2, true);
|
||||
naus_[other_player].init(&spawn_pos2, true);
|
||||
}
|
||||
|
||||
// Resume game
|
||||
@@ -1392,7 +1392,7 @@ void EscenaJoc::unir_jugador(uint8_t player_id) {
|
||||
|
||||
// Spawn with invulnerability
|
||||
Vec2 spawn_pos = obtenir_punt_spawn(player_id);
|
||||
naus_[player_id].inicialitzar(&spawn_pos, true);
|
||||
naus_[player_id].init(&spawn_pos, true);
|
||||
|
||||
// No visual message, just spawn (per user requirement)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user