feat(enemy): sistema d'HP declaratiu i nou enemic big_pentagon
This commit is contained in:
1 parent
610eaf257e
commit
f64c72f9a6
20 files changed
+287
-51
No files matched your search
@@ -58,7 +58,8 @@ namespace Effects {
|
||||
float lifetime,
|
||||
float friction,
|
||||
int segment_multiplier,
|
||||
const Vec2& bullet_impulse_velocity) {
|
||||
const Vec2& bullet_impulse_velocity,
|
||||
float piece_scale) {
|
||||
if (!shape || !shape->isValid()) {
|
||||
return;
|
||||
}
|
||||
@@ -85,7 +86,7 @@ namespace Effects {
|
||||
Vec2 world_p2 = transformPoint(local_p2, shape_centre, centro, angle, scale);
|
||||
|
||||
// Si el pool es ple, no té sentit continuar amb la resta de segments
|
||||
if (!spawnDebris(world_p1, world_p2, centro, velocitat_base, brightness, velocitat_objecte, velocitat_angular, factor_herencia_visual, color, lifetime, friction, bullet_impulse_velocity)) {
|
||||
if (!spawnDebris(world_p1, world_p2, centro, velocitat_base, brightness, velocitat_objecte, velocitat_angular, factor_herencia_visual, color, lifetime, friction, bullet_impulse_velocity, piece_scale)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -111,26 +112,36 @@ namespace Effects {
|
||||
return segments;
|
||||
}
|
||||
|
||||
auto DebrisManager::spawnDebris(const Vec2& world_p1, const Vec2& world_p2, const Vec2& centro, float velocitat_base, float brightness, const Vec2& velocitat_objecte, float velocitat_angular, float factor_herencia_visual, SDL_Color color, float lifetime, float friction, const Vec2& bullet_impulse_velocity) -> bool {
|
||||
auto DebrisManager::spawnDebris(const Vec2& world_p1_in, const Vec2& world_p2_in, const Vec2& centro, float velocitat_base, float brightness, const Vec2& velocitat_objecte, float velocitat_angular, float factor_herencia_visual, SDL_Color color, float lifetime, float friction, const Vec2& bullet_impulse_velocity, float piece_scale) -> bool {
|
||||
Debris* debris = findFreeSlot();
|
||||
if (debris == nullptr) {
|
||||
std::cerr << "[DebrisManager] Warning: no debris slots disponibles\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Escala el segment al voltant del seu punt mitjà segons piece_scale
|
||||
// (1.0 = original; 0.3 = "esquerda petita"). La resta del càlcul (angle,
|
||||
// half_length, p1/p2) en deriva naturalment.
|
||||
const Vec2 MID = {.x = (world_p1_in.x + world_p2_in.x) / 2.0F,
|
||||
.y = (world_p1_in.y + world_p2_in.y) / 2.0F};
|
||||
const Vec2 WORLD_P1 = {.x = MID.x + ((world_p1_in.x - MID.x) * piece_scale),
|
||||
.y = MID.y + ((world_p1_in.y - MID.y) * piece_scale)};
|
||||
const Vec2 WORLD_P2 = {.x = MID.x + ((world_p2_in.x - MID.x) * piece_scale),
|
||||
.y = MID.y + ((world_p2_in.y - MID.y) * piece_scale)};
|
||||
|
||||
// Geometria autoritaritzada: centro + original_angle + original_half_length.
|
||||
// p1/p2 es reconstrueixen cada frame en update() des d'aquestes dades.
|
||||
const float DX = world_p2.x - world_p1.x;
|
||||
const float DY = world_p2.y - world_p1.y;
|
||||
debris->centro = {.x = (world_p1.x + world_p2.x) / 2.0F,
|
||||
.y = (world_p1.y + world_p2.y) / 2.0F};
|
||||
const float DX = WORLD_P2.x - WORLD_P1.x;
|
||||
const float DY = WORLD_P2.y - WORLD_P1.y;
|
||||
debris->centro = {.x = (WORLD_P1.x + WORLD_P2.x) / 2.0F,
|
||||
.y = (WORLD_P1.y + WORLD_P2.y) / 2.0F};
|
||||
debris->original_angle = std::atan2(DY, DX);
|
||||
debris->original_half_length = std::sqrt((DX * DX) + (DY * DY)) / 2.0F;
|
||||
debris->p1 = world_p1;
|
||||
debris->p2 = world_p2;
|
||||
debris->p1 = WORLD_P1;
|
||||
debris->p2 = WORLD_P2;
|
||||
|
||||
// Direcció radial (desde el centro hacia el segment)
|
||||
Vec2 direccio = computeExplosionDirection(world_p1, world_p2, centro);
|
||||
Vec2 direccio = computeExplosionDirection(WORLD_P1, WORLD_P2, centro);
|
||||
|
||||
// Velocidad inicial (base ± variació aleatòria + velocity heretada de l'objecte +
|
||||
// velocitat de la bala escalada per BULLET_IMPULSE_FACTOR).
|
||||
|
||||
@@ -52,6 +52,9 @@ namespace Effects {
|
||||
// Defaults::Physics::Debris::BULLET_IMPULSE_FACTOR, independent de
|
||||
// velocitat_objecte. Permet que els trossos "salten amb la força de la bala"
|
||||
// encara que el cos sigui pesat i amb prou feines es mogui.
|
||||
// - piece_scale: multiplicador de la longitud de cada fragment al spawn
|
||||
// (per defecte 1.0). Útil per a debris "parcial" d'impactes no letals
|
||||
// en enemics HP>1 (trossos petits, com d'esquerda).
|
||||
void explode(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
const Vec2& centro,
|
||||
float angle,
|
||||
@@ -66,7 +69,8 @@ namespace Effects {
|
||||
float lifetime = Defaults::Physics::Debris::TEMPS_VIDA,
|
||||
float friction = Defaults::Physics::Debris::ACCELERACIO,
|
||||
int segment_multiplier = 1,
|
||||
const Vec2& bullet_impulse_velocity = {.x = 0.0F, .y = 0.0F});
|
||||
const Vec2& bullet_impulse_velocity = {.x = 0.0F, .y = 0.0F},
|
||||
float piece_scale = 1.0F);
|
||||
|
||||
// Actualitzar todos los fragments active
|
||||
void update(float delta_time);
|
||||
@@ -103,7 +107,7 @@ namespace Effects {
|
||||
-> std::vector<std::pair<Vec2, Vec2>>;
|
||||
// Inicialitza un debris en un slot lliure i el deixa actiu. Retorna
|
||||
// false si el pool está ple (la cridadora ha d'aturar el bucle).
|
||||
auto spawnDebris(const Vec2& world_p1, const Vec2& world_p2, const Vec2& centro, float velocitat_base, float brightness, const Vec2& velocitat_objecte, float velocitat_angular, float factor_herencia_visual, SDL_Color color, float lifetime, float friction, const Vec2& bullet_impulse_velocity) -> bool;
|
||||
auto spawnDebris(const Vec2& world_p1, const Vec2& world_p2, const Vec2& centro, float velocitat_base, float brightness, const Vec2& velocitat_objecte, float velocitat_angular, float factor_herencia_visual, SDL_Color color, float lifetime, float friction, const Vec2& bullet_impulse_velocity, float piece_scale) -> bool;
|
||||
static void applyAngularVelocity(Debris& debris, const Vec2& direccio, float velocitat_angular);
|
||||
static void applyVisualRotation(Debris& debris, float velocitat_angular, float factor_herencia_visual);
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user