[source ="cpp"]/*=================main.cppMain entry point for the Card application=================*/#include "GameConstants.h"#include "GameResources.h"#include "cD3DManager.h"#include "cD3DXSpriteMgr.h"#include "cD3DXTexture.h"#include "cSprite.h"#include "cExplosion.h"#include "cXAudio.h"#include "cBalloon.h"using namespace std;HINSTANCE hInst; // global handle to hold the application instanceHWND wndHandle; // global variable to hold the window handle// Get a reference to the DirectX Managerstatic cD3DManager* d3dMgr = cD3DManager::getInstance();// Get a reference to the DirectX Sprite renderer Manager static cD3DXSpriteMgr* d3dxSRMgr = cD3DXSpriteMgr::getInstance();RECT clientBounds;const RECT playerBounds;TCHAR szTempOutput[30];bool gHit = false;D3DXVECTOR3 expPos;list<cExplosion*> gExplode;cXAudio gExplodeSound;D3DXVECTOR2 rocketTrans = D3DXVECTOR2(400,500);D3DXVECTOR2 enemyTrans1 = D3DXVECTOR2(100,100);D3DXVECTOR2 enemyTrans2 = D3DXVECTOR2(300,100);D3DXVECTOR2 enemyTrans3 = D3DXVECTOR2(500,100);D3DXVECTOR2 enemyTrans4 = D3DXVECTOR2(300,300);vector<cBalloon*> aEnemy;vector<cBalloon*>::const_iterator iterRO;vector<cBalloon*>::iterator iter;vector<cBalloon*>::iterator index;/*==================================================================* LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,* LPARAM lParam)* The window procedure==================================================================*/LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ // Check any available messages from the queue switch (message) { case WM_KEYDOWN: { //Keep player inside the screen. if(rocketTrans.x <= 0) { rocketTrans.x = 0; } if(rocketTrans.x >= 650) { rocketTrans.x = 650; } //keys for player movement. if (wParam == VK_LEFT) { rocketTrans.x -= 10.0f; return 0; } if (wParam == VK_RIGHT) { rocketTrans.x += 10.0f; return 0; } if (wParam == VK_UP) { rocketTrans.y -= 10.0f; return 0; } if (wParam == VK_DOWN) { rocketTrans.y += 10.0f; return 0; } return 0; } case WM_LBUTTONDOWN: { POINT mouseXY; mouseXY.x = LOWORD(lParam); mouseXY.y = HIWORD(lParam); expPos = D3DXVECTOR3((float)mouseXY.x,(float)mouseXY.y, 0.0f); gExplode.push_back(new cExplosion(expPos,d3dMgr->getTheD3DDevice(),"Images\\explosion.png")); gExplodeSound.playSound(L"Sounds\\explosion.wav",false); StringCchPrintf(szTempOutput, STRSAFE_MAX_CCH, TEXT("Mouse: lLastX=%d lLastY=%d\r\n"), LOWORD(lParam), HIWORD(lParam)); OutputDebugString(szTempOutput); return 0; } case WM_CLOSE: { // Exit the Game PostQuitMessage(0); return 0; } case WM_DESTROY: { PostQuitMessage(0); return 0; } } // Always return the message to the default window // procedure for further processing return DefWindowProc(hWnd, message, wParam, lParam);}/*==================================================================* bool initWindow( HINSTANCE hInstance )* initWindow registers the window class for the application, creates the window==================================================================*/bool initWindow( HINSTANCE hInstance ){ WNDCLASSEX wcex; // Fill in the WNDCLASSEX structure. This describes how the window // will look to the system wcex.cbSize = sizeof(WNDCLASSEX); // the size of the structure wcex.style = CS_HREDRAW | CS_VREDRAW; // the class style wcex.lpfnWndProc = (WNDPROC)WndProc; // the window procedure callback wcex.cbClsExtra = 0; // extra bytes to allocate for this class wcex.cbWndExtra = 0; // extra bytes to allocate for this instance wcex.hInstance = hInstance; // handle to the application instance wcex.hIcon = LoadIcon(hInstance,MAKEINTRESOURCE(IDI_MyWindowIcon)); // icon to associate with the application wcex.hCursor = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_GUNSIGHT));// the default cursor wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // the background color wcex.lpszMenuName = NULL; // the resource name for the menu wcex.lpszClassName = "Balloons"; // the class name being created wcex.hIconSm = LoadIcon(hInstance,"Balloon.ico"); // the handle to the small icon RegisterClassEx(&wcex); // Create the window wndHandle = CreateWindow("Balloons", // the window class to use "Balloon Burst", // the title bar text WS_OVERLAPPEDWINDOW, // the window style CW_USEDEFAULT, // the starting x coordinate CW_USEDEFAULT, // the starting y coordinate 800, // the pixel width of the window 600, // the pixel height of the window NULL, // the parent window; NULL for desktop NULL, // the menu for the application; NULL for none hInstance, // the handle to the application instance NULL); // no values passed to the window // Make sure that the window handle that is created is valid if (!wndHandle) return false; // Display the window on the screen ShowWindow(wndHandle, SW_SHOW); UpdateWindow(wndHandle); return true;}/*==================================================================// This is winmain, the main entry point for Windows applications==================================================================*/int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ){ // Initialize the window if ( !initWindow( hInstance ) ) return false; // called after creating the window if ( !d3dMgr->initD3DManager(wndHandle) ) return false; if ( !d3dxSRMgr->initD3DXSpriteMgr(d3dMgr->getTheD3DDevice())) return false; // Grab the frequency of the high def timer __int64 freq = 0; // measured in counts per second; QueryPerformanceFrequency((LARGE_INTEGER*)&freq); float sPC = 1.0f / (float)freq; // number of seconds per count __int64 currentTime = 0; // current time measured in counts per second; __int64 previousTime = 0; // previous time measured in counts per second; float numFrames = 0.0f; // Used to hold the number of frames float timeElapsed = 0.0f; // cumulative elapsed time GetClientRect(wndHandle,&clientBounds); float fpsRate = 1.0f/25.0f; LPDIRECT3DSURFACE9 aSurface; // the Direct3D surface LPDIRECT3DSURFACE9 theBackbuffer = NULL; // This will hold the back buffer MSG msg; ZeroMemory( &msg, sizeof( msg ) ); // Initial starting position for Player D3DXVECTOR3 rocketPos = D3DXVECTOR3(300,300,0); cSprite theRocket(rocketPos,d3dMgr->getTheD3DDevice(),"Images\\player.png"); theRocket.setTranslation(D3DXVECTOR2(10.0f,0.0f)); // Initial starting position for Rocket D3DXVECTOR3 enemyPos; /* initialize random seed: */ srand ( (unsigned int)time(NULL) ); /* generate random number of balloons */ int numEnemy = (rand() % 5 + 1); for(int loop = 0; loop < numEnemy; loop++) { enemyPos = D3DXVECTOR3((float)clientBounds.right/(loop+2),0,0); aEnemy.push_back(new cBalloon(enemyPos,d3dMgr->getTheD3DDevice(),"Images\\enemy.png")); aEnemy[loop]->setTranslation(D3DXVECTOR2(5.0f,0.0f)); } // Initial starting position for Enemies D3DXVECTOR3 enemyPos1 = D3DXVECTOR3(300,300,0); cSprite theEnemy1(enemyPos1,d3dMgr->getTheD3DDevice(),"Images\\enemy.png"); theEnemy1.setTranslation(D3DXVECTOR2(5.0f,0.0f)); // Create the background surface aSurface = d3dMgr->getD3DSurfaceFromFile("Images\\space.png"); D3DXVECTOR3 aEnemyPos; while( msg.message!=WM_QUIT ) { // Check the message queue if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { // Game code goes here rocketPos = D3DXVECTOR3(rocketTrans.x,rocketTrans.y,0); theRocket.setSpritePos(rocketPos); enemyPos1 = D3DXVECTOR3(enemyTrans1.x,enemyTrans1.y,0); theEnemy1.setSpritePos(enemyPos1); QueryPerformanceCounter((LARGE_INTEGER*)¤tTime); float dt = (currentTime - previousTime)*sPC; // Accumulate how much time has passed. timeElapsed += dt; if(timeElapsed > fpsRate) { for(iter = aEnemy.begin(); iter != aEnemy.end(); ++iter) { (*iter)->update(); aEnemyPos = (*iter)->getSpritePos(); if (aEnemyPos.x>(clientBounds.right - 60) || aEnemyPos.x < 2 ) { (*iter)->setTranslation((*iter)->getTranslation()*(-1)); } for(index = aEnemy.begin(); index != aEnemy.end(); ++index) { if ((*iter)->collidedWith((*iter)->getBoundingRect(),(*index)->getBoundingRect())) { OutputDebugString("Collision!!"); (*iter)->setTranslation((*iter)->getTranslation()*(-1)); (*index)->setTranslation((*index)->getTranslation()*(-1)); } } } rocketPos = D3DXVECTOR3(rocketTrans.x,rocketTrans.y,0); theRocket.setSpritePos(rocketPos); d3dMgr->beginRender(); theBackbuffer = d3dMgr->getTheBackBuffer(); d3dMgr->updateTheSurface(aSurface, theBackbuffer); d3dMgr->releaseTheBackbuffer(theBackbuffer); d3dxSRMgr->beginDraw(); //d3dxSRMgr->drawSprite(theEnemy1.getTexture(),NULL,NULL,&theEnemy1.getSpritePos(),0xFFFFFFFF); for(iter = aEnemy.begin(); iter != aEnemy.end(); ++iter) { d3dxSRMgr->setTheTransform((*iter)->getSpriteTransformMatrix()); d3dxSRMgr->drawSprite((*iter)->getTexture(),NULL,NULL,NULL,0xFFFFFFFF); } d3dxSRMgr->drawSprite(theRocket.getTexture(),NULL,NULL,&theRocket.getSpritePos(),0xFFFFFFFF); d3dxSRMgr->endDraw(); d3dMgr->endRender(); } } } d3dxSRMgr->cleanUp(); d3dMgr->clean(); return (int) msg.wParam;}
Sorry about that. Here is a copy of my entire main class. This is where all my game code is.