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