Now have the ability to place animated fixtures anywhere and to flip them.
This commit is contained in:
parent
e99c07b50c
commit
387d1a5bf5
7 changed files with 36 additions and 17 deletions
28
boss/ui.cpp
28
boss/ui.cpp
|
|
@ -6,6 +6,8 @@
|
|||
#include <thread>
|
||||
#include "sound.hpp"
|
||||
|
||||
const bool DEBUG=false;
|
||||
|
||||
namespace boss {
|
||||
using namespace guecs;
|
||||
|
||||
|
|
@ -35,10 +37,13 @@ namespace boss {
|
|||
st.sprite = std::make_shared<sf::Sprite>(*st.texture);
|
||||
|
||||
auto anim = animation::load(name);
|
||||
float scale = fixture["scale"];
|
||||
float scale_x = fixture["scale_x"];
|
||||
float scale_y = fixture["scale_y"];
|
||||
std::string cell = fixture["cell"];
|
||||
float x = fixture["x"];
|
||||
float y = fixture["y"];
|
||||
|
||||
$fixtures.emplace_back(st, anim, cell, scale);
|
||||
$fixtures.emplace_back(st, anim, cell, scale_x, scale_y, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,11 +66,12 @@ namespace boss {
|
|||
move_player($scene.player["start_pos"]);
|
||||
|
||||
if($scene.floor) {
|
||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0, false);
|
||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0f, 1.0f, false);
|
||||
}
|
||||
|
||||
for(auto& fixture : $fixtures) {
|
||||
position_sprite(fixture.st, fixture.cell, fixture.scale, false);
|
||||
position_sprite(fixture.st, fixture.cell,
|
||||
fixture.scale_x, fixture.scale_y, false, fixture.x, fixture.y);
|
||||
}
|
||||
|
||||
$arena.init();
|
||||
|
|
@ -89,13 +95,13 @@ namespace boss {
|
|||
$combat_ui.init(cell.x, cell.y, cell.w, cell.h);
|
||||
}
|
||||
|
||||
void UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale, bool at_mid) {
|
||||
void UI::position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||
auto& cell = $arena.cell_for(cell_name);
|
||||
float x = float(at_mid ? cell.mid_x : cell.x);
|
||||
float y = float(at_mid ? cell.mid_y : cell.y);
|
||||
|
||||
st.sprite->setPosition({x, y});
|
||||
st.sprite->setScale({scale, scale});
|
||||
st.sprite->setPosition({x + x_diff, y + y_diff});
|
||||
st.sprite->setScale({scale_x, scale_y});
|
||||
}
|
||||
|
||||
void UI::render(sf::RenderWindow& window) {
|
||||
|
|
@ -114,6 +120,8 @@ namespace boss {
|
|||
|
||||
window.draw(*$boss_sprite.sprite);
|
||||
window.draw(*$player_sprite.sprite);
|
||||
|
||||
if(DEBUG) $arena.debug_layout(window);
|
||||
}
|
||||
|
||||
bool UI::mouse(float x, float y, Modifiers mods) {
|
||||
|
|
@ -127,14 +135,16 @@ namespace boss {
|
|||
}
|
||||
|
||||
void UI::move_boss(const std::string& cell_name) {
|
||||
position_sprite($boss_sprite, cell_name, $scene.boss["scale"], $scene.boss["mid_cell"]);
|
||||
float scale = $scene.boss["scale"];
|
||||
position_sprite($boss_sprite, cell_name, scale, scale, $scene.boss["mid_cell"]);
|
||||
|
||||
auto& cell = $arena.cell_for(cell_name);
|
||||
$boss_pos = {float(cell.mid_x), float(cell.mid_y)};
|
||||
}
|
||||
|
||||
void UI::move_player(const std::string& cell_name) {
|
||||
position_sprite($player_sprite, cell_name, $scene.player["scale"], $scene.player["mid_cell"]);
|
||||
float scale = $scene.player["scale"];
|
||||
position_sprite($player_sprite, cell_name, scale, scale, $scene.player["mid_cell"]);
|
||||
}
|
||||
|
||||
void UI::play_animations(sf::RenderWindow& window) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,11 @@ struct AnimatedFixture {
|
|||
textures::SpriteTexture st;
|
||||
components::Animation anim;
|
||||
std::string cell;
|
||||
float scale;
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
float x;
|
||||
float y;
|
||||
bool at_mid=false;
|
||||
};
|
||||
|
||||
namespace boss {
|
||||
|
|
@ -39,7 +43,7 @@ namespace boss {
|
|||
void init();
|
||||
void render(sf::RenderWindow& window);
|
||||
bool mouse(float x, float y, guecs::Modifiers mods);
|
||||
void position_sprite(SpriteTexture& st, const std::string& cell_name, float scale, bool at_mid=false);
|
||||
void position_sprite(textures::SpriteTexture& st, const std::string& cell_name, float scale_x, float scale_y, bool at_mid, float x_diff=0.0f, float y_diff=0.0f);
|
||||
void status(const std::wstring& msg);
|
||||
void move_boss(const std::string& cell_name);
|
||||
void move_player(const std::string& cell_name);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue