Boss fight is now working. Turned out to be something really dumb.
This commit is contained in:
parent
4958f24c1d
commit
4b4f9b3916
8 changed files with 154 additions and 127 deletions
|
|
@ -4,8 +4,11 @@
|
|||
#include "game_level.hpp"
|
||||
#include <iostream>
|
||||
#include "rand.hpp"
|
||||
#include "events.hpp"
|
||||
|
||||
namespace boss {
|
||||
using namespace DinkyECS;
|
||||
|
||||
Fight::Fight(shared_ptr<World> world, Entity boss_id, Entity player_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
|
|
@ -19,9 +22,10 @@ namespace boss {
|
|||
$ui.init();
|
||||
}
|
||||
|
||||
bool Fight::event(game::Event ev, std::any data) {
|
||||
void Fight::event(game::Event ev, std::any data) {
|
||||
|
||||
// if the mouse event is handled the done, this may be wrong later
|
||||
if(handle_mouse(ev)) return in_state(State::END);
|
||||
if(handle_mouse(ev)) return;
|
||||
|
||||
switch($state) {
|
||||
FSM_STATE(State, START, ev, data);
|
||||
|
|
@ -30,10 +34,6 @@ namespace boss {
|
|||
FSM_STATE(State, EXEC_PLAN, ev, data);
|
||||
FSM_STATE(State, END, ev, data);
|
||||
}
|
||||
|
||||
run_systems();
|
||||
|
||||
return in_state(State::END);
|
||||
}
|
||||
|
||||
void Fight::START(game::Event ev, std::any) {
|
||||
|
|
@ -41,10 +41,8 @@ namespace boss {
|
|||
|
||||
switch(ev) {
|
||||
// this is only if using the debug X key to skip it
|
||||
case BOSS_START:
|
||||
state(State::END);
|
||||
break;
|
||||
case TICK:
|
||||
case BOSS_START:
|
||||
$ui.status(L"PLAYER REQUESTS");
|
||||
$battle.ap_refresh();
|
||||
state(State::PLAYER_REQUESTS);
|
||||
|
|
@ -169,7 +167,6 @@ namespace boss {
|
|||
}
|
||||
|
||||
void Fight::render(sf::RenderWindow& window) {
|
||||
window.clear();
|
||||
$ui.play_animations();
|
||||
$ui.render(window);
|
||||
}
|
||||
|
|
@ -179,10 +176,10 @@ namespace boss {
|
|||
|
||||
switch(ev) {
|
||||
case MOUSE_CLICK: {
|
||||
$ui.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS);
|
||||
$ui.mouse($router.position.x, $router.position.y, guecs::NO_MODS);
|
||||
} break;
|
||||
case MOUSE_MOVE: {
|
||||
$ui.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover});
|
||||
$ui.mouse($router.position.x, $router.position.y, {1 << guecs::ModBit::hover});
|
||||
} break;
|
||||
case MOUSE_DRAG:
|
||||
dbc::log("mouse drag");
|
||||
|
|
@ -210,33 +207,47 @@ namespace boss {
|
|||
run_systems();
|
||||
}
|
||||
|
||||
void Fight::handle_world_events() {
|
||||
fmt::println(">>>>>>>>>>>>>>>>> BOSS FIGHT EVENTS");
|
||||
dbc::check($world->has_event<game::Event>(), "World doesn't have GUI events.");
|
||||
void Fight::set_window(sf::RenderWindow* window) {
|
||||
$window = window;
|
||||
}
|
||||
|
||||
while($world->has_event<game::Event>()) {
|
||||
auto [evt, entity, data] = $world->recv<game::Event>();
|
||||
fmt::println("boss fight received event", int(evt));
|
||||
bool Fight::handle_keyboard_mouse() {
|
||||
dbc::check($window != nullptr, "you didn't set_window");
|
||||
|
||||
switch(evt) {
|
||||
case game::Event::ATTACK:
|
||||
fmt::println("sending attack");
|
||||
event(game::Event::ATTACK, data);
|
||||
break;
|
||||
case game::Event::COMBAT_START:
|
||||
fmt::println("sending combat start {}", data.type().name());
|
||||
event(game::Event::COMBAT_START, data);
|
||||
break;
|
||||
case game::Event::COMBAT:
|
||||
fmt::println("sending combat {}", data.type().name());
|
||||
event(game::Event::COMBAT, data);
|
||||
break;
|
||||
default:
|
||||
fmt::println("GUI EVENT: {} entity={}", int(evt), entity);
|
||||
while(const auto ev = $window->pollEvent()) {
|
||||
auto gui_ev = $router.process_event(ev);
|
||||
|
||||
if(gui_ev == game::Event::KEY_PRESS) {
|
||||
using KEY = sf::Keyboard::Scan;
|
||||
|
||||
switch($router.scancode) {
|
||||
// REALLY? just go to state end or use another event
|
||||
case KEY::X:
|
||||
event(game::Event::BOSS_START, {});
|
||||
break;
|
||||
default:
|
||||
fmt::println("key press!");
|
||||
}
|
||||
} else if(gui_ev == game::Event::QUIT) {
|
||||
return true;
|
||||
} else {
|
||||
event(gui_ev, {});
|
||||
}
|
||||
}
|
||||
|
||||
dbc::check(!$world->has_event<game::Event>(), "World still has events!");
|
||||
fmt::println("<<<<<<<<<<<<<<<< BOSS FIGHT EVENTS");
|
||||
return in_state(State::END);
|
||||
}
|
||||
|
||||
bool Fight::handle_world_events() {
|
||||
if($world->has_event<game::Event>()) {
|
||||
while($world->has_event<game::Event>()) {
|
||||
auto [evt, entity, data] = $world->recv<game::Event>();
|
||||
|
||||
event(game::Event(evt), data);
|
||||
run_systems();
|
||||
}
|
||||
}
|
||||
|
||||
return in_state(State::END);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue