diff --git a/animation.cpp b/animation.cpp index a2bd3c2..f0dd2c4 100644 --- a/animation.cpp +++ b/animation.cpp @@ -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(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"]; diff --git a/assets/animations.json b/assets/animations.json index 3cd40a6..71bafe9 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -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, diff --git a/assets/config.json b/assets/config.json index 0f215bd..81f11b0 100644 --- a/assets/config.json +++ b/assets/config.json @@ -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": { diff --git a/assets/hands/hands.png b/assets/hands/hands.png new file mode 100644 index 0000000..cb74894 Binary files /dev/null and b/assets/hands/hands.png differ diff --git a/gui/fsm.cpp b/gui/fsm.cpp index 9c09dd2..35dae80 100644 --- a/gui/fsm.cpp +++ b/gui/fsm.cpp @@ -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); diff --git a/gui/main_ui.cpp b/gui/main_ui.cpp index 018df0f..36404ea 100644 --- a/gui/main_ui.cpp +++ b/gui/main_ui.cpp @@ -11,7 +11,9 @@ namespace gui { MainUI::MainUI(sf::RenderWindow& window) : $window(window), - $rayview(std::make_shared(RAY_VIEW_WIDTH, RAY_VIEW_HEIGHT)) + $rayview(std::make_shared(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); + } + } } diff --git a/gui/main_ui.hpp b/gui/main_ui.hpp index 354c2c7..48e9804 100644 --- a/gui/main_ui.hpp +++ b/gui/main_ui.hpp @@ -6,6 +6,7 @@ #include "gui/overlay_ui.hpp" #include "gui/debug_ui.hpp" #include "raycaster.hpp" +#include "animation.hpp" #include namespace gui { @@ -19,6 +20,8 @@ namespace gui { sf::RenderWindow& $window; OverlayUI $overlay_ui; std::shared_ptr $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(); }; } diff --git a/scripts/build_assets.ps1 b/scripts/build_assets.ps1 index a7f69c3..fa4ec86 100644 --- a/scripts/build_assets.ps1 +++ b/scripts/build_assets.ps1 @@ -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 diff --git a/tests/animation.cpp b/tests/animation.cpp index 5a0b586..c8f208f 100644 --- a/tests/animation.cpp +++ b/tests/animation.cpp @@ -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); }