diff --git a/assets/config.json b/assets/config.json index 8580e88..1774494 100644 --- a/assets/config.json +++ b/assets/config.json @@ -44,7 +44,8 @@ "axe_ranger": "assets/axe_ranger-256.png", "hairy_spider": "assets/hairy_spider-256.png", "down_the_well": "assets/down_the_well.jpg", - "boss_fight": "assets/rat-king-boss-fight-test-small.jpg" + "boss_fight_background": "assets/rat_king_boss_fight_background.jpg", + "boss_fight": "assets/rat_king_boss_fight_sprite.png" }, "enemy": { "HEARING_DISTANCE": 5 diff --git a/assets/enemies.json b/assets/enemies.json index 5befe3d..02ff373 100644 --- a/assets/enemies.json +++ b/assets/enemies.json @@ -36,7 +36,7 @@ {"_type": "EnemyConfig", "hearing_distance": 5}, {"_type": "Sprite", "name": "axe_ranger"}, {"_type": "Animation", "scale": 0.1, "simple": false, "frames": 10, "speed": 0.6}, - {"_type": "Sound", "attack": "Sword_Hit_1", "death": "Ranger_1"} + {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Ranger_1"} ] }, "EVIL_EYE": { diff --git a/assets/rat_king_boss_fight_background.jpg b/assets/rat_king_boss_fight_background.jpg new file mode 100644 index 0000000..68d8bd6 Binary files /dev/null and b/assets/rat_king_boss_fight_background.jpg differ diff --git a/assets/rat_king_boss_fight_sprite.png b/assets/rat_king_boss_fight_sprite.png new file mode 100644 index 0000000..4995f22 Binary files /dev/null and b/assets/rat_king_boss_fight_sprite.png differ diff --git a/boss_fight_ui.cpp b/boss_fight_ui.cpp index 1b746f7..11e218c 100644 --- a/boss_fight_ui.cpp +++ b/boss_fight_ui.cpp @@ -1,5 +1,6 @@ #include "boss_fight_ui.hpp" #include "easings.hpp" +#include "sound.hpp" namespace gui { BossFightUI::BossFightUI(GameLevel level) @@ -19,10 +20,15 @@ namespace gui { "[overlay_9|overlay_10|overlay_12]" "[overlay_13|overlay_14|overlay_16]"); + $boss_background = textures::get("boss_fight_background"); + auto bg_bounds = $boss_background.sprite->getLocalBounds(); + $boss_background.sprite->setPosition({300, 0}); + $boss_image = textures::get("boss_fight"); auto bounds = $boss_image.sprite->getLocalBounds(); - $boss_image.sprite->setPosition({300 + bounds.size.x / 2, bounds.size.y / 2}); + float x_diff = bg_bounds.size.x / 2; $boss_image.sprite->setOrigin({bounds.size.x / 2, bounds.size.y / 2}); + $boss_image.sprite->setPosition({300.0f + x_diff, bounds.size.y / 2}); } void BossFightUI::init() { @@ -54,13 +60,21 @@ namespace gui { void BossFightUI::bounce_boss(sf::RenderWindow& window) { auto time = $clock.getElapsedTime(); - float tick = ease::out_bounce(ease::sine(time.asSeconds())); - float scale = std::lerp(1.0, 1.15, tick); + float tick = ease::in_out_back(ease::sine(time.asSeconds() * 10.0f)); + float scale = std::lerp(0.8, 1.1, tick); $boss_image.sprite->setScale({scale, scale}); + + if(scale > 1.0) { + if(!sound::playing("Sword_Hit_2")) sound::play("Sword_Hit_2"); + $boss_image.sprite->setColor({255,255,255}); + } + window.draw(*$boss_image.sprite); } void BossFightUI::render(sf::RenderWindow& window) { + window.draw(*$boss_background.sprite); + if($boss_hit) { bounce_boss(window); } else { @@ -82,6 +96,8 @@ namespace gui { } if($overlay.mouse(x, y)) { + sound::play("Sword_Hit_1"); + $boss_image.sprite->setColor({255,225,225}); $boss_hit = !$boss_hit; $boss_hp--; } @@ -90,6 +106,7 @@ namespace gui { } void BossFightUI::update_level(GameLevel &level) { + $boss_image.sprite->setColor({255,255,255}); $level = level; $boss_hp = 10 * $level.index + 1; // make him stronger $boss_hit = false; diff --git a/boss_fight_ui.hpp b/boss_fight_ui.hpp index ed28550..52190c8 100644 --- a/boss_fight_ui.hpp +++ b/boss_fight_ui.hpp @@ -25,6 +25,7 @@ namespace gui { guecs::UI $status; guecs::UI $overlay; textures::SpriteTexture $boss_image; + textures::SpriteTexture $boss_background; BossFightUI(GameLevel level); diff --git a/sound.cpp b/sound.cpp index 4afd135..4422abb 100644 --- a/sound.cpp +++ b/sound.cpp @@ -12,6 +12,20 @@ namespace sound { using std::make_shared; namespace fs = std::filesystem; + SoundPair& get_sound_pair(const std::string& name) { + dbc::check(initialized, "You need to call sound::init() first"); + + if(SMGR.sounds.contains(name)) { + // get the sound from the sound map + return SMGR.sounds.at(name); + } else { + dbc::log(fmt::format("Attempted to stop {} sound but not available.", + name)); + return SMGR.sounds.at("blank"); + } + } + + void init() { if(!initialized) { Config assets("assets/config.json"); @@ -38,44 +52,28 @@ namespace sound { } void play(const std::string name, bool loop) { - dbc::check(initialized, "You need to call sound::init() first"); if(muted) return; - - if(SMGR.sounds.contains(name)) { - // get the sound from the sound map - auto pair = SMGR.sounds.at(name); - pair.sound->setLooping(loop); - // play it - pair.sound->play(); - } else { - dbc::log(fmt::format("Attempted to play {} sound but not available.", - name)); - } + auto& pair = get_sound_pair(name); + pair.sound->setLooping(loop); + // play it + pair.sound->play(); } void stop(const std::string name) { - dbc::check(initialized, "You need to call sound::init() first"); + auto& pair = get_sound_pair(name); + pair.sound->stop(); + } - if(SMGR.sounds.contains(name)) { - // get the sound from the sound map - auto pair = SMGR.sounds.at(name); - pair.sound->stop(); - } else { - dbc::log(fmt::format("Attempted to stop {} sound but not available.", - name)); - } + bool playing(const std::string name) { + auto& pair = get_sound_pair(name); + auto status = pair.sound->getStatus(); + return status == sf::SoundSource::Status::Playing; } void play_at(const std::string name, float x, float y, float z) { - dbc::check(initialized, "You need to call sound::init() first"); - if(SMGR.sounds.contains(name)) { - auto pair = SMGR.sounds.at(name); - pair.sound->setPosition({x, y, z}); - pair.sound->play(); - } else { - dbc::log(fmt::format("Attempted to play_at {} sound but not available.", - name)); - } + auto& pair = get_sound_pair(name); + pair.sound->setPosition({x, y, z}); + pair.sound->play(); } void mute(bool setting) { diff --git a/sound.hpp b/sound.hpp index 9a8b4eb..bf6a058 100644 --- a/sound.hpp +++ b/sound.hpp @@ -21,4 +21,6 @@ namespace sound { void play_at(const std::string name, float x, float y, float z); void stop(const std::string name); void mute(bool setting); + bool playing(const std::string name); + SoundPair& get_sound_pair(const std::string& name); }