bool BulletFactory::Suck(float mDelta,Evertable * ever,const char * str){ queue<Bullet*> temp; //const char * type("bonus"); while(!current.empty()){ Bullet * Bob = current.front(); current.pop(); IND_Entity2d * ent = ever->getEntity(); IND_Entity2d * ent2 = Bob->getEntity(); if((Bob->isEverted() == false) && mI->_entity2dManager->isCollision(ent,str,ent2,"bonus")){ float ydiff = ent2->getPosY() - ent->getPosY(); float xdiff = ent2->getPosX() - ent->getPosX(); float strength = xdiff*xdiff+ydiff*ydiff; float xrate = xdiff*xdiff/strength; float yrate = 1-xrate; if(ydiff < 0){ yrate = -yrate; } if(xdiff < 0){ xrate = -xrate; } Bob->setXY(ent2->getPosX()-xrate*300*mDelta,ent2->getPosY()-yrate*300*mDelta); if(strength < 20){ mScore->addtoScore(10); disappear(Bob); } else { temp.push(Bob); } } else { temp.push(Bob); } } current = temp; return true; }
IND_Entity2d * FontManager::createText(const char * type){ if(type == "small"){ IND_Entity2d* mText = IND_Entity2d::newEntity2d(); mI->_entity2dManager->add(mText); // Entity adding mText->setFont(mFontSmall); mText->setLineSpacing (18); mText->setCharSpacing (-7); return mText; } }
virtual int render() { STX_TRY; mI->Input->Update (); fElapsedTime = mI->Render->GetFrameTime() / 1000.0f; // ----- Text ----- g_szText = g_szTitle; g_szText += "\n"; g_szText += "Hit SPACE for next transition\n"; g_szText += "ESC to quit"; TextSmallWhite.SetText ((char*)g_szText.c_str()); mI->Render->BeginScene (); mI->Render->ClearViewPort (60, 60, 60); mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight()); Update(fElapsedTime); for (int i = 0; i < 2; i++) mI->Entity2dManager->RenderEntities2d ( i ); //???mI->Render->ShowFpsInWindowTitle(); mI->Render->EndScene (); STX_CATCH; return 0; }
virtual int render() { STX_TRY; // ----- Input update ---- mI->Input->Update (); // ----- Input ---- mDelta = mI->Render->GetFrameTime() / 1000.0f; if (mI->Input->IsKeyPressed (KEY_RIGHT)) mScale += mSpeedScaling * mDelta; if (mI->Input->IsKeyPressed (KEY_LEFT)) mScale -= mSpeedScaling * mDelta; mAngle += mSpeedRotation * mDelta; if (mScale < 0) mScale = 0; // ----- Updating entities attributes ----- mBack.SetAngleXYZ (0, 0, -mAngle); mRocket.SetAngleXYZ (0, 0, mAngle); mRocket.SetScale (mScale, mScale); mBeetle.SetPosition ((float) mI->Input->GetMouseX(), (float) mI->Input->GetMouseY(), 5); // ----- Check collisions ----- mTextSmallWhite.SetText ("No collision between the groups we are checking"); if (mI->Entity2dManager->IsCollision (&mRocket, "engines", &mBeetle, "beetle_boy_head")) mTextSmallWhite.SetText ("Collision between rocket boy head and engines"); if (mI->Entity2dManager->IsCollision (&mRocket, "rocket_head", &mBeetle, "beetle_head")) mTextSmallWhite.SetText ("Collision between rokect head and beetle head"); if (mI->Entity2dManager->IsCollision (&mRocket, "rocket_boy_head", &mBeetle, "beetle_boy_head")) mTextSmallWhite.SetText ("Collision between rocket boy head and beetle boy head"); if (mI->Entity2dManager->IsCollision (&mBeetle, "beetle_boy_head", &mSwordMaster, "sword")) mTextSmallWhite.SetText ("Collision between beetle boy head and the sword"); // ----- Render ----- mI->Render->BeginScene (); mI->Entity2dManager->RenderEntities2d (); mI->Entity2dManager->RenderCollisionAreas (255, 0, 0, 255); //mI->Entity2dManager->RenderGridAreas (255, 255, 0, 255); mI->Render->EndScene (); STX_CATCH; return 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 (!CIndieLib::Instance()-> Init ( "a_08_Collisions" )) return -1; #endif // ----- Surface loading ----- // Loading Background ////////////////////IND_Entity2d mTextSmallWhite; if (!mI->SurfaceManager->Add (&mSurfaceBack, "/twist.jpg", IND_OPAQUE, IND_32)) return 0; // Loading Rocket ////////////////////IND_Entity2d mTextSmallWhite; if (!mI->SurfaceManager->Add (&mSurfaceRocket, "/rocket.png", IND_ALPHA, IND_32)) return 0; // Loading Beetleship ////////////////////IND_Entity2d mTextSmallWhite; if (!mI->SurfaceManager->Add (&mSurfaceBeetle, "/beetleship.png", IND_ALPHA, IND_32)) return 0; // Sword Master animation, we apply a color key of (0, 255, 0) ////////////////////IND_Entity2d mTextSmallWhite; if (!mI->AnimationManager->AddToSurface (&mSwordMasterAnimation, "/animations/sword_master.xml", IND_ALPHA, IND_16, 0, 255, 0)) return 0; // ----- Font loading ----- // Font ////////////////////IND_Entity2d mTextSmallWhite; if (!mI->FontManager->Add (&mFontSmall, "/font_small.png", "/font_small.xml", IND_ALPHA, IND_32)) return 0; // ----- Set the surfaces into 2d entities ----- // Creating 2d entity for the background ////////////////////IND_Entity2d mTextSmallWhite; mI->Entity2dManager->Add (&mBack); // Entity adding mBack.SetSurface (&mSurfaceBack); // Set the surface into the entity // Creating 2d entity for the Rocket ////////////////////IND_Entity2d mTextSmallWhite; mI->Entity2dManager->Add (&mRocket); // Entity adding mRocket.SetSurface (&mSurfaceRocket); // Set the surface into the entity // Creating 2d entity for the Beetleship ////////////////////IND_Entity2d mTextSmallWhite; mI->Entity2dManager->Add (&mBeetle); // Entity adding mBeetle.SetSurface (&mSurfaceBeetle); // Set the surface into the entity // Creating 2d entity for the Sword Master animation ////////////////////IND_Entity2d mTextSmallWhite; mI->Entity2dManager->Add (&mSwordMaster); // Entity adding mSwordMaster.SetAnimation (&mSwordMasterAnimation); // Set the animation into the entity // Text small white ////////////////////IND_Entity2d mTextSmallWhite; mI->Entity2dManager->Add (&mTextSmallWhite); // Entity adding mTextSmallWhite.SetFont (&mFontSmall); // Set the font 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); // Beetle mBeetle.SetHotSpot (0.5f, 0.5f); mBeetle.SetMirrorX (1); mBeetle.SetBoundingTriangle ("beetle_head", 160, 105, 160, 170, 190, 135); mBeetle.SetBoundingCircle ("beetle_boy_head", 85, 52, 55); // Rocket mRocket.SetHotSpot (0.5f, 0.5f); mRocket.SetPosition (200, 450, 1); mRocket.SetBoundingAreas ("/rocket_collisions.xml"); //mRocket.DeleteBoundingAreas ("engines"); // Sword Master Animation mSwordMaster.SetHotSpot (0.5f, 0.5f); mSwordMaster.SetPosition (400, 220, 3); // Text mTextSmallWhite.SetLineSpacing (18); mTextSmallWhite.SetCharSpacing (-7); mTextSmallWhite.SetPosition (400, 30, 10); mTextSmallWhite.SetAlign (IND_CENTER); // ----- Main Loop ----- STX_CATCH; 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; }
/* ================== 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; }
virtual int render() { STX_TRY; mI->Input->Update (); // ----- Delta Time ----- fElapsedTime = mI->Render->GetFrameTime() / 1000.0f; // ----- Text ----- stx_strlcpy (szText, "Move the mouse left and right and watch the tank try to follow!\n", 2048); stx_strlcat (szText, "Press Left Mouse button to fire!\n", 2048); stx_strlcat (szText, "Press 'f' to toggle freezing the tank movement (debug)\n", 2048); stx_snprintf(szBuf, 2048, "%d, %d\n", mI->Input->GetMouseX(), mI->Input->GetMouseY() ); stx_strlcat (szText, szBuf, 2048); stx_snprintf(szBuf, 2048, "%.3f, %.3f\n", g_vecPlayer_Pos.x, g_vecPlayer_Pos.y); stx_strlcat (szText, szBuf, 2048); stx_snprintf(szBuf, 2048, "Muzzle angle %.3f\n", g_fGunAngle); stx_strlcat (szText, szBuf, 2048); stx_snprintf(szBuf, 2048, "Tank velocity %.3f\n", g_vecPlayer_Velocity.x); stx_strlcat (szText, szBuf, 2048); mTextSmallWhite.SetText (szText); // Position the mouse cursor cursor.SetPosition((float)mI->Input->GetMouseX(), (float)mI->Input->GetMouseY(), 1); // "Freeze" tank except allow gun to rotate if (mI->Input->OnKeyPress(KEY_f)) g_bToggleFreezeTank = !g_bToggleFreezeTank; ULONG Direction = 0; float deltaX = g_vecPlayer_Pos.x - mI->Input->GetMouseX(); if (!g_bToggleFreezeTank && fabs(deltaX) > g_Epsilon) { if (deltaX < 0) { Direction |= DIR_RIGHT; tank.SetSequence(1); } else if (deltaX > 0) { Direction |= DIR_LEFT; tank.SetSequence(2); } } else { // Stop the animation if not moving tank.SetSequence(0); } // Any movement? if ( Direction && !g_bToggleFreezeTank ) { Player_Move( Direction, g_fSpeed * fElapsedTime, true ); } //--------------------------- // Update the player //--------------------------- Player_Update( fElapsedTime ); //--------------------------- // Move and rotate the barrel // Note: there would normally be a class representing the whole tank //--------------------------- float fMouse2TankX = tank.GetPosX() - mI->Input->GetMouseX(); float fMouse2TankY = tank.GetPosY() - mI->Input->GetMouseY(); // y position going down // Clamp. Mouse is below tank if (fMouse2TankY < 0.0f) fMouse2TankY = 0.0f; g_fGunAngle = atan2(fMouse2TankY, fMouse2TankX) * 180.0f / fPI; // in degrees g_fGunAngle -= 90.0f; // barrel is initially pointing up (in image). atan2() w.r.t x-axis (pointing right) barrel.SetAngleXYZ(0.0f, 0.0f, g_fGunAngle); // Set position of barrel (child) on the tank (parent) g_vecBarrel.x = tank.GetPosX(); g_vecBarrel.y = tank.GetPosY(); barrel.SetPosition(g_vecBarrel.x, g_vecBarrel.y, 0); // Move the tank (player) tank.SetPosition(g_vecPlayer_Pos.x, g_vecPlayer_Pos.y, 1); tankShadow.SetPosition(tank.GetPosX(), tank.GetPosY() + 50, 0); // location is tank HotSpot plus an offset of 50 //--------------------------- // Fire weapon!! //--------------------------- if (5 && mI->Input->OnMouseButtonPress(MBUTTON_LEFT)) { // Initial bullet position (following code is rather verbose and could be combined into less lines // but did it that way to explain the math. float angleDegrees = barrel.GetAngleZ() + 90.0f; float angleRadians = angleDegrees * fPI / 180.0f; float fX = barrel.GetPosX() - cosf(angleRadians) * BARREL_LENGTH; float fY = barrel.GetPosY() - sinf(angleRadians) * BARREL_LENGTH; bullet.SetAngleXYZ(0, 0, angleDegrees - 90.0f); g_vecBullet_Pos = D3DXFROMWINEVECTOR3(fX, fY, 0.0f); bullet.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0); // Initial bullet velocity D3DXFROMWINEMATRIX mtxRotate; D3DXFROMWINEVECTOR3 vecVelDir = D3DXFROMWINEVECTOR3(-1.0f, 0.0f, 0.0f); D3DXFROMWINEMatrixRotationZ( &mtxRotate, angleRadians); D3DXFROMWINEVec3TransformNormal( &vecVelDir, &vecVelDir, &mtxRotate ); g_vecBullet_Velocity = vecVelDir * BULLET_SPEED; // Show blast! g_fMuzzleFlashTimer = 0.05f; muzzleFlash.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0); g_bBulletDead = false; // Make sound! (no sound lib hooked up but this is where you would do it. STX_Service::GetAudioInstance()->Play("tankfire1"); } // Update the single bullet if (!g_bBulletDead) { bullet.SetShow(true); Bullet_Update( fElapsedTime, &bullet ); bullet.SetPosition(g_vecBullet_Pos.x, g_vecBullet_Pos.y, 0); } else { bullet.SetShow(false); } //--------------------------- // Render muzzle flash effect //--------------------------- g_fMuzzleFlashTimer -= fElapsedTime; if (g_fMuzzleFlashTimer > 0.0f) { muzzleFlash.SetShow(true); } else { muzzleFlash.SetShow(false); g_fMuzzleFlashTimer = 0.0f; } //----------------- // Render the scene //----------------- mI->Render->BeginScene (); mI->Render->ClearViewPort (160, 160, 160); mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight()); mI->Entity2dManager->RenderEntities2d ( ); // Render GUI layer mI->Entity2dManager->RenderEntities2d (1); //???mI->Render->ShowFpsInWindowTitle(); // MUST call this to update FMOD STX_Service::GetAudioInstance()->Update(); mI->Render->EndScene (); STX_CATCH; return 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; // ----- Loading of the original image and making 4 duplicates ----- IND_Image *mImageBugOriginal = IND_Image::newImage(); if (!mI->_imageManager->add(mImageBugOriginal, "../../resources/Enemy Bug.png")) return 0; IND_Image *mImageBugGaussian = IND_Image::newImage(); if (!mI->_imageManager->clone(mImageBugGaussian, mImageBugOriginal)) return 0; IND_Image *mImageBugPixelize = IND_Image::newImage(); if (!mI->_imageManager->clone(mImageBugPixelize, mImageBugOriginal)) return 0; IND_Image *mImageBugContrast = IND_Image::newImage(); if (!mI->_imageManager->clone(mImageBugContrast, mImageBugOriginal)) return 0; // ----- Applying filters ----- mImageBugGaussian->gaussianBlur(5); mImageBugPixelize->pixelize(5); mImageBugContrast->contrast(60); // ----- Surface creation ----- // Loading Background IND_Surface *mSurfaceBack = IND_Surface::newSurface(); if (!mI->_surfaceManager->add(mSurfaceBack, "../../resources/blue_background.jpg", IND_OPAQUE, IND_32)) return 0; // Creating the "Original Bug" surface from the IND_Image IND_Surface *mOriginalSurface = IND_Surface::newSurface(); if (!mI->_surfaceManager->add(mOriginalSurface, mImageBugOriginal, IND_ALPHA, IND_32)) return 0; // Creating the "Gaussian bug" surface from the IND_Image IND_Surface *mGaussianSurface = IND_Surface::newSurface(); if (!mI->_surfaceManager->add(mGaussianSurface, mImageBugGaussian, IND_ALPHA, IND_32)) return 0; // Creating the "Pixelize bug" surface from the IND_Image IND_Surface *mPixelizeSurface = IND_Surface::newSurface(); if (!mI->_surfaceManager->add(mPixelizeSurface, mImageBugPixelize, IND_ALPHA, IND_32)) return 0; // Creating the "Contrast bug" surface from the IND_Image IND_Surface *mContrastSurface = IND_Surface::newSurface(); if (!mI->_surfaceManager->add(mContrastSurface, mImageBugContrast, IND_ALPHA, IND_32)) return 0; // ----- Deleting of images ----- mI->_imageManager->remove(mImageBugOriginal); mI->_imageManager->remove(mImageBugGaussian); mI->_imageManager->remove(mImageBugPixelize); mI->_imageManager->remove(mImageBugContrast); // ----- Set the surfaces into the 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 "Original bug" IND_Entity2d *mOriginal = IND_Entity2d::newEntity2d(); mI->_entity2dManager->add(mOriginal); // Entity adding mOriginal->setSurface(mOriginalSurface); // Set the surface into the entity // Creating 2d entity for the "Gaussian bug" IND_Entity2d *mGaussian = IND_Entity2d::newEntity2d(); mI->_entity2dManager->add(mGaussian); // Entity adding mGaussian->setSurface(mGaussianSurface); // Set the surface into the entity // Creating 2d entity for the "pixelize bug" IND_Entity2d *mPixelize = IND_Entity2d::newEntity2d(); mI->_entity2dManager->add(mPixelize); // Entity adding mPixelize->setSurface(mPixelizeSurface); // Set the surface into the entity // Creating 2d entity for the "Contrast bug" IND_Entity2d *mContrast = IND_Entity2d::newEntity2d(); mI->_entity2dManager->add(mContrast); // Entity adding mContrast->setSurface(mContrastSurface); // Set the surface into the entity // ----- Changing the attributes of the 2d entities ----- mOriginal->setPosition(290, 90, 0); mGaussian->setPosition( 50, 230, 0); mPixelize->setPosition(290, 230, 0); mContrast->setPosition(520, 230, 0); // ----- Main Loop ----- while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { mI->_input->update(); mI->_render->beginScene(); mI->_entity2dManager->renderEntities2d(); mI->_render->endScene(); } // ----- Free ----- mI->end(); return 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; }
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; }
virtual int render() { STX_TRY; mI->Input->Update (); // ----- Delta Time ----- fElapsedTime = mI->Render->GetFrameTime() / 1000.0f; // Toggle show bounding boxes if (mI->Input->OnKeyPress(KEY_p)) bShowBoundsToggle = !bShowBoundsToggle; // Walk Left! if (mI->Input->IsKeyPressed(KEY_LEFT)) { VelocityX -= speed * fElapsedTime; if (!playerJumping) Player.SetSequence(0); //walk Player.SetMirrorX(1); } // Walk Right! else if (mI->Input->IsKeyPressed(KEY_RIGHT)) { VelocityX += speed * fElapsedTime; if (!playerJumping) Player.SetSequence(0); //walk Player.SetMirrorX(0); } else { if (!playerJumping) Player.SetSequence(1); // stand VelocityX = 0.0f; // 0 = no slide } // JUMP! if(mI->Input->OnKeyPress(KEY_SPACE) && !playerJumping) { VelocityY -= fJumpForce; // jump force (minus is up) Player.SetSequence(2); // jump playerJumping = true; } // TODO - if no key press then apply friction. We want the player to move instantly // yet slide to a stop. VelocityY += gravity * fElapsedTime; // apply gravity (value is gravity) y += VelocityY * fElapsedTime; // position // Check falling limits (poor man collision detection!) if (y > 500) { VelocityY = 0; y = 500; playerJumping = false; } // Clamp walking velocity float Length = sqrtf(VelocityX * VelocityX); if ( Length > MaxVelocityX ) { VelocityX *= ( MaxVelocityX / Length ); } // End if clamp X velocity x += VelocityX * fElapsedTime; if (x < 0) x = 0; // Move the player Player.SetPosition(x, y, 0); // Apply slide friction float Dec = -Dir * slideFriction * fElapsedTime; if (mI->Entity2dManager->IsCollision (&Player, "/IndieLib-Animation-Collision/entire", &Beetle, "/IndieLib-Animation-Collision/beetle_boy_head")) { VelocityY = 80; // force him downward VelocityX = 0; } if (x > mI->Window->GetWidth() / 2) Cameras2d.SetPosition((int)x, MiddleScreenY); mI->Render->BeginScene (); mI->Render->ClearViewPort (60, 60, 60); mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth(), mI->Window->GetHeight()); mI->Render->SetCamera2d (&Cameras2d); for (int i = 0; i < 16; i++) { mI->Entity2dManager->RenderEntities2d ( i ); if (bShowBoundsToggle) mI->Entity2dManager->RenderCollisionAreas (i, 255, 0, 0, 255); } //???mI->Render->ShowFpsInWindowTitle(""); mI->Render->EndScene (); STX_CATCH; return 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; }
/* ====================================== Listen for possible changes that the selected backdrop (the one where the cursos is over) can suffer ====================================== */ void Listener::ListenHoverBackDrop () { static int mMouseClickX; static int mMouseClickY; IND_Entity2d *mBackDropOver = mBackDropNodeOver->GetEntity(); // -------------------- Translate the selected backdrop image -------------------- static float mInitialPosX, mInitialPosY; float mNewPosX, mNewPosY; if (!mIsRotatingBackDrop && !mIsScalingBackDrop) { if (mI->_input->onMouseButtonPress(IND_MBUTTON_LEFT)) { mMouseClickX = (int) mPosBrushX; mMouseClickY = (int) mPosBrushY; mInitialPosX = mBackDropOver->getPosX(); mInitialPosY = mBackDropOver->getPosY(); } if (mI->_input->isMouseButtonPressed (IND_MBUTTON_LEFT)) { mNewPosX = mInitialPosX + (mPosBrushX - mMouseClickX); mNewPosY = mInitialPosY + (mPosBrushY - mMouseClickY); mBackDropOver->setPosition (mNewPosX, mNewPosY, mBackDropOver->getPosZ()); mIsTranslatingBackDrop = true; } if (mI->_input->onMouseButtonRelease(IND_MBUTTON_LEFT)) { mIsTranslatingBackDrop = false; } } // -------------------- Translate pixel by pixel -------------------- if (mI->_input->onKeyPress (IND_F)) { mBackDropOver->setPosition (mBackDropOver->getPosX() - 1, mBackDropOver->getPosY(), mBackDropOver->getPosZ()); } if (mI->_input->onKeyPress (IND_G)) { mBackDropOver->setPosition (mBackDropOver->getPosX() + 1, mBackDropOver->getPosY(), mBackDropOver->getPosZ()); } if (mI->_input->onKeyPress (IND_C)) { mBackDropOver->setPosition (mBackDropOver->getPosX(), mBackDropOver->getPosY() - 1, mBackDropOver->getPosZ()); } if (mI->_input->onKeyPress (IND_V)) { mBackDropOver->setPosition (mBackDropOver->getPosX(), mBackDropOver->getPosY() + 1, mBackDropOver->getPosZ()); } // -------------------- Scale the selected backdrop image -------------------- static float mInitialScale; float mNewScale; static int mInitialRegionX, mInitialRegionY; int mNewRegionX, mNewRegionY; if (!mIsRotatingBackDrop && !mIsTranslatingBackDrop) { if (mI->_input->onMouseButtonPress (IND_MBUTTON_RIGHT) && mI->_input->isKeyPressed (IND_LSHIFT)) { mMouseClickX = (int) mPosBrushX; if (!mBackDropOver->ifWrap()) { mInitialScale = mBackDropOver->getScaleX(); } else { mInitialRegionX = mBackDropOver->getRegionWidth(); mInitialRegionY = mBackDropOver->getRegionHeight(); } } if (mI->_input->isMouseButtonPressed (IND_MBUTTON_RIGHT) && mI->_input->isKeyPressed(IND_LSHIFT)) { mIsScalingBackDrop = true; if (!mBackDropOver->ifWrap()) { mNewScale = mInitialScale + ((mPosBrushX - mMouseClickX) / 1000); if (mNewScale < 0.05f) mNewScale = 0.1f; mBackDropOver->setScale (mNewScale, mNewScale); } else { mNewRegionX = mInitialRegionX + ((int) mPosBrushX - mMouseClickX); mNewRegionY = mInitialRegionY + ((int) mPosBrushX - mMouseClickX); mBackDropOver->setRegion (0, 0, (int) mNewRegionX, (int) mNewRegionY); } } if (mI->_input->onMouseButtonRelease (IND_MBUTTON_RIGHT)) { mIsScalingBackDrop = false; } } // -------------------- Rotate the selected backdrop image -------------------- static float mInitialAngle; float mNewAngle; if (!mIsTranslatingBackDrop && !mIsScalingBackDrop) { if (mI->_input->onMouseButtonPress (IND_MBUTTON_RIGHT)) { mMouseClickX = (int) mPosBrushX; mInitialAngle = mBackDropOver->getAngleZ(); } if (mI->_input->isMouseButtonPressed (IND_MBUTTON_RIGHT)) { mNewAngle = mInitialAngle + (mPosBrushX - mMouseClickX); mBackDropOver->setAngleXYZ (0, 0, mNewAngle); mIsRotatingBackDrop = true; } if (mI->_input->onMouseButtonRelease (IND_MBUTTON_RIGHT)) { mIsRotatingBackDrop = false; } } // -------------------- Flip backdrop image -------------------- if (mI->_input->onKeyPress(IND_T)) { (mBackDropOver->getMirrorX() == true) ? mBackDropOver->setMirrorX (false) : mBackDropOver->setMirrorX (true); } if (mI->_input->onKeyPress(IND_Y)) { (mBackDropOver->getMirrorY() == true) ? mBackDropOver->setMirrorY (false) : mBackDropOver->setMirrorY (true); } // -------------------- Transparency -------------------- if (mI->_input->isKeyPressed (IND_U, 5)) { if (mBackDropOver->getTransparency() > 0) mBackDropOver->setTransparency (mBackDropOver->getTransparency() - 1); } if (mI->_input->isKeyPressed (IND_I, 5)) { if (mBackDropOver->getTransparency() < 255) mBackDropOver->setTransparency (mBackDropOver->getTransparency() + 1); } // -------------------- Tiling -------------------- if (mI->_input->onKeyPress(IND_L) && !mI->_input->isKeyPressed (IND_LCTRL)) { (mBackDropOver->ifWrap() == true) ? mBackDropOver->toggleWrap (false) : mBackDropOver->toggleWrap (true); mBackDropOver->setRegion (0, 0, mBackDropOver->getSurface()->getWidth(), mBackDropOver->getSurface()->getHeight()); } // -------------------- Tinting -------------------- if (mI->_input->isKeyPressed(IND_SPACE)) { mBackDropOver->setTint ((BYTE) mMouseX, (BYTE) mMouseY, (BYTE) mMouseX); mIsTintingBackDrop = true; } if (mI->_input->onKeyRelease(IND_SPACE)) { mIsTintingBackDrop = false; } // -------------------- Z ordering -------------------- if (mI->_input->onKeyPress(IND_Z)) { mBackDropOver->setPosition (mBackDropOver->getPosX(), mBackDropOver->getPosY(), mBackDropOver->getPosZ() - 1); } if (mI->_input->onKeyPress(IND_X)) { mBackDropOver->setPosition (mBackDropOver->getPosX(), mBackDropOver->getPosY(), mBackDropOver->getPosZ() + 1); } // -------------------- Clone -------------------- if (mI->_input->isKeyPressed(IND_LSHIFT) && mI->_input->onMouseButtonPress (IND_MBUTTON_LEFT)) { mMap->CloneNode (mBackDropNodeOver); // Clone node } // -------------------- Delete -------------------- if (mI->_input->onKeyPress(IND_DELETE)) { mMap->DeleteNode (mBackDropNodeOver); // Erase the node from the map vector } }
/* ================== Main ================== */ int IndieLib() { // ----- IndieLib intialization ----- CIndieLib *mI = CIndieLib::instance(); if (!mI->init()) return 0; // ----- Set the primitives into 2d entities ----- // Pixel IND_Entity2d *mPixel = new IND_Entity2d(); mI->_entity2dManager->add(mPixel); mPixel->setPrimitive2d(IND_PIXEL); mPixel->setPosition(200, 75, 0); mPixel->setTint(255, 255, 255); // Regular poly IND_Entity2d *mRegularPoly = new IND_Entity2d(); mI->_entity2dManager->add(mRegularPoly); mRegularPoly->setPrimitive2d(IND_REGULAR_POLY); mRegularPoly->setPosition(200, 75, 0); mRegularPoly->setNumSides(5); mRegularPoly->setRadius(50); mRegularPoly->setTint(255, 0, 0); // Line IND_Entity2d *mLine = new IND_Entity2d(); mI->_entity2dManager->add(mLine); mLine->setPrimitive2d (IND_LINE); mLine->setLine(100, 100, 50, 50); mLine->setTint(0, 255, 0); // Rectangle IND_Entity2d *mRectangle = new IND_Entity2d(); mI->_entity2dManager->add(mRectangle); mRectangle->setPrimitive2d(IND_RECTANGLE); mRectangle->setRectangle(350, 50, 400, 100); mRectangle->setTint(0, 0, 255); // Filled rectangle IND_Entity2d *mFillRectangle = new IND_Entity2d(); mI->_entity2dManager->add(mFillRectangle); mFillRectangle->setPrimitive2d(IND_FILL_RECTANGLE); mFillRectangle->setRectangle(550, 40, 650, 110); mFillRectangle->setTint(255, 0, 0); mFillRectangle->setTransparency(50); // 2d Poly IND_Entity2d *mPoly2d = new IND_Entity2d(); mI->_entity2dManager->add(mPoly2d); mPoly2d->setPrimitive2d(IND_POLY2D); IND_Point mVertPoly2 [] = { {440, 200}, {480, 100}, {450, 10}, {470, 220} }; // Poly points mPoly2d->setPolyPoints(mVertPoly2); mPoly2d->setNumLines(3); // Number of edges - 1 mPoly2d->setTint(255, 128, 255); // ----- Main Loop ----- while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { // ----- Input update ----- mI->_input->update(); // ----- Render ----- mI->_render->clearViewPort (0, 0, 0); mI->_render->beginScene(); // Direct bliting of primitives for (int i = 0; i < 400; i += 5) { mI->_render->blitLine(70, 150, i * 2, 500, i, 255 -i, 255, 255); mI->_render->blitRegularPoly(600, 600, i, 70, 0, 255 - i, i, i*4, 255); } mI->_entity2dManager->renderEntities2d(); mI->_render->endScene(); } // ----- Free ----- mI->end(); return 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; }
/* ================== 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; // ----- Animations loading ----- // Sun animation IND_Animation *mAnimationSun = new IND_Animation(); if (!mI->_animationManager->addToSurface(mAnimationSun, "../../resources/animations/sun.xml", IND_OPAQUE, IND_32)) return 0; // ----- Set the surface and animations into 2d entities ----- // Sun IND_Entity2d *mSun = new IND_Entity2d(); mI->_entity2dManager->add(mSun); // Entity adding mSun->setAnimation(mAnimationSun); // Set the animation into the entity // ----- Changing the attributes of the 2d entities ----- mSun->toggleWrap(1); mSun->setRegion(0, 0, 800, 600); // ----- Main Loop ----- float mDisp = 0.0f; float mSpeed = 0.5f; float mDelta; while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { // ----- Input update ---- mI->_input->update(); // ----- Updating entities attributes ----- mDelta = mI->_render->getFrameTime() / 1000.0f; mDisp += mSpeed * mDelta; mSun->setWrapDisplacement(mDisp, mDisp); // ----- Render ----- mI->_render->beginScene(); mI->_entity2dManager->renderEntities2d(); mI->_render->endScene(); } // ----- Free ----- mI->end(); return 0; }
/* ================== Main ================== */ int IndieLib() { // ----- IndieLib intialization ----- CIndieLib *mI = CIndieLib::Instance(); if (!mI->Init ()) return 0; // ----- Surface loading ----- // 3d Dino loading IND_3dMesh mMeshDino; if (!mI->MeshManager->Add (&mMeshDino, "..\\resources\\trex dx\\dino videogame.x", "..\\resources\\trex dx")) return 0; // Font IND_Font mFontSmall; if (!mI->FontManager->Add (&mFontSmall, "..\\resources\\font_small.png", "..\\resources\\font_small.xml", IND_ALPHA, IND_32)) return 0; // ----- Font creation ----- IND_Entity2d mTextSmallWhite; 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 mesh into 3d entity ----- // Creating 3d entity IND_Entity3d mDino; mI->Entity3dManager->Add (&mDino); // Entity adding mDino.Set3dMesh (&mMeshDino); // Set the 3d mesh into the entity // ----- Cameras ------ IND_Camera2d mCamera2d (mI->Window->GetWidth () / 2, mI->Window->GetHeight() / 2); IND_Camera3d mCamera3d (0.0f, 0.0f, -2.0f); mCamera3d.SetAspect ((float) mI->Window->GetWidth () / mI->Window->GetHeight()); // ----- Light ----- IND_Light mLight0; mI->LightManager->Add (&mLight0, IND_AMBIENT_LIGHT); mLight0.SetColor (1.0f, 1.0f, 1.0f, 1.0f); // Light 1 (Direction light) IND_Light mLight1; mI->LightManager->Add (&mLight1, IND_DIRECTIONAL_LIGHT); mLight1.SetColor (1.0f, 1.0f, 1.0f, 1.0f); mLight1.SetDirection (0.0f, -0.3f, 0.5f); mLight1.SetRange (1000.0f); // Light 2 (Point light) IND_Light mLight2; mI->LightManager->Add (&mLight2, IND_POINT_LIGHT); mLight2.SetPosition (3, 3, 3); mLight2.SetColor (0.4f, 1.0f, 0.4f, 1.0f); mLight2.SetRange (200); mLight2.SetAttenuation (0.5f); // Light 3 (Spot light) IND_Light mLight3; mI->LightManager->Add (&mLight3, IND_SPOT_LIGHT); mLight3.SetPosition (5, 5, 5); mLight3.SetColor (1.0f, 1.0f, 1.0f, 1.0f); mLight3.SetDirection (0.0f, -0.3f, 0.5f); mLight3.SetRange (1000); mLight3.SetAttenuation (0.2f); mLight3.SetFalloff (1.0f); mLight3.SetPhi (8.0f); mLight3.SetTheta (7); // ----- Main Loop ----- mI->LightManager->Disable(&mLight2); mI->LightManager->Disable(&mLight3); float mAngle = 0; char mText [2048]; mText [0] = 0; int mSpeed = 25; float mDelta; while (!mI->Input->OnKeyPress (IND_ESCAPE) && !mI->Input->Quit()) { // ----- Input update ---- mI->Input->Update (); // ----- Text ----- strcpy (mText, "Press 1, 2 or 3 in order to toggle between different lights\n"); mTextSmallWhite.SetText (mText); // ----- Input ----- mDelta = mI->Render->GetFrameTime() / 1000.0f; // Activate only light 1 if (mI->Input->IsKeyPressed (IND_1)) { mI->LightManager->Disable(&mLight2); mI->LightManager->Disable(&mLight3); mI->LightManager->Enable(&mLight1); } // Activate only light 2 if (mI->Input->IsKeyPressed (IND_2)) { mI->LightManager->Disable(&mLight1); mI->LightManager->Disable(&mLight3); mI->LightManager->Enable(&mLight2); } // Activate only light 3 if (mI->Input->IsKeyPressed (IND_3)) { mI->LightManager->Disable(&mLight1); mI->LightManager->Disable(&mLight2); mI->LightManager->Enable(&mLight3); } // ----- Updating entities attributes ----- mAngle += mDelta * mSpeed; mDino.SetAngleXYZ (0, mAngle, 0); // ----- Render ----- mI->Render->ClearViewPort (60, 60, 60); mI->Render->BeginScene (); mI->Render->SetViewPort3d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight()); mI->Render->SetCamera3d (&mCamera3d); mI->LightManager->Update (); mI->Entity3dManager->RenderEntities3d (); mI->Render->SetViewPort2d (0, 0, mI->Window->GetWidth (), mI->Window->GetHeight ()); mI->Render->SetCamera2d (&mCamera2d); 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; }
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 ----- }
/* ================== 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; }
/* ================== 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/blue_background.jpg", IND_OPAQUE, IND_32)) return 0; // ----- Animations loading ----- // Characters animations, we apply a color key of (0, 48, 152) IND_Animation *mAnimationCharacter1 = new IND_Animation(); if (!mI->_animationManager->addToSurface(mAnimationCharacter1, "../../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 = new IND_Animation(); if (!mI->_animationManager->addToSurface(mAnimationCharacter2, "../../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 = new IND_Animation(); if (!mI->_animationManager->addToSurface(mAnimationDust, "../../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 = new IND_Entity2d(); mI->_entity2dManager->add(mBack); // Entity adding mBack->setSurface(mSurfaceBack); // Set the surface into the entity // Character 1 IND_Entity2d *mPlayer1 = new IND_Entity2d(); mI->_entity2dManager->add(mPlayer1); // Entity adding mPlayer1->setAnimation(mAnimationCharacter1); // Set the animation into the entity // Character 2 IND_Entity2d *mPlayer2 = new IND_Entity2d(); mI->_entity2dManager->add(mPlayer2); // Entity adding mPlayer2->setAnimation(mAnimationCharacter2); // Set the animation into the entity // Dust explosion IND_Entity2d *mDust = new IND_Entity2d(); 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 // ----- Main Loop ----- while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { mI->_input->update(); mI->_render->beginScene(); mI->_entity2dManager->renderEntities2d(); mI->_render->endScene(); } // ----- Free ----- mI->end(); return 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 cursor IND_Surface *mSurfaceCursor = new IND_Surface(); if (!mI->_surfaceManager->add(mSurfaceCursor, "../../resources/cursor.png", IND_ALPHA, IND_32)) return 0; // Loading tile for the terrain IND_Surface *mSurfaceTerrain = new IND_Surface(); if (!mI->_surfaceManager->add(mSurfaceTerrain, "../../resources/tiled_terrain.png", IND_OPAQUE, IND_32)) return 0; // Loading alien hole 1 IND_Surface *mSurfaceHole1 = new IND_Surface(); if (!mI->_surfaceManager->add(mSurfaceHole1, "../../resources/hole1.png", IND_ALPHA, IND_32)) return 0; // Loading alien hole 2 IND_Surface *mSurfaceHole2 = new IND_Surface(); if (!mI->_surfaceManager->add(mSurfaceHole2, "../../resources/hole2.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; // ----- Animation loading ----- IND_Animation *mAnimationUfo = new IND_Animation(); if (!mI->_animationManager->addToSurface(mAnimationUfo, "../../resources/animations/ufo.xml", IND_ALPHA, IND_32)) return 0; // ----- Cursor creation ----- IND_Entity2d *mCursor = new IND_Entity2d(); mI->_entity2dManager->add(1, mCursor); // Entity adding in layer 1 (gui) mCursor->setSurface(mSurfaceCursor); // ----- Terrain creation ----- CTerrain *mTerrain = new CTerrain(X_TILES, Y_TILES, NUM_HOLES, mSurfaceTerrain, mSurfaceHole1, mSurfaceHole2); // ----- Font creation ----- IND_Entity2d *mTextSmallWhite = new IND_Entity2d(); mI->_entity2dManager->add(1, mTextSmallWhite); // Entity adding in layer 1 (gui) mTextSmallWhite->setFont(mFontSmall); // Set the font into the entity mTextSmallWhite->setLineSpacing(18); mTextSmallWhite->setCharSpacing(-8); mTextSmallWhite->setPosition(15, 15, 4); mTextSmallWhite->setAlign(IND_LEFT); // ----- Ufo creation ----- CUfo *mUfos = new CUfo[X_TILES * Y_TILES * 1024]; int cont = 0; for (int i = 0; i < X_TILES * 512; i += 50) { for (int j = 0; j < Y_TILES * 512; j += 50, ++cont) { mUfos [cont].Init ((float) i, (float) j, mAnimationUfo); } } // ----- Camera ------ // Camera used for moving along the terrain IND_Camera2d *mCameraTerrain = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 2); // Camera used for showing the menu options, fps, etc (this camera dosen't change) IND_Camera2d *mCameraGui = new IND_Camera2d(mI->_window->getWidth () / 2, mI->_window->getHeight() / 2); // ----- Main Loop ----- float mZoom = 1.0f; float mAngle = 0; char mFpsString [512]; char mFpsValueStr [15]; char mRenderedObjectsStr [15]; char mDiscardedObjectsStr [15]; mFpsString [0] = 0; int mSpeedRotation = 50; float mDelta; while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { // ----- Input update ---- mI->_input->update(); // ----- Texts ----- strcpy (mFpsString, "Fps: "); mI->_render->getFpsString(mFpsValueStr); strcat (mFpsString, mFpsValueStr); strcat (mFpsString, "\n"); strcat (mFpsString, "Rendered: "); mI->_render->getNumrenderedObjectsString(mRenderedObjectsStr); strcat (mFpsString, mRenderedObjectsStr); strcat (mFpsString, "\n"); strcat (mFpsString, "Discarded: "); mI->_render->getNumDiscardedObjectsString(mDiscardedObjectsStr); strcat (mFpsString, mDiscardedObjectsStr); mTextSmallWhite->setText(mFpsString); // ----- Input ---- // Delta mDelta = mI->_render->getFrameTime() / 1000.0f; // Cursor position mCursor->setPosition((float) mI->_input->getMouseX(), (float) mI->_input->getMouseY(), 3); // Change resolution to 640, 480 when pressing 1 if (mI->_input->onKeyPress(IND_1)) { //if (!mI->_render->reset("Alien BenchMark", 640, 480, 32, 0, 1)) return 0; //FIXME: this is broken - figure out how to use IND_Windowproperties correctly mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); } // Change resolution to 800, 600 when pressing 2 if (mI->_input->onKeyPress(IND_2)) { //if (!mI->_render->reset("Alien BenchMark", 800, 600, 32, 0, 1)) return 0; //FIXME: this is broken - figure out how to use IND_Windowproperties correctly mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); } // Change resolution to 1024, 768 when pressing 3 if (mI->_input->onKeyPress(IND_3)) { //if (!mI->_render->reset("Alien BenchMark", 1024, 768, 32, 0, 1)) return 0; //FIXME: this is broken - figure out how to use IND_Windowproperties correctly mCameraGui->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); mCameraTerrain->setPosition(mI->_window->getWidth() / 2, mI->_window->getHeight() / 2); } // Toogle full screen when pressing "space" if (mI->_input->onKeyPress(IND_SPACE)) mI->_render->toggleFullScreen(); // Camera Zoom in / out if (mI->_input->isMouseScroll()) { mZoom += mI->_input->getMouseScrollY() * K_ZOOMSPEED; } // Camera angle if (mI->_input->isMouseButtonPressed(IND_MBUTTON_LEFT)) mAngle += mSpeedRotation * mDelta; if (mI->_input->isMouseButtonPressed(IND_MBUTTON_RIGHT)) mAngle -= mSpeedRotation * mDelta; // ----- Updating entities attributes ----- // Zooming and rotating the camera if (mZoom < 0.1f) mZoom = 0.1f; mCameraTerrain->setAngle(mAngle); mCameraTerrain->setZoom(mZoom); // Camera translation if (mI->_input->getMouseX() > mI->_window->getWidth() - MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX() + (int) CAMERA_DISPLACE, mCameraTerrain->getPosY()); if (mI->_input->getMouseX() < MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX() - (int) CAMERA_DISPLACE, mCameraTerrain->getPosY()); if (mI->_input->getMouseY() > mI->_window->getHeight()- MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX(), mCameraTerrain->getPosY() + (int) CAMERA_DISPLACE); if (mI->_input->getMouseY() < MOVE_TERRAIN_BY_MOUSE_AREA) mCameraTerrain->setPosition(mCameraTerrain->getPosX(), mCameraTerrain->getPosY() - (int) CAMERA_DISPLACE); // ----- Render ----- mI->_render->beginScene(); mI->_render->clearViewPort(0, 0, 0); // --- Layer 0 (terrain) --- mI->_render->resetNumDiscardedObjects(); mI->_render->resetNumrenderedObject(); mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight()); mI->_render->setCamera2d(mCameraTerrain); mI->_entity2dManager->renderEntities2d(0); // --- Layer 1 (gui) --- mI->_render->setViewPort2d(0, 0, mI->_window->getWidth(), mI->_window->getHeight()); mI->_render->setCamera2d(mCameraGui); mI->_render->blitFillRectangle(10, 10, 240, 80, 128, 128, 128, 128); mI->_render->blitRectangle(10, 10, 240, 80, 255, 255, 255, 128); mI->_entity2dManager->renderEntities2d(1); mI->_render->endScene(); } // ----- Free ----- mI->end(); delete [] mUfos; return 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; }
/* ================== Main ================== */ int IndieLib () { // ----- IndieLib intialization ----- CIndieLib *mI = CIndieLib::instance(); if (!mI->init()) return 0; // ----- Surface loading ----- // Loading rabbit IND_Surface *mSurfaceRabbit = new IND_Surface(); if (!mI->_surfaceManager->add(mSurfaceRabbit, "../../resources/rabbit.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; // ----- Create rabbits ----- CRabbit *mRabbits = new CRabbit[MAX_OBJECTS]; int i; for (i = 0; i < MAX_OBJECTS; i++) mRabbits[i].init(mSurfaceRabbit, i); // ----- 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, i); mTextSmallWhite->setAlign(IND_LEFT); // ----- Main Loop ----- char mFpsString[128]; char mFpsValueString[15]; mFpsString [0] = 0; while (!mI->_input->onKeyPress(IND_ESCAPE) && !mI->_input->quit()) { // ----- Input update ---- mI->_input->update(); // ----- Fps ----- strcpy(mFpsString, "Fps: "); mI->_render->getFpsString(mFpsValueString); strcat(mFpsString, mFpsValueString); strcat(mFpsString, "\nPress space to toggle full screen"); mTextSmallWhite->setText(mFpsString); // ----- Game logic ---- // Toogle full screen when pressing "space" if (mI->_input->onKeyPress(IND_SPACE)) mI->_render->toggleFullScreen(); // Update rabbits position for (int i = 0; i < MAX_OBJECTS; i++) mRabbits[i].update(); // ----- Render ----- mI->_render->beginScene(); mI->_render->clearViewPort(60, 60, 60); mI->_entity2dManager->renderEntities2d(); mI->_render->endScene(); } // ----- Free ----- mI->end(); delete [] mRabbits; return 0; }