49 lines
1.6 KiB
C++
49 lines
1.6 KiB
C++
// enemy_event.hpp - Sistema declaratiu d'events i accions per a enemics
|
|
// © 2026 JailDesigner
|
|
//
|
|
// Cada enemic descriu al seu YAML què passa quan rep un event (on_hit,
|
|
// on_hurt_end, on_destroy) com a llista d'accions. El motor només dispatcha;
|
|
// el comportament viu a les dades.
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <vector>
|
|
|
|
enum class EnemyEventType : uint8_t {
|
|
ON_HIT, // Impactat per una bala
|
|
ON_HURT_END, // Timer wounded ha expirat aquest frame
|
|
ON_DESTROY, // L'acció destroy s'està executant (efectes col·laterals)
|
|
};
|
|
|
|
enum class EnemyActionType : uint8_t {
|
|
SET_HURT, // Entra estat wounded (o destrueix si ja era wounded)
|
|
DESTROY, // Dispara on_destroy + desactiva físicament
|
|
ADD_SCORE, // Suma config.score al shooter + floating score
|
|
CREATE_DEBRIS, // Explosió de debris amb herència de velocitat
|
|
CREATE_FIREWORKS, // Burst radial de firework
|
|
APPLY_IMPULSE, // Aplica l'impuls de la bala impactant
|
|
};
|
|
|
|
struct EnemyAction {
|
|
EnemyActionType type;
|
|
};
|
|
|
|
struct EnemyEventConfig {
|
|
std::vector<EnemyAction> on_hit;
|
|
std::vector<EnemyAction> on_hurt_end;
|
|
std::vector<EnemyAction> on_destroy;
|
|
|
|
[[nodiscard]] auto getActions(EnemyEventType event) const -> const std::vector<EnemyAction>& {
|
|
switch (event) {
|
|
case EnemyEventType::ON_HIT:
|
|
return on_hit;
|
|
case EnemyEventType::ON_HURT_END:
|
|
return on_hurt_end;
|
|
case EnemyEventType::ON_DESTROY:
|
|
return on_destroy;
|
|
}
|
|
return on_hit; // unreachable
|
|
}
|
|
};
|