void PlayState::Update()
//  Count time differentials then call updates for player, mobs and renderer
{
	//  Find the time since the last frame
	float timeDif = timer.GetTimeDeltaSeconds();
	if (timeDif > 0.1f) {
		timeDif = 0.0f;
	}
	
	//  Debug output FPS to console out
	if (pad[0].pressed & PAD_CROSS) {
		std::cout << "TimeDiff: " << timeDif << std::endl;
		std::cout << "FoV: " << testRenderer.GetFoV() << std::endl;
		std::cout << "FPS: " << (1.0f/timeDif) << std::endl; 
	}		

	//  Check for game pause
	if (pad[0].pressed & PAD_START) {
		value = GameState::GAMEPAUSED;
		EndMusic();
	}	
	
	//  Update player, renderer and mobs
	player.Update(timeDif);
	testRenderer.SetPosition(player.GetPosition());
	testRenderer.SetDirection(player.GetDirection());
	testRenderer.ConstructDepthMap();	
	testRenderer.BuildScene();
	testMobs.FindMobPositions(player.GetPosition(), player.GetDirection(), testRenderer.GetFoV());
	
	//  Check for damage dealt by player
	if (player.HasFired()) {
		testMobs.ShootMobs(testRenderer.GetCentreWallDistance(), player.GetGunMaxDamage());
	}
	
	testMobs.UpdateMobs(testLevel, timeDif);
	
	//  Check for damage dealt by mobs, flash red on damage
	int damage = testMobs.CheckMobDealtDamage();
	if (redAlpha > 5) {
		redAlpha-=5;
	}
	if (damage > 0) {
		player.Damage(damage);
		redAlpha = 'a';
	}
	redOverlay.SetAlpha(redAlpha);
	
	//  Check for end conditions (win or lose)
	if (testLevel.IsCompletion(player.GetPosition())) {
		value = GameState::GAMEWIN;
		EndMusic();
	}
	if (player.IsDead()) {
		value = GameState::GAMELOSE;
		EndMusic();
	}

}
Exemplo n.º 2
0
void JukeBox::NextMusic()
{
  if (!IsPlayingMusic())
    return;
  else if (!IsPlayingMusicSample())
    PlayMusic(playing_pl->first);
  else
    EndMusic(); // next music but before, we stop the current one.
}
Exemplo n.º 3
0
void JukeBox::StopMusic()
{
  if (!IsPlayingMusicSample())
    return;
  playing_music = playing_pl->second.end();
  playing_pl = playlist.end();
  Mix_HaltMusic();
  EndMusic();
}