void MapTool:: selectShape(const Geometry::Point<double,3>& pos) { MapManager* mapMan = crusta->getMapManager(); Shape*& curShape = mapMan->getActiveShape(toolId); Shape* oldShape = curShape; ShapePtrs shapes = getShapes(); double threshold = 1.0 / Vrui::getNavigationTransformation().getScaling(); threshold *= mapMan->getSelectDistance(); bool noShapeSelected = true; for (ShapePtrs::iterator it=shapes.begin(); it!=shapes.end(); ++it) { double distance; Shape::ControlId control = (*it)->select(pos, distance); if (control!=Shape::BAD_ID && distance<=threshold) { curShape = *it; threshold = distance; noShapeSelected = false; } } if (noShapeSelected && curShape!=NULL) unselectShape(curShape, curControl); //inform the manager that the active shape has changed if (curShape != oldShape) mapMan->updateActiveShape(toolId); }
MapManager DungeonGenerator::Generate(const DungeonSize& sizeData, const DungeonData& dungeonData) { MapManager manager; for (size_t i = 0; i < sizeData.DungeonHeight(); ++i) { for (size_t j = 0; j < sizeData.DungeonWidth(); ++j) { if (dungeonData.IsThis(ObjTypeOnMap::WALL, i, j)) { auto wall = std::make_shared<Wall>(Wall(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(wall); continue; } if (dungeonData.IsThis(ObjTypeOnMap::FLOOR, i, j)) { auto floor = std::make_shared<Floor>(Floor(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(floor); continue; } if (dungeonData.IsThis(ObjTypeOnMap::PATH, i, j)) { auto path = std::make_shared<Path>(Path(Vector2(j*GeneralConstant::img_size_width, i*GeneralConstant::img_size_height))); manager.Add(path); continue; } } } return manager; }
void RogueGame::initialize(void) { MapManager* mapmgr = MapManager::getInstance(); GraphicsManager* graph = GraphicsManager::getInstance(); FEStatViewer* sampleStatViewer = new FEStatViewer(); FEBattleField* sampleBattleField = new FEBattleField(2, 6, 6, sampleStatViewer); int map[36] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}; sampleBattleField->InitTerrain(map, 6, 6); sampleBattleField->setAI(new SampleFEAI(), 1); sampleBattleField->enter(new FEUnit('K', 4, 0, 6, 1, 6, 4, 100, 0, 8, "Lancelot"), 2, 2); sampleBattleField->enter(new FEUnit('A', 1, 1, 4, 2, 4, 0, 100, 0, 6, "Galehad "), 2, 4); sampleBattleField->enter(new FEUnit('K', 4, 0, 6, 1, 6, 4, 100, 0, 8, "Robin "), 4, 2); sampleBattleField->enter(new FEUnit('A', 1, 1, 4, 2, 4, 0, 100, 0, 6, "William "), 4, 4); //sampleBattleField->getCell(2, 2)->tryToMoveToCell(sampleBattleField->getCell(4, 3), FALSE); Camera* cam = new Camera(sampleBattleField, 0, 0, 0, 0, 6, 6); graph->insert(cam); Camera* cam2 = new Camera(sampleStatViewer, 6, 0, 0, 0, 11, 5); graph->insert(cam2); mapmgr->activateMap(sampleBattleField); mapmgr->registerForInput(sampleBattleField); }
void MapTool:: frame() { if (PROJECTION_FAILED) return; statsMan.start(StatsManager::EDITLINE); //handle motion Geometry::Point<double,3> pos = getPosition(); pos = crusta->mapToUnscaledGlobe(pos); if (pos == prevPosition) return; switch (mode) { case MODE_DRAGGING: { MapManager* mapMan = crusta->getMapManager(); Shape*& curShape = mapMan->getActiveShape(toolId); assert(curShape != NULL); ///\todo implement a way to check validity of curControl that doesn't suck assert(curShape->isValid(curControl)); ///\todo HACK: avoid moving control point if projection has failed Vis2010 float scaleFac = Vrui::getNavigationTransformation().getScaling(); if (scaleFac*Geometry::dist(pos, curControl.handle->pos) > 5.0) return; curShape->moveControlPoint(curControl, pos); break; } case MODE_SELECTING_CONTROL: { Shape*& curShape = crusta->getMapManager()->getActiveShape(toolId); if (curShape == NULL) { curControl = Shape::BAD_ID; mode = MODE_IDLE; } else { selectControl(pos); } break; } case MODE_SELECTING_SHAPE: { selectShape(pos); break; } default: break; } statsMan.stop(StatsManager::EDITLINE); }
void TestGame::initialize(void) { MapManager* map = MapManager::getInstance(); GraphicsManager* graph = GraphicsManager::getInstance(); Map* testMap = new TestMap(); Camera* cam = new Camera(testMap, 0, 0, -5, -5, 10, 10); graph->insert(cam); map->activateMap(testMap); map->registerForInput(testMap); }
MapManager* MapManager::create() { MapManager* manager = new MapManager(); if(manager && manager->init()) { manager->autorelease(); return manager; } CC_SAFE_DELETE(manager); return NULL; }
void GameLayer::explodeEffect(const MatchGrid* match) { MapManager* map = m_logic->currentMap(); if (map == NULL || match == NULL) return; Grid* grid = map->getGrid(match->head); GridNode* node = m_gridNodeArray[grid->row * TOTAL_COl+grid->col]; Effect::instance()->explodeEffect(this, node->getPosition()); grid = map->getGrid(match->tail); node = m_gridNodeArray[grid->row * TOTAL_COl+grid->col]; Effect::instance()->explodeEffect(this, node->getPosition()); }
void GameLayer::linkEffect(const MatchGrid* match) { MapManager* map = m_logic->currentMap(); if (map == NULL || match == NULL) return; int end = match->path.size(); std::vector<CCPoint> posArray; for (int i = 0; i < end; i++) { Grid* grid = map->getGrid(match->path[i]); posArray.push_back(m_gridNodeArray[grid->row * TOTAL_COl+grid->col]->getPosition()); } Effect::instance()->linkEffect(this, posArray, callfunc_selector(GameLayer::linkEffectCallback)); }
MapTool:: ~MapTool() { MapManager* mapMan = crusta->getMapManager(); Shape*& curShape = mapMan->getActiveShape(toolId); if (curShape != NULL) { unselectShape(curShape, curControl); mapMan->updateActiveShape(toolId); } mapMan->unregisterMappingTool(toolId); }
MapManager* MapManager::create() { MapManager *pRet = new MapManager(); if (pRet!=nullptr) { pRet->init(); pRet->autorelease(); return pRet; } else { delete pRet; pRet = NULL; return NULL; } }
MapManager* MapManager::create(cocos2d::CCLayer *pLayer, b2World *pWorld) { MapManager *pMapMgr = new MapManager(); if (pMapMgr && pMapMgr->init(pLayer, pWorld)) { pMapMgr->autorelease(); } else { delete pMapMgr; pMapMgr = NULL; } return pMapMgr; }
void FE::initialize(void) { MapManager* mapmgr = MapManager::getInstance(); GraphicsManager* graph = GraphicsManager::getInstance(); FEStatViewer* sampleStatViewer = new FEStatViewer(); FEBattleField* sampleBattleField = new FEBattleField(2, 6, 6, sampleStatViewer); int map[36] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1 }; sampleBattleField->InitTerrain(map, 6, 6); sampleBattleField->setAI(new SampleFEAI(), 1); StatBlock* standard_knight = new StatBlock(20, 15, 0, 8, 5, 7, 5, 5, 4, Proficiency()); StatBlock* standard_archer = new StatBlock(15, 13, 0, 5, 6, 8, 9, 5, 5, Proficiency()); FEUnit* lancelot = new FEUnit('K', 4, 0, standard_knight, 1, SWORD, 90, 5, "Lancelot"); FEUnit* william = new FEUnit('A', 4, 0, standard_archer, 2, BOW, 80, 5, "William"); FEUnit* galahad = new FEUnit('K', 1, 1, standard_knight, 1, SWORD, 90, 5, "Galahad"); FEUnit* robin = new FEUnit('A', 1, 1, standard_archer, 2, BOW, 80, 5, "Robin"); sampleBattleField->enter(lancelot, 2, 2); sampleBattleField->enter(william, 2, 4); sampleBattleField->enter(galahad, 4, 2); sampleBattleField->enter(robin, 4, 4); //sampleBattleField->enter(new FEUnit('K', 4, 0, 6, 1, 6, 4, 100, 0, 8, "Lancelot"), 2, 2); //sampleBattleField->enter(new FEUnit('A', 1, 1, 4, 2, 4, 0, 100, 0, 6, "Galehad "), 2, 4); //sampleBattleField->enter(new FEUnit('K', 4, 0, 6, 1, 6, 4, 100, 0, 8, "Robin "), 4, 2); //sampleBattleField->enter(new FEUnit('A', 1, 1, 4, 2, 4, 0, 100, 0, 6, "William "), 4, 4); //sampleBattleField->getCell(2, 2)->tryToMoveToCell(sampleBattleField->getCell(4, 3), FALSE); Camera* cam = new Camera(sampleBattleField, 0, 0, 0, 0, 6, 6); graph->insert(cam); Camera* cam2 = new Camera(sampleStatViewer, 6, 0, 0, 0, 12, 8); graph->insert(cam2); mapmgr->activateMap(sampleBattleField); mapmgr->registerForInput(sampleBattleField); }
void GameLayer::updateGridNode() { MapManager* map = m_logic->currentMap(); if (map == NULL) return; const MapManager::GridArray& grids = map->getGrids(); MapManager::GridArray::const_iterator pos = grids.begin(); for (; pos != grids.end(); ++pos) { Grid* grid = pos->second; //int status = grid->status; int index = grid->row * TOTAL_COl + grid->col; m_gridNodeArray[index]->updateGrid(pos->second); } int score = map->getScore(); //CCLog("score: %d", score); m_score->f_ShowNumber(score); int time = map->getTime(); m_time->f_ShowNumber(time); }
void MapTool:: selectControl(const Geometry::Point<double,3>& pos) { MapManager* mapMan = crusta->getMapManager(); Shape*& curShape = mapMan->getActiveShape(toolId); assert(curShape != NULL); curControl = Shape::BAD_ID; double distance; Shape::ControlId control = curShape->select(pos, distance, mapMan->getPointSelectionBias()); if (control == Shape::BAD_ID) return; double threshold = 1.0 / Vrui::getNavigationTransformation().getScaling(); threshold *= mapMan->getSelectDistance(); if (distance > threshold) return; curControl = control; }
int main() { cout << "[running program.]\n" << endl; // testmap.map is a simple map with two adjacent countries, c1 and c2. c1 will go to player1 and c2 to player2, so use that to test victory conditions. MapManager* manager = new MapManager("testmap"); manager->loadMap(); if (manager->isValid()) { cout << "Map file is valid!" << endl; } // fill the driver's country and continents list, based on the map loaded above. vector<Continent>continents = manager->getContinents(); vector<Country>countries = manager->getCountries(); // create the driver, assign its game logger. driver *gamedriver = new driver(continents, countries); // run the game loop and let it run its course. gamedriver->run(); cout << "\n[end of program. Press enter to exit.]"; cin.get(); return 0; }
void ComponentInventory::viewing() { //Si no ve obstacules se puede construir, si los ve no MapManager *aiAux = GameManager::getInstance()->getMapManager(); if(obstacles.empty()) { canBuild = true; } else { canBuild = false; } GraphicsEngine* graphicsEngine = GameManager::getInstance()->getGraphicsEngine(); node->setPosition(graphicsEngine->getMousePositionOnGround()); parent->position = graphicsEngine->getMousePositionOnGround(); if(aiAux->checkMap(aiAux->getFrame(parent->position).y,aiAux->getFrame(parent->position).x) == 'W' || parent->position.getSqrDistanceFrom(Vector2d(900,0)) < 122500) { canBuild = false; } //Si tiene parte estatica se pinta if(nodeStatic != NULL) { nodeStatic->setPosition(graphicsEngine->getMousePositionOnGround()); } //Mira a ver si se pulsa algun boton para destruir el actual inventory y que no puedan haber muchos a la vez EventManager *eventManager = GameManager::getInstance()->getEventManager(); if(eventManager->isKeyDown(KEY::KEY_KEY_1) || eventManager->isKeyDown(KEY::KEY_KEY_2) || eventManager->isKeyDown(KEY::KEY_KEY_3) || eventManager->isKeyDown(KEY::KEY_KEY_4) || eventManager->isKeyDown(KEY::KEY_KEY_5) || eventManager->isKeyDown(KEY::KEY_KEY_6) || eventManager->isKeyDown(KEY::KEY_KEY_7) || eventManager->isKeyDown(KEY::KEY_KEY_8) || eventManager->mouseState.rightButtonDown) { parent->kill(); } //Si se puede construir se le pone un color sino se le pone otro if(canBuild) { color = DebugColor::GREEN; } else { color = DebugColor::RED; } node->setColor(color); if(nodeStatic != NULL) { nodeStatic->setColor(color); } //Si pulsas el raton se mira que no estes encima del inventario y si se puede construir manda //un mensaje al jugador para ver si tiene dinero suficiente y se destruye el objeto if(GameManager::getInstance()->getEventManager()->mouseState.leftButtonDown) { GameManager::getInstance()->getEventManager()->mouseState.leftButtonDown = false; if(canBuild) { Message message; message.type = Message::TRY_BUY; message.value = price; message.gameObject = parent; GameManager::getInstance()->getGameObjectManager()->getMainPlayer()->broadcastMessage(message); } else { GameManager::getInstance()->getGraphicsEngine()->setWarningMessage(GameConstants::CANT_BUILD_MESSAGE); } } }
//int main(int argc, char **argv) int main(int, char **) { ALLEGRO_DISPLAY *display = NULL; ALLEGRO_EVENT_QUEUE *event_queue = NULL; ALLEGRO_TIMER *timer = NULL; Entity *player = new Entity(); //bool key[4] = { false, false, false, false }; int mvkeys[2] = { 0, 0 }; bool redraw = true; bool doexit = false; if(!al_init()) { fprintf(stderr, "failed to initialize allegro!\n"); return -1; } if(!al_init_image_addon()) { fprintf(stderr, "failed to initialize image addon!\n"); return -1; } if(!al_install_keyboard()) { fprintf(stderr, "failed to initialize the keyboard!\n"); return -1; } //--Calculate how long each frame should last in milliseconds, then create // a timer which ticks at that interval timer = al_create_timer(1.0 / FPS); if(!timer) { fprintf(stderr, "failed to create timer!\n"); return -1; } display = al_create_display(SCREEN_W, SCREEN_H); if(!display) { fprintf(stderr, "failed to create display!\n"); al_destroy_timer(timer); return -1; } //--Create a camera object for everything to use fprintf(stderr, "Creating camera\n"); Camera* camera = new Camera(); //--Initialize player entity player->init(display,camera); //player.init(display,sprite_x,sprite_y); //if (player->generate_bitmap() == -1) return -1; player->set_pos(SCREEN_W/2.0-SPRITE_W/2.0,SCREEN_H/2.0-SPRITE_H/2.0); MapManager* mapmanager = new MapManager(camera, player); mapmanager->add_map("data/levels/testmap.tmx"); mapmanager->set_active_map("data/levels/testmap.tmx"); //mapmanager->reset_camera(0,64); player->set_mapmanager(mapmanager); //fprintf(stderr, "Tileset for ID %i is %s\n",52,mapmanager->get_active_map()->get_tileset_for_id(19)->name); //TileMap *testmap = new TileMap("data/levels/outside.tmx"); event_queue = al_create_event_queue(); if(!event_queue) { fprintf(stderr, "failed to create event_queue!\n"); delete player; delete mapmanager; al_destroy_display(display); al_destroy_timer(timer); return -1; } al_register_event_source(event_queue, al_get_display_event_source(display)); al_register_event_source(event_queue, al_get_timer_event_source(timer)); al_register_event_source(event_queue, al_get_keyboard_event_source()); al_clear_to_color(al_map_rgb(0,0,0)); al_flip_display(); al_start_timer(timer); while(!doexit) { ALLEGRO_EVENT ev; al_wait_for_event(event_queue, &ev); //--Game Logic--// if(ev.type == ALLEGRO_EVENT_TIMER) { mapmanager->update(); player->update(mvkeys); //player->updatealt(mvkeys, key); redraw = true; } else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { break; } //--Store keypress info else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) { //printf("\n\nKEYCODE: %i\n\n", ev.keyboard.keycode); switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: //key[KEY_UP] = true; mvkeys[3] = 1; break; case ALLEGRO_KEY_DOWN: //key[KEY_DOWN] = true; mvkeys[4] = 1; break; case ALLEGRO_KEY_LEFT: //key[KEY_LEFT] = true; if (!mvkeys[0]) { mvkeys[0] = ALLEGRO_KEY_LEFT; } else { //mvkeys[1] = ALLEGRO_KEY_LEFT; mvkeys[1] = mvkeys[0]; mvkeys[0] = ALLEGRO_KEY_LEFT; } break; case ALLEGRO_KEY_RIGHT: //key[KEY_RIGHT] = true; if (!mvkeys[0]) { mvkeys[0] = ALLEGRO_KEY_RIGHT; } else { //mvkeys[1] = ALLEGRO_KEY_RIGHT; mvkeys[1] = mvkeys[0]; mvkeys[0] = ALLEGRO_KEY_RIGHT; } break; } } else if(ev.type == ALLEGRO_EVENT_KEY_UP) { switch(ev.keyboard.keycode) { case ALLEGRO_KEY_UP: //key[KEY_UP] = false; mvkeys[3] = 0; break; case ALLEGRO_KEY_DOWN: //key[KEY_DOWN] = false; mvkeys[4] = 0; break; case ALLEGRO_KEY_LEFT: //key[KEY_LEFT] = false; if (mvkeys[0] == ALLEGRO_KEY_LEFT) { mvkeys[0] = mvkeys[1]; mvkeys[1] = 0; } else if (mvkeys[1] == ALLEGRO_KEY_LEFT) { mvkeys[1] = 0; } break; case ALLEGRO_KEY_RIGHT: //key[KEY_RIGHT] = false; if (mvkeys[0] == ALLEGRO_KEY_RIGHT) { mvkeys[0] = mvkeys[1]; mvkeys[1] = 0; } else if (mvkeys[1] == ALLEGRO_KEY_RIGHT) { mvkeys[1] = 0; } break; case ALLEGRO_KEY_ESCAPE: doexit = true; break; } } //printf("\n[%i, %i]\n\n", mvkeys[0], mvkeys[1]); //--The screen has updated and needs to be redrawn //--Draw Logic--// if(redraw && al_is_event_queue_empty(event_queue)) { redraw = false; al_clear_to_color(al_map_rgb(50,50,50)); mapmanager->drawbg(); player->draw(); mapmanager->drawmg(); mapmanager->drawfg(); al_flip_display(); } } //--You could let Allegro do this automatically, but it's allegedly faster // if you do it manually delete player; //delete testmap; delete mapmanager; al_destroy_timer(timer); al_destroy_display(display); al_destroy_event_queue(event_queue); return 0; }
int main(int argc, char** argv) { /************************************************************************ * Input Handling * ************************************************************************/ string configFile; string logFile; CommandArgs arg; int nscale; int mscale; // Optional input parameters. arg.param("nscale", nscale, 1, "image scaling for the normal extraction"); arg.param("mscale", mscale, 1, "image scaling for matching"); // Last parameter has to be the working directory. arg.paramLeftOver("config_file", configFile, "", "file where the configuration will be written", true); arg.paramLeftOver("log_file", logFile, "", "synchronized log file", true); arg.parseArgs(argc, argv); //Aligner* aligner; //DepthImageConverter* converter; cerr << "processing log file [" << logFile << "] with parameters read from [" << configFile << "]" << endl; cerr << "reading the configuration from file [" << configFile << "]" << endl; std::vector<Serializable*> alignerInstances = readConfig(argv[0], aligner, converter, configFile); cerr<< "Aligner: " << aligner << endl; cerr<< "Converter: " << converter << endl; if (logFile=="") { cerr << "logfile not supplied" << endl; } Deserializer des; des.setFilePath(logFile); std::vector<BaseSensorData*> sensorDatas; RobotConfiguration* conf = readLog(sensorDatas, des); cerr << "# frames: " << conf->frameMap().size() << endl; cerr << "# sensors: " << conf->sensorMap().size() << endl; cerr << "# sensorDatas: " << sensorDatas.size() << endl; TSCompare comp; std::sort(sensorDatas.begin(), sensorDatas.end(), comp); MapManager* manager = new MapManager; SensingFrameNodeMaker* sensingFrameMaker = new SensingFrameNodeMaker; sensingFrameMaker->init(manager, conf); ImuRelationAdder* imuAdder = new ImuRelationAdder(manager, conf); OdometryRelationAdder* odomAdder = new OdometryRelationAdder(manager, conf); TwoDepthImageAlignerNode* pairwiseAligner = new TwoDepthImageAlignerNode(manager, conf, converter, aligner, "/kinect/depth_registered/image_raw"); for (size_t i = 0; i<sensorDatas.size(); i++) { // see if you make a sensing frame with all the infos you find SensingFrameNode* s = sensingFrameMaker->processData(sensorDatas[i]); if (s) { // add a unary relation modeling the imu to the sensing frame imuAdder->processNode(s); // add a binary relation modeling the odometry between two sensing frames odomAdder->processNode(s); // add a pwn sensing data(if you manage) pairwiseAligner->processNode(s); } } cerr << "writing out things" << endl; Serializer ser; ser.setFilePath("out.log"); for (size_t i = 0; i< alignerInstances.size(); i++) { ser.writeObject(*alignerInstances[i]); } conf->serializeInternals(ser); ser.writeObject(*conf); ReferenceFrame* lastFrame = 0; for (size_t i = 0; i<sensorDatas.size(); i++) { if (lastFrame != sensorDatas[i]->robotReferenceFrame()) { lastFrame = sensorDatas[i]->robotReferenceFrame(); ser.writeObject(*lastFrame); } ser.writeObject(*sensorDatas[i]); } ser.writeObject(*manager); for (std::set<MapNode*>::iterator it = manager->nodes().begin(); it!=manager->nodes().end(); it++) ser.writeObject(**it); cerr << "writing out " << manager->relations().size() << " relations" << endl; for (std::set<MapNodeRelation*>::iterator it = manager->relations().begin(); it!=manager->relations().end(); it++) ser.writeObject(**it); // write the aligner stuff // write the robot configuration // write the sensor data // write the manager // write the objects in the manager // // write back the log // Serializer ser; // ser.setFilePath("sensing_frame_test.log"); // conf->serializeInternals(ser); // ser.writeObject(*conf); // previousReferenceFrame = 0; // for (size_t i = 0; i< sensorDatas.size(); i++){ // BaseSensorData* data = sensorDatas[i]; // if (previousReferenceFrame!=data->robotReferenceFrame()){ // ser.writeObject(*data->robotReferenceFrame()); // } // ser.writeObject(*data); // previousReferenceFrame = data->robotReferenceFrame(); // } // for(size_t i=0; i<newObjects.size(); i++){ // ser.writeObject(*newObjects[i]); // } }
int main() { bool startGame = false; cout << "Welcome to Team 6 Project Intermediate Build Demo. " << endl << endl; do{ cout << "Would you like to load a map or create one? (type create/load) : " ; string choice; string* allowed ; allowed = new string[5]; allowed[0] = "create"; allowed[1] = "load"; logValues(&choice , 2, allowed); MapManager* demo = new MapManager() ; if(choice == "create"){ interactiveMapCreation(demo); } else if (choice == "load") { string mapname; bool exit = false; do { cout << "Enter your map file name (no need to write .map, type exit to go back) : " ; getline(cin,mapname); if(mapname == "exit") { exit = true; break; } demo = new MapManager(mapname); } while( demo->loadMap() == 0 ); if(exit == true) { continue; } } cout << "The map file was loaded properly, would you like to Edit this map or Save it and start the game? (type edit/save) : " ; allowed[0] = "edit"; allowed[1] = "save" ; logValues(&choice , 2, allowed); if(choice == "save"){ cout << "Verifying map" << endl ; cout << demo->validateMap(); cout << endl << "Saving map" << endl ; demo->saveMap(); if(choice == "save" && demo->isValid()) { startGame = true; } else if(choice == "save" && !demo->isValid()) { cout << "The loaded map file is not playable, Try loading a valid map. " << endl; } } else if (choice == "edit") { do { cout << "What would you like to modify? (Enter : settings,continents,territories or exit to save and quit) : " ; allowed[0] = "settings"; allowed[1] = "continents" ; allowed[2] = "territories"; allowed[3] = "exit" ; logValues(&choice , 4, allowed); if (choice == "exit") { cout << "Verifying map" << endl ; cout << demo->validateMap(); cout << endl << "Saving map" << endl ; demo->saveMap(); break; } else if(choice == "settings") { addMapSettings(demo); } else if(choice == "continents") { addContinents(demo); } else if(choice == "territories"){ addTerritories(demo); } } while( true ); cout << "The map file was edited properly, would you like to start the game or load a new map? (type start/load) : " ; allowed[0] = "start"; allowed[1] = "load" ; logValues(&choice , 2, allowed); if(choice == "start" && demo->isValid()) { startGame = true; } else if(choice == "start" && !demo->isValid()) { cout << "The loaded map file is not playable, Try loading a valid map. " << endl; } } } while(startGame == false); // GAME STARTS HERE cout << "Starting Gamee" << endl ; return 0; };
int main() { sf::RenderWindow App(sf::VideoMode(DemoConstants::SCREEN_WIDTH, DemoConstants::SCREEN_HEIGHT, 32), "SFML Graphics"); sf::Shape lines[6]; for(int i = 1; i < 4; ++i) { lines[i-1] = sf::Shape::Line(0,DemoConstants::CELLSIZE*i, DemoConstants::SCREEN_WIDTH, DemoConstants::CELLSIZE*i, 1, sf::Color::White); lines[i+2] = sf::Shape::Line(DemoConstants::CELLSIZE*i,0, DemoConstants::CELLSIZE*i, DemoConstants::SCREEN_HEIGHT, 1, sf::Color::White); } // How to load an image sf::Image image; // How to create a sprite from that image. CustomSprite::Init("chromatic_circle.png"); // Make an instance of our sprite manager. SpriteManager spriteManager; //Create an instance of the map manager MapManager mapManager; //Create an instance of the collision manager CollisionManager * m_pCollisionManager = CollisionManager::instance(); CustomSprite * theChosenOne; vector<CustomSprite *> & allSprites = spriteManager.GetAllSprites(); list<CustomSprite *> nearbySprites; theChosenOne = allSprites.at(8); App.SetFramerateLimit(120); // Start game loop while (App.IsOpened()) { // Process events sf::Event Event; while (App.PollEvent(Event)) { // Close window : exit if (Event.Type == sf::Event::Closed) App.Close(); } // Clear the screen (fill it with black color) App.Clear(); // How to draw a line. for(int i = 0; i < 6; ++i) { App.Draw(lines[i]); } //Mouse Input if (sf::Mouse::IsButtonPressed(sf::Mouse::Left)) { //Check Collision mouse for (int i = 0; i < allSprites.size(); ++i) { if (sf::Mouse::GetPosition(App).x % ((int)allSprites.at(i)->GetPosition().x+1) < (allSprites.at(i)->radius() * 2) && sf::Mouse::GetPosition(App).y % ((int)allSprites.at(i)->GetPosition().y+1) < (allSprites.at(i)->radius() * 2)) { theChosenOne = allSprites.at(i); } } } //Add all the sprites to their buckets for (int i = 0; i < allSprites.size(); ++i){ mapManager.RegisterSprite(allSprites.at(i)); } theChosenOne->SetColor(sf::Color(255, 255, 255)); //Get the list of sprites nearby nearbySprites = mapManager.GetNearbySprites(theChosenOne); list<CustomSprite *>::iterator iter = nearbySprites.begin(); //Collision check with nearby sprites for (int i = 0; i < nearbySprites.size(); ++i, ++iter) { if (m_pCollisionManager->CheckCollision(theChosenOne, *iter) == true) { iter.operator*()->reverse(); theChosenOne->reverse(); } iter.operator*()->SetColor(sf::Color(150, 150, 150)); } //Update the sprites, includes keeping them within //the boundaries of the window spriteManager.updateSprites(); // How to draw a container of sprites. for ( int i = 0; i < allSprites.size(); ++i ) { App.Draw( * allSprites.at(i) ); allSprites.at(i)->SetColor(sf::Color(50, 50, 50)); } mapManager.ClearBucketLists(); // Display window contents on screen App.Display(); } return EXIT_SUCCESS; }
void ComponentInventory::create() { GameObject* element = NULL; MapManager *aiAux = GameManager::getInstance()->getMapManager(); Vector2d pos = aiAux->getFrame(parent->position); pos = Vector2d(pos.y,pos.x); if(aiAux->checkMap(pos.x,pos.y) != 'W') { switch (parent->getName()) { case GameObject::N_INVENTORY_TURRET_PROJECTILE: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_PROJECTILE,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurret(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; case GameObject::N_INVENTORY_MINE: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_MINE,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingMine(parent->position); } break; case GameObject::N_MINE2: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_MINE2,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingMine2(parent->position); } break; case GameObject::N_MINE3: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_MINE3,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingMine3(parent->position); } break; case GameObject::N_INVENTORY_TURRET_BULLET: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_BULLET,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurret2(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; case GameObject::N_INVENTORY_TURRET_2_CANON: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_2_CANON,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurret2Canon(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; case GameObject::N_INVENTORY_TURRET_BIG_CANON: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_BIG_CANON,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurretBigCanon(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; case GameObject::N_INVENTORY_TURRET_1_CANON: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_1_CANON,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurret1Canon(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; case GameObject::N_INVENTORY_TURRET_GUN: //Crea un objeto para empezar a construirse if(GameManager::getInstance()->getNetworkEngine()->isStarted()) { GameManager::getInstance()->getNetworkEngine()->messageCreateSkill(GameObject::N_BUILDING_TURRET_GUN,parent->position); } else { element = GameManager::getInstance()->getGameObjectManager()->createBuildingTurretGun(parent->position); } delete node; node = NULL; delete nodeStatic; nodeStatic = NULL; break; } if(element != NULL) { element->setPosition(parent->position.x,parent->position.y); element->rotation = parent->rotation; } } parent->kill(); }