コード例 #1
0
 void ColoredCubeApp::reloadLevel()
{
	currentKeys = 0;
	flashLightObject.getBattery();
	//add in the maze reset function
	Dimension d;
	d.x=20;
	d.z = 20;
	maze.init(d,mfxWVPVar,mfxWorldVar,md3dDevice);
	maze.build();
	/*maze.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");	
	maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg");
	maze.setFloorTex(mfxDiffuseMapVar,mfxSpecMapVar,L"carpet_diffuse.jpg",L"brickwork-bump-map.jpg");*/

	for(int i = 0; i < numLightObjects; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		lamps[i].setPosition(Vector3(spot.x,5,spot.z));
	}
	for(int i = 0; i < totalKeys; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		keyObject[i].setPosition(Vector3(spot.x,-1,spot.z));
		keyObject[i].setActive();
	}
	for(int i = 0; i < numBatteries; i++)
	{
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		batteries[i].setPosition(Vector3(spot.x,-1,spot.z));
		batteries[i].setActive();
	}
}
コード例 #2
0
void ColoredCubeApp::initApp()
{
	D3DApp::initApp();
	//0: Parallel
	//1: Point
	//2: Spot

	hurtLight = D3DXCOLOR(1,0,0,1);

	ambientLight = D3DXCOLOR(0.3f, 0.03f, 0.2f, 1.0f);
	//ambientLight = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
	lights[1].ambient  = ambientLight;
	lights[1].diffuse  = D3DXCOLOR(0.0f, 0.02f, 0.02f, 1.0f);
	lights[1].specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	lights[1].att.x    = 1.0f;
	lights[1].att.y    = 0.0f;
	lights[1].att.z    = 0.0f;
	lights[1].spotPow  = 20;
	lights[1].range    = 100;
	lights[1].pos = D3DXVECTOR3(-10,20,-10);
	lights[1].dir = D3DXVECTOR3(0, -1, 0);	
	lights[1].lightType.x = 0;


	buildFX();
	buildVertexLayouts();

	Dimension d;
	d.x = 10;
	d.z = 10;
	mazeX = d.x;
	mazeZ = d.z;
	maze.init(d,mfxWVPVar,mfxWorldVar,md3dDevice);
	maze.build();
	maze.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");	
	maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg");
	maze.setFloorTex(mfxDiffuseMapVar,mfxSpecMapVar,L"carpet_diffuse.jpg",L"brickwork-bump-map.jpg");
	camera.init(&maze);

	mBox.init(md3dDevice, 1.0f);

	//testMesh.init(md3dDevice,1.0f,"surfrev2.dat");

	line.init(md3dDevice, 1.0f, DARKBROWN);
	line2.init(md3dDevice, 1.0f, RED);
	line3.init(md3dDevice, 1.0f, GREEN);

	origin.init(&line,&line2,&line3,mfxWVPVar,10);

	quad1.init(md3dDevice,1,D3DXCOLOR(0.5,0.25,0.1,1.0));

	//make the texture init in another function so it is not an issue switching between shaders
	/*floor.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3,0),Vector3(0,0,0),0,Vector3(20,0.1,20));
	floor.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"defaultspec.dds");

	wall1.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(-20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20));
	wall2.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(20,-3+20,0),Vector3(0,0,0),0,Vector3(0.1,20,20));
	wall3.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,20),Vector3(0,0,0),0,Vector3(20,20,0.1));
	wall4.init(&mBox,mfxWVPVar,mfxWorldVar,2,Vector3(0,-3+20,-20),Vector3(0,0,0),0,Vector3(20,20,0.1));*/

	player.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(10,0,10),Vector3(0,0,0),0,Vector3(1,1,1));
	player.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"brickwork-texture.jpg",L"brickwork-bump-map.jpg");
	Location start = maze.getStartPosition();
	start = maze.cellToPx(start);
	player.setPosition(Vector3(start.x+10,0,start.z+10));

	flashLightObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	flashLightObject.setRotation(Vector3(ToRadian(90),0,0));

	//lightObject1.init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	//lightObject1.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	for(int i = 0; i < numLightObjects; i++)
	{
		lamps[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,2,Vector3(10,3,0),Vector3(0,0,0),0,Vector3(0.75,0.75,0.75));
		lamps[i].setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		lamps[i].setPosition(Vector3(spot.x,5,spot.z));
		lamps[i].setColor(D3DXCOLOR(0.2f, 0.5f, 0.3f, 1.0f));
	}

	key.init(md3dDevice,1,"item1.txt");
	for(int i = 0; i < totalKeys; i++)
	{
		keyObject[i].init(&key,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		keyObject[i].setPosition(Vector3(spot.x,-1,spot.z));
	}

	endCube.init(&mBox,mfxWVPVar,mfxWorldVar,sqrt(3.0f),Vector3(0,0,0),Vector3(0,0,0),0,Vector3(2,2,2));
	endCube.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	Location end = maze.getEndPosition();
	end = maze.cellToPx(end);
	endCube.setPosition(Vector3(end.x,0,end.z));

	//set up the end light
	endLight.ambient  = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	endLight.diffuse  = D3DXCOLOR(1.0f, 1.0f, 0.3f, 1.0f);
	endLight.specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
	endLight.att.x    = 1.0f;
	endLight.att.y    = 0.0f;
	endLight.att.z    = 0.0f;
	endLight.spotPow  = 10;
	endLight.range    = 100;
	endLight.pos = D3DXVECTOR3(end.x,10,end.z);
	endLight.dir = D3DXVECTOR3(0, -1, 0);	
	endLight.lightType.x = 2;


	//batteryObject.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.25,0.25,0.25));
	for(int i = 0; i < numBatteries; i++)
	{
		batteries[i].init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(0,0,5),Vector3(0,0,0),0,Vector3(0.5,0.5,0.5));
		Location l;
		l.x = rand()%mazeX;
		l.z = rand()%mazeZ;
		auto spot = maze.cellToPx(l);
		batteries[i].setPosition(Vector3(spot.x,-1,spot.z));
	}

	ghosts.init(md3dDevice,mfxWVPVar,mfxWorldVar,sqrt(2.0f),Vector3(5,0,0),Vector3(0,0,0),10,Vector3(0.25,0.25,0.25));
	ghosts.setTex(mfxDiffuseMapVar,mfxSpecMapVar,L"WoodCrate01.dds",L"ice.dds");
	
	//Normalize(&mParallelLight.dir,&(flashLightObject.getPosition()-wall1.getPosition()));
	// init sound system
    audio = new Audio();
    if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0')  // if sound files defined
    {
        if( FAILED( hr = audio->initialize() ) )
        {
			exit(1);
            //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."));
        }
    }
	//set up the camera
	camera.setHeightAndWidth(mClientWidth,mClientHeight);

	audio->playCue(MUSIC);

	//input->initialize(this->getMainWnd(), false);  
	//sound object
	/*testSound = new SoundItem(audio,Vector3(0,0,0),50);
	static string sounds[] = {"gun_sound_effect","Light Bulb Breaking-SoundBible.com-53066515"};
	testSound->setSounds(sounds,2);*/
}