void RebelleUpgradeScreenGUI::unloadPlayerStats() { Game* game = Game::getSingleton(); GameGraphics *graphics = game->getGraphics(); TextureManager *guiTextureManager = graphics->getGUITextureManager(); unsigned int speedIconTID = guiTextureManager->loadTexture(SPEED_ICON_PATH); unsigned int attackIconTID = guiTextureManager->loadTexture(ATTACK_ICON_PATH); unsigned int defenseIconTID = guiTextureManager->loadTexture(DEFENSE_ICON_PATH); list<OverlayImage*>* overlayImageList = this->getOverlayImageList(); list<OverlayImage*>::iterator it = overlayImageList->begin(); while (it != overlayImageList->end()) { OverlayImage* image = *it; it++; if (image->imageID == speedIconTID || image->imageID == attackIconTID || image->imageID == defenseIconTID) { overlayImageList->remove(image); delete image; } } }
/* This method loads all the sprite types found in the provided sprite type list file into the game state manager, including their images. */ bool PoseurSpriteTypesImporter::loadSpriteTypes(Game *game, wstring spriteTypesListFileName) { int slashIndex = spriteTypesListFileName.rfind('/'); dir = string(spriteTypesListFileName.begin(), spriteTypesListFileName.end()).substr(0, slashIndex+1); const char *spriteTypesListFile = newCharArrayFromWstring(spriteTypesListFileName); bool success = loadSpriteTypesListInfo(spriteTypesListFile); if (!success) return false; for (unsigned int i = 0; i < spriteTypes.size(); i++) { success = loadSpriteTypeInfo(spriteTypes[i]); if (!success) return false; } TextureManager *tm = game->getGraphics()->getWorldTextureManager(); WStringTable *wStringTable = tm->getWStringTable(); // NOW LET'S USE ALL THE INFO WE'VE LOADED // LET'S START BY LOADING THE TEXTURES INTO THE WORLD TEXTURE MANAGER for (unsigned int i = 0; i < spriteTypes.size(); i++) { string spriteType = spriteTypes[i]; unsigned int offset = wStringTable->getNumWStringsInTable(); map<int, string> images = spriteTypesImages[spriteType]; for (int j = 0; j < images.size(); j++) { string imageToLoad = images[j]; wstring wImageToLoad(imageToLoad.begin(), imageToLoad.end()); tm->loadTexture(wImageToLoad); } AnimatedSpriteType *ast = new AnimatedSpriteType(); unsigned int spriteTypeId = game->getGSM()->getSpriteManager()->addSpriteType(ast); ast->setSpriteTypeID(spriteTypeId); Dimensions dim = spriteTypesDimensions[spriteType]; ast->setTextureSize(dim.width, dim.height); map<string, vector<Pose>> animations = spriteTypesAnimationsLists[spriteType]; map<string, vector<Pose>>::iterator it = animations.begin(); while (it != animations.end()) { string key = it->first; wstring wKey(key.begin(), key.end()); ast->addAnimationSequence(wKey); vector<Pose> poseList = it->second; vector<Pose>::iterator poseIt = poseList.begin(); while (poseIt != poseList.end()) { Pose pose = *poseIt; ast->addAnimationFrame(wKey, pose.imageId + offset - 1, pose.duration); poseIt++; } it++; } } return true; }
void TMXMapImporter::buildImageLayer(Game *game, ImageLayerInfo *ili, int idOffset) { TiledLayer *imageLayerToAdd = new TiledLayer( 1, 1, ili->imagewidth, ili->imageheight, 0, ili->collidable, largestLayerWidth, largestLayerHeight); game->getGSM()->getWorld()->addLayer(imageLayerToAdd); TextureManager *textureManager = game->getGraphics()->getWorldTextureManager(); Tile *imageTile = new Tile(); imageTile->collidable = ili->collidable; wstring imageSourceW(ili->imageSource.begin(), ili->imageSource.end()); imageTile->textureID = textureManager->loadTexture(dir + imageSourceW) + idOffset - 1; imageLayerToAdd->addTile(imageTile); }
ImageView::ImageView(const char *name, float w, float h) : View() { figure = NULL; clickable = false; ApplicationController *ctl = ApplicationController::getInstance(); TextureManager *texMgr = ctl->texMgr; Texture *tex = NULL; SharedTexture *stex = NULL; if ((stex = texMgr->findSharedTexture(name))) { if (w > 0 && h > 0) { this->setFigure(stex->makePlateWithSize(name, w, h)); } else if (w > 0) { this->setFigure(stex->makeFixPlate(name, w)); } else { this->setFigure(stex->makePlate(name)); } this->setTexture(stex); } else if ((tex = texMgr->loadTexture(name))) { this->setFigure(tex->makePlate()); this->setTexture(tex); } }
bool TMXMapImporter::buildWorldFromInfo(Game *game) { TextureManager *worldTextureManager = game->getGraphics()->getWorldTextureManager(); if (mapType == MapType::ORTHOGONAL_MAP) { World *world = game->getGSM()->getWorld(); int largestLayerWidth = 0; int largestLayerHeight = 0; // LET'S FIRST FIGURE OUT THE WORLD WIDTH AND HEIGHT // FIRST THE IMAGE LAYERS map<string, ImageLayerInfo>::const_iterator iliIt = imageLayerInfos.begin(); while (iliIt != imageLayerInfos.end()) { string key = iliIt->first; ImageLayerInfo ili = imageLayerInfos[key]; if (ili.imagewidth > largestLayerWidth) largestLayerWidth = ili.imagewidth; if (ili.imageheight > largestLayerHeight) largestLayerHeight = ili.imageheight; iliIt++; } // AND THE TILED LAYERS map<string, TiledLayerInfo>::const_iterator tliIt = tiledLayerInfos.begin(); while (tliIt != tiledLayerInfos.end()) { string key = tliIt->first; TiledLayerInfo tli = tiledLayerInfos[key]; int layerWidth = tli.width * tli.tileSetInfo->tilewidth; if (layerWidth > largestLayerWidth) largestLayerWidth = layerWidth; int layerHeight = tli.height * tli.tileSetInfo->tileheight; if (layerHeight > largestLayerHeight) largestLayerHeight = layerHeight; tliIt++; } unsigned int idOffset = worldTextureManager->getWStringTable()->getNumWStringsInTable(); // FIRST LOAD ALL THE TILE SETS map<string, TileSetInfo>::const_iterator tsiIt = tileSetInfos.begin(); while (tsiIt != tileSetInfos.end()) { string key = tsiIt->first; TileSetInfo tsi = tileSetInfos[key]; wstring sourceImageW(tsi.sourceImage.begin(), tsi.sourceImage.end()); bool success = worldTextureManager->loadTileSetFromTexture(game, dir, sourceImageW, tsi.tilewidth, tsi.tileheight); if (!success) return false; tsiIt++; } // NOW LOAD THE IMAGE LAYERS, IF THERE ARE ANY iliIt = imageLayerInfos.begin(); while (iliIt != imageLayerInfos.end()) { string key = iliIt->first; ImageLayerInfo ili = imageLayerInfos[key]; TiledLayer *imageLayerToAdd = new TiledLayer( 1, 1, ili.imagewidth, ili.imageheight, 0, ili.collidable, largestLayerWidth, largestLayerHeight); world->addLayer(imageLayerToAdd); Tile *imageTile = new Tile(); imageTile->collidable = ili.collidable; wstring imageSourceW(ili.imageSource.begin(), ili.imageSource.end()); imageTile->textureID = worldTextureManager->loadTexture(dir + imageSourceW); imageLayerToAdd->addTile(imageTile); iliIt++; } // AND NOW LOAD THE TILED LAYERS, WHICH REFERENCE THE TILE SETS tliIt = tiledLayerInfos.begin(); while (tliIt != tiledLayerInfos.end()) { // @TODO WE'LL NEED TO CUSTOMIZE THIS bool collidableLayer = false; string key = tliIt->first; TiledLayerInfo tli = tiledLayerInfos[key]; TiledLayer *tiledLayerToAdd = new TiledLayer( tli.width, tli.height, tli.tileSetInfo->tilewidth, tli.tileSetInfo->tileheight, 0, tli.collidable, largestLayerWidth, largestLayerHeight); world->addLayer(tiledLayerToAdd); // WE HAVE TO ADD ALL THE TILES int row = 0; int col = 0; int uncollidableIndex = tli.tileSetInfo->firstgid; for (unsigned int i = 0; i < tli.gids.size(); i++) { Tile *tileToAdd = new Tile(); tileToAdd->textureID = tli.gids[i] + idOffset - 1; if (tli.gids[i] == uncollidableIndex) tileToAdd->collidable = false; else { tileToAdd->collidable = tli.collidable; } tiledLayerToAdd->addTile(tileToAdd); } tliIt++; } // AND MAKE THE WORLD DIMENSIONS THE // SIZE OF THE LARGEST LAYER world->setWorldWidth(largestLayerWidth); world->setWorldHeight(largestLayerHeight); } return true; }
void RebelleUpgradeScreenGUI::loadPlayerStats() { Game* game = Game::getSingleton(); GameStateManager* gsm = game->getGSM(); SpriteManager* spriteMgr = gsm->getSpriteManager(); GameGraphics *graphics = game->getGraphics(); TextureManager *guiTextureManager = graphics->getGUITextureManager(); PlayerSprite *player = spriteMgr->getPlayer(); int speed = player->getSpeed(); int attack = player->getAttack(); int defense = player->getDefense(); unsigned int speedIconTID = guiTextureManager->loadTexture(SPEED_ICON_PATH); unsigned int attackIconTID = guiTextureManager->loadTexture(ATTACK_ICON_PATH); unsigned int defenseIconTID = guiTextureManager->loadTexture(DEFENSE_ICON_PATH); //// - first speed icon will be rendered at 20px right to upgrade button int speedIconY = statListY + statLineHeight + ydistBetweenStats; int nextSpeedIconX = statListX + statTitleWidth + statTitleWidth + upgradeButtonWidth + 20; for (int i = 0; i < speed; i++) { OverlayImage *speedIcon = new OverlayImage(); speedIcon->alpha = 255; speedIcon->width = STAT_ICON_WIDTH; speedIcon->height = STAT_ICON_HEIGHT; speedIcon->x = nextSpeedIconX; speedIcon->y = speedIconY; speedIcon->z = 0; speedIcon->imageID = speedIconTID; this->addOverlayImage(speedIcon); nextSpeedIconX += STAT_ICON_WIDTH + 3; } //// attack icons should be next to Attack stat title and the button. int attackIconY = speedIconY + statLineHeight + ydistBetweenStats; int nextAttackIconX = statListX + statTitleWidth + statTitleWidth + upgradeButtonWidth + 20; for (int i = 0; i < attack; i++) { OverlayImage *attackIcon = new OverlayImage(); attackIcon->alpha = 255; attackIcon->width = STAT_ICON_WIDTH; attackIcon->height = STAT_ICON_HEIGHT; attackIcon->x = nextAttackIconX; attackIcon->y = attackIconY; attackIcon->z = 0; attackIcon->imageID = attackIconTID; this->addOverlayImage(attackIcon); nextAttackIconX += STAT_ICON_WIDTH + 3; } //// defense icons int defenseIconY = attackIconY + statLineHeight + ydistBetweenStats; int nextDefenseIconX = statListX + statTitleWidth + statTitleWidth + upgradeButtonWidth + 20; for (int i = 0; i < attack; i++) { OverlayImage *defenseIcon = new OverlayImage(); defenseIcon->alpha = 255; defenseIcon->width = STAT_ICON_WIDTH; defenseIcon->height = STAT_ICON_HEIGHT; defenseIcon->x = nextDefenseIconX; defenseIcon->y = defenseIconY; defenseIcon->z = 0; defenseIcon->imageID = defenseIconTID; this->addOverlayImage(defenseIcon); nextDefenseIconX += STAT_ICON_WIDTH + 3; } }
int main() { if (!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); return -1; } glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //int w = 1024; int w = 768; int h = 768; window = glfwCreateWindow(w, h, "Cyborg-Engine", NULL, NULL); if (window == NULL){ fprintf(stderr, "Failed to open GLFW window."); glfwTerminate(); return -1; } glfwMakeContextCurrent(window); glfwSetFramebufferSizeCallback(window, Renderer::FramebufferSizeCallback); glfwSetKeyCallback(window, Renderer::key_callback); Renderer::FramebufferSizeCallback(window, w, h); glewExperimental = true; // Needed for core profile if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); return -1; } glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE); Renderer::initRender(window); //load resources: TextureManager* TM = TextureManager::getInstance(); TM->loadTexture("testi", "./textures/polygon.png"); TM->loadTexture("part", "./textures/particle2.png"); TM->loadTexture("sheet","./textures/spriteSheetTest.png"); float a = 0; float b = 0; // For rotation float spriteTimer = 0; int spriteNumber = 0; PointSprite ps(0, 0, "part"); //sprite stuff Sprite aa; aa.setUp(6,5); glm::vec2 rain[50]; for (int i = 0; i < 50; i++) { rain[i] = glm::vec2((float)(rand() % 2000) / 1000 - 1.0, (float)(rand() % 2000) / 1000 - 1.2); } Polygon p; glm::vec2 points[] { glm::vec2(0.0, 0.21), glm::vec2(0.05, 0.05), glm::vec2(0.4, 0.0), glm::vec2(0.05, -0.05), glm::vec2(0.0, -0.21), glm::vec2(-0.05, -0.05), glm::vec2(-0.4, 0.0), glm::vec2(-0.05, 0.05), }; p.setPoints(points, 8); p.setOrigin(-0.5, 0.0); Circle c; c.setPrecision(8); bool isEnterPressed = false; int scene = 0; //INITIALIZATION FOR NP_PHYSICS STUFF -------------------------------------------------------------------- START // Creating physics world NP_World world; // Creating objects NP_Object testObj, testObj2, testObj3, testObj4, testObj5, testObj6; // Creating bodies to the world NP_Body testBody(world, 2.f), testBody2(world, 1.f), testBody3(world, 1.f), testBody4(world, 0.5f), testBody5(world, 0.5f), testBody6(world, 100.f); //testBody3.m_mass = 10.f; // Binding objects to bodies testObj.bindBody(&testBody); testObj2.bindBody(&testBody2); testObj3.bindBody(&testBody3); testObj4.bindBody(&testBody4); testObj5.bindBody(&testBody5); testObj6.bindBody(&testBody6); testBody.addBoxCollider(0.5f); testBody2.addBoxCollider(0.5f); testBody3.addBoxCollider(0.5f); testBody4.addBoxCollider(.25f); testBody5.addBoxCollider(.25f); testBody6.addBoxCollider(0.5f); Polygon poly1, poly2, poly3, poly4, poly5, poly6; glm::vec2 pointsp[] = { // Box collider size glm::vec2(-0.25, 0.25), glm::vec2(-0.25, -0.25), glm::vec2(0.25, -0.25), glm::vec2(0.25, 0.25) }; glm::vec2 pointsp123[] = { // Box collider size glm::vec2(-0.125, 0.125), glm::vec2(-0.125, -0.125), glm::vec2(0.125, -0.125), glm::vec2(0.125, 0.125) }; poly1.setPoints(pointsp, 4); poly2.setPoints(pointsp, 4); poly3.setPoints(pointsp, 4); poly4.setPoints(pointsp123, 4); poly5.setPoints(pointsp123, 4); poly6.setPoints(pointsp, 4); testObj.bindPolygon(&poly1); testObj2.bindPolygon(&poly2); testObj3.bindPolygon(&poly3); testObj4.bindPolygon(&poly4); testObj5.bindPolygon(&poly5); testObj6.bindPolygon(&poly6); // Adding objects to the wold world.addObject(&testObj); world.addObject(&testObj2); world.addObject(&testObj3); // world.addObject(&testObj4); // world.addObject(&testObj5); // world.addObject(&testObj6); testObj3.getBody()->setPos(glm::vec2(-1.f, 0.4f)); testObj2.getBody()->setPos(glm::vec2(0.0f, 0.75f)); testObj.getBody()->setPos(glm::vec2(1.0f, 0.f)); testObj4.getBody()->setPos(glm::vec2(-0.35f, 1.f)); testObj5.getBody()->setPos(glm::vec2(0.35f, 1.f)); testObj6.getBody()->setPos(glm::vec2(0.0f, -0.25f)); testObj.getBody()->setVelocity(glm::vec2(-25.0f, 1.f)); testObj3.getBody()->setVelocity(glm::vec2(5.0f, 1.f)); testObj2.getBody()->setVelocity(glm::vec2(0.f, -5.f)); testObj4.getBody()->setVelocity(glm::vec2(.0f, -3.0f)); testObj5.getBody()->setVelocity(glm::vec2(.0f, -3.0f)); testObj6.getBody()->setVelocity(glm::vec2(0.f, 2.f)); //testObj.getBody()->m_orientation = glm::radians(30.f); //testObj3.getBody()->m_orientation = glm::radians(-45.f); //testObj3.getBody()->m_angularVelocity = 10.0f; //testObj2.getBody()->m_angularVelocity = 2.5f; //testObj.getBody()->m_angularVelocity = -2.f; //testObj4.getBody()->m_angularVelocity = -10.f; //testObj5.getBody()->m_angularVelocity = 10.f; //INITIALIZATION FOR NP_PHYSICS STUFF -------------------------------------------------------------------- END do{ Renderer::do_movement(); if (isEnterPressed == false) { if (glfwGetKey(window, GLFW_KEY_ENTER) == GLFW_PRESS) { isEnterPressed = true; scene = (scene+1) % 2; // SCENEJEN MÄÄRÄ a = 0.0f; if (scene == 0) { world.removeObjects(); world.addObject(&testObj); world.addObject(&testObj2); world.addObject(&testObj3); } else if (scene == 1) { world.removeObjects(); world.addObject(&testObj4); world.addObject(&testObj5); world.addObject(&testObj6); } } } else { if (glfwGetKey(window, GLFW_KEY_ENTER) != GLFW_PRESS) { isEnterPressed = false; } } a += 0.02; //clear screen Renderer::initDraw(); //--------------------draw-------------------- if (scene == 0) { Renderer::setColor(1, 1, 1, 0.5); Renderer::drawPolygon(&poly1, testObj.getBody()->m_collider.position.x, testObj.getBody()->m_collider.position.y); Renderer::drawPolygon(&poly2, testObj2.getBody()->m_collider.position.x, testObj2.getBody()->m_collider.position.y); Renderer::drawPolygon(&poly3, testObj3.getBody()->m_collider.position.x, testObj3.getBody()->m_collider.position.y); /* Renderer::drawCircle(testObj.getBody()->m_collider.corner[0].x, testObj.getBody()->m_collider.corner[0].y, 0.01f); Renderer::drawCircle(testObj.getBody()->m_collider.corner[1].x, testObj.getBody()->m_collider.corner[1].y, 0.01f); Renderer::drawCircle(testObj.getBody()->m_collider.corner[2].x, testObj.getBody()->m_collider.corner[2].y, 0.01f); Renderer::drawCircle(testObj.getBody()->m_collider.corner[3].x, testObj.getBody()->m_collider.corner[3].y, 0.01f); Renderer::drawCircle(testObj3.getBody()->m_collider.corner[0].x, testObj3.getBody()->m_collider.corner[0].y, 0.01f); Renderer::drawCircle(testObj3.getBody()->m_collider.corner[1].x, testObj3.getBody()->m_collider.corner[1].y, 0.01f); Renderer::drawCircle(testObj3.getBody()->m_collider.corner[2].x, testObj3.getBody()->m_collider.corner[2].y, 0.01f); Renderer::drawCircle(testObj3.getBody()->m_collider.corner[3].x, testObj3.getBody()->m_collider.corner[3].y, 0.01f); Renderer::drawCircle(testObj2.getBody()->m_collider.corner[0].x, testObj2.getBody()->m_collider.corner[0].y, 0.01f); Renderer::drawCircle(testObj2.getBody()->m_collider.corner[1].x, testObj2.getBody()->m_collider.corner[1].y, 0.01f); Renderer::drawCircle(testObj2.getBody()->m_collider.corner[2].x, testObj2.getBody()->m_collider.corner[2].y, 0.01f); Renderer::drawCircle(testObj2.getBody()->m_collider.corner[3].x, testObj2.getBody()->m_collider.corner[3].y, 0.01f); */ //std::cout << testObj.getBody()->m_collider.corner[0].x << std::endl; //testObj.getBody()->setOrient(a); world.update(a / 10000); } else if (scene == 1) { Renderer::setColor(1, 0.5, 0.75, 0.5); Renderer::drawPolygon(&poly4, testObj4.getBody()->m_collider.position.x, testObj4.getBody()->m_collider.position.y); Renderer::drawPolygon(&poly5, testObj5.getBody()->m_collider.position.x, testObj5.getBody()->m_collider.position.y); Renderer::drawPolygon(&poly6, testObj6.getBody()->m_collider.position.x, testObj6.getBody()->m_collider.position.y); /* Renderer::drawCircle(testObj4.getBody()->m_collider.corner[0].x, testObj4.getBody()->m_collider.corner[0].y, 0.01f); Renderer::drawCircle(testObj4.getBody()->m_collider.corner[1].x, testObj4.getBody()->m_collider.corner[1].y, 0.01f); Renderer::drawCircle(testObj4.getBody()->m_collider.corner[2].x, testObj4.getBody()->m_collider.corner[2].y, 0.01f); Renderer::drawCircle(testObj4.getBody()->m_collider.corner[3].x, testObj4.getBody()->m_collider.corner[3].y, 0.01f); Renderer::drawCircle(testObj5.getBody()->m_collider.corner[0].x, testObj5.getBody()->m_collider.corner[0].y, 0.01f); Renderer::drawCircle(testObj5.getBody()->m_collider.corner[1].x, testObj5.getBody()->m_collider.corner[1].y, 0.01f); Renderer::drawCircle(testObj5.getBody()->m_collider.corner[2].x, testObj5.getBody()->m_collider.corner[2].y, 0.01f); Renderer::drawCircle(testObj5.getBody()->m_collider.corner[3].x, testObj5.getBody()->m_collider.corner[3].y, 0.01f); */ world.update(a / 5000); } //--------------------end draw-------------------- //swap buffers Renderer::render(); glfwPollEvents(); } while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); Renderer::uninitRender(); glfwTerminate(); return 0; }