Skip to content

Commit

Permalink
bomb merge finished and gold bomb fixed.
Browse files Browse the repository at this point in the history
MISSION ALL OVER
  • Loading branch information
MatusGuy committed Jul 23, 2024
1 parent 368ed25 commit f5ad834
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
73 changes: 55 additions & 18 deletions src/badguy/goldbomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

#include "audio/sound_manager.hpp"
#include "audio/sound_source.hpp"
#include "badguy/bomb.hpp"
#include "badguy/haywire.hpp"
#include "badguy/owl.hpp"
#include "object/coin_explode.hpp"
Expand Down Expand Up @@ -51,7 +50,7 @@ GoldBomb::GoldBomb(const ReaderMapping& reader) :
void
GoldBomb::collision_solid(const CollisionHit& hit)
{
if ((m_state != STATE_NORMAL || m_state != STATE_TICKING) && (hit.left || hit.right))
if ((m_state != STATE_NORMAL && m_state != STATE_TICKING) && (hit.left || hit.right))
{
cornered();
return;
Expand All @@ -63,15 +62,25 @@ GoldBomb::collision_solid(const CollisionHit& hit)
void
GoldBomb::active_update(float dt_sec)
{
update_ticking(dt_sec);
if (m_state == STATE_TICKING)
{
update_ticking(dt_sec);
return;
}

if ((m_state == STATE_FLEEING || m_state == STATE_CORNERED) && on_ground() && might_fall(s_normal_max_drop_height+1))
if ((m_state == STATE_FLEEING || m_state == STATE_CORNERED || m_state == STATE_RECOVER)
&& on_ground() && might_fall(s_normal_max_drop_height+1))
{
// also check for STATE_CORNERED just so
// the bomb doesnt automatically turn around
cornered();
if (m_state == STATE_RECOVER)
recover();
else
cornered();

return;
}

WalkingBadguy::active_update(dt_sec);

if (m_frozen) return;
Expand Down Expand Up @@ -106,19 +115,17 @@ GoldBomb::active_update(float dt_sec)
if (m_state == STATE_CORNERED)
{
// Look back to check.
set_action("recover", m_dir);
if (!m_sprite->animation_done()) return;
recover();
return;
}

// Finally, when done recovering, go back to normal.
if (m_state == STATE_NORMAL) return;
if (m_state == STATE_RECOVER)
{
if (!m_sprite->animation_done())
return;
}

m_state = STATE_NORMAL;
m_physic.set_velocity_x(NORMAL_WALK_SPEED * (m_dir == Direction::LEFT ? -1 : 1));
m_physic.set_acceleration_x(0);
set_action(m_dir);
set_ledge_behavior(LedgeBehavior::SMART);
set_walk_speed(NORMAL_WALK_SPEED);
normalize();
return;
}

Expand Down Expand Up @@ -166,12 +173,18 @@ GoldBomb::active_update(float dt_sec)
}

case STATE_REALIZING:
if (!m_realize_timer.check()) break;
if (!m_realize_timer.check())
break;

flee(vecdist.x > 0 ? Direction::LEFT : Direction::RIGHT);
break;

default: break;
case STATE_RECOVER:
cornered();
return;

default:
break;
}
}

Expand Down Expand Up @@ -203,7 +216,8 @@ GoldBomb::flee(Direction dir)
void
GoldBomb::cornered()
{
if (m_state == STATE_CORNERED) return;
if (m_state == STATE_CORNERED)
return;

set_walk_speed(0);
m_physic.set_velocity_x(0);
Expand All @@ -214,4 +228,27 @@ GoldBomb::cornered()
m_state = STATE_CORNERED;
}

void
GoldBomb::recover()
{
if (m_state == STATE_RECOVER)
return;

set_action("recover", m_dir);

m_state = STATE_RECOVER;
}

void GoldBomb::normalize()
{
m_physic.set_velocity_x(NORMAL_WALK_SPEED * (m_dir == Direction::LEFT ? -1 : 1));
m_physic.set_acceleration_x(0);

set_action(m_dir);
set_ledge_behavior(LedgeBehavior::SMART);
set_walk_speed(NORMAL_WALK_SPEED);

m_state = STATE_NORMAL;
}

/* EOF */
5 changes: 4 additions & 1 deletion src/badguy/goldbomb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ class GoldBomb final : public MrBomb
private:
void flee(Direction dir);
void cornered();
void recover();
void normalize();

private:
enum State : uint8_t {
STATE_REALIZING = 2,
STATE_FLEEING,
STATE_CORNERED
STATE_CORNERED,
STATE_RECOVER
};

Timer m_realize_timer;
Expand Down
28 changes: 14 additions & 14 deletions src/badguy/mrbomb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,12 @@ MrBomb::collision_squished(GameObject& object)
void
MrBomb::active_update(float dt_sec)
{
update_ticking(dt_sec);
if (m_state == STATE_TICKING)
{
update_ticking(dt_sec);
return;
}

WalkingBadguy::active_update(dt_sec);
}

Expand Down Expand Up @@ -321,22 +326,17 @@ MrBomb::play_looping_sounds()

void MrBomb::update_ticking(float dt_sec)
{
if (m_state == STATE_TICKING)
{
m_exploding_sprite->set_action("exploding", 1);
m_exploding_sprite->set_action("exploding", 1);

if (on_ground())
m_physic.set_velocity_x(0);
if (on_ground())
m_physic.set_velocity_x(0);

m_ticking_sound->set_position(get_pos());

if (m_sprite->animation_done())
kill_fall();
else if (!is_grabbed())
m_col.set_movement(m_physic.get_movement(dt_sec));
m_ticking_sound->set_position(get_pos());

return;
}
if (m_sprite->animation_done())
kill_fall();
else if (!is_grabbed())
m_col.set_movement(m_physic.get_movement(dt_sec));
}

/* EOF */

0 comments on commit f5ad834

Please sign in to comment.