fix tiles being 1 pixel off their correct position
[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 "timer.h"
28 #include "screen/texture.h"
29 #include "physic.h"
30 #include "sprite.h"
31 #include "moving_object.h"
32 #include "collision.h"
33 #include "serializable.h"
34
35 /* Bad guy kinds: */
36 enum BadGuyKind {
37   BAD_MRICEBLOCK,
38   BAD_JUMPY,
39   BAD_MRBOMB,
40   BAD_BOMB,
41   BAD_STALACTITE,
42   BAD_FLAME,
43   BAD_FISH,
44   BAD_BOUNCINGSNOWBALL,
45   BAD_FLYINGSNOWBALL,
46   BAD_SPIKY,
47   BAD_SNOWBALL,
48   BAD_WINGLING,
49   BAD_WALKINGTREE,
50   NUM_BadGuyKinds
51 };
52
53 BadGuyKind  badguykind_from_string(const std::string& str);
54 std::string badguykind_to_string(BadGuyKind kind);
55 void load_badguy_gfx();
56 void free_badguy_gfx();
57
58 class Player;
59
60 /* Badguy type: */
61 class BadGuy : public MovingObject, public Serializable
62 {
63 public:
64   /* Enemy modes: */
65   enum BadGuyMode {
66     NORMAL=0,
67     FLAT,
68     KICK,
69     HELD,
70
71     JUMPY_JUMP,
72
73     BOMB_TICKING,
74     BOMB_EXPLODE,
75
76     STALACTITE_SHAKING,
77     STALACTITE_FALL,
78
79     FISH_WAIT,
80
81     FLY_UP,
82     FLY_DOWN,
83
84     BGM_BIG,
85     BGM_SMALL
86   };
87 public:
88   DyingType  dying;
89   BadGuyKind kind;
90   BadGuyMode mode;
91
92   /** If true the enemy will stay on its current platform, ie. if he
93       reaches the edge he will turn around and walk into the other
94       direction, if false the enemy will jump or walk of the edge */
95   bool stay_on_platform;
96
97   Direction dir;
98
99   Timer frozen_timer;  // gets frozen when a ice shot hits it
100
101 private:
102   bool removable;
103   bool seen;
104   int squishcount; /// number of times this enemy was squiched
105   Vector target; // Target that badguy is aiming for (wingling uses this)
106   Timer timer;
107   Vector start_position;
108   Physic physic;
109   float angle;
110
111   Sprite*   sprite_left;
112   Sprite*   sprite_right;
113
114   int animation_offset;
115
116 public:
117   BadGuy(BadGuyKind kind, float x, float y);
118   BadGuy(BadGuyKind kind, LispReader& reader);
119   virtual ~BadGuy();
120
121   virtual void write(LispWriter& writer);
122
123   virtual void action(float frame_ratio);
124   virtual void draw(DrawingContext& context);
125   virtual void collision(const MovingObject& other, int type);
126
127   void collision(void* p_c_object, int c_object,
128                  CollisionType type = COLLISION_NORMAL);
129
130   /** this functions tries to kill the badguy and lets him fall off the
131    * screen. Some badguys like the flame might ignore this.
132    */
133   void kill_me(int score);
134
135 private:
136   void init();
137   
138   void action_mriceblock(double frame_ratio);
139   void action_jumpy(double frame_ratio); 
140   void action_bomb(double frame_ratio);
141   void action_mrbomb(double frame_ratio);
142   void action_stalactite(double frame_ratio);
143   void action_flame(double frame_ratio);
144   void action_fish(double frame_ratio);
145   void action_bouncingsnowball(double frame_ratio);
146   void action_flyingsnowball(double frame_ratio);
147   void action_spiky(double frame_ratio);
148   void action_snowball(double frame_ratio);
149   void action_wingling(double frame_ratio);
150   void action_walkingtree(double frame_ratio);
151
152   /** initializes the badguy (when he appears on screen) */
153   void activate(Direction direction);
154
155   /** handles falling down. disables gravity calculation when we're back on
156    * ground */
157   void fall();
158
159   /** let the player jump a bit (used when you hit a badguy) */
160   void make_player_jump(Player* player);
161
162   /** Turn enemy into a bomb. To explode right way pass true */
163   void explode(bool right_away);
164
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 };
178
179 #endif /*SUPERTUX_BADGUY_H*/
180
181 /* Local Variables: */
182 /* mode:c++ */
183 /* End: */
184