- trampoline stuff
[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   int 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
135  private:
136   int power;
137   unsigned int frame;
138 };
139
140
141 void load_object_gfx();
142
143 #endif 
144
145 /* Local Variables: */
146 /* mode:c++ */
147 /* End: */