[Supertux-Commit] r5464 - in trunk/supertux: data/levels/test src/badguy

sommer at millhouse.dreamhost.com sommer at millhouse.dreamhost.com
Tue May 13 12:14:53 PDT 2008


Author: sommer
Date: 2008-05-13 12:14:53 -0700 (Tue, 13 May 2008)
New Revision: 5464

Added:
   trunk/supertux/data/levels/test/captainsnowball.stl
Modified:
   trunk/supertux/src/badguy/captainsnowball.cpp
   trunk/supertux/src/badguy/captainsnowball.hpp
Log:
CaptainSnowball uses his ability to jump more often


Added: trunk/supertux/data/levels/test/captainsnowball.stl
===================================================================
(Contents removed)

Modified: trunk/supertux/src/badguy/captainsnowball.cpp
===================================================================
--- trunk/supertux/src/badguy/captainsnowball.cpp	2008-05-12 19:53:12 UTC (rev 5463)
+++ trunk/supertux/src/badguy/captainsnowball.cpp	2008-05-13 19:14:53 UTC (rev 5464)
@@ -22,8 +22,8 @@
 #include "captainsnowball.hpp"
 
 namespace{
-  static const float WALK_SPEED = 50; 
-  static const float BOARDING_SPEED = 300;
+  static const float WALK_SPEED = 100; 
+  static const float BOARDING_SPEED = 200;
 }
 
 
@@ -39,17 +39,53 @@
 {
   // Created during game eg. by dispencer. Board the enemy!
   walk_speed = BOARDING_SPEED;
-  physic.set_velocity_y(-500);
+  max_drop_height = -1;
+  physic.set_velocity_y(-400);
 }
 
+bool
+CaptainSnowball::might_climb(int width, int height)
+{
+  // make sure we check for at least a 1-pixel climb
+  assert(height > 0);
+
+  float x1;
+  float x2;
+  float y1a = bbox.p1.y + 1;
+  float y2a = bbox.p2.y - 1;
+  float y1b = bbox.p1.y + 1 - height;
+  float y2b = bbox.p2.y - 1 - height;
+  if (dir == LEFT) {
+    x1 = bbox.p1.x - width;
+    x2 = bbox.p1.x - 1;
+  } else {
+    x1 = bbox.p2.x + 1;
+    x2 = bbox.p2.x + width;
+  }
+  return ((!Sector::current()->is_free_of_statics(Rect(x1, y1a, x2, y2a))) && (Sector::current()->is_free_of_statics(Rect(x1, y1b, x2, y2b))));
+}
+
 void
+CaptainSnowball::active_update(float elapsed_time)
+{
+  if (on_ground() && might_climb(8, 64)) {
+    physic.set_velocity_y(-400);
+  } else if (on_ground() && might_fall(16)) {
+    physic.set_velocity_y(-400);
+    walk_speed = BOARDING_SPEED;
+    physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
+  }
+  WalkingBadguy::active_update(elapsed_time);
+}
+
+void
 CaptainSnowball::collision_solid(const CollisionHit& hit)
 {
-  WalkingBadguy::collision_solid(hit);
-  if( is_active() ){ 
+  if (is_active() && (walk_speed == BOARDING_SPEED)) {
     walk_speed = WALK_SPEED;
     physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed);
   }
+  WalkingBadguy::collision_solid(hit);
 }
 
 bool

Modified: trunk/supertux/src/badguy/captainsnowball.hpp
===================================================================
--- trunk/supertux/src/badguy/captainsnowball.hpp	2008-05-12 19:53:12 UTC (rev 5463)
+++ trunk/supertux/src/badguy/captainsnowball.hpp	2008-05-13 19:14:53 UTC (rev 5464)
@@ -29,8 +29,11 @@
   CaptainSnowball(const Vector& pos, Direction d);
 
   virtual CaptainSnowball* clone() const { return new CaptainSnowball(*this); }
+  virtual void active_update(float elapsed_time);
   void collision_solid(const CollisionHit& hit);
 
+  bool might_climb(int width, int height);
+
 protected:
   bool collision_squished(GameObject& object);
 




More information about the Supertux-Commit mailing list