feat(attack): esquelet WhipAttack + canal d'spawn via EventBus
This commit is contained in:
1 parent
4752eb8ad7
commit
9ad21eb5bb
12 files changed
+346
-1
No files matched your search
@@ -28,7 +28,9 @@
|
||||
#include "core/ui/ui_config.hpp"
|
||||
#include "external/fkyaml_node.hpp"
|
||||
#include "game/entities/concrete/dust.hpp"
|
||||
#include "game/entities/concrete/whip_attack.hpp"
|
||||
#include "game/entities/entity.hpp"
|
||||
#include "game/entities/entity_factory.hpp"
|
||||
#include "game/entities/entity_loader.hpp"
|
||||
#include "game/entities/event_bus.hpp"
|
||||
#include "game/entities/player.hpp"
|
||||
@@ -312,6 +314,18 @@ GameScene::GameScene(Config config)
|
||||
if (pos != nullptr) { spawnDust(pos->x, pos->y, true); }
|
||||
});
|
||||
|
||||
// Whip: precarreguem les 4 surfaces (una per cardinal) abans del
|
||||
// primer spawn perquè el Player no facte disc al primer atac.
|
||||
// Subscriu `whip_spawn` per crear el `WhipAttack` corresponent.
|
||||
Resource::Cache::get().loadSurface("whip_east.gif", "data/entities/whip_attack/whip_east.gif");
|
||||
Resource::Cache::get().loadSurface("whip_west.gif", "data/entities/whip_attack/whip_west.gif");
|
||||
Resource::Cache::get().loadSurface("whip_north.gif", "data/entities/whip_attack/whip_north.gif");
|
||||
Resource::Cache::get().loadSurface("whip_south.gif", "data/entities/whip_attack/whip_south.gif");
|
||||
entity_manager_.getBus().subscribe("whip_spawn", [this](const Event& ev) {
|
||||
const auto* p = std::get_if<WhipSpawnPayload>(&ev.payload);
|
||||
if (p != nullptr) { spawnWhip(*p); }
|
||||
});
|
||||
|
||||
// Controls per jugador: P1 amb fletxes, P2 amb WASD. Cada Player
|
||||
// escolta les seues pròpies tecles dins del seu `update`, no hi ha
|
||||
// estat global d'input.
|
||||
@@ -877,6 +891,24 @@ void GameScene::spawnDust(float feet_x_center, float feet_y, bool is_landing) {
|
||||
entity_manager_.add(std::move(dust));
|
||||
}
|
||||
|
||||
void GameScene::spawnWhip(const WhipSpawnPayload& payload) {
|
||||
// El YAML ja viu cacheat al `EntityLoader`; les 4 surfaces les hem
|
||||
// precarregat al ctor. `configure()` selecciona la mida segons
|
||||
// direcció i posa pixel_rect; aquí resolem la surface via
|
||||
// `Resource::Cache` (mateix patró que `spawnDust`) per evitar que
|
||||
// l'entitat depengui directament del cache.
|
||||
auto whip_yaml = EntityLoader::loadTemplate("whip_attack");
|
||||
auto whip = std::make_unique<WhipAttack>(whip_yaml);
|
||||
whip->setOwner(payload.owner);
|
||||
whip->configure(
|
||||
static_cast<WhipAttack::Direction>(payload.direction),
|
||||
payload.spawn_x,
|
||||
payload.spawn_y,
|
||||
payload.range_px);
|
||||
whip->setSurface(Resource::Cache::get().getSurface(whip->getSurfaceKey()));
|
||||
entity_manager_.add(std::move(whip));
|
||||
}
|
||||
|
||||
void GameScene::handlePauseInput() {
|
||||
#ifdef _DEBUG
|
||||
// Mutex amb l'editor: si està actiu, ignorem la tecla de pausa.
|
||||
|
||||
Reference in new issue
Block a user