The whole boss fight scene is now configurable with json.
This commit is contained in:
parent
06f6098281
commit
06a174040f
5 changed files with 29 additions and 43 deletions
|
|
@ -4,7 +4,18 @@
|
|||
{"_type": "BossFight",
|
||||
"background": "test_background",
|
||||
"floor": "test_floor",
|
||||
"weapon_sound": "Sword_Hit_2"
|
||||
"floor_pos": "floor4",
|
||||
"player": {
|
||||
"sprite": "test_player",
|
||||
"start_pos": "player1",
|
||||
"scale": 0.5,
|
||||
"mid_cell": false
|
||||
},
|
||||
"boss": {
|
||||
"start_pos": "boss2",
|
||||
"scale": 0.7,
|
||||
"mid_cell": true
|
||||
}
|
||||
},
|
||||
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false},
|
||||
{"_type": "Animation",
|
||||
|
|
@ -19,31 +30,5 @@
|
|||
{"_type": "Sprite", "name": "test_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false},
|
||||
{"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"}
|
||||
]
|
||||
},
|
||||
"DEVILS_FINGERS": {
|
||||
"components": [
|
||||
{"_type": "BossFight",
|
||||
"background": "test_background",
|
||||
"floor": "test_floor",
|
||||
"weapon_sound": "Sword_Hit_2"
|
||||
},
|
||||
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false},
|
||||
{"_type": "Animation",
|
||||
"easing": 1,
|
||||
"ease_rate": 0.1,
|
||||
"simple": false,
|
||||
"frames": 2,
|
||||
"speed": 0.02,
|
||||
"scale": 0.1,
|
||||
"stationary": true
|
||||
},
|
||||
{"_type": "Sprite",
|
||||
"name": "test_boss",
|
||||
"width": 720,
|
||||
"height": 720,
|
||||
"scale": 1.0
|
||||
},
|
||||
{"_type": "Sound", "attack": "Spider_1", "death": "Spider_2"}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
boss/ui.cpp
16
boss/ui.cpp
|
|
@ -8,23 +8,23 @@ namespace boss {
|
|||
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
$scene(world->get<components::BossFight>($boss_id)),
|
||||
$combat_ui(true)
|
||||
{
|
||||
auto& sprite = world->get<components::Sprite>($boss_id);
|
||||
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);
|
||||
$floor_sprite = textures::get_sprite(*$scene.floor);
|
||||
|
||||
$player_sprite = textures::get_sprite("test_player");
|
||||
$player_sprite = textures::get_sprite($scene.player["sprite"]);
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
$arena.position(SCREEN_WIDTH-BOSS_VIEW_WIDTH,0, BOSS_VIEW_WIDTH, SCREEN_HEIGHT);
|
||||
$arena.set<Background>($arena.MAIN, {$arena.$parser, THEME.DARK_MID});
|
||||
auto& background = $arena.get<Background>($arena.MAIN);
|
||||
background.set_sprite("test_background", true);
|
||||
background.set_sprite($scene.background, true);
|
||||
|
||||
$arena.layout(
|
||||
"[_ |boss1 |boss2 |boss3 |boss4 |_]"
|
||||
|
|
@ -35,9 +35,9 @@ namespace boss {
|
|||
"[floor4|player5|player6|player7|player8|_]"
|
||||
);
|
||||
|
||||
position_sprite($boss_sprite, "boss3", 0.7, true);
|
||||
position_sprite($player_sprite, "player2", 0.5, false);
|
||||
position_sprite($floor_sprite, "floor1", 1.0, false);
|
||||
position_sprite($boss_sprite, $scene.boss["start_pos"], $scene.boss["scale"], $scene.boss["mid_cell"]);
|
||||
position_sprite($player_sprite, $scene.player["start_pos"], $scene.player["scale"], $scene.player["mid_cell"]);
|
||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0, false);
|
||||
|
||||
$arena.init();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,10 @@
|
|||
#include "textures.hpp"
|
||||
#include "gui/combat_ui.hpp"
|
||||
|
||||
namespace components {
|
||||
struct BossFight;
|
||||
}
|
||||
|
||||
namespace boss {
|
||||
using std::shared_ptr;
|
||||
using namespace DinkyECS;
|
||||
|
|
@ -14,6 +18,7 @@ namespace boss {
|
|||
struct UI {
|
||||
shared_ptr<World> $world = nullptr;
|
||||
Entity $boss_id = NONE;
|
||||
components::BossFight& $scene;
|
||||
gui::CombatUI $combat_ui;
|
||||
SpriteTexture $boss_sprite;
|
||||
SpriteTexture $player_sprite;
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ namespace components {
|
|||
struct BossFight {
|
||||
std::string background;
|
||||
std::optional<std::string> floor;
|
||||
std::string weapon_sound;
|
||||
std::string floor_pos;
|
||||
json player;
|
||||
json boss;
|
||||
};
|
||||
|
||||
struct Combat {
|
||||
|
|
@ -147,7 +149,7 @@ namespace components {
|
|||
using ComponentMap = std::unordered_map<std::string, ReflFuncSignature>;
|
||||
|
||||
ENROLL_COMPONENT(Tile, display, foreground, background);
|
||||
ENROLL_COMPONENT(BossFight, background, floor, weapon_sound);
|
||||
ENROLL_COMPONENT(BossFight, background, floor, floor_pos, player, boss);
|
||||
ENROLL_COMPONENT(Sprite, name, width, height, scale);
|
||||
ENROLL_COMPONENT(Curative, hp);
|
||||
ENROLL_COMPONENT(LightSource, strength, radius);
|
||||
|
|
|
|||
|
|
@ -52,10 +52,4 @@ TEST_CASE("make sure json_mods works", "[components]") {
|
|||
|
||||
auto boss = world.get<BossFight>(rat_king);
|
||||
REQUIRE(boss.floor != std::nullopt);
|
||||
|
||||
// now load the other one for the other way optional is used
|
||||
auto devils_fingers = world.entity();
|
||||
components::configure_entity(world, devils_fingers, config["DEVILS_FINGERS"]["components"]);
|
||||
auto boss2 = world.get<BossFight>(devils_fingers);
|
||||
REQUIRE(boss2.floor != std::nullopt);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue