From f6fa541aba887795d4b3329f69c3ead85e5e825a Mon Sep 17 00:00:00 2001 From: MatusGuy Date: Tue, 24 Dec 2024 13:23:15 +0000 Subject: [PATCH] Yeti taunts tux when he dies --- data/images/creatures/yeti/yeti.sprite | 23 +++++++ src/badguy/yeti.cpp | 83 ++++++++++++-------------- src/badguy/yeti.hpp | 2 +- 3 files changed, 61 insertions(+), 47 deletions(-) diff --git a/data/images/creatures/yeti/yeti.sprite b/data/images/creatures/yeti/yeti.sprite index 544877539c..d582700473 100644 --- a/data/images/creatures/yeti/yeti.sprite +++ b/data/images/creatures/yeti/yeti.sprite @@ -130,6 +130,29 @@ (hitbox 37 27 72 100) (mirror-action "rage-left") ) + + (action + (name "taunt-left") + (fps 18) + (loop-frame 4) + (hitbox 31 27 72 100) + (images "idle-0.png" + "idle-1.png" + "idle-2.png" + "idle-3.png" + "idle-4.png" + "idle-5.png" + "idle-3.png" + "idle-6.png" + "idle-7.png") + ) + (action + (name "taunt-right") + (fps 18) + (loop-frame 4) + (hitbox 37 27 72 100) + (mirror-action "taunt-left") + ) (action (name "leap-left") diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 92f22e5617..099df8c0a4 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -89,7 +89,7 @@ Yeti::initialize() { m_next_state = RUN; recalculate_pos(); - announce(); + announce(false); } void @@ -123,19 +123,24 @@ void Yeti::active_update(float dt_sec) { Boss::boss_update(dt_sec); - auto player = get_nearest_player(); Vector grab_pos = get_bbox().get_middle(); float push_distance; - push_distance = player ? (glm::length(grab_pos - player->get_bbox().get_middle())) : 0.f; + auto player = get_nearest_player(); - if (on_ground() && is_idle() && push_distance <= TUX_GRAB_DISTANCE && m_physic.get_velocity_x() == 0.f) + push_distance = player ? glm::length(grab_pos - player->get_bbox().get_middle()) : 0.f; + + if (player && on_ground() && is_idle() && + push_distance <= TUX_GRAB_DISTANCE && m_physic.get_velocity_x() == 0.f) { throw_tux(); } switch (m_state) { case ANNOUNCE: + if (m_next_state == ANNOUNCE) + break; + if (m_state_timer.check()) { if (m_next_state == RUN) @@ -170,7 +175,7 @@ Yeti::active_update(float dt_sec) run(true); break; - case STOMP: + case IDLE: idle(true); break; @@ -182,18 +187,10 @@ Yeti::active_update(float dt_sec) break; case RUN: - /* - if ((m_dir == Direction::RIGHT && get_pos().x >= m_right_stand_x) || - (m_dir == Direction::LEFT && get_pos().x <= m_left_stand_x)) - { - idle(true); - } - */ - if ((m_dir == Direction::RIGHT && math::in_bounds(get_pos().x, m_right_jump_x, m_right_jump_x + 64.f)) || (m_dir == Direction::LEFT && math::in_bounds(get_pos().x, m_left_jump_x - 64.f, m_left_jump_x))) { - m_next_state = STOMP; + m_next_state = IDLE; jump(JUMP_UP_VY); } @@ -209,9 +206,17 @@ Yeti::active_update(float dt_sec) if (m_state_timer.check()) { + // If the player is dead, laugh at him. Forever. + if (!player) + { + m_next_state = ANNOUNCE; + announce(true); + break; + } + if (!m_pinch_announced && m_pinch_mode) { - announce(); + announce(false); break; } @@ -358,10 +363,10 @@ Yeti::active_update(float dt_sec) } void -Yeti::announce() +Yeti::announce(bool taunt) { m_state = ANNOUNCE; - set_action("rage", m_dir); + set_action(taunt ? "taunt" : "rage", m_dir); m_state_timer.stop(); SoundManager::current()->play("sounds/yeti_roar.wav", get_pos()); @@ -591,39 +596,25 @@ void Yeti::collision_solid(const CollisionHit& hit) { update_on_ground_flag(hit); - if (hit.top || hit.bottom) { - // Hit floor or roof. - m_physic.set_velocity_y(0); - switch (m_state) { - case RUN: - break; - case JUMP: - break; - case THROW: - break; - case THROW_BIG: + if (!hit.bottom) + return; + + m_physic.set_velocity_y(0); + switch (m_state) + { + case STOMP: + if (m_attacked) break; - case STOMP: - // We just landed. - if (m_attacked) - break; + set_action("stomp", m_dir); + m_attack_count++; + m_attacked = true; + drop_stalactite(); - set_action("stomp", m_dir); - m_attack_count++; - m_attacked = true; - drop_stalactite(); + break; - break; - case DIZZY: - break; - case THROW_TUX: - break; - } - } else if (hit.left || hit.right) { - // Hit wall. - if(m_state != DIZZY) - jump(JUMP_UP_VY); + default: + break; } } diff --git a/src/badguy/yeti.hpp b/src/badguy/yeti.hpp index 1456f8fd94..7ba2f27f9c 100644 --- a/src/badguy/yeti.hpp +++ b/src/badguy/yeti.hpp @@ -60,7 +60,7 @@ class Yeti final : public Boss }; private: - void announce(); + void announce(bool taunt); void run(bool change_state); void jump(float velocity); void idle(bool stomp, float waitduration = 0);