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

@ -111,12 +111,22 @@
},
"test_boss": {
"_type": "Animation",
"easing": 3,
"easing": 1,
"ease_rate": 0.5,
"scale": 0.4,
"simple": true,
"frames": 1,
"speed": 0.02,
"stationary": true
},
"rat_king_boss": {
"_type": "Animation",
"easing": 1,
"ease_rate": 0.5,
"scale": 0.4,
"simple": false,
"frames": 2,
"speed": 0.02,
"stationary": true
}
}

View file

@ -2,23 +2,23 @@
"RAT_KING": {
"components": [
{"_type": "BossFight",
"background": "test_background",
"floor": "test_floor",
"floor_pos": "floor2",
"background": "boss_fight_background",
"floor": "devils_fingers_background",
"floor_pos": "floor1",
"player": {
"sprite": "test_player",
"sprite": "peasant_girl_rear_view",
"start_pos": "player2",
"scale": 0.5,
"mid_cell": false
},
"boss": {
"start_pos": "boss3",
"start_pos": "boss2",
"scale": 0.7,
"mid_cell": true
}
},
{"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false},
{"_type": "Sprite", "name": "test_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false},
{"_type": "Sprite", "name": "rat_king_boss", "width": 720, "height": 720, "scale": 0.8, "stationary": false},
{"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"}
]
}

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
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"]);
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);
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);
};
}