- added support for different types of objects
authorRyan Flegel <rflegel@gmail.com>
Sun, 16 May 2004 00:36:58 +0000 (00:36 +0000)
committerRyan Flegel <rflegel@gmail.com>
Sun, 16 May 2004 00:36:58 +0000 (00:36 +0000)
- working on adding trampoline

SVN-Revision: 1203

src/gameobjs.cpp
src/gameobjs.h
src/level.cpp
src/level.h
src/resources.cpp

index 010cf1d..3c04c05 100644 (file)
@@ -23,6 +23,8 @@
 #include "tile.h"
 #include "gameloop.h"
 #include "gameobjs.h"
+#include "sprite_manager.h"
+#include "resources.h"
 
 void
 BouncyDistro::init(float x, float y)
@@ -209,5 +211,45 @@ FloatingScore::draw()
   gold_text->draw(str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1);
 }
 
+/* Trampoline */
+
+#define TRAMPOLINE_FRAMES 4
+Sprite *img_trampoline[TRAMPOLINE_FRAMES];
+
+void load_trampoline_gfx()
+{
+  for (int i = 0; i < TRAMPOLINE_FRAMES; i++)
+  {
+    char sprite_name[16];
+    sprintf(sprite_name, "trampoline-%i", i+1);
+    img_trampoline[0] = sprite_manager->load(sprite_name);
+  }
+}
+
+void
+Trampoline::init(float x, float y)
+{
+  base.x = x;
+  base.y = y;
+}
+
+void
+Trampoline::action(double frame_ratio)
+{
+  (void) frame_ratio;
+  // TODO:
+  // If HELD
+  //   - move with tux
+  // If jumped on
+  //   - compress springs (reduce height)
+}
+
+void
+Trampoline::draw()
+{
+  img_trampoline[0]->draw((int)base.x, (int)base.y);
+}
+
+
 /* EOF */
 
index 92d311d..69a8453 100644 (file)
 #include "timer.h"
 #include "scene.h"
 
+template <class T>
+struct ObjectData
+{
+  int x;
+  int y;
+  T type_specific;
+
+  ObjectData(ObjectData* pobject)
+    : x((int)pobject->x), y((int)pobject->y) {};
+  ObjectData(int x_, int y_, T type_specific_) 
+    : x(x_), y(y_), type_specific(type_specific_) {};
+
+  ObjectData()
+    : x(0), y(0), type_specific() {};
+};
+
+struct TrampolineData
+{
+  unsigned int power;
+};
+
+
 /* Bounciness of distros: */
 #define NO_BOUNCE 0
 #define BOUNCE 1
@@ -85,6 +107,17 @@ class FloatingScore : public GameObject
   std::string type() { return "FloatingScore"; };
 };
 
+class Trampoline : public GameObject
+{
+ public:
+  void init(float x, float y);
+  void action(double frame_ratio);
+  void draw();
+  std::string type() { return "Trampoline"; };
+};
+
+void load_trampoline_gfx();
+
 #endif 
 
 /* Local Variables: */
index ce2414f..869c1e2 100644 (file)
@@ -33,6 +33,7 @@
 #include "lispreader.h"
 #include "resources.h"
 #include "music_manager.h"
+#include "gameobjs.h"
 
 using namespace std;
 
@@ -391,15 +392,28 @@ Level::load(const std::string& filename)
             while (!lisp_nil_p(cur))
               {
                 lisp_object_t* data = lisp_car(cur);
+                std::string object_type = "";
 
-                BadGuyData bg_data;
-                bg_data.kind = badguykind_from_string(lisp_symbol(lisp_car(data)));
                 LispReader reader(lisp_cdr(data));
-                reader.read_int("x", &bg_data.x);
-                reader.read_int("y", &bg_data.y);
-                reader.read_bool("stay-on-platform", &bg_data.stay_on_platform);
+                reader.read_string("type", &object_type);
 
-                badguy_data.push_back(bg_data);
+                if (object_type == "badguy" || object_type == "")
+                {
+                  BadGuyData bg_data;
+                  bg_data.kind = badguykind_from_string(lisp_symbol(lisp_car(data)));
+                  reader.read_int("x", &bg_data.x);
+                  reader.read_int("y", &bg_data.y);
+                  reader.read_bool("stay-on-platform", &bg_data.stay_on_platform);
+
+                  badguy_data.push_back(bg_data);
+                }
+                else
+                {
+                    if (lisp_symbol(lisp_car(data)) == "trampoline")
+                    {
+                      ObjectData<TrampolineData> _trampoline_data;
+                    }
+                }
 
                 cur = lisp_cdr(cur);
               }
index 0a023a5..8e70354 100644 (file)
@@ -26,6 +26,7 @@
 #include "badguy.h"
 #include "lispreader.h"
 #include "musicref.h"
+#include "gameobjs.h"
 
 class Tile;
 
@@ -97,6 +98,7 @@ class Level
   float hor_autoscroll_speed;
 
   std::vector<BadGuyData> badguy_data;
+  std::vector< ObjectData<TrampolineData> > trampoline_data;
 
   /** A collection of points to which Tux can be reset after a lost live */
   std::vector<ResetPoint> reset_points;
index cdef725..b6fcf70 100644 (file)
@@ -175,6 +175,9 @@ void loadshared()
   /* Upgrades: */
   load_special_gfx();
 
+  /* Trampoline */
+  load_trampoline_gfx();
+
   /* Distros: */
   img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png",
                USE_ALPHA);