Boss fight looking better, but I need to get this bounce animation in the main game fights.

master
Zed A. Shaw 1 week ago
parent 25d782df6d
commit 2d790c5986
  1. 3
      assets/config.json
  2. 2
      assets/enemies.json
  3. BIN
      assets/rat_king_boss_fight_background.jpg
  4. BIN
      assets/rat_king_boss_fight_sprite.png
  5. 23
      boss_fight_ui.cpp
  6. 1
      boss_fight_ui.hpp
  7. 46
      sound.cpp
  8. 2
      sound.hpp

@ -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

@ -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": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 152 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 466 KiB

@ -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;

@ -25,6 +25,7 @@ namespace gui {
guecs::UI $status;
guecs::UI $overlay;
textures::SpriteTexture $boss_image;
textures::SpriteTexture $boss_background;
BossFightUI(GameLevel level);

@ -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);
auto& pair = get_sound_pair(name);
pair.sound->setLooping(loop);
// play it
pair.sound->play();
} else {
dbc::log(fmt::format("Attempted to play {} sound but not available.",
name));
}
}
void stop(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
auto pair = SMGR.sounds.at(name);
auto& pair = get_sound_pair(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);
auto& pair = get_sound_pair(name);
pair.sound->setPosition({x, y, z});
pair.sound->play();
} else {
dbc::log(fmt::format("Attempted to play_at {} sound but not available.",
name));
}
}
void mute(bool setting) {

@ -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);
}

Loading…
Cancel
Save