Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Igel Improvements #2948

Merged
merged 3 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 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 @@ -147,6 +147,12 @@ Igel::collision_badguy(BadGuy &badguy, const CollisionHit &hit)
return WalkingBadguy::collision_badguy(badguy, hit);
}

bool
Igel::can_break() const
{
return m_state == STATE_ROLLING;
}

void
Igel::run_dead_script()
{
Expand Down Expand Up @@ -222,12 +228,22 @@ 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
4 changes: 3 additions & 1 deletion src/badguy/igel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Igel final : public WalkingBadguy
virtual void active_update(float dt_sec) override;
virtual void collision_solid(const CollisionHit &hit) override;
virtual HitResponse collision_badguy(BadGuy &badguy, const CollisionHit &hit) override;
virtual bool can_break() const override;
virtual void run_dead_script() override;

virtual std::string get_overlay_size() const override { return "2x1"; }
Expand All @@ -46,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