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