Lint: rename públicos al inglés + refactor cognitive-complexity + unused-includes
Identifier-naming: rename de métodos públicos y cross-file al inglés
(camelBack), traducción de campos y locales en el proceso (TitleShip,
StageManager, SpawnController, ShipAnimator, helpers de PlayArea, etc.).
Refactor por cognitive-complexity (>25): GameScene::draw (59→3) con 9
helpers de estado, PhysicsWorld::resolveBodyCollisions (35→5) extrayendo
resolveBodyPair, Options::load{Window,Physics,Audio}ConfigFromYaml
(32/49/57→5/2/3) con templates readField, TitleScene::update (68→4) con
5 sub-pasos por estado + handleSkipInput/handleStartInput +
triggerExitForJoinedPlayers, DebrisManager::explode (39→3) con
extractSegments/spawnDebris/applyAngularVelocity/applyVisualRotation.
use-anyofallof: bucles → std::ranges::any_of/all_of en Input,
ShipAnimator y SpawnController.
readability-static-accessed-through-instance: Director::run y
VectorText::getTextWidth/Height invocados por clase.
readability-convert-member-functions-to-static: ResourcePack::decryptData.
unused-includes: eliminación de <utility>, <cstdint>, <vector>,
<iostream>, defaults.hpp y otros no usados directamente en headers y
unidades de traducción. Restablecido core/defaults.hpp en title_scene.cpp
(falsa "unused" del header).
Bug fix: eliminado isActive() duplicado en Bullet (redeclaración tras
rename de esta_activa→isActive que chocaba con el override de Entity).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+149
-186
@@ -8,13 +8,9 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/entities/entity.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/math/easing.hpp"
|
||||
#include "core/physics/collision.hpp"
|
||||
#include "core/rendering/line_renderer.hpp"
|
||||
#include "core/system/scene_context.hpp"
|
||||
#include "game/stage_system/stage_loader.hpp"
|
||||
@@ -223,7 +219,7 @@ void GameScene::stepShootingInput() {
|
||||
|
||||
void GameScene::stepMidGameJoin() {
|
||||
// Permitir join solo durante PLAYING.
|
||||
if (stage_manager_->get_estat() != StageSystem::EstatStage::PLAYING) {
|
||||
if (stage_manager_->getState() != StageSystem::EstatStage::PLAYING) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -361,7 +357,7 @@ void GameScene::stepDeathSequence(float delta_time) {
|
||||
}
|
||||
|
||||
void GameScene::stepStageStateMachine(float delta_time) {
|
||||
const StageSystem::EstatStage STATE = stage_manager_->get_estat();
|
||||
const StageSystem::EstatStage STATE = stage_manager_->getState();
|
||||
switch (STATE) {
|
||||
case StageSystem::EstatStage::INIT_HUD:
|
||||
runStageInitHud(delta_time);
|
||||
@@ -382,11 +378,11 @@ void GameScene::runStageInitHud(float delta_time) {
|
||||
// Update stage manager timer (puede cambiar el state).
|
||||
stage_manager_->update(delta_time);
|
||||
// Si el state cambió, salir para no usar el timer del nuevo state.
|
||||
if (stage_manager_->get_estat() != StageSystem::EstatStage::INIT_HUD) {
|
||||
if (stage_manager_->getState() != StageSystem::EstatStage::INIT_HUD) {
|
||||
return;
|
||||
}
|
||||
|
||||
float global_progress = 1.0F - (stage_manager_->get_timer_transicio() / Defaults::Game::INIT_HUD_DURATION);
|
||||
float global_progress = 1.0F - (stage_manager_->getTransitionTimer() / Defaults::Game::INIT_HUD_DURATION);
|
||||
global_progress = std::min(1.0F, global_progress);
|
||||
|
||||
const float SHIP1_P = Systems::InitHud::computeRangeProgress(
|
||||
@@ -429,8 +425,8 @@ void GameScene::runStagePlaying(float delta_time) {
|
||||
|
||||
// Stage completado: cuando al menos un jugador está vivo y todos los enemies muertos.
|
||||
const bool ALGU_VIU = (hit_timer_per_player_[0] == 0.0F || hit_timer_per_player_[1] == 0.0F);
|
||||
if (ALGU_VIU && stage_manager_->getSpawnController().tots_enemics_destruits(enemies_)) {
|
||||
stage_manager_->stage_completat();
|
||||
if (ALGU_VIU && stage_manager_->getSpawnController().allEnemiesDestroyed(enemies_)) {
|
||||
stage_manager_->markStageCompleted();
|
||||
Audio::get()->playSound(Defaults::Sound::GOOD_JOB_COMMANDER, Audio::Group::GAME);
|
||||
return;
|
||||
}
|
||||
@@ -488,192 +484,159 @@ void GameScene::runCollisionDetections() {
|
||||
}
|
||||
|
||||
void GameScene::draw() {
|
||||
// Handle CONTINUE screen
|
||||
if (game_over_state_ == GameOverState::CONTINUE) {
|
||||
// Draw game background elements first
|
||||
drawMargins();
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
|
||||
// Draw CONTINUE screen overlay
|
||||
drawContinue();
|
||||
drawContinueState();
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle final GAME OVER state
|
||||
if (game_over_state_ == GameOverState::GAME_OVER) {
|
||||
// Game over: draw enemies, bullets, debris, and "GAME OVER" text
|
||||
drawMargins();
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// Draw centered "GAME OVER" text
|
||||
const std::string GAME_OVER_TEXT = "GAME OVER";
|
||||
constexpr float SCALE = Defaults::Game::GameOverScreen::TEXT_SCALE;
|
||||
constexpr float SPACING = Defaults::Game::GameOverScreen::TEXT_SPACING;
|
||||
|
||||
// Calcular centro de l'àrea de juego usant constants
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
float centre_x = play_area.x + (play_area.w / 2.0F);
|
||||
float centre_y = play_area.y + (play_area.h / 2.0F);
|
||||
|
||||
text_.renderCentered(GAME_OVER_TEXT, {.x = centre_x, .y = centre_y}, SCALE, SPACING);
|
||||
|
||||
drawScoreboard();
|
||||
drawGameOverState();
|
||||
return;
|
||||
}
|
||||
|
||||
// [NEW] Stage state rendering
|
||||
StageSystem::EstatStage state = stage_manager_->get_estat();
|
||||
|
||||
switch (state) {
|
||||
case StageSystem::EstatStage::INIT_HUD: {
|
||||
// Calcular progrés de cada animación independent
|
||||
float timer = stage_manager_->get_timer_transicio();
|
||||
float total_time = Defaults::Game::INIT_HUD_DURATION;
|
||||
float global_progress = 1.0F - (timer / total_time);
|
||||
|
||||
// [NEW] Calcular progress independiente para cada elemento
|
||||
float rect_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_END);
|
||||
|
||||
float score_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_END);
|
||||
|
||||
float ship1_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_END);
|
||||
|
||||
float ship2_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_END);
|
||||
|
||||
// Dibuixar elements animats
|
||||
if (rect_progress > 0.0F) {
|
||||
// [NOU] Reproduir so cuando comença l'animación del rectangle
|
||||
if (!init_hud_rect_sound_played_) {
|
||||
Audio::get()->playSound(Defaults::Sound::INIT_HUD, Audio::Group::GAME);
|
||||
init_hud_rect_sound_played_ = true;
|
||||
}
|
||||
|
||||
Systems::InitHud::drawBordersAnimated(sdl_.getRenderer(), rect_progress);
|
||||
}
|
||||
|
||||
if (score_progress > 0.0F) {
|
||||
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
||||
}
|
||||
|
||||
// [MODIFICAT] Dibuixar naves con progress independent
|
||||
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) {
|
||||
ships_[0].draw();
|
||||
}
|
||||
|
||||
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) {
|
||||
ships_[1].draw();
|
||||
}
|
||||
|
||||
switch (stage_manager_->getState()) {
|
||||
case StageSystem::EstatStage::INIT_HUD:
|
||||
drawInitHudState();
|
||||
break;
|
||||
}
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_START:
|
||||
drawMargins();
|
||||
// [NEW] Draw both ships if active and alive
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// [EXISTING] Draw intro message and score
|
||||
drawStageMessage(stage_manager_->get_missatge_level_start());
|
||||
drawScoreboard();
|
||||
drawLevelStartState();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::PLAYING:
|
||||
drawMargins();
|
||||
|
||||
// [EXISTING] Normal rendering - active ships
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
drawPlayingState();
|
||||
break;
|
||||
|
||||
case StageSystem::EstatStage::LEVEL_COMPLETED:
|
||||
drawMargins();
|
||||
// [NEW] Draw both ships if active and alive
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
|
||||
// [NEW] Draw bullets (allow last shots to be visible)
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
|
||||
// [NEW] Draw debris (from last destroyed enemies)
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
// [EXISTING] Draw completion message and score
|
||||
drawStageMessage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
drawScoreboard();
|
||||
drawLevelCompletedState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawEnemies() const {
|
||||
for (const auto& enemy : enemies_) {
|
||||
enemy.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawBullets() const {
|
||||
for (const auto& bullet : bullets_) {
|
||||
bullet.draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawActiveShipsAlive() const {
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
bool jugador_actiu = (i == 0) ? match_config_.jugador1_actiu : match_config_.jugador2_actiu;
|
||||
if (jugador_actiu && hit_timer_per_player_[i] == 0.0F) {
|
||||
ships_[i].draw();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawContinueState() {
|
||||
drawMargins();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
drawContinue();
|
||||
}
|
||||
|
||||
void GameScene::drawGameOverState() {
|
||||
drawMargins();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
|
||||
const std::string GAME_OVER_TEXT = "GAME OVER";
|
||||
constexpr float SCALE = Defaults::Game::GameOverScreen::TEXT_SCALE;
|
||||
constexpr float SPACING = Defaults::Game::GameOverScreen::TEXT_SPACING;
|
||||
|
||||
const SDL_FRect& play_area = Defaults::Zones::PLAYAREA;
|
||||
float centre_x = play_area.x + (play_area.w / 2.0F);
|
||||
float centre_y = play_area.y + (play_area.h / 2.0F);
|
||||
|
||||
text_.renderCentered(GAME_OVER_TEXT, {.x = centre_x, .y = centre_y}, SCALE, SPACING);
|
||||
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawInitHudState() {
|
||||
float timer = stage_manager_->getTransitionTimer();
|
||||
float total_time = Defaults::Game::INIT_HUD_DURATION;
|
||||
float global_progress = 1.0F - (timer / total_time);
|
||||
|
||||
float rect_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_RECT_RATIO_END);
|
||||
|
||||
float score_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SCORE_RATIO_END);
|
||||
|
||||
float ship1_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP1_RATIO_END);
|
||||
|
||||
float ship2_progress = Systems::InitHud::computeRangeProgress(
|
||||
global_progress,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_INIT,
|
||||
Defaults::Game::INIT_HUD_SHIP2_RATIO_END);
|
||||
|
||||
if (rect_progress > 0.0F) {
|
||||
if (!init_hud_rect_sound_played_) {
|
||||
Audio::get()->playSound(Defaults::Sound::INIT_HUD, Audio::Group::GAME);
|
||||
init_hud_rect_sound_played_ = true;
|
||||
}
|
||||
Systems::InitHud::drawBordersAnimated(sdl_.getRenderer(), rect_progress);
|
||||
}
|
||||
|
||||
if (score_progress > 0.0F) {
|
||||
Systems::InitHud::drawScoreboardAnimated(text_, buildScoreboard(), score_progress);
|
||||
}
|
||||
|
||||
if (ship1_progress > 0.0F && match_config_.jugador1_actiu && !ships_[0].isHit()) {
|
||||
ships_[0].draw();
|
||||
}
|
||||
|
||||
if (ship2_progress > 0.0F && match_config_.jugador2_actiu && !ships_[1].isHit()) {
|
||||
ships_[1].draw();
|
||||
}
|
||||
}
|
||||
|
||||
void GameScene::drawLevelStartState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawStageMessage(stage_manager_->getLevelStartMessage());
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawPlayingState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawEnemies();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::drawLevelCompletedState() {
|
||||
drawMargins();
|
||||
drawActiveShipsAlive();
|
||||
drawBullets();
|
||||
debris_manager_.draw();
|
||||
floating_score_manager_.draw();
|
||||
drawStageMessage(StageSystem::Constants::MISSATGE_LEVEL_COMPLETED);
|
||||
drawScoreboard();
|
||||
}
|
||||
|
||||
void GameScene::tocado(uint8_t player_id) {
|
||||
// Death sequence: 3 phases
|
||||
// Phase 1: First call (hit_timer_per_player_[player_id] == 0) - trigger explosion
|
||||
@@ -764,7 +727,7 @@ auto GameScene::buildScoreboard() const -> std::string {
|
||||
}
|
||||
|
||||
// Nivel (2 dígits)
|
||||
uint8_t stage_num = stage_manager_->get_stage_actual();
|
||||
uint8_t stage_num = stage_manager_->getCurrentStage();
|
||||
std::string stage_str = (stage_num < 10) ? "0" + std::to_string(stage_num)
|
||||
: std::to_string(stage_num);
|
||||
|
||||
@@ -801,7 +764,7 @@ void GameScene::drawStageMessage(const std::string& message) {
|
||||
float total_time;
|
||||
float typing_ratio;
|
||||
|
||||
if (stage_manager_->get_estat() == StageSystem::EstatStage::LEVEL_START) {
|
||||
if (stage_manager_->getState() == StageSystem::EstatStage::LEVEL_START) {
|
||||
total_time = Defaults::Game::LEVEL_START_DURATION;
|
||||
typing_ratio = Defaults::Game::LEVEL_START_TYPING_RATIO;
|
||||
} else { // LEVEL_COMPLETED
|
||||
@@ -810,7 +773,7 @@ void GameScene::drawStageMessage(const std::string& message) {
|
||||
}
|
||||
|
||||
// Calculate progress from timer (0.0 at start → 1.0 at end)
|
||||
float remaining_time = stage_manager_->get_timer_transicio();
|
||||
float remaining_time = stage_manager_->getTransitionTimer();
|
||||
float progress = 1.0F - (remaining_time / total_time);
|
||||
|
||||
// Determine how many characters to show
|
||||
@@ -834,7 +797,7 @@ void GameScene::drawStageMessage(const std::string& message) {
|
||||
// ===================================================
|
||||
|
||||
// Calculate text width at base scale (using FULL message for position calculation)
|
||||
float text_width_at_base = text_.get_text_width(message, BASE_SCALE, SPACING);
|
||||
float text_width_at_base = Graphics::VectorText::getTextWidth(message, BASE_SCALE, SPACING);
|
||||
|
||||
// Auto-scale if text exceeds max width
|
||||
float scale = (text_width_at_base <= MAX_WIDTH)
|
||||
@@ -842,8 +805,8 @@ void GameScene::drawStageMessage(const std::string& message) {
|
||||
: MAX_WIDTH / text_width_at_base;
|
||||
|
||||
// Recalculate dimensions with final scale (using FULL message for centering)
|
||||
float full_text_width = text_.get_text_width(message, scale, SPACING);
|
||||
float text_height = text_.get_text_height(scale);
|
||||
float full_text_width = Graphics::VectorText::getTextWidth(message, scale, SPACING);
|
||||
float text_height = Graphics::VectorText::getTextHeight(scale);
|
||||
|
||||
// Calculate position as if FULL text was there (for fixed position typewriter)
|
||||
float x = play_area.x + ((play_area.w - full_text_width) / 2.0F);
|
||||
@@ -862,7 +825,7 @@ auto GameScene::getSpawnPoint(uint8_t player_id) const -> Vec2 {
|
||||
const SDL_FRect& zona = Defaults::Zones::PLAYAREA;
|
||||
|
||||
float x_ratio;
|
||||
if (match_config_.es_un_jugador()) {
|
||||
if (match_config_.isSinglePlayer()) {
|
||||
// Un sol player: spawn al centro (50%)
|
||||
x_ratio = 0.5F;
|
||||
} else {
|
||||
@@ -901,7 +864,7 @@ void GameScene::fireBullet(uint8_t player_id) {
|
||||
// Buscar primera bullet inactiva en el pool del player
|
||||
int start_idx = player_id * 3; // P1=[0,1,2], P2=[3,4,5]
|
||||
for (int i = start_idx; i < start_idx + 3; i++) {
|
||||
if (!bullets_[i].esta_activa()) {
|
||||
if (!bullets_[i].isActive()) {
|
||||
bullets_[i].disparar(posicio_dispar, ship_angle, player_id);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user