7ee359b910
Sweep final del naming a CamelCase/camelBack/lower_case:
Fitxers renombrats:
- effects/gestor_puntuacio_flotant.{hpp,cpp} -> floating_score_manager.{hpp,cpp}
- effects/puntuacio_flotant.hpp -> floating_score.hpp
Tipus (CamelCase):
- GestorPuntuacioFlotant -> FloatingScoreManager
- PuntuacioFlotant -> FloatingScore
- ConfigStage -> StageConfig
- ConfigSistemaStages -> StageSystemConfig
- NauTitol -> TitleShip
- EstatNau -> ShipState
Metodes publics (camelBack):
- obte_renderer -> getRenderer
- get_num_actius -> getActiveCount
- calcular_direccio_explosio -> computeExplosionDirection
- trobar_slot_lliure -> findFreeSlot
- explotar -> explode
- reiniciar -> reset
- es_valida -> isValid
- parsejar_fitxer -> parseFile
- carregar -> load
- crear_explosio -> createExplosion
- registrar_puntuacio -> registerScore
- construir_marcador -> buildScoreboard
- render_centered -> renderCentered
Camps struct publics (snake_case):
- actiu/actius -> active
- rotacio -> rotation, rotacio_visual -> visual_rotation
- acceleracio -> acceleration
- velocitat -> velocity
- escala/escala_inicial/objectiu/actual -> scale/initial_scale/...
- posicio/posicio_inicial/objectiu/actual -> position/initial_position/...
- fase_oscilacio -> oscillation_phase
- temps_estat -> state_time
- jugador_id -> player_id
- estat -> state
- brillantor -> brightness
- tipus -> type
Camps privats (sufix _):
- naus_ -> ships_, orni_ -> enemies_, bales_ -> bullets_
- gestor_puntuacio_ -> floating_score_manager_
- punt_mort_ -> death_position_, punt_spawn_ -> spawn_position_
- itocado_per_jugador_ -> hit_timer_per_player_
- vides_per_jugador_ -> lives_per_player_
- puntuacio_per_jugador_ -> score_per_player_
- estat_game_over_ -> game_over_state_
- continues_usados_ -> continues_used_
Constants:
- MARGE_ESQ/DRET/DALT/BAIX -> MARGIN_LEFT/RIGHT/TOP/BOTTOM
Variables locals i parametres comuns (snake_case):
- nau -> ship, enemic -> enemy, bala -> bullet
- forma -> shape, punt(s) -> point(s)
- jugador -> player, partida -> match
- temps -> time, missatge -> message
Diff: 59 fitxers, +1000/-1000 (simetric). Compila i enllaça.
Pendents per a futures fases (no bloquejants):
- Comentaris de capçalera en catala -> castella
- Variables locals/parametres minoritaris en catala
- Include guards (queden alguns #ifndef en lloc de #pragma once)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
124 lines
4.8 KiB
C++
124 lines
4.8 KiB
C++
// enemy.hpp - Classe per a enemics (ORNIs pentàgons)
|
|
// © 1999 Visente i Sergi (versió Pascal)
|
|
// © 2025 Port a C++20 amb SDL3
|
|
|
|
#pragma once
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
|
|
#include "core/defaults.hpp"
|
|
#include "core/entities/entity.hpp"
|
|
#include "core/types.hpp"
|
|
#include "game/constants.hpp"
|
|
|
|
// Tipus d'enemy
|
|
enum class EnemyType : uint8_t {
|
|
PENTAGON = 0, // Pentàgon esquivador (zigzag)
|
|
QUADRAT = 1, // Quadrat perseguidor (tracks ship)
|
|
MOLINILLO = 2 // Molinillo agressiu (fast, spinning)
|
|
};
|
|
|
|
// Estat d'animació (palpitació i rotació accelerada)
|
|
struct EnemyAnimation {
|
|
// Palpitation (breathing effect)
|
|
bool palpitacio_activa = false;
|
|
float palpitacio_fase = 0.0F; // Phase in cycle (0.0-2π)
|
|
float palpitacio_frequencia = 2.0F; // Hz (cycles per second)
|
|
float palpitacio_amplitud = 0.15F; // Scale variation (±15%)
|
|
float palpitacio_temps_restant = 0.0F; // Time remaining (seconds)
|
|
|
|
// Rotation acceleration (long-term spin modulation)
|
|
float drotacio_base = 0.0F; // Base rotation speed (rad/s)
|
|
float drotacio_objetivo = 0.0F; // Target rotation speed (rad/s)
|
|
float drotacio_t = 0.0F; // Interpolation progress (0.0-1.0)
|
|
float drotacio_duracio = 0.0F; // Duration of transition (seconds)
|
|
};
|
|
|
|
class Enemy : public Entities::Entity {
|
|
public:
|
|
Enemy()
|
|
: Entity(nullptr) {}
|
|
Enemy(SDL_Renderer* renderer);
|
|
|
|
void init() override { init(EnemyType::PENTAGON, nullptr); }
|
|
void init(EnemyType type, const Vec2* ship_pos = nullptr);
|
|
void update(float delta_time) override;
|
|
void draw() const override;
|
|
|
|
// Override: Interfície d'Entity
|
|
[[nodiscard]] bool isActive() const override { return esta_; }
|
|
|
|
// Override: Interfície de col·lisió
|
|
[[nodiscard]] float getCollisionRadius() const override {
|
|
return Defaults::Entities::ENEMY_RADIUS;
|
|
}
|
|
[[nodiscard]] bool isCollidable() const override {
|
|
return esta_ && timer_invulnerabilitat_ <= 0.0F;
|
|
}
|
|
|
|
// Getters (API pública sense canvis)
|
|
void destruir() { esta_ = false; }
|
|
[[nodiscard]] float get_drotacio() const { return drotacio_; }
|
|
[[nodiscard]] Vec2 getVelocityVector() const {
|
|
return {
|
|
.x = velocity_ * std::cos(angle_ - (Constants::PI / 2.0F)),
|
|
.y = velocity_ * std::sin(angle_ - (Constants::PI / 2.0F))};
|
|
}
|
|
|
|
// Set ship position reference for tracking behavior
|
|
void set_ship_position(const Vec2* ship_pos) { ship_position_ = ship_pos; }
|
|
|
|
// [NEW] Getters for stage system (base stats)
|
|
[[nodiscard]] float get_base_velocity() const;
|
|
[[nodiscard]] float get_base_rotation() const;
|
|
[[nodiscard]] EnemyType getType() const { return type_; }
|
|
|
|
// [NEW] Setters for difficulty multipliers (stage system)
|
|
void set_velocity(float vel) { velocity_ = vel; }
|
|
void set_rotation(float rot) {
|
|
drotacio_ = rot;
|
|
animacio_.drotacio_base = rot;
|
|
}
|
|
void set_tracking_strength(float strength);
|
|
|
|
// [NEW] Invulnerability queries
|
|
[[nodiscard]] bool isInvulnerable() const { return timer_invulnerabilitat_ > 0.0F; }
|
|
[[nodiscard]] float get_temps_invulnerabilitat() const { return timer_invulnerabilitat_; }
|
|
|
|
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
|
|
bool esta_;
|
|
|
|
// [NEW] Enemy type and configuration
|
|
EnemyType type_;
|
|
|
|
// [NEW] Animation state
|
|
EnemyAnimation animacio_;
|
|
|
|
// [NEW] Behavior state (type-specific)
|
|
float tracking_timer_; // For Quadrat: 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
|
|
|
|
// [NEW] Invulnerability state
|
|
float timer_invulnerabilitat_; // Countdown timer (seconds), 0.0f = vulnerable
|
|
|
|
// [EXISTING] Private methods
|
|
void mou(float delta_time);
|
|
|
|
// [NEW] Private methods
|
|
void actualitzar_animacio(float delta_time);
|
|
void actualitzar_palpitacio(float delta_time);
|
|
void actualitzar_rotacio_accelerada(float delta_time);
|
|
void comportament_pentagon(float delta_time);
|
|
void comportament_quadrat(float delta_time);
|
|
void comportament_molinillo(float delta_time);
|
|
[[nodiscard]] float calcular_escala_actual() const; // Returns scale with palpitation applied
|
|
bool intent_spawn_safe(const Vec2& ship_pos, float& out_x, float& out_y);
|
|
};
|