converted player to new object system
[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 #include "game_object.h"
32 #include "drawable.h"
33
34 enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE };
35
36 template <class T>
37 struct ObjectData
38 {
39   int x;
40   int y;
41   ObjectType type;
42   T type_specific;
43
44   ObjectData(ObjectData* pobject)
45     : x((int)pobject->x), y((int)pobject->y), type(pobject->type), type_specific(pobject->type_specific) {};
46   ObjectData(int x_, int y_, ObjectType type_, T type_specific_) 
47     : x(x_), y(y_), type(type_), type_specific(type_specific_) {};
48
49   ObjectData()
50     : x(0), y(0), type(OBJ_NONE), type_specific() {};
51 };
52
53 /* Bounciness of distros: */
54 #define NO_BOUNCE 0
55 #define BOUNCE 1
56
57 class BouncyDistro : public _GameObject, public Drawable
58 {
59 public:
60   BouncyDistro(DisplayManager& displaymanager, const Vector& pos);
61   virtual void action(float elapsed_time);
62   virtual void draw(ViewPort& viewport, int layer);
63   virtual std::string type() const
64   { return "BouncyDistro"; };
65
66 private:
67   Vector position;
68   float ym;
69 };
70
71 extern Surface* img_distro[4];
72
73 #define BOUNCY_BRICK_MAX_OFFSET 8
74 #define BOUNCY_BRICK_SPEED 0.9
75
76 class Tile;
77
78 class BrokenBrick : public _GameObject, public Drawable
79 {
80 public:
81   BrokenBrick(DisplayManager& displaymanager, Tile* tile,
82       const Vector& pos, const Vector& movement);
83
84   virtual void action(float elapsed_time);
85   virtual void draw(ViewPort& viewport, int layer);
86
87   virtual std::string type() const
88   { return "BrokenBrick"; };
89
90 private:
91   Timer timer;
92   Tile* tile;
93   Vector position;
94   Vector movement;
95 };
96
97 class BouncyBrick : public _GameObject, public Drawable
98 {
99 public:
100   BouncyBrick(DisplayManager& displaymanager, const Vector& pos);
101   virtual void action(float elapsed_time);
102   virtual void draw(ViewPort& viewport, int layer);
103   
104   virtual std::string type() const
105   { return "BouncyBrick"; };
106
107 private:
108   Vector position;
109   float offset;   
110   float offset_m;
111   int shape;      
112 };
113
114 class FloatingScore : public _GameObject, public Drawable
115 {
116 public:
117   FloatingScore(DisplayManager& displaymanager, const Vector& pos, int s);
118   
119   virtual void action(float elapsed_time);
120   virtual void draw(ViewPort& viewport, int layer);
121   virtual std::string type() const
122   { return "FloatingScore"; };
123
124 private:
125   Vector position;
126   char str[10];
127   Timer timer;  
128 };
129
130
131 /* Trampoline */
132 struct TrampolineData
133 {
134   float power;
135 };
136
137 class Trampoline : public GameObject
138 {
139  public:
140   void init(float x, float y);
141   void action(double frame_ratio);
142   void draw();
143   std::string type() { return "Trampoline"; };
144
145   Trampoline(ObjectData<TrampolineData> data)
146   {
147     power = data.type_specific.power;
148
149     init(data.x, data.y);
150   };
151
152   void collision(void *p_c_object, int c_object, CollisionType type);
153
154   Physic physic;
155   enum { M_NORMAL, M_HELD } mode;
156
157  private:
158   float power;
159   unsigned int frame;
160 };
161
162 void load_object_gfx();
163
164 #endif 
165
166 /* Local Variables: */
167 /* mode:c++ */
168 /* End: */