Exemple #1
0
void Camera::Update(GameTime gameTime)
{
	// Check for movement of the camera.
	if(GetAsyncKeyState('Q'))
		MoveLeft(gameTime);
	else if(GetAsyncKeyState('E'))
		MoveRight(gameTime);

	if(GetAsyncKeyState('W'))
		MoveForward(gameTime);
	else if(GetAsyncKeyState('S'))
		MoveBack(gameTime);

	if(GetAsyncKeyState('A'))
		TurnHorizontal((float)(-gameTime.GetTimeSinceLastTick().Milliseconds) * C_TILTING_SPEED);
	else if(GetAsyncKeyState('D'))
		TurnHorizontal((float)gameTime.GetTimeSinceLastTick().Milliseconds * C_TILTING_SPEED);

	// Check for tilting of camera.
	//if(GetAsyncKeyState(VK_LBUTTON))
	//{
	//	float dx = prevInput.Mouse.x - currInput.Mouse.x;
	//	float dy = prevInput.Mouse.y - currInput.Mouse.y;
	//	//TurnHorizontal(dx * C_TILTING_SPEED);
	//	//TurnVertical(dy * C_TILTING_SPEED);
	//}
}
Exemple #2
0
bool Xiq::Update(GameTime time)
{
	float t = time.TotalElapsedSeconds();
	SetRadius(radius_waves[0](t) + radius_waves[1](t));

	angle += RandomRanged(-0.3f, 0.3f);
	while (angle > math::two_pi)
		angle -= math::two_pi;
	while (angle < 0)
		angle += math::two_pi;

	Vector center = location + steer*sqrt(2.0f);
	Point target = center + Vector(cos(angle), sin(angle));
	steer = (target - location).Normalised();
	force += steer*5;

	// see http://en.wikipedia.org/wiki/Verlet_integration:
	// np = p0*2 - p1 + a*t*t;
	// p1 = p0
	// p0 = np
	//
	// i have fudged this here to enforce constant speed:

	float dt = 1.0f/60.0f;
	Vector accel = force*(1.0f/mass);
	Point next_location = location*2.0f - last_pos + accel*dt*dt;

	Vector vel = (next_location - location).Normalised()*speed*time.DeltaSeconds();

	last_pos = location;
	location += vel;
	force = Vector(0,0);

	return true;
}
Exemple #3
0
	void InfoPanel::update(const GameTime& game_time) {
		if (game_time.total_game_time() - m_last_total_elapsed_time >= 1) {
			m_last_total_elapsed_time = game_time.total_game_time();
			m_frame_rate = m_frame_count;
			m_frame_count = 0;
		}
		++m_frame_count;
	}
Exemple #4
0
  void FpsComponent::Update(const GameTime& gameTime) {
    if (gameTime.TotalGameTime() - mLastTotalElapsedTime >= 1) {
      mLastTotalElapsedTime = gameTime.TotalGameTime();
      mFrameRate = mFrameCount;
      mFrameCount = 0;
    }

    mFrameCount++;
  }
	void GameClock::UpdateGameTime(GameTime& gameTime)
	{
		mCurrentTime = high_resolution_clock::now();

		gameTime.SetCurrentTime(mCurrentTime);
		gameTime.SetTotalGameTime(duration_cast<milliseconds>(mCurrentTime - mStartTime));
		gameTime.SetElapsedGameTime(duration_cast<milliseconds>(mCurrentTime - mLastTime));
		mLastTime = mCurrentTime;
	}
