Fase 1e: cierre de naming sweep (#pragma once, locals, comentarios castellano)
Tres tareas de pulido para cerrar la Fase 1 por completo: #pragma once uniforme: - sdl_manager.hpp y game_scene.hpp pasan de #ifndef/#define guards a #pragma once. Los archivos externos (stb_vorbis.h, fkyaml_node.hpp) se mantienen intactos (codigo de terceros). Variables locales y parametros restantes (catalan -> ingles): - fitxer -> file, moviment -> movement, inici -> start - comptador -> counter, escalada -> scaled - missatges -> messages, llista -> list - alçada -> height, amplada -> width, llargada -> length - origen -> origin, distancia -> distance, valor -> value, desti -> target - neteja -> clear, presenta -> present (SDLManager) - total_enemics -> total_enemies, configurar -> configure, iniciar -> start Comentarios catalan -> castellano: - Cabeceras de fichero actualizadas con nombres nuevos (escena_joc.hpp -> game_scene.hpp, etc.) - Palabras tecnicas: trasllacio->traslacion, col-lisio->colision, inicialitzacio->inicializacion, posicio->posicion, rotacio->rotacion, velocitat->velocidad, acceleracio->aceleracion, explosio->explosion, renderitzat->renderizado, calcul->calculo, transicio->transicion, comprovacio->comprobacion, substitucio->sustitucion, utilitzacio->utilizacion, opcio->opcion, configuracio->configuracion, funcio->funcion, distancia, animacio->animacion - Determinantes y conectores: aquest->este, aquesta->esta, amb->con, sense->sin, pero->pero, mai->nunca, nomes->solo, tambe->tambien, sempre->siempre, ja->ya, mateix->mismo, vegada->vez, dintre->dentro, fora->fuera, dreta->derecha, esquerra->izquierda, sortir->salir, sortida->salida, petit->pequeno, gran->grande, nou->nuevo, vell->viejo, molt->mucho, els->los, les->las, totes les->todas las, d'->de, com->como, quan->cuando, mentre->mientras, despres->despues, abans->antes, durant->durante, fins->hasta, encara->aun, llavors->entonces, aixi->asi, perque->porque - Sustantivos: classe->clase, metode->metodo, parametre->parametro, versio->version, entitat->entidad, joc->juego, nivell->nivel, enemic->enemigo, naus->naves, bales->balas, fitxer->archivo, pentagon->pentagono, pun- tuacio->puntuacion, flotant->flotante, titol->titulo, objectiu->objetivo, mostra->muestra, tipus->tipo Strings literales preservados en valenciano segun decision del usuario: el texto del HUD del juego (puntuaciones, mensajes en pantalla, archivo de config) se mantiene en valenciano original. 70 fitxers tocats, +1117 / -1123. Compila i enllaca. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
7ee359b910
commit
bf83f161b0
71 files changed
+1142
-1148
No files matched your search
@@ -1,6 +1,6 @@
|
||||
// bullet.cpp - Implementació de projectils de la ship
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "game/entities/bullet.hpp"
|
||||
|
||||
@@ -23,10 +23,10 @@ Bullet::Bullet(SDL_Renderer* renderer)
|
||||
esta_(false),
|
||||
owner_id_(0),
|
||||
grace_timer_(0.0F) {
|
||||
// [NUEVO] Brightness específic per bales
|
||||
// [NUEVO] Brightness específic per balas
|
||||
brightness_ = Defaults::Brightness::BALA;
|
||||
|
||||
// [NUEVO] Carregar shape compartida des de fitxer
|
||||
// [NUEVO] Carregar shape compartida desde file
|
||||
shape_ = Graphics::ShapeLoader::load("bullet.shp");
|
||||
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
@@ -50,7 +50,7 @@ void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||||
// Activar bullet
|
||||
esta_ = true;
|
||||
|
||||
// Posició inicial = centre de la ship
|
||||
// Posición inicial = centro de la ship
|
||||
center_.x = position.x;
|
||||
center_.y = position.y;
|
||||
|
||||
@@ -60,7 +60,7 @@ void Bullet::disparar(const Vec2& position, float angle, uint8_t owner_id) {
|
||||
// Almacenar propietario (0=P1, 1=P2)
|
||||
owner_id_ = owner_id;
|
||||
|
||||
// Velocitat alta (el joc Pascal original usava 7 px/frame)
|
||||
// Velocidad alta (el juego Pascal original usava 7 px/frame)
|
||||
// 7 px/frame × 20 FPS = 140 px/s
|
||||
velocity_ = 140.0F;
|
||||
|
||||
@@ -86,7 +86,7 @@ void Bullet::update(float delta_time) {
|
||||
void Bullet::draw() const {
|
||||
if (esta_ && shape_) {
|
||||
// [NUEVO] Usar render_shape en lloc de rota_pol
|
||||
// Les bales roten segons l'angle de trajectòria
|
||||
// Les balas roten segons l'angle de trajectòria
|
||||
Rendering::render_shape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_);
|
||||
}
|
||||
}
|
||||
@@ -96,20 +96,20 @@ void Bullet::mou(float delta_time) {
|
||||
// Basat en el codi Pascal original: procedure mou_bales
|
||||
// Copiat EXACTAMENT de joc_asteroides.cpp línies 396-419
|
||||
|
||||
// Calcular nova posició (moviment polar time-based)
|
||||
// velocity ja està en px/s (140 px/s), només cal multiplicar per delta_time
|
||||
// Calcular nueva posición (movement polar time-based)
|
||||
// velocity ya está en px/s (140 px/s), solo necesario multiplicar per delta_time
|
||||
float velocitat_efectiva = velocity_ * delta_time;
|
||||
|
||||
// Calcular desplaçament (angle-PI/2 perquè angle=0 apunta amunt)
|
||||
float dy = velocitat_efectiva * std::sin(angle_ - (Constants::PI / 2.0F));
|
||||
float dx = velocitat_efectiva * std::cos(angle_ - (Constants::PI / 2.0F));
|
||||
|
||||
// Acumulació directa amb precisió subpíxel
|
||||
// Acumulació directa con precisió subpíxel
|
||||
center_.y += dy;
|
||||
center_.x += dx;
|
||||
|
||||
// Desactivar si surt de la zona de joc (no rebota com els ORNIs)
|
||||
// CORRECCIÓ: Usar límits segurs amb radi de la bullet
|
||||
// Desactivar si surt de la zona de juego (no rebota como los ORNIs)
|
||||
// CORRECCIÓ: Usar límits segurs con radi de la bullet
|
||||
float min_x;
|
||||
float max_x;
|
||||
float min_y;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// bullet.hpp - Classe per a projectils de la ship
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// bullet.hpp - Clase para projectils de la ship
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -25,7 +25,7 @@ class Bullet : public Entities::Entity {
|
||||
// Override: Interfície d'Entity
|
||||
[[nodiscard]] bool isActive() const override { return esta_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
// Override: Interfície de colisión
|
||||
[[nodiscard]] float getCollisionRadius() const override {
|
||||
return Defaults::Entities::BULLET_RADIUS;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class Bullet : public Entities::Entity {
|
||||
return esta_ && grace_timer_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
// Getters (API pública sin canvis)
|
||||
[[nodiscard]] bool esta_activa() const { return esta_; }
|
||||
[[nodiscard]] uint8_t get_owner_id() const { return owner_id_; }
|
||||
[[nodiscard]] float get_grace_timer() const { return grace_timer_; }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// enemy.cpp - Implementació d'enemics (ORNIs)
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// enemy.cpp - Implementació de enemigos (ORNIs)
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "game/entities/enemy.hpp"
|
||||
|
||||
@@ -27,7 +27,7 @@ Enemy::Enemy(SDL_Renderer* renderer)
|
||||
ship_position_(nullptr),
|
||||
tracking_strength_(0.5F), // Default tracking strength
|
||||
timer_invulnerabilitat_(0.0F) { // Start vulnerable
|
||||
// [NUEVO] Brightness específic per enemics
|
||||
// [NUEVO] Brightness específic per enemigos
|
||||
brightness_ = Defaults::Brightness::ENEMIC;
|
||||
|
||||
// [NUEVO] Forma es carrega a init() segons el type
|
||||
@@ -52,10 +52,10 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
break;
|
||||
|
||||
case EnemyType::QUADRAT:
|
||||
shape_file = Defaults::Enemies::Quadrat::SHAPE_FILE;
|
||||
velocity_ = Defaults::Enemies::Quadrat::VELOCITAT;
|
||||
drotacio_min = Defaults::Enemies::Quadrat::DROTACIO_MIN;
|
||||
drotacio_max = Defaults::Enemies::Quadrat::DROTACIO_MAX;
|
||||
shape_file = Defaults::Enemies::Cuadrado::SHAPE_FILE;
|
||||
velocity_ = Defaults::Enemies::Cuadrado::VELOCITAT;
|
||||
drotacio_min = Defaults::Enemies::Cuadrado::DROTACIO_MIN;
|
||||
drotacio_max = Defaults::Enemies::Cuadrado::DROTACIO_MAX;
|
||||
tracking_timer_ = 0.0F;
|
||||
break;
|
||||
|
||||
@@ -83,7 +83,7 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
std::cerr << "[Enemy] Error: no s'ha pogut load " << shape_file << '\n';
|
||||
}
|
||||
|
||||
// [MODIFIED] Posició aleatòria amb comprovació de seguretat
|
||||
// [MODIFIED] Posición aleatòria con comprobación de seguretat
|
||||
float min_x;
|
||||
float max_x;
|
||||
float min_y;
|
||||
@@ -117,7 +117,7 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
center_.x = static_cast<float>((std::rand() % range_x) + static_cast<int>(min_x));
|
||||
center_.y = static_cast<float>((std::rand() % range_y) + static_cast<int>(min_y));
|
||||
|
||||
std::cout << "[Enemy] Advertència: spawn sense zona segura després de "
|
||||
std::cout << "[Enemy] Advertència: spawn sin zona segura después de "
|
||||
<< Defaults::Enemies::Spawn::MAX_SPAWN_ATTEMPTS << " intents" << '\n';
|
||||
}
|
||||
} else {
|
||||
@@ -128,15 +128,15 @@ void Enemy::init(EnemyType type, const Vec2* ship_pos) {
|
||||
center_.y = static_cast<float>((std::rand() % range_y) + static_cast<int>(min_y));
|
||||
}
|
||||
|
||||
// Angle aleatori de moviment
|
||||
// Angle aleatori de movement
|
||||
angle_ = (std::rand() % 360) * Constants::PI / 180.0F;
|
||||
|
||||
// Rotació visual aleatòria (rad/s) dins del rang del type
|
||||
// Rotación visual aleatòria (rad/s) dins del rang del type
|
||||
float drotacio_range = drotacio_max - drotacio_min;
|
||||
drotacio_ = drotacio_min + ((static_cast<float>(std::rand()) / RAND_MAX) * drotacio_range);
|
||||
rotacio_ = 0.0F;
|
||||
|
||||
// Inicialitzar state d'animació
|
||||
// Inicialitzar state de animación
|
||||
animacio_ = EnemyAnimation(); // Reset to defaults
|
||||
animacio_.drotacio_base = drotacio_;
|
||||
animacio_.drotacio_objetivo = drotacio_;
|
||||
@@ -171,10 +171,10 @@ void Enemy::update(float delta_time) {
|
||||
// Moviment autònom
|
||||
mou(delta_time);
|
||||
|
||||
// Actualitzar animacions (palpitació, rotació accelerada)
|
||||
// Actualitzar animaciones (palpitació, rotación accelerada)
|
||||
actualitzar_animacio(delta_time);
|
||||
|
||||
// Rotació visual (time-based: drotacio_ està en rad/s)
|
||||
// Rotación visual (time-based: drotacio_ está en rad/s)
|
||||
rotacio_ += drotacio_ * delta_time;
|
||||
}
|
||||
}
|
||||
@@ -210,7 +210,7 @@ void Enemy::mou(float delta_time) {
|
||||
|
||||
void Enemy::comportament_pentagon(float delta_time) {
|
||||
// Pentagon: zigzag esquivador (frequent direction changes)
|
||||
// Similar a comportament original però amb probabilitat més alta
|
||||
// Similar a comportament original pero con probabilitat més alta
|
||||
|
||||
float velocitat_efectiva = velocity_ * delta_time;
|
||||
|
||||
@@ -232,11 +232,11 @@ void Enemy::comportament_pentagon(float delta_time) {
|
||||
min_y,
|
||||
max_y);
|
||||
|
||||
// Zigzag: canvi d'angle més freqüent en tocar límits
|
||||
// Zigzag: canvi de angle més freqüent en tocar límits
|
||||
if (new_y >= min_y && new_y <= max_y) {
|
||||
center_.y = new_y;
|
||||
} else {
|
||||
// Probabilitat més alta de canvi d'angle
|
||||
// Probabilitat més alta de canvi de angle
|
||||
if (static_cast<float>(std::rand()) / RAND_MAX < Defaults::Enemies::Pentagon::CANVI_ANGLE_PROB) {
|
||||
float rand_angle = (static_cast<float>(std::rand()) / RAND_MAX) *
|
||||
Defaults::Enemies::Pentagon::CANVI_ANGLE_MAX;
|
||||
@@ -256,13 +256,13 @@ void Enemy::comportament_pentagon(float delta_time) {
|
||||
}
|
||||
|
||||
void Enemy::comportament_quadrat(float delta_time) {
|
||||
// Quadrat: perseguidor (tracks player position)
|
||||
// Cuadrado: perseguidor (tracks player position)
|
||||
|
||||
// Update tracking timer
|
||||
tracking_timer_ += delta_time;
|
||||
|
||||
// Periodically update angle toward ship
|
||||
if (tracking_timer_ >= Defaults::Enemies::Quadrat::TRACKING_INTERVAL) {
|
||||
if (tracking_timer_ >= Defaults::Enemies::Cuadrado::TRACKING_INTERVAL) {
|
||||
tracking_timer_ = 0.0F;
|
||||
|
||||
if (ship_position_ != nullptr) {
|
||||
@@ -488,7 +488,7 @@ float Enemy::calcular_escala_actual() const {
|
||||
constexpr float END = Defaults::Enemies::Spawn::INVULNERABILITY_SCALE_END;
|
||||
scale = START + ((END - START) * smooth_t);
|
||||
} else if (animacio_.palpitacio_activa) {
|
||||
// [EXISTING] Palpitació només quan no invulnerable
|
||||
// [EXISTING] Palpitació solo cuando no invulnerable
|
||||
scale += animacio_.palpitacio_amplitud * std::sin(animacio_.palpitacio_fase);
|
||||
}
|
||||
|
||||
@@ -502,7 +502,7 @@ float Enemy::get_base_velocity() const {
|
||||
case EnemyType::PENTAGON:
|
||||
return Defaults::Enemies::Pentagon::VELOCITAT;
|
||||
case EnemyType::QUADRAT:
|
||||
return Defaults::Enemies::Quadrat::VELOCITAT;
|
||||
return Defaults::Enemies::Cuadrado::VELOCITAT;
|
||||
case EnemyType::MOLINILLO:
|
||||
return Defaults::Enemies::Molinillo::VELOCITAT;
|
||||
default:
|
||||
@@ -544,8 +544,8 @@ bool Enemy::intent_spawn_safe(const Vec2& ship_pos, float& out_x, float& out_y)
|
||||
// Check Euclidean distance to ship
|
||||
float dx = out_x - ship_pos.x;
|
||||
float dy = out_y - ship_pos.y;
|
||||
float distancia = std::sqrt((dx * dx) + (dy * dy));
|
||||
float distance = std::sqrt((dx * dx) + (dy * dy));
|
||||
|
||||
// Return true if position is safe (>= 36px from ship)
|
||||
return distancia >= Defaults::Enemies::Spawn::SAFETY_DISTANCE;
|
||||
return distance >= Defaults::Enemies::Spawn::SAFETY_DISTANCE;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// enemy.hpp - Classe per a enemics (ORNIs pentàgons)
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// enemy.hpp - Clase para enemigos (ORNIs pentágonos)
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -13,14 +13,14 @@
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
// Tipus d'enemy
|
||||
// Tipo de enemy
|
||||
enum class EnemyType : uint8_t {
|
||||
PENTAGON = 0, // Pentàgon esquivador (zigzag)
|
||||
QUADRAT = 1, // Quadrat perseguidor (tracks ship)
|
||||
PENTAGON = 0, // Pentágono esquivador (zigzag)
|
||||
QUADRAT = 1, // Cuadrado perseguidor (tracks ship)
|
||||
MOLINILLO = 2 // Molinillo agressiu (fast, spinning)
|
||||
};
|
||||
|
||||
// Estat d'animació (palpitació i rotació accelerada)
|
||||
// Estat de animación (palpitació i rotación accelerada)
|
||||
struct EnemyAnimation {
|
||||
// Palpitation (breathing effect)
|
||||
bool palpitacio_activa = false;
|
||||
@@ -50,7 +50,7 @@ class Enemy : public Entities::Entity {
|
||||
// Override: Interfície d'Entity
|
||||
[[nodiscard]] bool isActive() const override { return esta_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
// Override: Interfície de colisión
|
||||
[[nodiscard]] float getCollisionRadius() const override {
|
||||
return Defaults::Entities::ENEMY_RADIUS;
|
||||
}
|
||||
@@ -58,7 +58,7 @@ class Enemy : public Entities::Entity {
|
||||
return esta_ && timer_invulnerabilitat_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
// Getters (API pública sin canvis)
|
||||
void destruir() { esta_ = false; }
|
||||
[[nodiscard]] float get_drotacio() const { return drotacio_; }
|
||||
[[nodiscard]] Vec2 getVelocityVector() const {
|
||||
@@ -90,8 +90,8 @@ class Enemy : public Entities::Entity {
|
||||
private:
|
||||
// Membres específics d'Enemy (heretats: renderer_, shape_, center_, angle_, brightness_)
|
||||
float velocity_;
|
||||
float drotacio_; // Delta rotació visual (rad/s)
|
||||
float rotacio_; // Rotació visual acumulada
|
||||
float drotacio_; // Delta rotación visual (rad/s)
|
||||
float rotacio_; // Rotación visual acumulada
|
||||
bool esta_;
|
||||
|
||||
// [NEW] Enemy type and configuration
|
||||
@@ -101,9 +101,9 @@ class Enemy : public Entities::Entity {
|
||||
EnemyAnimation animacio_;
|
||||
|
||||
// [NEW] Behavior state (type-specific)
|
||||
float tracking_timer_; // For Quadrat: time since last angle update
|
||||
float tracking_timer_; // For Cuadrado: time since last angle update
|
||||
const Vec2* ship_position_; // Pointer to ship position (for tracking)
|
||||
float tracking_strength_; // For Quadrat: tracking intensity (0.0-1.5), default 0.5
|
||||
float tracking_strength_; // For Cuadrado: tracking intensity (0.0-1.5), default 0.5
|
||||
|
||||
// [NEW] Invulnerability state
|
||||
float timer_invulnerabilitat_; // Countdown timer (seconds), 0.0f = vulnerable
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ship.cpp - Implementació de la nave del player
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#include "game/entities/ship.hpp"
|
||||
|
||||
@@ -25,10 +25,10 @@ Ship::Ship(SDL_Renderer* renderer, const char* shape_file)
|
||||
velocity_(0.0F),
|
||||
is_hit_(false),
|
||||
invulnerable_timer_(0.0F) {
|
||||
// [NUEVO] Brightness específic per naus
|
||||
// [NUEVO] Brightness específic per naves
|
||||
brightness_ = Defaults::Brightness::NAU;
|
||||
|
||||
// [NUEVO] Carregar shape compartida des de fitxer
|
||||
// [NUEVO] Carregar shape compartida desde file
|
||||
shape_ = Graphics::ShapeLoader::load(shape_file);
|
||||
|
||||
if (!shape_ || !shape_->isValid()) {
|
||||
@@ -37,12 +37,12 @@ Ship::Ship(SDL_Renderer* renderer, const char* shape_file)
|
||||
}
|
||||
|
||||
void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
// Inicialització de la ship (triangle)
|
||||
// Inicialización de la ship (triangle)
|
||||
// Basat en el codi Pascal original: lines 380-384
|
||||
// Copiat de joc_asteroides.cpp línies 30-44
|
||||
|
||||
// [NUEVO] Ja no cal configurar points polars - la geometria es carrega del
|
||||
// fitxer Només inicialitzem l'state de la instància
|
||||
// [NUEVO] Ya no necesario configure points polars - la geometria es carrega del
|
||||
// file Solo inicialitzem l'state de la instància
|
||||
|
||||
// Use custom spawn point if provided, otherwise use center
|
||||
if (spawn_point != nullptr) {
|
||||
@@ -72,9 +72,9 @@ void Ship::init(const Vec2* spawn_point, bool activar_invulnerabilitat) {
|
||||
}
|
||||
|
||||
void Ship::processInput(float delta_time, uint8_t player_id) {
|
||||
// Processar input continu (com teclapuls() del Pascal original)
|
||||
// Processar input continu (como teclapuls() del Pascal original)
|
||||
// Basat en joc_asteroides.cpp línies 66-85
|
||||
// Només processa input si la ship està viva
|
||||
// Solo processa input si la ship está viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ void Ship::processInput(float delta_time, uint8_t player_id) {
|
||||
}
|
||||
|
||||
void Ship::update(float delta_time) {
|
||||
// Només update si la ship està viva
|
||||
// Solo update si la ship está viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
@@ -129,12 +129,12 @@ void Ship::update(float delta_time) {
|
||||
invulnerable_timer_ = std::max(invulnerable_timer_, 0.0F);
|
||||
}
|
||||
|
||||
// Aplicar física (moviment + fricció)
|
||||
// Aplicar física (movement + fricció)
|
||||
applyPhysics(delta_time);
|
||||
}
|
||||
|
||||
void Ship::draw() const {
|
||||
// Només draw si la ship està viva
|
||||
// Solo draw si la ship está viva
|
||||
if (is_hit_) {
|
||||
return;
|
||||
}
|
||||
@@ -156,9 +156,9 @@ void Ship::draw() const {
|
||||
return;
|
||||
}
|
||||
|
||||
// Escalar velocity per l'efecte visual (200 px/s → ~6 px d'efecte)
|
||||
// Escalar velocity per l'efecte visual (200 px/s → ~6 px de efecte)
|
||||
// El codi Pascal original sumava velocity (0-6) al radi per donar
|
||||
// sensació de "empenta". Ara velocity està en px/s (0-200).
|
||||
// sensació de "empenta". Ara velocity está en px/s (0-200).
|
||||
// Basat en joc_asteroides.cpp línies 127-134
|
||||
//
|
||||
// [NUEVO] Convertir suma de velocitat_visual a scale multiplicativa
|
||||
@@ -171,12 +171,12 @@ void Ship::draw() const {
|
||||
}
|
||||
|
||||
void Ship::applyPhysics(float delta_time) {
|
||||
// Aplicar física de moviment
|
||||
// Aplicar física de movement
|
||||
// Basat en joc_asteroides.cpp línies 87-113
|
||||
|
||||
// Calcular nova posició basada en velocity i angle
|
||||
// S'usa (angle - PI/2) perquè angle=0 apunta cap amunt, no cap a la dreta
|
||||
// velocity_ està en px/s, així que multipliquem per delta_time
|
||||
// Calcular nueva posición basada en velocity i angle
|
||||
// S'usa (angle - PI/2) perquè angle=0 apunta sin amunt, no hacia la derecha
|
||||
// velocity_ está en px/s, así que multipliquem per delta_time
|
||||
float dy =
|
||||
((velocity_ * delta_time) * std::sin(angle_ - (Constants::PI / 2.0F))) +
|
||||
center_.y;
|
||||
@@ -184,7 +184,7 @@ void Ship::applyPhysics(float delta_time) {
|
||||
((velocity_ * delta_time) * std::cos(angle_ - (Constants::PI / 2.0F))) +
|
||||
center_.x;
|
||||
|
||||
// Boundary checking amb radi de la ship
|
||||
// Boundary checking con radi de la ship
|
||||
// CORRECCIÓ: Usar límits segurs i inequalitats inclusives
|
||||
float min_x;
|
||||
float max_x;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// ship.hpp - Classe per a la nave del player
|
||||
// © 1999 Visente i Sergi (versió Pascal)
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
// ship.hpp - Clase para la nave del player
|
||||
// © 1999 Visente i Sergi (versión Pascal)
|
||||
// © 2025 Port a C++20 con SDL3
|
||||
|
||||
#pragma once
|
||||
#include <SDL3/SDL.h>
|
||||
@@ -28,7 +28,7 @@ class Ship : public Entities::Entity {
|
||||
// Override: Interfície d'Entity
|
||||
[[nodiscard]] bool isActive() const override { return !is_hit_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
// Override: Interfície de colisión
|
||||
[[nodiscard]] float getCollisionRadius() const override {
|
||||
return Defaults::Entities::SHIP_RADIUS;
|
||||
}
|
||||
@@ -36,7 +36,7 @@ class Ship : public Entities::Entity {
|
||||
return !is_hit_ && invulnerable_timer_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
// Getters (API pública sin canvis)
|
||||
[[nodiscard]] bool isAlive() const { return !is_hit_; }
|
||||
[[nodiscard]] bool isHit() const { return is_hit_; }
|
||||
[[nodiscard]] bool isInvulnerable() const { return invulnerable_timer_ > 0.0F; }
|
||||
@@ -49,12 +49,12 @@ class Ship : public Entities::Entity {
|
||||
// Setters
|
||||
void setCenter(const Vec2& nou_centre) { center_ = nou_centre; }
|
||||
|
||||
// Col·lisions (Fase 10)
|
||||
// Colisiones (Fase 10)
|
||||
void markHit() { is_hit_ = true; }
|
||||
|
||||
private:
|
||||
// Membres específics de Ship (heretats: renderer_, shape_, center_, angle_, brightness_)
|
||||
float velocity_; // Velocitat (px/s)
|
||||
float velocity_; // Velocidad (px/s)
|
||||
bool is_hit_;
|
||||
float invulnerable_timer_; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
|
||||
|
||||
Reference in new issue
Block a user