Skip to content

Commit

Permalink
Revert "Snails can only be stomped by buttjumping" (#1812)
Browse files Browse the repository at this point in the history
* Revert "Snails can only be stomped by buttjumping"

* Revert hiding behaviour

* Delete function and constant
  • Loading branch information
mrkubax10 authored Oct 2, 2021
1 parent 34cbf3e commit 4d51855
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 58 deletions.
55 changes: 1 addition & 54 deletions src/badguy/snail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,12 @@ namespace {
const float SNAIL_KICK_SPEED = 500;
const int MAX_SNAIL_SQUISHES = 10;
const float SNAIL_KICK_SPEED_Y = -500; /**< y-velocity gained when kicked */
const float DANGER_SENSE_DIST = 25;
const float SHIELDED_TIME = 1.5f;
}

Snail::Snail(const ReaderMapping& reader) :
WalkingBadguy(reader, "images/creatures/snail/snail.sprite", "left", "right"),
state(STATE_NORMAL),
kicked_delay_timer(),
danger_gone_timer(),
squishcount(0)
{
walk_speed = 80;
Expand Down Expand Up @@ -94,36 +91,11 @@ Snail::be_kicked(bool upwards)
kicked_delay_timer.start(0.05f);
}

void
Snail::be_shielded()
{
state = STATE_SHIELDED;

m_physic.set_velocity_x(0);
m_physic.set_velocity_y(0);

m_sprite->set_action(m_dir == Direction::LEFT ? "shielded-left" : "shielded-right");

danger_gone_timer.start(SHIELDED_TIME);
}

bool
Snail::can_break() const {
return state == STATE_KICKED;
}

bool
Snail::is_in_danger()
{
Rectf sense_zone = get_bbox().moved(Vector(0, -DANGER_SENSE_DIST));
auto player = Sector::get().get_nearest_player(get_bbox());
if (player && sense_zone.contains(player->get_bbox()) && player->get_velocity().y > 0)
{
return true;
}
return false;
}

void
Snail::active_update(float dt_sec)
{
Expand All @@ -136,11 +108,6 @@ Snail::active_update(float dt_sec)
return;
}

if(state == STATE_NORMAL && is_in_danger())
{
be_shielded();
}

switch (state) {

case STATE_NORMAL:
Expand Down Expand Up @@ -168,13 +135,6 @@ Snail::active_update(float dt_sec)

case STATE_GRABBED:
break;

case STATE_SHIELDED:
if (danger_gone_timer.check())
{
be_normal();
}
break;
}

BadGuy::active_update(dt_sec);
Expand All @@ -201,10 +161,6 @@ Snail::collision_solid(const CollisionHit& hit)
switch (state)
{
case STATE_NORMAL:
case STATE_SHIELDED:
WalkingBadguy::collision_solid(hit);
return;

case STATE_KICKED:
if (hit.left || hit.right) {
SoundManager::current()->play("sounds/iceblock_bump.wav", get_pos());
Expand Down Expand Up @@ -240,8 +196,6 @@ Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit)

switch (state) {
case STATE_NORMAL:
case STATE_SHIELDED:
return WalkingBadguy::collision_badguy(badguy, hit);
case STATE_FLAT:
case STATE_KICKED_DELAY:
return FORCE_MOVE;
Expand Down Expand Up @@ -283,21 +237,14 @@ Snail::collision_squished(GameObject& object)
return WalkingBadguy::collision_squished(object);

Player* player = dynamic_cast<Player*>(&object);
if (player && player->is_invincible()) {
if (player && (player->is_invincible() || player->m_does_buttjump)) {
kill_fall();
player->bounce(*this);
return true;
}

switch (state) {

case STATE_SHIELDED:
case STATE_NORMAL:
if(player && !player->m_does_buttjump)
{
player->bounce(*this);
break;
}
BOOST_FALLTHROUGH;
case STATE_KICKED:
squishcount++;
Expand Down
4 changes: 0 additions & 4 deletions src/badguy/snail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,11 @@ class Snail final :

protected:
virtual bool collision_squished(GameObject& object) override;
bool is_in_danger();

void be_normal(); /**< switch to state STATE_NORMAL */
void be_flat(); /**< switch to state STATE_FLAT */
void be_kicked(bool upwards); /**< switch to state STATE_KICKED_DELAY */
void be_grabbed();
void be_shielded();

private:
enum State {
Expand All @@ -62,13 +60,11 @@ class Snail final :
STATE_KICKED_DELAY, /**< short delay before being launched */
STATE_KICKED, /**< launched */
STATE_GRABBED, /**< grabbed by tux */
STATE_SHIELDED /*< hidden into shell for protection */
};

private:
State state;
Timer kicked_delay_timer; /**< wait time until switching from STATE_KICKED_DELAY to STATE_KICKED */
Timer danger_gone_timer; /**< time after which snail turns back from STATE_SHELLED */
int squishcount;

private:
Expand Down

0 comments on commit 4d51855

Please sign in to comment.