Skip to content

Commit

Permalink
Add roll delay
Browse files Browse the repository at this point in the history
  • Loading branch information
MatusGuy committed May 21, 2024
1 parent 7db82e3 commit de313bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
29 changes: 19 additions & 10 deletions src/badguy/igel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ Igel::active_update(float dt_sec)

switch (m_state)
{
case STATE_ROLLING:
if (get_action() == "roll-start-" + dir_to_string(m_dir) &&
m_sprite->animation_done())
case STATE_CHARGING:
if (m_sprite->animation_done())
{
set_action("roll", m_dir);
roll();
}

break;

case STATE_ROLLING:
if (m_ease_timer.started())
{
float progress = m_ease_timer.get_progress();
float vel = (static_cast<float>(SineEaseOut(static_cast<double>(progress))) * (ROLL_SPEED - get_normal_walk_speed())) + get_normal_walk_speed();
float vel = (m_ease_timer.get_progress() * (ROLL_SPEED - get_normal_walk_speed())) + get_normal_walk_speed();
set_walk_speed(vel);
m_physic.set_velocity_x(vel * (m_dir == Direction::LEFT ? -1 : 1));
}
Expand Down Expand Up @@ -106,16 +107,15 @@ Igel::active_update(float dt_sec)

if (m_ease_timer.started())
{
float progress = m_ease_timer.get_progress();
float vel = (static_cast<float>(SineEaseIn(static_cast<double>(progress))) * (get_normal_walk_speed() - ROLL_SPEED)) + ROLL_SPEED;
float vel = (m_ease_timer.get_progress() * (get_normal_walk_speed() - ROLL_SPEED)) + ROLL_SPEED;
set_walk_speed(vel);
m_physic.set_velocity_x(vel * (m_dir == Direction::LEFT ? -1 : 1));
}

if (m_bonked && m_ease_timer.check())
set_action("roll-end", m_dir);

if (!m_roll_cooldown.started() && should_roll()) roll();
if (!m_roll_cooldown.started() && should_roll()) charge();

break;
}
Expand Down Expand Up @@ -228,12 +228,21 @@ Igel::should_roll() const
return in_reach_left && in_reach_right && in_reach_top && in_reach_bottom && can_see_player;
}

void Igel::charge()
{
m_state = STATE_CHARGING;
//TODO: Add an audio cue!!
set_action("roll-start", m_dir);
set_walk_speed(0.f);
m_physic.set_velocity_x(0.f);
}

void
Igel::roll()
{
m_state = STATE_ROLLING;

set_action("roll-start", m_dir);
set_action("roll", m_dir);

set_ledge_behavior(LedgeBehavior::FALL);

Expand Down
3 changes: 2 additions & 1 deletion src/badguy/igel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ class Igel final : public WalkingBadguy

private:
enum Type { NORMAL, CORRUPTED };
enum State { STATE_NORMAL, STATE_ROLLING };
enum State { STATE_NORMAL, STATE_CHARGING, STATE_ROLLING };

bool should_roll() const;
void charge();
void roll();
void stop_rolling(bool bonk = false);
float get_normal_walk_speed() const;
Expand Down

0 comments on commit de313bb

Please sign in to comment.