When Esc was pressed the menu was not being shown in leveleditor (fixed).
[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 /* Enemy modes: */
40 enum {
41     NORMAL=0,
42     FLAT,
43     KICK,
44     HELD,
45
46     MONEY_JUMP,
47
48     BOMB_TICKING,
49     BOMB_EXPLODE,
50
51     STALACTITE_SHAKING,
52     STALACTITE_FALL,
53
54     FISH_WAIT,
55
56     FLY_UP,
57     FLY_DOWN
58 };
59
60 /* Bad guy kinds: */
61 enum BadGuyKind {
62   BAD_BSOD,
63   BAD_LAPTOP,
64   BAD_MONEY,
65   BAD_MRBOMB,
66   BAD_BOMB,
67   BAD_STALACTITE,
68   BAD_FLAME,
69   BAD_FISH,
70   BAD_BOUNCINGSNOWBALL,
71   BAD_FLYINGSNOWBALL,
72   BAD_SPIKY,
73   BAD_SNOWBALL
74 };
75
76 BadGuyKind  badguykind_from_string(const std::string& str);
77 std::string badguykind_to_string(BadGuyKind kind);
78 void load_badguy_gfx();
79 void free_badguy_gfx();
80
81 struct BadGuyData
82 {
83   BadGuyKind kind;
84   int x;
85   int y;
86
87   BadGuyData(BadGuyKind kind_, int x_, int y_) 
88     : kind(kind_), x(x_), y(y_) {}
89
90   BadGuyData()
91     : kind(BAD_BSOD), x(0), y(0) {}
92 };
93
94 class Player;
95
96 /* Badguy type: */
97 class BadGuy
98 {
99 public:
100   DyingType dying;
101   base_type base;
102   BadGuyKind kind;
103   int mode;
104   bool stay_on_platform;
105   int dir;
106
107 private:
108   bool seen;
109   base_type old_base;
110   Timer timer;
111   Physic physic;
112
113   Sprite*   sprite_left;
114   Sprite*   sprite_right;
115
116   int animation_offset;
117   size_t animation_length;
118   float animation_speed;
119
120 public:
121   void init(float x, float y, BadGuyKind kind);
122
123   void action(float frame_ratio);
124   void draw();
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();
133   
134 private:
135   void action_bsod(float frame_ratio);
136   void action_laptop(float frame_ratio);
137   void action_money(float frame_ratio); 
138   void action_bomb(float frame_ratio);
139   void action_mrbomb(float frame_ratio);
140   void action_stalactite(float frame_ratio);
141   void action_flame(float frame_ratio);
142   void action_fish(float frame_ratio);
143   void action_bouncingsnowball(float frame_ratio);
144   void action_flyingsnowball(float frame_ratio);
145   void action_spiky(float frame_ratio);
146   void action_snowball(float frame_ratio);
147
148   /** handles falling down. disables gravity calculation when we're back on
149    * ground */
150   void fall();
151   /** remove ourself from the list of badguys. WARNING! This function will
152    * invalidate all members. So don't do anything else with member after calling
153    * this.
154    */
155   void remove_me();  
156   /** let the player jump a bit (used when you hit a badguy) */
157   void make_player_jump(Player* player);
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         int animlength = 1, float animspeed = 1);
171 };
172
173 #endif /*SUPERTUX_BADGUY_H*/
174
175 /* Local Variables: */
176 /* mode:c++ */
177 /* End: */
178