68cdb57edbcdc9edadee20e2803287d6e1adcb3f
[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 "utils/lispwriter.h"
15 #include "utils/lispreader.h"
16 #include "video/drawing_context.h"
17 #include "special/sprite_manager.h"
18
19 using namespace SuperTux;
20
21 class BadGuy : public MovingObject, public Serializable
22 {
23 public:
24   BadGuy();
25   ~BadGuy();
26
27   //virtual void action_activated(float elapsed_time);
28
29   virtual void draw(DrawingContext& context);
30   virtual void action(float elapsed_time);
31   virtual HitResponse collision(GameObject& other,
32       const CollisionHit& hit);
33
34   virtual void kill_fall();
35
36 protected:
37   enum State {
38     STATE_INIT,
39     STATE_INACTIVE,
40     STATE_ACTIVE,
41     STATE_SQUISHED,
42     STATE_FALLING
43   };
44   
45   virtual HitResponse collision_player(Player& player,
46       const CollisionHit& hit);
47   virtual HitResponse collision_solid(GameObject& other,
48       const CollisionHit& hit);
49   virtual HitResponse collision_badguy(BadGuy& other,
50       const CollisionHit& hit);
51   
52   virtual bool collision_squished(Player& player);
53
54   virtual void active_action(float elapsed_time);
55   virtual void inactive_action(float elapsed_time);
56
57   /**
58    * called when the badguy has been activated. (As a side effect the dir
59    * variable might have been changed so that it faces towards the player.
60    */
61   virtual void activate();
62   /** caleed when the badguy has been deactivated */
63   virtual void deactivate();
64
65   void kill_squished(Player& player);
66
67   void set_state(State state);
68   State get_state() const
69   { return state; }
70     
71   /**
72    * returns a pointer to the player, try to avoid this function to avoid
73    * problems later when we have multiple players or no player in scripted
74    * sequence.
75    */
76   Player* get_player();
77   
78   Sprite* sprite;
79   Physic physic;
80
81   /// is the enemy activated
82   bool activated;
83   /**
84    * initial position of the enemy. Also the position where enemy respawns when
85    * after being deactivated.
86    */
87   bool is_offscreen();
88   
89   Vector start_position;
90
91   Direction dir;
92 private:
93   void try_activate();
94   
95   State state;
96   Timer2 state_timer;
97 };
98
99 #endif
100