MrIceBlock stops after bouncing a lot.
authorMathnerd314 <man.is.allan@gmail.com>
Mon, 25 Jan 2010 22:55:44 +0000 (22:55 +0000)
committerMathnerd314 <man.is.allan@gmail.com>
Mon, 25 Jan 2010 22:55:44 +0000 (22:55 +0000)
Snail can be kicked.
Player backflip/duck jump behavior change.

SVN-Revision: 6272

src/badguy/mriceblock.cpp
src/badguy/snail.cpp
src/badguy/snail.hpp
src/object/player.cpp

index 4b8d6e3..eed83fe 100644 (file)
@@ -21,6 +21,8 @@
 #include "sprite/sprite.hpp"
 #include "supertux/object_factory.hpp"
 
+#include <math.h>
+
 namespace {
 const float KICKSPEED = 500;
 const int MAXSQUISHES = 10;
@@ -102,16 +104,14 @@ MrIceBlock::collision_solid(const CollisionHit& hit)
       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:
index c441b01..faf8660 100644 (file)
@@ -87,7 +87,7 @@ Snail::be_kicked()
   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
@@ -182,6 +182,24 @@ Snail::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
   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)
 {
@@ -196,17 +214,19 @@ 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());
index 9b482d3..40181b9 100644 (file)
@@ -31,6 +31,7 @@ public:
   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);
index 1f3b0cd..8c830bf 100644 (file)
@@ -658,15 +658,10 @@ Player::handle_vertical_input()
   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 {