Exemplo n.º 1
0
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;
}
Exemplo n.º 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 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;
}
int IndieLib() {
#ifdef PLATFORM_WIN32
	//memory leaks for win32 creation
	FINDMEMLEAK(-1);    //When you find a mem. leak, refer to the number displayed in the console and put it here to break when it is created
#endif
	// ----- IndieLib intialization -----

	CIndieLib *mI = CIndieLib::instance();
	if (!mI->init()) return 0;
    
    //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 !";
	}
	
    // ----- Fcn pointer tests initialization -----
	initTests();

	testsvectoriterator itr;
    //LOOP - Prepare Permanent tests
	for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

    //LOOP - Prepare Temporary tests
	for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
		(*itr)->prepareTests();
	}//LOOP END

	// ----- Main Loop -----
	g_mainTimer.start();
	double ticks = g_mainTimer.getTicks();
	double pastticks = g_mainTimer.getTicks();
    testsvectoriterator currentTest = g_tests.begin();
    (*currentTest)->setActive(true);

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

		mI->_input->update();

		// -------- Render -------
        mI->_render->clearViewPort(0,0,0);
		mI->_render->beginScene();
		//LOOP - Permanent Tests
		for (itr = g_permanenttests.begin(); itr != g_permanenttests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		//LOOP - Tests
		for (itr = g_tests.begin(); itr != g_tests.end(); ++itr) {
			(*itr)->performTests(static_cast<float>(ticks - pastticks));
		}//LOOP END

		mI->_entity2dManager->renderEntities2d();   //Entities rendering
		mI->_entity2dManager->renderGridAreas(g_gridcolorR,g_gridcolorG,g_gridcolorB,g_gridcolorA); //Grid areas rendering (on top of it) can be disabled per entity
		mI->_entity2dManager->renderCollisionAreas(g_collisionColorR,g_collisionColorG,g_collisionColorB,g_collisionColorA);  //Collision areas rendering (on top of it) can be disabled per entity
		mI->_render->endScene();
		//mI->_render->showFpsInWindowTitle();

		pastticks = ticks;
		ticks += g_mainTimer.getTicks();

        //Perform next test setup (if needed) Arrow keys change current temporary test using
        if (mI->_input->onKeyPress(IND_KEYRIGHT) && !mI->_input->onKeyPress(IND_KEYLEFT)){
            //Current test is not active
            (*currentTest)->setActive(false);
            currentTest++;
            
            //IF - Check limits
            if(currentTest == g_tests.end()){
                currentTest = g_tests.begin();
            }
            
            //Next test is active
            (*currentTest)->setActive(true);
        } else if (mI->_input->onKeyPress(IND_KEYLEFT) && !mI->_input->onKeyPress(IND_KEYRIGHT)){
            //Current test is not active
            (*currentTest)->setActive(false);
          
            //Decrement (taking into account limits)
            if(currentTest == g_tests.begin()){
                currentTest = g_tests.end();
            }
            currentTest--;
            
            //Next test is active
            (*currentTest)->setActive(true);
        }
            

	}

	// ----- Indielib End -----

    releaseTests();

    mI->end();
	return 0;
}
Exemplo n.º 4
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 -----
	}
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;
}
Exemplo n.º 6
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
	
//CIndieLib * mI = CIndieLib::Instance();
	if (!mI->
		Init (
		"IndieLib-Animation-Collision"
		)) return -1;
