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