Added flame fish.
[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 "defines.h"
33 #include "special/moving_object.h"
34 #include "collision.h"
35 #include "serializable.h"
36 #include "scene.h"
37
38 using namespace SuperTux;
39
40 /* Timing constants (in ms): */
41
42 #define KICKING_TIME 200
43
44 /* Bad guy kinds: */
45 enum BadGuyKind {
46   BAD_MRICEBLOCK,
47   BAD_JUMPY,
48   BAD_MRBOMB,
49   BAD_BOMB,
50   BAD_STALACTITE,
51   BAD_FLAME,
52   BAD_FISH,
53   BAD_FLAMEFISH,
54   BAD_BOUNCINGSNOWBALL,
55   BAD_FLYINGSNOWBALL,
56   BAD_SPIKY,
57   BAD_SNOWBALL,
58   BAD_WINGLING,
59   BAD_WALKINGTREE,
60   NUM_BadGuyKinds,
61
62   BAD_INVALID
63 };
64
65 BadGuyKind  badguykind_from_string(const std::string& str);
66 std::string badguykind_to_string(BadGuyKind kind);
67 void load_badguy_gfx();
68 void free_badguy_gfx();
69
70 class Player;
71
72 /* Badguy type: */
73 class BadGuy : public MovingObject, public Serializable
74 {
75 public:
76   /* Enemy modes: */
77   enum BadGuyMode {
78     NORMAL=0,
79     FLAT,
80     KICK,
81     HELD,
82
83     JUMPY_JUMP,
84
85     BOMB_TICKING,
86     BOMB_EXPLODE,
87
88     STALACTITE_SHAKING,
89     STALACTITE_FALL,
90
91     FISH_WAIT,
92
93     FLY_UP,
94     FLY_DOWN,
95
96     BGM_BIG,
97     BGM_SMALL
98   };
99 public:
100   DyingType  dying;
101   BadGuyKind kind;
102   BadGuyMode mode;
103
104   /** If true the enemy will stay on its current platform, ie. if he
105       reaches the edge he will turn around and walk into the other
106       direction, if false the enemy will jump or walk of the edge */
107   bool stay_on_platform;
108
109   Direction dir;
110   Vector start_position;
111
112   Timer frozen_timer;  // gets frozen when a ice shot hits it
113
114 private:
115   bool removable;
116   bool seen;
117   int squishcount; /// number of times this enemy was squiched
118   Vector target; // Target that badguy is aiming for (wingling uses this)
119   Timer timer;
120   Physic physic;
121   float angle;
122
123   Sprite*   sprite_left;
124   Sprite*   sprite_right;
125
126   int animation_offset;
127
128 public:
129   BadGuy(BadGuyKind kind, float x, float y);
130   BadGuy(BadGuyKind kind, LispReader& reader);
131   virtual ~BadGuy();
132
133   virtual void write(LispWriter& writer);
134
135   virtual void action(float frame_ratio);
136   virtual void draw(DrawingContext& context);
137   virtual void collision(const MovingObject& other, int type);
138
139   void collision(void* p_c_object, int c_object,
140                  CollisionType type = COLLISION_NORMAL);
141
142   /** this functions tries to kill the badguy and lets him fall off the
143    * screen. Some badguys like the flame might ignore this.
144    */
145   void kill_me(int score);
146
147   /** initializes the badguy (when he appears on screen) */
148   void activate(Direction direction);  // should only be used by BadGuy's objects
149
150   Surface* get_image()
151     { return sprite_left->get_frame(0); }
152
153 private:
154   void init();
155   
156   void action_mriceblock(double frame_ratio);
157   void action_jumpy(double frame_ratio); 
158   void action_bomb(double frame_ratio);
159   void action_mrbomb(double frame_ratio);
160   void action_stalactite(double frame_ratio);
161   void action_flame(double frame_ratio);
162   void action_fish(double frame_ratio);
163   void action_bouncingsnowball(double frame_ratio);
164   void action_flyingsnowball(double frame_ratio);
165   void action_spiky(double frame_ratio);
166   void action_snowball(double frame_ratio);
167   void action_wingling(double frame_ratio);
168   void action_walkingtree(double frame_ratio);
169
170   /** handles falling down. disables gravity calculation when we're back on
171    * ground */
172   void fall();
173
174   /** Turn enemy into a bomb. To explode right way pass true */
175   void explode(bool right_away);
176
177   /** check if we're running left or right in a wall and eventually change
178    * direction
179    */
180   void check_horizontal_bump(bool checkcliff = false);
181   /** called when we're bumped from below with a block */
182   void bump();
183   /** called when a player jumped on the badguy from above */
184   void squish(Player* player);
185   /** squish ourself, give player score and set dying to DYING_SQICHED */
186   void squish_me(Player* player);
187   /** set image of the badguy */
188   void set_sprite(Sprite* left, Sprite* right);
189 };
190
191 #endif /*SUPERTUX_BADGUY_H*/
192
193 /* Local Variables: */
194 /* mode:c++ */
195 /* End: */
196