예제 #1
0
void ColoredCubeApp::shootBullet(GameObject playerBullets[], float dt, GameObject player)
{

    if ( shotBuffer.fireElapsed() < 0.6f)
        return;
    else
        shotBuffer.resetClock();
    /*for (int i = 0; i < MAX_NUM_BULLETS; i++)
    {
    if (playerBullets[i].getActiveState())
    continue;
    else
    {
    D3DXVECTOR3 position = player.getPosition();
    position.y = 0.5;
    playerBullets[i].setActive();
    playerBullets[i].setPosition(position);
    return;
    }
    }*/

    D3DXVECTOR3 position = player.getPosition();
    position.y = 0.5;

    audio->playCue(LASER);
    playerBullets[currentBullet].setActive();
    playerBullets[currentBullet].setPosition(position);

    camera.cameraRecoil(dt);

    currentBullet++;
    if(currentBullet >= MAX_NUM_BULLETS) currentBullet = 0;

    return;
}
예제 #2
0
void ColoredCubeApp::updateScene(float dt)
{
	timer -= dt;
    std::wostringstream outs;   
	if(timer<=0)
	{
		outs.clear();
		outs << L"GAME OVER\nFINAL SCORE: " << score;
		mTimer = outs.str();
		return;
	}

	outs.precision(2);
    outs << L"Time: " << timer << L"\n";
	outs.precision(3);
	outs << "Score: " << score;
	mTimer = outs.str();

	//store old position and reset it if collide, very hackish
	shootCube.setVelocity(moveCube());
	auto oldSpot = shootCube.getPosition();
	D3DApp::updateScene(dt);

	
	leftWall.update(dt);
	//floor.update(dt);
	rightWall.update(dt);
	//ceiling.update(dt);

	hitCubes->update(dt);
	avoidCubes->update(dt);

	//from game jam
	//if(((int)timer)%5==0)
	//{
	//	for(int i = 0; i < 20; i++)
	//	{
	//		if(!tiles[i].getActiveState())
	//		{
	//			tiles[i].setActive();
	//			tiles[i].setPosition(Vector3((-5+rand()%10)*3,0,(-5+rand()%10)*3));
	//			break;
	//		}
	//	}
	//}

	//for(int i = 0; i < 20; i++)
	//{
	//	tiles[i].update(dt);
	//	//wall[i].update(dt);
	//}

	shootCube.update(dt);

	for(int i = 0; i < 20; i++)
	{
		if(shootCube.collided(&tiles[i]))
		{
			tiles[i].setInActive();
			score++;
			audio->playCue(GUN_SHOT);
			//shootCube.setPosition(oldSpot);
		}
		//if(shootCube.collided(&wall[i]))
		//{
		//	//shootCube.setPosition(oldSpot);
		//	wall[i].setInActive();
		//}
	}
	
	int numHits = hitCubes->checkCollisions(shootCube);

	score+=numHits;

	int numBadHits = avoidCubes->checkCollisions(shootCube);
	score-=numBadHits;

	if(numHits>0)
	{
		audio->playCue(GUN_SHOT);
	}

	if(numBadHits>0)
	{
		audio->playCue(TARGET_SHATTER);
	}

	if(shootCube.getPosition().x<-18 || shootCube.getPosition().x>18 || shootCube.getPosition().z<-18 || shootCube.getPosition().z>18)
	{
		shootCube.setPosition(oldSpot);
	}

	// Build the view matrix.
	D3DXVECTOR3 pos(0.0f,50.0f,0.001f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
	D3DXMatrixLookAtLH(&mView, &pos, &target, &up);
}
예제 #3
0
void ColoredCubeApp::initApp()
{
	D3DApp::initApp();
	
	buildFX();
	buildVertexLayouts();

	mBox.init(md3dDevice, 1.0f, D3DXCOLOR(0.5,0.5,0.5,1));
	redBox.init(md3dDevice, 1.0f, DARKBROWN);
	greenBox.init(md3dDevice, 1.0f, D3DXCOLOR(0.1,0.1,0.8,1));
	shootBox.init(md3dDevice, 1.0f, BEACH_SAND);

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

	/*xLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1);
	xLine.setPosition(Vector3(0,0,0));
	yLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1);
	yLine.setPosition(Vector3(0,0,0));
	yLine.setRotationZ(ToRadian(90));
	zLine.init(&line, mfxWVPVar, Vector3(0,0,0), 1);
	zLine.setPosition(Vector3(0,0,0));
	zLine.setRotationY(ToRadian(90));*/

	shootCube.init(&shootBox,mfxWVPVar,sqrt(2.0f),Vector3(10,0,10),Vector3(0,0,0),0,Vector3(1,1,1));
	//shootCube.setRotation(Vector3(ToRadian(-20),ToRadian(45),0));

	leftWall.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(20,0,0),Vector3(0,0,0),0,Vector3(0.5,20,100));
	//leftWall.setRotation(Vector3(ToRadian(-20),ToRadian(45),0));

	floor.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(0,-5,0),Vector3(0,0,0),0,Vector3(20,0.2,20));
	//floor.setRotation(Vector3(ToRadian(-26),ToRadian(45),0));

	ceiling.init(&mBox,mfxWVPVar,sqrt(2.0f),Vector3(0,20,0),Vector3(0,0,0),0,Vector3(20,0.2,100));
	ceiling.setRotation(Vector3(ToRadian(-20),ToRadian(45),0));

	rightWall.init(&redBox,mfxWVPVar,sqrt(2.0f),Vector3(-20,0,0),Vector3(0,0,0),0,Vector3(0.5,20,100));
	//rightWall.setRotation(Vector3(ToRadian(-20),ToRadian(45),0));

	//srand(time(0));

	for(int i = 0; i < 20; i++)
	{
		tiles[i].init(&greenBox,mfxWVPVar,sqrt(2.0f),Vector3((-5+rand()%10)*3,-100,(-5+rand()%10)*3),Vector3(0,0,0),0,Vector3(1,1,1));
	}

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

	quad1.init(md3dDevice, 10, CYAN);
	quad1.setPosition(Vector3(0,0,0));

	spinAmount = 0;

	// 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."));
        }
    }

	hitCubes = new CubeHoard(100,10,5,5,1,-15,15,-15,15,-100,40);
	hitCubes->init(&redBox,mfxWVPVar,sqrt(4.0f),Vector3(0,0,0),Vector3(0,100,0),70,Vector3(2,2,2));

	avoidCubes = new CubeHoard(100,20,10,10,1,-20,20,-20,20,-100,50);
	avoidCubes->init(&greenBox,mfxWVPVar,sqrt(4.0f),Vector3(0,0,0),Vector3(0,100,0),70,Vector3(2,2,2));

	audio->playCue(MUSIC);

	//input->initialize(this->getMainWnd(), false);  

}
예제 #4
0
void ColoredCubeApp::updateScene(float dt)
{
    for (int i = 0; i < MAX_NUM_STARS; i++)
    {
        stars[i].update(dt);
    }

    switch (gsm->getGameState()) {
    case GameStateManager::START_GAME: {
        D3DApp::updateScene(dt);
        gameObject1.update(dt);
        D3DXMATRIX w;

        D3DXMatrixTranslation(&w, 2, 2, 0);
        mfxWVPVar->SetMatrix(w);

        score = 0;

        // Build the view matrix.
        /*D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f);
        D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
        D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
        D3DXMatrixLookAtLH(&mView, &pos, &target, &up);*/

        if(GetAsyncKeyState(VK_SPACE) & 0x8000 && gsm->getGameState() != GameStateManager::IN_GAME) {
            gsm->setGameState(GameStateManager::IN_GAME);
            audio->playCue(SELECT);
        }

        Vector3 oldEnemyPositions[MAX_NUM_ENEMIES];
        for (int i = 0; i < MAX_NUM_ENEMIES; i++)
        {
            oldEnemyPositions[i] = enemyObjects[i].getPosition();
        }

        Vector3 oldBulletPositions[MAX_NUM_BULLETS];
        for (int i = 0; i < MAX_NUM_BULLETS; i++)
        {
            oldBulletPositions[i] = playerBullets[i].getPosition();
        }

        //Camera Object
        camera.update(dt);
        break;
    }

    case GameStateManager::IN_GAME:
    {
        //Generate a block every three seconds
        if (enemyBuffer.elapsedTime() > 2) {
            enemyBuffer.resetClock();

            generateEnemy(enemyObjects, dt);
        }

        if (gameTimer.elapsedTime() >= 1) {
            gameTimer.resetClock();
            secondsRemaining--;
        }


        for (int i = 0; i < MAX_NUM_BULLETS; i++)
        {
            playerBullets[i].update(dt);
        }


        for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++)
        {
            particles[i].update(dt);
        }

        if (camera.isCameraRecoiling()) {
            camera.cameraRecoil(dt);
        }


        if(explosionRunning) explosionTimer += dt;
        if (explosionTimer > .55) {
            explosionTimer = 0;
            explosionRunning = false;
            for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++)
            {
                particles[i].setInActive();
            }
        }

        if(GetAsyncKeyState(VK_RETURN) & 0x8000) {
            if(shotRelease) {

                shootBullet(playerBullets, dt, gameObject1);

                //shotRelease = false;
            }
        }


        //if(!(GetAsyncKeyState(VK_RETURN) & 0x8000)) shotRelease = true;

        Vector3 oldEnemyPositions[MAX_NUM_ENEMIES];
        for (int i = 0; i < MAX_NUM_ENEMIES; i++)
        {
            oldEnemyPositions[i] = enemyObjects[i].getPosition();
        }

        Vector3 direction(0, 0, 0);
        Vector3 oldposition = gameObject1.getPosition();

        D3DApp::updateScene(dt);
        gameObject1.update(dt);
        for (int i = 0; i < MAX_NUM_ENEMIES; i++) {
            enemyObjects[i].update(dt);
        }

        if((GetAsyncKeyState('A') & 0x8000) && !(GetAsyncKeyState('D') & 0x8000))  direction.z = -1.0f;
        if((GetAsyncKeyState('D') & 0x8000) && !(GetAsyncKeyState('A') & 0x8000))  direction.z = +1.0f;

        D3DXVec3Normalize(&direction, &direction);

        for (int i = 0; i < MAX_NUM_ENEMIES; i++)
        {
            //if they collide and are active
            if(gameObject1.collided(&enemyObjects[i]) && enemyObjects[i].getActiveState())
            {
                audio->playCue(FAIL);
                enemyObjects[i].setInActive();
                //score++;
                camera.cameraShake(dt);
                score = 0;
                gsm->setGameState(GameStateManager::END_GAME);
            }


            if (enemyObjects[i].getPosition().x > 7) {
                enemyObjects[i].setInActive();
            }
        }

        for (int i = 0; i < MAX_NUM_BULLETS; i++)
        {
            for (int j = 0; j < MAX_NUM_ENEMIES; j++)
            {
                if(playerBullets[i].collided(&enemyObjects[j]) && enemyObjects[j].getActiveState())
                {
                    audio->playCue(BOOM);
                    explosionTimer = 0;
                    runExplosion(playerBullets[i].getPosition());
                    enemyObjects[j].setInActive();
                    playerBullets[i].setInActive();
                    score++;
                }
            }
        }


        gameObject1.setVelocity( direction * gameObject1.getSpeed());

        if (gameObject1.getPosition().z < -PLAYER_Z_RANGE) {
            gameObject1.setPosition(Vector3(oldposition.x, oldposition.y, -PLAYER_Z_RANGE));
            camera.setCameraMoveLeft(false);
            camera.setCameraMoveRight(true);
        }
        else if (gameObject1.getPosition().z > PLAYER_Z_RANGE) {
            gameObject1.setPosition(Vector3(oldposition.x, oldposition.y, PLAYER_Z_RANGE));
            camera.setCameraMoveRight(false);
            camera.setCameraMoveLeft(true);
        }
        else {
            camera.setCameraMoveRight(true);
            camera.setCameraMoveLeft(true);
        }

        //Destroys bullet if too far away
        for (int i = 0; i < MAX_NUM_BULLETS; i++)
        {
            if(playerBullets[i].getPosition().x < -10 && playerBullets[i].getActiveState())
                playerBullets[i].setInActive();
        }

        D3DXMATRIX w;

        D3DXMatrixTranslation(&w, 2, 2, 0);
        mfxWVPVar->SetMatrix(w);

        //Camera Object
        camera.update(dt);

        //Get Camera viewMatrix
        mView = camera.getViewMatrix();
        mProj = camera.getProjectionMatrix();
    }

    if (secondsRemaining <= 0)
    {
        gsm->setGameState(GameStateManager::END_GAME);
    }

    case GameStateManager::END_GAME:
    {
        //D3DApp::updateScene(dt);
        //gameObject1.update(dt);

        if (camera.isCameraShaking()) {
            camera.cameraShake(dt);
        }

        D3DXMATRIX w;

        D3DXMatrixTranslation(&w, 2, 2, 0);
        mfxWVPVar->SetMatrix(w);

        //// Build the view matrix.
        //D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f);
        //D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
        //D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
        //D3DXMatrixLookAtLH(&mView, &pos, &target, &up);

        if(GetAsyncKeyState(VK_SPACE) & 0x8000 && gsm->getGameState() != GameStateManager::IN_GAME) {
            restartGame();
            gsm->setGameState(GameStateManager::IN_GAME);
            audio->playCue(SELECT);
        }

        //Camera Object
        camera.update(dt);

        break;
    }


    default: {
        throw(GameError(gameErrorNS::FATAL_ERROR, "Game State Error"));
        break;
    }
    }
}
예제 #5
0
void ColoredCubeApp::initApp()
{

    D3DApp::initApp();
    //input->initialize(getMainWnd(), false);
    //audio->initialize();

    float boxScale = 0.5f;
    float collisionFixFactor = 1.1f;
    currentBullet = 0;
    explosionTimer = 0;
    explosionRunning = false;
    shotRelease = true;

    // increments when you run into a cube // just for now
    score = 0;
    mAxes.init(md3dDevice, 1.0f);
    mEnemy.init(md3dDevice, .5f, RED);
    mPlayer.init(md3dDevice, .5f, BLUE);
    mBullet.init(md3dDevice, .25f, D3DXCOLOR(0.0f, 1.0f, 0.0f, 0.0f));
    particleBox.init(md3dDevice, .01f, GREEN);
    particleBox2.init(md3dDevice, .04f, RED);
    starBox.init(md3dDevice, 0.05f, WHITE);
    //mBox.init(md3dDevice, boxScale);
    mLine.init(md3dDevice, 1.0f);
    //mTriangle.init(md3dDevice, 1.0f);
    //mQuad.init(md3dDevice, 10.0f);
    mQuad.init(md3dDevice, 0.0f);

    gameObject1.init(&mPlayer, sqrt(2.0f), Vector3(6,.5,0), Vector3(0,0,0), 5.0f,1.0f);
    //gameObject1.init(&mBox, sqrt(2.0f), Vector3(6,.5,0), Vector3(0,0,0), 5000.0f,1.0f);
    gameObject1.setRadius(gameObject1.getRadius()*boxScale*collisionFixFactor);

    int step = 2;
    for (int i = 0; i < MAX_NUM_ENEMIES; i++)
    {
        enemyObjects[i].init(&mEnemy, sqrt(2.0), Vector3(-5,.5,step*i - 3.8), Vector3(1,0,0), 8.0f, 1);
        //enemyObjects[i].init(&mBox, sqrt(2.0), Vector3(-5,.5,step*i - 3.8), Vector3(1,0,0), 3000.0f, 1);
        enemyObjects[i].setRadius(enemyObjects[i].getRadius()*boxScale * collisionFixFactor);
        enemyObjects[i].setInActive();
    }

    for (int i = 0; i < MAX_NUM_BULLETS; i++)
    {
        playerBullets[i].init(&mBullet, 0.5f, Vector3(0,0,0), Vector3(-12,0,0), 0.0f, 1);
        playerBullets[i].setInActive();
    }

    for (int i = 0; i < MAX_NUM_EXP_PARTICLES; i++)
    {

        if(i%5 == 0)particles[i].init(&particleBox2, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1);
        else particles[i].init(&particleBox, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1);
        particles[i].setInActive();
    }

    for (int i = 0; i < MAX_NUM_STARS; i++)
    {
        stars[i].init(&starBox, 0.5f, Vector3(0,0,0), Vector3(0,0,0), 7000.0f, 1);
        stars[i].setActive();
    }

    buildFX();
    buildVertexLayouts();

    audio = new Audio();

    if (*WAVE_BANK != '\0' && *SOUND_BANK != '\0')  // if sound files defined
    {
        if (!audio->initialize()) {

        }

        /*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."));
        }*/
    }

    enemyBuffer.resetClock();
    shotBuffer.resetClock();
    gameTimer.resetClock();


    D3DXVECTOR3 pos(10.0f, 2.0f, 0.0f);
    D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

    //Camera Object
    camera.init(pos, Vector3(0,0,0), Vector3(0,0,0));
    camera.setPerspective();
    // camera
    cameraPos = pos;

    audio->playCue(BKG);

    //Places stars in scene
    placeStars();
}
예제 #6
0
void ColoredCubeApp::updateScene(float dt)
{
	updateGameState();
	if(GetAsyncKeyState(VK_ESCAPE) & 0x8000) PostQuitMessage(0);
	if(gamestate == title)
	{
		float rad = 0.0f;
		camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true);
		maze.update(dt);
		if(once)
		{
			maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Title Screen.jpg",L"brickwork-bump-map.jpg");
			once = false;
		}
		ambientLight = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
		//set ceiling texture here
	}
	if(gamestate == controls)
	{
		float rad = 0.0f;
		camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true);
		maze.update(dt);
		if(onceAgain)
		{
			maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Rules Screen.jpg",L"brickwork-bump-map.jpg");
			onceAgain = false;
		}
		ambientLight = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
		//set ceiling texture here
	}
	if(gamestate == level1 || gamestate == level2)
	{
		ambientLight = D3DXCOLOR(0.3f, 0.03f, 0.2f, 1.0f);
		if(onceAgainStart)
		{
			maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"13.free-brick-textures.jpg",L"brickwork-bump-map.jpg");
			onceAgainStart = false;
		}
		if(GetAsyncKeyState('Y') & 0x8000)
			perspective = true;
		else
			perspective = false;
		if(oldBLevel!=0 && flashLightObject.getPowerLevel()<=0)
		{
			audio->playCue(BATTERY_DIE);
		}
		oldBLevel = flashLightObject.getPowerLevel();
		//check for win game conditions	
		auto oldP = player.getPosition();
		timer -= dt;
		std::wostringstream outs; 
		//update the camera
		camera.update(mTheta,mPhi,mRadius,0,dt,player,mView,mEyePos,perspective);
		//move the player
		camera.movePlayer(player,30,camera.getTarget(),perspective);
		player.update(dt);
		Location playerLoc;
		playerLoc.x = player.getPosition().x;
		playerLoc.z = player.getPosition().z;
		//collision detection
		if(player.getPosition()!=oldP)
		{
			if(maze.collided(playerLoc))
			{
				player.setPosition(oldP);
				player.setVelocity(Vector3(0,0,0));
				player.update(dt);
			}
		}

		for(int i = 0; i < numLightObjects; i++)
		{
			lamps[i].update(dt);
		}

		for(int i = 0; i < numBatteries; i++)
		{
			batteries[i].update(dt);
			if(player.collided(&batteries[i]))
			{
				batteries[i].setInActive();
				flashLightObject.getBattery();
				audio->playCue(BATTERY_CHARGE);
			}
		}

		if(gamestate == level1)
		{
			for(int i = 0; i < totalKeys; i++)
			{
				keyObject[i].update(dt);
				if(player.collided(&keyObject[i]))
				{
					currentKeys++;
					keyObject[i].setInActive();
					audio->playCue(ITEM);
				}
			}
		}

		if(gamestate==level2)
		{
			for(int i = 0; i < ghosts.getNumEnemies(); i++)
			{
				if(flashLightObject.hitTarget(&ghosts.getEnemies()[i]))
				{
					ghosts.getEnemies()[i].decreaseHealth();
					audio->playCue(G_HIT);
				}
			}
		}

		if(gamestate==level2)
		{
			if(player.collided(&endCube))
			{
				gamestate = win;
				maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"You Win.jpg",L"brickwork-bump-map.jpg");
				maze.update(dt);
			}
		}

		if(player.getHealth()<=0)
		{
			gamestate = gameover;
			maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"You Lose.jpg",L"brickwork-bump-map.jpg");
			maze.update(dt);
		}

		endCube.update(dt);

		lights[1].ambient = ambientLight;
		if(gamestate == level2)
		{
			for(int i = 0; i < ghosts.getNumEnemies(); i++)
			{
				//player gets hit by a ghost
				if(player.collided(&ghosts.getEnemies()[i]))
				{
					player.setHealth(player.getHealth()-1);
					lights[1].ambient = hurtLight;
					//make flash take longer
					ghosts.getEnemies()[i].setInActive();
					audio->playCue(P_HIT);
				}
			}
		}

		maze.update(dt);
	

		if(flashLightObject.getPosition()!=(player.getPosition()+(camera.getTarget()*5)))
		{
			flashLightObject.setPosition(player.getPosition() + camera.getTarget()*5);
			int i = 0;
		}

		//orientating the flashlight
		if(flashLightObject.lightSource.dir!=camera.getTarget())
		{
			//vectors for caluclating z-rotation
			Vector2 cameraXY = Vector2(camera.getTarget().x,camera.getTarget().y);
			Vector2 startXY = Vector2(flashLightObject.lightSource.dir.x,flashLightObject.lightSource.dir.y);
			//vectors for calculating y-rotation
			Vector2 cameraXZ = Vector2(camera.getTarget().x,camera.getTarget().z);
			Vector2 startXZ = Vector2(flashLightObject.lightSource.dir.x,flashLightObject.lightSource.dir.z);
			//vectors for calculating x-rotation
			Vector2 cameraYZ = Vector2(camera.getTarget().y,camera.getTarget().z);
			Vector2 startYZ = Vector2(flashLightObject.lightSource.dir.y,flashLightObject.lightSource.dir.z);

			float xAngle = flashLightObject.getRotation().x;
			float yAngle = flashLightObject.getRotation().y;
			float zAngle = flashLightObject.getRotation().z;
			float topEquation;
			float bottomEquation;

			topEquation = Dot2(&cameraXY,&startXY);
			bottomEquation = Length2(&cameraXY)*Length2(&startXY);
			if(bottomEquation>0)
			{
				zAngle+=acos((topEquation/bottomEquation));
			}

			topEquation = Dot2(&cameraXZ,&startXZ);
			bottomEquation = Length2(&cameraXZ)*Length2(&startXZ);
			if(bottomEquation>0)
			{
				yAngle+=acos((topEquation/bottomEquation));
			}

			topEquation = Dot2(&cameraYZ,&startYZ);
			bottomEquation = Length2(&cameraYZ)*Length2(&startYZ);
			if(bottomEquation>0)
			{
				xAngle+=acos((topEquation/bottomEquation));
			}

			flashLightObject.setRotation(Vector3(xAngle,yAngle,zAngle));
			flashLightObject.lightSource.dir = camera.getTarget();
		}

		flashLightObject.update(dt);
		//batteryObject.update(dt);
		ghosts.update(dt,&player);
		//lightObject1.update(dt);
		/*floor.update(dt);
		wall1.update(dt);
		wall2.update(dt);
		wall3.update(dt);
		wall4.update(dt);*/

		//flashLightObject.setRotation(

		/*if(player.collided(&batteryObject))
		{
			flashLightObject.getBattery();
		}*/
		//mParallelLight.pos = testCube.getPosition();
		//set up the flashlight light direction based on the direction the geometry is pointing
		//D3DXVec3Normalize(&mParallelLight.dir, &(playerCamera.getTarget()-testCube.getPosition()));

		outs.precision(2);
		outs << L"Health: " << player.getHealth() << L"\n";
		outs.precision(3);
		outs << "Battery: " << flashLightObject.getPowerLevel();
		mTimer = outs.str();
	}
	if(gamestate == gameover)
	{
		float rad = 0.0f;
		camera.update(mTheta,mPhi,rad,0,dt,player,mView,mEyePos,true);
		//set ceiling texture here
		if(onceAgainEnd)
		{
			maze.setCeilTex(mfxDiffuseMapVar,mfxSpecMapVar,L"Rules Screen.jpg",L"brickwork-bump-map.jpg");
			onceAgainEnd = false;
			onceAgainStart = true;
		}
	}
}
예제 #7
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);*/
}