// 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 #include #include #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); };