Пример #1
0
void BemGame::MoveParticles()
{
//	const GlFixed g = -0.003;
	const int alphaDelta = 3;

	GlFixed half;
	half.v = GlFixed_1 / 2;

//	GlFixed oldz;
	
	Particle* particle;
	GlCircleListIterator<Particle> it( particleList );

	for( it.Begin(); !it.Done(); it.Next() )
	{
		particle = &it.Current();

		particle->x += particle->vx;
		particle->y += particle->vy;

// 		oldz = particle->z;
		particle->z += particle->vz;
//  		particle->vz += g;

		GlFixed mapx = particle->x + half;
		GlFixed mapy = particle->y + half;
		int tx = mapx.ToInt();
		int ty = mapy.ToInt();

		// Check for gizmo hit:
		if ( GetMap( tx, MAPY - 1 - ty ) == GIZMO )
		{	
			engine->Tree()->DeleteNode( particle->sprite );
			it.Remove();
			it.Prev();
			continue;
		}

		int sx, sy;
		isoMath->TileToScreen( particle->x, particle->y, particle->z,
							   &sx, &sy );

		particle->sprite->SetPos( sx, sy );

		GlFixed x, y, z;
		isoMath->TileToWorld(	particle->x, particle->y, particle->z,
								&x, &y, &z );
		particle->sprite->SetZDepth( -z.v );

		KrColorTransform color;
		color = particle->sprite->CTransform();
		
		// Get rid of off screen:
		if (  color.Alpha() <= alphaDelta
			 || sx < 0 || sy < 0 
		     || sx > engine->FullScreenBounds().max.x
			 || sy > engine->FullScreenBounds().max.y )
		{
			engine->Tree()->DeleteNode( particle->sprite );
			it.Remove();
			it.Prev();
			continue;
		}
		color.SetAlpha( color.Alpha() - alphaDelta );
		particle->sprite->SetColor( color );
	}
}