void TilePlacementState::Update(float dt)
{
	UpdateKeyboardInput(dt);
	if (Next)
	{
		Next = false;
		mStateMachine->SetCurrState(mNextState);
	}

}
void PlayerTurnState::Update(float dt)
{
	col;
	row;
	PlayerTile->SetPos(XMVectorSet(PlayerPos.x, PlayerPos.y, 0.0f, 1.0f));
	UpdateKeyboardInput(dt);
	
	if (Next)
	{
		Next = false;
		mStateMachine->SetCurrState(mNextState);
	}
}
void TilePlacementState::Update(float dt)
{
	curCol;
	curRow;

	TileToBePlaced->SetPos(XMVectorSet(TilePos.x, TilePos.y, 0.0f, 1.0f));

	UpdateKeyboardInput(dt);
	if (Next)
	{
		Next = false;
		mNextState->Init();
		mStateMachine->SetCurrState(mNextState);
	}
	
}
コード例 #4
0
void InClassProj::UpdateScene(float dt)
{
	ID3D11RasterizerState* rs;
	D3D11_RASTERIZER_DESC rsd;
	rsd.CullMode = D3D11_CULL_NONE;
	rsd.AntialiasedLineEnable = false;
	rsd.DepthBias = 0.0f;
	rsd.DepthBiasClamp = 0.0f;
	rsd.DepthClipEnable = true;
	rsd.FillMode = D3D11_FILL_SOLID;
	rsd.FrontCounterClockwise = true;
	rsd.MultisampleEnable = true;
	rsd.ScissorEnable = false;
	rsd.SlopeScaledDepthBias = 0.0f;
	md3dDevice->CreateRasterizerState(&rsd, &rs);
	md3dImmediateContext->RSSetState(rs);

	if (recoverTime > 0.0f)
	{
		recoverTime = recoverTime - dt;
	}
	else
	{
		recoverTime = 0.0f;
	}

	playerBB.pos.x = mPlayer->GetPos().m128_f32[0];
	playerBB.pos.y = mPlayer->GetPos().m128_f32[1];

	UpdateKeyboardInput(dt);
	
	m2DCam->Update();

	//update particles
	/*for (int i = 0; i < mParticles.size(); ++i)
	{
		XMVECTOR vel = XMLoadFloat3(&mParticles[i].vel);
		XMVECTOR pos = XMLoadFloat3(&mParticles[i].pos);
		pos = pos + vel;
		XMStoreFloat3(&mParticles[i].pos, pos);
	}
	UpdateParticleVB();*/

	//update player
	mPlayer->Update(dt);
	mPlayer->AddForce(XMVectorSet(0.0f, -9.8f, 0.0f, 0.0f));   //adds gravity
	//update enemy damage done to player
	for (int i = 0; i < enemies.size(); ++i)
	{
		if (PlayerEnemyCollision(mPlayer, enemies[i]) && recoverTime == 0.0f)
		{
			enemies[i]->ApplyDamage(mPlayer);
			recoverTime = 3.0f;   //player has 3 seconds before damage can be done to him again
		}
	}
	if (mPlayer->GetHealth() == 0)
	{ 
		//switch to game over state to display game over screen
	}

	//update enemies
	for (int i = 0; i < enemies.size(); ++i)
	{
		enemies[i]->Update(dt);
		enemies[i]->Chase(enemies, mPlayer, dt);

		//set health bars to above enemies' heads and red bar to adjust accordingly
		redXPos = enemies[i]->GetPos().m128_f32[0];
		currHealth = enemies[i]->GetHealth();
		maxHealth = 5.0f;
		ratio = 1.0f - (currHealth / maxHealth);
		redXPos += ((1.0f - ratio) / 2.0f) * 32.0f;
		redXScale = ratio/* * 32.0f*/;
		greenBarVec[i]->SetPos(XMVectorSet(enemies[i]->GetPos().m128_f32[0], enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetPos(XMVectorSet(redXPos, enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetScale(XMVectorSet(redXScale, 1.0f, 0.0f, 0.0f));

		//collision checks between enemies and playerBB		
		SpriteRectCollision(enemies[i], playerBB);

		//collision checks between enemies and environmentBBs
		for (int j = 0; j < boxes.size(); ++j)
		{
			SpriteRectCollision(enemies[i], boxes[j]);
		}

		//delete enemy upon death
		if (enemies[i]->GetHealth() == 0)
		{
			delete enemies[i];
			enemies.erase(enemies.begin() + i);
			i--;
			break;
		}
	}
	//when all enemies eliminated:
	if (enemies.size() == 0)
	{
  		EOLobjActive = true;
	}

	//collision between playerBB and environmentBBs
	for (int i = 0; i < boxes.size(); ++i)
	{
		RectRectCollision(playerBB, boxes[i], mPlayer);

		//update mGrounded bool for player jump
		if (RectRectCollision(playerBB, boxes[i], mPlayer) == CollisionSide::bot)
		{
			mPlayer->HitGround();
		}
	}

	//update projectiles
	for (int i = 0; i < mProjectiles.size(); ++i)
	{
 		mProjectiles[i]->Update(dt);
		for (int j = 0; j < enemies.size(); ++j)
		{
			if (mProjectiles[i]->GetDistanceTravelled() > mProjectiles[i]->MAX_DISTANCE ||
				mProjectiles[i]->GetDistanceTravelled() < mProjectiles[i]->MIN_DISTANCE)
			{
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
			//collision checks between enemies and projectiles	
			if (EnemyProjCollision(enemies[j], mProjectiles[i]))
			{
				mProjectiles[i]->ApplyDamage(enemies[j]);
				/*std::wstringstream ss;
				ss << enemies[j]->GetHealth();
				OutputDebugString(ss.str().c_str());
				OutputDebugString(L"\n");*/
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
		}
	}

	EOLobj->Update(dt);
		
	//update sounds
	sys->update();
}
コード例 #5
0
ファイル: Game.cpp プロジェクト: RyanJeff/JetpackArcher
void Game::UpdateScene(ID3D11DeviceContext* md3dImmediateContext, ID3D11Device* md3dDevice, float dt, JetpackArcher* instance)
{
	controlsTimer += dt;

	ID3D11RasterizerState* rs;
	D3D11_RASTERIZER_DESC rsd;
	rsd.CullMode = D3D11_CULL_NONE;
	rsd.AntialiasedLineEnable = false;
	rsd.DepthBias = 0.0f;
	rsd.DepthBiasClamp = 0.0f;
	rsd.DepthClipEnable = true;
	rsd.FillMode = D3D11_FILL_SOLID;
	rsd.FrontCounterClockwise = true;
	rsd.MultisampleEnable = true;
	rsd.ScissorEnable = false;
	rsd.SlopeScaledDepthBias = 0.0f;
	md3dDevice->CreateRasterizerState(&rsd, &rs);
	md3dImmediateContext->RSSetState(rs);

	if (recoverTime > 0.0f)
	{
		recoverTime = recoverTime - dt;
	}
	else
	{
		recoverTime = 0.0f;
	}

	playerBB.pos.x = mPlayer->GetPos().m128_f32[0];
	playerBB.pos.y = mPlayer->GetPos().m128_f32[1];

	UpdateKeyboardInput(md3dDevice, dt);

	m2DCam->Update();

	//update player
	mPlayer->Update(dt);
	mPlayer->AddForce(XMVectorSet(0.0f, -9.8f, 0.0f, 0.0f));   //adds gravity
	//update jetpack flame
	if (isFacingRight)
	{
		mFlame->SetPos(XMVectorSet(mPlayer->GetPos().m128_f32[0] - 5, mPlayer->GetPos().m128_f32[1] - 16, 0.0f, 0.0f));
	}
	else if (!isFacingRight)
	{
		mFlame->SetPos(XMVectorSet(mPlayer->GetPos().m128_f32[0] + 5, mPlayer->GetPos().m128_f32[1] - 16, 0.0f, 0.0f));
	}
	mFlame->Update(dt);
	//update enemy damage done to player
	for (int i = 0; i < enemies.size(); ++i)
	{
		if (PlayerEnemyCollision(mPlayer, enemies[i]) && recoverTime == 0.0f)
		{
			enemies[i]->ApplyDamage(mPlayer);
			recoverTime = 3.0f;   //player has 3 seconds before damage can be done to him again
		}
	}
	//set player health bar
	redXPosP = 60.0f;
	currHealthP = mPlayer->GetHealth();
	maxHealthP = 3.0f;
	ratioP = 1.0f - (currHealthP / maxHealthP);
	redXPosP += ((1.0f - ratioP) / 2.0f) * 96.0f; //96 is barSize
	redXScaleP = ratioP;
	mGreenHBarP->SetPos(XMVectorSet(60.0f, 736.0f, 0.0f, 0.0f));
	mRedHBarP->SetPos(XMVectorSet(redXPosP, 736.0f, 0.0f, 0.0f));
	mRedHBarP->SetScale(XMVectorSet(redXScaleP, 1.0f, 0.0f, 0.0f));
	//player dead / game over
	if (mPlayer->GetHealth() == 0)
	{
		instance->SetState(JetpackArcher::States::GAME_OVER);
	}
	//collision between player and end of level object / game won
	if (RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::top || 
		RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::left || 
		RectRectCollision(playerBB, EOLobjBB, mPlayer) == CollisionSide::right)
	{
		instance->SetState(JetpackArcher::States::GAME_WON);
	}

	//update enemies
	for (int i = 0; i < enemies.size(); ++i)
	{
		enemies[i]->Update(dt);
		enemies[i]->Chase(enemies, mPlayer, dt);
		//set health bars to above enemies' heads and red bar to adjust accordingly
		redXPos = enemies[i]->GetPos().m128_f32[0];
		currHealth = enemies[i]->GetHealth();
		maxHealth = 5.0f;
		ratio = 1.0f - (currHealth / maxHealth);
		redXPos += ((1.0f - ratio) / 2.0f) * 32.0f; //32 is barSize
		redXScale = ratio;
		greenBarVec[i]->SetPos(XMVectorSet(enemies[i]->GetPos().m128_f32[0], enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetPos(XMVectorSet(redXPos, enemies[i]->GetPos().m128_f32[1] + 32, 0.0f, 0.0f));
		redBarVec[i]->SetScale(XMVectorSet(redXScale, 1.0f, 0.0f, 0.0f));
		//collision checks between enemies and playerBB		
		SpriteRectCollision(enemies[i], playerBB);
		//collision checks between enemies and environmentBBs
		for (int j = 0; j < boxes.size(); ++j)
		{
			SpriteRectCollision(enemies[i], boxes[j]);
		}
		//delete enemy upon death
		if (enemies[i]->GetHealth() == 0)
		{
			delete enemies[i];
			enemies.erase(enemies.begin() + i);
			i--;
			break;
		}
	}
	//when all enemies eliminated:
	if (enemies.size() == 0)
	{
		EOLobjActive = true;
		EOLobjBB.pos = XMFLOAT2(EOLobj->GetPos().m128_f32[0], EOLobj->GetPos().m128_f32[1]);
		EOLobjBB.height = 32.0f;
		EOLobjBB.width = 32.0f;
	}

	//collision between playerBB and environmentBBs
	for (int i = 0; i < boxes.size(); ++i)
	{
		RectRectCollision(playerBB, boxes[i], mPlayer);

		//update mGrounded bool for player jump
		if (RectRectCollision(playerBB, boxes[i], mPlayer) == CollisionSide::bot)
		{
			mPlayer->HitGround();
		}
	}

	//update projectiles
	for (int i = 0; i < mProjectiles.size(); ++i)
	{
		mProjectiles[i]->Update(dt);
		for (int j = 0; j < enemies.size(); ++j)
		{
			if (mProjectiles[i]->GetDistanceTravelled() > mProjectiles[i]->MAX_DISTANCE ||
				mProjectiles[i]->GetDistanceTravelled() < mProjectiles[i]->MIN_DISTANCE)
			{
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
			//collision checks between enemies and projectiles	
			if (EnemyProjCollision(enemies[j], mProjectiles[i]))
			{
				mProjectiles[i]->ApplyDamage(enemies[j]);
				delete mProjectiles[i];
				mProjectiles.erase(mProjectiles.begin() + i);
				i--;
				break;
			}
		}
	}

	mGreenFuel->Update(dt);
	mRedFuel->Update(dt);
	EOLobj->Update(dt);
}