Game development basis (8)

zhaozj2021-02-16  59

Game development basis (8)

The first window moves and changing the size of the hour Case WM_SIZE: Case WM_MOVE: IF ("FoxBear is minimized, pausing"); pausegame ();} if (bfullscreen) {setRect (& rcwindow, 0 , 0, GetSystemMetrics (SM_CXSCREEN), GetSystemMetrics (SM_CYSCREEN));} else {GetClientRect (hWnd, & rcWindow); ClientToScreen (hWnd, (lPPOINT) & rcWindow); ClientToScreen (hWnd, (lPPOINT) & rcWindow 1);} Msg ( " Window Rect: [% D,% D,% D,% D] ", rcwindow.left, rcwindow.top, rcwindow.right, rcwindow.bottom; Break; case wm_size: is sent when the window is changed . Case WM_MOVE: Yes when the window is moved. When these two messages are received, the first detecting the window is minimized, and if it is, the game is suspended. Otherwise, the game is detected whether the game is converted to full screen mode. If it is changed to change the size of the user area is full screen. If it is only changed the size of the window but does not make the display mode to minimize the full screen or window, then the user area coordinates of the window (X, Y and the x, y of the lower left corner) will be deposited. Structure RCWindows, then convert the coordinates in RCWindows into screen coordinates. Note that rcwindows is a RECT type structure, but the clientToscreen () requires the POINT type structure, and the value of X, Y and the lower right corner of the upper left corner of the structure REC are the value of the value of X, Y, and the upper right corner. The store is just the value of X and Y. Therefore, in ClientToscreen (hwnd, (lppoint) & rcwindow); ClientToscreen (HWnd, (LPPOINT) & RCWindow 1); first for RCWindow, and call the function twice, while making RCWindow when pulling RCWindow Address from 1. The second window is activated Case WM_ActivateApp: BiSACTIVE = (BOOL) WPARM && getForegroundWindow () == hWnd; if (bisactive) MSG ("FoxBear is Active"); Else MSG ("FoxBear Is Not Active"); IF BPAUSED & BISACTIVE) {IF ()) {unpausegame ();} else {if (getForeGroundWindow () == hWnd) {if (initgame ()) {unpauseGame ();}}}} Break; Case WM_ActivateApp: When Send this message when the window of the application that is different from the current window is activated. When this message is received, the BiUCTIVE is equal to () wparam && getForeGroup, and then detects whether the BiCTIVE is TURE. Here is to detect whether the window of the game is activated and in the current system.

