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