Bosses and other enemies now have a 2 frame animation, the first boss the Rat King now screams at you and attacks.

master
Zed A. Shaw 1 week ago
parent b3b8cbbeee
commit 43835da88f
  1. 9
      assets/config.json
  2. 11
      assets/enemies.json
  3. BIN
      assets/rat_king_2_frame_animation.png
  4. BIN
      assets/sounds/Creature_Sounds-Creature_Death_1.ogg
  5. BIN
      assets/sounds/Creature_Sounds-Evil_Eye_Sound_1.ogg
  6. BIN
      assets/sounds/Creature_Sounds-Evil_Eye_Sound_2.ogg
  7. BIN
      assets/sounds/Creature_Sounds-Giant_Voice_1.ogg
  8. BIN
      assets/sounds/Creature_Sounds-Humanoid_Death_1.ogg
  9. BIN
      assets/sounds/Creature_Sounds-Marmot_Scream_1.ogg
  10. BIN
      assets/sounds/Creature_Sounds-Medium_Rat.ogg
  11. BIN
      assets/sounds/Creature_Sounds-Ranger_1.ogg
  12. BIN
      assets/sounds/Creature_Sounds-Small_Rat.ogg
  13. BIN
      assets/sounds/Creature_Sounds-Spider_1-001.ogg
  14. BIN
      assets/sounds/Creature_Sounds-Spider_1.ogg
  15. BIN
      assets/sounds/Creature_Sounds-Spider_2.ogg
  16. BIN
      assets/sounds/Creature_Sounds-Sword_Hit_1.ogg
  17. BIN
      assets/sounds/Creature_Sounds-Sword_Hit_2.ogg
  18. BIN
      assets/sounds/Creature_Sounds-Walk.ogg
  19. 30
      boss_fight_ui.cpp
  20. 2
      boss_fight_ui.hpp
  21. 3
      components.cpp
  22. 1
      components.hpp
  23. 1
      gui_fsm.cpp
  24. 2
      main.cpp

@ -7,13 +7,14 @@
"Medium_Rat": "assets/sounds/Creature_Sounds-Medium_Rat.ogg", "Medium_Rat": "assets/sounds/Creature_Sounds-Medium_Rat.ogg",
"Ranger_1": "assets/sounds/Creature_Sounds-Ranger_1.ogg", "Ranger_1": "assets/sounds/Creature_Sounds-Ranger_1.ogg",
"Small_Rat": "assets/sounds/Creature_Sounds-Small_Rat.ogg", "Small_Rat": "assets/sounds/Creature_Sounds-Small_Rat.ogg",
"Spider_1": "assets/sounds/Creature_Sounds-Spider_1-001.ogg", "Spider_1": "assets/sounds/Creature_Sounds-Spider_1.ogg",
"Spider_2": "assets/sounds/Creature_Sounds-Spider_1-002.ogg", "Spider_2": "assets/sounds/Creature_Sounds-Spider_2.ogg",
"Sword_Hit_1": "assets/sounds/Creature_Sounds-Sword_Hit_1.ogg", "Sword_Hit_1": "assets/sounds/Creature_Sounds-Sword_Hit_1.ogg",
"Sword_Hit_2": "assets/sounds/Creature_Sounds-Sword_Hit_2.ogg", "Sword_Hit_2": "assets/sounds/Creature_Sounds-Sword_Hit_2.ogg",
"walk": "assets/sounds/Creature_Sounds-Walk.ogg", "walk": "assets/sounds/Creature_Sounds-Walk.ogg",
"Creature_Death_1": "assets/sounds/Creature_Sounds-Creature_Death_1.ogg", "Creature_Death_1": "assets/sounds/Creature_Sounds-Creature_Death_1.ogg",
"Humanoid_Death_1": "assets/sounds/Creature_Sounds-Humanoid_Death_1.ogg", "Humanoid_Death_1": "assets/sounds/Creature_Sounds-Humanoid_Death_1.ogg",
"Marmot_Scream_1": "assets/sounds/Creature_Sounds-Marmot_Scream_1.ogg",
"blank": "assets/sounds/blank.ogg", "blank": "assets/sounds/blank.ogg",
"pickup": "assets/sounds/pickup.ogg", "pickup": "assets/sounds/pickup.ogg",
"ambient_1": "assets/sounds/ambient_1.ogg" "ambient_1": "assets/sounds/ambient_1.ogg"
@ -23,6 +24,7 @@
"sword": "assets/cinqueda_1-512.png", "sword": "assets/cinqueda_1-512.png",
"rat_with_sword": "assets/rat_with_sword-256.png", "rat_with_sword": "assets/rat_with_sword-256.png",
"rat_king": "assets/rat_king-256.png", "rat_king": "assets/rat_king-256.png",
"rat_king_boss": "assets/rat_king_2_frame_animation.png",
"barrel_small": "assets/wood_barrel_small-256.png", "barrel_small": "assets/wood_barrel_small-256.png",
"hanging_brazier": "assets/hanging_brazier-256.png", "hanging_brazier": "assets/hanging_brazier-256.png",
"torch_pillar": "assets/torch_pillar-256.png", "torch_pillar": "assets/torch_pillar-256.png",
@ -44,8 +46,7 @@
"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_background": "assets/rat_king_boss_fight_background.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

