Beispiel #1
0
void KrButton::PlaceIcon()
{
	GLASSERT( Engine() );

	if ( icon )
	{
		int width  = bevel.width - 4;	// Give some border space.
		int height = bevel.height - 4;

		if ( width > 0 && height > 0 )
		{
			KrRect bounds;
			icon->QueryBoundingBox( &bounds );

			GlFixed wScale = GlFixed( width ) / GlFixed( bounds.Width() );
			GlFixed hScale = GlFixed( height ) / GlFixed( bounds.Height() );
			GlFixed scale = GlMin( wScale, hScale );
			GLASSERT( scale > 0 );

			iconX = width - ( scale * bounds.Width() ).ToInt();
			iconX = iconX / 2 - ( scale * bounds.xmin ).ToInt() + 1;

			iconY = height - ( scale * bounds.Height() ).ToInt();
			iconY = iconY / 2 - ( scale * bounds.ymin ).ToInt() + 1;

			icon->SetScale( scale, scale );
			icon->SetPos( iconX, iconY );
			Engine()->Tree()->AddNode( holder, icon );
			icon->SetZDepth( ICON_DEPTH );
		}
	}
}
Beispiel #2
0
void EdStateMovie::StateOpening()
{
	movieNode = new KrImNode();
	shared->Engine()->Tree()->AddNode( shared->ImNode(), movieNode );

	// Create the action, put it in a sprite resource.
	KrAction* movieAction = shared->CreateAnimationAction();
	if ( movieAction )
	{
		spriteResource = new KrSpriteResource(	"AlignerSprite" );
		spriteResource->AddAction( movieAction );

		numFrames = spriteResource->GetActionByIndex( 0 )->NumFrames();
	
		KrSprite* sprite = new KrSprite( spriteResource );
		sprite->SetFrame( 0 );
		sprite->SetNodeId( 0 );

		KrRect rect = shared->Engine()->ScreenBounds();
		sprite->SetPos( rect.Width()  / 2,
						rect.Height() / 2 );
		shared->Engine()->Tree()->AddNode( movieNode, sprite );
	}	
	shared->ConsoleNode()->SetVisible( false );	
	shared->SetInfoBox( false );
}
Beispiel #3
0
void EdStateMovie::ZoomOut()
{
	GlFixed scale = movieNode->XScale();
	if ( scale.v > GlFixed_1 / 4 )
	{
		scale /= 2;
		movieNode->SetScale( scale, scale );


		KrImNode* image = shared->Engine()->Tree()->FindNodeById( 0 );
		GLASSERT( image );
		KrSprite* sprite = image->ToSprite();
		GLASSERT( sprite );

		shared->Engine()->Tree()->Walk();

		//int x = sprite->CompositeXForm(0).x.ToInt();
		//int y = sprite->CompositeXForm(0).y.ToInt();
		KrRect screen = shared->Engine()->ScreenBounds();
		GlFixed scale = movieNode->XScale();
		GlFixed inverse = GlFixed( 1 ) / scale;

		sprite->SetPos( (inverse * screen.Width()).ToInt() / 2, (inverse*screen.Height()).ToInt()/2 );
	}
}
Beispiel #4
0
void BemGame::AddSpaceTiles()
{
	// This functions adds the background bitmaps. (Pictures
	// of Space.) The Space picture is a tile that is rotated
	// for variaton.

	KrResource* resource = engine->Vault()->GetResource(	KYRATAG_TILE,
															BEM_SPACE );
	GLASSERT( resource );

	KrTileResource* spaceTileRes = resource->ToTileResource();
	GLASSERT( spaceTileRes );

	int i, j;
	KrRect bounds = engine->FullScreenBounds();

	for( i=0; i<(bounds.Width() / spaceTileRes->Size() + 1); i++ )
	{
		for( j=0; j<(bounds.Height() / spaceTileRes->Size() + 1); j++ )
		{
			KrTile* spaceTile = new KrTile( spaceTileRes );
			GLASSERT( spaceTile );

			spaceTile->SetPos( i * spaceTile->Size(), j * spaceTile->Size() );
			spaceTile->SetRotation( (i+j) & 7 );

			engine->Tree()->AddNode( backgroundTree, spaceTile );
		}
	}
}
Beispiel #5
0
void EdStateMovie::FrameTick()
{
	KrImNode* image = shared->Engine()->Tree()->FindNodeById( 0 );
	GLASSERT( image );
	KrSprite* sprite = image->ToSprite();
	GLASSERT( sprite );

	sprite->DoStep();

	int x = sprite->CompositeXForm(0).x.ToInt();
	int y = sprite->CompositeXForm(0).y.ToInt();
	KrRect screen = shared->Engine()->ScreenBounds();
	GlFixed scale = movieNode->XScale();
	GlFixed inverse = GlFixed( 1 ) / scale;

	if ( x < 0 )
		sprite->SetPos( (inverse * screen.Width()).ToInt(), sprite->Y() );
	if ( x > screen.Width() )
		sprite->SetPos( 0, sprite->Y() );
	if ( y < 0 )
		sprite->SetPos( sprite->X(), (inverse*screen.Height()).ToInt() );
	if ( y > screen.Height() )
		sprite->SetPos( sprite->X(), 0 );
}
Beispiel #6
0
int main( int argc, char *argv[] )
{
	const SDL_version* sdlVersion = SDL_Linked_Version();
	if ( sdlVersion->minor < 2 )
	{
		printf( "SDL version must be at least 1.2.0\n" );
		GLASSERT( 0 );
		exit( 254 );
	}

	if ( argc < 2 )
	{
		printf( "Usage: krmapmaker map.xml\n" );
		exit( 253 );
	}

	TiXmlDocument doc( argv[1] );
	doc.LoadFile();

	XmlUtil xmlUtil( &doc );
	if ( !xmlUtil.IsValidMap() )
	{
		printf( "Not a valid map file.\n" );
		exit( 252 );
	}

	/* Initialize the SDL library */
	if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) < 0 ) {
		#ifdef DEBUG
			GLOUTPUT( "Couldn't initialize SDL: %s\n",SDL_GetError());
		#endif
		exit(255);
	}

	SDL_WM_SetCaption( "Kyra MapMaker", 0 );

	int screenX = 800;
	int screenY = 600;

	SDL_Surface* screen = SDL_SetVideoMode( screenX, screenY, 32, SDL_SWSURFACE );

	if ( screen )
	{
		KrResourceVault fontVault;
		//fontVault.LoadDatFileFromMemory( fontDat, sizeof( fontDat ) );
		KrFontResource* consoleFontRes =  KrEncoder::CreateFixedFontResource( "CONSOLE", CONSOLEFONT_DAT, CONSOLEFONT_SIZE );

		Layout layout( screen, consoleFontRes );
		if ( layout.Engine()->Vault()->LoadDatFile( xmlUtil.DatFileName().c_str() ) != true )
		{
			printf( "Couldn't load dat file.\n" );
			exit( 250 );
		}

		KrSquareWorldMap* worldMap = new KrSquareWorldMap( 100, 100, 100 );	// fixme hardcoded!
		layout.Engine()->Tree()->AddNode( layout.Map(), worldMap );
		worldMap->SetPos( 0, screenY-1, Layout::MAIN_VIEW );

		xmlUtil.Init( layout.Engine()->Vault(), layout.Engine(), layout.Map(), worldMap );
//		xmlUtil.InsertLayers( layout.LayerBox() );

		UILogic logic( &layout, &xmlUtil );
		layout.SetLayer( xmlUtil.GetLayer( "null" ), 0 );		

		KrRGBA white;
		white.Set( 200, 200, 200 );
		KrBox* whereBox = new KrBox( layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).Width(),
									 layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).Height(),
									 white, 
									 KrBoxResource::OUTLINE );
		layout.Engine()->Tree()->AddNode( 0, whereBox );
		whereBox->SetVisible( false );
		whereBox->SetVisible( true, Layout::MINIMAP_VIEW );

		layout.Engine()->Draw();

		SDL_Event event;

		while ( SDL_WaitEvent( &event ) )
		{
			if ( event.type == SDL_QUIT )
				break;

			KrEventManager::Instance()->HandleEvent( event, layout.Engine() );

			bool mapChanged = false;

			if (	( event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEBUTTONDOWN )
				 && layout.Engine()->GetWindowFromPoint( event.motion.x, event.motion.y ) == Layout::MAIN_VIEW )
			{
				KrVector2T< GlFixed > map;
				worldMap->ScreenToMap( event.motion.x, event.motion.y, &map, Layout::MAIN_VIEW );
				layout.DisplayMapCoords( map.x.ToFloat(), map.y.ToFloat() );

				if(			event.type == SDL_MOUSEBUTTONDOWN 
					   ||  ( event.type == SDL_MOUSEMOTION && event.motion.state == 1 ) )
				{
					if ( logic.CurrentImage() )
					{
						worldMap->SetLoc( map.x.ToInt(), map.y.ToInt(), 
										  logic.CurrentImage()->Clone()->ToImage() );
						mapChanged = true;
					}
				}
			}
			else if ( event.type == SDL_KEYDOWN )
			{
				if ( event.key.keysym.sym == SDLK_UP )
				{
					worldMap->SetPos( worldMap->X(), worldMap->Y() + worldMap->TileHeight(), Layout::MAIN_VIEW );
					mapChanged = true;
				}
				else if ( event.key.keysym.sym == SDLK_DOWN )
				{
					worldMap->SetPos( worldMap->X(), worldMap->Y() - worldMap->TileHeight(), Layout::MAIN_VIEW );
					mapChanged = true;
				}				
				else if ( event.key.keysym.sym == SDLK_RIGHT )
				{
					worldMap->SetPos( worldMap->X() - worldMap->TileWidth(), worldMap->Y(), Layout::MAIN_VIEW );
					mapChanged = true;
				}
				else if ( event.key.keysym.sym == SDLK_LEFT )
				{
					worldMap->SetPos( worldMap->X() + worldMap->TileWidth(), 
									  worldMap->Y(), 
									  Layout::MAIN_VIEW );
					mapChanged = true;
				}
				else if ( event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_7 )
				{
					layout.SetRotation( event.key.keysym.sym - SDLK_0 );
					logic.SetRotation( event.key.keysym.sym - SDLK_0 );
				}
			}

			if ( mapChanged )
			{
				layout.Engine()->Tree()->Walk();
				KrRect bounds = worldMap->CompositeBounds( Layout::MAIN_VIEW );

//				layout.Map()->SetPos(	-bounds.xmin, // - layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).xmin,
//										-bounds.ymin, // - layout.Engine()->ScreenBounds( Layout::MAIN_VIEW ).ymin,
//										Layout::MINIMAP_VIEW );

				GlFixed scale = GlMin(  GlFixed( layout.Engine()->ScreenBounds( Layout::MINIMAP_VIEW ).Width() ) / GlFixed( bounds.Width() ),
										GlFixed( layout.Engine()->ScreenBounds( Layout::MINIMAP_VIEW ).Height() ) / GlFixed( bounds.Height() ) );
				
				layout.Map()->SetPos(	0,
										( GlFixed( Layout::UI_WIDTH ) / scale ).ToInt(),
										Layout::MINIMAP_VIEW );

				layout.Engine()->Tree()->Root()->SetScale( scale, scale, Layout::MINIMAP_VIEW );
				GLOUTPUT( "Minimap scale set to %f\n", scale.ToFloat() );

				whereBox->SetPos( -worldMap->X(), bounds.Height() - 1 - worldMap->Y() );		
			}

			layout.Engine()->Draw();
		}	
	}
	SDL_Quit();

	return 0;
}
Beispiel #7
0
void ScalingTest::DrawFrame()
{
	if ( state == BOTH )		
	{	
		scaleX.v += GlFixed_1 / 64;
		scaleY.v += GlFixed_1 / 64;
		if ( scaleX > GlFixed( 1.4 ) ) 
		{
			scaleX.v = GlFixed_1 / 2;
			scaleY.v = GlFixed_1 / 2;
			state = HORIZONTAL;
		}
	}
	else if ( state == HORIZONTAL )
	{
		scaleX.v += GlFixed_1 / 64;
		if ( scaleX > GlFixed( 1.4 ) ) 
		{
			scaleX.v = GlFixed_1 / 2;
			scaleY.v = GlFixed_1 / 2;
			state = VERTICAL;
		}
	}
	else
	{
		scaleY.v += GlFixed_1 / 64;
		if ( scaleY > GlFixed( 1.4 ) ) 
		{
			scaleX.v = GlFixed_1 / 8;
			scaleY.v = GlFixed_1 / 8;
			state = BOTH;
		}
	}

	ship->SetScale( scaleX, scaleY );

	travellingShip->SetPos( travellingShip->X() - 2, travellingShip->Y() );
	if ( travellingShip->X() < 0 ) 
	{
		travellingShip->SetPos( engine->ScreenBounds().Width(), travellingShip->Y() );
	}

	GlFixed tscale;
	tscale = 1.0 + sin( double( Frame() ) / 25.0 ) / 2.0;
	travellingShip->SetScale( tscale, tscale );

	for( int i=0; i<3; ++i )
	{
		canvas[i]->SetScale( scaleX, scaleY );
	}

	char buffer[ 64 ];
	sprintf( buffer, "scale: %.3f X %.3f", scaleX.ToDouble(), scaleY.ToDouble() );
	textBox->SetTextChar( buffer, 0 );
	textBox->SetTextChar( "Sprite", 1 );
	textBox->SetTextChar( "Alpha Blended Canvas: fast -- bi-linear -- adaptive", 2 );

	KrRect bounds;
	KrMatrix2 xForm;
	xForm.Set( SHIPX, SHIPY, scaleX, scaleY );
 	ship->SpriteResource()->GetAction( "BODY" )->CalculateBounds( 0, xForm, &bounds );

	// Add the background alignment boxes.
	KrRGBA color;;
	color.Set( 255, 0, 0, 128 );

	KrBoxResource* boxRes = new KrBoxResource(	"databox",
												bounds.Width(), bounds.Height(),
												&color, 1,
												KrBoxResource::OUTLINE );
	KrBox* box = new KrBox( boxRes );
	box->SetPos( bounds.min.x, bounds.min.y );
	engine->Tree()->AddNode( 0, box );

	engine->Draw();

	engine->Tree()->DeleteNode( box );

	delete boxRes;
}