feat(entities): migrar la configuració del player a data/entities/player/player.yaml

This commit is contained in:
2026-05-25 08:32:49 +02:00
parent 9f278772bb
commit 6447932212
18 changed files with 396 additions and 121 deletions
+13 -12
View File
@@ -9,12 +9,16 @@
#include "core/defaults.hpp"
#include "core/entities/entity.hpp"
#include "core/types.hpp"
#include "game/entities/player_config.hpp"
class Ship : public Entities::Entity {
public:
Ship()
: Entity(nullptr) {}
explicit Ship(Rendering::Renderer* renderer, const char* shape_file = "ship.shp");
// shape_override: si no és nullptr, substitueix config.shape.path
// (utilitzat per donar al P2 un model visual diferent compartint la
// mateixa configuració del player).
explicit Ship(Rendering::Renderer* renderer, PlayerConfig config, const char* shape_override = nullptr);
void init() override { init(nullptr, false); }
void init(const Vec2* spawn_point, bool activar_invulnerabilitat = false);
@@ -28,7 +32,7 @@ class Ship : public Entities::Entity {
// Override: Interfaz de colisión
[[nodiscard]] auto getCollisionRadius() const -> float override {
return Defaults::Entities::SHIP_RADIUS;
return config_.physics.collision_radius;
}
[[nodiscard]] auto isCollidable() const -> bool override {
return !is_hit_ && invulnerable_timer_ <= 0.0F;
@@ -36,10 +40,9 @@ class Ship : public Entities::Entity {
// Getters
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_timer_ > 0.0F; }
// Velocidad como vector cartesiano (ahora viene directa del body_).
[[nodiscard]] auto getVelocityVector() const -> Vec2 { return body_.velocity; }
// Velocidad escalar (utilidad para draw y debugging).
[[nodiscard]] auto getSpeed() const -> float { return body_.velocity.length(); }
[[nodiscard]] auto getConfig() const -> const PlayerConfig& { return config_; }
// Setters
void setCenter(const Vec2& nou_centre) {
@@ -65,17 +68,15 @@ class Ship : public Entities::Entity {
void setTouchingEnemyPrevFrame(bool touching) { touching_enemy_prev_frame_ = touching; }
private:
// Miembros específicos de Ship (heredados: renderer_, shape_, center_, angle_, brightness_, body_).
// Inicializados en la declaración: el ctor por defecto deja la nave "viva y sin invulnerabilidad",
// que es el estado coherente al que llevan tanto init() como el ctor con renderer.
// Configuració carregada des de YAML. Default-init zero permet el ctor
// per defecte (necessari per a `std::array<Ship, N>`); s'omple via
// copy/move-assignment quan GameScene crea la nau real.
PlayerConfig config_{};
bool is_hit_{false};
float invulnerable_timer_{0.0F}; // 0.0f = vulnerable, >0.0f = invulnerable
// Colors de la nau (propietats, prep per migració a YAML).
SDL_Color color_normal_{Defaults::Palette::SHIP};
SDL_Color color_hurt_{Defaults::Palette::WOUNDED};
// >0 → estat HURT (parpelleig color_normal_ ↔ color_hurt_).
// >0 → estat HURT (parpelleig color normal ↔ color hurt).
float hurt_timer_{0.0F};
// Edge-trigger: true si el frame anterior la nau ja estava en contacte amb un enemic.