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

Revert "Snails can only be stomped by buttjumping" #1812

Merged
merged 3 commits into from
Oct 2, 2021
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
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