Arena works better now and I can give a list of sprites to work as fixtures in a scene.
This commit is contained in:
parent
59ba73baa0
commit
71e3c97cf0
8 changed files with 169 additions and 36 deletions
37
boss/ui.cpp
37
boss/ui.cpp
|
|
@ -15,8 +15,8 @@ namespace boss {
|
|||
$scene(world->get<components::BossFight>($boss_id)),
|
||||
$combat_ui(true)
|
||||
{
|
||||
auto& sprite = $world->get<components::Sprite>($boss_id);
|
||||
$boss_sprite = textures::get_sprite(sprite.name);
|
||||
std::string sprite_name = $scene.boss["sprite"];
|
||||
$boss_sprite = textures::get_sprite(sprite_name);
|
||||
|
||||
// floor is std::optional
|
||||
if($scene.floor) {
|
||||
|
|
@ -25,14 +25,21 @@ namespace boss {
|
|||
|
||||
$player_sprite = textures::get_sprite($scene.player["sprite"]);
|
||||
|
||||
dbc::check(animation::has(sprite.name), "add boss animation to animations.json");
|
||||
$boss_anim = animation::load(sprite.name);
|
||||
dbc::check(animation::has(sprite_name), "add boss animation to animations.json");
|
||||
$boss_anim = animation::load(sprite_name);
|
||||
|
||||
$torch_left = textures::get_sprite("torch_crappy");
|
||||
$torch_left_anim = animation::load("torch_crappy");
|
||||
$torch_right.texture = $torch_left.texture;
|
||||
$torch_right.sprite = std::make_shared<sf::Sprite>(*$torch_right.texture);
|
||||
$torch_right_anim = animation::load("torch_crappy");
|
||||
for(auto& fixture : $scene.fixtures) {
|
||||
std::string name = fixture["name"];
|
||||
auto st = textures::get_sprite(name);
|
||||
// clone the sprite so it can be positioned
|
||||
st.sprite = std::make_shared<sf::Sprite>(*st.texture);
|
||||
|
||||
auto anim = animation::load(name);
|
||||
float scale = fixture["scale"];
|
||||
std::string cell = fixture["cell"];
|
||||
|
||||
$fixtures.emplace_back(st, anim, cell, scale);
|
||||
}
|
||||
}
|
||||
|
||||
void UI::init() {
|
||||
|
|
@ -57,8 +64,9 @@ namespace boss {
|
|||
position_sprite($floor_sprite, $scene.floor_pos, 1.0, false);
|
||||
}
|
||||
|
||||
position_sprite($torch_left, "torch1", 1.0, false);
|
||||
position_sprite($torch_right, "torch2", 1.0, false);
|
||||
for(auto& fixture : $fixtures) {
|
||||
position_sprite(fixture.st, fixture.cell, fixture.scale, false);
|
||||
}
|
||||
|
||||
$arena.init();
|
||||
|
||||
|
|
@ -103,10 +111,9 @@ namespace boss {
|
|||
window.draw(*$boss_sprite.sprite);
|
||||
window.draw(*$player_sprite.sprite);
|
||||
|
||||
window.draw(*$torch_left.sprite);
|
||||
window.draw(*$torch_right.sprite);
|
||||
|
||||
// $arena.debug_layout(window);
|
||||
for(auto& fixture : $fixtures) {
|
||||
window.draw(*fixture.st.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
bool UI::mouse(float x, float y, Modifiers mods) {
|
||||
|
|
|
|||
12
boss/ui.hpp
12
boss/ui.hpp
|
|
@ -7,6 +7,13 @@
|
|||
#include "gui/combat_ui.hpp"
|
||||
#include "components.hpp"
|
||||
|
||||
struct AnimatedFixture {
|
||||
textures::SpriteTexture st;
|
||||
components::Animation anim;
|
||||
std::string cell;
|
||||
float scale;
|
||||
};
|
||||
|
||||
namespace boss {
|
||||
using std::shared_ptr;
|
||||
using namespace DinkyECS;
|
||||
|
|
@ -25,10 +32,7 @@ namespace boss {
|
|||
components::Animation $boss_anim;
|
||||
sf::Vector2f $boss_pos;
|
||||
|
||||
SpriteTexture $torch_left;
|
||||
SpriteTexture $torch_right;
|
||||
components::Animation $torch_left_anim;
|
||||
components::Animation $torch_right_anim;
|
||||
std::vector<AnimatedFixture> $fixtures;
|
||||
|
||||
UI(shared_ptr<World> world, Entity boss_id);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue