Exemple #1
0
virtual int render()
{
	STX_TRY;
		// ----- Input update ----

		mI->Input->Update ();

		// ----- Delta -----

		mDelta = mI->Render->GetFrameTime() / 1000.0f;

		// ----- Render  -----

		mI->Render->BeginScene ();
		mI->Render->ClearViewPort (60, 60, 60);


		// --------------------------------------------------------------------------------
		//					Blitting Draco directly (IND_Surface object)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceDraco.GetWidth();
		mHeight = mSurfaceDraco.GetHeight();
		mI->Render->SetTransform2d	(50,				// x pos
									70,					// y pos
									0,					// Angle x
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									&mMatrix);			// Matrix in wich the transformation will be applied (optional)

		// 2) We apply the color, blending and culling transformations.
		mI->Render->SetRainbow2d	(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color
									0,					// G Component	for fading to a color
									0,					// B Component	for fading to a color
									255,				// Amount of fading
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->Render->BlitSurface	(&mSurfaceDraco);


		// --------------------------------------------------------------------------------
		//		Blitting Bug directly (IND_Surface object with a HotSpot and rotating)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mAngle += mSpeed *mDelta;
		mHotSpotX = 0.5f;
		mHotSpotY = 0.5f;
		mWidth = mSurfaceBug.GetWidth();
		mHeight = mSurfaceBug.GetHeight();
		mAxisCalX = (int) (mHotSpotX * mWidth * -1);
		mAxisCalY = (int) (mHotSpotY * mHeight * -1);

		mI->Render->SetTransform2d	(500,				// x pos
									100,				// y pos
									0,					// Angle x
									0,					// Angle y
									mAngle,				// Angle z
									1,					// Scale x
									1,					// Scale y
									mAxisCalX,			// Axis cal x
									mAxisCalY,			// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									&mMatrix);			// Matrix in wich the transformation will be applied (optional)

		// 2) We apply the color, blending and culling transformations.
		mI->Render->SetRainbow2d	(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color
									0,					// G Component	for fading to a color
									0,					// B Component	for fading to a color
									255,				// Amount of fading
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->Render->BlitSurface	(&mSurfaceBug);


		// --------------------------------------------------------------------------------
		//				Blitting a region of Gem directly (IND_Surface region)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceGem.GetWidth();
		mHeight = mSurfaceGem.GetHeight();
		mI->Render->SetTransform2d	(600,				// x pos
									200,				// y pos
									0,					// Angle x
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									&mMatrix);			// Matrix in wich the transformation will be applied (optional)

		// 2) We apply the color, blending and culling transformations.
		mI->Render->SetRainbow2d	(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color
									0,					// G Component	for fading to a color
									0,					// B Component	for fading to a color
									255,				// Amount of fading
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->Render->BlitRegionSurface (&mSurfaceGem, 10, 10, 70, 70);


		// --------------------------------------------------------------------------------
		//				Blitting a tiled region of Gem directly (IND_Surface wrap)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mSurfaceGem.GetWidth();
		mHeight = mSurfaceGem.GetHeight();
		mI->Render->SetTransform2d	(500,				// x pos
									350,				// y pos
									0,					// Angle x
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									&mMatrix);			// Matrix in wich the transformation will be applied (optional)

		// 2) We apply the color, blending and culling transformations.
		mI->Render->SetRainbow2d	(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color
									0,					// G Component	for fading to a color
									0,					// B Component	for fading to a color
									255,				// Amount of fading
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Surface
		mI->Render->BlitWrapSurface (&mSurfaceGem, 200, 200, 0, 0);


		// --------------------------------------------------------------------------------
		//				Blitting a ufo animation directly (IND_Animation object)
		// --------------------------------------------------------------------------------

		// 1) We apply the world space transformation (translation, rotation, scaling).
		// If you want to recieve the transformation in a single matrix you can pass
		// and IND_Matrix object by reference.

		mWidth = mAnimationUfo.GetActualSurface (0)->GetWidth();
		mHeight= mAnimationUfo.GetActualSurface (0)->GetHeight();
		mI->Render->SetTransform2d	(650,				// x pos
									70,					// y pos
									0,					// Angle x
									0,					// Angle y
									0,					// Angle z
									1,					// Scale x
									1,					// Scale y
									0,					// Axis cal x
									0,					// Axis cal y
									0,					// Mirror x
									0,					// Mirror y
									mWidth,				// Width
									mHeight,			// Height
									&mMatrix);			// Matrix in wich the transformation will be applied (optional)

		// 2) We apply the color, blending and culling transformations.
		mI->Render->SetRainbow2d	(IND_ALPHA,			// IND_Type
									1,					// Back face culling 0/1 => off / on
									0,					// Mirror x
									0,					// Mirror y
									IND_FILTER_LINEAR,	// IND_Filter
									255,				// R Component	for tinting
									255,				// G Component	for tinting
									255,				// B Component	for tinting
									255,				// A Component	for tinting
									0,					// R Component	for fading to a color
									0,					// G Component	for fading to a color
									0,					// B Component	for fading to a color
									255,				// Amount of fading
									IND_SRCALPHA,		// IND_BlendingType (source)
									IND_INVSRCALPHA);	// IND_BlendingType (destination)


		// 3) Blit the IND_Animation looping
		if (mI->Render->BlitAnimation	(&mAnimationUfo, 0, 0, 0, 0, 0, 0, 0, 0) == -1)
			mAnimationUfo.SetActualFramePos (0, 0);

		mI->Render->EndScene ();
		STX_CATCH;
		return 0;
	}
Exemple #2
0
		virtual int init(unsigned int width, unsigned int height)
		{
			STX_INIT_SEGVCATCH;
			STX_TRY;
			g_pIndieLib = mI = CIndieLib::Instance();

	// ----- IndieLib intialization -----

#if 0
	//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->Init ()) return 0;
#else
	
	mI = g_pIndieLib = CIndieLib::Instance();
	if (!mI->
		Init (
		"IndieLib-TankFollowsMouseFires"
		)) return -1;
#endif

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;

	// Characters animations
	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceSky, "/IndieLib-TankFollowsMouseFires/images/frigistan_sky.png", IND_OPAQUE, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceGnd, "/IndieLib-TankFollowsMouseFires/images/frigistan_ground.png", IND_OPAQUE, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->AnimationManager->AddToSurface (&animTank, "/IndieLib-TankFollowsMouseFires/images/tank.xml", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceBarrel, "/IndieLib-TankFollowsMouseFires/images/barrel.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceCursor, "/IndieLib-TankFollowsMouseFires/images/crosshairs1.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceBullet, "/IndieLib-TankFollowsMouseFires/images/bullet.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceTankShadow, "/IndieLib-TankFollowsMouseFires/images/tankshadow.png", IND_ALPHA, IND_32)) return 0;

	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	if (!mI->SurfaceManager->Add(&surfaceMuzzleFlash, "/IndieLib-TankFollowsMouseFires/images/muzzleflash.png", IND_ALPHA, IND_32)) return 0;


	//////////////////////////////////////IND_Entity2d mTextSmallWhite;
	mI->Entity2dManager->Add(&sky);
	sky.SetSurface(&surfaceSky);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&ground);
	ground.SetSurface(&surfaceGnd);
	ground.SetPosition(0, mI->Window->GetHeight() - surfaceGnd.GetHeight(), 0);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&tank);
	tank.SetAnimation(&animTank);
	tank.SetHotSpot(0.5f, 0.1f);
	tank.SetPosition(g_vecPlayer_Pos.x, g_vecPlayer_Pos.y, 0);  // initial position

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&barrel);
	barrel.SetSurface(&surfaceBarrel);
	barrel.SetHotSpot(0.5f, 1.0f);
	barrel.SetScale(1.5f, 1.5f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(&bullet);
	bullet.SetSurface(&surfaceBullet);
	bullet.SetHotSpot(0.5f, 0.5f);
	bullet.SetShow(false);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(1, &cursor);		// GUI layer
	cursor.SetSurface(&surfaceCursor);
	cursor.SetHotSpot(0.5f, 0.5f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(0, &tankShadow);
	tankShadow.SetSurface(&surfaceTankShadow);
	tankShadow.SetHotSpot(0.5f, 0.7f);

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(0, &muzzleFlash);
	muzzleFlash.SetSurface(&surfaceMuzzleFlash);
	muzzleFlash.SetHotSpot(0.5f, 0.5f);
	muzzleFlash.SetShow(false);


	// Font
	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	if (!mI->FontManager->Add (&FontSmall, "/IndieLib-TankFollowsMouseFires/font_small.png", "/IndieLib-TankFollowsMouseFires/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----

	//////////////////////////////////////IND_Entity2d mTextSmallWhite
	mI->Entity2dManager->Add(1, &mTextSmallWhite);		// Entity adding (Layer 1)
	mTextSmallWhite.SetFont			(&FontSmall);						// Set the font into the entity
	mTextSmallWhite.SetLineSpacing	(18);
	mTextSmallWhite.SetCharSpacing	(-8);
	mTextSmallWhite.SetPosition		(5, 5, 1);
	mTextSmallWhite.SetAlign		(IND_LEFT);


	timer.Start();



	// global audio manager pointer variable automatically set
	//IAudio* pAudioManager = STX_Service::GetAudioInstance()
	STX_Service::GetAudioInstance()->Init();

#if 1
	//------------------------------
	// Load all sounds
	//------------------------------
	for (int i = 0; i < MAX_SOUNDS; i++)
	{
		STX_Service::GetAudioInstance()->Load(g_SoundNames[i].szFilename.c_str(), g_SoundNames[i].szName.c_str());
	}
#endif
	STX_CATCH;
	return 0;


	// ----- Main Loop -----
	}
Exemple #3
0
//Save parameters of sprite in an xml element
void SpriteBuilder::SaveSprite(SpritePointer thesprite, ticpp::Element& xmlelement)
{
	/*XML DEFINITION EXPECTED FOR SPRITE ELEMENT:
	Element: SPRITE Atts: Id (string) x(number) y(number) h(number) w(number) Layer(number)
					 [Element: Image Atts: Id(string) [CollisionPath(string)]]
					 [Element: Font Atts: Id(string) [LineSpacing(number)] [CharSpacing(number)] [Align(string)] Text(string)]
					 [Element: Animation Atts: Id(string)] 
	*/
	
	//Get needed values from GFX system for calculations
	float globalscale = SingletonIndieLib::Instance()->GetGeneralScale();

	//-------Get attributes to save from entity---------
	float h,w; //Later is initialized
	float x = thesprite->GetPosX();
	float y = thesprite->GetPosY();
	Vector2 coordpos = SingletonIndieLib::Instance()->FromPixToCoord(Vector2(x,y));
	int z = thesprite->GetPosZ();
	float rotation = thesprite->GetAngleZ();
	int transparency = thesprite->GetTransparency();
	bool mirrorx = thesprite->GetMirrorX();
	bool mirrory = thesprite->GetMirrorY();
	bool wrap = thesprite->IfWrap();
	int wrapx = thesprite->GetRegionWidth();
	int wrapy = thesprite->GetRegionHeight();
	int layer = thesprite->GetLayer();

	//----Get elements associated with entity and remaining attributes------
	//Only one element can be associated to an entity: Image,Font,Animation
	//IF - Sprite is an image
	if(thesprite->GetSurface() != NULL)
	{
		IND_Surface* thesurface = thesprite->GetSurface();
		//Get Id of related surface
		std::string surfaceid = SingletonResourceMgr::Instance()->GetSurfaceId(thesurface);
		//Create "Image" element inside sprite
		ticpp::Element imageelement("Image");
		imageelement.SetAttribute("Id",surfaceid);
		xmlelement.InsertEndChild(imageelement);

		//Set remaining attributes from sprite
		w = (thesurface->GetWidth() * thesprite->GetScaleX()) / globalscale; 
		h = (thesurface->GetHeight() * thesprite->GetScaleY()) / globalscale;
	}//ELSE IF - Sprite is an animation
	else if(thesprite->GetAnimation() != NULL)
	{
		IND_Animation* theanimation = thesprite->GetAnimation();
		//Get Id of related animation
		std::string animationid = SingletonResourceMgr::Instance()->GetAnimationId(theanimation);
		//Create "Animation" element inside sprite
		ticpp::Element animationelement("Animation");
		animationelement.SetAttribute("Id",animationid);
		xmlelement.InsertEndChild(animationelement);

		//Find higher Width and Height in all sequences to calculate h and w
		int numsequences = theanimation->GetNumSequences();
		int hightwidth, highheight; 
		hightwidth = highheight = 0;
		//LOOP  Find bigger x and y to scale
		for(int i = 0;i<numsequences;i++)
		{
			int animwidth = theanimation->GetHighWidth(i);  //Bigger width of this sequence
			int animheight = theanimation->GetHighHeight(i); //Bigger heigth of this sequence

			//Assignment if it is bigger
			if(animwidth > hightwidth)
				hightwidth =  animwidth;
			if(animheight > highheight)
				highheight =  animheight;
		}//LOOP END

		//Set remaining attributes from sprite
		w = (hightwidth * thesprite->GetScaleX()) / globalscale; 
		h = (highheight * thesprite->GetScaleY()) / globalscale;
	}
	//TODO: SAVE FONT SETTINGS
	/*else if(////CODE \\\\\ IS A FONT)
	{

	}*/

	//Set all attributes of entity in order (to ease reading of file)
	xmlelement.SetAttribute("x",coordpos.x);
	xmlelement.SetAttribute("y",coordpos.y);
	xmlelement.SetAttribute("z",z);
	xmlelement.SetAttribute("w",w);
	xmlelement.SetAttribute("h",h);
	xmlelement.SetAttribute("Rotation",rotation);
	xmlelement.SetAttribute("Transp",transparency);
	xmlelement.SetAttribute("FlipX",mirrorx);
	xmlelement.SetAttribute("FlipY",mirrory);
	xmlelement.SetAttribute("Wrap",wrap);
	xmlelement.SetAttribute("WrapX",wrapx);
	xmlelement.SetAttribute("WrapY",wrapy);
	xmlelement.SetAttribute("Layer",layer);

}