Boss fight looking better, but I need to get this bounce animation in the main game fights.
This commit is contained in:
parent
25d782df6d
commit
2d790c5986
8 changed files with 54 additions and 35 deletions
|
@ -44,7 +44,8 @@
|
||||||
"axe_ranger": "assets/axe_ranger-256.png",
|
"axe_ranger": "assets/axe_ranger-256.png",
|
||||||
"hairy_spider": "assets/hairy_spider-256.png",
|
"hairy_spider": "assets/hairy_spider-256.png",
|
||||||
"down_the_well": "assets/down_the_well.jpg",
|
"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": {
|
"enemy": {
|
||||||
"HEARING_DISTANCE": 5
|
"HEARING_DISTANCE": 5
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
{"_type": "EnemyConfig", "hearing_distance": 5},
|
{"_type": "EnemyConfig", "hearing_distance": 5},
|
||||||
{"_type": "Sprite", "name": "axe_ranger"},
|
{"_type": "Sprite", "name": "axe_ranger"},
|
||||||
{"_type": "Animation", "scale": 0.1, "simple": false, "frames": 10, "speed": 0.6},
|
{"_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": {
|
"EVIL_EYE": {
|
||||||
|
|
BIN
assets/rat_king_boss_fight_background.jpg
Normal file
BIN
assets/rat_king_boss_fight_background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 KiB |
BIN
assets/rat_king_boss_fight_sprite.png
Normal file
BIN
assets/rat_king_boss_fight_sprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 466 KiB |
|
@ -1,5 +1,6 @@
|
||||||
#include "boss_fight_ui.hpp"
|
#include "boss_fight_ui.hpp"
|
||||||
#include "easings.hpp"
|
#include "easings.hpp"
|
||||||
|
#include "sound.hpp"
|
||||||
|
|
||||||
namespace gui {
|
namespace gui {
|
||||||
BossFightUI::BossFightUI(GameLevel level)
|
BossFightUI::BossFightUI(GameLevel level)
|
||||||
|
@ -19,10 +20,15 @@ namespace gui {
|
||||||
"[overlay_9|overlay_10|overlay_12]"
|
"[overlay_9|overlay_10|overlay_12]"
|
||||||
"[overlay_13|overlay_14|overlay_16]");
|
"[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");
|
$boss_image = textures::get("boss_fight");
|
||||||
auto bounds = $boss_image.sprite->getLocalBounds();
|
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->setOrigin({bounds.size.x / 2, bounds.size.y / 2});
|
||||||
|
$boss_image.sprite->setPosition({300.0f + x_diff, bounds.size.y / 2});
|
||||||
}
|
}
|
||||||
|
|
||||||
void BossFightUI::init() {
|
void BossFightUI::init() {
|
||||||
|
@ -54,13 +60,21 @@ namespace gui {
|
||||||
|
|
||||||
void BossFightUI::bounce_boss(sf::RenderWindow& window) {
|
void BossFightUI::bounce_boss(sf::RenderWindow& window) {
|
||||||
auto time = $clock.getElapsedTime();
|
auto time = $clock.getElapsedTime();
|
||||||
float tick = ease::out_bounce(ease::sine(time.asSeconds()));
|
float tick = ease::in_out_back(ease::sine(time.asSeconds() * 10.0f));
|
||||||
float scale = std::lerp(1.0, 1.15, tick);
|
float scale = std::lerp(0.8, 1.1, tick);
|
||||||
$boss_image.sprite->setScale({scale, scale});
|
$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);
|
window.draw(*$boss_image.sprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BossFightUI::render(sf::RenderWindow& window) {
|
void BossFightUI::render(sf::RenderWindow& window) {
|
||||||
|
window.draw(*$boss_background.sprite);
|
||||||
|
|
||||||
if($boss_hit) {
|
if($boss_hit) {
|
||||||
bounce_boss(window);
|
bounce_boss(window);
|
||||||
} else {
|
} else {
|
||||||
|
@ -82,6 +96,8 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
if($overlay.mouse(x, y)) {
|
if($overlay.mouse(x, y)) {
|
||||||
|
sound::play("Sword_Hit_1");
|
||||||
|
$boss_image.sprite->setColor({255,225,225});
|
||||||
$boss_hit = !$boss_hit;
|
$boss_hit = !$boss_hit;
|
||||||
$boss_hp--;
|
$boss_hp--;
|
||||||
}
|
}
|
||||||
|
@ -90,6 +106,7 @@ namespace gui {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BossFightUI::update_level(GameLevel &level) {
|
void BossFightUI::update_level(GameLevel &level) {
|
||||||
|
$boss_image.sprite->setColor({255,255,255});
|
||||||
$level = level;
|
$level = level;
|
||||||
$boss_hp = 10 * $level.index + 1; // make him stronger
|
$boss_hp = 10 * $level.index + 1; // make him stronger
|
||||||
$boss_hit = false;
|
$boss_hit = false;
|
||||||
|
|
|
@ -25,6 +25,7 @@ namespace gui {
|
||||||
guecs::UI $status;
|
guecs::UI $status;
|
||||||
guecs::UI $overlay;
|
guecs::UI $overlay;
|
||||||
textures::SpriteTexture $boss_image;
|
textures::SpriteTexture $boss_image;
|
||||||
|
textures::SpriteTexture $boss_background;
|
||||||
|
|
||||||
BossFightUI(GameLevel level);
|
BossFightUI(GameLevel level);
|
||||||
|
|
||||||
|
|
58
sound.cpp
58
sound.cpp
|
@ -12,6 +12,20 @@ namespace sound {
|
||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
namespace fs = std::filesystem;
|
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() {
|
void init() {
|
||||||
if(!initialized) {
|
if(!initialized) {
|
||||||
Config assets("assets/config.json");
|
Config assets("assets/config.json");
|
||||||
|
@ -38,44 +52,28 @@ namespace sound {
|
||||||
}
|
}
|
||||||
|
|
||||||
void play(const std::string name, bool loop) {
|
void play(const std::string name, bool loop) {
|
||||||
dbc::check(initialized, "You need to call sound::init() first");
|
|
||||||
if(muted) return;
|
if(muted) return;
|
||||||
|
auto& pair = get_sound_pair(name);
|
||||||
if(SMGR.sounds.contains(name)) {
|
pair.sound->setLooping(loop);
|
||||||
// get the sound from the sound map
|
// play it
|
||||||
auto pair = SMGR.sounds.at(name);
|
pair.sound->play();
|
||||||
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) {
|
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)) {
|
bool playing(const std::string name) {
|
||||||
// get the sound from the sound map
|
auto& pair = get_sound_pair(name);
|
||||||
auto pair = SMGR.sounds.at(name);
|
auto status = pair.sound->getStatus();
|
||||||
pair.sound->stop();
|
return status == sf::SoundSource::Status::Playing;
|
||||||
} else {
|
|
||||||
dbc::log(fmt::format("Attempted to stop {} sound but not available.",
|
|
||||||
name));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void play_at(const std::string name, float x, float y, float z) {
|
void play_at(const std::string name, float x, float y, float z) {
|
||||||
dbc::check(initialized, "You need to call sound::init() first");
|
auto& pair = get_sound_pair(name);
|
||||||
if(SMGR.sounds.contains(name)) {
|
pair.sound->setPosition({x, y, z});
|
||||||
auto pair = SMGR.sounds.at(name);
|
pair.sound->play();
|
||||||
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) {
|
void mute(bool setting) {
|
||||||
|
|
|
@ -21,4 +21,6 @@ namespace sound {
|
||||||
void play_at(const std::string name, float x, float y, float z);
|
void play_at(const std::string name, float x, float y, float z);
|
||||||
void stop(const std::string name);
|
void stop(const std::string name);
|
||||||
void mute(bool setting);
|
void mute(bool setting);
|
||||||
|
bool playing(const std::string name);
|
||||||
|
SoundPair& get_sound_pair(const std::string& name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue