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