Exemple #6
0
void StatusText::Update(const GameTime & gameTime)
{
    if (m_endTime == TimeSpan::Zero())
        m_endTime = gameTime.Current() + m_duration;

    if (gameTime.Current() > m_endTime)
        m_displaying = false;

    float percentLife = (float)((m_endTime.ms() - gameTime.Current().ms()) / (float)m_duration.ms());
    m_textColor = Color::Lerp(m_endColor, m_startColor, percentLife);
}
Exemple #7
0
int main(int argc, char* args[])
{
	//Run and check if the initialize function returns false
	//and if so, it prints an error and ends the program
	if (!Initialize())
	{
		printf("Could not initialize!\n");
		return -1;
	}
	
	bool run = true;
	
	EventHandler e;
	GameTime t;

	//Create a Vector (List) of all Rooms (Levels)
	std::vector<Room_MainParent*> rooms
	{
		new Room_TestRoom(renderer, 2000, 2000, 0, 0)
	};

	//Main game loop
	while (run)
	{
		//EVENTS
		e.update();
		t.update();

		//Exit event or escape key
		if (e.getEvent(SDL_QUIT))
			run = false;

		//Update the current room
		rooms[0]->mainUpdate(e, t);
		//rooms[0]->update(e, t);

		//RENDERING
		//Clear the Window
		SDL_RenderClear(renderer);

		//Render all items in the current room
		rooms[0]->mainRender();

		//Update the renderer (Screen)
		SDL_RenderPresent(renderer);
	}

	return 0;
}
	void AnimationPlayer::Update(const GameTime& gameTime)
	{
		if (mIsPlayingClip)
		{
			assert(mCurrentClip != nullptr);

			mCurrentTime += (static_cast<float>(gameTime.ElapsedGameTime().count()) / 1000.0f) * mCurrentClip->TicksPerSecond();
			if (mCurrentTime >= mCurrentClip->Duration())
			{
				if (mIsClipLooped)
				{
					mCurrentTime = 0.0f;
				}
				else
				{
					mIsPlayingClip = false;
					return;
				}
			}

			if (mInterpolationEnabled)
			{
				GetInterpolatedPose(mCurrentTime, *(mModel->RootNode()));
			}
			else
			{
				GetPose(mCurrentTime, *(mModel->RootNode()));
			}
		}
	}
