home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / demo2 / actor.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-13  |  5.8 KB  |  263 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 postProcessCollision();
  114.  
  115.         bool isActive();
  116.         bool isOnScreen();
  117.         bool isHit();
  118.  
  119.         gsCVector getPosition();
  120.         gsCVector getVelocity();
  121.         CActor *getOwner();
  122.         int getShield();
  123.         int getDirection(int num_dir);
  124.         virtual gsCRect getCollisionRect();
  125.  
  126.         void setPosition(const gsCVector& position);
  127.         void setVelocity(const gsCVector& velocity);
  128.         void setOwner(CActor *owner);
  129.         void setScene(CScene *scene);
  130.         void setShield(int shield);
  131.  
  132.         bool animate(AnimationMode mode);
  133.         bool animate(AnimationMode mode,int first_frame,int num_frames);
  134.  
  135.         void increaseScoreMultiplier(float amount);
  136. };
  137.  
  138. //-------------------------------------------------------------
  139.  
  140. inline bool CActor::isActive()
  141. {
  142.     return m_is_active;
  143. }
  144.  
  145. //-------------------------------------------------------------
  146.  
  147. inline gsCVector CActor::getPosition()
  148. {
  149.     return m_position;
  150. }
  151.  
  152. //-------------------------------------------------------------
  153.  
  154. inline gsCVector CActor::getVelocity()
  155. {
  156.     return m_velocity;
  157. }
  158.  
  159. //-------------------------------------------------------------
  160.  
  161. inline void CActor::setPosition(const gsCVector& position)
  162. {
  163.     m_position = position;
  164. }
  165.  
  166. //-------------------------------------------------------------
  167.  
  168. inline void CActor::setVelocity(const gsCVector& velocity)
  169. {
  170.     m_velocity = velocity;
  171. }
  172.  
  173. //-------------------------------------------------------------
  174.  
  175. inline bool CActor::isOnScreen()
  176. {
  177.     return m_is_on_screen;
  178. }
  179.  
  180. //-------------------------------------------------------------
  181.  
  182. inline bool CActor::isHit()
  183. {
  184.     return m_is_hit;
  185. }
  186.  
  187. //-------------------------------------------------------------
  188. // Overridable
  189.  
  190. inline gsCRect CActor::getCollisionRect()
  191. {
  192.     return m_sprite.getRect();
  193. }
  194.  
  195. //-------------------------------------------------------------
  196. // Overridable
  197.  
  198. inline void CActor::onLeavingScreen()
  199. {
  200. }
  201.  
  202. //-------------------------------------------------------------
  203. // Overridable
  204.  
  205. inline void CActor::onCollisionWithActor(CActor *actor)
  206. {
  207. }
  208.  
  209. //-------------------------------------------------------------
  210. // Overridable
  211.  
  212. inline void CActor::postProcessCollision()
  213. {
  214. }
  215.  
  216. //-------------------------------------------------------------
  217.  
  218. inline void CActor::setOwner(CActor *owner)
  219. {
  220.     m_owner = owner;
  221. }
  222.  
  223. //-------------------------------------------------------------
  224.  
  225. inline void CActor::setScene(CScene *scene)
  226. {
  227.     m_scene = scene;
  228. }
  229.  
  230. //-------------------------------------------------------------
  231.  
  232. inline CActor *CActor::getOwner()
  233. {
  234.     return m_owner;
  235. }
  236.  
  237. //-------------------------------------------------------------
  238.  
  239. inline void CActor::setShield(int shield)
  240. {
  241.     m_shield = shield;
  242. }
  243.  
  244. //-------------------------------------------------------------
  245.  
  246. inline int CActor::getShield()
  247. {
  248.     return m_shield;
  249. }
  250.  
  251. //-------------------------------------------------------------
  252.  
  253. inline void CActor::increaseScoreMultiplier(float amount)
  254. {
  255.     m_score_multiplier += amount;
  256. }
  257.  
  258. //-------------------------------------------------------------
  259.  
  260. #endif
  261.  
  262.  
  263.