void SelectChar::loadBackground() { AObject *background = new MenuBackground(); background->initialize(_texManag.getTexture("back")); _background = background; }
bool initialize() { if (!_context.start(800, 600, "My bomberman!")) return false; glEnable(GL_DEPTH_TEST); if (!_shader.load("./LibBomberman_linux_x64/shaders/basic.fp", GL_FRAGMENT_SHADER) || !_shader.load("./LibBomberman_linux_x64/shaders/basic.vp", GL_VERTEX_SHADER) || !_shader.build()) { std::cout << "error on shader" << std::endl; return false; } glm::mat4 projection; glm::mat4 transformation; projection = glm::perspective(60.0f, 800.0f / 600.0f, 0.1f, 100.0f); transformation = glm::lookAt(glm::vec3(0, 10, -30), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); _shader.bind(); _shader.setUniform("view", transformation); _shader.setUniform("projection", projection); AObject *cube = new Marvin(); if (cube->initialize() == false) return (false); _objects.push_back(cube); return true; }
void RandomMenu::displayY(int nb) { std::stringstream ss; AObject* letter; int i = 0; int x = -30, y = -15; std::string s = std::to_string(nb); char const *nbStr = s.c_str(); _yMap.clear(); while (nbStr[i]) { ss.str(""); ss.clear(); ss << "./images/fonts/"; ss << nbStr[i]; ss << ".tga"; std::cout << "ss : " << ss.str() << std::endl; letter = new Letters(); letter->initialize(ss.str()); letter->translate(glm::vec3(-0.06 * (i + 1) + x * 0.01, 0 + y * 0.01, 0)); _yMap.push_back(letter); i++; } }
void RandomMenu::loadBackground() { AObject *background = new MenuBackground(); background->initialize(_texManag.getTexture("backRM")); _background = background; AObject *letter = new Letters(); letter->initialize("./images/fonts/1.tga"); letter->translate(glm::vec3(-0.06 * (0 + 1) + 16 * 0.01, 0 + 12 * 0.01, 0)); _iaNb.push_back(letter); letter = new Letters(); letter->initialize("./images/fonts/1.tga"); letter->translate(glm::vec3(-0.06 * (0 + 1) + 60 * 0.01, 0 + -15 * 0.01, 0)); _xMap.push_back(letter); letter = new Letters(); letter->initialize("./images/fonts/1.tga"); letter->translate(glm::vec3(-0.06 * (0 + 1) + -30 * 0.01, 0 + -15 * 0.01, 0)); _yMap.push_back(letter); }
bool CubeAnim::makeCube(const int x, const int y, const int z) { AObject *cube = create<Cube>(); std::pair<float, float> pos; cube->setType(BLOCKD); if (cube->initialize() == false) return (false); pos = std::make_pair(x, z); cube->setPos(pos); _objects.push_back(cube); return (true); }
void MelodyObj::NexAnimationObjGenerate(){ if(!animationIndexAlreadyChose){ NextAnmiationInfo(); } //----------------------------------------------------------------------- //Calculate necessary condition and spawn the animation object //----------------------------------------------------------------------- bool spawndingConditionGood = false; if(effectiveMelodyLineToneList.size() > 1){ spawndingConditionGood = BestMatchParameters(targetAnimationIndex); } if(spawndingConditionGood){ memset(&theAniStruct, 0, sizeof(AStruct)); theAniStruct.usingTex = true; theAniStruct.aControl = theControl; theAniStruct.vertex = 4; theAniStruct.theShape = rect_dia; theAniStruct.texInfo = theReader->GetTextureInfo(0, AnimationTexture); aniStructSpawnCondition = RectDiaRadConstraintSpawning(x1, y1, x2, y2, 0, 0, previousAngleInRad, aniFlipped, theAniStruct); //simple entrance time setting theAniStruct.enterTime = (curTimeInMS - previousAnimationEndingTimeInMS)/1000; if(aniStructSpawnCondition){ AObject * aAobject = new AObject(&theAniStruct); theChildren->Insert((AInterface*) aAobject); FreeAll(theAniStruct.aPositionQ); FreeAll(theAniStruct.aSpeedQ); inScreenTraceX.push_back(aAobject->GetAvgX()); inScreenTraceY.push_back(aAobject->GetAvgY()); aniFlipped = !aniFlipped; previousAnimationEndingTimeInMS = curTimeInMS; } } }
bool AObject::dropBomb() { if (_simult > 0) { AObject *bomb; bomb = new Bomb(); if (bomb->initialize() == false) return false; bomb->setPos(getPos()); bomb->setRange(getRange()); getMap()->setBox(bomb->getPos(), Map::BOMB); _bomb.push_back(bomb); setSimult(getSimult() - 1); _time = 0; } return true; }
bool Menu::initialize() { glm::mat4 projection; glm::mat4 transformation; projection = glm::perspective(60.0f, 800.0f / 600.0f, 0.1f, 100.0f); transformation = glm::lookAt(glm::vec3(10, 20, 25), glm::vec3(10, 20, 0), glm::vec3(0, 1, 0)); _shader.bind(); _shader.setUniform("view", transformation); _shader.setUniform("projection", projection); AObject *arrow = new Icon(10.75, 18.75, "./assets/arrow.tga", 1); if (arrow->initialize() == false) return (false); _menu.push_back(arrow); AObject *exit = new Icon(11.75, 18, "./assets/exit.tga", 1); if (exit->initialize() == false) return (false); _menu.push_back(exit); AObject *start = new Icon(11.75, 18.75, "./assets/start.tga", 1); if (start->initialize() == false) return (false); _menu.push_back(start); AObject *map2 = new Icon(11.75, 18, "./assets/map2.tga", 2); if (map2->initialize() == false) return (false); _menu.push_back(map2); AObject *map1 = new Icon(11.75, 18.75, "./assets/map1.tga", 2); if (map1->initialize() == false) return (false); _menu.push_back(map1); AObject *ia = new Icon(11.75, 18, "./assets/ia.tga", 3); if (ia->initialize() == false) return (false); _menu.push_back(ia); AObject *player = new Icon(11.75, 18.75, "./assets/player.tga", 3); if (player->initialize() == false) return (false); _menu.push_back(player); return (true); }
bool load() { std::ifstream file(_filename.c_str(), std::ios::in); std::vector<AObject*> tmp; std::string line; unsigned int size_line; _z = 0; _x = 0; if (!file) { std::cout << "Cannot load map " << _filename << std::endl; return false; } AObject* obj; while (getline(file, line)) { if (_x < line.size()) _x = line.size(); for (unsigned int i = 0; i < line.size(); ++i) { switch (line[i]) { case 'w': { obj = new Cube(glm::vec3(i, 0, _z), "./assets/stone.tga", AObject::WALL); if (!obj->initialize()) { std::cout << "Fail to draw wall" << std::endl; return false; } break; } case 'c': { obj = new Cube(glm::vec3(i, 0, _z), "./assets/box.tga", AObject::BOX); if (!obj->initialize()) { std::cout << "Fail to draw box" << std::endl; return false; } break; } case '.': { obj = NULL; break; } default: { std::cout << "Wrong element" << std::endl; obj = NULL; break; } } tmp.push_back(obj); } _map.push_back(tmp); tmp.clear(); line.clear(); _z++; } return true; }
Map::Map(int row, int col, newin::SceneMgr bbman) { std::pair<int, int> it; /* AObject* tmp = bbman.addModel("plane.obj", "map"); tmp->setPos(newin::Vector3D<GLfloat>(0.1,0.1,0.1));*/ srand (time(NULL)); AObject *tmp; _row = row; _col = col; it.first = 0; it.second = 0; while (it.first != row) { while (it.second != col) { _map[it] = NULL; if (rand()%5 == 0 && it.second != 0 && it.first != 0 && it.second != (col - 1) && it.first != (row - 1) ) _map[it] = new Wall2(&bbman, it.second, it.first); if (rand()%20 == 0 && it.second != 0 && it.first != 0 && it.second != (col - 1) && it.first != (row - 1) ) { delete (_map[it]); _map[it] = new BonusBomb(&bbman, it.second, it.first); } if (rand()%20 == 0 && it.second != 0 && it.first != 0 && it.second != (col - 1) && it.first != (row - 1) ) { delete (_map[it]); _map[it] = new BonusRange(&bbman, it.second, it.first); } if (rand()%15 == 0 && it.second != 0 && it.first != 0 && it.second != (col - 1) && it.first != (row - 1) ) { delete (_map[it]); _map[it] = new BonusMouv(&bbman, it.second, it.first); } if (it.second == col/2 && it.first == row/2) { delete (_map[it]); _map[it] = new BonusLife(&bbman, it.second, it.first); } if (it.second == 0 || it.first == 0) _map[it] = new Wall(&bbman, it.second, it.first); else if (it.first == (row -1) || it.second == (col - 1)) _map[it] = new Wall(&bbman, it.second, it.first); it.second = it.second + 1; tmp = bbman.addModel("grid.obj", "Grille"); tmp->setPos(newin::Vector3D<GLfloat>(it.second, 0.1, it.first)); ((newin::Mesh*)(tmp))->toogleWireframe(); } it.second = 0; it.first = it.first + 1; } it.first = 3; it.second = 7; if (_map[it] != NULL) { delete(_map[it]); _map[it] = NULL; } _map[it] = new Player(&bbman, it.second, it.first, this, false); /* delete (_map[it]); _map[it] = NULL;*/ it.first = 5; it.second = 7; if (_map[it] != NULL) { delete(_map[it]); _map[it] = NULL; } _map[it] = new Player(&bbman, it.second, it.first, this, true); bbman.run(); }
int Graphic::pause(void) { int i = 0; int oldX = _camX; int oldY = _camY; int oldZ = _camZ; int oldO = _orientation; AObject *plan = new Pause(0, 0, 0, 23, 23, 23); AObject *cursor = new Bombe(1.4, 22, -2.8, 0.003, 0.003, 0.003); glm::mat4 transformation; _camX = 0; _camY = 32; _camZ = 1; _orientation = -1; camUpdate(); if (plan->initialize() == false) return (2); if (cursor->initialize() == false) return (2); while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); this->_shader.bind(); plan->draw(this->_shader, this->_clock); cursor->draw(this->_shader, this->_clock); this->_init.flush(); if (this->_input.getKey(SDL_QUIT, true)) return (2); if (this->_input.getKey(SDLK_UP, true)) { i--; cursor->translate(glm::vec3(0, 0, -1.7)); } if (this->_input.getKey(SDLK_DOWN, true)) { i++; cursor->translate(glm::vec3(0, 0, 1.7)); } if (i < 0) { i = 2; cursor->translate(glm::vec3(0, 0, 1.7 * 3)); } if (i > 2) { i = 0; cursor->translate(glm::vec3(0, 0, -1.7 * 3)); } if (this->_input.getKey(SDLK_RETURN, true)) { _camX = oldX; _camY = oldY; _camZ = oldZ; _orientation = oldO; camUpdate(); return (i); } this->_init.updateClock(this->_clock); this->_init.updateInputs(this->_input); } }
int Graphic::menu(void) { int i = 0; AObject *plan = new Plan(0, 0, 0, 23, 23, 23); AObject *cursor = new Bombe(1.4, 22, -3.2, 0.003, 0.003, 0.003); _camX = 0; _camY = 32; _camZ = 1; _orientation = -1; camUpdate(); if (plan->initialize() == false) return (3); if (cursor->initialize() == false) return (3); plan->rotate(glm::vec3(1, 0, 0), 1); while (1) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); this->_shader.bind(); plan->draw(this->_shader, this->_clock); cursor->draw(this->_shader, this->_clock); this->_init.flush(); if (this->_input.getKey(SDL_QUIT, true) || this->_input.getKey(SDLK_ESCAPE, true)) return (3); if (this->_input.getKey(SDLK_UP, true)) { i--; cursor->translate(glm::vec3(0, 0, -1.655)); } if (this->_input.getKey(SDLK_DOWN, true)) { i++; cursor->translate(glm::vec3(0, 0, 1.655)); } if (i < 0) { i = 3; cursor->translate(glm::vec3(0, 0, 1.655 * 4)); } if (i > 3) { i = 0; cursor->translate(glm::vec3(0, 0, -1.655 * 4)); } if (this->_input.getKey(SDLK_RETURN, true)) return (i); this->_init.updateClock(this->_clock); this->_init.updateInputs(this->_input); } }
void SelectChar::loadButtons() { AObject *b = new DisplayButton(); b = new DisplayButton(); b->initialize(_texManag.getTexture("1ia")); b->translate(glm::vec3(0, -0.39, 0)); _buttons["1ia"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("5ia")); b->translate(glm::vec3(0, -0.39, 0)); _buttons["5ia"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("10ia")); b->translate(glm::vec3(0, -0.39, 0)); _buttons["10ia"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("15ia")); b->translate(glm::vec3(0, -0.39, 0)); _buttons["15ia"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("20ia")); b->translate(glm::vec3(0, -0.39, 0)); _buttons["20ia"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("1P")); b->translate(glm::vec3(0.4, -0.39, 0)); _buttons["1P"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("2P")); b->translate(glm::vec3(0.4, -0.39, 0)); _buttons["2P"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map1")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map1"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map2")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map2"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map3")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map3"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map4")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map4"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map5")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map5"] = b; b = new DisplayButton(); b->initialize(_texManag.getTexture("Map6")); b->translate(glm::vec3(-0.42, -0.39, 0)); _buttons["Map6"] = b; }
void Ground::addRessource(e_object type, gdl::Model* model) { float x = this->_position.x; float y = this->_position.y; float z = this->_position.z; AObject* res; switch (type) { case LINEMATE: _ressources.push_back(new Linemate(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.1f, 0.1f, 0.1f)); res->rotate(glm::vec3(0,1,0), 180); break ; case DERAUMERE: _ressources.push_back(new Deraumere(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.02f, 0.02f, 0.02f)); res->rotate(glm::vec3(0,1,0), 180); break ; case SIBUR: _ressources.push_back(new Sibur(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.1f, 0.1f, 0.1f)); res->rotate(glm::vec3(0,1,0), 180); res->translate(glm::vec3(0,0.25f,0)); break ; case MENDIANE: _ressources.push_back(new Mendiane(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.1f, 0.1f, 0.1f)); break ; case PHIRAS: _ressources.push_back(new Phiras(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.02f, 0.02f, 0.02f)); break ; case THYSTANE: _ressources.push_back(new Thystane(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.1f, 0.1f, 0.1f)); break ; case FOODR: _ressources.push_back(new Food(*model)); res = _ressources.back(); res->translate(glm::vec3(x + static_cast<ARessource*>(res)->getPaddingX(), y + 1, z + static_cast<ARessource*>(res)->getPaddingY())); res->scale(glm::vec3(0.1f, 0.1f, 0.1f)); res->rotate(glm::vec3(1,0,0), 180); res->translate(glm::vec3(0,0.25f,0)); break ; default: break ; }; }
void IA::move(gdl::Clock const& clock, int input, std::vector<AObject*>&object) { float move_val; move_val = 1 * static_cast<float>(clock.getElapsed()) * _speed; if (input == 0) { if (_map[round(_x)][round(_y + move_val + 0.4)] != NULL) return ; _y += 1 * static_cast<float>(clock.getElapsed()) * _speed; if (_y >= _height - 2) { _y = _height - 2; return ; } translate(glm::vec3(0, 0, 1) * static_cast<float>(clock.getElapsed()) * _speed); } if (input == 1) { if (_y > 2) if (_map[round(_x)][round(_y - move_val - 0.4)] != NULL) return ; _y -= 1 * static_cast<float>(clock.getElapsed()) * _speed; if (_y < 1) { _y = 1; return ; } translate(glm::vec3(0, 0, -1) * static_cast<float>(clock.getElapsed()) * _speed); } if (input == 2) { if (_map[round(_x + move_val + 0.4)][round(_y)] != NULL) return ; _x += 1 * static_cast<float>(clock.getElapsed()) * _speed; if (_x >= _widht - 2) { _x = _widht - 2; return ; } translate(glm::vec3(1, 0, 0) * static_cast<float>(clock.getElapsed()) * _speed); } if (input == 3) { if (_map[round(_x - move_val - 0.4)][round(_y)] != NULL) return ; _x -= 1 * static_cast<float>(clock.getElapsed()) * _speed; if (_x < 1) { _x = 1; return; } translate(glm::vec3(-1, 0, 0) * static_cast<float>(clock.getElapsed()) * _speed); } if (input == 4 && this->_nbbomb != 0) { AObject *bomb = new Bomb(round(_x), round(_y)); this->_bomb.push_back(bomb); if(bomb->initialize() == false) { std::cerr << "Cannot load the bomb" << std::endl; return ; } object.push_back(bomb); this->_nbbomb = 0; } this->_nbbomb = 1; }