#endif
	//IND_Entity2d Beetle

	// Loading Background
	//IND_Entity2d Beetle
	if (!mI->SurfaceManager->Add (&mSurfaceBack, "/IndieLib-Animation-Collision/cave.png", IND_ALPHA, IND_32))
		return 0;

	// Loading Beetleship
	//IND_Entity2d Beetle
	if (!mI->SurfaceManager->Add (&mSurfaceBeetle, "/IndieLib-Animation-Collision/beetleship.png", IND_ALPHA, IND_32))
		return 0;

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

	// Characters animations
	//IND_Entity2d Beetle
	if (!mI->AnimationManager->AddToSurface (&AnimationCharacter, "/IndieLib-Animation-Collision/mario.xml", IND_ALPHA, IND_32))
		return 0;



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

	// Creating 2d entity for the background
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (&mBack);						// Entity adding (layer 0)
	mBack.SetSurface (&mSurfaceBack);						// Set the surface into the entity

	// Character 1
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (1, &Player);					// Entity adding (layer 1)
	Player.SetAnimation (&AnimationCharacter);				// Set the animation into the entity

	// Beetle
	//IND_Entity2d Beetle
	mI->Entity2dManager->Add (0, &Beetle);					// (layer 1)
	Beetle.SetSurface (&mSurfaceBeetle);					// Set the surface into the entity
	Beetle.SetPosition(500, 460, 0);
	Beetle.SetHotSpot (0.5f, 0.5f);
	Beetle.SetMirrorX (1);
	Beetle.SetBoundingTriangle ("beetle_head", 160, 105, 160, 170, 190, 135);
	Beetle.SetBoundingCircle ("beetle_boy_head", 85, 52, 55);



	MiddleScreenX = mI->Window->GetWidth() / 2;
	MiddleScreenY = mI->Window->GetHeight() / 2;
	CamPosX = MiddleScreenX;
	Cameras2d=IND_Camera2d(MiddleScreenX, MiddleScreenY);

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

	timer.Start();



	// Init Player
	Player.SetSequence (0);			// standing
	Player.SetPosition (x , y, 0);
	Player.SetHotSpot (0.5f, 0.5f);
	Player.SetMirrorX (0);
	Player.SetBoundingRectangle("entire", 0, 0, 48, 48);
	STX_CATCH;
	return 0;

	}
Exemplo n.º 7
0
int IndieLib()
{
	//Executable path

	//Sets the working path as the 'exe' directory. All resource paths are relative to this directory

	//TCHAR NPath[MAX_PATH];
	//GetCurrentDirectory(MAX_PATH, NPath);

	//std::basic_string<TCHAR> strName = NPath;
	//new std::string(strName.c_str());

	//std::string path = "D:\Vs2012 Project\C++ game development course\ShipGame\GameDevelopmentC-Cource\MyGame\SpaceGame";

	//ConfigurationReader* reader = new ConfigurationReader((path + "\GameConfiguration.ini").c_str());
	//std::string token = reader->getSetting("Token");

	//InstanceManager* iM = new InstanceManager();
	//iM->getPlayer(token, iM->getMachineName());

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

	_engine = new GameEngine(mI);

	_engine->initializeFonts();
	_engine->initializeEntities();

	_firstInitializationTimer.start();

	while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit())  //idle
	{
		mI->_input->update();
		_engine->processUserInput();

		if (!_firstInitializationTimer.isStarted() || _firstInitializationTimer.getTicks() > 2)
		{
			_engine->manageCollisions();
		}
		else
		{
			if (_firstInitializationTimer.isStarted())
				_firstInitializationTimer.stop();
		}

		_engine->update();

		mI->_input->update();
		mI->_render->beginScene();

		mI->_entity2dManager->renderEntities2d();
		mI->_entity2dManager->renderCollisionAreas(255, 0, 0, 255);

		mI->_render->endScene();
		
	}

	//sound->drop();
	mI->end();

	return 0;
}
Exemplo n.º 8
0
int IndieLib() // main
{
	
	char TempText[30];
	
	// ----- Sound Library --------------


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

	GameControll controller = GameControll(mI); // createing a game controller and initialize
	controller.sceneGenerator();
		

	//<------ DELTA TIME ------>
	double *delta = new double(0.1);
	double *deltaAverage = new double(0.001);
	double *mDeltaSum = new double(0.001);
	int count = 0;
	
	// time
	int gameTime = 125;

	// Create and start the timer;
	IND_Timer *mTimer = new IND_Timer();
	mTimer->start();

	bool play = false;

	float animationDelay = 30; // 30 fps animation refresh

	// ----- Main Loop -----
	while (!mI->_input->onKeyPress(IND_F12) && !mI->_input->quit() && !controller.isExitSelected())
	{
		gameTime = (int)(mTimer->getTicks() / 1000.0f); //time in seconds

		
		

		// ------ Average delta time ---------
		*delta = mI->_render->getFrameTime() / 1000.0f;
			count++;
			*mDeltaSum += *delta;

			if (count == 100){			
				count = 0;
				*deltaAverage = *mDeltaSum / 100;
				*mDeltaSum = 0;
			}

			// ----- Input Update ----
			mI->_input->update();

			// ------ Game controller update ---------------
			controller.Update(gameTime, deltaAverage);

			// ---- Update rarely -----
			// creating delay for animation
			//animationDelay -= 1000 * (*deltaAverage);
			animationDelay -= mI->_render->getFrameTime();
			if (animationDelay < 0) 
			{
				animationDelay = 30;
				controller.AnimationsUpdate();
			}
		
			

		// -------- Render -------
		mI->_render->clearViewPort(0, 0, 60);
		mI->_render->beginScene();
		mI->_entity2dManager->renderEntities2d();
		// mI->_entity2dManager->renderCollisionAreas(255, 0, 0, 255); // for tests
		mI->_render->endScene();
		mI->_render->showFpsInWindowTitle(); //FPS
		//mI->_entity2dManager->renderGridAreas(255, 255, 0, 255);
	}

	// ----- Indielib End -----
	mI->end();

	return 0;
}
Exemplo n.º 9
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 (!CIndieLib::Instance()->Init ()) return 0;
#else
	
	mI = CIndieLib::Instance();
	if (!CIndieLib::Instance()->
		Init (
		"IndieLib-Transitions"
		)) return -1;
