home *** CD-ROM | disk | FTP | other *** search
/ Programming a Multiplayer FPS in DirectX / Programming a Multiplayer FPS in DirectX (Companion CD).iso / Source / Chapter 12 / Game / PlayerObject.h < prev   
Encoding:
C/C++ Source or Header  |  2004-10-01  |  3.5 KB  |  100 lines

  1. //-----------------------------------------------------------------------------
  2. // Derived scene object to provide the functionality for a player.
  3. //
  4. // Programming a Multiplayer First Person Shooter in DirectX
  5. // Copyright (c) 2004 Vaughan Young
  6. //-----------------------------------------------------------------------------
  7. #ifndef PLAYER_OBJECT_H
  8. #define PLAYER_OBJECT_H
  9.  
  10. //-----------------------------------------------------------------------------
  11. // Player Object Type Define
  12. //-----------------------------------------------------------------------------
  13. #define TYPE_PLAYER_OBJECT 3
  14.  
  15. //-----------------------------------------------------------------------------
  16. // Animation Callback Data Structure
  17. //-----------------------------------------------------------------------------
  18. struct AnimationCallbackData
  19. {
  20.     char foot; // Identifies which foot caused the callback.
  21. };
  22.  
  23. //-----------------------------------------------------------------------------
  24. // Player Object Class
  25. //-----------------------------------------------------------------------------
  26. class PlayerObject : public AnimatedObject
  27. {
  28. public:
  29.     PlayerObject( PlayerInfo *player, Script *script, unsigned long type = TYPE_PLAYER_OBJECT );
  30.     virtual ~PlayerObject();
  31.  
  32.     virtual void Update( float elapsed, bool addVelocity = true );
  33.     virtual void Render( D3DXMATRIX *world = NULL );
  34.  
  35.     virtual void CollisionOccurred( SceneObject *object, unsigned long collisionStamp );
  36.  
  37.     void MouseLook( float x, float y, bool reset = false );
  38.  
  39.     void Hurt( float damage, PlayerObject *attacker );
  40.     void Kill();
  41.  
  42.     DPNID GetID();
  43.     char *GetName();
  44.  
  45.     void SetHealth( float health );
  46.     float GetHealth();
  47.     void SetDying( bool dying );
  48.     bool GetDying();
  49.  
  50.     void SetIsViewing( bool isViewing );
  51.  
  52.     void SetFrags( unsigned long frags );
  53.     unsigned long GetFrags();
  54.     void SetDeaths( unsigned long deaths );
  55.     unsigned long GetDeaths();
  56.  
  57.     void SetDrive( float drive );
  58.     float GetDrive();
  59.     void SetStrafe( float strafe );
  60.     float GetStrafe();
  61.     void SetFire( bool fire );
  62.     bool GetFire();
  63.  
  64.     void SetViewTilt( float tilt );
  65.     float GetViewTilt();
  66.     D3DXVECTOR3 GetEyePoint();
  67.  
  68. private:
  69.     virtual HRESULT CALLBACK HandleCallback( THIS_ UINT Track, LPVOID pCallbackData );
  70.  
  71. private:
  72.     enum{ ANIM_IDLE, ANIM_DEATH, ANIM_FORWARDS, ANIM_BACKWARDS, ANIM_LEFT, ANIM_RIGHT };
  73.  
  74.     DPNID m_dpnid; // DirectPlay ID of the player.
  75.     char *m_name; // Name of the player.
  76.     float m_health; // Player's health.
  77.     bool m_dying; // Indicates if the player is dying.
  78.     bool m_isViewing; // Inidicates if this player is the viewing player.
  79.  
  80.     unsigned long m_frags; // Player's frag count.
  81.     unsigned long m_deaths; // Player's death tally.
  82.  
  83.     float m_drive; // Player's drive direction.
  84.     float m_strafe; // Player's strafe direction.
  85.     bool m_fire; // Indicates if the player is firing their weapon.
  86.  
  87.     D3DXVECTOR3 m_viewPoint; // Translation of the player's view point in model space.
  88.     float m_viewTilt; // Player's view tilt (i.e. rotation around the x axis).
  89.  
  90.     float m_viewSmoothing; // Amount of smoothing applied to view movements (local player only).
  91.     float m_viewSensitivity; // Sensitivity of view movements (local player only).
  92.  
  93.     AnimationCallbackData m_callbackData[2]; // Data used for the foot step call back.
  94.     RayIntersectionResult m_stepResult; // Used to determine if a foot is touching the ground.
  95.  
  96.     AudioPath3D *m_leftStepAudioPath; // Audio path for playing the left foot step sound.
  97.     AudioPath3D *m_rightStepAudioPath; // Audio path for playing the right foot step sound.
  98. };
  99.  
  100. #endif