@ -35,7 +35,7 @@
{"_type": "Motion", "dx": 0, "dy": 0, "random": true}, {"_type": "Motion", "dx": 0, "dy": 0, "random": true},
{"_type": "EnemyConfig", "hearing_distance": 5}, {"_type": "EnemyConfig", "hearing_distance": 5},
{"_type": "Sprite", "name": "axe_ranger"}, {"_type": "Sprite", "name": "axe_ranger"},
{"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": false, "frames": 10, "speed": 0.6}, {"_type": "Animation", "easing": 3, "ease_rate": 0.5, "scale": 0.1, "simple": false, "frames": 2, "speed": 0.6},
{"_type": "Sound", "attack": "Sword_Hit_2", "death": "Ranger_1"} {"_type": "Sound", "attack": "Sword_Hit_2", "death": "Ranger_1"}
] ]
}, },
@ -49,7 +49,7 @@
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
{"_type": "EnemyConfig", "hearing_distance": 5}, {"_type": "EnemyConfig", "hearing_distance": 5},
{"_type": "Sprite", "name": "evil_eye"}, {"_type": "Sprite", "name": "evil_eye"},
{"_type": "Animation", "easing": 3, "ease_rate": 0.1, "scale": 0.1, "simple": false, "frames": 10, "speed": 0.3}, {"_type": "Animation", "easing": 3, "ease_rate": 0.1, "scale": 0.1, "simple": false, "frames": 2, "speed": 0.3},
{"_type": "Sound", "attack": "Evil_Eye_Sound_2", "death": "Evil_Eye_Sound_1"} {"_type": "Sound", "attack": "Evil_Eye_Sound_2", "death": "Evil_Eye_Sound_1"}
] ]
}, },
@ -68,6 +68,7 @@
] ]
}, },
"RAT_KING": { "RAT_KING": {
"placement": "fixed",
"components": [ "components": [
{"_type": "Tile", "display": "\u08ac", {"_type": "Tile", "display": "\u08ac",
"foreground": [205, 164, 100], "foreground": [205, 164, 100],
@ -76,9 +77,9 @@
{"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 50, "dead": false}, {"_type": "Combat", "hp": 50, "max_hp": 50, "damage": 50, "dead": false},
{"_type": "Motion", "dx": 0, "dy": 0, "random": false}, {"_type": "Motion", "dx": 0, "dy": 0, "random": false},
{"_type": "EnemyConfig", "hearing_distance": 3}, {"_type": "EnemyConfig", "hearing_distance": 3},
{"_type": "Animation", "easing": 2, "ease_rate": 0.2, "scale": 0.1, "simple": true, "frames": 10, "speed": 1.0}, {"_type": "Animation", "easing": 2, "ease_rate": 0.2, "scale": 0.2, "simple": false, "frames": 2, "speed": 0.02},
{"_type": "Sprite", "name": "rat_king"}, {"_type": "Sprite", "name": "rat_king_boss"},
{"_type": "Sound", "attack": "Sword_Hit_2", "death": "Creature_Death_1"} {"_type": "Sound", "attack": "Marmot_Scream_1", "death": "Creature_Death_1"}
] ]
}, },
"SPIDER_GIANT_HAIRY": { "SPIDER_GIANT_HAIRY": {

Binary file not shown.

After

Width:  |  Height:  |  Size: 1011 KiB

@ -24,7 +24,10 @@ namespace gui {
auto bg_bounds = $boss_background.sprite->getLocalBounds(); auto bg_bounds = $boss_background.sprite->getLocalBounds();
$boss_background.sprite->setPosition({300, 0}); $boss_background.sprite->setPosition({300, 0});
$boss_image = textures::get("boss_fight"); $boss_image = textures::get("rat_king_boss");
sf::IntRect frame_rect{{0,0},{720,720}};
$boss_image.sprite->setTextureRect(frame_rect);
$boss_image.sprite->setScale($scale);
auto bounds = $boss_image.sprite->getLocalBounds(); auto bounds = $boss_image.sprite->getLocalBounds();
float x_diff = bg_bounds.size.x / 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});
@ -34,6 +37,8 @@ namespace gui {
void BossFightUI::init() { void BossFightUI::init() {
auto& config = $level.world->get_the<components::GameConfig>(); auto& config = $level.world->get_the<components::GameConfig>();
$sounds = components::get<components::Sound>(config.enemies["RAT_KING"]); $sounds = components::get<components::Sound>(config.enemies["RAT_KING"]);
$animation = components::get<components::Animation>(config.enemies["RAT_KING"]);
$animation.texture_width = 720;
$status.world().set_the<Background>({$status.$parser}); $status.world().set_the<Background>({$status.$parser});
@ -62,16 +67,20 @@ namespace gui {
} }
void BossFightUI::bounce_boss(sf::RenderWindow& window) { void BossFightUI::bounce_boss(sf::RenderWindow& window) {
auto time = $clock.getElapsedTime(); sf::IntRect frame_rect{{0,0},{720,720}};
float tick = ease::in_out_back(ease::sine(time.asSeconds() * 10.0f)); auto scale = $scale;
float scale = std::lerp(0.8, 1.1, tick); $animation.step(scale, frame_rect);
$boss_image.sprite->setScale({scale, scale}); $boss_image.sprite->setScale(scale);
if(scale > 1.0) { if(!sound::playing($sounds.attack) && $animation.current == 1) {
if(!sound::playing($sounds.attack)) sound::play($sounds.attack); sound::play($sounds.attack);
$boss_image.sprite->setColor({255,255,255}); }
if(!sound::playing("Sword_Hit_2") && $animation.subframe > 1.2 && $animation.subframe < 1.5) {
sound::play("Sword_Hit_2");
} }
$boss_image.sprite->setTextureRect(frame_rect);
window.draw(*$boss_image.sprite); window.draw(*$boss_image.sprite);
} }
@ -99,8 +108,8 @@ namespace gui {
} }
if($overlay.mouse(x, y)) { if($overlay.mouse(x, y)) {
$animation.play();
sound::play("Sword_Hit_1"); sound::play("Sword_Hit_1");
$boss_image.sprite->setColor({255,225,225});
$boss_hit = !$boss_hit; $boss_hit = !$boss_hit;
$boss_hp--; $boss_hp--;
} }
@ -109,7 +118,6 @@ 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;

@ -21,7 +21,9 @@ namespace gui {
sf::Clock $clock; sf::Clock $clock;
int $boss_hp = 10; int $boss_hp = 10;
bool $boss_hit = false; bool $boss_hit = false;
sf::Vector2f $scale{0.8, 0.8};
components::Sound $sounds; components::Sound $sounds;
components::Animation $animation;
GameLevel $level; GameLevel $level;
guecs::UI $status; guecs::UI $status;
guecs::UI $overlay; guecs::UI $overlay;

@ -56,8 +56,9 @@ namespace components {
float tick = twitching(); float tick = twitching();
scale_out.x = std::lerp(scale_out.x, scale_out.x + scale, tick); 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); scale_out.y = std::lerp(scale_out.y, scale_out.y + scale, tick);
if(!simple) { if(!simple) {
rect_out.position.x += current * TEXTURE_WIDTH; rect_out.position.x += current * texture_width;
} }
subframe += speed; subframe += speed;

@ -108,6 +108,7 @@ namespace components {
float subframe = 0; float subframe = 0;
ease::Style easing = ease::IN_OUT_BACK; ease::Style easing = ease::IN_OUT_BACK;
float ease_rate = 0.5f; float ease_rate = 0.5f;
int texture_width = TEXTURE_WIDTH;
void play(); void play();
float twitching(); float twitching();

@ -330,7 +330,6 @@ namespace gui {
$renderer.draw($map_ui); $renderer.draw($map_ui);
} else if(in_state(State::NEXT_LEVEL)) { } else if(in_state(State::NEXT_LEVEL)) {
$window.clear(); $window.clear();
$boss_fight_ui.init();
$boss_fight_ui.render($window); $boss_fight_ui.render($window);
} else { } else {
draw_gui(); draw_gui();

@ -6,7 +6,7 @@
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
textures::init(); textures::init();
sound::init(); sound::init();
sound::mute(true); sound::mute(false);
gui::FSM main; gui::FSM main;
main.event(gui::Event::STARTED); main.event(gui::Event::STARTED);
Autowalker walker(main); Autowalker walker(main);

Loading…
Cancel
Save