Exemple #9
0
	void DebugSystem::Update( const GameTime& gameTime_ )
	{
		m_fFPSTime += gameTime_.FrameTime();
		m_iFPSCount++;
		
		if (m_fFPSTime >= 1.0f)
		{
			//AverageDrawCalls = drawCallThisSecond / m_iFPSCount;
			//AverageTrianglesDrawn = trianglesDrawnThisSecond / m_iFPSCount;
			//Reset startSecondTick and repaintCountSecond

			m_fFPSTime -= 1.0f;
			float FPSDelta = (float)m_iFPSCount * m_fFPSTime;			
			//FPS - delta, to reduce the calculation to 1 second precisely
			m_iLastFPSCount = (int)( (float)m_iFPSCount - FPSDelta + m_fFPSLastDelta );

			m_iFPSCount = 0;
			m_fFPSLastDelta = FPSDelta;
			//drawCallThisSecond = 0;
			//trianglesDrawnThisSecond = 0;

			//CA_TRACE("FPS %d\n", m_iLastFPSCount);

			GlobalEventSet::Instance().fireEvent(
				FPSChangeEvent::FPSChangeEventName,
				FPSChangeEvent(m_iLastFPSCount));
		}
	}
	void SpecularLightingDemo::UpdateAmbientLight(const GameTime& gameTime)
	{
		float elapsedTime = gameTime.ElapsedGameTimeSeconds().count();
		static float ambientr = mPSCBufferPerFrame.AmbientColor.x;
		static float ambientg = mPSCBufferPerFrame.AmbientColor.y;
		static float ambientb = mPSCBufferPerFrame.AmbientColor.z;

		//Color
		if (mKeyboard->IsKeyDown(Keys::NumPad1) || mGamePad->IsButtonDown(GamePadButtons::A)) {
			ambientr = max(0.0f, min(ambientr + elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
		else if (mKeyboard->IsKeyDown(Keys::D1) || mGamePad->IsButtonDown(GamePadButtons::X)) {
			ambientr = max(0.0f, min(ambientr - elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
		if (mKeyboard->IsKeyDown(Keys::NumPad2) || mGamePad->IsButtonDown(GamePadButtons::A)) {
			ambientg = max(0.0f, min(ambientg + elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
		else if (mKeyboard->IsKeyDown(Keys::D2) || mGamePad->IsButtonDown(GamePadButtons::X)) {
			ambientg = max(0.0f, min(ambientg - elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
		if (mKeyboard->IsKeyDown(Keys::NumPad3) || mGamePad->IsButtonDown(GamePadButtons::A)) {
			ambientb = max(0.0f, min(ambientb + elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
		else if (mKeyboard->IsKeyDown(Keys::D3) || mGamePad->IsButtonDown(GamePadButtons::X)) {
			ambientb = max(0.0f, min(ambientb - elapsedTime, 1.0f));
			mPSCBufferPerFrame.AmbientColor = XMFLOAT4(ambientr, ambientg, ambientb, 1.0f);
		}
	}
bool Application::OnUpdate()
{
	//System Update
	m_pMouse->Update();
	m_pKeyboard->Update();
	m_pCamera->Update();
	m_pGameTime->Update();

	//m_fRot += PI * GameTime::GetTimeElapsed();
	//m_pScene->SetRotateY(m_fRot);

	m_pScene->Update();

	if(m_pKeyboard->IsKeyPressed(KEY_1))
	{
		m_pParent->DetachChild(m_pChild);
	}
	else if(m_pKeyboard->IsKeyPressed(KEY_2))
	{
		m_pParent->AttachChild(m_pChild);
	}

	m_pChild->Update();

	DX11Camera::FreeLookCamera(m_pCamera,10.0f);
	//m_pCamera->LookAt(D3DXVECTOR3(0,0,0));

	

	//Window Update
	return m_pWindow->Tick();
}
Exemple #12
0
// Move camera forwards: walk
void Camera::MoveForward(GameTime& gameTime)
{
	D3DXVECTOR3 forward;

	forward = mDirection - (D3DXVec3Dot(&mDirection, &mWorldUp) * mWorldUp);
	D3DXVec3Normalize(&forward, &forward);
	mPosition += forward * C_MOVE_SPEED * (float)gameTime.GetTimeSinceLastTick().Seconds;
}
void AsteroidsGame::OnUpdate(const GameTime& time)
{
	updateBound();
	collisionDetect(time); 
	auto title = "Time: " + to_string(time.TotalSeconds()) + " Score: " + to_string(score);
	title += " Life: " + to_string(life) + " Level: " + to_string(level);
	glfwSetWindowTitle(m_window, title.c_str());
}
void PPhysics2D::v_updateEntity(entityID id, const GameTime& gameTime) {
    CRigidBody *body = getEntityAs<CRigidBody>(id);
    CTransform *transform = getEntityAs<CTransform>(id);

    //transform->m_position.addScaledVector(body->m_velocity, gameTime.getElapsedSecond());
    transform->setX(transform->getX()  + body->m_velocity.x * gameTime.getElapsedSecond());
    transform->setY(transform->getY()  + body->m_velocity.y * gameTime.getElapsedSecond());
    if (body->m_bApplyGravity) {
        body->addForce(glm::vec2(.0f, 200.0f));
    }
    //body->m_velocity.addScaledVector(body->m_forceAccum, gameTime.getElapsedSecond());
    body->m_velocity.x += body->m_forceAccum.x * gameTime.getElapsedSecond();
    body->m_velocity.y += body->m_forceAccum.y * gameTime.getElapsedSecond();

    body->m_velocity *= powf(body->m_damping, gameTime.getElapsedSecond());

    body->clearForce();
}
 void BlinnPhongDemo::UpdateDirectionalLight(const GameTime& gameTime)
 {
     static float directionalIntensity = 1.0f;
     float elapsedTime = (float)gameTime.ElapsedGameTime();
     
     // Upddate directional light intensity
     if (glfwGetKey(mGame->Window(), GLFW_KEY_T) && directionalIntensity < 1.0f)
     {
         directionalIntensity += elapsedTime;
         directionalIntensity = glm::min(directionalIntensity, 1.0f);
         
         mDirectionalLight->SetColor(vec4((vec3)directionalIntensity, 1.0f));
     }
     if (glfwGetKey(mGame->Window(), GLFW_KEY_G) && directionalIntensity > 0.0f)
     {
         directionalIntensity -= elapsedTime;
         directionalIntensity = glm::max(directionalIntensity, 0.0f);
         
         mDirectionalLight->SetColor(vec4((vec3)directionalIntensity, 1.0f));
     }
     
     // Rotate directional light
     vec2 rotationAmount = Vector2Helper::Zero;
     if (glfwGetKey(mGame->Window(), GLFW_KEY_LEFT))
     {
         rotationAmount.x += LightRotationRate.x * elapsedTime;
     }
     if (glfwGetKey(mGame->Window(), GLFW_KEY_RIGHT))
     {
         rotationAmount.x -= LightRotationRate.x * elapsedTime;
     }
     if (glfwGetKey(mGame->Window(), GLFW_KEY_UP))
     {
         rotationAmount.y += LightRotationRate.y * elapsedTime;
     }
     if (glfwGetKey(mGame->Window(), GLFW_KEY_DOWN))
     {
         rotationAmount.y -= LightRotationRate.y * elapsedTime;
     }
     
     mat4 lightRotationMatrix;
     if (rotationAmount.x != 0)
     {
         lightRotationMatrix = glm::rotate(mat4(), rotationAmount.x, Vector3Helper::Up);
     }
     
     if (rotationAmount.y != 0)
     {
         lightRotationMatrix = rotate(lightRotationMatrix, rotationAmount.y, mDirectionalLight->Right());
     }
     
     if (rotationAmount.x != 0.0f || rotationAmount.y != 0.0f)
     {
         mDirectionalLight->ApplyRotation(lightRotationMatrix);
         //mProxyModel->ApplyRotation(lightRotationMatrix);
     }
 }
    void FirstPersonCamera::Update(const GameTime& gameTime)
    {
		XMFLOAT2 movementAmount = Vector2Helper::Zero;
        if (mKeyboard != nullptr)
        {
            if (mKeyboard->IsKeyDown(DIK_W))
            {
                movementAmount.y = 1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_S))
            {
                movementAmount.y = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_A))
            {
                movementAmount.x = -1.0f;
            }

            if (mKeyboard->IsKeyDown(DIK_D))
            {
                movementAmount.x = 1.0f;
            }
        }

        XMFLOAT2 rotationAmount = Vector2Helper::Zero;
        if ((mMouse != nullptr) && (mMouse->IsButtonHeldDown(MouseButtons::Left)))
        {
            LPDIMOUSESTATE mouseState = mMouse->CurrentState();			
            rotationAmount.x = -mouseState->lX * mMouseSensitivity;
            rotationAmount.y = -mouseState->lY * mMouseSensitivity;
        }

		float elapsedTime = (float)gameTime.ElapsedGameTime();
        XMVECTOR rotationVector = XMLoadFloat2(&rotationAmount) * mRotationRate * elapsedTime;
        XMVECTOR right = XMLoadFloat3(&mRight);

        XMMATRIX pitchMatrix = XMMatrixRotationAxis(right, XMVectorGetY(rotationVector));
        XMMATRIX yawMatrix = XMMatrixRotationY(XMVectorGetX(rotationVector));

        ApplyRotation(XMMatrixMultiply(pitchMatrix, yawMatrix));

        XMVECTOR position = XMLoadFloat3(&mPosition);
		XMVECTOR movement = XMLoadFloat2(&movementAmount) * mMovementRate * elapsedTime;

		XMVECTOR strafe = right * XMVectorGetX(movement);
        position += strafe;

        XMVECTOR forward = XMLoadFloat3(&mDirection) * XMVectorGetY(movement);
        position += forward;
        
        XMStoreFloat3(&mPosition, position);

        Camera::Update(gameTime);
    }
Exemple #17
0
    void BacteroidsState::Update(const GameTime &gameTime)
    {
        static float spawn_rate = 0.1f;
        static float num_spawn = 1.0f;
        spawn_rate = std::log(10.0f + gameTime.GetTotalSeconds() * 0.1f) * 0.5f;
        num_spawn += spawn_rate * gameTime.GetDeltaSeconds();
        while (num_spawn >= 1.0f)
        {
            SpawnBacter();
            num_spawn -= 1.0f;
        }

        m_soundPlayer.UpdateTime(gameTime);

        UpdatePlayer(gameTime);

        DoCollisions();

        for (size_t_32 i = 0; i < m_objects.Size(); i++)
        {
            m_objects[i]->Update(gameTime, PLAY_AREA);
            // TODO: Spontaneous splitting is very much a hack I says. Fix pls. Solution CES?
            if (m_objects[i]->GetType() == Bacter::TYPE)
            {
                Bacter *bacter = (Bacter*)m_objects[i];
                if (bacter->WantsToSplit() && m_objects.CanObtainBacter())
                    SplitBacter(bacter);
            }
        }

        for (size_t_32 i = 0; i < m_objects.Size(); )
        {
            if (!m_objects[i]->IsAlive())
            {
                m_objects.Remove(i);
                continue;
            }
            i++;
        }

        m_damageFade.Update(gameTime.GetDeltaSeconds());
    }
	void FogDemo::UpdateAmbientLight(const GameTime& gameTime)
	{
		static float ambientIntensity = 0.0f;

		if (mGamePad->IsButtonHeldDown(GamePadButton::X) && ambientIntensity < 1.0f)
		{
			ambientIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			ambientIntensity = min(ambientIntensity, 1.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}

		if (mGamePad->IsButtonHeldDown(GamePadButton::Y) && ambientIntensity > 0.0f)
		{
			ambientIntensity -= (float)gameTime.GetElapsedSeconds();
			ambientIntensity = max(ambientIntensity, 0.0f);

			mPixelCBufferPerFrameData.AmbientColor = XMFLOAT4(ambientIntensity, ambientIntensity, ambientIntensity, 1.0f);
		}
	}
 void BlinnPhongDemo::UpdateAmbientLight(const GameTime& gameTime)
 {
     static float ambientIntensity = 0.0f;
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_R) && ambientIntensity < 1.0f)
     {
         ambientIntensity += (float)gameTime.ElapsedGameTime();
         ambientIntensity = glm::min(ambientIntensity, 1.0f);
         
         mAmbientLight->SetColor(vec4((vec3)ambientIntensity, 1.0f));
     }
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_F) && ambientIntensity > 0.0f)
     {
         ambientIntensity -= (float)gameTime.ElapsedGameTime();
         ambientIntensity = glm::max(ambientIntensity, 0.0f);
         
         mAmbientLight->SetColor(vec4((vec3)ambientIntensity, 1.0f));
     }
 }
void FireParticleEmitter::UpdateFireParticleEmitter(const GameTime &gameTime)
{
	if(!IsActive() || burnState == Dead) { return; }

	if(burnState == Dieing)
	{
		if(runtime >= deathTime)
		{
			burnState = Dead;
			SetActive(false);
			return;
		}

		runtime += gameTime.GetDeltaTime();
		i32 depth = tree->GetDepth();
		f32 K = (1.0f / deathTime) * runtime;
		burnLevel = depth - (i32)lerp(0, (f32)depth,K) - 1;

		tree->SetTreeDeathDepth(max(0, burnLevel));

		f32 DeathTimePerDepth = deathTime/depth;
		f32 P = fmod(runtime,DeathTimePerDepth);
		tree->SetAlpha(1.0f - ((1.0f/DeathTimePerDepth)*P));
	}
	else if(burnState == Igniting)
	{
		if(runtime >= ignitionTime)
		{
			runtime = 0;
			SetBurningState(Burning);
		}

		runtime += gameTime.GetDeltaTime();
		ignitionRuntime += gameTime.GetDeltaTime();
		f32 timePerDepthToIgnite = ignitionTime / tree->GetDepth();
		if(ignitionRuntime > timePerDepthToIgnite) { ignitionRuntime = 0; }
		f32 k = (1.0f / ignitionTime) * runtime;
		burnLevel = (i32)lerp(0, (f32)tree->GetDepth(), k) - 1;
		tree->SetTreeDeathDepth(max(0, burnLevel));
	}
};
Exemple #21
0
void Game::start()
{
    GameTime t;
    t.reset();
    _gameTime = t.getElapsedTime();
    _map.init();
    _map.setDelegate(this);
    _numberOfPlayerAlive = _playerList.size();
    Message msg;
    while (stillPlaying()) {
        while (t.getElapsedTime() - _gameTime < TIME_UNIT) {
            getPlayerActions(msg);
        }
        _gameTime = t.getElapsedTime();
        addSpawn();
        updateMap();
        sendMap(msg);
    }

    _gameEnd = _gameTime;
    while (msg.time - _gameTime < 100) {
        msg.messageType = (_gameState == GAME_WON) ? MSG_WON : MSG_LOST;
        msg.time = t.getElapsedTime();
        sendAll(msg);
        getPlayerActions(msg);
    }
    while (msg.time - _gameTime < 100) {
        for (std::list<Player *>::iterator it = _playerList.begin(); it != _playerList.end(); ++it) {
            (*it)->recvMsg(msg);
        }
    }
    release();
}
/**
 * <param name="gameTime"></param>
 * <param name="horizontalAxis_"> value between -1.0 and 1.0 </param>
 * <param name="verticalAxis_"> value between -1.0 and 1.0 </param>
 * <param name="rollAxis_"> value between -1.0 and 1.0 </param>
 * <param name="zoom"> zoom value </param>
*/
void ArcBallCameraController::HandleControls(const GameTime& gameTime_,
	float rightAxis_, float upAxis_, float forwardAxis_,
	float horizontalOrbit_, float verticalOrbit_, float /*rollOrbit_*/, float zoom_)
{
	float r = rightAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; 
	float u = upAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate; 
	float f = forwardAxis_ * gameTime_.FrameTime() * m_fInputDisplacementRate;

	float dH = horizontalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate;
	float dV = verticalOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate;
	//float dR = rollOrbit_ * gameTime_.FrameTime() * m_fInputTurnRate;

	if ( dH != 0.0f ) RotateTargetRight(dH);//OrbitUp( dH );
	if ( dV != 0.0f ) RotateTargetUp(dV); //OrbitRight( dV );
	//if ( dR != 0.0f ) RotateClockwise( dR );

	//decrease distance to target
	m_fDistance += zoom_ * gameTime_.FrameTime() * m_fInputDistanceRate;

	if ( m_fDistance < 0.001f ) m_fDistance = 0.001f;

	if ( r != 0.0f || u != 0.0f || f != 0.0f ) 
	{
		Vector3F pos = Target() + (Right() * r) + (Up() * u) + (Direction() * f);
		Target(pos);

		/*Vector3F target = pos;
		target.Normalize();
		target *= m_fDistance;
		target += pos;

		SetCamera(pos, target, Up());*/
	}
}
Exemple #23
0
bool Game::Run()
{
    if(!Initialize())
    {
        Log::Error << "Could not initialize GLFW window.\n";
        return false;
    }
    
    GameTime time;

    
    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(m_window))
    {
        /* Poll for and process events */
        glfwPollEvents();
        
        Update(time);
        
        
        gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
        
        Render(time);
        
        /* Render here */
        /* Swap front and back buffers */
        glfwSwapBuffers(m_window);
        
        auto title = "Time: " + std::to_string(time.TotalSeconds());
        
        glfwSetWindowTitle(m_window, title.c_str());
                           
        time.Update();
    }
    
    Dispose();
    
    return true;
    
}
void PPlayer::v_updateEntity(entityID id, const GameTime& gameTime) {
    CPlayer *player = getEntityAs<CPlayer>(id);
    CTransform *transform = getEntityAs<CTransform>(id);
    CRigidBody *body = getEntityAs<CRigidBody>(id);

    if (player->m_bAlive) {
        player->m_elapsedTime += gameTime.getElapsedMillisecond();
        double temp = 0.25f * sin((double)(MathUtils::TWO_PI * 0.001 * player->m_elapsedTime + 0));

        // set screen position with floating in account
        player->m_floatingAmount = temp;
        transform->setOffsetY(transform->getOffsetY() + player->m_floatingAmount);

        if (player->m_bSpeedUp) {
            if (player->m_actualThrustAmount < player->m_speedupThrustAmount) {
                player->m_actualThrustAmount += 350 * gameTime.getElapsedSecond();
            }
            player->m_bSpeedUp = false;
        }
        else {
            if (player->m_actualThrustAmount < player->m_maxThrustAmount) {
                player->m_actualThrustAmount += 150 * gameTime.getElapsedSecond();
            }
            else if (player->m_actualThrustAmount > player->m_maxThrustAmount) {
                player->m_actualThrustAmount -= 250 * gameTime.getElapsedSecond();
            }
        }
        
        body->m_velocity.y = sin(transform->getRotation()) * player->m_actualThrustAmount;
        body->m_velocity.x = player->m_forward.x * cos(transform->getRotation()) * player->m_actualThrustAmount;

        if (player->m_cooldown > 0) {
            player->m_cooldown -= gameTime.getElapsedMillisecond();
            // Design issue : Draw with UpdateProcess
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, 75, 5, 0xFF, 0xFF, 0xFF);
            Locator::getRenderer()->renderRectangle(true, transform->getX() - 25, transform->getY() + 55, (1 - (player->m_cooldown / player->m_defaultCooldown)) * 75, 5, 0x66, 0x99, 0x99);
        }
    }
}
Exemple #25
0
void Camera::Update(const InputState& prevInput, const InputState& currInput, const GameTime& gameTime)
{
	D3DXVECTOR3 displacement = mDestination - mPosition;
	//D3DXVec3Normalize(&displacement, &displacement);

	mPosition += displacement * gameTime.GetTimeSinceLastTick().Seconds;
	
	displacement = mDestination - mPosition;
	if (D3DXVec3Length(&displacement) <= 1.0f)
	{
		mPosition = mDestination;
	}
}
	void FogDemo::UpdateSpecularLight(const GameTime& gameTime)
	{
		static float specularIntensity = 1.0f;

		if (mGamePad->IsButtonHeldDown(GamePadButton::DPadUp) && specularIntensity < 1.0f)
		{
			specularIntensity += static_cast<float>(gameTime.GetElapsedSeconds());
			specularIntensity = min(specularIntensity, 1.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		if (mGamePad->IsButtonHeldDown(GamePadButton::DPadDown) && specularIntensity > 0.0f)
		{
			specularIntensity -= (float)gameTime.GetElapsedSeconds();
			specularIntensity = max(specularIntensity, 0.0f);

			mPixelCBufferPerObjectData.SpecularColor = XMFLOAT3(specularIntensity, specularIntensity, specularIntensity);
		}

		static float specularPower = mPixelCBufferPerObjectData.SpecularPower;

		if (mGamePad->IsButtonHeldDown(GamePadButton::RightShoulder) && specularPower < UCHAR_MAX)
		{
			specularPower += LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = min(specularPower, static_cast<float>(UCHAR_MAX));

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}

		if (mGamePad->IsButtonHeldDown(GamePadButton::LeftShoulder) && specularPower > 1.0f)
		{
			specularPower -= LightModulationRate * static_cast<float>(gameTime.GetElapsedSeconds());
			specularPower = max(specularPower, 1.0f);

			mPixelCBufferPerObjectData.SpecularPower = specularPower;
		}
}
 void BlinnPhongDemo::UpdateSpecularLight(const GameTime& gameTime)
 {
     static float specularIntensity = 1.0f;
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_Y) && specularIntensity < 1.0f)
     {
         specularIntensity += (float)gameTime.ElapsedGameTime();
         specularIntensity = glm::min(specularIntensity, 1.0f);
         
         mSpecularColor = (vec4((vec3)specularIntensity, 1.0f));
     }
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_H) && specularIntensity > 0.0f)
     {
         specularIntensity -= (float)gameTime.ElapsedGameTime();
         specularIntensity = glm::max(specularIntensity, 0.0f);
         
         mSpecularColor = (vec4((vec3)specularIntensity, 1.0f));
     }
     
     static float specularPower = mSpecularPower;
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_U) && specularPower < UCHAR_MAX)
     {
         specularPower += LightModulationRate * (float)gameTime.ElapsedGameTime();
         specularPower = glm::min(specularPower, static_cast<float>(UCHAR_MAX));
         
         mSpecularPower = specularPower;
     }
     
     if (glfwGetKey(mGame->Window(), GLFW_KEY_J) && specularPower > 0.0f)
     {
         specularPower -= LightModulationRate * (float)gameTime.ElapsedGameTime();
         specularPower = glm::max(specularPower, 0.0f);
         
         mSpecularPower = specularPower;
     }
 }
Exemple #28
0
	void InGameLogger::Update(const GameTime& gameTime_)
	{
 		float time = gameTime_.FrameTime();

		for (int i=0; i<NBLOGLINES; i++)
		{
			m_Lines[i].delay -= time;			

			if (m_Lines[i].delay <= 0.0f)
			{
				m_Lines[i].isDeleted = true;
			}
		}
	}
Exemple #29
0
// Tilt the camera horisontally: look left/right
void Camera::TurnHorizontal(const GameTime& gameTime, bool turnLeft)
{
	float angle = (float)gameTime.GetTimeSinceLastTick().Milliseconds * C_TILTING_SPEED;
	if(turnLeft)
		angle = -angle;

	D3DXVECTOR3 up;
	D3DXVec3Cross(&up, &mDirection, &GetRight());
	D3DXMATRIX rotation;

	D3DXMatrixRotationAxis(&rotation, &up, angle);
	D3DXVec3TransformCoord(&mDirection, &mDirection, &rotation);
	D3DXVec3Normalize(&mDirection, &mDirection);
}
void Sprite::update(GameTime t)
{
	if (speedCounter >= (1.0f / speed))
	{
		frame += 1;
		if (frame >= frames)
			frame = 0;
		speedCounter = 0.0f;
	}
	else
	{
		speedCounter += t.getDeltaTime();
	}
}