home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / directx2 / sdk / samples / duel / duel.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-28  |  7.4 KB  |  350 lines

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995-1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File:       duel.h
  6.  *  Content:    main include file
  7.  *
  8.  *
  9.  ***************************************************************************/
  10.  
  11. #ifndef DUEL_INCLUDED
  12. #define DUEL_INCLUDED
  13.  
  14. #define INITGUID
  15. #define WIN32_LEAN_AND_MEAN
  16. #include <windows.h>
  17. #include <windowsx.h>
  18. #include <mmsystem.h>
  19. #include <ddraw.h>
  20. #include <dplay.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <io.h>
  24. #include "resource.h"
  25. #include "ddutil.h"
  26.  
  27. #define DEF_SHOW_DELAY     (2000)
  28. #define MAX_BUFFER_SIZE    256
  29.  
  30. /*
  31.  * keyboard commands
  32.  */
  33.  
  34. #define KEY_STOP   0x00000001l
  35. #define KEY_DOWN   0x00000002l
  36. #define KEY_LEFT   0x00000004l
  37. #define KEY_RIGHT  0x00000008l
  38. #define KEY_UP     0x00000010l
  39. #define KEY_FIRE   0x00000020l
  40. #define KEY_THROW  0x00000040l
  41. #define KEY_SHIELD 0x00000080l
  42.  
  43. // program states
  44. enum
  45. {
  46.     PS_SPLASH,
  47.     PS_ACTIVE,
  48.     PS_BEGINREST,
  49.     PS_REST
  50. };
  51.  
  52. #define     MAX_SCREEN_X    639
  53. #define     MAX_SCREEN_Y    479
  54. #define     MAX_SHIP_X     (MAX_SCREEN_X - 32)
  55. #define     MAX_SHIP_Y     (MAX_SCREEN_Y - 32)
  56. #define     MAX_SHIP_FRAME 40
  57. #define     MAX_BULLET_X    (MAX_SCREEN_X - 3)
  58. #define     MAX_BULLET_Y    (MAX_SCREEN_Y - 3)
  59. #define     MAX_BULLET_FRAME 400
  60.  
  61.  
  62. // Offsets for the bullet bitmap
  63. #define     BULLET_X    304
  64. #define     BULLET_Y    0
  65.  
  66.  
  67. /*
  68.  * structures
  69.  */
  70.  
  71. typedef struct _GLOBALSHIP
  72. {
  73.     BOOL                enable;     // is this ship active?
  74.     double              posx, posy; // x and y position
  75.     double              velx, vely; // x and y velocity (pixels/millisecond)
  76.     double              frame;      // current frame
  77.     BOOL                benable;    // Is there an active bullet?
  78.     double              bposx, bposy;  // bullet x and y position
  79.     double              bvelx, bvely; // bullet x and y velocity (pixels/millisecond)
  80.     double              bframe;     // bullet frame
  81.     int                 score;      // current score
  82.     DWORD               lastTick;   // time since last frame
  83.     DWORD               timeStamp;  // time received
  84. } GLOBALSHIP, *LPGLOBALSHIP;
  85.  
  86. typedef struct _BLOCKS
  87. {
  88.     BYTE        bits[30][5];
  89. } BLOCKS, *LPBLOCKS;
  90.  
  91. //----------------------------------------------------------
  92. // communication packet structures
  93. //----------------------------------------------------------
  94. #define MSG_UPDATE      0x11
  95. #define MSG_HEREIAM     0x22
  96. #define MSG_INIT        0x33
  97. #define MSG_BLOCKHIT    0x44
  98. #define MSG_SHIPHIT     0x55
  99. #define MSG_ADDBLOCK    0x66
  100.  
  101. typedef struct _UPDATEMSG
  102. {
  103.     BYTE        MsgCode;
  104.     BYTE        WhoIAm;
  105.     GLOBALSHIP  Ship;
  106. } UPDATEMSG, *LPUPDATEMSG;
  107.  
  108. typedef struct _HEREIAMMSG
  109. {
  110.     BYTE        MsgCode;
  111.     DWORD       ID;
  112. } HEREIAMMSG, *LPHEREIAMMSG;
  113.  
  114. typedef struct _INITMSG
  115. {
  116.     BYTE        MsgCode;
  117.     BYTE        YouAre;
  118.     BLOCKS      Blocks;
  119. } INITMSG, *LPINITMSG;
  120.  
  121. typedef struct _BLOCKHITMSG
  122. {
  123.     BYTE        MsgCode;
  124.     BYTE        row;
  125.     BYTE        col;
  126.     BYTE        mask;
  127. } BLOCKHITMSG, *LPBLOCKHITMSG;
  128.  
  129. typedef struct _SHIPHITMSG
  130. {
  131.     BYTE        MsgCode;
  132.     BYTE        You;
  133. } SHIPHITMSG, *LPSHIPHITMSG;
  134.  
  135. typedef struct _frag
  136. {
  137.     double      posx;
  138.     double      posy;
  139.     LPDIRECTDRAWSURFACE surf;
  140.     RECT        src;
  141.     double      velx;
  142.     double      vely;
  143.     BOOL        valid;
  144. } FRAG, *LPFRAG;
  145.  
  146. typedef struct _ADDBLOCKMSG
  147. {
  148.     BYTE        MsgCode;
  149.     BYTE        x;
  150.     BYTE        y;
  151. } ADDBLOCKMSG, *LPADDBLOCKMSG;
  152.  
  153. double      Dirx[40] =
  154. {
  155.     0.000000,
  156.     0.156434,
  157.     0.309017,
  158.     0.453991,
  159.     0.587785,
  160.     0.707107,
  161.     0.809017,
  162.     0.891007,
  163.     0.951057,
  164.     0.987688,
  165.     1.000000,
  166.     0.987688,
  167.     0.951057,
  168.     0.891007,
  169.     0.809017,
  170.     0.707107,
  171.     0.587785,
  172.     0.453990,
  173.     0.309017,
  174.     0.156434,
  175.     0.000000,
  176.     -0.156435,
  177.     -0.309017,
  178.     -0.453991,
  179.     -0.587785,
  180.     -0.707107,
  181.     -0.809017,
  182.     -0.891007,
  183.     -0.951057,
  184.     -0.987688,
  185.     -1.000000,
  186.     -0.987688,
  187.     -0.951056,
  188.     -0.891006,
  189.     -0.809017,
  190.     -0.707107,
  191.     -0.587785,
  192.     -0.453990,
  193.     -0.309017,
  194.     -0.156434
  195. };
  196.  
  197. double      Diry[40] =
  198. {
  199.     -1.000000,
  200.     -0.987688,
  201.     -0.951057,
  202.     -0.891007,
  203.     -0.809017,
  204.     -0.707107,
  205.     -0.587785,
  206.     -0.453990,
  207.     -0.309017,
  208.     -0.156434,
  209.     0.000000,
  210.     0.156434,
  211.     0.309017,
  212.     0.453991,
  213.     0.587785,
  214.     0.707107,
  215.     0.809017,
  216.     0.891007,
  217.     0.951057,
  218.     0.987688,
  219.     1.000000,
  220.     0.987688,
  221.     0.951057,
  222.     0.891006,
  223.     0.809017,
  224.     0.707107,
  225.     0.587785,
  226.     0.453990,
  227.     0.309017,
  228.     0.156434,
  229.     0.000000,
  230.     -0.156435,
  231.     -0.309017,
  232.     -0.453991,
  233.     -0.587785,
  234.     -0.707107,
  235.     -0.809017,
  236.     -0.891007,
  237.     -0.951057,
  238.     -0.987688
  239. };
  240.  
  241. double HomeX[16] =
  242. {
  243.     16.0,
  244.     624.0,
  245.     16.0,
  246.     624.0,
  247.     320.0,
  248.     16.0,
  249.     624.0,
  250.     320.0,
  251.     160.0,
  252.     480.0,
  253.     16.0,
  254.     624.0,
  255.     16.0,
  256.     160.0,
  257.     480.0,
  258.     624.0,
  259. };
  260.  
  261. double HomeY[16] =
  262. {
  263.     16.0,
  264.     16.0,
  265.     464.0,
  266.     464.0,
  267.     16.0,
  268.     240.0,
  269.     240.0,
  270.     464.0,
  271.     16.0,
  272.     464.0,
  273.     360.0,
  274.     120.0,
  275.     120.0,
  276.     464.0,
  277.     16.0,
  278.     360.0
  279. };
  280.  
  281. double HomeFrame[16] =
  282. {
  283.     15.0,
  284.     25.0,
  285.     5.0,
  286.     35.0,
  287.     20.0,
  288.     10.0,
  289.     30.0,
  290.     0.0,
  291.     20.0,
  292.     0.0,
  293.     10.0,
  294.     30.0,
  295.     10.0,
  296.     0.0,
  297.     20.0,
  298.     30.0
  299. };
  300.  
  301. /*
  302.  * fn prototypes
  303.  */
  304. void    DestroyGame( void );
  305. BOOL    InitializeGame( void );
  306. void    UpdateFrame( void );
  307. BOOL    CleanupAndExit( int err );
  308. BOOL    RestoreSurfaces( void );
  309. void    initShip( LPGLOBALSHIP ship);
  310. void    initLevel( int level );
  311. int     randInt( int low, int high );
  312. double  randDouble( double low, double high );
  313. void    bltScore( char *num, int x, int y );
  314. void    DisplayFrameRate( void );
  315. void    bltSplash( LPRECT );
  316. void    EraseScreen( void );
  317. void    FlipScreen( void );
  318. void    DisplayLevel( void );
  319. void    DrawScreen( void );
  320. void    DrawShip( int i );
  321. void    DrawBlock( int x, int y );
  322. void    bltObject( int x, int y, LPDIRECTDRAWSURFACE surf, LPRECT src, DWORD flags );
  323. BOOL    setBlock( int x, int y );
  324. void    ReadKey(void);
  325. void    UpdatePosition( LPGLOBALSHIP ship );
  326. void    DrawBullet( int i );
  327. BOOL    IsHit( int x, int y );
  328. BOOL    RemoteCreate(GUID pGuid, LPSTR FullName, LPSTR NickName);
  329. int     GetProvider(void);
  330. int     CreateGame(void);
  331. int     GetGame(void);
  332. BOOL CALLBACK DlgProcChooseProvider(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  333. BOOL CALLBACK DlgProcQCreate (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  334. BOOL CALLBACK DlgProcSelSession (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
  335. BOOL FAR PASCAL EnumSP(LPGUID lpGuid, LPSTR lpDesc, DWORD dwJamorVersion,
  336.                        DWORD dwMinorVersion, LPVOID lpv);
  337. BOOL FAR PASCAL EnumSession(LPDPSESSIONDESC lpDPGameDesc, LPVOID pContext, 
  338.                             LPDWORD lpdwTimeOut, DWORD dwFlags);
  339. void    EvaluateMessage( DWORD len );
  340. void    ReceiveGameMessages( void );
  341. void    InitGame(void);
  342. void    SendGameMessage( BYTE msg, DWORD to, BYTE row, BYTE col, BYTE mask );
  343. void    DrawScore( void );
  344. void    AddFrag(int which, int offX, int offY);
  345. void    DrawFragments( void );
  346. void    UpdateFragment(int i);
  347. void    DestroyShip( int which );
  348. #endif
  349.  
  350.