feat(player): mort i respawn (DYING + death_spinning + lives counter)
This commit is contained in:
1 parent
6397f9d4eb
commit
9f0a566ffb
11 files changed
+377
-7
No files matched your search
@@ -87,11 +87,15 @@ Mummy::Mummy(const fkyaml::node& yaml)
|
||||
collides_ = true;
|
||||
interactable_ = false;
|
||||
|
||||
// Velocitat i dany des del bloc `stats` (si existeix).
|
||||
// Velocitat i dany des del bloc `stats` (si existeix). El flag
|
||||
// `kills_outright` també hi viu: per defecte true (la mòmia mata
|
||||
// d'un sol toc); posat a false al YAML, el contacte només publica
|
||||
// `player_hit` sense disparar el cicle DYING.
|
||||
if (yaml.contains("stats")) {
|
||||
const auto& s = yaml["stats"];
|
||||
if (s.contains("speed")) { setSpeed(s["speed"].get_value<float>()); }
|
||||
if (s.contains("damage")) { setDamage(s["damage"].get_value<int>()); }
|
||||
if (s.contains("kills_outright")) { kills_outright_ = s["kills_outright"].get_value<bool>(); }
|
||||
}
|
||||
|
||||
// Direcció inicial llegida del bloc `ai:`. Per defecte est, per
|
||||
@@ -324,11 +328,25 @@ void Mummy::applyChoice(Direction dir) {
|
||||
}
|
||||
|
||||
void Mummy::onPlayerContact(Player* player) {
|
||||
if (bus_ != nullptr) {
|
||||
if (bus_ == nullptr) { return; }
|
||||
const int PID = (player != nullptr) ? player->getId() : -1;
|
||||
bus_->publish(Event{
|
||||
.name = "player_hit",
|
||||
.payload = getDamage(),
|
||||
.player_id = PID,
|
||||
});
|
||||
// Path letal: si la mòmia està marcada com a `kills_outright`
|
||||
// (default a Oh Mummy!), notifiquem al GameScene que el jugador
|
||||
// ha de morir. La transició concreta (`Player::enterDying`) la fa
|
||||
// el subscriptor — així mummy.cpp no toca cap símbol del Player més
|
||||
// enllà de la forward-decl, i els tests d'entitats no han d'arrossegar
|
||||
// l'stack pesat del jugador per linkar-se. El subscriptor (GameScene)
|
||||
// és qui resol el `player_id` a la instància concreta.
|
||||
if (kills_outright_) {
|
||||
bus_->publish(Event{
|
||||
.name = "player_hit",
|
||||
.name = "player_killed",
|
||||
.payload = getDamage(),
|
||||
.player_id = (player != nullptr) ? player->getId() : -1,
|
||||
.player_id = PID,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ class Mummy : public DynamicHazard {
|
||||
[[nodiscard]] auto getState() const -> State { return state_; }
|
||||
[[nodiscard]] auto isWhippable() const -> bool { return whippable_; }
|
||||
[[nodiscard]] auto getHurtRemainingS() const -> float { return hurt_remaining_s_; }
|
||||
[[nodiscard]] auto killsOutright() const -> bool { return kills_outright_; }
|
||||
|
||||
private:
|
||||
// Caixa de col·lisió candidata si l'entitat es desplaçara (dx, dy).
|
||||
@@ -146,4 +147,10 @@ class Mummy : public DynamicHazard {
|
||||
bool whippable_{true};
|
||||
float hurt_remaining_s_{0.0F};
|
||||
float hurt_speed_{0.0F};
|
||||
|
||||
// Si true, el contacte amb el jugador dispara `Player::enterDying`
|
||||
// (mort d'un sol toc, bypass del flux `hurt`/knockback). Llegit del
|
||||
// bloc `stats.kills_outright` del YAML; default true per coherència
|
||||
// amb el comportament d'Oh Mummy! (les mòmies maten).
|
||||
bool kills_outright_{true};
|
||||
};
|
||||
Reference in new issue
Block a user