📄 g01.htm
字号:
<p>int paddle_x = 0, paddle_y = 0; // tracks position of paddle<br> int ball_x = 0, ball_y = 0; // tracks position of ball<br> int ball_dx = 0, ball_dy = 0; // velocity of ball<br> int score = 0; // the score<br> int level = 1; // the current level<br> int blocks_hit = 0; // tracks number of blocks hit</p> <p>// this contains the game grid data </p> <p>UCHAR blocks[NUM_BLOCK_ROWS][NUM_BLOCK_COLUMNS]; </p> <p>// FUNCTIONS //////////////////////////////////////////////////</p> <p>LRESULT CALLBACK WindowProc(HWND hwnd, <br> UINT msg, <br> WPARAM wparam, <br> LPARAM lparam)<br> {<br> // this is the main message handler of the system<br> PAINTSTRUCT ps; // used in WM_PAINT<br> HDC hdc; // handle to a device context</p> <p>// what is the message <br> switch(msg)<br> { <br> case WM_CREATE: <br> {<br> // do initialization stuff here<br> return(0);<br> } break;</p> <p> case WM_PAINT:<br> {<br> // start painting<br> hdc = BeginPaint(hwnd,&ps);</p> <p> // the window is now validated </p> <p> // end painting<br> EndPaint(hwnd,&ps);<br> return(0);<br> } break;</p> <p> case WM_DESTROY: <br> {<br> // kill the application <br> PostQuitMessage(0);<br> return(0);<br> } break;</p> <p> default:break;</p> <p> } // end switch</p> <p>// process any messages that we didn't take care of <br> return (DefWindowProc(hwnd, msg, wparam, lparam));</p> <p>} // end WinProc</p> <p>// WINMAIN ////////////////////////////////////////////////////</p> <p>int WINAPI WinMain( HINSTANCE hinstance,<br> HINSTANCE hprevinstance,<br> LPSTR lpcmdline,<br> int ncmdshow)<br> {<br> // this is the winmain function</p> <p>WNDCLASS winclass; // this will hold the class we create<br> HWND hwnd; // generic window handle<br> MSG msg; // generic message<br> HDC hdc; // generic dc<br> PAINTSTRUCT ps; // generic paintstruct</p> <p>// first fill in the window class stucture<br> winclass.style = CS_DBLCLKS | CS_OWNDC | <br> CS_HREDRAW | CS_VREDRAW;<br> winclass.lpfnWndProc = WindowProc;<br> winclass.cbClsExtra = 0;<br> winclass.cbWndExtra = 0;<br> winclass.hInstance = hinstance;<br> winclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);<br> winclass.hCursor = LoadCursor(NULL, IDC_ARROW);<br> winclass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);<br> winclass.lpszMenuName = NULL; <br> winclass.lpszClassName = WINDOW_CLASS_NAME;</p> <p>// register the window class<br> if (!RegisterClass(&winclass))<br> return(0);</p> <p>// create the window, note the use of WS_POPUP<br> if (!(hwnd = CreateWindow(WINDOW_CLASS_NAME, // class<br> "WIN3D Game Console", // title<br> WS_POPUP | WS_VISIBLE,<br> 0,0, // initial x,y<br> GetSystemMetrics(SM_CXSCREEN), // intial width<br> GetSystemMetrics(SM_CYSCREEN), // initial height<br> NULL, // handle to parent <br> NULL, // handle to menu<br> hinstance,// instance<br> NULL))) // creation parms<br> return(0);</p> <p>// hide mouse<br> ShowCursor(FALSE);</p> <p>// save the window handle and instance in a global<br> main_window_handle = hwnd;<br> main_instance = hinstance;</p> <p>// perform all game console specific initialization<br> Game_Init();</p> <p>// enter main event loop<br> while(1)<br> {<br> if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))<br> { <br> // test if this is a quit<br> if (msg.message == WM_QUIT)<br> break;<br> <br> // translate any accelerator keys<br> TranslateMessage(&msg);</p> <p> // send the message to the window proc<br> DispatchMessage(&msg);<br> } // end if<br> <br> // main game processing goes here<br> Game_Main();</p> <p> } // end while</p> <p>// shutdown game and release all resources<br> Game_Shutdown();</p> <p>// show mouse<br> ShowCursor(TRUE);</p> <p>// return to Windows like this<br> return(msg.wParam);</p> <p>} // end WinMain</p> <p>// T3DX GAME PROGRAMMING CONSOLE FUNCTIONS ////////////////////</p> <p>int Game_Init(void *parms)<br> {<br> // this function is where you do all the initialization <br> // for your game</p> <p><br> // return success<br> return(1);</p> <p>} // end Game_Init</p> <p>///////////////////////////////////////////////////////////////</p> <p>int Game_Shutdown(void *parms)<br> {<br> // this function is where you shutdown your game and<br> // release all resources that you allocated</p> <p><br> // return success<br> return(1);</p> <p>} // end Game_Shutdown</p> <p>///////////////////////////////////////////////////////////////</p> <p>void Init_Blocks(void)<br> {<br> // initialize the block field<br> for (int row=0; row < NUM_BLOCK_ROWS; row++)<br> for (int col=0; col < NUM_BLOCK_COLUMNS; col++)<br> blocks[row][col] = row*16+col*3+16;</p> <p>} // end Init_Blocks</p> <p>///////////////////////////////////////////////////////////////</p> <p>void Draw_Blocks(void)<br> {<br> // this function draws all the blocks in row major form<br> int x1 = BLOCK_ORIGIN_X, // used to track current position<br> y1 = BLOCK_ORIGIN_Y; </p> <p>// draw all the blocks<br> for (int row=0; row < NUM_BLOCK_ROWS; row++)<br> { <br> // reset column position<br> x1 = BLOCK_ORIGIN_X;</p> <p> // draw this row of blocks<br> for (int col=0; col < NUM_BLOCK_COLUMNS; col++)<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -