Пример #1
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;
}
Пример #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 tile for the terrain
	IND_Surface *mSurfaceBack = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/twist.jpg", IND_OPAQUE, IND_32)) return 0;
	
	// Loading beetle
	IND_Surface *mSurfaceBeetle = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBeetle, "../../resources/beetleship.png", IND_ALPHA, IND_32)) return 0;
	
	// Loading octopus
	IND_Surface *mSurfaceOctopus = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceOctopus, "../../resources/octopus.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;

	// 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);

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

	// Terrain
	IND_Entity2d *mTerrain = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mTerrain);
	mTerrain->setSurface(mSurfaceBack);

	// Beetle
	IND_Entity2d *mBeetle = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBeetle);
	mBeetle->setSurface(mSurfaceBeetle);
	mBeetle->setHotSpot(0.5f, 0.5f);
	mBeetle->setPosition(150, 150, 2);

	// Octopus
	IND_Entity2d *mOctopus = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mOctopus);
	mOctopus->setSurface(mSurfaceOctopus);
	mOctopus->setHotSpot(0.5f, 0.5f);
	mOctopus->setPosition(450, 150, 2);

	// But
	IND_Entity2d *mBug = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBug);
	mBug->setSurface(mSurfaceBug);
	mBug->setHotSpot(0.5f, 0.5f);
	mBug->setPosition(700, 150, 2);
	
	// ----- Camera ------

	// Camera for the viewport 1
	IND_Camera2d *mCamera1 = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 4);

	// Camera for the viewport 2
	IND_Camera2d *mCamera2 = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 4);

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

	float mZoom = 1.0f;
	float mCameraAngle = 0;
	float mBugAngle = 0;
	char mText [2048];
	mText [0] = 0;
	float mSpeedRotation = 50;
	float mDelta;

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

		mI->_input->update();

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

		strcpy (mText, "Use mouse wheel for zooming in/out\n");
		strcat (mText, "Use mouse buttons for rotating the camera");
		mTextSmallWhite->setText(mText);	

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

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

		// Camera Zoom in / out
		if (mI->_input->isMouseScroll()) {
			mZoom += mI->_input->getMouseScrollY() * K_ZOOMSPEED;
		}	

		// Camera angle
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_LEFT))			mCameraAngle += mSpeedRotation * mDelta;
		if (mI->_input->isMouseButtonPressed(IND_MBUTTON_RIGHT))		mCameraAngle -= mSpeedRotation * mDelta;

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

		// Rotation of the beetle and bug
		mBugAngle += mSpeedRotation * mDelta;
		mBeetle->setAngleXYZ(0, 0, mBugAngle);
		mBeetle->setAngleXYZ(0, 0, mBugAngle);
		mBug->setAngleXYZ(0, 0, -mBugAngle);
		mBug->setAngleXYZ(0, 0, -mBugAngle);

		// Zooming and rotating the camera
		if (mZoom < 0.1f) mZoom =  0.1f;
		mCamera2->setAngle(mCameraAngle);
		mCamera2->setZoom(mZoom);

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

		// ----- Upper viewport -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight() / 2);
		mI->_render->setCamera2d(mCamera1);
		mI->_entity2dManager->renderEntities2d();

		// ----- Lower viewport -----

		mI->_render->setViewPort2d(0, mI->_window->getHeight() / 2, mI->_window->getWidth(), mI->_window->getHeight() / 2);
		mI->_render->setCamera2d(mCamera2);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

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

	mI->end();

	return 0;
}
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 -----

	// Font
	IND_Font *mFontBig = new IND_Font();
	if (!mI->_fontManager->add(mFontBig, "../../resources/font_big.png", "../../resources/font_big.xml", IND_ALPHA, IND_32)) return 0;

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

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

	// Title text
	IND_Entity2d *mTextTime = new IND_Entity2d();					
	mI->_entity2dManager->add(mTextTime);						// Entity adding
	mTextTime->setFont(mFontBig);							// Set the font into the entity

	// Creating 2d entity for the draco
	IND_Entity2d *mDraco = new IND_Entity2d();					
	mI->_entity2dManager->add(mDraco);						// Entity adding
	mDraco->setSurface(mSurfaceDraco);						// Set the surface into the entity
	mDraco->setHotSpot(0.5f, 0.5f);
	mDraco->setPosition(400, 330, 1);

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

	// Text showing the time
	mTextTime->setLineSpacing(18);
	mTextTime->setCharSpacing(-8);
	mTextTime->setPosition(280, 20, 1);
	mTextTime->setAlign(IND_LEFT);

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

	char mTimeString[128];
	mTimeString[0] = 0;
	char mTempTime[1024];
		
	// Create and start the timer;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();

	int mX = 0;
	int mSecond;

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

		mI->_input->update();

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

		// Pause / Restart time when pressing space
		if (mI->_input->onKeyPress(IND_SPACE))
		{
			if (mTimer->isPaused()){
				mTimer->unpause();
			}
			else{
				mTimer->pause();
			}
		}

		// ----- Updating entities attributes  -----
 
		mSecond = (int) (mTimer->getTicks() / 1000.0f);

		// Show the time passing in seconds
		mI->_math->itoa(mSecond,mTempTime);
           						   
		strcpy (mTimeString, "Seconds: ");
		strcat (mTimeString, mTempTime);
		mTextTime->setText(mTimeString);

		// Update Draco position each second
		mDraco->setAngleXYZ(0, 0, mSecond + 10);
 
		// ----- Render  -----

		mI->_render->beginScene();
		mI->_render->clearViewPort(60, 60, 60);
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

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

	mI->end();

	return 0;
}
Пример #4
0
/*
==================
Main
==================
*/
int IndieLib()			
{
	// ----- IndieLib intialization -----

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

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

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

	// Loading Beettleship
	IND_Surface *mSurfaceBeetleship = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceBeetleship, "../../resources/beetleship.png", IND_ALPHA, IND_32)) return 0;

	// Loading Octopus
	IND_Surface *mSurfaceOctopus = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfaceOctopus, "../../resources/octopus.png", IND_ALPHA, IND_32)) return 0;

	// Loading Planet
	IND_Surface *mSurfacePlanet = new IND_Surface();
	if (!mI->_surfaceManager->add(mSurfacePlanet, "../../resources/planet.png", IND_ALPHA, IND_32)) return 0;

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

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

	IND_Entity2d *mTextSmallWhite = new IND_Entity2d();					
	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);

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

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

	// Creating 2d entity for the bettleship
	IND_Entity2d *mBeetleship = new IND_Entity2d();					
	mI->_entity2dManager->add(mBeetleship);				// Entity adding
	mBeetleship->setSurface(mSurfaceBeetleship);			// Set the surface into the entity

	// Creating 2d entity for the octopus
	IND_Entity2d *mOctopus = new IND_Entity2d();					
	mI->_entity2dManager->add(mOctopus);				// Entity adding
	mOctopus->setSurface(mSurfaceOctopus);				// Set the surface into the entity

	// Creating 2d entity for the planet
	IND_Entity2d *mPlanet = new IND_Entity2d();					
	mI->_entity2dManager->add(mPlanet);				// Entity adding
	mPlanet->setSurface(mSurfacePlanet);				// Set the surface into the entity

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

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

	mBeetleship->setHotSpot(0.5f, 0.5f); 

	mOctopus->setMirrorX(true);
	mOctopus->setHotSpot(0.5f, 0.5f);

	mPlanet->setHotSpot(0.5f, 0.5f);

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

	float mAngle = 0;
	float mPos = 400;
	int mSpeed = 200;
	float mDelta;
	char mText [2048];
	mText [0] = 0;

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

		mI->_input->update();

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

		strcpy (mText, "Use the mouse for moving the planet\n");
		strcat (mText, "Use left and right arrow keys for moving the ships\n");
		strcat (mText, "Press CTRL + X or ESC key to quit");
		mTextSmallWhite->setText(mText);	

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

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

		// Move entities when pressing right
		if (mI->_input->isKeyPressed(IND_KEYRIGHT)){
			mPos += mSpeed * mDelta;
		}

		// Move entities when pressing left
		if (mI->_input->isKeyPressed(IND_KEYLEFT)){
			mPos -= mSpeed * mDelta;
		}

		// If CTRL + X pressed then exit
		if (mI->_input->isKeyPressed(IND_LCTRL) && mI->_input->isKeyPressed(IND_X)){
			mI->_render->endScene();
			mI->end();
			exit(0);
		}

		mAngle += (mSpeed / 4) * mDelta;

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

		// Back
		mBack->setAngleXYZ(0, 0, mAngle);		

		// Beetle
		mBeetleship->setPosition((float) mPos, 140, 1);
		mBeetleship->setAngleXYZ(0, 0, (float) mPos);

		// Planet
		mPlanet->setPosition((float) mI->_input->getMouseX(), 300, 2);
		
		// Octopus
		mOctopus->setPosition(800 - (float) mPos, 480, 3);

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

		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		mI->_render->endScene();	
	}

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

	mI->end();

	return 0;
}
Пример #5
0
/*
==================
Main
==================
*/
int IndieLib()
{
	//Sets the working path as the 'exe' directory. All resource paths are relative to this directory

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

	AnimatedGameEntity* shipExplotion = new AnimatedGameEntity(mI, Position3D(0, 0, 1), "../SpaceGame/resources/animations/Ship_Explotion.xml");
	shipExplotion->Draw();

	AnimatedGameEntity* shipRotate = new AnimatedGameEntity(mI, Position3D(0, 0, 0), "../SpaceGame/resources/animations/kali/three_oclock.xml");
	shipExplotion->Draw();




	//mDelta = mI->_render->getFrameTime() / 1000.0f;
	IND_Surface *mSurfaceBeetleship = IND_Surface::newSurface();
	if (!mI->_surfaceManager->add(mSurfaceBeetleship, "../../SpaceGame/resources/beetleship.png", IND_ALPHA, IND_32)) return 0;
	//ufo->setSequence(0);
	// Font
	IND_Font *mFontSmall = IND_Font::newFont();
	if (!mI->_fontManager->add(mFontSmall, "../../SpaceGame/resources/font_small.png", "../../resources/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// Creating 2d entity for the bettleship
	IND_Entity2d *mBeetleship = IND_Entity2d::newEntity2d();
	mI->_entity2dManager->add(mBeetleship);				// Entity adding
	mBeetleship->setSurface(mSurfaceBeetleship);			// Set the surface into the entity
	// ----- 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);



	mBeetleship->setHotSpot(0.5f, 0.5f);
	GameEntity* space = new Space(mI, Position3D(0, 0, 0), "../SpaceGame/resources/planetki new/space.jpg");
	space->Draw();


	//GameEntity* planet1 = new Planet(mI, Position3D(0, 0, 1), "../SpaceGame/resources/a4203_planetes_g.png");
	//planet1->DrawRegion(new Region(100, 220, 140, 150));

	//GameEntity* planet2 = new Planet(mI, Position3D(300, 0, 1), "../SpaceGame/resources/a4203_planetes_g.png");
	//planet1->setPosition(Position3D(300, 0, 1));
	//planet1->DrawRegion(new Region(100, 220, 140, 150));

	//GameEntity* ship = new Ship(mI, Position3D(300, 200, 1), "../SpaceGame/resources/rocket.png");
	//ship->Draw();



	float mAngle = 0;
	float mPos = 400;
	int mSpeed = 200;
	float mDelta;
	char mText[2048];
	mText[0] = 0;


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

		strcat(mText, "Use left and right arrow keys for moving the ships\n");
		strcat(mText, "Press CTRL + X or ESC key to quit");
		mTextSmallWhite->setText(mText);
		mDelta = mI->_render->getFrameTime() / 1000.0f;
		// Move entities when pressing right
		if (mI->_input->isKeyPressed(IND_KEYRIGHT)){
			mPos += mSpeed * mDelta;
		}

		// Move entities when pressing left
		if (mI->_input->isKeyPressed(IND_KEYLEFT)){
			mPos -= mSpeed * mDelta;
		}

		// If CTRL + X pressed then exit
		if (mI->_input->isKeyPressed(IND_LCTRL) && mI->_input->isKeyPressed(IND_X)){
			mI->_render->endScene();
			mI->end();
			exit(0);
		}

		mAngle += (mSpeed / 4) * mDelta;
		mBeetleship->setPosition((float)mPos, 140, 1);
		mBeetleship->setAngleXYZ(0, 0, (float)mPos);

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

	mI->end();

	return 0;
}