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