- barebones BadGuyManager -> ObjectManager
[supertux.git] / src / gameobjs.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2000 Bill Kendrick <bill@newbreedsoftware.com>
5 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 // 
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 //  02111-1307, USA.
21
22 #ifndef SUPERTUX_GAMEOBJS_H
23 #define SUPERTUX_GAMEOBJS_H
24
25 #include "type.h"
26 #include "texture.h"
27 #include "timer.h"
28 #include "scene.h"
29 #include "physic.h"
30 #include "collision.h"
31
32 enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE };
33
34 template <class T>
35 struct ObjectData
36 {
37   int x;
38   int y;
39   ObjectType type;
40   T type_specific;
41
42   ObjectData(ObjectData* pobject)
43     : x((int)pobject->x), y((int)pobject->y), type(pobject->type), type_specific(pobject->type_specific) {};
44   ObjectData(int x_, int y_, ObjectType type_, T type_specific_) 
45     : x(x_), y(y_), type(type_), type_specific(type_specific_) {};
46
47   ObjectData()
48     : x(0), y(0), type(OBJ_NONE), type_specific() {};
49 };
50
51 /* Bounciness of distros: */
52 #define NO_BOUNCE 0
53 #define BOUNCE 1
54
55 class BouncyDistro : public GameObject
56 {
57  public:
58   
59   void init(float x, float y);
60   void action(double frame_ratio);
61   void draw(); 
62   std::string type() { return "BouncyDistro"; };
63 };
64
65 extern Surface* img_distro[4];
66
67 #define BOUNCY_BRICK_MAX_OFFSET 8
68 #define BOUNCY_BRICK_SPEED 0.9
69
70 class Tile;
71
72 class BrokenBrick : public GameObject
73 {
74  public:
75   Timer timer;
76   Tile* tile;
77
78   void init(Tile* tile, float x, float y, float xm, float ym);
79   void action(double frame_ratio);
80   void draw();
81   std::string type() { return "BrokenBrick"; };
82 };
83
84 class BouncyBrick : public GameObject
85 {
86  public:
87   float offset;
88   float offset_m;
89   int shape;
90
91   void init(float x, float y);
92   void action(double frame_ratio);
93   void draw();
94   std::string type() { return "BouncyBrick"; };
95 };
96
97 class FloatingScore : public GameObject
98 {
99  public:
100   int value;
101   Timer timer;
102   
103   void init(float x, float y, int s);
104   void action(double frame_ratio);
105   void draw();
106   std::string type() { return "FloatingScore"; };
107 };
108
109
110 /* Trampoline */
111 struct TrampolineData
112 {
113   float power;
114 };
115
116 class Trampoline : public GameObject
117 {
118  public:
119   void init(float x, float y);
120   void action(double frame_ratio);
121   void draw();
122   std::string type() { return "Trampoline"; };
123
124   Trampoline(ObjectData<TrampolineData> data)
125   {
126     power = data.type_specific.power;
127
128     init(data.x, data.y);
129   };
130
131   void collision(void *p_c_object, int c_object, CollisionType type);
132
133   Physic physic;
134   enum { M_NORMAL, M_HELD } mode;
135
136  private:
137   float power;
138   unsigned int frame;
139 };
140
141 void load_object_gfx();
142
143
144 class ObjectManager
145 {
146  private:
147   ObjectManager();
148   ~ObjectManager();
149
150   static ObjectManager* instance_;
151
152   // XXX Objects will have to be split up into two categories:
153   //  - Drawn before tux
154   //  - Drawn after tux
155
156   std::vector<BadGuy*> badguys;
157   std::vector<Trampoline> trampolines;
158   //std::vector<ParticleSystem> particle_systems;
159   std::vector<BouncyDistro> bouncy_distros;
160   std::vector<BrokenBrick> broken_bricks;
161   std::vector<BouncyBrick> bouncy_bricks;
162   //std::vector<Upgrade> upgrades;
163   //std::vector<Bullet> bullets;
164
165   void load_badguys(std::string filename);
166
167  public:
168   static ObjectManager* instance() { return instance_ ? instance_ : instance_ = new ObjectManager(); }
169   static void destroy_instance() { delete instance_; instance_ = 0; }
170   
171 /*  Object* get(unsigned int id) {
172     if(id < badguys.size())
173       {
174         return badguys[id]; 
175       }
176     else
177       {
178         // Never return 0, but return the 0th tile instead so that
179         // user code doesn't have to check for NULL pointers all over
180         // the place
181         return badguys[0]; 
182       } 
183   }
184 */
185 };
186
187 #endif 
188
189 /* Local Variables: */
190 /* mode:c++ */
191 /* End: */