Esempio n. 1
0
void BemGame::ProcessRightWindow()
{
	GlFixed scale = engine->Tree()->Root()->XScale( 4 );
	const GlFixed step = 0.03;
	KrColorTransform color;

	if ( rightDormant )
	{
		--rightDormant;
		if ( rightDormant == 0 ) rightTarget = 0.3 + random.DRand( 1.2 );
	}
	else
	{
		if ( scale < rightTarget )
		{
			color.TintRed( 100 );
			scale += step;
			if ( scale > rightTarget ) scale = rightTarget;
		}
		if ( scale > rightTarget )
		{
			color.TintBlue( 100 );
			scale -= step;
			if ( scale < rightTarget ) scale = rightTarget;
		}
		if ( scale == rightTarget )
			rightDormant = 15;
	}
	KrMatrix2 matrix;
	matrix.Set( ( scale * -actor[0].sprite->X()).ToIntRound() + engine->ScreenBounds( 4 ).Width() / 2,
				( scale * (-actor[0].sprite->Y() + 100) ).ToIntRound() + engine->ScreenBounds( 4 ).Height() / 2,
				scale, scale );

	engine->Tree()->Root()->SetTransform( matrix, 4 );
	engine->Tree()->Root()->SetColor( color, 4 );
}
Esempio n. 2
0
void BemGame::DrawFrame()
{
	AddText( engine );
	int i;

	// The whole demo works because it takes exactly 12 ticks for a 
	// Drone or Brain to walk one tile. So every 12 subticks
	// we calculate a new direction for the actor.
	subtick++;
	tick++;
	teleFrame++;

	if ( subtick == SUBTICK )
	{
		subtick = 0;
		for ( i=0; i<numActors; i++ )
		{
			ProcessMap( &actor[i] );
		}
	}

	// calculate the tinting, from map 4.5,4.5
 	float rad = float( tick ) / 45.0;
 	float fred   = fabs( sin( rad*1.5 ) ) * 0.5;
 	float fgreen = fabs( sin( rad*2.5 ) ) * 0.5;
 	float fblue  = fabs( sin( rad*3.5 ) ) * 0.5;
 	float falpha = fabs( sin( rad ) ) * 0.3;
	
	KrColorTransform gizmoColor;
	gizmoColor.TintRed(   U8( fred * 255.0 ));
	gizmoColor.TintGreen( U8( fgreen * 255.0 ));
	gizmoColor.TintBlue(  U8( fblue * 255.0 ));
	gizmoColor.TintAlpha( U8( falpha * 255.0 ));
	gizmo->SetColor( gizmoColor );

	// update all the actors.
	for( i=0; i<numActors; i++ )
	{
		KrColorTransform actorColor;
		float d = DistanceFromCenter( &actor[i] );
		if ( d < 3.0 )
		{
			float fraction = 1.0 - d / 3.0;
			actorColor.TintRed(   U8( fred * 255.0 * fraction ));
			actorColor.TintGreen( U8( fgreen * 255.0 * fraction ));
			actorColor.TintBlue(  U8( fblue * 255.0 * fraction ));
			actorColor.TintAlpha( U8( falpha * 255.0 * fraction ));
		}
		actor[i].sprite->SetColor( actorColor );

		actor[i].sprite->DoStep();

		// In order to sort with the particles, sort with
		// the world Y.
		GlFixed wx, wy, wz, tx, ty;

		isoMath->ScreenToFlatTile(	actor[i].sprite->X(), 
									actor[i].sprite->Y(),
									0, &tx, &ty );
		isoMath->TileToWorld( tx, ty, 0, &wx, &wy, &wz );
		actor[i].sprite->SetZDepth( -wy.v );
	}

	// The teleport in and out special effect. Done "by hand"
	// counting frames with a switch. Looks cool and tests
	// the visibility stuff.
	if ( teleFrame > 9 && numActors > 0 )
	{
		KrColorTransform cform;

		switch ( teleFrame )
		{
			case 10:
				teleSprite = actor[ random.Rand( numActors ) ].sprite;
				cform.Brighten( 128 );
				break;

			case 11:
				cform.Brighten( 200 );
				cform.SetAlpha( 220 );
				break;

			case 12:
			case 13:
				cform.Brighten( 255 );
				cform.SetAlpha( 200 );
				break;

			case 14:
				{
					GlFixed x, y;
					isoMath->ScreenToFlatTile(	teleSprite->X(),
												teleSprite->Y(),
												0, &x, &y );
					AddParticles( x, y );
					teleSprite->SetVisible( false );
				}
				break;

			case 35:
			case 36:
			case 37:
			case 38:
			case 39:
			case 40:
				teleSprite->SetVisible( true );
				cform.TintBlue( 240 - 30 * ( teleFrame - 35 ) );
				cform.SetAlpha( 100 + 20 * ( teleFrame - 35 ) );
				break;
				
			case 41:
				teleFrame = 0;
				break;

			default:
				break;
		}
		teleSprite->SetColor( cform );
	}

	MoveParticles();

	// Since the map coordinates only change if the subtick rolled
	// over, we only change the mini map every 12 frames.
	if ( subtick == 0 )
		DrawMiniMap();

	if ( UseWindows() )
		ProcessRightWindow();

	engine->Draw();
}