diff --git a/assets/enemies.json b/assets/enemies.json index 9d12a8c..6b209e6 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -22,7 +22,7 @@ {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, - {"_type": "Personality", "hearing_distance": 5, "tough": true}, + {"_type": "Personality", "hearing_distance": 5, "tough": false}, {"_type": "Sprite", "name": "gold_savior", "width": 256, "height": 256, "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Humanoid_Death_1"} ] @@ -67,7 +67,7 @@ {"_type": "Collision", "has": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "ai_script": "Enemy::actions", "ai_start_name": "Enemy::initial_state", "ai_goal_name": "Enemy::final_state"}, - {"_type": "Personality", "hearing_distance": 5, "tough": true}, + {"_type": "Personality", "hearing_distance": 5, "tough": false}, {"_type": "Sprite", "name": "rat_with_sword", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "Small_Rat", "death": "Creature_Death_1"} ] diff --git a/boss/fight.cpp b/boss/fight.cpp index 727d598..9d41205 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -1,4 +1,5 @@ #include "boss/fight.hpp" +#include "boss/system.hpp" namespace boss { Fight::Fight(shared_ptr world, Entity boss_id) : @@ -10,33 +11,26 @@ namespace boss { } bool Fight::event(gui::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); + switch($state) { FSM_STATE(State, START, ev, data); + FSM_STATE(State, BOSS_TURN, ev, data); + FSM_STATE(State, PLAYER_TURN, ev, data); FSM_STATE(State, END, ev, data); } return in_state(State::END); } - void Fight::START(gui::Event ev, std::any data) { + bool Fight::handle_mouse(gui::Event ev) { using enum gui::Event; switch(ev) { - // this is only if using the debug X key to skip it - case BOSS_START: - state(State::END); - break; case MOUSE_CLICK: { $ui.mouse(mouse_pos.x, mouse_pos.y, guecs::NO_MODS); - - if($ui.boss_dead()) { - state(State::END); - } } break; - case ATTACK: { - int attack_id = std::any_cast(data); - $ui.attack(attack_id); - } break; case MOUSE_MOVE: { $ui.mouse(mouse_pos.x, mouse_pos.y, {1 << guecs::ModBit::hover}); } @@ -50,17 +44,79 @@ namespace boss { case MOUSE_DROP: dbc::log("mouse DROP"); break; + default: + return false; + } + + // switch/default didn't happen so handled it. + return true; + } + + void Fight::START(gui::Event ev, std::any data) { + (void)data; + using enum gui::Event; + + switch(ev) { + // this is only if using the debug X key to skip it + case BOSS_START: + state(State::END); + break; case TICK: - $ui.run_systems(); + run_systems(); + break; + case ATTACK: + state(State::PLAYER_TURN); break; default: fmt::println("BOSS_FIGHT unknown event {}", (int)ev); } } + void Fight::BOSS_TURN(gui::Event ev, std::any data) { + using enum gui::Event; + + switch(ev) { + // this is only if using the debug X key to skip it + case BOSS_START: + state(State::END); + break; + case ATTACK: { + int attack_id = std::any_cast(data); + boss::System::combat(attack_id); + state(State::PLAYER_TURN); + } break; + default: + break; + // skip it + } + } + + void Fight::PLAYER_TURN(gui::Event ev, std::any data) { + using enum gui::Event; + + switch(ev) { + // this is only if using the debug X key to skip it + case BOSS_START: + state(State::END); + break; + case ATTACK: { + int attack_id = std::any_cast(data); + boss::System::combat(attack_id); + state(State::BOSS_TURN); + } break; + default: + // skip it + break; + } + } + void Fight::END(gui::Event ev, std::any data) { // We need to clean up that world I think, but not sure how (void)ev; (void)data; } + + void Fight::run_systems() { + + } } diff --git a/boss/fight.hpp b/boss/fight.hpp index 6917b4c..b7cd779 100644 --- a/boss/fight.hpp +++ b/boss/fight.hpp @@ -1,5 +1,6 @@ #pragma once +#define FSM_DEBUG 1 #include "simplefsm.hpp" #include "dinkyecs.hpp" #include "boss/ui.hpp" @@ -12,7 +13,9 @@ namespace boss { enum class State { START=0, - END=1 + BOSS_TURN=1, + PLAYER_TURN=2, + END=3 }; class Fight : public DeadSimpleFSM { @@ -21,16 +24,22 @@ namespace boss { DinkyECS::Entity $boss_id = NONE; boss::UI $ui; sf::Vector2f mouse_pos{0,0}; + int run = 0; Fight(shared_ptr world, DinkyECS::Entity boss_id); + bool handle_mouse(gui::Event ev); bool event(gui::Event ev, std::any data); void START(gui::Event ev, std::any data); + void BOSS_TURN(gui::Event ev, std::any data); + void PLAYER_TURN(gui::Event ev, std::any data); void END(gui::Event ev, std::any data); void render(sf::RenderWindow& window) { $ui.render(window); } + + void run_systems(); }; } diff --git a/boss/system.cpp b/boss/system.cpp index 135ff57..60d3b95 100644 --- a/boss/system.cpp +++ b/boss/system.cpp @@ -26,4 +26,11 @@ namespace boss { return make_shared(world, boss_id); } + + void System::combat(int attack_id) { + (void)attack_id; + } + + void System::ai_initialize() { + } } diff --git a/boss/system.hpp b/boss/system.hpp index fb9b621..9bcfbb9 100644 --- a/boss/system.hpp +++ b/boss/system.hpp @@ -7,5 +7,7 @@ namespace boss { namespace System { void load_config(); std::shared_ptr create_bossfight(); + void combat(int attack_id); + void ai_initialize(); } } diff --git a/boss/ui.cpp b/boss/ui.cpp index 8790141..ebeb7fb 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -86,16 +86,4 @@ namespace boss { || $combat_ui.mouse(x, y, mods) || $actions.mouse(x, y, mods); } - - bool UI::boss_dead() { - return false; - } - - void UI::run_systems() { - // does nothing yet - } - - void UI::attack(int attack_id) { - fmt::println("boss attacked with {}", attack_id); - } } diff --git a/boss/ui.hpp b/boss/ui.hpp index 5cd4072..a5bb795 100644 --- a/boss/ui.hpp +++ b/boss/ui.hpp @@ -32,8 +32,5 @@ namespace boss { void render(sf::RenderWindow& window); bool mouse(float x, float y, guecs::Modifiers mods); void position_sprite(SpriteTexture& st, const std::string& name, float scale, bool at_mid=false); - bool boss_dead(); - void run_systems(); - void attack(int attack_id); }; }