#endif

	// Loading layer 1
	//////////IND_Timer timer;
	if (!mI->SurfaceManager->Add (&SurfaceSnake, "/IndieLib-Transitions/snake_512.jpg", IND_ALPHA, IND_32)) return 0;

	// Loading layer 1
	//////////IND_Timer timer;
	if (!mI->SurfaceManager->Add (&SurfacePool, "/IndieLib-Transitions/pool_512.jpg", IND_ALPHA, IND_32)) return 0;

	// ----- Font creation -----
	// Font (layer 3)
	//////////IND_Timer timer;
	if (!mI->FontManager->Add (&FontSmall, "/IndieLib-Transitions/font_small.png", "/IndieLib-Transitions/font_small.xml", IND_ALPHA, IND_32)) return 0;

	// Create the Font
	//////////IND_Timer timer;
	mI->Entity2dManager->Add		(1, &TextSmallWhite);		// Entity adding (Layer 3)
	TextSmallWhite.SetFont			(&FontSmall);				// Set the font into the entity
	TextSmallWhite.SetLineSpacing	(18);
	TextSmallWhite.SetCharSpacing	(-8);
	TextSmallWhite.SetPosition		(5, 5, 1);
	TextSmallWhite.SetAlign		(IND_LEFT);

	// Creating 2d entity for the pool
	g_pSourceEntity2d = new IND_Entity2d();
	mI->Entity2dManager->Add (0, g_pSourceEntity2d);			// Entity adding !!! Note the first parameter is layer #
	g_pSourceEntity2d->SetSurface (&SurfacePool);				// Set the surface into the entity

	// Creating 2d entity for the snake
	g_pDestEntity2d	= new IND_Entity2d();
	mI->Entity2dManager->Add (0, g_pDestEntity2d);			// Entity adding !!! Note the first parameter is layer #
	g_pDestEntity2d->SetSurface (&SurfaceSnake);			// Set the surface into the entity
	g_pDestEntity2d->SetPosition(0, 0, 0);


	//////////IND_Timer timer;

	g_szTitle = "ALPHA2";
	
	// ----- Main Loop -----

	timer.Start();

	// Create the first transition
	g_pMainTransition = new Transition(g_pSourceEntity2d, g_pDestEntity2d, ALPHA2, g_pSourceEntity2d->GetSurface()->GetWidth(), g_pSourceEntity2d->GetSurface()->GetHeight());
	STX_CATCH;
	return 0;


	}