8037db6624e41b9f7f173d124105a44e92455e74
[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
30 enum ObjectType { OBJ_NONE, OBJ_BADGUY, OBJ_TRAMPOLINE };
31
32 template <class T>
33 struct ObjectData
34 {
35   int x;
36   int y;
37   ObjectType type;
38   T type_specific;
39
40   ObjectData(ObjectData* pobject)
41     : x((int)pobject->x), y((int)pobject->y), type(pobject->type), type_specific(pobject->type_specific) {};
42   ObjectData(int x_, int y_, ObjectType type_, T type_specific_) 
43     : x(x_), y(y_), type(type_), type_specific(type_specific_) {};
44
45   ObjectData()
46     : x(0), y(0), type(OBJ_NONE), type_specific() {};
47 };
48
49 struct TrampolineData
50 {
51   int power;
52 };
53
54
55 /* Bounciness of distros: */
56 #define NO_BOUNCE 0
57 #define BOUNCE 1
58
59 class BouncyDistro : public GameObject
60 {
61  public:
62   
63   void init(float x, float y);
64   void action(double frame_ratio);
65   void draw(); 
66   std::string type() { return "BouncyDistro"; };
67 };
68
69 extern Surface* img_distro[4];
70
71 #define BOUNCY_BRICK_MAX_OFFSET 8
72 #define BOUNCY_BRICK_SPEED 0.9
73
74 class Tile;
75
76 class BrokenBrick : public GameObject
77 {
78  public:
79   Timer timer;
80   Tile* tile;
81
82   void init(Tile* tile, float x, float y, float xm, float ym);
83   void action(double frame_ratio);
84   void draw();
85   std::string type() { return "BrokenBrick"; };
86 };
87
88 class BouncyBrick : public GameObject
89 {
90  public:
91   float offset;
92   float offset_m;
93   int shape;
94
95   void init(float x, float y);
96   void action(double frame_ratio);
97   void draw();
98   std::string type() { return "BouncyBrick"; };
99 };
100
101 class FloatingScore : public GameObject
102 {
103  public:
104   int value;
105   Timer timer;
106   
107   void init(float x, float y, int s);
108   void action(double frame_ratio);
109   void draw();
110   std::string type() { return "FloatingScore"; };
111 };
112
113 class Trampoline : public GameObject
114 {
115  public:
116   void init(float x, float y);
117   void action(double frame_ratio);
118   void draw();
119   std::string type() { return "Trampoline"; };
120
121   Trampoline(ObjectData<TrampolineData> data)
122   {
123     base.x = data.x;
124     base.y = data.y;
125
126     power = data.type_specific.power;
127   }
128
129  private:
130   int power;
131 };
132
133 void load_trampoline_gfx();
134
135 #endif 
136
137 /* Local Variables: */
138 /* mode:c++ */
139 /* End: */