Some basic animations working but the loop in bad.

This commit is contained in:
Zed A. Shaw 2025-10-10 01:42:42 -04:00
parent c33f370572
commit 0930b05fc5
5 changed files with 40 additions and 20 deletions

View file

@ -88,9 +88,6 @@ namespace boss {
boss::System::combat(attack_id);
state(State::PLAYER_TURN);
} break;
case TICK:
$ui.play_animations();
break;
default:
break;
// skip it
@ -107,15 +104,12 @@ namespace boss {
break;
case ATTACK: {
$ui.status(L"BOSS TURN");
$ui.move_boss(run % 10 < 5 ? "boss1" : "boss3");
$ui.move_boss(run % 10 < 5 ? "boss1" : "boss2");
$ui.$boss_anim.play();
int attack_id = std::any_cast<int>(data);
boss::System::combat(attack_id);
state(State::BOSS_TURN);
} break;
case TICK:
$ui.play_animations();
break;
default:
// skip it
break;
@ -134,5 +128,6 @@ namespace boss {
void Fight::render(sf::RenderWindow& window) {
$ui.render(window);
$ui.play_animations(window);
}
}

View file

@ -2,6 +2,8 @@
#include "constants.hpp"
#include "components.hpp"
#include "animation.hpp"
#include <chrono>
#include <thread>
namespace boss {
using namespace guecs;
@ -16,7 +18,9 @@ namespace boss {
$boss_sprite = textures::get_sprite(sprite.name);
// floor is std::optional
$floor_sprite = textures::get_sprite(*$scene.floor);
if($scene.floor) {
$floor_sprite = textures::get_sprite(*$scene.floor);
}
$player_sprite = textures::get_sprite($scene.player["sprite"]);
@ -41,7 +45,10 @@ namespace boss {
move_boss($scene.boss["start_pos"]);
move_player($scene.player["start_pos"]);
position_sprite($floor_sprite, $scene.floor_pos, 1.0, false);
if($scene.floor) {
position_sprite($floor_sprite, $scene.floor_pos, 1.0, false);
}
$arena.init();
@ -78,7 +85,10 @@ namespace boss {
$combat_ui.render(window);
$arena.render(window);
window.draw(*$floor_sprite.sprite);
if($floor_sprite.sprite) {
window.draw(*$floor_sprite.sprite);
}
window.draw(*$boss_sprite.sprite);
window.draw(*$player_sprite.sprite);
@ -106,9 +116,14 @@ namespace boss {
position_sprite($player_sprite, cell_name, $scene.player["scale"], $scene.player["mid_cell"]);
}
void UI::play_animations() {
if($boss_anim.playing) {
void UI::play_animations(sf::RenderWindow& window) {
using namespace std::chrono_literals;
while($boss_anim.playing) {
animation::apply($boss_anim, *$boss_sprite.sprite, $boss_pos);
render(window);
window.display();
std::this_thread::sleep_for(16ms);
}
}
}

View file

@ -34,6 +34,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();
void play_animations(sf::RenderWindow& window);
};
}