Example #1
0
void Game::DoTick()
{
	// Tutorial 3: Walk the meteor list.
	// This looks really clunky to me...there's probably a better way.
	// Just be careful not to delete the iterator you are using.

	std::list< Meteor* >::iterator it = meteorList.begin();
	while ( it != meteorList.end() )
	{
		Meteor* meteor = *it;
		if ( meteor->Done() )
		{
			std::list< Meteor* >::iterator deleteIt = it;
			++it;
			meteorList.erase( deleteIt );
			delete meteor;
		}
		else
		{
			meteor->DoTick();
			++it;
		}
	}
	// Tutorial 4: Weather
	U32 day, hour, minute, second;
	Lilith3D::GetTimeClock()->CalcCalendarTime( &day, &hour, &minute, &second );
	Weather* weather = lilith->GetTargetWeather();

	// This is just so we don't keep calling this withou
	// significant time change. Look for the 'minute' in
	// game time to actually be different.
	if ( weatherMinute != minute )
	{
		const float FOG_MAX = 0.7f;
		const U32 FOG_START = 2;
		const U32 FOG_PEAK = 7;
		const U32 FOG_END = 11;
		const int RAIN_START = 16;
		const int RAIN_PEAK = 20;
		const int RAIN_END = 23;

		if ( hour >= FOG_START && hour <= FOG_END )
		{
			// Fog in the morning.
			if ( hour < FOG_PEAK )
				weather->SetFog( FOG_MAX * Interpolate( (float)FOG_START*60, (float)0.0f,
														  (float)FOG_PEAK*60, (float)1.0,
														  (float)(hour*60+minute) ) );
			else
				weather->SetFog( FOG_MAX * Interpolate( (float)FOG_PEAK*60, (float)1.0f,
														  (float)FOG_END*60, (float)0.0,
														  (float)(hour*60+minute) ) );
		}
		else if ( hour >= RAIN_START && hour <= RAIN_END )
		{
			// Rain in the evening - be sure to set a little fog too. Rain
			// looks bad without fog.		
			if ( hour < RAIN_PEAK )
			{
				weather->SetRain( Interpolate( (float)RAIN_START*60, (float)0.0f,
												 (float)RAIN_PEAK*60, (float)1.0,
												 (float)(hour*60+minute) ) );
				weather->SetFog( 0.5f * Interpolate( (float)RAIN_START*60, (float)0.0f,
													   (float)RAIN_PEAK*60, (float)1.0,
													   (float)(hour*60+minute) ) );
			}
			else
			{
				weather->SetRain( Interpolate( (float)RAIN_PEAK*60, (float)1.0f,
												 (float)RAIN_END*60, (float)0.0,
												 (float)(hour*60+minute) ) );
				weather->SetFog( 0.5f * Interpolate( (float)RAIN_PEAK*60, (float)1.0f,
													   (float)RAIN_END*60, (float)0.0,
													   (float)(hour*60+minute) ) );
			}
		}
		else
		{
			weather->SetRain( 0.0f );
			weather->SetFog( 0.0f );
		}
	}

}