Skip to content

Commit

Permalink
code style polish for zeekling
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Markus <[email protected]>
  • Loading branch information
MatusGuy and tobbi committed Sep 5, 2023
1 parent 41eff8f commit 1037d4e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 38 deletions.
74 changes: 38 additions & 36 deletions src/badguy/zeekling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -68,7 +68,7 @@ Zeekling::onBumpHorizontal()
}

void
Zeekling::onBumpVertical()
Zeekling::on_bump_vertical()
{
if (BadGuy::get_state() == STATE_BURNING)
{
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/badguy/zeekling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 1037d4e

Please sign in to comment.