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