- added new jumpy/money gfx
[supertux.git] / src / badguy.h
1 //
2 // Interface: badguy
3 //
4 // Description:
5 //
6 //
7 // Author: Tobias Glaesser <tobi.web@gmx.de> (C) 2003
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12
13 #ifndef SUPERTUX_BADGUY_H
14 #define SUPERTUX_BADGUY_H
15
16 #include "SDL.h"
17 #include "bitmask.h"
18 #include "type.h"
19 #include "timer.h"
20 #include "texture.h"
21 #include "physic.h"
22 #include "collision.h"
23
24 extern Surface* img_bsod_left[4];
25 extern Surface* img_bsod_right[4];
26 extern Surface* img_laptop_left[4];
27 extern Surface* img_jumpy_left_up;
28 extern Surface* img_jumpy_left_down;
29 extern Surface* img_jumpy_left_middle;
30
31 /* Enemy modes: */
32 enum {
33     NORMAL=0,
34     FLAT,
35     KICK,
36     HELD,
37
38     MONEY_JUMP,
39
40     BOMB_TICKING,
41     BOMB_EXPLODE,
42
43     STALACTITE_SHAKING,
44     STALACTITE_FALL,
45
46     FISH_WAIT,
47
48     FLY_UP,
49     FLY_DOWN
50 };
51
52 /* Bad guy kinds: */
53 enum BadGuyKind {
54   BAD_BSOD,
55   BAD_LAPTOP,
56   BAD_MONEY,
57   BAD_MRBOMB,
58   BAD_BOMB,
59   BAD_STALACTITE,
60   BAD_FLAME,
61   BAD_FISH,
62   BAD_BOUNCINGSNOWBALL,
63   BAD_FLYINGSNOWBALL,
64   BAD_SPIKY,
65   BAD_SNOWBALL
66 };
67
68 BadGuyKind  badguykind_from_string(const std::string& str);
69 std::string badguykind_to_string(BadGuyKind kind);
70 void load_badguy_gfx();
71 void free_badguy_gfx();
72
73 struct BadGuyData
74 {
75   BadGuyKind kind;
76   int x;
77   int y;
78
79   BadGuyData(BadGuyKind kind_, int x_, int y_) 
80     : kind(kind_), x(x_), y(y_) {}
81
82   BadGuyData()
83     : kind(BAD_BSOD), x(0), y(0) {}
84 };
85
86 class Player;
87
88 /* Badguy type: */
89 class BadGuy
90 {
91 public:
92   DyingType dying;
93   base_type base;
94   BadGuyKind kind;
95   int mode;
96   int dir;
97
98 private:
99   bool seen;
100   base_type old_base;
101   Timer timer;
102   Physic physic;
103
104   Surface** texture_left;
105   Surface** texture_right;
106   int animation_offset;
107   size_t animation_length;
108   float animation_speed;
109
110 public:
111   void init(float x, float y, BadGuyKind kind);
112
113   void action(float frame_ratio);
114   void draw();
115
116   void collision(void* p_c_object, int c_object,
117           CollisionType type = COLLISION_NORMAL);
118
119   /** this functions tries to kill the badguy and lets him fall off the
120    * screen. Some badguys like the flame might ignore this.
121    */
122   void kill_me();
123   
124 private:
125   void action_bsod(float frame_ratio);
126   void action_laptop(float frame_ratio);
127   void action_money(float frame_ratio); 
128   void action_bomb(float frame_ratio);
129   void action_mrbomb(float frame_ratio);
130   void action_stalactite(float frame_ratio);
131   void action_flame(float frame_ratio);
132   void action_fish(float frame_ratio);
133   void action_bouncingsnowball(float frame_ratio);
134   void action_flyingsnowball(float frame_ratio);
135   void action_spiky(float frame_ratio);
136   void action_snowball(float frame_ratio);
137
138   /** handles falling down. disables gravity calculation when we're back on
139    * ground */
140   void fall();
141   /** remove ourself from the list of badguys. WARNING! This function will
142    * invalidate all members. So don't do anything else with member after calling
143    * this.
144    */
145   void remove_me();  
146   /** let the player jump a bit (used when you hit a badguy) */
147   void make_player_jump(Player* player);
148   /** check if we're running left or right in a wall and eventually change
149    * direction
150    */
151   void check_horizontal_bump(bool checkcliff = false);
152   /** called when we're bumped from below with a block */
153   void bump();
154   /** called when a player jumped on the badguy from above */
155   void squish(Player* player);
156   /** squish ourself, give player score and set dying to DYING_SQICHED */
157   void squish_me(Player* player);
158   /** set image of the badguy */
159   void set_texture(Surface** left, Surface** right,
160         int animlength = 1, float animspeed = 1);
161 };
162
163 #endif /*SUPERTUX_BADGUY_H*/
164
165