diff --git a/animation.cpp b/animation.cpp index 32e7177..8cc6dd4 100644 --- a/animation.cpp +++ b/animation.cpp @@ -1,4 +1,5 @@ #include "animation.hpp" +#include "rand.hpp" namespace components { void Animation::play() { @@ -10,7 +11,7 @@ namespace components { } float Animation::twitching() { - float tick = ease::sine(float(frames) / subframe * ease_rate); + float tick = ease::sine(float(frames) / (subframe + 0.0001) * ease_rate); switch(easing) { case ease::NONE: @@ -23,6 +24,10 @@ namespace components { return ease::sine(ease::out_bounce(tick)); case ease::IN_OUT_BACK: return ease::sine(ease::in_out_back(tick)); + case ease::RANDOM: + return Random::uniform_real(0.0001f, 1.0f); + case ease::NORM_DIST: + return Random::normal(0.5f, 0.1f); default: dbc::sentinel( fmt::format("Invalid easing {} given to animation", @@ -38,9 +43,36 @@ namespace components { float tick = twitching(); if(stationary) { - scale_out.x = std::lerp(scale_x, max_scale, tick); - scale_out.y = std::lerp(scale_y, max_scale, tick); - pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); + switch(motion) { + case ease::SHAKE: { + pos_out.x += std::lerp(scale_x, max_scale, tick); + } break; + case ease::BOUNCE: { + pos_out.y -= std::lerp(scale_y, max_scale, tick); + } break; + case ease::RUSH: { + scale_out.x = std::lerp(scale_x, max_scale, tick); + scale_out.y = std::lerp(scale_y, max_scale, tick); + pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); + } break; + case ease::SQUEEZE: { + scale_out.x *= std::lerp(scale_x, max_scale, tick); + + } break; + case ease::SQUASH: { + scale_out.y *= std::lerp(scale_y, max_scale, tick); + } break; + case ease::STRETCH: { + scale_out.x = std::lerp(scale_x, max_scale, tick); + fmt::println("scale_x: {} max_scale: {} tick: {} scale_out.x: {}", + scale_x, max_scale, tick, scale_out.x); + } break; + case ease::GROW: { + scale_out.y = std::lerp(scale_y, max_scale, tick); + } break; + default: + dbc::sentinel("Unknown animation.motion setting."); + } } else { scale_out.x = std::lerp(scale_out.x * scale_x, scale_out.x * max_scale, tick); scale_out.y = std::lerp(scale_out.y * scale_y, scale_out.y * max_scale, tick); @@ -86,7 +118,11 @@ namespace animation { sprite.setTextureRect(rect); sprite.setPosition(pos); - sprite.setScale(scale); + + // BUG: make this an option: apply_scale, apply_position and ranges for x y + if(anim.motion != ease::SHAKE && anim.motion != ease::BOUNCE && anim.motion != ease::RUSH) { + sprite.setScale(scale); + } return anim.playing; } diff --git a/assets/animations.json b/assets/animations.json index 439eae3..ddf78c8 100644 --- a/assets/animations.json +++ b/assets/animations.json @@ -2,6 +2,7 @@ "burning_animation": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -16,6 +17,7 @@ "male_hand": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -30,6 +32,7 @@ "female_hand": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -44,6 +47,7 @@ "lightning_animation": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -58,6 +62,7 @@ "ritual_crafting_area": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -72,6 +77,7 @@ "peasant_girl_rear_view": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.2, "scale_x": 0.5, "scale_y": 0.5, @@ -86,6 +92,7 @@ "gold_savior": { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.2, "scale_x": 1.1, "scale_y": 1.1, @@ -100,6 +107,7 @@ "armored_knight" : { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.2, "scale_x": 1.1, "scale_y": 1.1, @@ -114,6 +122,7 @@ "axe_ranger": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.1, "scale_y": 1.1, @@ -128,6 +137,7 @@ "rat_with_sword": { "_type": "Animation", "easing": 3, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, @@ -142,6 +152,7 @@ "hairy_spider": { "_type": "Animation", "easing": 2, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.9, "scale_y": 0.9, @@ -156,6 +167,7 @@ "test_boss": { "_type": "Animation", "easing": 1, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.4, "scale_y": 0.4, @@ -170,10 +182,11 @@ "rat_king_boss": { "_type": "Animation", "easing": 4, - "ease_rate": 0.9, + "motion": 0, + "ease_rate": 0.5, "scale_x": 0.6, "scale_y": 0.6, - "max_scale": 0.7, + "max_scale": 2.0, "simple": false, "frames": 2, "speed": 0.02, @@ -184,6 +197,7 @@ "torch_fixture": { "_type": "Animation", "easing": 0, + "motion": 0, "ease_rate": 0.5, "scale_x": 0.5, "scale_y": 0.5, @@ -198,6 +212,7 @@ "test_floor": { "_type": "Animation", "easing": 2, + "motion": 0, "ease_rate": 0.5, "scale_x": 1.0, "scale_y": 1.0, diff --git a/assets/boss2/boss_fight_scene_1_floor.png b/assets/boss2/boss_fight_scene_1_floor.png index 180007b..f29904a 100644 Binary files a/assets/boss2/boss_fight_scene_1_floor.png and b/assets/boss2/boss_fight_scene_1_floor.png differ diff --git a/assets/boss2/boss_fight_scene_1_wall.png b/assets/boss2/boss_fight_scene_1_wall.png index ddb95f2..73018c8 100644 Binary files a/assets/boss2/boss_fight_scene_1_wall.png and b/assets/boss2/boss_fight_scene_1_wall.png differ diff --git a/boss/fight.cpp b/boss/fight.cpp index 502fc18..38c0113 100644 --- a/boss/fight.cpp +++ b/boss/fight.cpp @@ -105,7 +105,7 @@ namespace boss { break; case ATTACK: { $ui.status(L"BOSS TURN"); - $ui.move_actor("boss", run % 10 < 5 ? "boss5" : "boss6"); + // $ui.move_actor("boss", run % 10 < 5 ? "boss5" : "boss6"); $ui.animate_actor("boss"); int attack_id = std::any_cast(data); boss::System::combat(attack_id); diff --git a/boss/ui.cpp b/boss/ui.cpp index bc4cad0..be0a9f7 100644 --- a/boss/ui.cpp +++ b/boss/ui.cpp @@ -1,8 +1,6 @@ #include "boss/ui.hpp" #include "scene.hpp" #include "constants.hpp" -#include -#include namespace boss { using namespace guecs; diff --git a/components.hpp b/components.hpp index 774d9ac..a7de9f5 100644 --- a/components.hpp +++ b/components.hpp @@ -122,6 +122,7 @@ namespace components { int frames = 10; float speed = 0.3f; ease::Style easing = ease::IN_OUT_BACK; + ease::Motion motion = ease::RUSH; float ease_rate = 0.5f; bool stationary = false; bool toggled = false; @@ -161,7 +162,7 @@ namespace components { ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); ENROLL_COMPONENT(Device, config, events); ENROLL_COMPONENT(Animation, scale_x, scale_y, max_scale, simple, frames, - speed, easing, ease_rate, stationary, toggled, looped); + speed, easing, motion, ease_rate, stationary, toggled, looped); ENROLL_COMPONENT(Sound, attack, death); ENROLL_COMPONENT(Collision, has); diff --git a/easings.hpp b/easings.hpp index 871d791..8971d81 100644 --- a/easings.hpp +++ b/easings.hpp @@ -9,7 +9,18 @@ namespace ease { OUT_CIRC=2, OUT_BOUNCE=3, IN_OUT_BACK=4, - FUCKFACE + RANDOM=5, + NORM_DIST=6 + }; + + enum Motion { + RUSH=0, + SHAKE=1, + BOUNCE=2, + SQUEEZE=3, + SQUASH=4, + STRETCH=5, + GROW=6 }; inline double sine(double x) { diff --git a/scene.cpp b/scene.cpp index fdd3c81..5143b11 100644 --- a/scene.cpp +++ b/scene.cpp @@ -3,7 +3,6 @@ #include const bool DEBUG=false; -const bool YOU_REMOVED_MID_CELL_IDIOT=false; namespace scene { Element config_scene_element(nlohmann::json& config, bool and_play, bool duped) { @@ -18,8 +17,6 @@ namespace scene { // BUG: need to make animation optional auto anim = animation::load(sprite_name); if(and_play) anim.play(); - anim.scale_x = scale_x; - anim.scale_y = scale_y; std::string cell = config["cell"]; std::string name = config["name"]; diff --git a/scripts/build_assets.ps1 b/scripts/build_assets.ps1 index efa9508..fb87c47 100644 --- a/scripts/build_assets.ps1 +++ b/scripts/build_assets.ps1 @@ -28,9 +28,9 @@ 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 24 +# Build-Images -Source "Animations" -pixel_count 24 # Build-Images -Source "Hands" -pixel_count 6 -# Build-Images -Source "Boss2" -pixel_count 4 +Build-Images -Source "Boss2" -pixel_count 4 # Build-Images -Source "Fixtures" -pixel_count 24