void Menu::initialize(Graphics *g, Input *i) { mainMenu.push_back("Main Menu"); mainMenu.push_back("Recovery - 200"); mainMenu.push_back("Projectile Ammo (Not in yet) - 100"); mainMenu.push_back("Done"); titleMenu.push_back("Play"); titleMenu.push_back("Controls"); retryMenu.push_back("Retry"); retryMenu.push_back("Exit"); scoreScreen.push_back("Scores"); highlightColor = graphicsNS::RED; normalColor = graphicsNS::WHITE; menuAnchor = D3DXVECTOR2(50,50); input = i; verticalOffset = 45; horizontalOffset = 160; linePtr = 0; selectedItem = -1; graphics = g; menuItemFont = new TextDX(); menuHeadingFont = new TextDX(); menuItemFontHighlight = new TextDX(); if(menuItemFont->initialize(graphics, 20, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuItem font")); if(menuItemFontHighlight->initialize(graphics, 25, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuItem font")); if(menuHeadingFont->initialize(graphics, 35, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuHeading font")); menuHeadingFont->setFontColor(normalColor); menuItemFont->setFontColor(normalColor); menuItemFontHighlight->setFontColor(highlightColor); upDepressedLastFrame = false; downDepressedLastFrame = false; mainDepressedLastFrame = false; titleMenuDepressedLastFrame = false; done = false; }
bool NPC::initialize(Game* gamePtr, int width, int height, int ncols, TextureManager* textureM, Image* gameDialogBox) { gameConfig = gamePtr->getGameConfig(); // image must be initialized first in order to use sprite size data bool result = Entity::initialize(gamePtr, width, height, ncols, textureM); // active and set collision box area active = true; edge.left = -spriteData.width/2; edge.right = spriteData.width/2; edge.top = -spriteData.height/2; edge.bottom = spriteData.height/2; dialogBox = gameDialogBox; if(!dialogText.initialize(gamePtr->getGraphics(), SPRITE_TEXT_FILE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing NPC dialogText")); dialogText.setFontHeight(14); if(!responseText.initialize(gamePtr->getGraphics(), SPRITE_TEXT_FILE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing NPC response Text")); responseText.setFontHeight(14); // dialogText.setProportional(true); if(!selectorTexture.initialize(gamePtr->getGraphics(), "pictures/text/selector.png")) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing NPC selector texture")); if(!selector.initialize(gamePtr->getGraphics(), 0, 0, 0, &selectorTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing NPC selector image")); return result; }
ItemController::ItemController(Graphics *graphics, TextureManager* iTxt) { itemTexture = new TextureManager(); if (!itemTexture->initialize(graphics, TEXTURE_ITEM)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing item texture")); crateList = new std::list<Crate*>(); itemList = std::vector<Item*>(); //init crate location first levelCrateLoc[0] = new std::list<VECTOR2>(); levelCrateLoc[0]->push_back(VECTOR2(321, 568)); // crate 1.1 levelCrateLoc[0]->push_back(VECTOR2(1152, 250)); // crate 2.1 levelCrateLoc[0]->push_back(VECTOR2(2447, 250)); //crate 2.5.1 levelCrateLoc[0]->push_back(VECTOR2(2688, 668)); // crate 3.1 levelCrateLoc[0]->push_back(VECTOR2(2815, 602)); // crate 3.2 //init crate item second levelCrateItemType[0] = new std::list<int>(); levelCrateItemType[0]->push_back(itemControllerNS::ItemType::machineGun); // crate 1.1 levelCrateItemType[0]->push_back(itemControllerNS::ItemType::shotGun); // crate 2.1 levelCrateItemType[0]->push_back(itemControllerNS::ItemType::machineGun); // crate 2.5.1 levelCrateItemType[0]->push_back(itemControllerNS::ItemType::machineGun); // crate 3.1 levelCrateItemType[0]->push_back(itemControllerNS::ItemType::shotGun); // crate 3.2 itemIconTexture = iTxt; gunTexture = new TextureManager(); if (!gunTexture->initialize(graphics, TEXTURE_GUNS)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing gun texture")); gunImage = new Image(); gunImage->initialize(graphics, itemControllerNS::GUN_TEXTURE_WIDTH, itemControllerNS::GUN_TEXTURE_HEIGHT, 1, gunTexture); itemIconTexture = new TextureManager(); if (!itemIconTexture->initialize(graphics, ITEM_ICON_TEXTURE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing item icon texture")); }
//============================================================================= // Initializes the game // throws GameError on error //============================================================================= void Game::initialize(HWND hw) { hwnd = hw; // save window handle // initialize graphics graphics = new Graphics(); // throws GameError graphics->initialize(hwnd, GAME_WIDTH, GAME_HEIGHT, FULLSCREEN); // initialize input, do not capture mouse input->initialize(hwnd, false); // throws GameError // init sound system audio = new Audio(); if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0') // if sound files defined { if( FAILED( hr = audio->initialize() ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found.")); else throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system.")); } } // attempt to set up high resolution timer if(QueryPerformanceFrequency(&timerFreq) == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing high resolution timer")); QueryPerformanceCounter(&timeStart); // get starting time initialized = true; }
void Menu::initialize(Graphics *g, Input *i) { menuHeading ="Test Menu"; highlightColor = graphicsNS::RED; normalColor = graphicsNS::WHITE; menuAnchor = D3DXVECTOR2(270,10); input = i; verticalOffset = 30; linePtr = 0; selectedItem = -1; graphics = g; menuItemFont = new TextDX(); menuHeadingFont = new TextDX(); menuItemFontHighlight = new TextDX(); if(menuItemFont->initialize(graphics, 15, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuItem font")); if(menuItemFontHighlight->initialize(graphics, 18, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuItem font")); if(menuHeadingFont->initialize(graphics, 25, true, false, "Calibri") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing menuHeading font")); menuHeadingFont->setFontColor(normalColor); menuItemFont->setFontColor(normalColor); menuItemFontHighlight->setFontColor(highlightColor); upDepressedLastFrame = false; downDepressedLastFrame = false; down = false; oldLeftPos = menuAnchor.x; parentSelected = 0; leftPos = 200; rightPos = 400; showMenu = -1; srand(time(0)); level1.push_back("Options"); level1.push_back("Enable SoundFX"); level1.push_back("I'm feeling lucky"); level2.resize(2); level2[0].push_back("Amazing Value"); level2[0].push_back("Same Great Price"); level2[1].push_back("On"); level2[1].push_back("Off"); /* vector<string> level21; level21.push_back("Amazing Value"); level21.push_back("Same Great Price"); vector<string> level22; level22.push_back("On"); level22.push_back("Off"); level2.push_back(level21); level2.push_back(level22);*/ }
void Graphics::initialize(HWND hw, int w, int h, bool full) { hwnd = hw; width = w; height = h; fullscreen = full; direct3d = Direct3DCreate9(D3D_SDK_VERSION); if (direct3d == NULL) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Direct3D")); initD3Dpp(); if(fullscreen) { if(isAdapterCompatible()) d3dpp.FullScreen_RefreshRateInHz = pMode.RefreshRate; else throw(GameError(gameErrorNS::FATAL_ERROR, "The graphics device does not support the specified resolution and/or format.")); } D3DCAPS9 caps; DWORD behavior; result = direct3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); if( (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 || caps.VertexShaderVersion < D3DVS_VERSION(1,1) ) behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING; else behavior = D3DCREATE_HARDWARE_VERTEXPROCESSING; result = direct3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, behavior, &d3dpp, &device3d); if (FAILED(result)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating Direct3D device")); result = D3DXCreateSprite(device3d, &sprite); if (FAILED(result)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating Direct3D sprite")); device3d->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); device3d->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); device3d->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); if( FAILED( direct3d->CheckDeviceFormat(caps.AdapterOrdinal, caps.DeviceType, d3dpp.BackBufferFormat, D3DUSAGE_DEPTHSTENCIL, D3DRTYPE_SURFACE, D3DFMT_D24S8 ) ) ) stencilSupport = false; else stencilSupport = true; device3d->CreateQuery(D3DQUERYTYPE_OCCLUSION, &pOcclusionQuery); }
//============================================================================= // Initializes the game // throws GameError on error //============================================================================= void Game::initialize(HWND hw) { hwnd = hw; // save window handle //AllocConsole(); // initialize gameConfig gameConfig = new GameConfig(); gameConfig->initialize(hwnd); // initialize graphics graphics = new Graphics(); // throws GameError graphics->initialize(hwnd, gameConfig->getGameWidth(), gameConfig->getGameHeight(), FULLSCREEN); // initialize input, do not capture mouse input->initialize(hwnd, false); // throws GameError // initialize console console = new Console(); console->initialize(graphics, input); // prepare console console->print("---Console---"); // initialize messageDialog messageDialog = new MessageDialog(); messageDialog->initialize(graphics, input, hwnd); // initialize inputDialog inputDialog = new InputDialog(); inputDialog->initialize(graphics, input, hwnd); // initialize DirectX font if(dxFont.initialize(graphics, gameNS::POINT_SIZE, false, false, gameNS::FONT) == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize DirectX font.")); dxFont.setFontColor(gameNS::FONT_COLOR); // init sound system audio = new Audio(); if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0') // if sound files defined { if( FAILED( hr = audio->initialize() ) ) { if( hr == HRESULT_FROM_WIN32( ERROR_FILE_NOT_FOUND ) ) throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system because media file not found.")); else throw(GameError(gameErrorNS::FATAL_ERROR, "Failed to initialize sound system.")); } } // attempt to set up high resolution timer if(QueryPerformanceFrequency(&timerFreq) == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing high resolution timer")); QueryPerformanceCounter(&timeStart); // get starting time initialized = true; }
//============================================================================= // Initialize DirectX graphics // throws GameError on error //============================================================================= void Graphics::initialize(HWND hw, int w, int h, bool full) { hwnd = hw; width = w; height = h; fullscreen = full; //initialize Direct3D direct3d = Direct3DCreate9(D3D_SDK_VERSION); if (direct3d == NULL) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Direct3D")); initD3Dpp(); // init D3D presentation parameters if(fullscreen) // if full-screen mode { if(isAdapterCompatible()) // is the adapter compatible // set the refresh rate with a compatible one d3dpp.FullScreen_RefreshRateInHz = pMode.RefreshRate; else throw(GameError(gameErrorNS::FATAL_ERROR, "The graphics device does not support the specified resolution and/or format.")); } // determine if graphics card supports harware texturing and lighting and vertex shaders D3DCAPS9 caps; DWORD behavior; result = direct3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); // If device doesn't support HW T&L or doesn't support 1.1 vertex // shaders in hardware, then switch to software vertex processing. if( (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 || caps.VertexShaderVersion < D3DVS_VERSION(1,1) ) behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // use software only processing else behavior = D3DCREATE_HARDWARE_VERTEXPROCESSING; // use hardware only processing //create Direct3D device result = direct3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, behavior, &d3dpp, &device3d); if (FAILED(result)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating Direct3D device")); result = D3DXCreateSprite(device3d, &sprite); if (FAILED(result)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating Direct3D sprite")); // Configure for alpha blend of primitives device3d->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); device3d->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); device3d->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); }
HUD::HUD(Graphics*& g) { graphics = g; itemTexture = new TextureManager(); gunHUDTexture = new TextureManager(); hpHUDTexture = new TextureManager(); hpTexture = new TextureManager(); //Load and set up hp HUD texture if (!hpHUDTexture->initialize(graphics, TEXTURE_HUD_HP)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing hp hud texture")); hpHUD = new Image(); hpHUD->initialize(graphics, hudNS::HP_HUD_WIDTH, hudNS::HP_HUD_HEIGHT, 1, hpHUDTexture); hpHUD->setCurrentFrame(0); hpHUD->setX(50); hpHUD->setY(60); if (!hpTexture->initialize(graphics, TEXTURE_HUD_HP_RED)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing hp texture")); hp = new Image(); hp->initialize(graphics, hudNS::HP_WIDTH, hudNS::HP_HEIGHT, 1, hpTexture); hp->setCurrentFrame(0); hp->setX(hpHUD->getX() + 30); hp->setY(hpHUD->getY()); //Load and set up gun HUD texture if (!gunHUDTexture->initialize(graphics, TEXTURE_HUD_GUN)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing gun hud texture")); gunHud = new Image(); gunHud->initialize(graphics, hudNS::GUN_HUD_WIDTH, hudNS::GUN_HUD_HEIGHT, 1, gunHUDTexture); gunHud->setCurrentFrame(0); gunHud->setX(hpHUD->getX() + hpHUD->getWidth() + 50); gunHud->setY(50); //Load and set up item HUD texture if (!itemTexture->initialize(graphics, TEXTURE_GUNS)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing gun texture")); currentItemImage = new Image(); currentItemImage->initialize(graphics, gunNS::TEXTURE_WIDTH, gunNS::TEXTURE_HEIGHT, gunNS::TEXTURE_COLS, itemTexture); currentItemImage->setX(gunHud->getX()); currentItemImage->setY(gunHud->getY() + 10); currentItemImage->setScale(0.8); //Load and set up Points HUD texture pointHud = new Image(); pointHud->initialize(graphics, hudNS::GUN_HUD_WIDTH, hudNS::GUN_HUD_HEIGHT, 1, gunHUDTexture); pointHud->setCurrentFrame(0); pointHud->setX(gunHud->getX() + gunHud->getWidth() + 50); pointHud->setY(50); //set up font ammoFont = new TextDX(); ammoFont->initialize(graphics, 20, false, false, "Courier New"); ammoFont->setFontColor(SETCOLOR_ARGB(192, 0, 0, 0)); currentItem = nullptr; currentPlayer = nullptr; }
bool Bowser::initialize(Game *gamePtr, int width, int height, int ncols, TextureManager *textureM) { attackTimer = 1.0f; // Bowser sprite initialize bowserSpriteCoordinates.populateVector("sprite_data\\bowser.xml"); if (!initializeCoords(bowserSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bowser")); //Idle bowserIdle.initialize(gamePtr->getGraphics(), bowserNS::WIDTH, bowserNS::HEIGHT, 0, textureM); if (!bowserIdle.initialize(bowserSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bowser")); bowserIdle.setFrames(bowserNS::IDLE_START_FRAME, bowserNS::IDLE_END_FRAME); bowserIdle.setCurrentFrame(bowserNS::IDLE_START_FRAME); bowserIdle.setFrameDelay(bowserNS::IDLE_ANIMATION_DELAY); //Spin Attack bowserSpin.initialize(gamePtr->getGraphics(), bowserNS::WIDTH, bowserNS::HEIGHT, 0, textureM); if (!bowserSpin.initialize(bowserSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bowser")); bowserSpin.setFrames(bowserNS::SPIN_START_FRAME, bowserNS::SPIN_END_FRAME); bowserSpin.setCurrentFrame(bowserNS::SPIN_START_FRAME); bowserSpin.setFrameDelay(bowserNS::SPIN_ANIMATION_DELAY); // Fire Ball Attack bowserFireBreath.initialize(gamePtr->getGraphics(), bowserNS::WIDTH, bowserNS::HEIGHT, 0, textureM); if (!bowserFireBreath.initialize(bowserSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bowser")); bowserFireBreath.setFrames(bowserNS::FIRE_BREATH_START_FRAME, bowserNS::FIRE_BREATH_END_FRAME); bowserFireBreath.setCurrentFrame(bowserNS::FIRE_BREATH_START_FRAME); bowserFireBreath.setFrameDelay(bowserNS::FIRE_BREATH_ANIMATION_DELAY); //Dying bowserDying.initialize(gamePtr->getGraphics(), bowserNS::WIDTH, bowserNS::HEIGHT, 0, textureM); if (!bowserDying.initialize(bowserSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bowser")); bowserDying.setFrames(bowserNS::DYING_START_FRAME, bowserNS::DYING_END_FRAME); bowserDying.setCurrentFrame(bowserNS::DYING_START_FRAME); bowserDying.setFrameDelay(bowserNS::DYING_ANIMATION_DELAY); bowserDying.setLoop(false); return(Entity::initialize(gamePtr, width, height, ncols, textureM)); }
//============================================================================= // Initializes the game // Throws GameError on error //============================================================================= void Spacewar::initialize(HWND hwnd) { Game::initialize(hwnd); // throws GameError // nebula texture if (!nebulaTexture.initialize(graphics,NEBULA_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing nebula texture")); // main game textures if (!gameTextures.initialize(graphics,TEXTURES_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing game textures")); // nebula image if (!nebula.initialize(graphics,0,0,0,&nebulaTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing nebula")); // planet if (!planet.initialize(this, planetNS::WIDTH, planetNS::HEIGHT, 2, &gameTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing planet")); // ship if (!ship1.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures, true)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship1")); ship1.setFrames(shipNS::SHIP1_START_FRAME, shipNS::SHIP1_END_FRAME); ship1.setCurrentFrame(shipNS::SHIP1_START_FRAME); ship1.setX(GAME_WIDTH/4); ship1.setY(GAME_HEIGHT/4); ship1.setVelocity(VECTOR2(shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) // ship2 if (!ship2.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures, true)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship2")); ship2.setFrames(shipNS::SHIP2_START_FRAME, shipNS::SHIP2_END_FRAME); ship2.setCurrentFrame(shipNS::SHIP2_START_FRAME); ship2.setX(GAME_WIDTH - GAME_WIDTH/4); ship2.setY(GAME_HEIGHT/4); ship2.setVelocity(VECTOR2(-shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) //ship3 initalization. Do not rotate, start pointing north. This ship is controlled by the arrow keys. //ship3 ignores direction and will move in the direction of the key if (!ship3.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures, false)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship3")); ship3.setFrames(shipNS::SHIP1_START_FRAME, shipNS::SHIP1_END_FRAME); ship3.setCurrentFrame(shipNS::SHIP1_START_FRAME); ship3.setX(GAME_WIDTH - GAME_WIDTH/4); ship3.setY(GAME_HEIGHT - GAME_HEIGHT/4); ship3.setDegrees(270); //ship3.setVelocity(VECTOR2(shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) //ship4 initalization. Do not rotate, start pointing north. This ship is controlled by WASD //ship4 will rotate with A and D, and will move forward based on direction on W, and move backward based on direction on S. if (!ship4.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures, false)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship4")); ship4.setFrames(shipNS::SHIP2_START_FRAME, shipNS::SHIP2_END_FRAME); ship4.setCurrentFrame(shipNS::SHIP2_START_FRAME); ship4.setX(GAME_WIDTH/4); ship4.setY(GAME_HEIGHT - GAME_HEIGHT/4); ship4.setDegrees(270); //ship4.setVelocity(VECTOR2(shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) return; }
bool ParticleManager::initialize(Graphics *g) { if (!tm.initialize(g, FLAMES_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing dust texture")); for (int i = 0; i < MAX_NUMBER_PARTICLES; i++) { if (!particles[i].initialize(g,0,0,0,&tm)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing dust")); particles[i].setActive(false); particles[i].setVisible(false); particles[i].setScale(0.125f); //particles[i].setRotationValue(0.05f); } return true; }
//============================================================================= // Initialize D3D presentation parameters //============================================================================= void Graphics::initD3Dpp() { try{ ZeroMemory(&d3dpp, sizeof(d3dpp)); // fill the structure with 0 // fill in the parameters we need d3dpp.BackBufferWidth = width; d3dpp.BackBufferHeight = height; if(fullscreen) // if fullscreen d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; // 24 bit color else d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // use desktop setting d3dpp.BackBufferCount = 1; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.hDeviceWindow = hwnd; d3dpp.Windowed = (!fullscreen); if(VSYNC) // if vertical sync is enabled d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE; else d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; d3dpp.EnableAutoDepthStencil = true; d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8; // Depth 24, Stencil 8 } catch(...) { throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing D3D presentation parameters")); } }
// ================================================================== // マウスとコントローラの入力を初期化 // マウスをキャプチャする場合、capture = trueを設定 // GameErrorをスロー // ================================================================== void Input::initialize(HWND hwnd, bool capture) { try { mouseCaptured = capture; // 高精細マウスを登録 Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hwnd; RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])); if(mouseCaptured) SetCapture(hwnd); // マウスをキャプチャ // コントローラの状態をクリア ZeroMemory(controllers, sizeof(ControllerState) * MAX_CONTROLLERS); checkControllers(); // 接続されているコントローラをチェック } catch(...) { throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing input system")); } }
void CyraxWComponent::activate(bool facingRight, float x, float y, Game *cipher) { Bullet *newBullet = new Bullet(); newBullet->setBulletSprite(CyraxWComponentNS::WIDTH, CyraxWComponentNS::HEIGHT, CyraxWComponentNS::WBULLET_START_FRAME, CyraxWComponentNS::WBULLET_END_FRAME, 100); newBullet->setCurrentFrame(CyraxWComponentNS::WBULLET_START_FRAME); if (!newBullet->initialize(cipher, CyraxWComponentNS::WIDTH, CyraxWComponentNS::HEIGHT, CyraxWComponentNS::TEXTURE_COLS, &WbulletTexture)) { throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing cyrax W")); } newBullet->setX(x); newBullet->setY(y); newBullet->setActive(true); VECTOR2 direction; if (facingRight) //shoot right { direction.x = CyraxWComponentNS::WBULLET_MIN_SPEED; direction.y = CyraxWComponentNS::WBULLET_MIN_SPEED; newBullet->flipHorizontal(true); newBullet->setDirection(direction); } else if (!facingRight) //shoot left { direction.x = -CyraxWComponentNS::WBULLET_MIN_SPEED; direction.y = CyraxWComponentNS::WBULLET_MIN_SPEED; newBullet->setDirection(direction); } bulletList.push_back(newBullet); }
//============================================================================= // Initialize mouse and controller input // Set capture=true to capture mouse // Throws GameError //============================================================================= void Input::initialize(HWND hwnd, bool capture) { try { mouseCaptured = capture; // register high-definition mouse Rid[0].usUsagePage = HID_USAGE_PAGE_GENERIC; Rid[0].usUsage = HID_USAGE_GENERIC_MOUSE; Rid[0].dwFlags = RIDEV_INPUTSINK; Rid[0].hwndTarget = hwnd; RegisterRawInputDevices(Rid, 1, sizeof(Rid[0])); if(mouseCaptured) SetCapture(hwnd); // capture mouse // Clear controllers state ZeroMemory( controllers, sizeof(ControllerState) * MAX_CONTROLLERS ); checkControllers(); // check for connected controllers } catch(...) { throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing input system")); } }
//============================================================================= // Initializes the game // Throws GameError on error //============================================================================= void GroveMon::initialize(HWND hwnd) { Game::initialize(hwnd); for (int i = 0; i < nTextures; i++) { if (!textures[i].initialize(graphics, images[i].c_str())) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing texture")); } text.initialize(graphics, 24, false, false, "Cambria"); background.initialize(graphics, 0, 0, 0, &textures[3]); background.setX(0); background.setY(0); textBoxBack.initialize(graphics, 0, 0, 0, &textures[4]); textBoxBack.setX(0); textBoxBack.setY(290); textBoxBack.setScale(GAME_WIDTH / textBoxBack.getWidth()); liz.initialize(graphics, 0, 0, 0, &textures[2]); liz.setScale(0.5); lizard->image = &liz; tur.initialize(graphics, 0, 0, 0, &textures[0]); tur.setScale(0.5); turtle->image = &tur; din.initialize(graphics, 0, 0, 0, &textures[1]); din.setScale(0.5); dino->image = &din; }
Necrid::Necrid(Game *cipher) { Qcomponent = new NecridQComponent(cipher); Wcomponent = new NecridWComponent(cipher); Ecomponent = new NecridEComponent(cipher); //Rcomponent = new NecridRComponent(); Q_CoolDown = NecridNS::QSkillCD; W_CoolDown = NecridNS::WSkillCD; E_CoolDown = NecridNS::ESkillCD; if (!characterTexture.initialize(cipher->getGraphics(), NECRID_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Player texture")); if (!this->initialize(cipher, charactersNS::WIDTH, charactersNS::HEIGHT, NecridNS::TEXTURE_COLS, &characterTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player")); currentFrame = startFrame; startFrame = NecridNS::NECRID_START_FRAME; // first frame of ship animation endFrame = NecridNS::NECRID_END_FRAME; // last frame of ship animation }
Agent47::Agent47(Game *cipher) { Qcomponent = new Agent47QComponent(cipher); Wcomponent = new Agent47WComponent(cipher); Ecomponent = new Agent47EComponent(cipher); //Rcomponent = new Agent47RComponent(); Q_CoolDown = Agent47NS::QSkillCD; W_CoolDown = Agent47NS::WSkillCD; E_CoolDown = Agent47NS::ESkillCD; if (!characterTexture.initialize(cipher->getGraphics(), AGENT47_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Player texture")); if (!this->initialize(cipher, charactersNS::WIDTH, charactersNS::HEIGHT, Agent47NS::TEXTURE_COLS, &characterTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player")); currentFrame = startFrame; startFrame = Agent47NS::AGENT_START_FRAME; // first frame of ship animation endFrame = Agent47NS::AGENT_END_FRAME; // last frame of ship animation }
void Character_Menu::initialize(HWND hwnd, Graphics*& graphics, bool right) { if (right)//PLAYER 2 { goku_ = GOKU_2; piccolo_ = PICCOLO_2; naruto_ = NARUTO_2; luffy_ = LUFFY_2; } else//player 1 { goku_ = GOKU_1; piccolo_ = PICCOLO_1; naruto_ = NARUTO_1; luffy_ = LUFFY_1; } //initializing goku menu if (!goku_image.initialize(graphics,GAME_WIDTH,GAME_HEIGHT,0,&goku_texture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing GOKU menu")); if (!goku_texture.initialize(graphics,goku_,TRANSCOLORR)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing GOKU menu texture")); //initializing piccolo menu if (!piccolo_image.initialize(graphics, GAME_WIDTH, GAME_HEIGHT, 0, &piccolo_texture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing PICCOLO menu")); if (!piccolo_texture.initialize(graphics, piccolo_, TRANSCOLORR)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing start PICCOLO texture")); //initilaizing naruto menu if (!naruto_image.initialize(graphics, GAME_WIDTH, GAME_HEIGHT, 0, &naruto_texture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing naruto menu")); if (!naruto_texture.initialize(graphics, naruto_, TRANSCOLORR)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing start naruto texture")); //initialize luffy menu if (!luffy_image.initialize(graphics, GAME_WIDTH, GAME_HEIGHT, 0, &luffy_texture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing luffy menu")); if (!luffy_texture.initialize(graphics, luffy_, TRANSCOLORR)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing start luffy texture")); //place player 2 on the other side of screem if (right) { goku_image.setX(GAME_WIDTH / 2); piccolo_image.setX(GAME_WIDTH / 2); naruto_image.setX(GAME_WIDTH / 2); luffy_image.setX(GAME_WIDTH / 2); } }
GameManager::GameManager() { if( m_pGameManager ) throw GameError( "[GameManager::GameManager]: Attempt to instantiate multiple instances of singleton class GameManager." ); m_pGameManager = this; /* Setup default game settings. */ PlayerConfiguration playerConfig; // Player defaults: 1 user controlled and 3 AI players. m_gameConfig.NumPlayers = 4; playerConfig.IsAIPlayer = false; m_gameConfig.PlayerConfigs.push_back( playerConfig ); playerConfig.IsAIPlayer = true; m_gameConfig.PlayerConfigs.push_back( playerConfig ); m_gameConfig.PlayerConfigs.push_back( playerConfig ); m_gameConfig.PlayerConfigs.push_back( playerConfig ); // Dealer defaults. m_gameConfig.DealerConfig.HitOnSoftSeventeen = false; // Misc defaults. m_gameConfig.AllowSplit = true; m_gameConfig.AllowSurrender = false; // Add some AI players. m_players.push_back( new UserPlayer( 1 ) ); m_players.push_back( new AIPlayer( 2 ) ); m_players.push_back( new AIPlayer( 3 ) ); m_players.push_back( new AIPlayer( 4 ) ); /* Create game visualizer and input singletons */ GameInput::Create(); GameVisualizer::Create(); // Visualize game board GameVisuals()->Visualize( GameVisualizer::GameBoard ); // Initialize visualizations for player names & starting chips sPlayerXNameChanged nameData; sPlayerXSetChipsToY chipsData; for( uint index = 0; index < m_players.size(); ++index ) { nameData.playerIndex = index; nameData.name = std::string("Player ") + NumToStr( index + 1 ); chipsData.playerIndex = index; chipsData.chips = m_players[ index ]->GetChips(); GameVisuals()->Visualize( GameVisualizer::PlayerXNameChanged, (void*)&nameData ); GameVisuals()->Visualize( GameVisualizer::PlayerXSetChipsToY, (void*)&chipsData ); } }
//============================================================================= // Initialize Mega Man. // Post: returns true if successful, false if failed //============================================================================= bool chargingSprites::initialize(Game *gamePtr, int width, int height, int ncols, TextureManager *textureM) { // chargingSprites shooting sprite initialize megamanShootingSpriteCoordinates.populateVector("sprite_data\\xshootcoords.txt"); if (!initializeCoords(megamanShootingSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing chargingSprites")); megamanCharge1.initialize(gamePtr->getGraphics(), chargingSpritesNS::WIDTH, chargingSpritesNS::HEIGHT, 0, textureM); if (!megamanCharge1.initialize(megamanShootingSpriteCoordinates)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing chargingSprites")); megamanCharge1.setFrames(chargingSpritesNS::CHARGE1_MEGAMAN_START_FRAME, chargingSpritesNS::CHARGE1_MEGAMAN_END_FRAME); megamanCharge1.setCurrentFrame(chargingSpritesNS::CHARGE1_MEGAMAN_START_FRAME); megamanCharge1.setFrameDelay(chargingSpritesNS::CHARGE1_MEGAMAN_ANIMATION_DELAY); return(Entity::initialize(gamePtr, width, height, ncols, textureM)); }
//============================================================================= // Initializes the game // Throws GameError on error //============================================================================= void Spacewar::initialize(HWND hwnd) { Game::initialize(hwnd); // throws GameError if (!jpoTexture.initialize(graphics,JPO_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing jpo texture")); if (!jpo.initialize(graphics,JPO_WIDTH, JPO_HEIGHT, JPO_COLS, &jpoTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing jpo")); jpo.setX(GAME_WIDTH/4); // start above and left of planet jpo.setY(GAME_HEIGHT/4); jpo.setFrames(JPO_LOOKING_RIGHT_START, JPO_LOOKING_RIGHT_END); // animation frames jpo.setCurrentFrame(JPO_LOOKING_RIGHT_START); // starting frame jpo.setFrameDelay(JPO_ANIMATION_DELAY); lastDirection = right; keyDownLastFrame = false; keyDownThisFrame = false; return; }
//============================================================================= // Initializes the game // Throws GameError on error //============================================================================= void Spacewar::initialize(HWND hwnd) { Game::initialize(hwnd); // throws GameError this->counterText = new TextDX(); // initialize DirectX fonts // 15 pixel high Arial if(this->counterText->initialize(graphics, 15, true, false, "Arial") == false) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing DirectX font")); // nebula texture if (!nebulaTexture.initialize(graphics,NEBULA_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing nebula texture")); // main game textures if (!gameTextures.initialize(graphics,TEXTURES_IMAGE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing game textures")); // nebula image if (!nebula.initialize(graphics,0,0,0,&nebulaTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing nebula")); // planet if (!planet.initialize(this, planetNS::WIDTH, planetNS::HEIGHT, 2, &gameTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing planet")); // ship if (!ship1.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship1")); ship1.setFrames(shipNS::SHIP1_START_FRAME, shipNS::SHIP1_END_FRAME); ship1.setCurrentFrame(shipNS::SHIP1_START_FRAME); ship1.setX(GAME_WIDTH/4); ship1.setY(GAME_HEIGHT/4); ship1.setVelocity(VECTOR2(shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) // ship2 if (!ship2.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship2")); ship2.setFrames(shipNS::SHIP2_START_FRAME, shipNS::SHIP2_END_FRAME); ship2.setCurrentFrame(shipNS::SHIP2_START_FRAME); ship2.setX(GAME_WIDTH - GAME_WIDTH/4); ship2.setY(GAME_HEIGHT/4); ship2.setVelocity(VECTOR2(-shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) //ship3 if (!ship3.initialize(this, shipNS::WIDTH, shipNS::HEIGHT, shipNS::TEXTURE_COLS, &gameTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ship3")); ship3.setFrames(shipNS::SHIP3_START_FRAME, shipNS::SHIP3_END_FRAME); ship3.setCurrentFrame(shipNS::SHIP3_START_FRAME); ship3.setX(GAME_WIDTH - GAME_WIDTH/6); ship3.setY(GAME_HEIGHT/6); ship3.setVelocity(VECTOR2(-shipNS::SPEED,-shipNS::SPEED)); // VECTOR2(X, Y) return; }
//============================================================================= // Initializes the game // Throws GameError on error //============================================================================= void MegaMan::initialize(HWND hwnd) { Game::initialize(hwnd); // throws GameError // Initialize game resources if (!rmTexture->initialize(graphics, MEGAMAN_SPRITE)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing rockman texture")); megaman->spriteInitialize(graphics, rmTexture); return; }
//============================================================================= // Initialize DirectX graphics // throws GameError on error //============================================================================= void Graphics::initialize(HWND hw, int w, int h, bool full) { hwnd = hw; width = w; height = h; fullscreen = full; //initialize Direct3D direct3d = Direct3DCreate9(D3D_SDK_VERSION); if (direct3d == NULL) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing Direct3D")); initD3Dpp(); // init D3D presentation parameters // determine if graphics card supports harware texturing and lighting and vertex shaders D3DCAPS9 caps; DWORD behavior; result = direct3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &caps); // If device doesn't support HW T&L or doesn't support 1.1 vertex // shaders in hardware, then switch to software vertex processing. if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0 || caps.VertexShaderVersion < D3DVS_VERSION(1, 1)) behavior = D3DCREATE_SOFTWARE_VERTEXPROCESSING; // use software only processing else behavior = D3DCREATE_HARDWARE_VERTEXPROCESSING; // use hardware only processing //create Direct3D device result = direct3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, behavior, &d3dpp, &device3d); if (FAILED(result)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error creating Direct3D device")); }
Application::Application( std::string title, uint width, uint height ) : m_title( title ), m_wndWidth( width ), m_wndHeight( height ), m_isActive( true ) { if( m_pApplication ) { throw GameError( "[Application::Application]: Attempt to create multiple instances of singleton class Application." ); } m_pApplication = this; }
GameVisualizer::GameVisualizer() { if( m_pGameVisualizer ) throw GameError( "[GameVisualizer::GameVisualizer]: Attempt to instantiate multiple instances of singleton GameVisualizer." ); m_pGameVisualizer = this; // Create the player visual objects for( uint playerIndex = 0; playerIndex < GameMgr()->GetGameConfiguration().NumPlayers; ++playerIndex ) { m_playerVisuals.push_back( new PlayerVisual( playerIndex ) ); } }
// Initialize the game void Purgatory::initialize(HWND hwnd) { Game::initialize(hwnd); // throws GameError // scoreFont.initialize(graphics,25,false,false,"score"); if (!BgTexture.initialize(graphics,"ArtAssets\\Background.png")) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializingbackground")); // if (!PlayerTextures.initialize(graphics,"ArtAssets\\Jeramiah.png")) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing player")); // if (!enemyTexture.initialize(graphics,"pictures\\ghoul.png")) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing ENEMY")); // for(int j=0;j<2;j++) { if (!background[j].initialize(this, BgNS::WIDTH, BgNS::HEIGHT, &BgTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bg")); } // if (!player1.initialize(this, BumNS::WIDTH, BumNS::HEIGHT, BumNS::TEXTURE_COLS, &PlayerTextures)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing bum")); // for(int i =0;i<3;i++) { if (!enemy[i].initialize(this, BumNS::WIDTH, BumNS::HEIGHT, BumNS::TEXTURE_COLS, &enemyTexture)) throw(GameError(gameErrorNS::FATAL_ERROR, "Error initializing enemy")); enemy[i].setFrames(enemyNS::ENEMY_START_FRAME,enemyNS::ENEMY_END_FRAME); enemy[i].setCurrentFrame(enemyNS::ENEMY_START_FRAME); enemy[i].setColorFilter(SETCOLOR_ARGB(255,255,255,255)); enemy[i].setCollisionType(box); enemy[i].setEdge(ENEMY); enemy[i].setX(650); enemy[i].setY(350); } enemy[0].setVelocity(VECTOR2(0,enemyNS::SPEED1));enemy[1].seteID(1); enemy[1].setVelocity(VECTOR2(0,enemyNS::SPEED2));enemy[2].seteID(2); // player1.setFrames(BumNS::BUM_START_FRAME, BumNS::BUM_END_FRAME); player1.setCurrentFrame(BumNS::BUM_START_FRAME); player1.setColorFilter(SETCOLOR_ARGB(255,255,255,255)); player1.setCollisionType(box); player1.setEdge(PLAYER); // player1.setX(50); player1.setY(350); player1.setVelocity(VECTOR2(BumNS::JUMP_HEIGHT,BumNS::SPEED)); // playerScore=0; background[0].setX(0); background[1].setX(GAME_WIDTH-0); background[0].setY(0); background[1].setY(0); return; }
bool Player::initialize(Game *gamePtr, int width, int height, int ncols, TextureManager *textureM) { bool retVal = Entity::initialize(gamePtr, width, height, ncols, textureM); //Initialize the mirror texture if (!this->mirrorTexture.initialize(this->graphics, TURRET_MIRROR)) throw GameError(gameErrorNS::FATAL_ERROR, "Error initializing the player turret mirror texture"); //Initialize the turret texture if (!this->turretTexture.initialize(this->graphics, TURRET)) throw GameError(gameErrorNS::FATAL_ERROR, "Error initializing the player turret texture"); //Initialize the mirror object if (!this->mirror.initialize(gamePtr, playerMirrorNS::WIDTH, playerMirrorNS::HEIGHT, 1, &this->mirrorTexture)) throw GameError(gameErrorNS::FATAL_ERROR, "Error initializing the player turret mirror object"); //Initialize the turret object if (!this->turret.initialize(gamePtr, playerTurretNS::WIDTH, playerTurretNS::HEIGHT, 1, &this->turretTexture)) throw GameError(gameErrorNS::FATAL_ERROR, "Error initializing the player turret object"); turret.setColor(SETCOLOR_ARGB(255,152,254,178)); return retVal; }