bool DuckHuntMain::Init() { if (!D3DApp::Init()) return false; // Must init Effects first since InputLayouts depend on shader signatures. Effects::InitAll(md3dDevice); InputLayouts::InitAll(md3dDevice); RenderStates::InitAll(md3dDevice); mCrosshair = new Crosshair(md3dDevice); mTexMgr.Init(md3dDevice); DuckHuntMain::ShowCursors(false); mSky = new Sky(md3dDevice, L"Textures/desertcube1024.dds", 5000.0f); mSmap = new ShadowMap(md3dDevice, SMapSize, SMapSize); Terrain::InitInfo tii; tii.HeightMapFilename = L"Textures/myT5.raw"; tii.LayerMapFilename0 = L"Textures/grass.dds"; tii.LayerMapFilename1 = L"Textures/darkdirt.dds"; tii.LayerMapFilename2 = L"Textures/stone.dds"; tii.LayerMapFilename3 = L"Textures/lightdirt.dds"; tii.LayerMapFilename4 = L"Textures/snow.dds"; tii.BlendMapFilename = L"Textures/blend.dds"; tii.HeightScale = 50.0f; tii.HeightmapWidth = 2049; tii.HeightmapHeight = 2049; tii.CellSpacing = 0.5f; mTerrain.Init(md3dDevice, md3dImmediateContext, tii); //Sound result = FMOD::System_Create(&mSystem); result = mSystem->init(32, FMOD_INIT_NORMAL, 0); result = mSystem->createSound("Sounds/GunFire.wav", FMOD_DEFAULT, 0, &mGunFire); result = mGunFire->setMode(FMOD_LOOP_OFF); mCam.SetLens(0.25f*MathHelper::Pi, AspectRatio(), 1.0f, 1000.0f); mSsao = new Ssao(md3dDevice, md3dImmediateContext, mClientWidth, mClientHeight, mCam.GetFovY(), mCam.GetFarZ()); BuildScreenQuadGeometryBuffers(); testModelDuck = new BasicModel(md3dDevice, mTexMgr, "Models\\duck.obj", L"Textures\\DUCK.jpg"); BasicModelInstance testInstanceDuck; BasicModelInstance testInstanceDuck2; BasicModelInstance testInstanceDuck3; BasicModelInstance testInstanceDuck4; testInstanceDuck.Model = testModelDuck; testInstanceDuck2.Model = testModelDuck; testInstanceDuck3.Model = testModelDuck; testInstanceDuck4.Model = testModelDuck; //Duck 1 XMMATRIX modelScale = XMMatrixScaling(1.0f, 1.0f, -1.0f); XMMATRIX modelRot = XMMatrixRotationY(0.0f); XMMATRIX modelOffset = XMMatrixTranslation(0.0f, 0.0f, 0.0f); //Duck 2 XMMATRIX modelScale2 = XMMatrixScaling(2.0f, 2.0f, -1.0f); XMMATRIX modelRot2 = XMMatrixRotationY(-1.0f); XMMATRIX modelOffset2 = XMMatrixTranslation(1.0f, 1.0f, -1.0f); //Duck3 XMMATRIX modelScale3 = XMMatrixScaling(1.5f, 1.5f, 1.5f); XMMATRIX modelRot3 = XMMatrixRotationY(0.5f); XMMATRIX modelOffset3 = XMMatrixTranslation(2.0f, 1.0f, -1.0f); //Duck4 XMMATRIX modelScale4 = XMMatrixScaling(0.5f, 0.5f, -1.0f); XMMATRIX modelRot4 = XMMatrixRotationY(1.0f); XMMATRIX modelOffset4 = XMMatrixTranslation(0.5f, 1.0f, -1.0f); //Duck 1 XMStoreFloat4x4(&testInstanceDuck.World, modelScale*modelRot*modelOffset); mModelInstances.push_back(testInstanceDuck); //Duck 2 XMStoreFloat4x4(&testInstanceDuck2.World, modelScale2*modelRot2*modelOffset2); mModelInstances.push_back(testInstanceDuck2); //Duck 3 XMStoreFloat4x4(&testInstanceDuck3.World, modelScale3*modelRot3*modelOffset3); mModelInstances.push_back(testInstanceDuck3); //Duck 4 XMStoreFloat4x4(&testInstanceDuck4.World, modelScale4*modelRot4*modelOffset4); mModelInstances.push_back(testInstanceDuck4); //create collision box for (unsigned i = 0; i < mModelInstances.size(); i++) { mModelInstances[i].Model->CreateCollisionBox(mModelInstances[i].Model->BasicVertices); } // // Compute scene bounding box. // XMFLOAT3 minPt(+MathHelper::Infinity, +MathHelper::Infinity, +MathHelper::Infinity); XMFLOAT3 maxPt(-MathHelper::Infinity, -MathHelper::Infinity, -MathHelper::Infinity); for (UINT i = 0; i < mModelInstances.size(); ++i) { for (UINT j = 0; j < mModelInstances[i].Model->BasicVertices.size(); ++j) { XMFLOAT3 P = mModelInstances[i].Model->BasicVertices[j].Pos; minPt.x = MathHelper::Min(minPt.x, P.x); minPt.y = MathHelper::Min(minPt.x, P.x); minPt.z = MathHelper::Min(minPt.x, P.x); maxPt.x = MathHelper::Max(maxPt.x, P.x); maxPt.y = MathHelper::Max(maxPt.x, P.x); maxPt.z = MathHelper::Max(maxPt.x, P.x); } } // // Derive scene bounding sphere from bounding box. // mSceneBounds.Center = XMFLOAT3( 0.5f*(minPt.x + maxPt.x), 0.5f*(minPt.y + maxPt.y), 0.5f*(minPt.z + maxPt.z)); XMFLOAT3 extent( 0.5f*(maxPt.x - minPt.x), 0.5f*(maxPt.y - minPt.y), 0.5f*(maxPt.z - minPt.z)); mSceneBounds.Radius = sqrtf(extent.x*extent.x + extent.y*extent.y + extent.z*extent.z); return true; }
bool Game::Init(HINSTANCE hInstance) { if (!D3DApp::Init()) return false; // Must init Effects first since InputLayouts depend on shader signatures. Effects::InitAll(md3dDevice); InputLayouts::InitAll(md3dDevice); mTexMgr.Init(md3dDevice); mSky = new Sky(md3dDevice, L"Textures//sunsetcube1024.dds", 5000.0f); /// create the player PlayerOne = new Player(md3dDevice, mTexMgr, "Models\\gawky.obj", L"Textures\\", 0.0f, 10.0f, 0.0f); ModelLoader* modelLoader = new ModelLoader(); if( !PlayerOne->init( md3dDevice, modelLoader, mTexMgr, L"Textures\\" ) ) { wchar_t msgbuf[256]; wsprintf( msgbuf, L"\nPlayer Init Failed!!!\n\n"); OutputDebugString( msgbuf ); return false; } //// load the level models theEnemies = new Enemies(md3dDevice, mTexMgr); Objects = new TheObjects(md3dDevice, mTexMgr); Level1 = new LevelBuilder(md3dDevice, mTexMgr); Objects->createObject(branch, 60.0f, 0.25f, 55.0f, ctStumble, 1); Objects->createObject(branch, 0.0f, 0.25f, 20.0f, ctStumble, 1); Objects->createObject(orange, 80.0f, 30.0f, 20.0f, ctCollect, 1); Objects->createObject(orange, 20.0f, 4.0f, 20.0f, ctCollect, 1); Objects->createObject(orange, -80.0f, 10.0f, -60.0f, ctCollect, 1); //Objects->createObject(gatetwo, -95.0f, 8.5f, 0.0f, ctStumble, 7); theEnemies->createEnemy(simpleEnemy, -85.0f, 9.0f, 78.0f, -65.f, 9.0f, 78.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy); theEnemies->createEnemy(simpleEnemy, 55.0f, 3.0f, 80.0f, 55.0f, 3.0f, 60.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy); theEnemies->createEnemy(simpleEnemy, 0.0f, 3.0f, 45.0f, 0.0f, 3.0f, 25.0f, NULL, 0, 0, 0, 0, 0, 3, 15, ctEnemy); Level1->createLevelParts(Ground, 0, -1.8, 0, 0, 7, 0); ///left side 3 platforms Level1->createLevelParts(Platform, -76, 2.1, 26.6, 0, 7, 0); Level1->createLevelParts(Platform, -76, 9.1, 50.82, 0, 7, 0); Level1->createLevelParts(Platform, -76, 2.1, 74.2, 0, 7, 0); ///rightside 3 platforms Level1->createLevelParts(Platform, 73, 2.1, 75.6, 0, 7, 0); Level1->createLevelParts(Platform, 73, 9.1, 50.82, 0, 7, 0); Level1->createLevelParts(Platform, 73, 14.0, 15.82, 0, 7, 0); ///the tree's Level1->createLevelParts(SmallTree, -56, 15.4, 86.8, 0, 7, 0); Level1->createLevelParts(SmallTree, -56, 15.4, 72.8, 0, 7, 0); Level1->createLevelParts(SmallTree, -56, 15.4, 58.8, 0, 7, 0); /// large tree Level1->createLevelParts(TreeTrunk, 0, 14, 57.6, 0, 7, 0); Level1->createLevelParts(TreeTop, 0, 61.6, 57.6, 0, 7, 0); // the Fence Level1->createLevelParts(Fence1, 87, 5, 0, 0, 7, 0); Level1->createLevelParts(FencePart2, -95, 6, 48, 0, 7, 0); Level1->createLevelParts(FencePart2, -95, 6, -48, 0, 7, 0); Level1->createLevelParts(Fence2, -5, 6, 91, 0, 7, 0); Level1->createLevelParts(Fence2, -5, 6, -91, 0, 7, 0); //cattails Level1->createLevelParts(Cattail, 84, 5.6, -47.6, 0, 7, 0); Level1->createLevelParts(Cattail, 77, 5.6, -47.6, 0, 7, 0); Level1->createLevelParts(Cattail, 68.25, 5.6, -47.6, 0, 7, 0); Level1->createLevelParts(Cattail, 59.5, 5.6, -47.6, 0, 7, 0); Level1->createLevelParts(Cattail, 50.75, 5.6, -47.6, 0, 7, 0); /// the House Level1->createLevelParts(HouseSide, 43.4, 14, -70.0, 0, 7, 0); Level1->createLevelParts(HouseSide, 7, 14, -70.0, 0, 7, 0); Level1->createLevelParts(HouseBack, 24.5, 14, -82.6, 0, 7, 0); Level1->createLevelParts(HouseRoof, 24.5, 34.0, -70.5, 0, 6, 0); /// build the sandbox Level1->createLevelParts(SandBox, -60.9, 1.4, -68.0, 0, 7, 0); ////2nd section of level ////offset everything by -250 and -15 //the barn int x2o = -230; int y2o = 0; int z2o = 0; Level1->createLevelParts(lvl2Ground, 0 + x2o, -5 + y2o, 0.0 + z2o, ctLevel, 14, 0); Level1->createLevelParts(barnback, -81.56 + x2o, 22.8 + y2o, 136.8 + z2o, ctLevel, 23, 0); Level1->createLevelParts(barnside, -124.34 + x2o, 23.58 + y2o, 100.92 + z2o, ctLevel, 25, 0); Level1->createLevelParts(barnside, -36.34 + x2o, 23.58 + y2o, 100.92 + z2o, ctLevel, 25, 0); Level1->createLevelParts(barnfrontside, -44.74 + x2o, 23.74 + y2o, 64.96 + z2o, ctLevel, 25, 0); Level1->createLevelParts(barnfrontside2, -117.21 + x2o, 22.8 + y2o, 64.96 + z2o, ctLevel, 25, 0); Level1->createLevelParts(barnfronttop, -80.47 + x2o, 64.38 + y2o, 64.96 + z2o, ctLevel, 25, 0); Level1->createLevelParts(barnroof, -81.56 + x2o, 75.84 + y2o, 102.79 + z2o, ctLevel, 25, 0); /// 1.57 = 90 degrees Level1->createLevelParts(Fence1, -139 + x2o, 7 + y2o, 0 + z2o, ctLevel, 11, 0); Level1->createLevelParts(Fence1, 0 + x2o, 7 + y2o, 139 + z2o, ctLevel, 11, 1.57); Level1->createLevelParts(Fence1, 0 + x2o, 7 + y2o, -139 + z2o, ctLevel, 11, 1.57); //bails //bottom Row Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 129 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 11.6 + y2o, 129 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 120.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 111.48 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 0 + y2o, 102.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -100 + x2o, 0 + y2o, 128.98 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -86.68 + x2o, 0 + y2o, 128.98 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -86.68 + x2o, 5.5 + y2o, 128.98 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -86.68 + x2o, 11.6 + y2o, 128.98 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -103 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -93.9 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -84.98 + x2o, 0 + y2o, 118 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -103 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -93.9 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -85 + x2o, 0 + y2o, 104.9 + z2o, ctLevel, 7, 1.57); Level1->createLevelParts(squarebail, -114 + x2o, 5.5 + y2o, 120.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 11.6 + y2o, 120.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -114 + x2o, 5.5 + y2o, 111.48 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -100.6 + x2o, 5.5 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -100.6 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 119.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 119.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 111.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 111.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 102.4 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 102.4 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 0 + y2o, 94 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 5.5 + y2o, 94 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -72.7 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 0 + y2o, 94 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 5.5 + y2o, 94 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -59 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 128.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 119.9 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 111.2 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 102.4 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, 40 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 40 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 40 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, 54 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 54 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 54 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, 68.5 + x2o, 0 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 68.5 + x2o, 5.5 + y2o, -43 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 68.5 + x2o, 11.6 + y2o, -43 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, 54 + x2o, 0 + y2o, -52 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, 54 + x2o, 5.5 + y2o, -52 + z2o, ctLevel, 7, 0); // Level1->createLevelParts(squarebail, 40 + x2o, 0 + y2o, -52 + z2o, ctLevel, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 0 + y2o, 94 + z2o, ctNothing, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 5.5 + y2o, 94 + z2o, ctNothing, 7, 0); Level1->createLevelParts(squarebail, -45.3 + x2o, 11.6 + y2o, 94 + z2o, ctLevel, 7, 0); Level1->createLevelParts(roundbail, 41 + x2o, 9 + y2o, 52 + z2o, ctLevel, 14, 0); Level1->createLevelParts(roundbail, 67 + x2o, 9 + y2o, 52 + z2o, ctLevel, 14, 0); Level1->createLevelParts(woodpile, -130 + x2o, 4 + y2o, -127 + z2o, ctLevel, 1, 1.57); Objects->createObject(branch, 20 + x2o, -3 + y2o, -70 + z2o, ctStumble, 1); Objects->createObject(orange, 54 + x2o, 4 + y2o, 32 + z2o, ctCollect, 1); Objects->createObject(orange, 54 + x2o, 4 + y2o, -7 + z2o, ctCollect, 1); Objects->createObject(orange, -59 + x2o, 4 + y2o, 111 + z2o, ctCollect, 1); Objects->createObject(orange, -45 + x2o, 4 + y2o, 111 + z2o, ctCollect, 1); // Objects->createObject(orange, 54 + x2o, 35 + y2o, 53 + z2o, ctCollect, 1); Objects->createObject(orange, 54 + x2o, 35 + y2o, 13 + z2o, ctCollect, 1); Objects->createObject(orange, 54 + x2o, 35 + y2o, -27 + z2o, ctCollect, 1); theEnemies->createEnemy(simpleEnemy, 31 + x2o, 2 + y2o, -6 + z2o, 76 + x2o, 2 + y2o, -6 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy); theEnemies->createEnemy(simpleEnemy, 76 + x2o, 2 + y2o, 32 + z2o, 31 + x2o, 2 + y2o, 32 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy); theEnemies->createEnemy(simpleEnemy, 27 + x2o, 2 + y2o, -62 + z2o, 27 + x2o, 2 + y2o, -42 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy); theEnemies->createEnemy(simpleEnemy, 47 + x2o, 2 + y2o, -62 + z2o, 27 + x2o, 2 + y2o, -62 + z2o, NULL, 0, 0, NULL, 0, 0, 3, 15, ctEnemy); ///unkillable enemies must be placed at the end theEnemies->createEnemy(tractor, 4.0f + x2o, 13 + y2o, 88.0f + z2o, 4 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, 88 + z2o, 1, 30, ctUnkillable); theEnemies->createEnemy(tractor, 103 + x2o, 13 + y2o, -96 + z2o, 103 + x2o, 13 + y2o, 88 + z2o, 4.0f + x2o, 13 + y2o, 88.0f + z2o, 4 + x2o, 13 + y2o, -96 + z2o, 1, 30, ctUnkillable); theEnemies->CreateBoundingBox(); Objects->CreateBoundingBox(); Level1->CreateBoundingBox(); //////// ///////////////////////////////////////////////////////// std::vector <XNA::AxisAlignedBox> temp; temp = Level1->getLevelPartsCollisions(); for (UINT i = 0; i < temp.size(); i++) { LevelCollisions.push_back(temp[i]); } temp = Objects->getObjectCollisions(); for (UINT i = 0; i < temp.size(); i++) { LevelCollisions.push_back(temp[i]); totCollect++; } temp = theEnemies->getEnemyCollisions(); for (UINT i = 0; i < temp.size(); i++) { LevelCollisions.push_back(temp[i]); totEnemy++; } ////////////////////////////////////////////////////////// // create sound object HRESULT result;\ // init the sound object result = SoundSystem::Init(mhMainWnd); if (!result) { MessageBox(mhMainWnd, L"Could not initialize FMOD_Ex Sound!", L"Error", MB_OK); return true; // returning true or we'll drop out of game init = let game play even if sound load fails } return true; }