Beispiel #1
0
void TestBlitter::SetUp(	KrRGBA newColorBase,
							KrRGBA surfaceColorBase,
							KrColorTransform cformBase  )
{
	KrRGBA newColor;
	KrRGBA surfaceColor;
	KrColorTransform cform;

	// NoAlpha in source
	// -- Simple transform
	cform.Set( 255, 0, 255, 0, 255, 0, 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Color transform
	cform = cformBase;
	cform.SetAlpha( 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Alpha transform
	cform = cformBase;
	cform.SetRed( 255, 0 );
	cform.SetGreen( 255, 0 );
	cform.SetBlue( 255, 0 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );

	// -- Full transform
	cform = cformBase;
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	newColor.c.alpha = 255;
	Run( surfaceColor, newColor, cform, false );


	// Alpha in source
	// -- Simple transform
	cform.Set( 255, 0, 255, 0, 255, 0, 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Color transform
	cform = cformBase;
	cform.SetAlpha( 255 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Alpha transform
	cform = cformBase;
	cform.SetRed( 255, 0 );
	cform.SetGreen( 255, 0 );
	cform.SetBlue( 255, 0 );
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );

	// -- Full transform
	cform = cformBase;
	surfaceColor = surfaceColorBase;
	newColor     = newColorBase;
	Run( surfaceColor, newColor, cform, true );
}
Beispiel #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();
}
Beispiel #3
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 );
	}
}
Beispiel #4
0
TileTest::TileTest( SDL_Surface* _screen )
{
	drawn = false;
	screen = _screen;
	engine = new KrEngine( screen );
	//GLOUTPUT( "TileTest::TileTest\n" );
	engine->Validate();	// check validity

	int i, j;

	// Classes to hold other objects:
	engine->Vault()->LoadDatFile( "standardtest.dat" );

	KrTileResource* noAlphaRes = engine->Vault()->GetTileResource( "NOALPHA" );
	KrTileResource* alphaRes = engine->Vault()->GetTileResource( "ALPHA" );
	GLASSERT( noAlphaRes && alphaRes );

	// Transforms:
	KrColorTransform alphaCForm;
	alphaCForm.SetAlpha( 255 * 70 / 100 );

	KrColorTransform redCForm;
	redCForm.SetRed( 255 * 50 / 100, 127 );

	KrColorTransform blueCForm;
	blueCForm.SetBlue( 255 * 50 / 100, 127 );

	KrColorTransform greenAlphaCForm;
	greenAlphaCForm.SetGreen( 255 * 50 / 100, 127 );
	greenAlphaCForm.SetAlpha( 255 * 70 / 100 );

	KrColorTransform blueAlphaCForm;
	blueAlphaCForm.SetBlue( 255 * 50 / 100, 127 );
	blueAlphaCForm.SetAlpha( 255 * 70 / 100 );

	// Containers:
	KrImNode* c0 = new KrImNode;	// background
	KrImNode* c1 = new KrImNode;	// tiles
 	KrImNode* c2 = new KrImNode;	// canvas

	engine->Tree()->AddNode( 0, c0 );
	engine->Tree()->AddNode( c0, c1 );
	engine->Tree()->AddNode( c0, c2 );

	c1->SetPos(   0,   0 );
	c2->SetPos(	420,   0 );
	c1->SetZDepth( 1 );
	c2->SetZDepth( 1 );

	// ---------- Background ----------- //
	KrSpriteResource* backSpriteRes = engine->Vault()->GetSpriteResource( "BACKGROUND" );
	GLASSERT( backSpriteRes );
	KrAction* action = backSpriteRes->GetActionByIndex( 0 );
	GLASSERT( action );
	const KrRle& rle = action->Frame( 0 );

	for ( i=0; i <= (screen->w) / rle.Width(); i++ )
	{
		for ( j=0; j <= (screen->h) / rle.Height(); j++ )
		{
			KrSprite* sprite = new KrSprite( backSpriteRes );
			sprite->SetPos( i*rle.Width(), j*rle.Height() );
			GLASSERT( sprite );
			engine->Tree()->AddNode( c0, sprite );
		}
	}

	// ---------- The "no alpha" tile.
	// no transform:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][0] = new KrTile( noAlphaRes );
		noAlpha[i][0]->SetPos( i*noAlpha[i][0]->Size(), 0 );
		noAlpha[i][0]->SetRotation( i );
		GLASSERT( noAlpha );
		engine->Tree()->AddNode( c1, noAlpha[i][0] );
	}

	// alpha:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][1] = new KrTile( noAlphaRes );
		noAlpha[i][1]->SetColor( alphaCForm );
		noAlpha[i][1]->SetPos( i*noAlpha[i][1]->Size(), 1*noAlpha[i][1]->Size() );
		noAlpha[i][1]->SetRotation( i );
		GLASSERT( noAlpha[i][1] );
		engine->Tree()->AddNode( c1, noAlpha[i][1] );
	}

	// red:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][2] = new KrTile( noAlphaRes );
		noAlpha[i][2]->SetColor( redCForm );
		noAlpha[i][2]->SetPos( i*noAlpha[i][2]->Size(), 2*noAlpha[i][2]->Size() );
		noAlpha[i][2]->SetRotation( i );
		GLASSERT( noAlpha[i][2] );
		engine->Tree()->AddNode( c1, noAlpha[i][2] );
	}

	// combination:
	for ( i=0; i<8; i++ )
	{
		noAlpha[i][3] = new KrTile( noAlphaRes );
		noAlpha[i][3]->SetColor( blueAlphaCForm );
		noAlpha[i][3]->SetPos( i*noAlpha[i][3]->Size(), 3*noAlpha[i][3]->Size() );
		noAlpha[i][3]->SetRotation( i );
		GLASSERT( noAlpha );
		engine->Tree()->AddNode( c1, noAlpha[i][3] );
	}

	// ---------- The "alpha" tile.
	// no transform:
	for ( i=0; i<8; i++ )
	{
// 		i=6;
		alpha[i][0] = new KrTile( alphaRes );
		alpha[i][0]->SetPos( i*alpha[i][0]->Size(), 4*alpha[i][0]->Size() );
		alpha[i][0]->SetRotation( i );
		GLASSERT( alpha[i][0] );
		engine->Tree()->AddNode( c1, alpha[i][0] );
	}

	// alpha:
	for ( i=0; i<8; i++ )
	{
		alpha[i][1] = new KrTile( alphaRes );
		alpha[i][1]->SetColor( alphaCForm );
		alpha[i][1]->SetPos( i*alpha[i][1]->Size(), 5*alpha[i][1]->Size() );
		alpha[i][1]->SetRotation( i );
		GLASSERT( alpha[i][1] );
		engine->Tree()->AddNode( c1, alpha[i][1] );
	}

	// red:
	for ( i=0; i<8; i++ )
	{
		alpha[i][2] = new KrTile( alphaRes );
		alpha[i][2]->SetColor( redCForm );
		alpha[i][2]->SetPos( i*alpha[i][2]->Size(), 6*alpha[i][2]->Size() );
		alpha[i][2]->SetRotation( i );
		GLASSERT( alpha[i][2] );
		engine->Tree()->AddNode( c1, alpha[i][2] );
	}

	// combination:
	for ( i=0; i<8; i++ )
	{
		alpha[i][3] = new KrTile( alphaRes );
		alpha[i][3]->SetColor( blueAlphaCForm );
		alpha[i][3]->SetPos( i*alpha[i][3]->Size(), 7*alpha[i][3]->Size() );
		alpha[i][3]->SetRotation( i );
		GLASSERT( alpha[i][3] );
		engine->Tree()->AddNode( c1, alpha[i][3] );
	}

	// ----------- A canvas ----------------- //
	KrCanvasResource* canvasResource = new KrCanvasResource( "mycanvas",
															 50, 50,
															 true );
	engine->Vault()->AddResource( canvasResource );
	KrRGBA* pixels = canvasResource->Pixels();
	KrRGBA color;
	for( i=0; i<canvasResource->Width(); i++ )
	{
		for( j=0; j<canvasResource->Height(); j++ )
		{
			color.c.red = i*4 + 50;
			color.c.green = j*4 + 50;
			color.c.blue = 0;
			color.c.alpha = 255 - i;
			pixels[ j*canvasResource->Width() + i ] = color;
		}
		// Put in a diagonal line:
		color.Set( 0, 0, 255 );
		pixels[ i*canvasResource->Width() + i ] = color;
	}

	const int NUMCANVASDIV2 = NUMCANVAS / 2;
	for ( i=0; i<NUMCANVASDIV2; i++ )
	{
		GlFixed sx;
		GlFixed sy;

		// The left canvas:
		canvas[i*2] = new KrCanvas( canvasResource );

		engine->Tree()->AddNode( c2, canvas[i*2] );
		canvas[i*2]->SetPos( 0, i * canvas[i*2]->Height() * 3 / 2 );
		sx.v = GlFixed_1 * (i+1) / 3;
		sy.v = GlFixed_1 * (i+1) / 3;

		canvas[i*2]->SetScale( sx, sy );

		// The right canvas:
		canvas[i*2+1] = new KrCanvas( canvasResource );
		engine->Tree()->AddNode( c2, canvas[i*2+1] );

		canvas[i*2+1]->SetPos( 100, i * canvas[i*2+1]->Height() * 3 / 2 );
		sx.v = GlFixed_1 * (NUMCANVASDIV2 + 1 - i) / 3;
		sy.v = GlFixed_1 * (i+1) / 3;

		canvas[i*2+1]->SetScale( sx, sy );
	}
}