Changes:
[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 "screen/surface.h"
27 #include "timer.h"
28 #include "scene.h"
29 #include "physic.h"
30 #include "collision.h"
31 #include "game_object.h"
32 #include "moving_object.h"
33 #include "serializable.h"
34 #include "lispwriter.h"
35
36 /* Bounciness of distros: */
37 #define NO_BOUNCE 0
38 #define BOUNCE 1
39
40 class Sprite;
41
42 struct TileId;
43
44 class BouncyDistro : public GameObject
45 {
46 public:
47   BouncyDistro(const Vector& pos);
48   virtual void action(float elapsed_time);
49   virtual void draw(DrawingContext& context);
50
51 private:
52   Vector position;
53   float ym;
54 };
55
56 extern Surface* img_distro[4];
57
58 #define BOUNCY_BRICK_MAX_OFFSET 8
59 #define BOUNCY_BRICK_SPEED 0.9
60
61 class Tile;
62
63 class BrokenBrick : public GameObject
64 {
65 public:
66   BrokenBrick(Tile* tile, const Vector& pos, const Vector& movement);
67
68   virtual void action(float elapsed_time);
69   virtual void draw(DrawingContext& context);
70
71 private:
72   Timer timer;
73   Tile* tile;
74   Vector position;
75   Vector movement;
76 };
77
78 class BouncyBrick : public GameObject
79 {
80 public:
81   BouncyBrick(const Vector& pos);
82   virtual void action(float elapsed_time);
83   virtual void draw(DrawingContext& context);
84   
85 private:
86   Vector position;
87   float offset;   
88   float offset_m;
89   TileId& shape;      
90 };
91
92 class FloatingScore : public GameObject
93 {
94 public:
95   FloatingScore(const Vector& pos, int s);
96   
97   virtual void action(float elapsed_time);
98   virtual void draw(DrawingContext& context);
99
100 private:
101   Vector position;
102   char str[10];
103   Timer timer;  
104 };
105
106 #define TRAMPOLINE_FRAMES 4
107 extern Sprite *img_trampoline[TRAMPOLINE_FRAMES];
108
109 class Trampoline : public MovingObject, public Serializable
110 {
111 public:
112   Trampoline(LispReader& reader);
113   Trampoline(float x, float y);
114  
115   virtual void write(LispWriter& writer);
116   virtual void action(float frame_ratio);
117   virtual void draw(DrawingContext& context);
118
119   virtual void collision(const MovingObject& other, int);
120   void collision(void *p_c_object, int c_object, CollisionType type);
121
122   Physic physic;
123   enum { M_NORMAL, M_HELD } mode;
124
125  private:
126   float power;
127   unsigned int frame;
128 };
129
130 extern Sprite *img_flying_platform;
131
132 class FlyingPlatform : public MovingObject, public Serializable
133 {
134 public:
135   FlyingPlatform(LispReader& reader);
136   FlyingPlatform(int x, int y);
137  
138   virtual void write(LispWriter& writer);
139   virtual void action(float frame_ratio);
140   virtual void draw(DrawingContext& context);
141
142   virtual void collision(const MovingObject& other, int);
143   void collision(void *p_c_object, int c_object, CollisionType type);
144
145   float get_vel_x() { return vel_x; }
146   float get_vel_y() { return vel_y; }
147
148   Physic physic;
149   enum { M_NORMAL, M_HELD } mode;
150
151  private:
152   std::vector<int> pos_x;
153   std::vector<int> pos_y;
154   float velocity;
155
156   float vel_x, vel_y;  // calculated based in the velocity
157
158   int point;
159   bool move;
160   unsigned int frame;
161 };
162
163 void load_object_gfx();
164
165 #endif 
166
167 /* Local Variables: */
168 /* mode:c++ */
169 /* End: */