From 1037d4e85fc38265572023f44169b94a91125155 Mon Sep 17 00:00:00 2001 From: MatusGuy <85036874+MatusGuy@users.noreply.github.com> Date: Tue, 5 Sep 2023 13:37:33 +0100 Subject: [PATCH] code style polish for zeekling Co-authored-by: Tobias Markus --- src/badguy/zeekling.cpp | 74 +++++++++++++++++++++-------------------- src/badguy/zeekling.hpp | 4 +-- 2 files changed, 40 insertions(+), 38 deletions(-) diff --git a/src/badguy/zeekling.cpp b/src/badguy/zeekling.cpp index fafd2f71f17..fcab7851226 100644 --- a/src/badguy/zeekling.cpp +++ b/src/badguy/zeekling.cpp @@ -54,7 +54,7 @@ Zeekling::collision_squished(GameObject& object) } void -Zeekling::onBumpHorizontal() +Zeekling::on_bump_horizontal() { m_dir = (m_dir == Direction::LEFT ? Direction::RIGHT : Direction::LEFT); set_action(m_dir); @@ -68,7 +68,7 @@ Zeekling::onBumpHorizontal() } void -Zeekling::onBumpVertical() +Zeekling::on_bump_vertical() { if (BadGuy::get_state() == STATE_BURNING) { @@ -97,21 +97,23 @@ void Zeekling::collision_solid(const CollisionHit& hit) { if (m_frozen) - BadGuy::collision_solid(hit); - else { - if (m_sprite->get_action() == "squished-left" || + BadGuy::collision_solid(hit); + return; + } + + if (m_sprite->get_action() == "squished-left" || m_sprite->get_action() == "squished-right") - { - return; - } - - if (hit.top || hit.bottom) { - onBumpVertical(); - } - else if (hit.left || hit.right) { - onBumpHorizontal(); - } + { + return; + } + + if (hit.top || hit.bottom) { + on_bump_vertical(); + } + else if (hit.left || hit.right) + { + on_bump_horizontal(); } } @@ -170,28 +172,28 @@ Zeekling::should_we_dive() void Zeekling::active_update(float dt_sec) { - if (state == FLYING) { - if (should_we_dive()) { - state = DIVING; - m_physic.set_velocity_y(2*fabsf(m_physic.get_velocity_x())); - set_action("dive", m_dir); - } - BadGuy::active_update(dt_sec); - return; - } else if (state == DIVING) { - BadGuy::active_update(dt_sec); - return; - } else if (state == CLIMBING) { - // Stop climbing when we're back at initial height. - if (get_pos().y <= m_start_position.y) { - state = FLYING; - m_physic.set_velocity_y(0); - } - BadGuy::active_update(dt_sec); - return; - } else { - assert(false); + switch (state) { + case FLYING: + if (should_we_dive()) { + state = DIVING; + m_physic.set_velocity_y(2 * fabsf(m_physic.get_velocity_x())); + set_action("dive", m_dir); + } + break; + + case CLIMBING: + // Stop climbing when we're back at initial height. + if (get_pos().y <= m_start_position.y) { + state = FLYING; + m_physic.set_velocity_y(0); + } + break; + + default: + break; } + + BadGuy::active_update(dt_sec); } void diff --git a/src/badguy/zeekling.hpp b/src/badguy/zeekling.hpp index 73577595821..92e5891e42d 100644 --- a/src/badguy/zeekling.hpp +++ b/src/badguy/zeekling.hpp @@ -44,8 +44,8 @@ class Zeekling final : public BadGuy virtual bool collision_squished(GameObject& object) override; bool should_we_dive(); - void onBumpHorizontal(); - void onBumpVertical(); + void on_bump_horizontal(); + void on_bump_vertical(); private: enum ZeeklingState {