home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / sdk / netds / rpc / mazelord / mazewnd.c < prev    next >
C/C++ Source or Header  |  1996-01-07  |  29KB  |  718 lines

  1. /***********************************************************************
  2. File:   MazeWnd.c
  3.  
  4.  
  5. Abstract:
  6.  
  7.     This module contains the windows procedure responsible for drawing the 3-d
  8.     maze.
  9.  
  10.  
  11. Contents:
  12.  
  13.     StretchBitmaps() --Prestretches loaded pictures to bitmap size.
  14.     KillSelf() -- Takes care of hassles associated with dying
  15.     MazeWndProc() -- Main entrypoint for drawing 3-d maze
  16.  
  17. ************************************************************************/
  18.  
  19. #include "winmaze.h"
  20. #include "mazproto.h"
  21. #include "net.h"
  22. #include <mmsystem.h>
  23.  
  24.  
  25. /*=====================================================================
  26. Function:   StretchBitmaps()
  27.  
  28. Inputs:     none
  29.  
  30. Outputs:    none
  31.  
  32. Abstract:
  33.     StretchBitmaps() will take care of stretching the appropriate bitmaps
  34.     to their correct dimensions.
  35. ======================================================================*/
  36.  
  37. void StretchBitmaps(
  38.     void
  39.     )
  40. {
  41.     float xSize,ySize,xOrg,yOrg,x,y,z;
  42.     int iPicNum,iRely,iFacing;
  43.     HDC hDC,hSrcDC,hDestDC,hMemDC;
  44.     FullPicType FAR *fptTrav;
  45.     HBITMAP hBM;
  46.     HCURSOR hCursor;
  47.  
  48.     //
  49.     // Set the cursor to an hourglass since this takes time...
  50.     //
  51.     hCursor = SetCursor(LoadCursor((HINSTANCE)NULL,IDC_WAIT));
  52.  
  53.     hDC = GetDC(hWndMaze);
  54.     hSrcDC = CreateCompatibleDC(hDC);
  55.     hDestDC = CreateCompatibleDC(hDC);
  56.     hMemDC = CreateCompatibleDC(hDestDC);
  57.  
  58.     GetClientRect(hWndMaze,(LPRECT) &rMaze);
  59.  
  60.     //
  61.     // Set x and y to logical panel origin.
  62.     //
  63.     y = (float) (-PANEL_HEIGHT/2);
  64.     x = (float) (-PANEL_WIDTH/2);
  65.  
  66.     //
  67.     // Loop through all of the pictures we know about.
  68.     //
  69.     for(iPicNum=0;iPicNum < NUM_PICS;iPicNum++) {
  70.  
  71.         AddPic(iPicNum);
  72.  
  73.         //
  74.         // Find the fptPic entry for Picture # iPicNum
  75.         //
  76.         fptTrav = &fptPic;
  77.         while (fptTrav->next != NULL) {
  78.             fptTrav = fptTrav->next;
  79.             if (fptTrav->iPicNum == iPicNum) {
  80.                 break;
  81.                 }
  82.             }
  83.         //
  84.         // Loop from closest to us to furthest away from us for stretching
  85.         //
  86.         for (iRely = 0;iRely < MAX_DRAW_DIST;iRely++) {
  87.             PreStretch[iPicNum][iRely].next = NULL;
  88.             PreStretch[iPicNum][iRely].iPicNum = iPicNum;
  89.  
  90.             //
  91.             // We need to stretch once per facing
  92.             //
  93.             for (iFacing=0;iFacing<4;iFacing++) {
  94.  
  95. #if ( _ALPHA_ == 1 ) 
  96.                 z = (float) (iRely ? iRely*PANEL_WIDTH:PANEL_WIDTH/4);
  97. #else
  98.                 z = (float) (iRely-1)*PANEL_WIDTH; //- PANEL_WIDTH/2;
  99. #endif
  100.  
  101.                 xSize = MC_TO_SC(fptTrav->P[iFacing].xSize,z);
  102.                 ySize = MC_TO_SC(fptTrav->P[iFacing].ySize,z);
  103.                 xOrg = MC_TO_SC(fptTrav->P[iFacing].xOrg,z);
  104.                 yOrg = MC_TO_SC(fptTrav->P[iFacing].yOrg,z);
  105.  
  106.                 PreStretch[iPicNum][iRely].P[iFacing].xSize = (int) xSize;
  107.                 PreStretch[iPicNum][iRely].P[iFacing].ySize = (int) ySize;
  108.                 PreStretch[iPicNum][iRely].P[iFacing].xOrg = (int) xOrg;
  109.                 PreStretch[iPicNum][iRely].P[iFacing].yOrg = (int) yOrg;
  110.                 PreStretch[iPicNum][iRely].M[iFacing].xSize = (int) xSize;
  111.                 PreStretch[iPicNum][iRely].M[iFacing].ySize = (int) ySize;
  112.                 PreStretch[iPicNum][iRely].M[iFacing].xOrg = (int) xOrg;
  113.                 PreStretch[iPicNum][iRely].M[iFacing].yOrg = (int) yOrg;
  114.  
  115.                 //
  116.                 // If we're supposed to prestretch this bitmap, do so
  117.                 //
  118.                 if (((iPicNum == PIC_DRONE)&&bDronePrestretch)||
  119.                      (bPlayerPrestretch)
  120.                    ) {
  121.                     //
  122.                     // If there were already stretched bitmaps, delete them.
  123.                     //
  124.                     if (PreStretch[iPicNum][iRely].P[iFacing].hBitmap !=
  125.                         (HBITMAP)NULL) {
  126.                         DeleteObject(PreStretch[iPicNum][iRely].P[iFacing].hBitmap);
  127.                         }
  128.                     if (PreStretch[iPicNum][iRely].M[iFacing].hBitmap !=
  129.                         (HBITMAP)NULL) {
  130.                         DeleteObject(PreStretch[iPicNum][iRely].M[iFacing].hBitmap);
  131.                         }
  132.  
  133.                     //
  134.                     // Stretch the bitmap
  135.                     //
  136.                     hBM = CreateCompatibleBitmap(hDC,(int)xSize,(int)ySize);
  137.  
  138.                     SelectObject(hSrcDC,fptTrav->P[iFacing].hBitmap);
  139.                     SelectObject(hDestDC,hBM);
  140.                     StretchBlt(hDestDC,0,0,(int)xSize,(int)ySize,
  141.                                hSrcDC,0,0,
  142.                                fptTrav->P[iFacing].xSize,
  143.                                fptTrav->P[iFacing].ySize,
  144.                                SRCCOPY);
  145.                     PreStretch[iPicNum][iRely].P[iFacing].hBitmap = hBM;
  146.  
  147.                     //
  148.                     // Now stretch the mask
  149.                     //
  150.                     hBM = CreateCompatibleBitmap(hMemDC,(int)xSize,(int)ySize);
  151.  
  152.                     SelectObject(hSrcDC,fptTrav->M[iFacing].hBitmap);
  153.                     SelectObject(hMemDC,hBM);
  154.                     StretchBlt(hMemDC,0,0,(int)xSize,(int)ySize,
  155.                                hSrcDC,0,0,
  156.                                fptTrav->M[iFacing].xSize,
  157.                                fptTrav->M[iFacing].ySize,
  158.                                SRCCOPY);
  159.                     PreStretch[iPicNum][iRely].M[iFacing].hBitmap = hBM;
  160.  
  161.                     }
  162.                 else {
  163.                     //
  164.                     // If we're not stretching bitmaps, we should delete
  165.                     // any we don't need anymore to free memory.
  166.                     //
  167.                     if (PreStretch[iPicNum][iRely].P[iFacing].hBitmap !=
  168.                         (HBITMAP)NULL) {
  169.                         DeleteObject(PreStretch[iPicNum][iRely].P[iFacing].hBitmap);
  170.                         }
  171.                     if (PreStretch[iPicNum][iRely].M[iFacing].hBitmap !=
  172.                         (HBITMAP)NULL) {
  173.                         DeleteObject(PreStretch[iPicNum][iRely].M[iFacing].hBitmap);
  174.                         }
  175.                     PreStretch[iPicNum][iRely].P[iFacing].hBitmap = (HBITMAP)NULL;
  176.                     PreStretch[iPicNum][iRely].M[iFacing].hBitmap = (HBITMAP)NULL;
  177.                     }
  178.                 }
  179.             }
  180.         }
  181.  
  182.     DeleteDC(hMemDC);
  183.     DeleteDC(hSrcDC);
  184.     DeleteDC(hDestDC);
  185.     ReleaseDC(hWndMaze,hDC);
  186.  
  187.     //
  188.     // Return the cursor.
  189.     //
  190.     SetCursor(hCursor);
  191.     return;
  192. }
  193.  
  194.  
  195.  
  196. /*=====================================================================
  197. Function:   KillSelf()
  198.  
  199. Inputs:     none
  200.  
  201. Outputs:    none
  202.  
  203. Abstract:
  204.     KillSelf() takes care of playing the teleport sound, teleporting us back to
  205.     the sanctuary, and notifying the network that we've died...
  206. ======================================================================*/
  207.  
  208. void KillSelf(void)
  209. {
  210.     RECT rScratch;
  211.  
  212.     if (!sndPlaySound("tele.wav",SND_ASYNC)) {
  213.         MessageBeep((UINT) -1);
  214.         MessageBeep((UINT) -1);
  215.         MessageBeep((UINT) -1);
  216.         }
  217.     //
  218.     // these are from initmaze.c
  219.     //
  220.  
  221.     if (bDemoMode) {
  222.         ptSelf.Pos.ix = RandRange(5*X_CELLS_PER_SUBGRID,8*X_CELLS_PER_SUBGRID-1);
  223.         ptSelf.Pos.iy = RandRange(7*Y_CELLS_PER_SUBGRID,8*Y_CELLS_PER_SUBGRID-1);
  224.         PrintTextLine(GetStringRes(IDS_TELEPORT));
  225.         }
  226.     else {
  227.         ptSelf.Pos.ix = 6*X_CELLS_PER_SUBGRID+1;
  228.         ptSelf.Pos.iy = 7*Y_CELLS_PER_SUBGRID+1;
  229.         }
  230.     ptSelf.Pos.Facing = NORTH;
  231.     ptLastPos = ptSelf.Pos;
  232.  
  233.     bSelfInSanct=TRUE;
  234.     PrintTextLine(GetStringRes(IDS_SANCTUARY));
  235.  
  236.     if (!SendNetMessage(0,0,&ptSelf.Pos,NP_MOVETO)) {
  237.         MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"MazeWndProc",
  238.                MB_ICONEXCLAMATION|MB_APPLMODAL);
  239.         }
  240.     if (bBitmapDraw) {
  241.         PostMessage(hWndMaze,WM_COMMAND,IDM_REDRAW,(DWORD)NULL);
  242.         }
  243.     else {
  244.         InvalidateRect(hWndMaze,&rMaze,TRUE);
  245.         }
  246.  
  247.     GetClientRect(hWndTopView,&rScratch);
  248.     InvalidateRect(hWndTopView,&rScratch,TRUE);
  249.  
  250.     PostMessage(hWndScore,WM_COMMAND,WC_UPDATESCORE,ptSelf.ulID);
  251.     PostMessage(hWndScore,WM_COMMAND,WC_UPDATEDIRECTION,0);
  252.     iTimesKilled++;
  253.  
  254.  
  255.     return;
  256. }
  257.  
  258.  
  259.  
  260.  
  261. /*=====================================================================
  262. Function:   MazeWndProc()
  263.  
  264. Inputs:     Standard windows procedure inputs
  265.  
  266. Outputs:    returns success/failure
  267.  
  268. Abstract:
  269.     MazeWndProc is the process responsible for drawing the maze 3-d view
  270.     perspective window. It has the corresponding controls.
  271. ======================================================================*/
  272.  
  273. LONG FAR PASCAL MazeWndProc(
  274.     HWND hWnd,
  275.     UINT Message,
  276.     WPARAM wParam,
  277.     LPARAM lParam
  278.     )
  279. {
  280.     HDC     hDC,hBMDC;
  281.     int     nRc=0,i,ix,iy;
  282.     BYTE bSquare1,bSquare2,Facing;
  283.     PlayerType FAR *ptTrav;
  284.     BOOL bKilled,bNewSelfInSanct,bHitSomething;
  285.     PositionType ptPos;
  286.     char cBuff[132];
  287.     LPRECT rTemp,rPtr;
  288.     HGLOBAL hMem;
  289.  
  290.  
  291.     switch (Message) {
  292.  
  293.         case WM_CREATE:
  294.             if (uiTimer != (UINT) NULL) {
  295.                 KillTimer((HWND)NULL,uiTimer);
  296.                 }
  297.  
  298.             if ((iNumDrones)&&(iDroneSpeed != 0)) {
  299.                 if (! (uiTimer = SetTimer((HWND) NULL,0,ONE_SECOND/iDroneSpeed,MoveDrone))) {
  300.                     MessageBox(NULL,GetStringRes(IDS_CRETMRFAIL),
  301.         GetStringRes2(IDS_FATALERR), MB_ICONEXCLAMATION|MB_APPLMODAL);
  302.                     PostMessage(hWndMain,WM_CLOSE,0,0);
  303.                     }
  304.                 }
  305.  
  306.             InitDrones();
  307.  
  308.             if ((bBitmapDraw)&&(((HWND)hMaze3DBM) == ((HWND)NULL))) {
  309.                 hDC = GetDC(hWnd);
  310.                 GetClientRect(hWnd,&rMaze);
  311.                 hMazeDC = CreateCompatibleDC(hDC);
  312.                 hMaze3DBM = CreateCompatibleBitmap(hDC,rMaze.right-rMaze.left,
  313.                                                   rMaze.bottom-rMaze.top);
  314.                 SelectObject(hMazeDC,hMaze3DBM);
  315.                 ReleaseDC(hWnd,hDC);
  316.                 }
  317.             else {
  318.                 hMazeDC = GetDC(hWnd);
  319.                 }
  320.  
  321.             break;
  322.  
  323.         case WM_COMMAND:
  324.             switch(wParam) {
  325.  
  326.                 case IDM_DRAWPLAYERS:
  327.                     DrawPlayers(hMazeDC,&ptPlayers,NULL);
  328.                     break;
  329.  
  330.                 case IDM_DRAWDRONES:
  331.                     DrawPlayers(hMazeDC,&ptDrones,(LPRECT) lParam);
  332. //                    if (lParam != (LPARAM) NULL) {
  333. //                        hMem = (HGLOBAL) GlobalHandle(SELECTOROF( (LPRECT) lParam));
  334. //                        GlobalUnlock(hMem);
  335. //                        GlobalFree(hMem);
  336. //                    }
  337.                     break;
  338.  
  339.                 case IDM_REDRAW:
  340.                     hDC = GetDC(hWnd);
  341.                     if (lParam != (LPARAM)NULL) {
  342.                         rTemp = (LPRECT)lParam;
  343.                         }
  344.                     else {
  345.                         hMem = GlobalAlloc(GHND,sizeof(RECT));
  346.                         rTemp = (LPRECT) GlobalLock(hMem);
  347.                         if (rTemp == NULL) {
  348.                             MessageBox((HWND)NULL,GetStringRes(IDS_MALLOCFAIL),"MazeWnd",
  349.                                        MB_ICONEXCLAMATION|MB_APPLMODAL);
  350.                             PostMessage(hWndMain,WM_CLOSE,0,0);
  351.                             }
  352.                         GetClientRect(hWnd,rTemp);
  353.                         }
  354.  
  355.                     DrawMaze(hMazeDC,rTemp);
  356.  
  357.                     if (bBitmapDraw) {
  358.                         BitBlt(hDC,rTemp->left, rTemp->top,
  359.                                RECTWIDTH(*rTemp),
  360.                                RECTDEPTH(*rTemp),
  361.                                hMazeDC,rTemp->left,rTemp->top,SRCCOPY);
  362.                         }
  363.  
  364.                     ReleaseDC(hWnd,hDC);
  365.                     hMem = (HGLOBAL) GlobalHandle(SELECTOROF( rTemp));
  366.                     GlobalUnlock(hMem);
  367.                     GlobalFree(hMem);
  368.  
  369.                 default:
  370.                     break;
  371.                 }
  372.  
  373.             break;
  374.  
  375.         case WM_KEYDOWN:
  376.             bSquare1 = bMaze[ptSelf.Pos.ix][ptSelf.Pos.iy];
  377.  
  378.             if ((! GamePaused)&&(GameStarted)) {
  379.  
  380.                 switch(wParam) {
  381.                     //
  382.                     // Space = Fire straight ahead
  383.                     //
  384.                     case VK_SPACE:
  385.                         if (InSanctuary(&ptSelf.Pos)) {
  386.                             //
  387.                             //If we shoot while in the Sanctuary, we get chastized.
  388.                             //
  389.                             sprintf(cBuff,GetStringRes(IDS_NOVIOLENCE));
  390.                             PrintTextLine(cBuff);
  391.                             sndPlaySound("sanctu.wav",SND_SYNC);
  392.                             }
  393.                         else {
  394.                             //
  395.                             // Otherwise, fine, shoot.
  396.                             //
  397.                             hDC=GetDC(hWndMaze);
  398.                             hBMDC = CreateCompatibleDC(hDC);
  399.                             SelectObject(hBMDC,hShotBM[1]);
  400.                             BitBlt(hDC,(rMaze.left+rMaze.right)/2 - 12,
  401.                                     (rMaze.top+rMaze.bottom)/2 - 12,
  402.                                     24,24,
  403.                                     hBMDC,0,0,SRCINVERT);
  404.  
  405.                             if (!sndPlaySound("laser.wav",SND_ASYNC)) {
  406.                                 MessageBeep((UINT)-1);
  407.                                 }
  408.  
  409.                             //
  410.                             // Tell everyone else we're firing */
  411.                             //
  412.                             if (!SendNetMessage(0,0,&ptSelf.Pos,NP_SHOTFIRED)) {
  413.                                 MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"WndProc",
  414.                                            MB_ICONEXCLAMATION|MB_APPLMODAL);
  415.                                 }
  416.  
  417.                             bHitSomething = FALSE;
  418.  
  419.                             //
  420.                             // Check to see if we hit any drones
  421.                             //
  422.                             ix = ptSelf.Pos.ix;
  423.                             iy = ptSelf.Pos.iy;
  424.                             Facing = ptSelf.Pos.Facing;
  425.  
  426.                             bSquare2 = bMaze[ix][iy];
  427.  
  428.                             //
  429.                             // for each square until the next wall, */
  430.                             //
  431.                             do {
  432.                                 ptTrav = &ptDrones;
  433.                                         /* Loop through all drones to see if it's there */
  434.                                 while (ptTrav->next != NULL) {
  435.                                     ptTrav = ptTrav->next;
  436.  
  437.                                     if ((ix == ptTrav->Pos.ix)&&(iy == ptTrav->Pos.iy)) {
  438.                                         if (!sndPlaySound("squish.wav",SND_ASYNC)) {
  439.                                             MessageBeep((UINT)-1);
  440.                                             }
  441.  
  442.                                         FadePic(ptTrav->iPicNum,
  443.                                                 ptTrav->Pos.Facing,
  444.                                                 hMazeDC,
  445.                                                 &ptTrav->rFrom,
  446.                                                 &ptTrav->rDrawn);
  447.                                         ptTrav->Pos.ix = RandRange(5*X_CELLS_PER_SUBGRID,8*X_CELLS_PER_SUBGRID-1);
  448.                                         ptTrav->Pos.iy = RandRange(7*Y_CELLS_PER_SUBGRID,8*Y_CELLS_PER_SUBGRID-1);
  449.                                         i = RandRange(1,4);
  450.                                         ptTrav->Pos.Facing = ((i == 1) ? NORTH :
  451.                                                       ((i == 2) ? WEST :
  452.                                                       ((i == 3) ? SOUTH :
  453.                                                       EAST)));
  454.                                         if (bBitmapDraw) {
  455.                                             hMem = GlobalAlloc(GHND,sizeof(RECT));
  456.                                             rPtr = (LPRECT)GlobalLock(hMem);
  457.                                             *rPtr = ptTrav->rDrawn;
  458.                                             PostMessage(hWndMaze,WM_COMMAND,IDM_REDRAW,(DWORD)rPtr);
  459.                                             }
  460.                                         ptSelf.iScore += iDronesKilled*iDroneSpeed*iDroneSpeed*iNumDrones/20;
  461.                                         SendNetMessage(0,0,NULL,NP_SCORE);
  462.                                         iDronesKilled++;
  463.                                         PostMessage(hWndScore,WM_COMMAND,WC_UPDATESCORE,ptSelf.ulID);
  464.                                         bHitSomething = TRUE;
  465.                                         sprintf(cBuff,GetStringRes(IDS_FMT_YOUZAPPED),ptTrav->cUserName);
  466.                                         PrintTextLine(cBuff);
  467.                                         }
  468.                                     }
  469.  
  470.                                 bSquare1 = bSquare2;
  471.                                 bSquare2 = bMaze[ix = ADJ_X(ix,Facing)][iy = ADJ_Y(iy,Facing)];
  472.  
  473.                                 } while (!(bHitSomething||
  474.                                          ((bSquare1 & Facing)||(bSquare2 & BACK_TO_ABS(Facing)))));
  475.  
  476.                             if (!bHitSomething) {
  477.                                 Sleep(100);
  478.                                 BitBlt(hDC,(rMaze.left+rMaze.right)/2 - 12,
  479.                                        (rMaze.top+rMaze.bottom)/2 - 12,
  480.                                        24,24,
  481.                                        hBMDC,0,0,SRCINVERT);
  482.                                 SelectObject(hBMDC,(HGDIOBJ)NULL);
  483.                                 }
  484.  
  485.  
  486.                             DeleteDC(hBMDC);
  487.                             ReleaseDC(hWndMaze,hDC);
  488.                             }
  489.  
  490.                         break;
  491.  
  492.  
  493.                     case VK_UP:
  494.                         bSquare2 = bMaze[ADJ_X(ptSelf.Pos.ix,ptSelf.Pos.Facing)]
  495.                                     [ADJ_Y(ptSelf.Pos.iy,ptSelf.Pos.Facing)];
  496.                         if ((bSquare1 & ptSelf.Pos.Facing)||(bSquare2&BACK_TO_ABS(ptSelf.Pos.Facing))) {
  497.                             if (!sndPlaySound("blocks.wav",SND_ASYNC)) {
  498.                                 MessageBeep((UINT) -1);
  499.                                 }
  500.                             }
  501.                         else {
  502.                             ptLastPos = ptSelf.Pos;
  503.                             ptSelf.Pos.ix = ADJ_X(ptSelf.Pos.ix,ptSelf.Pos.Facing);
  504.                             ptSelf.Pos.iy = ADJ_Y(ptSelf.Pos.iy,ptSelf.Pos.Facing);
  505.                             ptTrav = &ptDrones;
  506.                             bKilled = FALSE;
  507.                             while (ptTrav->next != NULL) {
  508.                                 ptTrav = ptTrav->next;
  509.                                 ptPos = ptTrav->Pos;
  510.                                 if ((!InSanctuary(&ptSelf.Pos))&&
  511.                                     (ptSelf.Pos.ix == ptPos.ix)&&
  512.                                     (ptSelf.Pos.iy == ptPos.iy)
  513.                                    ) {
  514.                                     sprintf(cBuff,GetStringRes(IDS_FMT_SLEW),ptTrav->cUserName);
  515.                                     PrintTextLine(cBuff);
  516.                                     iKilledByDrones++;
  517.                                     ptSelf.iScore -= (iDroneSpeed) ?    36/iDroneSpeed/iDroneSpeed : 72;
  518.                                     KillSelf();
  519.                                     SendNetMessage(0,0,NULL,NP_SCORE);
  520.  
  521.                                     bKilled = TRUE;
  522.                                     break;
  523.                                     }
  524.                                 }
  525.  
  526.                             if (!bKilled) {
  527.                                 if (!SendNetMessage(0,0,&ptSelf.Pos,NP_MOVETO)) {
  528.                                     MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"MazeWndProc",
  529.                                                MB_ICONEXCLAMATION|MB_APPLMODAL);
  530.                                     }
  531.                                 bNewSelfInSanct = InSanctuary(&ptSelf.Pos);
  532.                                 if (bSelfInSanct != bNewSelfInSanct) {
  533.                                     sprintf(cBuff, GetStringRes(IDS_FMT_SANCTUARY),
  534.                                             GetStringRes2(bNewSelfInSanct ? IDS_ENTERED : IDS_LEFT));
  535.                                     PrintTextLine(cBuff);
  536.                                     bSelfInSanct = bNewSelfInSanct;
  537.                                     }
  538.  
  539.                                 PostMessage(hWnd,WM_COMMAND,IDM_REDRAW,(LPARAM)NULL);
  540.                                 hDC = GetDC(hWndTopView);
  541.                                 DrawTopView(hDC,FALSE);
  542.                                 ReleaseDC(hWndTopView,hDC);
  543.                                 PostMessage(hWndScore,WM_COMMAND,WC_UPDATEDIRECTION,0);
  544.                                 }
  545.                             }
  546.                         break;
  547.  
  548.                     case VK_LEFT:
  549.                         ptLastPos = ptSelf.Pos;
  550.                         ptSelf.Pos.Facing = LEFT_TO_ABS(ptSelf.Pos.Facing);
  551.                         PostMessage(hWnd,WM_COMMAND,IDM_REDRAW,(LPARAM)NULL);
  552.                         if (!SendNetMessage(0,0,&ptSelf.Pos,NP_MOVETO)) {
  553.                             MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"MazeWndProc",
  554.                                         MB_ICONEXCLAMATION|MB_APPLMODAL);
  555.                             }
  556.                         hDC = GetDC(hWndTopView);
  557.                         DrawTopView(hDC,FALSE);
  558.                         ReleaseDC(hWndTopView,hDC);
  559.                         PostMessage(hWndScore,WM_COMMAND,WC_UPDATEDIRECTION,0);
  560.                         break;
  561.  
  562.                     case VK_RIGHT:
  563.                         ptLastPos = ptSelf.Pos;
  564.                         ptSelf.Pos.Facing = RIGHT_TO_ABS(ptSelf.Pos.Facing);
  565.                         PostMessage(hWnd,WM_COMMAND,IDM_REDRAW,(LPARAM)NULL);
  566.                         if (!SendNetMessage(0,0,&ptSelf.Pos,NP_MOVETO)) {
  567.                             MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"MazeWndProc",
  568.                                              MB_ICONEXCLAMATION|MB_APPLMODAL);
  569.                             }
  570.                         hDC = GetDC(hWndTopView);
  571.                         DrawTopView(hDC,FALSE);
  572.                         ReleaseDC(hWndTopView,hDC);
  573.                         PostMessage(hWndScore,WM_COMMAND,WC_UPDATEDIRECTION,0);
  574.                         break;
  575.  
  576.                     case VK_DOWN:
  577.                         bSquare2 = bMaze[ADJ_X(ptSelf.Pos.ix,BACK_TO_ABS(ptSelf.Pos.Facing))]
  578.                                     [ADJ_Y(ptSelf.Pos.iy,BACK_TO_ABS(ptSelf.Pos.Facing))];
  579.                         if ((bSquare2 & ptSelf.Pos.Facing)||(bSquare1&BACK_TO_ABS(ptSelf.Pos.Facing))) {
  580.                             if (!sndPlaySound("blocks.wav",SND_ASYNC)) {
  581.                                 MessageBeep((UINT) -1);
  582.                                 }
  583.                             }
  584.                         else {
  585.                             ptLastPos = ptSelf.Pos;
  586.  
  587.                             ptSelf.Pos.ix = ADJ_X(ptSelf.Pos.ix,BACK_TO_ABS(ptSelf.Pos.Facing));
  588.                             ptSelf.Pos.iy = ADJ_Y(ptSelf.Pos.iy,BACK_TO_ABS(ptSelf.Pos.Facing));
  589.                             ptTrav = &ptDrones;
  590.                             bKilled = FALSE;
  591.                             while (ptTrav->next != NULL) {
  592.                                 ptTrav = ptTrav->next;
  593.                                 ptPos = ptTrav->Pos;
  594.                                 if ((!InSanctuary(&ptSelf.Pos))&&
  595.                                     (ptSelf.Pos.ix == ptPos.ix)&&
  596.                                     (ptSelf.Pos.iy == ptPos.iy)
  597.                                    ) {
  598.                                     sprintf(cBuff,GetStringRes(IDS_FMT_SLEW),ptTrav->cUserName);
  599.                                     PrintTextLine(cBuff);
  600.                                     ptSelf.iScore -= (iDroneSpeed) ? 36/iDroneSpeed/iDroneSpeed : 72;
  601.                                     SendNetMessage(0,0,NULL,NP_SCORE);
  602.  
  603.                                     iKilledByDrones++;
  604.                                     KillSelf();
  605.                                     bKilled = TRUE;
  606.                                     break;
  607.                                     }
  608.                                 }
  609.                             if (!bKilled) {
  610.                                 if (!SendNetMessage(0,0,&ptSelf.Pos,NP_MOVETO)) {
  611.                                     MessageBox((HWND)NULL,GetStringRes(IDS_SNDPCKTFAIL),"MazeWndProc",
  612.                                                MB_ICONEXCLAMATION|MB_APPLMODAL);
  613.                                     }
  614.                                 bNewSelfInSanct = InSanctuary(&ptSelf.Pos);
  615.                                 if (bSelfInSanct != bNewSelfInSanct) {
  616.                                     sprintf(cBuff, GetStringRes(IDS_FMT_SANCTUARY),
  617.                                             GetStringRes2(bNewSelfInSanct ? IDS_ENTERED : IDS_LEFT));
  618.                                     PrintTextLine(cBuff);
  619.                                     bSelfInSanct = bNewSelfInSanct;
  620.                                     }
  621.                                 PostMessage(hWnd,WM_COMMAND,IDM_REDRAW,(LPARAM)NULL);
  622.                                 hDC = GetDC(hWndTopView);
  623.                                 DrawTopView(hDC,FALSE);
  624.                                 ReleaseDC(hWndTopView,hDC);
  625.                                 PostMessage(hWndScore,WM_COMMAND,WC_UPDATEDIRECTION,0);
  626.                                 }
  627.                             }
  628.                         break;
  629.  
  630.                     //
  631.                     // Whisper something
  632.                     //
  633.                     case 'W':
  634.                     case 'w':
  635.                         iLoudness = iWhisperDist;
  636.                         DialogBox(hInst,"INTONE_DLG", hWnd, IntoneDlg);
  637.                         iWhisperDist = iLoudness;
  638.                         break;
  639.                     //
  640.                     // Shout something
  641.                     //
  642.                     case 'S':
  643.                     case 's':
  644.                         iLoudness = iShoutDist;
  645.                         DialogBox(hInst,"INTONE_DLG", hWnd, IntoneDlg);
  646.                         iShoutDist = iLoudness;
  647.                         break;
  648.                     default:
  649.                         SendMessage(hWnd,WM_KEYDOWN,wParam,lParam);
  650.                         break;
  651.                     }
  652.                 }
  653.             break;
  654.  
  655.         case WM_MOVE:
  656.             break;
  657.  
  658.         case WM_SIZE:
  659.             GetClientRect(hWnd,&rMaze);
  660.             Calc3DMaze();
  661.             StretchBitmaps();
  662.             if (bBitmapDraw) {
  663.                 if (((HWND)hMaze3DBM) != (HWND)NULL) {
  664.                     DeleteObject(hMaze3DBM);
  665.                     }
  666.                 hDC = GetDC(hWnd);
  667.                 if (hMaze3DBM != NULL) {
  668.                     DeleteObject(hMaze3DBM);
  669.                 }
  670.                 hMaze3DBM = CreateCompatibleBitmap(hDC,rMaze.right-rMaze.left,
  671.                                                    rMaze.bottom-rMaze.top);
  672.                 SelectObject(hMazeDC,hMaze3DBM);
  673.                 ReleaseDC(hWnd,hDC);
  674.                 }
  675.             break;
  676.  
  677.         case WM_PAINT:
  678.             hMem = GlobalAlloc(GHND,sizeof(RECT));
  679.             rTemp = (LPRECT) GlobalLock(hMem);
  680.             if (rTemp == NULL) {
  681.                 MessageBox((HWND)NULL,GetStringRes(IDS_MALLOCFAIL),"MazeWnd",
  682.                            MB_ICONEXCLAMATION|MB_APPLMODAL);
  683.                 PostMessage(hWndMain,WM_CLOSE,0,0);
  684.                 }
  685.             GetUpdateRect(hWnd,rTemp,FALSE);
  686.             ValidateRect(hWnd,rTemp);
  687.             PostMessage(hWnd,WM_COMMAND,IDM_REDRAW,(LPARAM)rTemp);
  688.             break;
  689.  
  690.         case WM_CLOSE:
  691.             KillTimer((HWND)NULL,uiTimer);
  692. #ifdef WIN32
  693.             //
  694.             // Destroy the mailslot.
  695.             //
  696.             if (hMailSlot != (HANDLE)NULL) {
  697.                 CloseHandle(hMailSlot);
  698.                 }
  699. #endif
  700.             DestroyWindow(hWnd);
  701.             if (((HWND)hMaze3DBM) != (HWND)NULL) {
  702.                 DeleteObject(hMaze3DBM);
  703.                 DeleteDC(hMazeDC);
  704.                 }
  705.             if (hWnd == hWndMain) {
  706.                 PostQuitMessage(0);
  707.                 }
  708.             break;
  709.  
  710.         default:
  711.             return DefWindowProc(hWnd, Message, wParam, lParam);
  712.             break;
  713.         }
  714.  
  715.     return(0);
  716. }
  717.  
  718.