renamed timer_type to Timer
[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 texture_type img_bsod_left[4];
25 extern texture_type img_bsod_right[4];
26 extern texture_type img_laptop_left[4];
27 extern texture_type img_money_left[2];
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   texture_type* texture_left;
103   texture_type* texture_right;
104   int animation_offset;
105   size_t animation_length;
106   float animation_speed;
107
108 public:
109   void init(float x, float y, BadGuyKind kind);
110
111   void action(float frame_ratio);
112   void draw();
113
114   void collision(void* p_c_object, int c_object,
115           CollisionType type = COLLISION_NORMAL);
116
117   /** this functions tries to kill the badguy and lets him fall off the
118    * screen. Some badguys like the flame might ignore this.
119    */
120   void kill_me();
121   
122 private:
123   void action_bsod(float frame_ratio);
124   void action_laptop(float frame_ratio);
125   void action_money(float frame_ratio); 
126   void action_bomb(float frame_ratio);
127   void action_mrbomb(float frame_ratio);
128   void action_stalactite(float frame_ratio);
129   void action_flame(float frame_ratio);
130   void action_fish(float frame_ratio);
131   void action_bouncingsnowball(float frame_ratio);
132   void action_flyingsnowball(float frame_ratio);
133   void action_spiky(float frame_ratio);
134   void action_snowball(float frame_ratio);
135
136   /** handles falling down. disables gravity calculation when we're back on
137    * ground */
138   void fall();
139   /** remove ourself from the list of badguys. WARNING! This function will
140    * invalidate all members. So don't do anything else with member after calling
141    * this.
142    */
143   void remove_me();  
144   /** let the player jump a bit (used when you hit a badguy) */
145   void make_player_jump(Player* player);
146   /** check if we're running left or right in a wall and eventually change
147    * direction
148    */
149   void check_horizontal_bump(bool checkcliff = false);
150   /** called when we're bumped from below with a block */
151   void bump();
152   /** called when a player jumped on the badguy from above */
153   void squish(Player* player);
154   /** squish ourself, give player score and set dying to DYING_SQICHED */
155   void squish_me(Player* player);
156   /** set image of the badguy */
157   void set_texture(texture_type* left, texture_type* right,
158         int animlength = 1, float animspeed = 1);
159 };
160
161 #endif /*SUPERTUX_BADGUY_H*/
162
163