Now have a fancy hand animation when you cast your rituals.

This commit is contained in:
Zed A. Shaw 2025-09-15 02:14:13 -04:00
parent ad3e580495
commit 7af264e147
9 changed files with 43 additions and 8 deletions

View file

@ -81,7 +81,6 @@ namespace animation {
sprite.setPosition(pos);
sprite.setScale(scale);
return anim.playing;
}
@ -105,6 +104,10 @@ namespace animation {
for(auto& [name, data] : animations.json().items()) {
try {
auto anim = components::convert<Animation>(data);
dbc::check(sprites.contains(name),
fmt::format("animation '{}' doesn't have sprite, spelled wrong in config.json?", name));
auto& sprite_config = sprites[name];
anim.frame_width = sprite_config["frame_width"];

View file

@ -9,6 +9,16 @@
"speed": 0.1,
"stationary": false
},
"hand": {
"_type": "Animation",
"easing": 0,
"ease_rate": 0.5,
"scale": 1.0,
"simple": false,
"frames": 3,
"speed": 0.1,
"stationary": false
},
"lightning_animation": {
"_type": "Animation",
"easing": 0,

View file

@ -229,6 +229,11 @@
{"path": "assets/sprites/dead_body_lootable.png",
"frame_width": 256,
"frame_height": 256
},
"hand":
{"path": "assets/hands/hands.png",
"frame_width": 900,
"frame_height": 600
}
},
"worldgen": {

BIN
assets/hands/hands.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View file

@ -243,6 +243,7 @@ namespace gui {
run_systems();
break;
case ATTACK:
$main_ui.play_hands();
$main_ui.dirty();
sound::play("Sword_Hit_1");
state(State::ATTACKING);

View file

@ -11,7 +11,9 @@ namespace gui {
MainUI::MainUI(sf::RenderWindow& window) :
$window(window),
$rayview(std::make_shared<Raycaster>(RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT))
$rayview(std::make_shared<Raycaster>(RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)),
$hand(textures::get_sprite("hand")),
$hand_anim(animation::load("hand"))
{
$window.setVerticalSyncEnabled(VSYNC);
$window.setFramerateLimit(FRAME_LIMIT);
@ -39,6 +41,8 @@ namespace gui {
if($mind_reading) render_mind_reading();
$overlay_ui.render($window);
if($hand_anim.playing) render_hands();
}
lel::Cell MainUI::overlay_cell(const std::string& name) {
@ -133,4 +137,15 @@ namespace gui {
void MainUI::mouse(int x, int y, guecs::Modifiers mods) {
$overlay_ui.$gui.mouse(x, y, mods);
}
void MainUI::play_hands() {
$hand_anim.play();
}
void MainUI::render_hands() {
if(animation::apply($hand_anim, *$hand.sprite)) {
$hand.sprite->setPosition({RAY_VIEW_X, RAY_VIEW_Y});
$window.draw(*$hand.sprite);
}
}
}

View file

@ -6,6 +6,7 @@
#include "gui/overlay_ui.hpp"
#include "gui/debug_ui.hpp"
#include "raycaster.hpp"
#include "animation.hpp"
#include <optional>
namespace gui {
@ -19,6 +20,8 @@ namespace gui {
sf::RenderWindow& $window;
OverlayUI $overlay_ui;
std::shared_ptr<Raycaster> $rayview;
textures::SpriteTexture $hand;
components::Animation $hand_anim;
MainUI(sf::RenderWindow& window);
@ -41,5 +44,7 @@ namespace gui {
void dead_entity(DinkyECS::Entity entity);
void toggle_mind_reading();
void render_mind_reading();
void play_hands();
void render_hands();
};
}

View file

@ -28,6 +28,7 @@ function Build-Images {
# Build-Images -Source "Textures" -pixel_count 12
# Build-Images -Source "Sprites" -pixel_count 6
# Build-Images -Source "Items" -pixel_count 2
Build-Images -Source "Animations" -pixel_count 6
# Build-Images -Source "Animations" -pixel_count 6
Build-Images -Source "Hands" -pixel_count 2
cp -recurse -force C:\Users\lcthw\Pictures\Games\Renders\Raycaster\UI assets\ui

View file

@ -30,11 +30,6 @@ TEST_CASE("animation easing tests", "[animation]") {
anim.easing = ease::IN_OUT_BACK;
res = anim.twitching();
REQUIRE(!std::isnan(res));
anim.easing = ease::FUCKFACE;
bool throws = false;
try { anim.twitching(); } catch(...) { throws = true; }
REQUIRE(throws);
}