home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Tennis / Ball.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-23  |  2.3 KB  |  70 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    Ball.h
  7. //----------------------------------------------------------------------------------------------
  8.  
  9. #ifndef __TENNISBALL_H
  10. #define __TENNISBALL_H
  11.  
  12. //----------------------------------------------------------------------------------------------
  13. // Include files
  14. //----------------------------------------------------------------------------------------------
  15.  
  16. #include "directdraw.h"
  17. #include "observer.h"
  18.  
  19. //----------------------------------------------------------------------------------------------
  20. // Defined constants
  21. //----------------------------------------------------------------------------------------------
  22.  
  23. #define GROUND_ACCELERATION        0.1f
  24. #define GROUND_FRICTION            1.5f
  25. #define BALL_SIZE                5
  26. #define OWNER_SERVICE            0
  27. #define UPWARD_BOUNCE_FORCE        3
  28.  
  29. //----------------------------------------------------------------------------------------------
  30. // CTennisBall: Represents the tennis ball
  31. //----------------------------------------------------------------------------------------------
  32.  
  33. class CTennisBall : public CSubject {
  34. public:
  35.                 CTennisBall() { 
  36.                     px = py = pz = vx = vy = vz = 0;
  37.                 }
  38.  
  39.                 ~CTennisBall() {
  40.                 }
  41.  
  42.     void        Update();
  43.     void        SetPosition(float x, float y, float z) { px = x; py = y; pz = z; }
  44.     void        SetVelocity(float x, float y, float z) { vx = x; vy = y; vz = -z; }
  45.     void        Paint(LPDDS lpdds);
  46.     void        GetBoundingRect(RECT * lpRect);
  47.     int            GetHeight() { return (int)pz; }
  48.     void        GetPosition(POINT & pt) { pt.x = (int)px; pt.y = (int)py; }
  49.     void        SetOwner(int BallOwner) { owner = BallOwner; }
  50.     int            GetOwner() { return owner; }    
  51.     void        GetBouncePosition(POINT & pt) { pt = BouncePosition; } // used by AI
  52.     void        BounceBall(float x, float y);
  53.  
  54. protected:
  55.     
  56.     void        ApplyVelocity();
  57.     void        ApplyGroundForce();
  58.     void        InterpolateToBouncePosition(POINT & pt); 
  59.  
  60. protected:
  61.     int            owner;
  62.     float        px, py, pz;
  63.     float        vx, vy, vz;    
  64.     POINT        BouncePosition;
  65. };
  66.  
  67. //----------------------------------------------------------------------------------------------
  68. #endif // __TENNISBALL_H
  69.  
  70.