feat: implementar jerarquia d'entitats amb classe base Entitat
This commit is contained in:
@@ -120,10 +120,11 @@ constexpr float BLINK_INVISIBLE_TIME = 0.1F; // Tiempo invisible (segundos)
|
||||
|
||||
// Game rules (lives, respawn, game over)
|
||||
namespace Game {
|
||||
constexpr int STARTING_LIVES = 3; // Initial lives
|
||||
constexpr float DEATH_DURATION = 3.0F; // Seconds of death animation
|
||||
constexpr float GAME_OVER_DURATION = 5.0F; // Seconds to display game over
|
||||
constexpr float COLLISION_SHIP_ENEMY_AMPLIFIER = 0.80F; // 80% hitbox (generous)
|
||||
constexpr int STARTING_LIVES = 3; // Initial lives
|
||||
constexpr float DEATH_DURATION = 3.0F; // Seconds of death animation
|
||||
constexpr float GAME_OVER_DURATION = 5.0F; // Seconds to display game over
|
||||
constexpr float COLLISION_SHIP_ENEMY_AMPLIFIER = 0.80F; // 80% hitbox (generous)
|
||||
constexpr float COLLISION_BULLET_ENEMY_AMPLIFIER = 1.15F; // 115% hitbox (generous)
|
||||
|
||||
// Friendly fire system
|
||||
constexpr bool FRIENDLY_FIRE_ENABLED = true; // Activar friendly fire
|
||||
|
||||
49
source/core/entities/entitat.hpp
Normal file
49
source/core/entities/entitat.hpp
Normal file
@@ -0,0 +1,49 @@
|
||||
// entitat.hpp - Classe base abstracta per a totes les entitats del joc
|
||||
// © 2025 Orni Attack - Arquitectura d'entitats
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Entities {
|
||||
|
||||
class Entitat {
|
||||
public:
|
||||
virtual ~Entitat() = default;
|
||||
|
||||
// Interfície principal (virtual pur)
|
||||
virtual void inicialitzar() = 0;
|
||||
virtual void actualitzar(float delta_time) = 0;
|
||||
virtual void dibuixar() const = 0;
|
||||
[[nodiscard]] virtual bool esta_actiu() const = 0;
|
||||
|
||||
// Interfície de col·lisió (override opcional)
|
||||
[[nodiscard]] virtual float get_collision_radius() const { return 0.0F; }
|
||||
[[nodiscard]] virtual bool es_collidable() const { return false; }
|
||||
|
||||
// Getters comuns (inline, sense overhead)
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] float get_angle() const { return angle_; }
|
||||
[[nodiscard]] float get_brightness() const { return brightness_; }
|
||||
[[nodiscard]] const std::shared_ptr<Graphics::Shape>& get_forma() const { return forma_; }
|
||||
|
||||
protected:
|
||||
// Estat comú (accés directe, sense overhead)
|
||||
SDL_Renderer* renderer_;
|
||||
std::shared_ptr<Graphics::Shape> forma_;
|
||||
Punt centre_;
|
||||
float angle_{0.0F};
|
||||
float brightness_{1.0F};
|
||||
|
||||
// Constructor protegit (classe abstracta)
|
||||
Entitat(SDL_Renderer* renderer = nullptr)
|
||||
: renderer_(renderer),
|
||||
centre_({.x = 0.0F, .y = 0.0F}) {}
|
||||
};
|
||||
|
||||
} // namespace Entities
|
||||
32
source/core/physics/collision.hpp
Normal file
32
source/core/physics/collision.hpp
Normal file
@@ -0,0 +1,32 @@
|
||||
// collision.hpp - Utilitats de detecció de col·lisions
|
||||
// © 2025 Orni Attack - Sistema de física
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/entities/entitat.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Physics {
|
||||
|
||||
// Comprovació genèrica de col·lisió entre dues entitats
|
||||
inline bool check_collision(const Entities::Entitat& a, const Entities::Entitat& b, float amplifier = 1.0F) {
|
||||
// Comprovar si ambdós són col·lisionables
|
||||
if (!a.es_collidable() || !b.es_collidable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Calcular radi combinat (amb amplificador per hitbox generós)
|
||||
float suma_radis = (a.get_collision_radius() + b.get_collision_radius()) * amplifier;
|
||||
float suma_radis_sq = suma_radis * suma_radis;
|
||||
|
||||
// Comprovació distància al quadrat (sense sqrt)
|
||||
const Punt& pos_a = a.get_centre();
|
||||
const Punt& pos_b = b.get_centre();
|
||||
float dx = pos_a.x - pos_b.x;
|
||||
float dy = pos_a.y - pos_b.y;
|
||||
float dist_sq = (dx * dx) + (dy * dy);
|
||||
|
||||
return dist_sq <= suma_radis_sq;
|
||||
}
|
||||
|
||||
} // namespace Physics
|
||||
Reference in New Issue
Block a user