Next, check if the game window is from the status of the status to the activation. If you run restoregame () from the new beginning, if restoreGame () successfully runs unpausegame (), if it is not from the status to the activation, the program is detected. Whether the window has the highest priority, if there is a new initialization game (running initGame ()), you run unpausegame (). When implementing logical palette third case WM_QUERYNEWPALETTE: if (bFullscreen && lpPalette && lpFrontBuffer!) {HRESULT ddrval; ddrval = IDirectDrawSurface_SetPalette (lpFrontBuffer, lpPalette); if (ddrval == DDERR_SURFACELOST) {IDirectDrawSurface_Restore (lpFrontBuffer); ddrval = IDirectDrawSurface_SetPalette (lpFrontBuffer, lpPalette); if (ddrval == DDERR_SURFACELOST) {Msg ( "Failed to restore palette after second try");}} if (ddrval == DD_OK) {SetWindowText (hWnd, OUR_APP_NAME);}} break; WM_QUERYNEWPALETTE: When the window receives the input focus, it will return to whether it can implement a logical palette when the window receives the input focus. After this message is obtained, the program first detects whether it is running on the window mode and the palette and the front buffer have been set, and then set a palette. If it fails, restore the front buffer and try again, if still failure Output error message. Two sets of settings change the title to "WIN FOX Application" once again. Section IV Change the system palette when Case WM_PALETTECHANGED: IF ((hwnd) WPARETTECHANGED: IF (if (! Bfullscreen) {if (! Bstress) {msg ("***** palette changed, pausing game") ; PauseGame ();} else {Msg ( "Lost palette but continuing"); SetWindowText (hWnd, OUR_APP_NAME "- palette changed COLORS PROBABLY WRONG")}}} break; WM_PALETTECHANGED: this message achieve its current window has the input focus The logical palette is sent to all windows. At this time, the system palette is changed. This message allows the window that does not have input focus to use a palette to implement its own logical palette and update its user area.

After getting this message, the program first is the current window to change the system palette. If it is directly skipped out the window process, if it is not detected whether it is a full screen mode, if it is directly jumped out of the window process, if it is not to detect whether bstress is detected first For Flase, if the game is paused, if Ture is turned to "- Palette Changed Colors Probly Wrong". Section 5 When the operation key is pressed, the WM_KEYDOWN message is generated when a non-system key is pressed, and the non-system key means that the button is pressed when the ALT key is not pressed, or when a window has input focus The next button. In the WPARAM parameter of the message, the virtual key code of the component is included, and the keyboard can be completed by different virtual key code. We know that the keys pressed in the operation of the game can be divided into: operation keys and function keys. Let's take a look at how to define the operation key in the routine. In the previous chapter, we will introduce the operation keys in this routine are "2345678" on the small built-in, but have not talked about how to implement it. Let us take a look now. Definition of the function of the operation key is the case VK_NUMPAD5: lastInput = KEY_STOP; break; case VK_DOWN: case VK_NUMPAD2: lastInput = KEY_DOWN; break; case VK_LEFT: case VK_NUMPAD4: lastInput = KEY_LEFT; break; case VK_RIGHT: case VK_NUMPAD6: lastInput = KEY_RIGHT; break; case VK_UP: case VK_NUMPAD8: lastInput = KEY_UP; break; case VK_HOME: case VK_NUMPAD7: lastInput = KEY_JUMP; break; case VK_NUMPAD3: lastInput = KEY_THROW; break; you can see all get after each virtual key code Assign the LastInput, then the definition of the action key is completed, as for how the operation key has its effect, you can see in Section 8 of this chapter. Section 6 When the function key is pressed, the function key in this game is F3, F4, F5, F6, F7, F8, F9. What is the role of these keys? Let's take a look at one below! 1.F3 role is to pause the game and unpubstate. This effect is implemented in the program: Case VK_F3: bpaused =! Bpaused; Break; 2. F4 function is to achieve the role of Alt Enter. In the program, use Case VK_F4: PostMessage (HWND, WM_SYSKEYUP, VK_RETURN, 0); Break; 4. F6 effect is the display mode in the display mode list one by one.

Case vk_f6: {static i; if (bfullscreen) {for (i = 0; i

Case vk_f8: if (bfullscreen) {bstretch; initgame ();} else {rect rc; getClientRect (hwnd, & rc); bstretch = (rc.right! = gamesize.cx) || (rc.bottom! = Gamesize.cy); if (bstretch =! Bstretch) SetRect (& RC, 0, 0, Gamemode.cx * 2, GameMode.Cy * 2); Else SetRect (& RC, 0, 0, Gamemode.cx, GameMode.cy) AdjustWindowRectex (& rc, getwindowstyle (hwnd), getMenu (hwnd)! = Null, getWindowexStyle (hwnd)); setWindowPos (hwnd, null, 0, 0, rc.right-rc.Left, rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);} Break; This part of the running process is: If full screen mode, the BSTRETCH is not taken, then the game is initialized. If the window mode is obtained, the feature of the at the time is obtained to determine the value of the Bstretch, then from the new display window. 7. The role of F9 is to cancel the use of software simulation and use existing driver Case vk_f9: devindex ; buseemulation = false; if (devindex> = maxdevindex) devindex = 0; exitgame (); dddisable (TRUE); / / Destroy DirectDraw Object InIntGame (); Break; Section 7 Other Messages Case WM_DISPLAYCHANGE: BREAK; CASE WM_CREATE: BREAK; After these two messages are received, they will not do any reactions. Case WM_SETCURSOR: IF (BfullScreen && BiActive) {setCursor (null); return true;} Break; This information is sent when the cursor moves with the mouse and the input is not captured. Since this game does not require a mouse, after the subsequent detection is a full screen mode or activated statement, after obtaining a positive answer, delete the cursor from the screen. Case WM_Paint: HDC = Beginpaint (HWND, & PS); if (bpaused) {char * SZ = "Game is Paused, this is not a bug."; Textout (ps.hdc, 0, 0, sz, lstrlen (SZ) );} Endpaint (hwnd, & ps); Return 1; this message is issued in the request to re-draw the application window. After receiving this message, call BeginPaint () to make painting preparation for the window referred to in HWND.

Then determine if the game is suspended, if it outputs GAME IS PAUSED, this is not a bug to the screen, last call endpaint () case wm_destroy: hwndmain = null; LastInput = 0; destroyGame (); // end of game dddisable (TRUE) // DESTROY DIRECTDRAW Object PostquitMessage (0); Break; This message is sent to the window when you want to undo a window. After receiving this message, the program command points to the handle of the window as NULL, set to 0 for the next input of the game's refresh unit, and then clear the memory of the game and game workers. Section 8 Refreshing the game unit After discussing the window process, we should begin to introduce the message loop part of this game. Most of this game's message loop section has been talked in the chapter Windows programming basis, so we will only introduce the refresh game unit and the redraw game unit part. In the message loop, the program is a call function processfox (short sinput) to perform both part of the work. In the ProcessFox (SINPUT) function, check whether the game is running or restoring the game runs successfully, then call the ProcessInput (SINPUT) function to refresh the game cell section, then call newgameframe () to redraw game Unit work. Let's take a look at the new game unit part first. This part of the running process is: 1. The behavior of the fox is first taken to get the speed, behavior, and direction of the current fox. Then detect whether to obtain the position of the fox or whether the input is 4209, if the detected expression is TURE, it is input to 0, that is, no input, if FLASE begins to respond to various inputs. In the process of responding, the program first judges the current state of the fox, and then determines the basic state of the next frame of fox according to the current state of the fox. For example, "↓" or keypad "2" is pressed the response process for case key_down: if (foxAction == stop) {Break;} else == 2 {setspriteAction (hfox, crouch, same } Else if (foxAction == walk) {setspriteAction (hfox, crouchwalk, same);} Break; When the "↓" button is pressed, if the movement of the fox is in an emergency, it is jumped out; if the fox is Static, then the fox squats; if the fox is moving, the fox's action is changed to crawling. After the initial treatment of the input, the program combines other properties of fox behavior to determine the state of the next frame of foxes. It is also done with the Switch - CASE statement and a large number of if - else statements. 2. The behavior of bear and Apple refreshes the running process of these two parts is actually consistent, and it is first collision detection, and then determines the new behavior attribute of the role according to the test results. The work of the part of the segment of the Heavy Picture of the game unit is done by newgameframe (). This function first calls setspritex (), setspritey () two-function setting roles, then calls the setPlanevelX () and setPlanex () functions to set the moving speed of the three-layer background and the position of the next frame. Then by detecting the value of BTransdest is to paste the character's bitmap to BackBuffer or first paste the bitmap of the background to the Backibuffer, and finally call the function GFXSwapBuffers () Turn the page flip to display the figure in the backup buffer to the screen.

转载请注明原文地址:https://www.9cbs.com/read-23327.html

New Post(0)