feat: implementar jerarquia d'entitats amb classe base Entitat
This commit is contained in:
@@ -6,22 +6,26 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/audio/audio.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/graphics/shape_loader.hpp"
|
||||
#include "core/rendering/shape_renderer.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
Bala::Bala(SDL_Renderer* renderer)
|
||||
: renderer_(renderer),
|
||||
centre_({.x = 0.0F, .y = 0.0F}),
|
||||
angle_(0.0F),
|
||||
: Entitat(renderer),
|
||||
velocitat_(0.0F),
|
||||
esta_(false),
|
||||
grace_timer_(0.0F),
|
||||
brightness_(Defaults::Brightness::BALA) {
|
||||
owner_id_(0),
|
||||
grace_timer_(0.0F) {
|
||||
// [NUEVO] Brightness específic per bales
|
||||
brightness_ = Defaults::Brightness::BALA;
|
||||
|
||||
// [NUEVO] Carregar forma compartida des de fitxer
|
||||
forma_ = Graphics::ShapeLoader::load("bullet.shp");
|
||||
|
||||
|
||||
@@ -6,43 +6,45 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
class Bala {
|
||||
class Bala : public Entities::Entitat {
|
||||
public:
|
||||
Bala()
|
||||
: renderer_(nullptr) {}
|
||||
: Entitat(nullptr) {}
|
||||
Bala(SDL_Renderer* renderer);
|
||||
|
||||
void inicialitzar();
|
||||
void inicialitzar() override;
|
||||
void disparar(const Punt& posicio, float angle, uint8_t owner_id);
|
||||
void actualitzar(float delta_time);
|
||||
void dibuixar() const;
|
||||
void actualitzar(float delta_time) override;
|
||||
void dibuixar() const override;
|
||||
|
||||
// Override: Interfície d'Entitat
|
||||
[[nodiscard]] bool esta_actiu() const override { return esta_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
[[nodiscard]] float get_collision_radius() const override {
|
||||
return Defaults::Entities::BULLET_RADIUS;
|
||||
}
|
||||
[[nodiscard]] bool es_collidable() const override {
|
||||
return esta_ && grace_timer_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
[[nodiscard]] bool esta_activa() const { return esta_; }
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] uint8_t get_owner_id() const { return owner_id_; }
|
||||
[[nodiscard]] float get_grace_timer() const { return grace_timer_; }
|
||||
void desactivar() { esta_ = false; }
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// [NUEVO] Forma vectorial (compartida entre totes les bales)
|
||||
std::shared_ptr<Graphics::Shape> forma_;
|
||||
|
||||
// [NUEVO] Estat de la instància (separat de la geometria)
|
||||
Punt centre_;
|
||||
float angle_;
|
||||
// Membres específics de Bala (heretats: renderer_, forma_, centre_, angle_, brightness_)
|
||||
float velocitat_;
|
||||
bool esta_;
|
||||
uint8_t owner_id_; // 0=P1, 1=P2
|
||||
float grace_timer_; // Grace period timer (0.0 = vulnerable)
|
||||
float brightness_; // Factor de brillantor (0.0-1.0)
|
||||
|
||||
void mou(float delta_time);
|
||||
};
|
||||
|
||||
@@ -10,24 +10,26 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/graphics/shape_loader.hpp"
|
||||
#include "core/rendering/shape_renderer.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
Enemic::Enemic(SDL_Renderer* renderer)
|
||||
: renderer_(renderer),
|
||||
centre_({.x = 0.0F, .y = 0.0F}),
|
||||
angle_(0.0F),
|
||||
: Entitat(renderer),
|
||||
velocitat_(0.0F),
|
||||
drotacio_(0.0F),
|
||||
rotacio_(0.0F),
|
||||
esta_(false),
|
||||
brightness_(Defaults::Brightness::ENEMIC),
|
||||
tipus_(TipusEnemic::PENTAGON),
|
||||
tracking_timer_(0.0F),
|
||||
ship_position_(nullptr),
|
||||
tracking_strength_(0.5F), // Default tracking strength
|
||||
timer_invulnerabilitat_(0.0F) { // Start vulnerable
|
||||
// [NUEVO] Brightness específic per enemics
|
||||
brightness_ = Defaults::Brightness::ENEMIC;
|
||||
|
||||
// [NUEVO] Forma es carrega a inicialitzar() segons el tipus
|
||||
// Constructor no carrega forma per permetre tipus diferents
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
@@ -36,22 +36,30 @@ struct AnimacioEnemic {
|
||||
float drotacio_duracio = 0.0F; // Duration of transition (seconds)
|
||||
};
|
||||
|
||||
class Enemic {
|
||||
class Enemic : public Entities::Entitat {
|
||||
public:
|
||||
Enemic()
|
||||
: renderer_(nullptr) {}
|
||||
: Entitat(nullptr) {}
|
||||
Enemic(SDL_Renderer* renderer);
|
||||
|
||||
void inicialitzar(TipusEnemic tipus = TipusEnemic::PENTAGON, const Punt* ship_pos = nullptr);
|
||||
void actualitzar(float delta_time);
|
||||
void dibuixar() const;
|
||||
void inicialitzar() override { inicialitzar(TipusEnemic::PENTAGON, nullptr); }
|
||||
void inicialitzar(TipusEnemic tipus, const Punt* ship_pos = nullptr);
|
||||
void actualitzar(float delta_time) override;
|
||||
void dibuixar() const override;
|
||||
|
||||
// Override: Interfície d'Entitat
|
||||
[[nodiscard]] bool esta_actiu() const override { return esta_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
[[nodiscard]] float get_collision_radius() const override {
|
||||
return Defaults::Entities::ENEMY_RADIUS;
|
||||
}
|
||||
[[nodiscard]] bool es_collidable() const override {
|
||||
return esta_ && timer_invulnerabilitat_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
[[nodiscard]] bool esta_actiu() const { return esta_; }
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] const std::shared_ptr<Graphics::Shape>& get_forma() const { return forma_; }
|
||||
void destruir() { esta_ = false; }
|
||||
[[nodiscard]] float get_brightness() const { return brightness_; }
|
||||
[[nodiscard]] float get_drotacio() const { return drotacio_; }
|
||||
[[nodiscard]] Punt get_velocitat_vector() const {
|
||||
return {
|
||||
@@ -80,19 +88,11 @@ class Enemic {
|
||||
[[nodiscard]] float get_temps_invulnerabilitat() const { return timer_invulnerabilitat_; }
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// [NUEVO] Forma vectorial (compartida entre tots els enemics)
|
||||
std::shared_ptr<Graphics::Shape> forma_;
|
||||
|
||||
// [NUEVO] Estat de la instància (separat de la geometria)
|
||||
Punt centre_;
|
||||
float angle_; // Angle de moviment
|
||||
// Membres específics d'Enemic (heretats: renderer_, forma_, centre_, angle_, brightness_)
|
||||
float velocitat_;
|
||||
float drotacio_; // Delta rotació visual (rad/s)
|
||||
float rotacio_; // Rotació visual acumulada
|
||||
bool esta_;
|
||||
float brightness_; // Factor de brillantor (0.0-1.0)
|
||||
|
||||
// [NEW] Enemy type and configuration
|
||||
TipusEnemic tipus_;
|
||||
|
||||
@@ -8,22 +8,26 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/graphics/shape_loader.hpp"
|
||||
#include "core/input/input.hpp"
|
||||
#include "core/input/input_types.hpp"
|
||||
#include "core/rendering/shape_renderer.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
Nau::Nau(SDL_Renderer* renderer, const char* shape_file)
|
||||
: renderer_(renderer),
|
||||
centre_({.x = 0.0F, .y = 0.0F}),
|
||||
angle_(0.0F),
|
||||
: Entitat(renderer),
|
||||
velocitat_(0.0F),
|
||||
esta_tocada_(false),
|
||||
brightness_(Defaults::Brightness::NAU),
|
||||
invulnerable_timer_(0.0F) {
|
||||
// [NUEVO] Brightness específic per naus
|
||||
brightness_ = Defaults::Brightness::NAU;
|
||||
|
||||
// [NUEVO] Carregar forma compartida des de fitxer
|
||||
forma_ = Graphics::ShapeLoader::load(shape_file);
|
||||
|
||||
|
||||
@@ -7,31 +7,39 @@
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/defaults.hpp"
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/types.hpp"
|
||||
#include "game/constants.hpp"
|
||||
|
||||
class Nau {
|
||||
class Nau : public Entities::Entitat {
|
||||
public:
|
||||
Nau()
|
||||
: renderer_(nullptr) {}
|
||||
: Entitat(nullptr) {}
|
||||
Nau(SDL_Renderer* renderer, const char* shape_file = "ship.shp");
|
||||
|
||||
void inicialitzar(const Punt* spawn_point = nullptr, bool activar_invulnerabilitat = false);
|
||||
void inicialitzar() override { inicialitzar(nullptr, false); }
|
||||
void inicialitzar(const Punt* spawn_point, bool activar_invulnerabilitat = false);
|
||||
void processar_input(float delta_time, uint8_t player_id);
|
||||
void actualitzar(float delta_time);
|
||||
void dibuixar() const;
|
||||
void actualitzar(float delta_time) override;
|
||||
void dibuixar() const override;
|
||||
|
||||
// Override: Interfície d'Entitat
|
||||
[[nodiscard]] bool esta_actiu() const override { return !esta_tocada_; }
|
||||
|
||||
// Override: Interfície de col·lisió
|
||||
[[nodiscard]] float get_collision_radius() const override {
|
||||
return Defaults::Entities::SHIP_RADIUS;
|
||||
}
|
||||
[[nodiscard]] bool es_collidable() const override {
|
||||
return !esta_tocada_ && invulnerable_timer_ <= 0.0F;
|
||||
}
|
||||
|
||||
// Getters (API pública sense canvis)
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] float get_angle() const { return angle_; }
|
||||
[[nodiscard]] bool esta_viva() const { return !esta_tocada_; }
|
||||
[[nodiscard]] bool esta_tocada() const { return esta_tocada_; }
|
||||
[[nodiscard]] bool es_invulnerable() const { return invulnerable_timer_ > 0.0F; }
|
||||
[[nodiscard]] const std::shared_ptr<Graphics::Shape>& get_forma() const { return forma_; }
|
||||
[[nodiscard]] float get_brightness() const { return brightness_; }
|
||||
[[nodiscard]] Punt get_velocitat_vector() const {
|
||||
return {
|
||||
.x = velocitat_ * std::cos(angle_ - (Constants::PI / 2.0F)),
|
||||
@@ -45,18 +53,9 @@ class Nau {
|
||||
void marcar_tocada() { esta_tocada_ = true; }
|
||||
|
||||
private:
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// [NUEVO] Forma vectorial (compartida, només 1 instància de Nau però preparat
|
||||
// per reutilització)
|
||||
std::shared_ptr<Graphics::Shape> forma_;
|
||||
|
||||
// [NUEVO] Estat de la instància (separat de la geometria)
|
||||
Punt centre_;
|
||||
float angle_; // Angle d'orientació
|
||||
// Membres específics de Nau (heretats: renderer_, forma_, centre_, angle_, brightness_)
|
||||
float velocitat_; // Velocitat (px/s)
|
||||
bool esta_tocada_;
|
||||
float brightness_; // Factor de brillantor (0.0-1.0)
|
||||
float invulnerable_timer_; // 0.0f = vulnerable, >0.0f = invulnerable
|
||||
|
||||
void aplicar_fisica(float delta_time);
|
||||
|
||||
Reference in New Issue
Block a user