|
Documentation
|
Creating a complete game: BreakoutThis document has been updated for use with GapiDraw 4.0 or later. |
Step 1 : Skeleton applicationWe will base our Breakout application from the Minimal application included with GapiDraw. Begin by copying the Minimal sample application in GapiDraw40\Samples\Win32\Minimal to GapiDraw40\Samples\Win32\Breakout. Then add the following code to myapplication.h, located in Breakout\common: #include "resource.h" enum { GAMEPARAM_BORDERWIDTH = 13, GAMEPARAM_SCOREHEIGHT = 16, GAMEPARAM_BRICKWIDTH = 40, GAMEPARAM_BRICKHEIGHT = 20, GAMEPARAM_BRICKSPACE = 2, GAMEPARAM_NUMLINES = 4, GAMEPARAM_BRICKOFFSETY = 32, GAMEPARAM_SUBPIXELSTEPS = 10, GAMEPARAM_NUMEXPLOSIONS = 7, GAMEPARAM_NUMBATS = 4, GAMEPARAM_NUMSHINE = 6, GAMEPARAM_NUMBORDERPIPES = 8 }; class CMyApplication : public CGapiApplication { ... // Game parameters DWORD m_dwGameBallsLeft; DWORD m_dwPlayerScore; float m_nGameBallSpeed; // Operations protected: HRESULT GameMoveBall(CGapiSurface* pBackBuffer); HRESULT GameCheckBat(CGapiSurface* pBackBuffer); HRESULT GameCheckBricks(CGapiSurface* pBackBuffer); HRESULT GameMoveBat(CGapiSurface* pBackBuffer); HRESULT GameDrawBackgrund(CGapiSurface* pBackBuffer); HRESULT GameDrawObjects(CGapiSurface* pBackBuffer); HRESULT GameDrawScore(CGapiSurface* pBackBuffer); HRESULT GameInitBricks(CGapiSurface* pBackBuffer); ... } Add the following code to myapplication.cpp, also located in Breakout\common: CMyApplication::CMyApplication(const GDAPPCONFIG& config) : CGapiApplication(config) { ... m_dwGameBallsLeft = 0; m_dwPlayerScore = 0; m_nGameBallSpeed = 0.0f; ... } HRESULT CMyApplication::GameMoveBall(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameCheckBat(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameCheckBricks(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameMoveBat(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameDrawBackgrund(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameDrawObjects(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameDrawScore(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::GameInitBricks(CGapiSurface* pBackBuffer) { return S_OK; } HRESULT CMyApplication::ProcessNextFrame(CGapiSurface* pBackBuffer, DWORD dwFlags) { // Enable clipping on back buffer pBackBuffer->SetClipper(NULL); // Draw toolbar buttons pBackBuffer->BltFast(pBackBuffer->GetWidth()-m_pButtons->GetWidth(), 0, m_pButtons, NULL, GDBLTFAST_KEYSRC, NULL); return S_OK; } Now we have a starting point! Let's add some game modes to our application!
|