0db6b6160da287968a79af53121113152ea4d88f
[supertux.git] / src / badguy.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 //  Copyright (C) 2004 Matthias Braun <matze@braunis.de>
7 //
8 //  This program is free software; you can redistribute it and/or
9 //  modify it under the terms of the GNU General Public License
10 //  as published by the Free Software Foundation; either version 2
11 //  of the License, or (at your option) any later version.
12 //
13 //  This program is distributed in the hope that it will be useful,
14 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
15 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 //  GNU General Public License for more details.
17 // 
18 //  You should have received a copy of the GNU General Public License
19 //  along with this program; if not, write to the Free Software
20 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 //  02111-1307, USA.
22
23 #ifndef SUPERTUX_BADGUY_H
24 #define SUPERTUX_BADGUY_H
25
26 #include "SDL.h"
27
28 #include "special/timer.h"
29 #include "video/surface.h"
30 #include "math/physic.h"
31 #include "special/sprite.h"
32 #include "app/defines.h"
33 #include "special/moving_object.h"
34 #include "collision.h"
35 #include "serializable.h"
36 #include "scene.h"
37
38 /* Timing constants (in ms): */
39
40 #define KICKING_TIME 200
41
42 /* Bad guy kinds: */
43 enum BadGuyKind {
44   BAD_MRICEBLOCK,
45   BAD_JUMPY,
46   BAD_MRBOMB,
47   BAD_BOMB,
48   BAD_STALACTITE,
49   BAD_FLAME,
50   BAD_FISH,
51   BAD_BOUNCINGSNOWBALL,
52   BAD_FLYINGSNOWBALL,
53   BAD_SPIKY,
54   BAD_SNOWBALL,
55   BAD_WINGLING,
56   BAD_WALKINGTREE,
57   NUM_BadGuyKinds,
58
59   BAD_INVALID
60 };
61
62 BadGuyKind  badguykind_from_string(const std::string& str);
63 std::string badguykind_to_string(BadGuyKind kind);
64 void load_badguy_gfx();
65 void free_badguy_gfx();
66
67 class Player;
68
69 /* Badguy type: */
70 class BadGuy : public MovingObject, public Serializable
71 {
72 public:
73   /* Enemy modes: */
74   enum BadGuyMode {
75     NORMAL=0,
76     FLAT,
77     KICK,
78     HELD,
79
80     JUMPY_JUMP,
81
82     BOMB_TICKING,
83     BOMB_EXPLODE,
84
85     STALACTITE_SHAKING,
86     STALACTITE_FALL,
87
88     FISH_WAIT,
89
90     FLY_UP,
91     FLY_DOWN,
92
93     BGM_BIG,
94     BGM_SMALL
95   };
96 public:
97   DyingType  dying;
98   BadGuyKind kind;
99   BadGuyMode mode;
100
101   /** If true the enemy will stay on its current platform, ie. if he
102       reaches the edge he will turn around and walk into the other
103       direction, if false the enemy will jump or walk of the edge */
104   bool stay_on_platform;
105
106   Direction dir;
107   Vector start_position;
108
109   Timer frozen_timer;  // gets frozen when a ice shot hits it
110
111 private:
112   bool removable;
113   bool seen;
114   int squishcount; /// number of times this enemy was squiched
115   Vector target; // Target that badguy is aiming for (wingling uses this)
116   Timer timer;
117   Physic physic;
118   float angle;
119
120   Sprite*   sprite_left;
121   Sprite*   sprite_right;
122
123   int animation_offset;
124
125 public:
126   BadGuy(BadGuyKind kind, float x, float y);
127   BadGuy(BadGuyKind kind, LispReader& reader);
128   virtual ~BadGuy();
129
130   virtual void write(LispWriter& writer);
131
132   virtual void action(float frame_ratio);
133   virtual void draw(DrawingContext& context);
134   virtual void collision(const MovingObject& other, int type);
135
136   void collision(void* p_c_object, int c_object,
137                  CollisionType type = COLLISION_NORMAL);
138
139   /** this functions tries to kill the badguy and lets him fall off the
140    * screen. Some badguys like the flame might ignore this.
141    */
142   void kill_me(int score);
143
144   /** initializes the badguy (when he appears on screen) */
145   void activate(Direction direction);  // should only be used by BadGuy's objects
146
147   Surface* get_image()
148     { return sprite_left->get_frame(0); }
149
150 private:
151   void init();
152   
153   void action_mriceblock(double frame_ratio);
154   void action_jumpy(double frame_ratio); 
155   void action_bomb(double frame_ratio);
156   void action_mrbomb(double frame_ratio);
157   void action_stalactite(double frame_ratio);
158   void action_flame(double frame_ratio);
159   void action_fish(double frame_ratio);
160   void action_bouncingsnowball(double frame_ratio);
161   void action_flyingsnowball(double frame_ratio);
162   void action_spiky(double frame_ratio);
163   void action_snowball(double frame_ratio);
164   void action_wingling(double frame_ratio);
165   void action_walkingtree(double frame_ratio);
166
167   /** handles falling down. disables gravity calculation when we're back on
168    * ground */
169   void fall();
170
171   /** Turn enemy into a bomb. To explode right way pass true */
172   void explode(bool right_away);
173
174   /** check if we're running left or right in a wall and eventually change
175    * direction
176    */
177   void check_horizontal_bump(bool checkcliff = false);
178   /** called when we're bumped from below with a block */
179   void bump();
180   /** called when a player jumped on the badguy from above */
181   void squish(Player* player);
182   /** squish ourself, give player score and set dying to DYING_SQICHED */
183   void squish_me(Player* player);
184   /** set image of the badguy */
185   void set_sprite(Sprite* left, Sprite* right);
186 };
187
188 #endif /*SUPERTUX_BADGUY_H*/
189
190 /* Local Variables: */
191 /* mode:c++ */
192 /* End: */
193