home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / xenon / includes / actor.h next >
Encoding:
C/C++ Source or Header  |  2000-09-09  |  6.0 KB  |  270 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CActor
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    None
  10. //
  11. // Derived:    CShip
  12. //            CAlien
  13. //            CBullet
  14. //            CPickup
  15. //
  16. //-------------------------------------------------------------
  17.  
  18. #ifndef _INCLUDE_ACTOR_H
  19. #define _INCLUDE_ACTOR_H
  20.  
  21. #include "gamesystem.h"
  22. #include "actorinfo.h"
  23.  
  24. class CShip;
  25. class CScene;
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. struct Controls
  30. {
  31.     bool left;                // true if left control held
  32.     bool right;                // true if right control held
  33.     bool up;                // true if up control held
  34.     bool down;                // true if down control held
  35.     bool fire;                // true if fire control held
  36.     bool firePressed;        // true if fire control has just been pressed
  37.     bool divePressed;        // true if dive control has just been pressed
  38.     bool reversePressed;    // true if reverse control has just been pressed
  39.     gsKeyCode key;            // latest key press
  40. };
  41.  
  42. //-------------------------------------------------------------
  43. // Actor Info for creating actors
  44. /*
  45. struct ActorInfo
  46. {
  47.     ActorType m_type;            // type of actor
  48.     char *m_filename;            // file containing sprite frames
  49.     int m_hotspot_x;            // hotspot position (i.e. offset to centre)
  50.     int m_hotspot_y;
  51.     float m_anim_rate;            // animation rate (in frames per second)
  52.     int m_initial_shield;        // initial shield value
  53.     int m_kill_bonus;            // score bonus for killing actor
  54. };
  55. */
  56. //-------------------------------------------------------------
  57.  
  58. typedef enum {
  59.     ANIMATE_LOOP,                // cycle repeatedly through frames
  60.     ANIMATE_ONESHOT,            // cycle once then flag as finished
  61. } AnimationMode;
  62.  
  63. //-------------------------------------------------------------
  64.  
  65. const float ACTOR_HIT_TIME = 0.1f;    // time in seconds for hit to register
  66.  
  67. const int INFINITE_SHIELD = -1;
  68.  
  69. //-------------------------------------------------------------
  70.  
  71. class CActor
  72. {
  73.     private:
  74.  
  75.         CActor *m_owner;            // owner
  76.         bool m_is_active;
  77.         gsCTimer m_hit_timer;        // for animation of hit
  78.  
  79.     protected:
  80.  
  81.         CScene *m_scene;            // scene containing this actor
  82.  
  83.         gsCVector m_position;        // relative to map
  84.         gsCVector m_velocity;
  85.         int m_shield;                // shield strength
  86.         gsCSprite m_sprite;
  87.         gsCTiledImage *m_image;
  88.         gsCTimer m_timer;            // for animation
  89.  
  90.         bool m_is_on_screen;
  91.  
  92.         bool m_is_hit;
  93.  
  94.         float m_score_multiplier;
  95.  
  96.     public:
  97.  
  98.         CActor();
  99.         virtual ~CActor();
  100.  
  101.         virtual const ActorInfo& getActorInfo() = 0;
  102.  
  103.         virtual bool activate();
  104.         virtual void kill();
  105.         virtual void explode();
  106.         virtual bool update(Controls *controls = 0) = 0;
  107.         virtual bool draw();
  108.         virtual void registerHit(int energy,CActor *hitter);
  109.  
  110.         virtual void onKilled();
  111.         virtual void onLeavingScreen();
  112.         virtual void onCollisionWithActor(CActor *actor);
  113.         virtual void onCollisionWithMap(gsCMap *map,int hits);
  114.         virtual void postProcessCollision();
  115.  
  116.         bool isActive();
  117.         bool isOnScreen();
  118.         bool isHit();
  119.  
  120.         gsCVector getPosition();
  121.         gsCVector getVelocity();
  122.         CActor *getOwner();
  123.         int getShield();
  124.         int getDirection(int num_dir);
  125.         virtual gsCRect getCollisionRect();
  126.  
  127.         void setPosition(const gsCVector& position);
  128.         void setVelocity(const gsCVector& velocity);
  129.         void setOwner(CActor *owner);
  130.         void setScene(CScene *scene);
  131.         void setShield(int shield);
  132.  
  133.         bool animate(AnimationMode mode);
  134.         bool animate(AnimationMode mode,int first_frame,int num_frames);
  135.  
  136.         void increaseScoreMultiplier(float amount);
  137. };
  138.  
  139. //-------------------------------------------------------------
  140.  
  141. inline bool CActor::isActive()
  142. {
  143.     return m_is_active;
  144. }
  145.  
  146. //-------------------------------------------------------------
  147.  
  148. inline gsCVector CActor::getPosition()
  149. {
  150.     return m_position;
  151. }
  152.  
  153. //-------------------------------------------------------------
  154.  
  155. inline gsCVector CActor::getVelocity()
  156. {
  157.     return m_velocity;
  158. }
  159.  
  160. //-------------------------------------------------------------
  161.  
  162. inline void CActor::setPosition(const gsCVector& position)
  163. {
  164.     m_position = position;
  165. }
  166.  
  167. //-------------------------------------------------------------
  168.  
  169. inline void CActor::setVelocity(const gsCVector& velocity)
  170. {
  171.     m_velocity = velocity;
  172. }
  173.  
  174. //-------------------------------------------------------------
  175.  
  176. inline bool CActor::isOnScreen()
  177. {
  178.     return m_is_on_screen;
  179. }
  180.  
  181. //-------------------------------------------------------------
  182.  
  183. inline bool CActor::isHit()
  184. {
  185.     return m_is_hit;
  186. }
  187.  
  188. //-------------------------------------------------------------
  189. // Overridable
  190.  
  191. inline gsCRect CActor::getCollisionRect()
  192. {
  193.     return m_sprite.getRect();
  194. }
  195.  
  196. //-------------------------------------------------------------
  197. // Overridable
  198.  
  199. inline void CActor::onLeavingScreen()
  200. {
  201. }
  202.  
  203. //-------------------------------------------------------------
  204. // Overridable
  205.  
  206. inline void CActor::onCollisionWithActor(CActor *actor)
  207. {
  208. }
  209.  
  210. //-------------------------------------------------------------
  211.  
  212. inline void CActor::onCollisionWithMap(gsCMap *map,int hits)
  213. {
  214. }
  215.  
  216. //-------------------------------------------------------------
  217. // Overridable
  218.  
  219. inline void CActor::postProcessCollision()
  220. {
  221. }
  222.  
  223. //-------------------------------------------------------------
  224.  
  225. inline void CActor::setOwner(CActor *owner)
  226. {
  227.     m_owner = owner;
  228. }
  229.  
  230. //-------------------------------------------------------------
  231.  
  232. inline void CActor::setScene(CScene *scene)
  233. {
  234.     m_scene = scene;
  235. }
  236.  
  237. //-------------------------------------------------------------
  238.  
  239. inline CActor *CActor::getOwner()
  240. {
  241.     return m_owner;
  242. }
  243.  
  244. //-------------------------------------------------------------
  245.  
  246. inline void CActor::setShield(int shield)
  247. {
  248.     m_shield = shield;
  249. }
  250.  
  251. //-------------------------------------------------------------
  252.  
  253. inline int CActor::getShield()
  254. {
  255.     return m_shield;
  256. }
  257.  
  258. //-------------------------------------------------------------
  259.  
  260. inline void CActor::increaseScoreMultiplier(float amount)
  261. {
  262.     m_score_multiplier += amount;
  263. }
  264.  
  265. //-------------------------------------------------------------
  266.  
  267. #endif
  268.  
  269.  
  270.