ae5cc1cfb4
Tots els tipus d'entitat passen del catala a l'angles seguint el
.clang-tidy del projecte (tipus en CamelCase, metodes en camelBack,
membres en lower_case amb sufix _).
Renames de tipus:
- Entitat -> Entity (core/entities/entity.hpp)
- Nau -> Ship (game/entities/ship.{hpp,cpp})
- Enemic -> Enemy (game/entities/enemy.{hpp,cpp})
- Bala -> Bullet (game/entities/bullet.{hpp,cpp})
- TipusEnemic -> EnemyType
- AnimacioEnemic -> EnemyAnimation
Metodes virtuals (s'aplica a tot el codi, no nomes a entitats):
- actualitzar -> update
- dibuixar -> draw
- inicialitzar -> init
- processar_input -> processInput
- esta_actiu -> isActive
- es_collidable -> isCollidable
- get_collision_radius -> getCollisionRadius
Getters comuns:
- get_centre -> getCenter
- get_angle -> getAngle
- get_brightness -> getBrightness
- get_forma -> getShape
Metodes especifics:
- esta_viva -> isAlive
- esta_tocada -> isHit
- es_invulnerable -> isInvulnerable
- get_velocitat_vector -> getVelocityVector
- set_centre -> setCenter
- marcar_tocada -> markHit
- aplicar_fisica -> applyPhysics
- get_tipus -> getType
Camps privats:
- centre_ -> center_
- velocitat_ -> velocity_
- forma_ -> shape_
- esta_tocada_ -> is_hit_
- tipus_ -> type_
L'import d'audio/input d'AEEA quedara coherent (mateix estil).
Diff net: 30 fitxers, +437/-437 (la majoria es renames simetrics).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
124 lines
4.8 KiB
C++
124 lines
4.8 KiB
C++
// enemic.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'enemic
|
|
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 tipus, 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);
|
|
};
|