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