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