feat: implementar jerarquia d'entitats amb classe base Entitat
This commit is contained in:
@@ -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