Changed kill_me() in order to get the score has an argument.
[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 #include "defines.h"
28 #include "bitmask.h"
29 #include "type.h"
30 #include "timer.h"
31 #include "texture.h"
32 #include "physic.h"
33 #include "collision.h"
34 #include "sprite.h"
35
36 /* Bad guy kinds: */
37 enum BadGuyKind {
38   BAD_BSOD,
39   BAD_MRICEBLOCK,
40   BAD_JUMPY,
41   BAD_MRBOMB,
42   BAD_BOMB,
43   BAD_STALACTITE,
44   BAD_FLAME,
45   BAD_FISH,
46   BAD_BOUNCINGSNOWBALL,
47   BAD_FLYINGSNOWBALL,
48   BAD_SPIKY,
49   BAD_SNOWBALL
50 };
51
52 BadGuyKind  badguykind_from_string(const std::string& str);
53 std::string badguykind_to_string(BadGuyKind kind);
54 void load_badguy_gfx();
55 void free_badguy_gfx();
56
57 struct BadGuyData
58 {
59   BadGuyKind kind;
60   int x;
61   int y;
62   bool stay_on_platform;
63
64   BadGuyData(BadGuyKind kind_, int x_, int y_, bool stay_on_platform_) 
65     : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {}
66
67   BadGuyData()
68     : kind(BAD_BSOD), x(0), y(0), stay_on_platform(false) {}
69 };
70
71 class Player;
72
73 /* Badguy type: */
74 class BadGuy
75 {
76 public:
77   /* Enemy modes: */
78   enum BadGuyMode {
79     NORMAL=0,
80     FLAT,
81     KICK,
82     HELD,
83
84     JUMPY_JUMP,
85
86     BOMB_TICKING,
87     BOMB_EXPLODE,
88
89     STALACTITE_SHAKING,
90     STALACTITE_FALL,
91
92     FISH_WAIT,
93
94     FLY_UP,
95     FLY_DOWN
96   };
97 public:
98   DyingType  dying;
99   base_type  base;
100   BadGuyKind kind;
101   BadGuyMode mode;
102
103   /** If true the enemy will stay on its current platform, ie. if he
104       reaches the edge he will turn around and walk into the other
105       direction, if false the enemy will jump or walk of the edge */
106   bool stay_on_platform;
107
108   Direction dir;
109
110 private:
111   bool removable;
112   bool seen;
113   int squishcount; /// number of times this enemy was squiched
114   base_type old_base;
115   Timer timer;
116   Physic physic;
117
118   Sprite*   sprite_left;
119   Sprite*   sprite_right;
120
121   int animation_offset;
122
123 public:
124   BadGuy(float x, float y, BadGuyKind kind, bool stay_on_platform);
125
126   void action(float frame_ratio);
127   void draw();
128
129   void collision(void* p_c_object, int c_object,
130                  CollisionType type = COLLISION_NORMAL);
131
132   /** this functions tries to kill the badguy and lets him fall off the
133    * screen. Some badguys like the flame might ignore this.
134    */
135   void kill_me(int score);
136
137   /** remove ourself from the list of badguys. WARNING! This function will
138    * invalidate all members. So don't do anything else with member after calling
139    * this.
140    */
141   void remove_me();  
142   bool is_removable() const { return removable; }
143  
144 private:
145   void action_bsod(float frame_ratio);
146   void action_mriceblock(float frame_ratio);
147   void action_jumpy(float frame_ratio); 
148   void action_bomb(float frame_ratio);
149   void action_mrbomb(float frame_ratio);
150   void action_stalactite(float frame_ratio);
151   void action_flame(float frame_ratio);
152   void action_fish(float frame_ratio);
153   void action_bouncingsnowball(float frame_ratio);
154   void action_flyingsnowball(float frame_ratio);
155   void action_spiky(float frame_ratio);
156   void action_snowball(float frame_ratio);
157
158   /** handles falling down. disables gravity calculation when we're back on
159    * ground */
160   void fall();
161
162   /** let the player jump a bit (used when you hit a badguy) */
163   void make_player_jump(Player* player);
164
165   /** check if we're running left or right in a wall and eventually change
166    * direction
167    */
168   void check_horizontal_bump(bool checkcliff = false);
169   /** called when we're bumped from below with a block */
170   void bump();
171   /** called when a player jumped on the badguy from above */
172   void squish(Player* player);
173   /** squish ourself, give player score and set dying to DYING_SQICHED */
174   void squish_me(Player* player);
175   /** set image of the badguy */
176   void set_sprite(Sprite* left, Sprite* right);
177 };
178
179 #endif /*SUPERTUX_BADGUY_H*/
180
181 /* Local Variables: */
182 /* mode:c++ */
183 /* End: */
184