MAZEWND.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:29k
源码类别:

Windows编程

开发平台:

Visual C++

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