#include "sprite/sprite.hpp"
#include "supertux/object_factory.hpp"
+#include <math.h>
+
namespace {
const float KICKSPEED = 500;
const int MAXSQUISHES = 10;
WalkingBadguy::collision_solid(hit);
break;
case ICESTATE_KICKED: {
- if(hit.right && dir == RIGHT) {
- dir = LEFT;
- sound_manager->play("sounds/iceblock_bump.wav", get_pos());
- physic.set_velocity_x(-KICKSPEED);
- } else if(hit.left && dir == LEFT) {
- dir = RIGHT;
+ if((hit.right && dir == RIGHT) || (hit.left && dir == LEFT)) {
+ dir = (dir == LEFT) ? RIGHT : LEFT;
sound_manager->play("sounds/iceblock_bump.wav", get_pos());
- physic.set_velocity_x(KICKSPEED);
+ physic.set_velocity_x(-physic.get_velocity_x()*.975);
}
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+ if(fabsf(physic.get_velocity_x()) < walk_speed*1.5)
+ set_state(ICESTATE_NORMAL);
break;
}
case ICESTATE_FLAT:
state = STATE_KICKED_DELAY;
sprite->set_action(dir == LEFT ? "flat-left" : "flat-right", 1);
- physic.set_velocity_x(0);
+ physic.set_velocity_x(dir == LEFT ? -SNAIL_KICK_SPEED : SNAIL_KICK_SPEED);
physic.set_velocity_y(0);
// start a timer to delay addition of upward movement until we are (hopefully) out from under the player
return ABORT_MOVE;
}
+HitResponse
+Snail::collision_player(Player& player, const CollisionHit& hit)
+{
+ // handle kicks from left or right side
+ if(state == STATE_FLAT && (hit.left || hit.right)) {
+ if(hit.left) {
+ dir = RIGHT;
+ } else if(hit.right) {
+ dir = LEFT;
+ }
+ player.kick();
+ be_kicked();
+ return FORCE_MOVE;
+ }
+
+ return BadGuy::collision_player(player, hit);
+}
+
bool
Snail::collision_squished(GameObject& object)
{
case STATE_KICKED:
case STATE_NORMAL:
- {
+
+ // Can't stomp in midair
+ if(!on_ground())
+ break;
+
squishcount++;
if (squishcount >= MAX_SNAIL_SQUISHES) {
kill_fall();
return true;
}
- }
-
- sound_manager->play("sounds/stomp.wav", get_pos());
- be_flat();
- break;
+ sound_manager->play("sounds/stomp.wav", get_pos());
+ be_flat();
+ break;
case STATE_FLAT:
sound_manager->play("sounds/kick.wav", get_pos());
void initialize();
void collision_solid(const CollisionHit& hit);
HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+ HitResponse collision_player(Player& player, const CollisionHit& hit);
bool can_break();
void active_update(float elapsed_time);
if(controller->hold(Controller::JUMP) && jump_button_timer.started() && can_jump) {
jump_button_timer.stop();
if (duck) {
- // when running, only jump a little bit; else do a backflip
- if ((physic.get_velocity_x() != 0) ||
- (controller->hold(Controller::LEFT)) ||
- (controller->hold(Controller::RIGHT)))
- {
+ // jump a little bit if moving in same direction; otherwise, do a backflip
+ if ((physic.get_velocity_x() < 0 && dir == LEFT) || (physic.get_velocity_x() > 0 && dir == RIGHT)) {
do_jump(-300);
- }
- else
- {
+ } else {
do_backflip();
}
} else {