Boss fight now has combat stats and damage so I can now have a boss fight.

This commit is contained in:
Zed A. Shaw 2025-11-22 00:50:47 -05:00
parent 8ee3e8736f
commit 63a17d7efa
7 changed files with 58 additions and 9 deletions

27
assets/stories.json Normal file
View file

@ -0,0 +1,27 @@
{
"rat_king":
{"_type": "Storyboard",
"image": "test_story",
"audio": "rat_king_fight",
"layout": [
"[a|b|c1]",
"[d|e|c2]",
"[g|h|i]"
],
"beats": [
["00:00", "a","pan"],
["00:06", "a","pan"],
["00:13", "b","pan"],
["00:19", "g","pan"],
["00:25", "h","pan"],
["00:29", "h","bounce"],
["00:31", "c1","pan"],
["00:34", "c2","pan"],
["00:39", "d","bounce"],
["00:44", "e","shake"],
["00:48", "i","pan"],
["00:53", "i","shake"],
["00:55", "i","bounce"]
]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

View file

@ -3,10 +3,10 @@
#include "animation.hpp"
namespace boss {
Fight::Fight(shared_ptr<World> world, Entity boss_id) :
Fight::Fight(shared_ptr<World> world, Entity boss_id, Entity player_id) :
$world(world),
$boss_id(boss_id),
$ui(world->get<components::AnimatedScene>($boss_id), boss_id)
$ui(world, boss_id, player_id)
{
$ui.init();
}
@ -88,6 +88,7 @@ namespace boss {
$ui.move_actor("player", player_pos);
int attack_id = std::any_cast<int>(data);
boss::System::combat($world, $boss_id, attack_id);
$ui.update_stats();
state(State::PLAYER_TURN);
} break;
default:

View file

@ -26,7 +26,7 @@ namespace boss {
sf::Vector2f mouse_pos{0,0};
int run = 0;
Fight(shared_ptr<World> world, DinkyECS::Entity boss_id);
Fight(shared_ptr<World> world, Entity boss_id, Entity player_id);
bool handle_mouse(gui::Event ev);
bool event(gui::Event ev, std::any data);

View file

@ -46,7 +46,7 @@ namespace boss {
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
return make_shared<boss::Fight>(world, boss_id);
return make_shared<boss::Fight>(world, boss_id, level.player);
}
void System::combat(std::shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, int attack_id) {
@ -55,8 +55,8 @@ namespace boss {
dbc::check(world->has<ai::EntityAI>(boss_id), "boss doesn't have an AI");
auto& player_combat = world->get<Combat>(level.player);
auto& boss_ai = world->get<ai::EntityAI>(boss_id);
auto& boss_combat = world->get<Combat>(boss_id);
auto& boss_ai = world->get<ai::EntityAI>(boss_id);
combat::BattleEngine battle;
battle.add_enemy({boss_id, boss_ai, boss_combat});

View file

@ -3,14 +3,19 @@
#include "constants.hpp"
#include "components.hpp"
#include "animation.hpp"
#include <fmt/xchar.h>
#include "game_level.hpp"
namespace boss {
using namespace guecs;
using namespace DinkyECS;
UI::UI(components::AnimatedScene& scene, Entity boss_id) :
UI::UI(shared_ptr<World> world, Entity boss_id, Entity player_id) :
$world(world),
$boss_id(boss_id),
$player_id(player_id),
$combat_ui(true),
$arena(scene),
$arena(world->get<components::AnimatedScene>($boss_id)),
$view_texture({BOSS_VIEW_WIDTH, BOSS_VIEW_HEIGHT}),
$view_sprite($view_texture.getTexture())
{
@ -33,7 +38,7 @@ namespace boss {
auto stats = $actions.entity("stats");
$actions.set<Rectangle>(stats, {});
$actions.set<Text>(stats, {L"stats"});
update_stats();
$actions.init();
@ -41,6 +46,14 @@ namespace boss {
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
}
void UI::update_stats() {
auto& player_combat = $world->get<components::Combat>($player_id);
auto& boss_combat = $world->get<components::Combat>($boss_id);
$actions.show_text("stats", fmt::format(
L"PLAYER: {}\nBOSS: {}", player_combat.hp, boss_combat.hp));
}
void UI::render(sf::RenderWindow& window) {
$actions.render(window);
$combat_ui.render(window);

View file

@ -9,11 +9,18 @@ namespace components {
struct Animation;
}
// needed to break an include cycle
namespace GameDB {
struct Level;
}
namespace boss {
using std::shared_ptr;
struct UI {
shared_ptr<DinkyECS::World> $world = nullptr;
DinkyECS::Entity $boss_id = DinkyECS::NONE;
DinkyECS::Entity $player_id = DinkyECS::NONE;
gui::CombatUI $combat_ui;
scene::Engine $arena;
guecs::UI $actions;
@ -21,7 +28,7 @@ namespace boss {
sf::Sprite $view_sprite;
cinematic::Camera $camera;
UI(components::AnimatedScene &scene, DinkyECS::Entity boss_id);
UI(shared_ptr<DinkyECS::World> world, DinkyECS::Entity boss_id, DinkyECS::Entity player_id);
void init();
void render(sf::RenderWindow& window);
@ -29,6 +36,7 @@ namespace boss {
void status(const std::wstring& msg);
void move_actor(const std::string& actor, const std::string& cell_name);
void animate_actor(const std::string& actor);
void update_stats();
void play_animations();
void zoom(const std::string &cell);
};