/* ================== 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; }
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; }