AnimatedScene now defines how a scene with animated sprites and actors is structured and played.
This commit is contained in:
parent
e1da089600
commit
25f7096489
10 changed files with 43 additions and 48 deletions
31
boss/ui.cpp
31
boss/ui.cpp
|
|
@ -14,10 +14,10 @@ namespace boss {
|
|||
UI::UI(shared_ptr<World> world, Entity boss_id) :
|
||||
$world(world),
|
||||
$boss_id(boss_id),
|
||||
$scene(world->get<components::BossFight>($boss_id)),
|
||||
$scene(world->get<components::AnimatedScene>($boss_id)),
|
||||
$combat_ui(true)
|
||||
{
|
||||
std::string sprite_name = $scene.boss["sprite"];
|
||||
std::string sprite_name = $scene.actors["boss"]["sprite"];
|
||||
$boss_sprite = textures::get_sprite(sprite_name);
|
||||
|
||||
// floor is std::optional
|
||||
|
|
@ -25,7 +25,7 @@ namespace boss {
|
|||
$floor_sprite = textures::get_sprite(*$scene.floor);
|
||||
}
|
||||
|
||||
$player_sprite = textures::get_sprite($scene.player["sprite"]);
|
||||
$player_sprite = textures::get_sprite($scene.actors["player"]["sprite"]);
|
||||
|
||||
dbc::check(animation::has(sprite_name), "add boss animation to animations.json");
|
||||
$boss_anim = animation::load(sprite_name);
|
||||
|
|
@ -66,8 +66,8 @@ namespace boss {
|
|||
"[floor4|player5|player6|player7|player8|_]"
|
||||
);
|
||||
|
||||
move_boss($scene.boss["start_pos"]);
|
||||
move_player($scene.player["start_pos"]);
|
||||
$boss_pos = move_actor($boss_sprite, "boss", $scene.actors["boss"]["start_pos"]);
|
||||
move_actor($player_sprite, "player", $scene.actors["player"]["start_pos"]);
|
||||
|
||||
if($scene.floor) {
|
||||
position_sprite($floor_sprite, $scene.floor_pos, 1.0f, 1.0f, false);
|
||||
|
|
@ -100,13 +100,16 @@ 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_x, float scale_y, bool at_mid, float x_diff, float y_diff) {
|
||||
sf::Vector2f 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 + x_diff, y + y_diff});
|
||||
sf::Vector2f pos{x + x_diff, y + y_diff};
|
||||
st.sprite->setPosition(pos);
|
||||
st.sprite->setScale({scale_x, scale_y});
|
||||
|
||||
return pos;
|
||||
}
|
||||
|
||||
void UI::render(sf::RenderWindow& window) {
|
||||
|
|
@ -139,17 +142,9 @@ namespace boss {
|
|||
$arena.show_text("status", msg);
|
||||
}
|
||||
|
||||
void UI::move_boss(const std::string& cell_name) {
|
||||
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) {
|
||||
float scale = $scene.player["scale"];
|
||||
position_sprite($player_sprite, cell_name, scale, scale, $scene.player["mid_cell"]);
|
||||
sf::Vector2f UI::move_actor(textures::SpriteTexture& st, const std::string& actor, const std::string& cell_name) {
|
||||
float scale = $scene.actors[actor]["scale"];
|
||||
return position_sprite(st, cell_name, scale, scale, $scene.actors[actor]["mid_cell"]);
|
||||
}
|
||||
|
||||
void UI::play_animations() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue