diff --git a/assets/bosses.json b/assets/bosses.json index 5d9a47d..c8bf044 100644 --- a/assets/bosses.json +++ b/assets/bosses.json @@ -3,8 +3,8 @@ "components": [ {"_type": "BossFight", "background": "boss_fight_background", "weapon_sound": "Sword_Hit_2"}, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, - {"_type": "Animation", "easing": 3, "ease_rate": 0.2, "scale": 0.2, "simple": false, "frames": 2, "speed": 0.02, "scale": 0.2}, - {"_type": "Sprite", "name": "rat_king_boss", "width": 720, "height": 720, "scale": 0.8}, + {"_type": "Animation", "easing": 3, "ease_rate": 0.2, "simple": false, "frames": 2, "speed": 0.02, "scale": 0.2}, + {"_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"} ] }, @@ -15,7 +15,15 @@ "weapon_sound": "Sword_Hit_2" }, {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, - {"_type": "Animation", "easing": 0, "ease_rate": 0.1, "scale": 0.2, "simple": true, "frames": 2, "speed": 0.02, "scale": 0.2}, + {"_type": "Animation", + "easing": 1, + "ease_rate": 0.1, + "simple": false, + "frames": 2, + "speed": 0.02, + "scale": 0.1, + "stationary": true + }, {"_type": "Sprite", "name": "devils_fingers_sprite", "width": 720, diff --git a/assets/devils_fingers_sprite.png b/assets/devils_fingers_sprite.png index 3b0526e..d99be03 100644 Binary files a/assets/devils_fingers_sprite.png and b/assets/devils_fingers_sprite.png differ diff --git a/assets/enemies.json b/assets/enemies.json index 5ab6150..ca46990 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -20,7 +20,7 @@ {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 1, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "hearing_distance": 5}, - {"_type": "Animation", "easing": 1, "ease_rate": 0.2, "scale": 0.1, "simple": true, "frames": 10, "speed": 0.3}, + {"_type": "Animation", "easing": 1, "ease_rate": 0.2, "scale": 0.1, "simple": true, "frames": 10, "speed": 0.3, "stationary": false}, {"_type": "Sprite", "name": "armored_knight", "width": 256, "height": 256, "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Humanoid_Death_1"} ] @@ -35,7 +35,7 @@ {"_type": "Motion", "dx": 0, "dy": 0, "random": true}, {"_type": "EnemyConfig", "hearing_distance": 5}, {"_type": "Sprite", "name": "axe_ranger", "width": 256, "height": 256, "scale": 1.0}, - {"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": false, "frames": 2, "speed": 0.6}, + {"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": false, "frames": 2, "speed": 0.6, "stationary": false}, {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Ranger_1"} ] }, @@ -48,7 +48,7 @@ {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "hearing_distance": 10}, - {"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0}, + {"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0, "stationary": false}, {"_type": "Sprite", "name": "rat_with_sword", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "Small_Rat", "death": "Creature_Death_1"} ] @@ -62,7 +62,7 @@ {"_type": "Combat", "hp": 20, "max_hp": 20, "damage": 20, "dead": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "EnemyConfig", "hearing_distance": 10}, - {"_type": "Animation", "easing": 2, "ease_rate": 0.5, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0}, + {"_type": "Animation", "easing": 2, "ease_rate": 0.5, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0, "stationary": false}, {"_type": "Sprite", "name": "hairy_spider", "width": 256, "height": 256, "scale": 1.0}, {"_type": "Sound", "attack": "Spider_1", "death": "Spider_2"} ] diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index d1c72d2..a9220f3 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -42,8 +42,10 @@ namespace gui { auto bounds = $boss_image.sprite->getLocalBounds(); auto bg_bounds = $boss_background.sprite->getLocalBounds(); float x_diff = bg_bounds.size.x / 2; + + $boss_pos = {float(BOSS_VIEW_X) + x_diff, bounds.size.y / 2}; $boss_image.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2}); - $boss_image.sprite->setPosition({float(BOSS_VIEW_X) + x_diff, bounds.size.y / 2}); + $boss_image.sprite->setPosition($boss_pos); } void BossFightUI::configure_background() { @@ -88,9 +90,13 @@ namespace gui { void BossFightUI::bounce_boss(sf::RenderWindow& window) { sf::IntRect frame_rect{{0,0},{$sprite_config.width,$sprite_config.height}}; sf::Vector2f scale{$sprite_config.scale, $sprite_config.scale}; - $animation.step(scale, frame_rect); + sf::Vector2f pos{$boss_pos.x, $boss_pos.y}; + + $animation.step(scale, pos, frame_rect); $boss_image.sprite->setScale(scale); + if($animation.stationary) $boss_image.sprite->setPosition(pos); + if(!sound::playing($sounds.attack) && $animation.current == 1) { sound::play($sounds.attack); } diff --git a/boss_fight_ui.hpp b/boss_fight_ui.hpp index 389f1af..ef09526 100644 --- a/boss_fight_ui.hpp +++ b/boss_fight_ui.hpp @@ -19,6 +19,7 @@ namespace gui { public: sf::Clock $clock; bool $boss_hit = false; + sf::Vector2f $boss_pos; components::Combat $combat; components::Sprite $sprite_config; components::Sound $sounds; diff --git a/components.cpp b/components.cpp index 12ba26a..d66fbbe 100644 --- a/components.cpp +++ b/components.cpp @@ -54,12 +54,16 @@ namespace components { } } - void Animation::step(sf::Vector2f& scale_out, sf::IntRect& rect_out) { + void Animation::step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out) { if(playing && current < frames) { float tick = twitching(); scale_out.x = std::lerp(scale_out.x, scale_out.x + scale, tick); scale_out.y = std::lerp(scale_out.y, scale_out.y + scale, tick); + if(stationary) { + pos_out.y = pos_out.y - (pos_out.y * scale_out.y - pos_out.y); + } + if(!simple) { rect_out.position.x += current * texture_width; } diff --git a/components.hpp b/components.hpp index ad769d0..f31f62d 100644 --- a/components.hpp +++ b/components.hpp @@ -112,16 +112,17 @@ namespace components { bool simple = true; int frames = 10; float speed = 0.3f; + ease::Style easing = ease::IN_OUT_BACK; + float ease_rate = 0.5f; + bool stationary = false; int current = 0; bool playing = false; float subframe = 0; - ease::Style easing = ease::IN_OUT_BACK; - float ease_rate = 0.5f; int texture_width = TEXTURE_WIDTH; void play(); float twitching(); - void step(sf::Vector2f& scale_out, sf::IntRect& rect_out); + void step(sf::Vector2f& scale_out, sf::Vector2f& pos_out, sf::IntRect& rect_out); }; template struct NameOf; @@ -138,7 +139,8 @@ namespace components { ENROLL_COMPONENT(Motion, dx, dy, random); ENROLL_COMPONENT(Combat, hp, max_hp, damage, dead); ENROLL_COMPONENT(Device, config, events); - ENROLL_COMPONENT(Animation, scale, simple, frames, speed, easing, ease_rate); + ENROLL_COMPONENT(Animation, scale, simple, frames, + speed, easing, ease_rate, stationary); ENROLL_COMPONENT(Sound, attack, death); using ReflFuncSignature = std::function; diff --git a/raycaster.cpp b/raycaster.cpp index bd59935..3c4828e 100644 --- a/raycaster.cpp +++ b/raycaster.cpp @@ -158,7 +158,7 @@ void Raycaster::sprite_casting(sf::RenderTarget &target) { if($level.world->has(rec.second)) { auto& animation = $level.world->get(rec.second); - if(animation.playing) animation.step(scale, in_texture); + if(animation.playing) animation.step(scale, position, in_texture); } sf_sprite->setOrigin(origin);