feat(orb): contra-atac amb bullet_double dirigida al jugador en rebre impacte

This commit is contained in:
JailDesigner committed 2026-05-26 18:53:34 +02:00
1 parent a77bbe4420
commit 885caa6bc3
7 files changed
+174 -10

No files matched your search

+1 -1
View File
@@ -114,6 +114,6 @@ void Bullet::desactivar() {
void Bullet::draw() const {
if (is_active_ && shape_) {
Rendering::renderShape(renderer_, shape_, center_, angle_, 1.0F, 1.0F, brightness_, config_->colors.normal);
Rendering::renderShape(renderer_, shape_, center_, angle_, config_->shape.scale, 1.0F, brightness_, config_->colors.normal);
}
}
+43 -6
View File
@@ -186,6 +186,11 @@ namespace {
}
}
// Forward-decl: aimModeFromString viu més avall (junt amb la resta de
// helpers d'AI) però parseActionList el necessita per al payload de
// FIRE_BULLET. Evita reordenar tot el bloc.
auto aimModeFromString(const std::string& s) -> std::optional<AimMode>;
auto actionTypeFromString(const std::string& s) -> std::optional<EnemyActionType> {
if (s == "set_hurt") { return EnemyActionType::SET_HURT; }
if (s == "destroy") { return EnemyActionType::DESTROY; }
@@ -197,6 +202,7 @@ namespace {
if (s == "apply_impulse") { return EnemyActionType::APPLY_IMPULSE; }
if (s == "decrease_health") { return EnemyActionType::DECREASE_HEALTH; }
if (s == "flash") { return EnemyActionType::FLASH; }
if (s == "fire_bullet") { return EnemyActionType::FIRE_BULLET; }
return std::nullopt;
}
@@ -219,19 +225,50 @@ namespace {
<< event_name << " (" << enemy_name << ")\n";
return false;
}
out.push_back({*PARSED});
EnemyAction action;
action.type = *PARSED;
// Payload de FIRE_BULLET. Camps opcionals; els defaults són els del struct.
if (action.type == EnemyActionType::FIRE_BULLET) {
if (item.contains("bullet")) {
action.bullet_config_name = item["bullet"].get_value<std::string>();
}
if (item.contains("bullet_speed")) {
action.bullet_speed = item["bullet_speed"].get_value<float>();
}
if (item.contains("aim_mode")) {
const auto AIM_STR = item["aim_mode"].get_value<std::string>();
const auto AIM = aimModeFromString(AIM_STR);
if (!AIM) {
std::cerr << "[EnemyConfig] Error: aim_mode desconegut '" << AIM_STR
<< "' a " << event_name << " (" << enemy_name << ")\n";
return false;
}
action.aim_mode = *AIM;
}
if (item.contains("jitter_rad")) {
action.jitter_rad = item["jitter_rad"].get_value<float>();
}
}
out.push_back(action);
}
return true;
}
// Defaults: replica el flux hardcoded actual (set_hurt → destroy → score+debris+fireworks).
// Construïm via mutació per esquivar warnings de designated-init parcial sobre
// l'EnemyAction (que té payload de FIRE_BULLET no rellevant ací).
void fillLegacyDefaults(EnemyEventConfig& events) {
events.on_hit = {{EnemyActionType::SET_HURT}};
events.on_hurt_end = {{EnemyActionType::DESTROY}};
const auto MAKE = [](EnemyActionType type) {
EnemyAction a;
a.type = type;
return a;
};
events.on_hit = {MAKE(EnemyActionType::SET_HURT)};
events.on_hurt_end = {MAKE(EnemyActionType::DESTROY)};
events.on_destroy = {
{EnemyActionType::ADD_SCORE},
{EnemyActionType::CREATE_DEBRIS},
{EnemyActionType::CREATE_FIREWORKS},
MAKE(EnemyActionType::ADD_SCORE),
MAKE(EnemyActionType::CREATE_DEBRIS),
MAKE(EnemyActionType::CREATE_FIREWORKS),
};
}
+11
View File
@@ -8,8 +8,11 @@
#pragma once
#include <cstdint>
#include <string>
#include <vector>
#include "game/entities/enemy_ai.hpp" // AimMode
enum class EnemyEventType : uint8_t {
ON_HIT, // Impactat per una bala
ON_NO_HEALTH, // health ha arribat a 0 o menys aquest frame (via DECREASE_HEALTH)
@@ -28,10 +31,18 @@ enum class EnemyActionType : uint8_t {
APPLY_IMPULSE, // Aplica l'impuls de la bala impactant
DECREASE_HEALTH, // Decrementa health_; si <=0, dispatcha ON_NO_HEALTH
FLASH, // Flash visual breu (feedback per impacte parcial)
FIRE_BULLET, // Dispara una bala (config per nom) dirigida o aleatòria
};
struct EnemyAction {
EnemyActionType type;
// Payload de FIRE_BULLET (ignorat per altres tipus). Paral·lel a AiTickAction
// perquè un futur refactor pugui compartir doShoot/doFireBullet si val la pena.
std::string bullet_config_name;
float bullet_speed{200.0F};
AimMode aim_mode{AimMode::RANDOM};
float jitter_rad{0.0F};
};
struct EnemyEventConfig {