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