Now have animated torches that are defined from json, and smoother animations in the arena.

This commit is contained in:
Zed A. Shaw 2025-10-21 00:21:46 -04:00
parent 387d1a5bf5
commit 7c11ffa2af
10 changed files with 111 additions and 73 deletions

View file

@ -128,7 +128,8 @@ namespace boss {
}
void Fight::render(sf::RenderWindow& window) {
$ui.play_animations(window);
window.clear();
$ui.play_animations();
$ui.render(window);
}
}

View file

@ -35,10 +35,14 @@ namespace boss {
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_x = fixture["scale_x"];
float scale_y = fixture["scale_y"];
auto anim = animation::load(name);
anim.scale_x = scale_x;
anim.scale_y = scale_y;
anim.play();
std::string cell = fixture["cell"];
float x = fixture["x"];
float y = fixture["y"];
@ -72,6 +76,7 @@ namespace boss {
for(auto& fixture : $fixtures) {
position_sprite(fixture.st, fixture.cell,
fixture.scale_x, fixture.scale_y, false, fixture.x, fixture.y);
fixture.pos = fixture.st.sprite->getPosition();
}
$arena.init();
@ -147,27 +152,14 @@ namespace boss {
position_sprite($player_sprite, cell_name, scale, scale, $scene.player["mid_cell"]);
}
void UI::play_animations(sf::RenderWindow& window) {
if($boss_anim.playing) {
using namespace std::chrono_literals;
auto& sound = $world->get<components::Sound>($boss_id);
animation::apply($boss_anim, *$boss_sprite.sprite, $boss_pos);
if($boss_anim.current == 1 && !sound::playing(sound.attack)) {
sound::play(sound.attack);
void UI::play_animations() {
for(auto& fixture : $fixtures) {
if(fixture.anim.playing) {
animation::apply(fixture.anim, *fixture.st.sprite, fixture.pos);
}
}
// https://www.construct.net/en/blogs/ashleys-blog-2/using-lerp-delta-time-924
// frame start
render(window);
window.display();
// frame end
// deltaTime = end - start
// lerp(a, b, 1 - f ^ deltaTime)
// std::this_thread::sleep_for(16ms);
} else {
if($boss_anim.playing) {
animation::apply($boss_anim, *$boss_sprite.sprite, $boss_pos);
}
}

View file

@ -16,6 +16,7 @@ struct AnimatedFixture {
float x;
float y;
bool at_mid=false;
sf::Vector2f pos{0,0};
};
namespace boss {
@ -47,6 +48,6 @@ namespace boss {
void status(const std::wstring& msg);
void move_boss(const std::string& cell_name);
void move_player(const std::string& cell_name);
void play_animations(sf::RenderWindow& window);
void play_animations();
};
}