Create the systems.cpp for the boss fight mini game.
This commit is contained in:
parent
27b71d4ba3
commit
06f6098281
7 changed files with 67 additions and 38 deletions
29
boss/system.cpp
Normal file
29
boss/system.cpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include "boss/system.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include "components.hpp"
|
||||
#include "game_level.hpp"
|
||||
|
||||
namespace boss {
|
||||
using namespace components;
|
||||
|
||||
void System::load_config() {
|
||||
fmt::println("load it");
|
||||
}
|
||||
|
||||
shared_ptr<boss::UI> System::create_bossfight() {
|
||||
auto& level = GameDB::current_level();
|
||||
auto prev_world = GameDB::current_world();
|
||||
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
|
||||
auto world = GameDB::clone_load_world(prev_world);
|
||||
auto& config = prev_world->get_the<GameConfig>();
|
||||
|
||||
auto boss_names = config.bosses.keys();
|
||||
auto& level_name = boss_names[level.index % boss_names.size()];
|
||||
auto& boss_data = config.bosses[level_name];
|
||||
|
||||
auto boss_id = world->entity();
|
||||
components::configure_entity(*world, boss_id, boss_data["components"]);
|
||||
|
||||
return make_shared<boss::UI>(world, boss_id);
|
||||
}
|
||||
}
|
||||
11
boss/system.hpp
Normal file
11
boss/system.hpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
#include "dinkyecs.hpp"
|
||||
#include <memory>
|
||||
#include "boss/ui.hpp"
|
||||
|
||||
namespace boss {
|
||||
namespace System {
|
||||
void load_config();
|
||||
std::shared_ptr<boss::UI> create_bossfight();
|
||||
}
|
||||
}
|
||||
14
boss/ui.cpp
14
boss/ui.cpp
|
|
@ -1,5 +1,6 @@
|
|||
#include "boss/ui.hpp"
|
||||
#include "constants.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
namespace boss {
|
||||
using namespace guecs;
|
||||
|
|
@ -7,11 +8,16 @@ namespace boss {
|
|||
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
$combat_ui(true),
|
||||
$boss_sprite(textures::get_sprite("test_boss")),
|
||||
$player_sprite(textures::get_sprite("test_player")),
|
||||
$floor_sprite(textures::get_sprite("test_floor"))
|
||||
$combat_ui(true)
|
||||
{
|
||||
auto& sprite = world->get<components::Sprite>($boss_id);
|
||||
$boss_sprite = textures::get_sprite(sprite.name);
|
||||
|
||||
auto& boss_conf = world->get<components::BossFight>($boss_id);
|
||||
// floor is std::optional
|
||||
$floor_sprite = textures::get_sprite(*boss_conf.floor);
|
||||
|
||||
$player_sprite = textures::get_sprite("test_player");
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
|
|
|
|||
|
|
@ -16,19 +16,6 @@ struct LevelScaling {
|
|||
int map_height=20;
|
||||
};
|
||||
|
||||
inline shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world)
|
||||
{
|
||||
auto world = make_shared<DinkyECS::World>();
|
||||
|
||||
if(prev_world == nullptr) {
|
||||
GameDB::load_configs(*world);
|
||||
} else {
|
||||
prev_world->clone_into(*world);
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
namespace GameDB {
|
||||
using std::shared_ptr, std::string, std::make_shared;
|
||||
|
||||
|
|
@ -48,6 +35,19 @@ namespace GameDB {
|
|||
};
|
||||
}
|
||||
|
||||
shared_ptr<DinkyECS::World> clone_load_world(shared_ptr<DinkyECS::World> prev_world) {
|
||||
auto world = make_shared<DinkyECS::World>();
|
||||
|
||||
if(prev_world == nullptr) {
|
||||
GameDB::load_configs(*world);
|
||||
} else {
|
||||
prev_world->clone_into(*world);
|
||||
}
|
||||
|
||||
return world;
|
||||
}
|
||||
|
||||
|
||||
size_t new_level(std::shared_ptr<DinkyECS::World> prev_world) {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto world = clone_load_world(prev_world);
|
||||
|
|
@ -88,24 +88,6 @@ namespace GameDB {
|
|||
return current_level().world;
|
||||
}
|
||||
|
||||
shared_ptr<boss::UI> create_bossfight() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
auto prev_world = current_world();
|
||||
dbc::check(prev_world != nullptr, "Starter world for boss fights can't be null.");
|
||||
auto world = clone_load_world(prev_world);
|
||||
auto& config = prev_world->get_the<GameConfig>();
|
||||
|
||||
// BUG: the jank is too strong here
|
||||
auto boss_names = config.bosses.keys();
|
||||
auto& level_name = boss_names[LDB->current_level % boss_names.size()];
|
||||
auto& boss_data = config.bosses[level_name];
|
||||
|
||||
auto boss_id = world->entity();
|
||||
components::configure_entity(*world, boss_id, boss_data["components"]);
|
||||
|
||||
return make_shared<boss::UI>(world, boss_id);
|
||||
}
|
||||
|
||||
Level& create_level() {
|
||||
dbc::check(initialized, "Forgot to call GameDB::init()");
|
||||
dbc::check(LDB->current_level < LDB->levels.size(), "attempt to get next level when at end");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
#include "dinkyecs.hpp"
|
||||
#include "boss/ui.hpp"
|
||||
#include "dinkyecs.hpp"
|
||||
#include "lights.hpp"
|
||||
#include "map.hpp"
|
||||
#include <memory>
|
||||
|
|
@ -22,7 +21,6 @@ namespace GameDB {
|
|||
std::shared_ptr<SpatialMap> collision = nullptr;
|
||||
};
|
||||
|
||||
std::shared_ptr<boss::UI> create_bossfight();
|
||||
Level& create_level();
|
||||
|
||||
void init();
|
||||
|
|
@ -31,5 +29,6 @@ namespace GameDB {
|
|||
components::Position& player_position();
|
||||
DinkyECS::Entity the_player();
|
||||
|
||||
std::shared_ptr<DinkyECS::World> clone_load_world(std::shared_ptr<DinkyECS::World> prev_world);
|
||||
void load_configs(DinkyECS::World &world);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include <fmt/xchar.h>
|
||||
#include "gui/guecstra.hpp"
|
||||
#include "game_level.hpp"
|
||||
#include "boss/system.hpp"
|
||||
|
||||
namespace gui {
|
||||
using namespace components;
|
||||
|
|
@ -544,7 +545,7 @@ namespace gui {
|
|||
|
||||
void FSM::next_level(bool bossfight) {
|
||||
if(bossfight) {
|
||||
$boss_fight_ui = GameDB::create_bossfight();
|
||||
$boss_fight_ui = boss::System::create_bossfight();
|
||||
$boss_fight_ui->init();
|
||||
} else {
|
||||
GameDB::create_level();
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ sources = [
|
|||
'autowalker.cpp',
|
||||
'backend.cpp',
|
||||
'battle.cpp',
|
||||
'boss/system.cpp',
|
||||
'boss/ui.cpp',
|
||||
'combat.cpp',
|
||||
'components.cpp',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue