bf83f161b0
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>
124 lines
4.8 KiB
C++
124 lines
4.8 KiB
C++
// 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>
|
|
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
|
|
#include "core/defaults.hpp"
|
|
#include "core/entities/entity.hpp"
|
|
#include "core/types.hpp"
|
|
#include "game/constants.hpp"
|
|
|
|
// Tipo de enemy
|
|
enum class EnemyType : uint8_t {
|
|
PENTAGON = 0, // Pentágono esquivador (zigzag)
|
|
QUADRAT = 1, // Cuadrado perseguidor (tracks ship)
|
|
MOLINILLO = 2 // Molinillo agressiu (fast, spinning)
|
|
};
|
|
|
|
// Estat de animación (palpitació i rotación 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 colisión
|
|
[[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 sin 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ón visual (rad/s)
|
|
float rotacio_; // Rotación 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 Cuadrado: time since last angle update
|
|
const Vec2* ship_position_; // Pointer to ship position (for tracking)
|
|
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
|
|
|
|
// [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);
|
|
};
|