92bd0104ebf447c083ce4dd2738cabc68a122a82
[supertux.git] / src / badguy / badguy.h
1 #ifndef __BADGUY_H__
2 #define __BADGUY_H__
3
4 // moved them here to make it less typing when implementing new badguys
5 #include <math.h>
6 #include "timer.h"
7 #include "special/moving_object.h"
8 #include "special/sprite.h"
9 #include "math/physic.h"
10 #include "object/player.h"
11 #include "serializable.h"
12 #include "resources.h"
13 #include "sector.h"
14 #include "direction.h"
15 #include "object_factory.h"
16 #include "lisp/parser.h"
17 #include "lisp/lisp.h"
18 #include "lisp/writer.h"
19 #include "video/drawing_context.h"
20 #include "special/sprite_manager.h"
21
22 using namespace SuperTux;
23
24 class BadGuy : public MovingObject, public Serializable
25 {
26 public:
27   BadGuy();
28   ~BadGuy();
29
30   //virtual void action_activated(float elapsed_time);
31
32   virtual void draw(DrawingContext& context);
33   virtual void action(float elapsed_time);
34   virtual HitResponse collision(GameObject& other,
35       const CollisionHit& hit);
36
37   virtual void kill_fall();
38
39   Vector get_start_position() const
40   {
41     return start_position;
42   }
43   void set_start_position(const Vector& vec)
44   {
45     start_position = vec;
46   }
47
48 protected:
49   enum State {
50     STATE_INIT,
51     STATE_INACTIVE,
52     STATE_ACTIVE,
53     STATE_SQUISHED,
54     STATE_FALLING
55   };
56   
57   virtual HitResponse collision_player(Player& player,
58       const CollisionHit& hit);
59   virtual HitResponse collision_solid(GameObject& other,
60       const CollisionHit& hit);
61   virtual HitResponse collision_badguy(BadGuy& other,
62       const CollisionHit& hit);
63   
64   virtual bool collision_squished(Player& player);
65
66   virtual void active_action(float elapsed_time);
67   virtual void inactive_action(float elapsed_time);
68
69   /**
70    * called when the badguy has been activated. (As a side effect the dir
71    * variable might have been changed so that it faces towards the player.
72    */
73   virtual void activate();
74   /** caleed when the badguy has been deactivated */
75   virtual void deactivate();
76
77   void kill_squished(Player& player);
78
79   void set_state(State state);
80   State get_state() const
81   { return state; }
82     
83   /**
84    * returns a pointer to the player, try to avoid this function to avoid
85    * problems later when we have multiple players or no player in scripted
86    * sequence.
87    */
88   Player* get_player();
89   
90   Sprite* sprite;
91   Physic physic;
92
93   /// is the enemy activated
94   bool activated;
95   /**
96    * initial position of the enemy. Also the position where enemy respawns when
97    * after being deactivated.
98    */
99   bool is_offscreen();
100   
101   Vector start_position;
102
103   Direction dir;
104
105   int hitpoints;
106 private:
107   void try_activate();
108   
109   State state;
110   Timer2 state_timer;
111 };
112
113 #endif
114