- tux can now pick up trampoline
authorRyan Flegel <rflegel@gmail.com>
Mon, 17 May 2004 05:24:40 +0000 (05:24 +0000)
committerRyan Flegel <rflegel@gmail.com>
Mon, 17 May 2004 05:24:40 +0000 (05:24 +0000)
SVN-Revision: 1226

src/gameobjs.cpp
src/gameobjs.h
src/player.cpp

index 3fcf030..f96a72c 100644 (file)
@@ -26,6 +26,7 @@
 #include "gameobjs.h"
 #include "sprite_manager.h"
 #include "resources.h"
+#include "level.h"
 
 void
 BouncyDistro::init(float x, float y)
@@ -232,11 +233,12 @@ Trampoline::init(float x, float y)
 {
   base.x = x;
   base.y = y;
-
   base.width = 32;
   base.height = 32;
 
   frame = 0;
+  mode = M_NORMAL;
+  physic.reset();
 }
 
 void
@@ -256,23 +258,47 @@ Trampoline::action(double frame_ratio)
   physic.apply(frame_ratio, base.x, base.y);
 
   // Falling
-  if (issolid(base.x + base.width/2, base.y + base.height))
+  if (mode != M_HELD)
   {
-    base.y = int((base.y + base.height)/32) * 32 - base.height;
+    if (issolid(base.x + base.width/2, base.y + base.height))
+    {
+      base.y = int((base.y + base.height)/32) * 32 - base.height;
+
+      physic.enable_gravity(false);
+      physic.set_velocity_y(0.0f);
 
-    physic.enable_gravity(false);
-    physic.set_velocity_y(0.0f);
+      physic.set_velocity_x(0);
+    }
+    else
+    {
+      physic.enable_gravity(true);
+    }
   }
-  else
-    physic.enable_gravity(true);
+  else // Player is carrying us around
+  {
+    /* FIXME: The trampoline object shouldn't know about pplayer objects. */
+    /* If we're holding the iceblock */
+    Player& tux = *World::current()->get_tux();
+    Direction dir = tux.dir;
 
-}
+    if(dir == RIGHT)
+    {
+      base.x = tux.base.x + 16;
+      base.y = tux.base.y + tux.base.height/1.5 - base.height;
+    }
+    else /* facing left */
+    {
+      base.x = tux.base.x - 16;
+      base.y = tux.base.y + tux.base.height/1.5 - base.height;
+    }
 
-// TODO:
-// If HELD
-//   - move with tux
-// If jumped on
-//   - compress springs (reduce height)
+    if(collision_object_map(base))
+    {
+      base.x = tux.base.x;
+      base.y = tux.base.y + tux.base.height/1.5 - base.height;
+    }
+  }
+}
 
 void
 Trampoline::collision(void *p_c_object, int c_object, CollisionType type)
@@ -285,14 +311,11 @@ Trampoline::collision(void *p_c_object, int c_object, CollisionType type)
 
       if (type == COLLISION_NORMAL)
       {
-        // TODO: Pick up if HELD
+        // Pick up if HELD (done in Player)
       }
 
       else if (type == COLLISION_SQUISH)
       {
-        // TODO: compress springs
-        // TODO: launch tux, if necessary
-
         int squish_amount = (32 - (int)pplayer_c->base.y % 32);
 
         if (squish_amount < 24)
index 36c508c..b6470e4 100644 (file)
@@ -131,6 +131,7 @@ class Trampoline : public GameObject
   void collision(void *p_c_object, int c_object, CollisionType type);
 
   Physic physic;
+  enum { M_NORMAL, M_HELD } mode;
 
  private:
   float power;
index c04bd03..178c750 100644 (file)
@@ -18,6 +18,8 @@
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <math.h>
+#include <iostream>
+#include <iostream>
 #include <cassert>
 #include "gameloop.h"
 #include "globals.h"
@@ -699,19 +701,43 @@ Player::collision(void* p_c_object, int c_object)
     case CO_TRAMPOLINE:
       ptramp_c = (Trampoline*) p_c_object;
       
-      if (physic.get_velocity_x() > 0) // RIGHT
+      // Pick up trampoline
+      if (ptramp_c->mode != Trampoline::M_HELD && input.fire == DOWN && !holding_something)
       {
-        physic.set_velocity_x(0);
-        base.x = ptramp_c->base.x - base.width;
+        holding_something = true;
+        ptramp_c->mode = Trampoline::M_HELD;
+        ptramp_c->base.y -= 8;
       }
-      else if (physic.get_velocity_x() < 0) // LEFT
+      // Set down trampoline
+      else if (ptramp_c->mode == Trampoline::M_HELD && input.fire != DOWN)
       {
-        physic.set_velocity_x(0);
-        base.x = ptramp_c->base.x + ptramp_c->base.width;
+        holding_something = false;
+        ptramp_c->mode = Trampoline::M_NORMAL;
+        ptramp_c->base.y += 8;
+        ptramp_c->physic.set_velocity(physic.get_velocity_x(), physic.get_velocity_y());
+
+        //if (dir == RIGHT)
+        //  ptramp_c->base.x = base.x + base.width+1;
+        //else /* LEFT */
+        //  ptramp_c->base.x = base.x - base.width-1;
       }
-      else
+/*
+      // Don't let tux walk through trampoline
+      else if (ptramp_c->mode != Trampoline::M_HELD && on_ground())
       {
+        if (physic.get_velocity_x() > 0) // RIGHT
+        {
+          physic.set_velocity_x(0);
+          base.x = ptramp_c->base.x - base.width;
+        }
+        else if (physic.get_velocity_x() < 0) // LEFT
+        {
+          physic.set_velocity_x(0);
+          base.x = ptramp_c->base.x + ptramp_c->base.width;
+        }
       }
+*/
+
       break;
 
     default: