/**
 * Returns 1 (true) if the font object type 1 passed as a parameter
 * exists and is added successfully to the manager loading the font directly from
 * ::IND_Image object and a configuration file, both generated with MudFont
 * (modified version for IndieLib can be found in the section tools).
 *
 * The posibility of changing the font from an ::IND_Image object is offered in case
 * that you want to change the original font with any modification or filter from
 * ::IND_ImageManager.
 *
 * @param pNewFont					Pointer to a new object type 1 font.
 * @param pImage					Pointer to an object ::IND_Image that contains a previously loaded font from a graphic file generated by MudFont (see tools section).
 * @param pFile						Name of the configuration file of the font generated by MudFont (see tools section).
 * @param pType						Font type (see ::IND_Type).
 * @param pQuality					Font quality (see ::IND_Quality).
 */
bool IND_FontManager::addMudFont(IND_Font		*pNewFont,
                                 IND_Image		*pImage,
                                 const char     *pFile,
                                 IND_Type		pType,
                                 IND_Quality	pQuality) {
	g_debug->header("Parsing and loading MudFont font", DebugApi::LogHeaderBegin);
	g_debug->header("File name:", DebugApi::LogHeaderInfo);
	g_debug->dataChar(pFile, 1);

	if (!_ok) {
		writeMessage();
		return 0;
	}

	// ----- Width and height of the bitmap font MUST be power of two -----

	IND_Math mMath;

	if (!mMath.isPowerOfTwo(pImage->getWidth()) ||
	        !mMath.isPowerOfTwo(pImage->getHeight())) {
		g_debug->header("This operation can not be done", DebugApi::LogHeaderInfo);
		g_debug->dataChar("", 1);
		g_debug->header("The height and width of the MudFont font must be power of 2", DebugApi::LogHeaderError);
		return 0;
	}
    
    // ----- XML font parsing -----
    
	if (!parseMudFont(pNewFont, pFile)) {
		g_debug->header("Fatal error, cannot load the MudFont font xml file", DebugApi::LogHeaderError);
		return 0;
	}
    
	pNewFont->setFileName(pFile);

	// ----- Bitmap (IND_Surface object) creation -----

	IND_Surface *mNewSurface = IND_Surface::newSurface();
	if (!_surfaceManager->add(mNewSurface, pImage, pType, pQuality))
		return 0;

	// IND_Surface object MUST have one block ONLY
	if (mNewSurface->getNumBlocks() > 1) {
		_surfaceManager->remove(mNewSurface);
		return 0;
	}

	pNewFont->setSurface(mNewSurface);

	// ----- Puts the object into the manager -----

	addToList(pNewFont);

	// ----- g_debug -----

	g_debug->header("MudFont font parsed and loaded", DebugApi::LogHeaderEnd);

	return 1;
}
Exemple #2
0
/*
==================
Main
==================
*/
int IndieLib()
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;		

	// ----- Surface loading -----

	// Loading draco
	IND_Surface *mSurfaceDraco = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceDraco, "../../resources/draco.png", IND_ALPHA, IND_32)) return 0;

	// Loading gem (this image has a blue rectangle surronding it)
	IND_Surface *mSurfaceGem = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceGem, "../../resources/gem_squared.png", IND_ALPHA, IND_32)) return 0;

	// Loading bug
	IND_Surface *mSurfaceBug = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBug, "../../resources/Enemy Bug.png", IND_ALPHA, IND_32)) return 0;

	// ----- Animation loading -----

	IND_Animation *mAnimationUfo = IND_Animation::newAnimation();
	if (!mI->_animationManager->addToSurface(mAnimationUfo, "../../resources/animations/ufo.xml", IND_ALPHA, IND_32)) return 0;

	// ----- Main Loop -----

	int mWidth, mHeight;
	float mAngle = 0.0f;
	float mHotSpotX, mHotSpotY;
	int mAxisCalX, mAxisCalY;
	IND_Matrix *mMatrix = new IND_Matrix();
	float mSpeed = 50;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- 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();	
	}

	// ----- Free -----

	mI->end();

	delete mMatrix;

	return 0;
}
Exemple #3
0
/*
==================
Main
==================
*/
int IndieLib()			
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/twist.jpg", IND_OPAQUE, IND_32)) return 0;

	// Loading draco
	IND_Surface *mSurfaceDraco = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceDraco, "../../resources/draco.png", IND_ALPHA, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

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

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d() ;					
	mI->_entity2dManager->add(mTextSmallWhite);				// Entity adding
	mTextSmallWhite->setFont(mFontSmall);					// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Create a grid for Draco IND_Surface -----

	mSurfaceDraco->setGrid(8, 8);

	// ----- Set the surfaces into 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mBack);						// Entity adding
	mBack->setSurface(mSurfaceBack);						// Set the surface into the entity

	// Creating 2d entity for the draco
	IND_Entity2d *mDraco = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(mDraco);						// Entity adding
	mDraco->setSurface(mSurfaceDraco);						// Set the surface into the entity

	// ----- Changing the attributes of the 2d entities -----

	// Background
	mBack->setHotSpot(0.5f, 0.5f);
	mBack->setPosition(400, 300, 0);
	mBack->setScale(1.7f, 1.7f);

	// Draco
	mDraco->setPosition(150, 50, 1);

	// ----- Main Loop -----

	int mNumBlocksX = mSurfaceDraco->getBlocksX();
	int mNumBlocksY = mSurfaceDraco->getBlocksY();
	int mWidthBlock = mSurfaceDraco->getWidthBlock();
	int mHeightBlock = mSurfaceDraco->getHeightBlock();
	bool mShowGrid = 0;
	float mAngle = 0;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();
	float mT;
	char mText [2048];
	mText [0] = 0;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

		strcpy(mText, "Press space to see the grid in action. This is really cool, isn't it?");
		mTextSmallWhite->setText(mText);

		// ----- Input ----

		// Show / Hide the grid pressing "space"
		if (mI->_input->onKeyPress(IND_SPACE))
		{
			if (mShowGrid){
				mShowGrid = 0;
			}else{
				mShowGrid = 1;
			}
		}

		// ----- Updating entities attributes  -----

		mAngle += 0.1f;
		mBack->setAngleXYZ(0, 0, mAngle);

		// Update grid vertices for making a "wave" effect
		mT = mTimer->getTicks() / 1000.0f;
		
		for (int i = 1; i < mNumBlocksX; i++)
			for (int j = 1; j < mNumBlocksY; j++)
				mSurfaceDraco->setVertexPos (j, i, (int) ((j * mHeightBlock + cosf (mT * 10 + (i + j) / 2) * 5)), (int) ((i * mWidthBlock	+ sinf (mT * 10 + (i + j) / 2) * 5)));

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

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_entity2dManager->renderEntities2d();
		if (mShowGrid) mI->_entity2dManager->renderGridAreas(0, 0, 0, 255);
		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
/*
 ==================
 Parses an Angelcode
 XML font file
 Uses Tinyxml
 ==================
 */
bool IND_FontManager::parseAngelCodeFont(IND_Font *pNewFont,const char *pFileName, IND_Type pType, IND_Quality pQuality) {
	TiXmlDocument   *mXmlDoc = new TiXmlDocument(pFileName);
    
	// Fatal error, cannot load
	if (!mXmlDoc->LoadFile()) {
        DISPOSE(mXmlDoc);
     	return 0;
    }
    
    // Setting font filename
    pNewFont->setFileName(pFileName);
    
    // Setting the type of the font
    pNewFont->setFontType(IND_Font::FONTTYPE_AngelCode);
    
    
    // Document root
	TiXmlElement *mXFont = 0;
	mXFont = mXmlDoc->FirstChildElement("font");
    
	if (!mXFont) {
		g_debug->header("Invalid name for document root, should be <font>", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    
    //TODO : info element variables ... maybe
    
    //TODO : common element variables ... maybe
    
    //TODO : pages, this one needs to be done ... MudFont have (allways?) just one page .. Angelcode can have multiple
    
    // Image loading
    
    // Pages element
    TiXmlElement *mXPages = 0;
	mXPages = mXFont->FirstChildElement("pages");
    
    if (!mXPages) {
		g_debug->header("The <font> element doesn't have a <pages> child element", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    // Page element
	TiXmlElement *mXPage = 0;
	mXPage = mXPages->FirstChildElement("page");
    
	if (!mXPage) {
		g_debug->header("There are no <page> elements to parse", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
	// Parse each page
	int mPageCount = 0;
	while (mXPage) {
        
        // Id
		if (mXPage->Attribute("id")) {
			//pNewFont->getLetters() [mCharCount]._letter = static_cast<unsigned char>(atoi(mXChar->Attribute("id")));  //TODO : FIXME !! id refers to font image, starting from 0 -> 
		} else {
			g_debug->header("The <page> element doesn't have a \"id\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
        // File
        if (mXPage->Attribute("file")) {
            
            IND_Image *mNewImage = IND_Image::newImage();
            bool noImgError = _imageManager->add(mNewImage, mXPage->Attribute("file"));
            if (!noImgError) {
                DISPOSEMANAGED(mNewImage);
                g_debug->header("Failed at adding page image for Angelcode font", DebugApi::LogHeaderError);
                mXmlDoc->Clear();
                delete mXmlDoc;
                return 0;
            }
            
            // ----- Width and height of the bitmap font MUST be power of two -----
            
            IND_Math mMath;
            
            if (!mMath.isPowerOfTwo(mNewImage->getWidth()) ||
                !mMath.isPowerOfTwo(mNewImage->getHeight())) {
                g_debug->header("This operation can not be done", DebugApi::LogHeaderInfo);
                g_debug->dataChar("", 1);
                g_debug->header("The height and width of the AngelCode font font must be power of 2", DebugApi::LogHeaderError);
                mXmlDoc->Clear();
                delete mXmlDoc;
                return 0;
            }
            
            // ----- Bitmap (IND_Surface object) creation -----
            
            IND_Surface *mNewSurface = IND_Surface::newSurface();
            if (!_surfaceManager->add(mNewSurface, mNewImage, pType, pQuality)) {
                mXmlDoc->Clear();
                delete mXmlDoc;
                return 0;
            }   
            
            // IND_Surface object MUST have one block ONLY
            if (mNewSurface->getNumBlocks() > 1) {
                mXmlDoc->Clear();
                delete mXmlDoc;
                _surfaceManager->remove(mNewSurface);
                return 0;
            }
            
            pNewFont->setSurface(mNewSurface); // TODO: somehow handle more than one font surface, - this relates to the "id" attribute parsed..
            
		} else {
			g_debug->header("The <page> element doesn't have a \"file\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
        // Move to the next char declaration
        mXPage = mXPage->NextSiblingElement("page");
        
		mPageCount++;
	
    }
   
   
    // Chars element
    TiXmlElement *mXChars = 0;
	mXChars = mXFont->FirstChildElement("chars");
    
    if (!mXChars) {
		g_debug->header("The <font> element doesn't have a <chars> child element", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    
    if (mXChars->Attribute("count")) {
		pNewFont->setNumChars(atoi(mXChars->Attribute("count")));
		pNewFont->setLetters(new IND_Font::LETTER [pNewFont->getNumChars()]);
	} else {
		g_debug->header("The <chars> element doesn't have a \"count\" attribute", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    
    // Char element
	TiXmlElement *mXChar = 0;
	mXChar = mXChars->FirstChildElement("char");
    
	if (!mXChar) {
		g_debug->header("There are no <char> elements to parse", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
	// Parse each char
	int mCharCount = 0;
	while (mXChar) {
		
        // Id
		if (mXChar->Attribute("id")) {
			pNewFont->getLetters() [mCharCount]._letter = static_cast<unsigned char>(atoi(mXChar->Attribute("id")));
		} else {
			g_debug->header("The <char> element doesn't have a \"id\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
		// x
		if (mXChar->Attribute("x")) {
			pNewFont->getLetters() [mCharCount]._x = atoi(mXChar->Attribute("x"));
		} else {
			g_debug->header("The <char> element doesn't have a \"x\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
		// y
		if (mXChar->Attribute("y")) {
			pNewFont->getLetters() [mCharCount]._y = atoi(mXChar->Attribute("y"));
		} else {
			g_debug->header("The <char> element doesn't have a \"y\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
		// width
		if (mXChar->Attribute("width")) {
			pNewFont->getLetters() [mCharCount]._width = atoi(mXChar->Attribute("width"));
		} else {
			g_debug->header("The <char> element doesn't have a \"width\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
		// height
		if (mXChar->Attribute("height")) {
			pNewFont->getLetters() [mCharCount]._height = atoi(mXChar->Attribute("height"));
		} else {
			g_debug->header("The <char> element doesn't have a \"height\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
		// xoffset
		if (mXChar->Attribute("xoffset")) {
			pNewFont->getLetters() [mCharCount]._xOffset = atoi(mXChar->Attribute("xoffset"));
		} else {
			g_debug->header("The char doesn't have a \"xoffset\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}

		// yoffset
		if (mXChar->Attribute("yoffset")) {
			pNewFont->getLetters() [mCharCount]._yOffset = atoi(mXChar->Attribute("yoffset"));
		} else {
			g_debug->header("The <char> element doesn't have a \"yoffset\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
        // xadvance
		if (mXChar->Attribute("xadvance")) {
			pNewFont->getLetters() [mCharCount]._xAdvance = atoi(mXChar->Attribute("xadvance"));
		} else {
			g_debug->header("The <char> element doesn't have a \"xadvance\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}

        // page
		if (mXChar->Attribute("page")) {
			pNewFont->getLetters() [mCharCount]._page = atoi(mXChar->Attribute("page"));
		} else {
			g_debug->header("The <char> element doesn't have a \"page\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
 
        // chnl
		if (mXChar->Attribute("chnl")) {
			pNewFont->getLetters() [mCharCount]._chnl = atoi(mXChar->Attribute("chnl"));
		} else {
			g_debug->header("The <char> element doesn't have a \"chnl\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}

        
		// Move to the next char declaration
		mXChar = mXChar->NextSiblingElement("char");
        
		mCharCount++;
	}
    
    
    
    
    // Kernings element
    TiXmlElement *mXKernings = 0;
	mXKernings = mXFont->FirstChildElement("kernings");
    
    if (!mXKernings) {
		g_debug->header("The <font> element doesn't have a <kernings> child element", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    
    if (mXKernings->Attribute("count")) {
        pNewFont->setNumKernings(atoi(mXKernings->Attribute("count")));
		pNewFont->setKernings(new IND_Font::KERNING [pNewFont->getNumKernings()]);
	} else {
		g_debug->header("The <kernings> element doesn't have a \"count\" attribute", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
    
    // Kerning element
	TiXmlElement *mXKerning = 0;
	mXKerning = mXKernings->FirstChildElement("kerning");
    
	if (!mXKerning) {
		g_debug->header("There are no <kerning> elements to parse", DebugApi::LogHeaderError);
		mXmlDoc->Clear();
		delete mXmlDoc;
		return 0;
	}
    
	// Parse each kerning
	int mKerCount = 0;
	while (mXKerning) {
		
        // First
		if (mXKerning->Attribute("first")) {
            pNewFont->getKernings()[mKerCount]._first = atoi(mXKerning->Attribute("first"));
		} else {
			g_debug->header("The <kerning> element doesn't have a \"first\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
        // Second
		if (mXKerning->Attribute("second")) {
			pNewFont->getKernings()[mKerCount]._second = atoi(mXKerning->Attribute("second"));
		} else {
			g_debug->header("The <kerning> element doesn't have a \"second\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
                
        // Amount
		if (mXKerning->Attribute("amount")) {
			pNewFont->getKernings()[mKerCount]._amount = atoi(mXKerning->Attribute("amount"));
		} else {
			g_debug->header("The <kerning> element doesn't have a \"second\" attribute", DebugApi::LogHeaderError);
			mXmlDoc->Clear();
			delete mXmlDoc;
			return 0;
		}
        
        // Move to the next kerning declaration
		mXKerning = mXKerning->NextSiblingElement("kerning");
        
		mKerCount++;
	}


    
    
    
	mXmlDoc->Clear();
	delete mXmlDoc;
    
	return 1;
}
int IndieLib()
{
    // ----- IndieLib intialization -----

    CIndieLib *mI = CIndieLib::instance();
    if (!mI->init()) return 0;

    // ----- Get Window Dimensions

    int winWidth = mI->_window->getWidth();
    int winHeight = mI->_window->getHeight();

    srand(static_cast<unsigned int>(time(0)));

    // ----- Surface loading -----

    IND_Surface *mSurfaceBack = IND_Surface::newSurface();
    if (!mI->_surfaceManager->add(mSurfaceBack, "../SpaceGame/resources/Backgrounds/18.jpg", IND_OPAQUE, IND_32)) return 0;

    /*IND_Animation* mTestA = IND_Animation::newAnimation();
    if (!mI->_animationManager->addToSurface(mTestA, "resources/animations/dust.xml", IND_ALPHA, IND_32, 255, 0, 255)) return 0;
    mTestA->getActualFramePos(0);*/

    // Loading 2D Entities

    // Background
    IND_Entity2d* mBack = IND_Entity2d::newEntity2d();
    mI->_entity2dManager->add(mBack);
    mBack->setSurface(mSurfaceBack);
    mBack->setScale((float)winWidth / mSurfaceBack->getWidth(), (float)winHeight / mSurfaceBack->getHeight());

    Controls* controls = new Controls();
    controls->loadSettings();

    ErrorHandler* error = new ErrorHandler();
    error->initialize(mI);

    Hud* mHud = new Hud();
    mHud->createHud(mI);

    Menu* mMenu = new Menu();
    mMenu->createMenu(mI);

    Save* quickSave = new Save();

    if (!SoundEngine::initialize())
    {
        error->writeError(200, 100, "Error", "SoundEngine");
    }

    vector<Planet*> mPlanets;
    Ship* mShip = NULL;

    bool loadSave = false;
    float mDelta = 0.0f;

    IND_Timer* mTimer = new IND_Timer;
    mTimer->start();

    while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit() && !mMenu->isExit())
    {
        // get delta time
        mDelta = mI->_render->getFrameTime() / 1000.0f;

        if (mI->_input->isKeyPressed(controls->getMenu()))
        {
            mMenu->show();
            SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
        }
        if (!mMenu->isHidden())
        {
            mMenu->updateMenu(mHud, quickSave, mPlanets, mShip);
            loadSave = mHud->getLoadingText()->isShow();
        }
        else
        {
            if (loadSave)
            {
                mDelta = 0.0;
                loadSave = false;
                SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                mHud->getLoadingText()->setShow(false);
                quickSave->loadSave(mI, mShip, mPlanets);
                mHud->showHud();
            }

            if (mShip != NULL)
            {
                if (mI->_input->onKeyPress(controls->getQuickSave()))
                {
                    quickSave->makeSave(mI, mShip, mPlanets);
                }

                mHud->updateHud(mShip);

                if (mI->_input->onKeyPress(controls->getQuickLoad()))
                {
                    deleteObjects(mHud, mShip, mPlanets);
                    loadSave = true;
                }
                if (mShip->isDestroyed())
                {
                    SoundEngine::getSoundEngine()->setAllSoundsPaused(true);
                    mHud->updateGameOverText(mShip->getScore());
                    deleteObjects(mHud, mShip, mPlanets);
                    mHud->getLoadingText()->setShow(false);
                    mHud->getGameOverText()->setShow(true);
                    mMenu->show();
                }
                if(mShip!=NULL)
                {
                    //----- Collisions -----
                    checkShipPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsPlanetsCollisions(mI, mPlanets, mShip);
                    checkBulletsShipCollisions(mI, mPlanets, mShip);

                    //----- Movement update -----
                    mShip->updateShip(controls, mDelta);
                    if ((mTimer->getTicks() / 1000.0f) >= 3.0f)
                    {
                        mTimer->start();
                        mPlanets.at(rand() % mPlanets.size())->addSatellite();
                    }
                    for (vector<Planet*>::iterator it = mPlanets.begin(); it != mPlanets.end(); ++it)
                    {
                        (*it)->updatePlanet(mDelta, (mShip->getPosX() + 0.25f * mShip->getHeight() * cos(mShip->getAngleZRadian())), (mShip->getPosY() - 0.25f * mShip->getHeight() * sin(mShip->getAngleZRadian())));
                    }
                }
            }
        }

        //mI->_render->showFpsInWindowTitle();
        mI->_input->update();
        mI->_render->beginScene();
        mI->_entity2dManager->renderEntities2d();
        mI->_render->endScene();
    }

    // ----- Free -----
    delete controls;
    delete error;
    delete mHud;
    delete mMenu;
    delete quickSave;
    mI->_surfaceManager->remove(mSurfaceBack);
    mI->_entity2dManager->remove(mBack);
    deleteObjects(mHud, mShip, mPlanets);
    mI->end();
    return 0;
}
Exemple #6
0
/*!
\b Parameters:

\arg \b pNewFont				Pointer to a new object type 1 font.
\arg \b pImage					Pinter to an object ::IND_Image that contains a previously loaded font from a graphic file generated by \b MudFont (see \b tools section).
\arg \b pFile					Name of the configuration file of the font generated by \b MudFont (see \b tools section)
\arg \b pType					Font type (see ::IND_Type)
\arg \b pQuality				Font quality (see ::IND_Quality)

\b Operation:

This function returns 1 (true) if the font object type 1 passed as a parameter 
exists and is added successfully to the manager loading the font directly from
::IND_Image object and a configuration file, both generated with \b MudFont
(modified version for \b IndieLib can be found in the section \b tools).

The posibility of changing the font from an ::IND_Image object is offered in case 
that you want to change the original font with any modification or filter from 
::IND_ImageManager
*/
bool IND_FontManager::Add		(IND_Font		*pNewFont,
								IND_Image		*pImage,
								char			*pFile,
								IND_Type		pType,
								IND_Quality		pQuality)
{
	Debug->Header ("Parsing and loading font", 5);
	Debug->Header ("File name:", 3);
	Debug->DataChar (pFile, 1);

	if (!mOk)
	{	
		WriteMessage ();
		return 0;
	}
	
	// ----- Width and height of the bitmap font MUST be power of two -----

	IND_Math mMath;

	if (!mMath.IsPowerOfTwo (pImage->GetWidth ()) || 
		!mMath.IsPowerOfTwo (pImage->GetHeight ()))
	{
		Debug->Header ("This operation can not be done", 3);
		Debug->DataChar ("", 1);
		Debug->Header ("The height and width of the font must be power of 2", 2);
		return 0;
	}

	// ----- Bitmap (IND_Surface object) creation -----

	IND_Surface *mNewSurface = new IND_Surface;
	if (!mSurfaceManager->Add (mNewSurface, pImage, pType, pQuality)) 
		return 0;

	// IND_Surface object MUST have one block ONLY
	if (mNewSurface->GetNumBlocks() > 1)
	{
		mSurfaceManager->Delete (mNewSurface);
		return 0;
	}

	pNewFont->SetSurface (mNewSurface);

	// ----- XML font parsing -----

	if (!ParseFont (pNewFont, pFile))
	{
		Debug->Header ("Fatal error, cannot load the font xml file", 2);
		return 0;
	}

	pNewFont->SetFileName (pFile);

	// ----- Puts the object into the manager -----

	AddToList (pNewFont);
	
	// ----- Debug -----

	Debug->Header("Font parsed and loaded", 6);	
	
	return 1;
}
Exemple #7
0
/*
==================
Main
==================
*/
int IndieLib()			
{
    //Sets the working path as the 'exe' directory. All resource paths are relative to this directory
	if (!WorkingPathSetup::setWorkingPathFromExe(NULL)) {
		std::cout<<"\nUnable to Set the working path !";
	}
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;			

	// ----- Surface loading -----

	// Loading cave
	IND_Surface *mSurfaceCave = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceCave, "../../resources/cave.png", IND_ALPHA, IND_32)) return 0;

	// Loading cave (first plane)
	IND_Surface *mSurfaceCaveFirstPlane = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceCaveFirstPlane, "../../resources/cave_near.png", IND_ALPHA, IND_32)) return 0;

	// Loading sky
	IND_Surface *mSurfaceSky = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceSky, "../../resources/sky.jpg", IND_OPAQUE, IND_32)) return 0;

	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

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

	IND_Entity2d *mTextSmallWhite = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(3, mTextSmallWhite);				// Entity adding (Layer 3)
	mTextSmallWhite->setFont(mFontSmall);					// Set the font into the entity
	mTextSmallWhite->setLineSpacing(18);
	mTextSmallWhite->setCharSpacing	(-8);
	mTextSmallWhite->setPosition(5, 5, 1);
	mTextSmallWhite->setAlign(IND_LEFT);

	// ----- Entities -----

	// Creating 2d entity for the sky
	IND_Entity2d *mSky = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(0, mSky);					// Entity adding (Layer 0)
	mSky->setSurface(mSurfaceSky);
	mSky->setPosition(600, 0, 0);

	// Creating 2d entity for the cave
	IND_Entity2d *mCave = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(1, mCave);					// Entity adding (Layer 1)
	mCave->setSurface(mSurfaceCave);

	// Creating 2d entity for the cave (first plane)
	IND_Entity2d *mCaveFirstPlane = IND_Entity2d::newEntity2d();					
	mI->_entity2dManager->add(2, mCaveFirstPlane);				// Entity adding (Layer 2)
	mCaveFirstPlane->setSurface(mSurfaceCaveFirstPlane);

	// ----- Cameras -----

	// --- Cameras for the parallax layers --- 

	int mMiddleScreenX = mI->_window->getWidth() / 2;
	int mMiddleScreenY = mI->_window->getHeight() / 2;

	float mPosXCamera0 = (float) mMiddleScreenX;
	float mPosXCamera1 = (float) mMiddleScreenX;
	float mPosXCamera2 = (float) mMiddleScreenX;

	IND_Camera2d *mCamera0 = new IND_Camera2d((int) mPosXCamera0, mMiddleScreenY);
	IND_Camera2d *mCamera1 = new IND_Camera2d((int) mPosXCamera1, mMiddleScreenY);
	IND_Camera2d *mCamera2 = new IND_Camera2d((int) mPosXCamera2, mMiddleScreenY);

	int mSpeedLayer0 = 50;
	int mSpeedLayer1 = 162;
	int mSpeedLayer2 = 250;

	// --- Camera for showing the text that explain the input controls --- 

	IND_Camera2d *mCameraText = new IND_Camera2d((int) mI->_window->getWidth() / 2, mI->_window->getHeight() / 2);

	// --- Some variables ---

	char mText [2048];
	mText [0] = 0;
	float mDelta;

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		// ----- Input update ----

		mI->_input->update();

		// ----- Text -----

		strcpy (mText, "Use right and left arrow keys for moving the camera\n");
		mTextSmallWhite->setText(mText);

		// ----- Input ----

		mDelta = mI->_render->getFrameTime() / 1000.0f;

		// Move cameras when pressing right key
		if (mI->_input->isKeyPressed(IND_KEYRIGHT))	
		{
			// Check limits
			if (mPosXCamera2 < mSurfaceCaveFirstPlane->getWidth() - mMiddleScreenX)
			{
				mPosXCamera0 += mSpeedLayer0 * mDelta;
				mPosXCamera1 += mSpeedLayer1 * mDelta;
				mPosXCamera2 += mSpeedLayer2 * mDelta;
			}
		}

		// Move cameras when pressing left key
		if (mI->_input->isKeyPressed(IND_KEYLEFT))	
		{
			// Check limits
			if (mPosXCamera2 > mMiddleScreenX)
			{
				mPosXCamera0 -= mSpeedLayer0 * mDelta;
				mPosXCamera1 -= mSpeedLayer1 * mDelta;
				mPosXCamera2 -= mSpeedLayer2 * mDelta;
			}
		}

		// ----- Updating cameras-----

		mCamera0->setPosition((int) mPosXCamera0, mMiddleScreenY);
		mCamera1->setPosition((int) mPosXCamera1, mMiddleScreenY);
		mCamera2->setPosition((int) mPosXCamera2, mMiddleScreenY);

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

		mI->_render->clearViewPort(60, 60, 60);
		mI->_render->beginScene();

		// Render sky (Layer 0)
		mI->_render->setCamera2d(mCamera0);
		mI->_entity2dManager->renderEntities2d(0);

		// Render cave (Layer 1)
		mI->_render->setCamera2d(mCamera1);
		mI->_entity2dManager->renderEntities2d(1);

		// Render the first plane cave (Layer 2)
		mI->_render->setCamera2d(mCamera2);
		mI->_entity2dManager->renderEntities2d(2);

		// Render the text explaining the controls plane cave (Layer 3)
		mI->_render->setCamera2d(mCameraText);
		mI->_entity2dManager->renderEntities2d(3);

		mI->_render->endScene();	
	}

	// ----- Free -----

	mI->end();

	return 0;
}
Exemple #8
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 #9
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 #10
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);

}
Exemple #11
0
/*
==================
Main
==================
*/
int IndieLib()
{
	
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;

	
	// ----- Surface loading -----

	// Loading Background
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../SpaceGame/resources/blue_background.jpg", IND_OPAQUE, IND_32)) return 0;

	// Loading sprite of a star
	IND_Surface *mSurfaceStar = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceStar, "../SpaceGame/resources/star.png", IND_ALPHA, IND_32)) return 0;

	// ----- Animations loading -----

	// Characters animations, we apply a color key of (0, 48, 152)
	IND_Animation *mAnimationCharacter1 = IND_Animation::newAnimation();
	if (!mI->_animationManager->addToSurface(mAnimationCharacter1, "../SpaceGame/resources/animations/character1.xml", IND_ALPHA, IND_32, 0, 48, 152)) return 0;

	// Characters animations, we apply a color key of (0, 48, 152)
	IND_Animation *mAnimationCharacter2 = IND_Animation::newAnimation();
	if (!mI->_animationManager->addToSurface(mAnimationCharacter2, "../SpaceGame/resources/animations/character2.xml", IND_ALPHA, IND_32, 0, 48, 152)) return 0;

	// Dust animation, we apply a color key of (255, 0, 255)
	IND_Animation *mAnimationDust = IND_Animation::newAnimation();
	if (!mI->_animationManager->addToSurface(mAnimationDust, "../SpaceGame/resources/animations/dust.xml", IND_ALPHA, IND_16, 255, 0, 255)) return 0;

	// ----- Set the surface and animations into 2d entities -----

	// Creating 2d entity for the background
	IND_Entity2d *mBack = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBack);					// Entity adding
	mBack->setSurface(mSurfaceBack);					// Set the surface into the entity

	//star
	IND_Entity2d *star = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(star);
	star->setSurface(mSurfaceStar);

	// Character 1
	IND_Entity2d *mPlayer1 = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mPlayer1);					// Entity adding
	mPlayer1->setAnimation(mAnimationCharacter1);				// Set the animation into the entity

	// Character 2
	IND_Entity2d *mPlayer2 = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mPlayer2);					// Entity adding
	mPlayer2->setAnimation(mAnimationCharacter2);				// Set the animation into the entity

	// Dust explosion
	IND_Entity2d *mDust = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mDust);					// Entity adding
	mDust->setAnimation(mAnimationDust);					// Set the animation into the entity

	// ----- Changing the attributes of the 2d entities -----

	// Player 1
	mPlayer1->setSequence(0);						// Choose sequence
	mPlayer1->setPosition(140, 200, 0);
	mPlayer1->setMirrorX(1);						// Horizontal mirroring

	// Dust explosion
	mDust->setPosition(360, 250, 0);

	// Player 2
	mPlayer2->setSequence(0);						// Choose sequence
	mPlayer2->setPosition(550, 200, 0);
	mPlayer2->setNumReplays(3);						// The animation will be displayed 3 times


	//star
	star->setPosition(mI->_window->getWidth() - mSurfaceStar->getWidth(), 0, 100);
	// ----- Main Loop -----

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())
	{
		mI->_input->update();
		// Toogle full screen when pressing "space"
		//if (mI->_input->onKeyPress(IND_SPACE)) mI->_render->toggleFullScreen();
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();
	}

	// ----- Free -----

	mI->end();

	return 0;
}