|
|
@ -12,19 +12,19 @@ |
|
|
|
#include "shaders.hpp" |
|
|
|
#include "shaders.hpp" |
|
|
|
#include <fmt/xchar.h> |
|
|
|
#include <fmt/xchar.h> |
|
|
|
#include "gui/guecstra.hpp" |
|
|
|
#include "gui/guecstra.hpp" |
|
|
|
|
|
|
|
#include "game_level.hpp" |
|
|
|
|
|
|
|
|
|
|
|
namespace gui { |
|
|
|
namespace gui { |
|
|
|
using namespace components; |
|
|
|
using namespace components; |
|
|
|
|
|
|
|
|
|
|
|
FSM::FSM() : |
|
|
|
FSM::FSM() : |
|
|
|
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), |
|
|
|
$window(sf::VideoMode({SCREEN_WIDTH, SCREEN_HEIGHT}), "Zed's Raycaster Thing"), |
|
|
|
$debug_ui($levels), |
|
|
|
$debug_ui(Game::get_the_manager()), |
|
|
|
$main_ui($window), |
|
|
|
$main_ui($window), |
|
|
|
$level($levels.current()), |
|
|
|
$combat_ui(Game::current()), |
|
|
|
$combat_ui($level), |
|
|
|
$status_ui(Game::current()), |
|
|
|
$status_ui($level), |
|
|
|
$map_ui(Game::current()), |
|
|
|
$map_ui($level), |
|
|
|
$loot_ui(Game::current()), |
|
|
|
$loot_ui($level), |
|
|
|
|
|
|
|
$font{FONT_FILE_NAME}, |
|
|
|
$font{FONT_FILE_NAME}, |
|
|
|
$dnd_loot($status_ui, $loot_ui, $window, $router) |
|
|
|
$dnd_loot($status_ui, $loot_ui, $window, $router) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -47,7 +47,8 @@ namespace gui { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSM::START(Event ) { |
|
|
|
void FSM::START(Event ) { |
|
|
|
$main_ui.update_level($level); |
|
|
|
auto& level = Game::current(); |
|
|
|
|
|
|
|
$main_ui.update_level(level); |
|
|
|
$main_ui.init(); |
|
|
|
$main_ui.init(); |
|
|
|
$loot_ui.init(); |
|
|
|
$loot_ui.init(); |
|
|
|
|
|
|
|
|
|
|
@ -58,7 +59,7 @@ namespace gui { |
|
|
|
$combat_ui.init(); |
|
|
|
$combat_ui.init(); |
|
|
|
$status_ui.init(); |
|
|
|
$status_ui.init(); |
|
|
|
|
|
|
|
|
|
|
|
$boss_fight_ui = $levels.create_bossfight($level.world); |
|
|
|
$boss_fight_ui = Game::create_bossfight(); |
|
|
|
$boss_fight_ui->init(); |
|
|
|
$boss_fight_ui->init(); |
|
|
|
|
|
|
|
|
|
|
|
$map_ui.init(); |
|
|
|
$map_ui.init(); |
|
|
@ -72,7 +73,7 @@ namespace gui { |
|
|
|
void FSM::MOVING(Event ) { |
|
|
|
void FSM::MOVING(Event ) { |
|
|
|
// this should be an optional that returns a point
|
|
|
|
// this should be an optional that returns a point
|
|
|
|
if(auto move_to = $main_ui.play_move()) { |
|
|
|
if(auto move_to = $main_ui.play_move()) { |
|
|
|
System::plan_motion($level, *move_to); |
|
|
|
System::plan_motion(Game::current(), *move_to); |
|
|
|
run_systems(); |
|
|
|
run_systems(); |
|
|
|
$main_ui.dirty(); |
|
|
|
$main_ui.dirty(); |
|
|
|
state(State::IDLE); |
|
|
|
state(State::IDLE); |
|
|
@ -83,7 +84,7 @@ namespace gui { |
|
|
|
using enum Event; |
|
|
|
using enum Event; |
|
|
|
switch(ev) { |
|
|
|
switch(ev) { |
|
|
|
case TICK: { |
|
|
|
case TICK: { |
|
|
|
System::combat($level, $temp_attack_id); |
|
|
|
System::combat(Game::current(), $temp_attack_id); |
|
|
|
run_systems(); |
|
|
|
run_systems(); |
|
|
|
state(State::IN_COMBAT); |
|
|
|
state(State::IN_COMBAT); |
|
|
|
} break; |
|
|
|
} break; |
|
|
@ -101,7 +102,7 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
|
|
void FSM::ROTATING(Event) { |
|
|
|
void FSM::ROTATING(Event) { |
|
|
|
if(auto aim = $main_ui.play_rotate()) { |
|
|
|
if(auto aim = $main_ui.play_rotate()) { |
|
|
|
auto& player_pos = System::player_position($level); |
|
|
|
auto& player_pos = Game::player_position(); |
|
|
|
player_pos.aiming_at = *aim; |
|
|
|
player_pos.aiming_at = *aim; |
|
|
|
state(State::IDLE); |
|
|
|
state(State::IDLE); |
|
|
|
} |
|
|
|
} |
|
|
@ -109,7 +110,7 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
|
|
void FSM::COMBAT_ROTATE(Event) { |
|
|
|
void FSM::COMBAT_ROTATE(Event) { |
|
|
|
if(auto aim = $main_ui.play_rotate()) { |
|
|
|
if(auto aim = $main_ui.play_rotate()) { |
|
|
|
auto& player_pos = System::player_position($level); |
|
|
|
auto& player_pos = Game::player_position(); |
|
|
|
player_pos.aiming_at = *aim; |
|
|
|
player_pos.aiming_at = *aim; |
|
|
|
state(State::IN_COMBAT); |
|
|
|
state(State::IN_COMBAT); |
|
|
|
} |
|
|
|
} |
|
|
@ -194,7 +195,7 @@ namespace gui { |
|
|
|
auto gui_id = std::any_cast<guecs::Entity>(data); |
|
|
|
auto gui_id = std::any_cast<guecs::Entity>(data); |
|
|
|
auto& slot_name = $status_ui.$gui.name_for(gui_id); |
|
|
|
auto& slot_name = $status_ui.$gui.name_for(gui_id); |
|
|
|
|
|
|
|
|
|
|
|
if(System::use_item($level, slot_name)) { |
|
|
|
if(System::use_item(Game::current(), slot_name)) { |
|
|
|
$status_ui.update(); |
|
|
|
$status_ui.update(); |
|
|
|
} |
|
|
|
} |
|
|
|
} break; |
|
|
|
} break; |
|
|
@ -206,7 +207,7 @@ namespace gui { |
|
|
|
mouse_action({1 << guecs::ModBit::hover}); |
|
|
|
mouse_action({1 << guecs::ModBit::hover}); |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case AIM_CLICK: |
|
|
|
case AIM_CLICK: |
|
|
|
System::pickup($level); |
|
|
|
System::pickup(Game::current()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
default: |
|
|
|
default: |
|
|
|
break; // ignore everything else
|
|
|
|
break; // ignore everything else
|
|
|
@ -272,11 +273,12 @@ namespace gui { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSM::try_move(int dir, bool strafe) { |
|
|
|
void FSM::try_move(int dir, bool strafe) { |
|
|
|
|
|
|
|
auto& level = Game::current(); |
|
|
|
using enum State; |
|
|
|
using enum State; |
|
|
|
// prevent moving into occupied space
|
|
|
|
// prevent moving into occupied space
|
|
|
|
Point move_to = $main_ui.plan_move(dir, strafe); |
|
|
|
Point move_to = $main_ui.plan_move(dir, strafe); |
|
|
|
|
|
|
|
|
|
|
|
if($level.map->can_move(move_to) && !$level.collision->occupied(move_to)) { |
|
|
|
if(level.map->can_move(move_to) && !level.collision->occupied(move_to)) { |
|
|
|
sound::play("walk"); |
|
|
|
sound::play("walk"); |
|
|
|
state(MOVING); |
|
|
|
state(MOVING); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -360,8 +362,9 @@ namespace gui { |
|
|
|
event(Event::LOOT_OPEN); |
|
|
|
event(Event::LOOT_OPEN); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case KEY::Z: { |
|
|
|
case KEY::Z: { |
|
|
|
auto& player_pos = System::player_position($level); |
|
|
|
auto& level = Game::current(); |
|
|
|
System::distribute_loot($level, {player_pos.aiming_at}); |
|
|
|
auto& player_pos = Game::player_position(); |
|
|
|
|
|
|
|
System::distribute_loot(level, {player_pos.aiming_at}); |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case KEY::X: |
|
|
|
case KEY::X: |
|
|
|
event(Event::STAIRS_DOWN); |
|
|
|
event(Event::STAIRS_DOWN); |
|
|
@ -419,13 +422,14 @@ namespace gui { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSM::run_systems() { |
|
|
|
void FSM::run_systems() { |
|
|
|
System::generate_paths($level); |
|
|
|
auto& level = Game::current(); |
|
|
|
System::enemy_ai_initialize($level); |
|
|
|
System::generate_paths(level); |
|
|
|
System::enemy_pathing($level); |
|
|
|
System::enemy_ai_initialize(level); |
|
|
|
System::collision($level); |
|
|
|
System::enemy_pathing(level); |
|
|
|
System::motion($level); |
|
|
|
System::collision(level); |
|
|
|
System::lighting($level); |
|
|
|
System::motion(level); |
|
|
|
System::death($level); |
|
|
|
System::lighting(level); |
|
|
|
|
|
|
|
System::death(level); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool FSM::active() { |
|
|
|
bool FSM::active() { |
|
|
@ -434,11 +438,11 @@ namespace gui { |
|
|
|
|
|
|
|
|
|
|
|
void FSM::handle_world_events() { |
|
|
|
void FSM::handle_world_events() { |
|
|
|
using eGUI = Events::GUI; |
|
|
|
using eGUI = Events::GUI; |
|
|
|
auto& world = *$level.world; |
|
|
|
auto world = Game::current_world(); |
|
|
|
|
|
|
|
|
|
|
|
while(world.has_event<eGUI>()) { |
|
|
|
while(world->has_event<eGUI>()) { |
|
|
|
auto [evt, entity, data] = world.recv<eGUI>(); |
|
|
|
auto [evt, entity, data] = world->recv<eGUI>(); |
|
|
|
auto player = world.get_the<Player>(); |
|
|
|
auto player = world->get_the<Player>(); |
|
|
|
|
|
|
|
|
|
|
|
// HERE: this has to go, unify these events and just use them in the state machine directly
|
|
|
|
// HERE: this has to go, unify these events and just use them in the state machine directly
|
|
|
|
|
|
|
|
|
|
|
@ -463,7 +467,7 @@ namespace gui { |
|
|
|
event(Event::START_COMBAT); |
|
|
|
event(Event::START_COMBAT); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eGUI::ENTITY_SPAWN: { |
|
|
|
case eGUI::ENTITY_SPAWN: { |
|
|
|
auto& sprite = world.get<components::Sprite>(entity); |
|
|
|
auto& sprite = world->get<components::Sprite>(entity); |
|
|
|
$main_ui.$rayview->update_sprite(entity, sprite); |
|
|
|
$main_ui.$rayview->update_sprite(entity, sprite); |
|
|
|
$main_ui.dirty(); |
|
|
|
$main_ui.dirty(); |
|
|
|
run_systems(); |
|
|
|
run_systems(); |
|
|
@ -489,7 +493,7 @@ namespace gui { |
|
|
|
event(Event::AIM_CLICK); |
|
|
|
event(Event::AIM_CLICK); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eGUI::LOOT_ITEM: { |
|
|
|
case eGUI::LOOT_ITEM: { |
|
|
|
dbc::check(world.has<components::InventoryItem>(entity), |
|
|
|
dbc::check(world->has<components::InventoryItem>(entity), |
|
|
|
"INVALID LOOT_ITEM, that entity has no InventoryItem"); |
|
|
|
"INVALID LOOT_ITEM, that entity has no InventoryItem"); |
|
|
|
$loot_ui.add_loose_item(entity); |
|
|
|
$loot_ui.add_loose_item(entity); |
|
|
|
event(Event::LOOT_ITEM); |
|
|
|
event(Event::LOOT_ITEM); |
|
|
@ -500,7 +504,7 @@ namespace gui { |
|
|
|
event(Event::LOOT_OPEN); |
|
|
|
event(Event::LOOT_OPEN); |
|
|
|
} break; |
|
|
|
} break; |
|
|
|
case eGUI::HP_STATUS: |
|
|
|
case eGUI::HP_STATUS: |
|
|
|
System::player_status($level); |
|
|
|
System::player_status(Game::current()); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case eGUI::NEW_RITUAL: |
|
|
|
case eGUI::NEW_RITUAL: |
|
|
|
$combat_ui.init(); |
|
|
|
$combat_ui.init(); |
|
|
@ -543,16 +547,15 @@ namespace gui { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSM::next_level() { |
|
|
|
void FSM::next_level() { |
|
|
|
$levels.create_level($level.world); |
|
|
|
auto& level = Game::create_level(); |
|
|
|
$level = $levels.next(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$status_ui.update_level($level); |
|
|
|
$status_ui.update_level(level); |
|
|
|
$map_ui.update_level($level); |
|
|
|
$map_ui.update_level(level); |
|
|
|
$combat_ui.update_level($level); |
|
|
|
$combat_ui.update_level(level); |
|
|
|
$main_ui.update_level($level); |
|
|
|
$main_ui.update_level(level); |
|
|
|
$loot_ui.update_level($level); |
|
|
|
$loot_ui.update_level(level); |
|
|
|
|
|
|
|
|
|
|
|
$boss_fight_ui = $levels.create_bossfight($level.world); |
|
|
|
$boss_fight_ui = Game::create_bossfight(); |
|
|
|
$boss_fight_ui->init(); |
|
|
|
$boss_fight_ui->init(); |
|
|
|
|
|
|
|
|
|
|
|
run_systems(); |
|
|
|
run_systems(); |
|
|
|