home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / graphics / directx / duel / gameproc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  6.8 KB  |  215 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1997 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File:        gameproc.h
  6.  *  Content:    game processing info. include file
  7.  *
  8.  *
  9.  ***************************************************************************/
  10. #define IDIRECTPLAY2_OR_GREATER
  11. #include <ddraw.h>
  12. #include <dplay.h>
  13. #include <dsound.h>
  14. #include "sfx.h"
  15. #include "duel.h"
  16.  
  17. // align on single byte boundaries
  18. // this is a stop-gap measure until the structures can be re-arranged.
  19. #pragma pack(1)
  20.  
  21. #define     MAX_SHIP_X     (MAX_SCREEN_X - 32)
  22. #define     MAX_SHIP_Y     (MAX_SCREEN_Y - 32)
  23. #define     MAX_SHIP_FRAME 40
  24. #define     MAX_BULLET_X    (MAX_SCREEN_X - 3)
  25. #define     MAX_BULLET_Y    (MAX_SCREEN_Y - 3)
  26. #define     MAX_BULLET_FRAME 400
  27.  
  28. #define        NUM_SHIP_TYPES 4
  29.  
  30. #define        DEF_SHOW_DELAY     (2000)
  31. #define        MAX_BUFFER_SIZE       256
  32.  
  33. #define     UPDATE_INTERVAL     40      // interval between position updates in milliseconds (25 FPS)
  34. #define     SYNC_INTERVAL       1000    // synchronize once every second
  35. #define     HIDE_TIMEOUT        5000    // time for which a ship is disabled after a hit
  36.  
  37. /*
  38.  * keyboard commands
  39.  */
  40.  
  41. #define KEY_STOP        0x00000001l
  42. #define KEY_DOWN        0x00000002l
  43. #define KEY_LEFT        0x00000004l
  44. #define KEY_RIGHT       0x00000008l
  45. #define KEY_UP          0x00000010l
  46. #define KEY_FIRE        0x00000020l
  47. #define KEY_ENGINEOFF   0x00000040l
  48.  
  49. /*
  50.  * Offsets for the bullet bitmap
  51.  */
  52.  
  53. #define     BULLET_X    304
  54. #define     BULLET_Y    0
  55.  
  56. typedef struct _frag
  57. {
  58.     double        dPosX;
  59.     double        dPosY;
  60.     LPDIRECTDRAWSURFACE surf;
  61.     RECT        src;
  62.     double      dVelX;
  63.     double      dVelY;
  64.     BOOL        valid;
  65. } FRAG, *LPFRAG;
  66.  
  67. /*
  68.  * structures
  69.  */
  70.  
  71. typedef struct _SHIP
  72. {
  73.     double                dPosX, dPosY;                // ship x and y position
  74.     double                dBulletPosX, dBulletPosY;    // bullet x and y position
  75.     DWORD                dwBulletFrame;                // bullet frame
  76.     char                 cFrame;                        // current ship frame
  77.     BYTE                byType;                        // ship type 
  78.     BOOL                bEnable;                    // is this ship active?
  79.     BOOL                bBulletEnable;                // Is there an active bullet?
  80.  
  81.     double                dVelX, dVelY;                // ship x and y velocity (pixels/millisecond)
  82.     double                dBulletVelX, dBulletVelY;    // bullet x and y velocity (pixels/millisecond)
  83.     DWORD                dwScore;                    // current score
  84.     DWORD               dwLastTick;                    // most recent time stamp
  85.     BOOL                bIgnore;                    // flag used to synchronize ship explosions
  86.     int                    iCountDown;                 // enable time-out            
  87.     DWORD               dwFrameCount;               // number of frames since beginning of time
  88.     /* DSOUND members */
  89.     LPDIRECTSOUNDBUFFER   lpDirectSoundBuffer  [MAX_SOUNDS]; // SoundBuffer interface
  90.     LPDIRECTSOUND3DBUFFER lpDirectSound3DBuffer[MAX_SOUNDS]; // 3D interface (to same buffer)  
  91.     DWORD                 dwKeys;                            // the keyboard state
  92.     BOOL                  bEngineRunning;                    // These BOOLs keep track of the ship's
  93.     BOOL                  bMoving;                           //   last condition so we can play sounds
  94.     BOOL                  bBounced;                          //   when they change
  95.     BOOL                  bBlockHit;
  96.     BOOL                  bDeath;
  97.     BOOL                  bFiring;
  98.     /* DSOUND members */
  99.  
  100. } SHIP, *LPSHIP;
  101.  
  102. typedef struct _BLOCKS
  103. {
  104.     BYTE        bits[30][5];
  105. } BLOCKS, *LPBLOCKS;
  106.  
  107. //----------------------------------------------------------
  108. // communication packet structures
  109. //----------------------------------------------------------
  110. #define MSG_HOST        0x11    // message containing field layout, sent by host
  111. #define MSG_BLOCKHIT    0x22    // block hit message
  112. #define MSG_SHIPHIT     0x33    // ship hit message
  113. #define MSG_ADDBLOCK    0x44    // add block message
  114. #define MSG_CONTROL     0x55    // game keys message
  115. #define MSG_SYNC        0x66    // synchronization message containing the rendezvous location
  116.  
  117. typedef struct _GENERICMSG
  118. {
  119.     BYTE        byType;
  120. } GENERICMSG, *LPGENERICMSG;
  121.  
  122. typedef struct _HOSTMSG
  123. {
  124.     BYTE        byType;
  125.     BLOCKS      Blocks;
  126. } HOSTMSG, *LPHOSTMSG;
  127.  
  128. typedef struct _BLOCKHITMSG
  129. {
  130.     BYTE        byType;
  131.     BYTE        byRow;
  132.     BYTE        byCol;
  133.     BYTE        byMask;
  134. } BLOCKHITMSG, *LPBLOCKHITMSG;
  135.  
  136. typedef struct _SHIPHITMSG
  137. {
  138.     BYTE        byType;
  139.     DPID        Id;
  140. } SHIPHITMSG, *LPSHIPHITMSG;
  141.  
  142. typedef struct _ADDBLOCKMSG
  143. {
  144.     BYTE        byType;
  145.     BYTE        byX;
  146.     BYTE        byY;
  147. } ADDBLOCKMSG, *LPADDBLOCKMSG;
  148.  
  149. typedef struct _CONTROLMSG
  150. {
  151.     BYTE        byType;
  152.     BYTE        byState;
  153. } CONTROLMSG, *LPCONTROLMSG;
  154.  
  155. typedef struct _SYNCMSG
  156. {
  157.     BYTE        byType;
  158.     BYTE        byShipType;     // this is needed only when sends are unreliable
  159.     char        cFrame;
  160.     double      dPosX;
  161.     double      dPosY;
  162. } SYNCMSG, *LPSYNCMSG;
  163.  
  164. /*
  165.  * Prototypes
  166.  */
  167. void    LaunchGame(void);
  168. void    ExitGame(void);
  169. HRESULT InitOurShip(void);
  170.  
  171. HRESULT InitLocalSoundData(void);
  172. void InitPlayerLocalSoundData(LPSHIP lpShip, BOOL bOurShip);
  173. BOOL WINAPI SetPlayerLocalSoundDataCB(DPID dpId, DWORD dwPlayerType, LPCDPNAME lpName, 
  174.                                          DWORD dwFlags, LPVOID lpContext);
  175.  
  176. void ReleaseLocalData(void);
  177. void ReleasePlayerLocalSoundData(LPSHIP lpShip);
  178. BOOL WINAPI ReleasePlayerLocalDataCB(DPID dpId, DWORD dwPlayerType, LPCDPNAME lpName,
  179.                                      DWORD dwFlags, LPVOID lpContext);
  180.  
  181. void    UpdateState(LPSHIP lpShip, DWORD dwControls);
  182. void    SendSync(LPSHIP lpShip);
  183. void    UpdateDisplayStatus(LPSHIP lpShip);
  184. void    UpdatePosition( DPID dpId, LPSHIP ship );
  185. BOOL    IsHit( int x, int y );
  186. void    InitField(void);
  187. BOOL    setBlock( int x, int y );
  188. void    AddFrag(LPSHIP lpShip, int offX, int offY);
  189. void    UpdateFragment(int i);
  190. void    DestroyShip( LPSHIP lpShip);
  191. void    DestroyGame( void );
  192. BOOL    UpdateFrame( void );
  193.  
  194. void    ProcessSoundFlags(LPSHIP lpShip);
  195. BOOL WINAPI RenderPlayerCB(DPID dpId, DWORD dwPlayerType, LPCDPNAME lpName, 
  196.                          DWORD dwFlags, LPVOID lpContext);
  197. BOOL    DrawScreen( void );
  198. BOOL    DrawScore( void );
  199. void    DrawShip( LPSHIP lpShip );
  200. void    DrawBlock( int x, int y );
  201. void    DrawBullet( LPSHIP lpShip );
  202. void    DrawFragments( void );
  203. void    DisplayFrameRate( void );
  204.  
  205. void    GetConnection(void);
  206. HRESULT ReceiveMessages( void );
  207. void    DoSystemMessage( LPDPMSG_GENERIC lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo );
  208. void    DoApplicationMessage( LPGENERICMSG lpMsg, DWORD dwMsgSize, DPID idFrom, DPID idTo );
  209. void    SendGameMessage( LPGENERICMSG lpMsg, DPID idTo );
  210. void    CleanupComm(void);
  211.  
  212.  
  213. // restore default alignment
  214. #pragma pack()
  215.