-converted remaining classes to GameObject
[supertux.git] / src / gameobjs.h
index b6cec55..103defa 100644 (file)
 #include "scene.h"
 #include "physic.h"
 #include "collision.h"
-
-enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE };
-
-template <class T>
-struct ObjectData
-{
-  int x;
-  int y;
-  ObjectType type;
-  T type_specific;
-
-  ObjectData(ObjectData* pobject)
-    : x((int)pobject->x), y((int)pobject->y), type(pobject->type), type_specific(pobject->type_specific) {};
-  ObjectData(int x_, int y_, ObjectType type_, T type_specific_) 
-    : x(x_), y(y_), type(type_), type_specific(type_specific_) {};
-
-  ObjectData()
-    : x(0), y(0), type(OBJ_NONE), type_specific() {};
-};
+#include "game_object.h"
+#include "drawable.h"
+#include "moving_object.h"
+#include "lispwriter.h"
 
 /* Bounciness of distros: */
 #define NO_BOUNCE 0
 #define BOUNCE 1
 
-class BouncyDistro : public GameObject
+class BouncyDistro : public GameObject, public Drawable
 {
- public:
-  
-  void init(float x, float y);
-  void action(double frame_ratio);
-  void draw(); 
-  std::string type() { return "BouncyDistro"; };
+public:
+  BouncyDistro(DisplayManager& displaymanager, const Vector& pos);
+  virtual void action(float elapsed_time);
+  virtual void draw(ViewPort& viewport, int layer);
+  virtual std::string type() const
+  { return "BouncyDistro"; };
+
+private:
+  Vector position;
+  float ym;
 };
 
 extern Surface* img_distro[4];
@@ -69,65 +58,70 @@ extern Surface* img_distro[4];
 
 class Tile;
 
-class BrokenBrick : public GameObject
+class BrokenBrick : public GameObject, public Drawable
 {
- public:
-  Timer timer;
-  Tile* tile;
+public:
+  BrokenBrick(DisplayManager& displaymanager, Tile* tile,
+      const Vector& pos, const Vector& movement);
 
-  void init(Tile* tile, float x, float y, float xm, float ym);
-  void action(double frame_ratio);
-  void draw();
-  std::string type() { return "BrokenBrick"; };
-};
+  virtual void action(float elapsed_time);
+  virtual void draw(ViewPort& viewport, int layer);
 
-class BouncyBrick : public GameObject
-{
- public:
-  float offset;
-  float offset_m;
-  int shape;
+  virtual std::string type() const
+  { return "BrokenBrick"; };
 
-  void init(float x, float y);
-  void action(double frame_ratio);
-  void draw();
-  std::string type() { return "BouncyBrick"; };
+private:
+  Timer timer;
+  Tile* tile;
+  Vector position;
+  Vector movement;
 };
 
-class FloatingScore : public GameObject
+class BouncyBrick : public GameObject, public Drawable
 {
- public:
-  int value;
-  Timer timer;
+public:
+  BouncyBrick(DisplayManager& displaymanager, const Vector& pos);
+  virtual void action(float elapsed_time);
+  virtual void draw(ViewPort& viewport, int layer);
   
-  void init(float x, float y, int s);
-  void action(double frame_ratio);
-  void draw();
-  std::string type() { return "FloatingScore"; };
-};
+  virtual std::string type() const
+  { return "BouncyBrick"; };
 
+private:
+  Vector position;
+  float offset;   
+  float offset_m;
+  int shape;      
+};
 
-/* Trampoline */
-struct TrampolineData
+class FloatingScore : public GameObject, public Drawable
 {
-  float power;
+public:
+  FloatingScore(DisplayManager& displaymanager, const Vector& pos, int s);
+  
+  virtual void action(float elapsed_time);
+  virtual void draw(ViewPort& viewport, int layer);
+  virtual std::string type() const
+  { return "FloatingScore"; };
+
+private:
+  Vector position;
+  char str[10];
+  Timer timer;  
 };
 
-class Trampoline : public GameObject
+class Trampoline : public MovingObject, public Drawable, public Serializable
 {
- public:
-  void init(float x, float y);
-  void action(double frame_ratio);
-  void draw();
-  std::string type() { return "Trampoline"; };
-
-  Trampoline(ObjectData<TrampolineData> data)
-  {
-    power = data.type_specific.power;
-
-    init(data.x, data.y);
-  };
-
+public:
+  Trampoline(DisplayManager& displaymanager, LispReader& reader);
+  virtual void write(LispWriter& writer);
+  virtual void action(float frame_ratio);
+  virtual void draw(ViewPort& viewport, int layer);
+  virtual std::string type() const
+  { return "Trampoline"; };
+
+  virtual void collision(const MovingObject& other, int);
   void collision(void *p_c_object, int c_object, CollisionType type);
 
   Physic physic;
@@ -140,54 +134,6 @@ class Trampoline : public GameObject
 
 void load_object_gfx();
 
-
-class ObjectManager
-{
- private:
-  ObjectManager();
-  ~ObjectManager();
-
-  static ObjectManager* instance_;
-
-  // XXX Objects will have to be split up into two categories:
-  //  - Drawn before tux
-  //  - Drawn after tux
-  // Eventually Player should be a part of ObjectManager
-
-  std::vector<BadGuy*> badguys;
-  std::vector<Trampoline> trampolines;
-  std::vector<BouncyDistro> bouncy_distros;
-  std::vector<BrokenBrick> broken_bricks;
-  std::vector<BouncyBrick> bouncy_bricks;
-  //std::vector<Upgrade> upgrades;
-  //std::vector<Bullet> bullets;
-
-  void load_badguys(std::string filename);
-
- public:
-  static ObjectManager* instance() { return instance_ ? instance_ : instance_ = new ObjectManager(); }
-  static void destroy_instance() { delete instance_; instance_ = 0; }
-
-  void draw_bg();
-  void draw_fg();
-  void actions();
-  
-/*  Object* get(unsigned int id) {
-    if(id < badguys.size())
-      {
-        return badguys[id]; 
-      }
-    else
-      {
-        // Never return 0, but return the 0th tile instead so that
-        // user code doesn't have to check for NULL pointers all over
-        // the place
-        return badguys[0]; 
-      } 
-  }
-*/
-};
-
 #endif 
 
 /* Local Variables: */