|
Documentation
|
Creating a complete game: BreakoutThis document has been updated for use with GapiDraw 4.0 or later. |
Step 9 : Random shine effectsWe will now make our game look a bit more interesting, and to do so we will add a special shine effect to the bricks. This is a small animation of 6 frames, and looks as follows:
We will make it so that at random intervals one of the bricks gets highlighted using the above animation. We will of course filter away the purple colors using a color key so that only the white "shine" remains. First, download the file shine.png and save it to your Breakout\Common\res folder. Then add it to your Visual Studio project as a PNG image and name it IDB_BRICKSHINE. Add the following code to myapplication.h: class CMyApplication : public CGapiApplication { ... CGapiSurface* m_pBrickShine; ... } Add the following code to myapplication.cpp: CMyApplication::CMyApplication(const GDAPPCONFIG& config) : CGapiApplication(config) { ... m_pBrickShine = new CGapiSurface(GetGlobal()); ... } CMyApplication::~CMyApplication() { ... delete m_pBrickShine; ... } HRESULT CMyApplication::CreateVidMemSurfaces(CGapiSurface* pBackBuffer, HINSTANCE hInstance) { ... m_pBrickShine->CreateSurface(0, hInstance, IDB_BRICKSHINE, _T("PNG")); m_pBrickShine->SetColorKey(RGB(255, 0, 255)); ... } HRESULT CMyApplication::GameDrawObjects(CGapiSurface* pBackBuffer) { ... // Set brickshine DWORD dwUpdateInterval = (m_config.dwMaxFPS > 0) ? m_config.dwMaxFPS * 2 : 60; if ((DWORD)((float)rand()/(float)RAND_MAX*(float) dwUpdateInterval) == (m_config.dwMaxFPS >> 1)) { DWORD dwBrickIndex = (DWORD)((float)rand()/(float)RAND_MAX*(float)(GAMEPARAM_NUMLINES * m_dwGameBricksPerLine)); if (m_pBricks[dwBrickIndex].bShowBrick) { m_pBricks[dwBrickIndex].dwShineIndex = GAMEPARAM_NUMSHINE; } } // Draw brickshine for (dwY=0; dwY < GAMEPARAM_NUMLINES; dwY++) { for (dwX=0; dwX < m_dwGameBricksPerLine; dwX++) { DWORD dwBrickIndex = dwY * m_dwGameBricksPerLine + dwX; if (m_pBricks[dwBrickIndex].bShowBrick && (m_pBricks[dwBrickIndex].dwShineIndex > 0)) { DWORD dwLeft = GAMEPARAM_BORDERWIDTH + dwBrickOffsetX + dwX * (GAMEPARAM_BRICKWIDTH + GAMEPARAM_BRICKSPACE); DWORD dwTop = GAMEPARAM_BRICKOFFSETY + dwY * (GAMEPARAM_BRICKHEIGHT + GAMEPARAM_BRICKSPACE); DWORD dwXOffset = (GAMEPARAM_NUMSHINE - m_pBricks[dwBrickIndex].dwShineIndex) * GAMEPARAM_BRICKWIDTH; pBackBuffer->BltFast(dwLeft, dwTop, m_pBrickShine, CRect(dwXOffset, 0, dwXOffset+GAMEPARAM_BRICKWIDTH, GAMEPARAM_BRICKHEIGHT), GDBLTFAST_KEYSRC, NULL); m_pBricks[dwBrickIndex].dwShineIndex--; } } } return S_OK; } Shiny bricks done! Let's move on to show some text!
|