void testApp::update(){ ken.update(); ryu.update(); Projectile::gravity = panel.getValueF("gravity"); Projectile::friction = panel.getValueF("friction"); Projectile::explosionTime = panel.getValueF("explosionTime"); if(panel.getValueB("manualMode")) { if(panel.getValueB("fire0")) { panel.setValueB("fire0", false); fire(getId(0)); } if(panel.getValueB("fire1")) { panel.setValueB("fire1", false); fire(getId(1)); } if(panel.hasValueChanged(variadic("playerCount"))) { setPlayerCount(panel.getValueI("playerCount")); panel.clearAllChanged(); } updatePosition(0, panel.getValueF("player0x"), panel.getValueF("player0y")); updatePosition(1, panel.getValueF("player1x"), panel.getValueF("player1y")); } while(receiver.hasWaitingMessages()) { ofxOscMessage msg; receiver.getNextMessage(&msg); if (msg.getAddress() == "/pew/playerPosition") { updatePosition(getId(msg.getArgAsInt32(0)), msg.getArgAsFloat(1), msg.getArgAsFloat(2)); } else if(msg.getAddress() == "/pew/fire") { fire(getId(msg.getArgAsInt32(0))); } else if (msg.getAddress() == "/pew/players") { setPlayerCount(msg.getArgAsInt32(0)); } } float explodeDistance = panel.getValueF("explodeDistance"); float dt = ofGetLastFrameTime(); for(int i = 0; i < projectiles.size(); i++) { projectiles[i].update(dt); for(int j = 0; j < players.size(); j++) { float distance = projectiles[i].position.distance(players[j].position); if(projectiles[i].source != j && distance < explodeDistance) { if(!projectiles[i].exploding) { projectiles[i].explode(); players[j].ouch(); } } } } ofRemove(projectiles, isOldProjectile); }
void CMapGenOptions::finalize(CRandomGenerator & rand) { logGlobal->info("RMG settings: players %d, teams %d, computer players %d, computer teams %d, water %d, monsters %d", static_cast<int>(getPlayerCount()), static_cast<int>(getTeamCount()), static_cast<int>(getCompOnlyPlayerCount()), static_cast<int>(getCompOnlyTeamCount()), static_cast<int>(getWaterContent()), static_cast<int>(getMonsterStrength())); if(!mapTemplate) { mapTemplate = getPossibleTemplate(rand); } assert(mapTemplate); if (getPlayerCount() == RANDOM_SIZE) { auto possiblePlayers = mapTemplate->getPlayers().getNumbers(); //ignore all non-randomized players, make sure these players will not be missing after roll possiblePlayers.erase(possiblePlayers.begin(), possiblePlayers.lower_bound(countHumanPlayers() + countCompOnlyPlayers())); assert(!possiblePlayers.empty()); setPlayerCount (*RandomGeneratorUtil::nextItem(possiblePlayers, rand)); updatePlayers(); } if(teamCount == RANDOM_SIZE) { teamCount = rand.nextInt(getPlayerCount() - 1); if (teamCount == 1) teamCount = 0; } if(compOnlyPlayerCount == RANDOM_SIZE) { auto possiblePlayers = mapTemplate->getCpuPlayers().getNumbers(); compOnlyPlayerCount = *RandomGeneratorUtil::nextItem(possiblePlayers, rand); updateCompOnlyPlayers(); } if(compOnlyTeamCount == RANDOM_SIZE) { compOnlyTeamCount = rand.nextInt(std::max(compOnlyPlayerCount - 1, 0)); } if(waterContent == EWaterContent::RANDOM) { waterContent = static_cast<EWaterContent::EWaterContent>(rand.nextInt(EWaterContent::NONE, EWaterContent::ISLANDS)); } if(monsterStrength == EMonsterStrength::RANDOM) { monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); } assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS)); assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); //rectangular maps are the future of gaming //setHeight(20); //setWidth(50); logGlobal->trace("Player config:"); int humanPlayers = 0, cpuOnlyPlayers = 0, AIplayers = 0; for (auto player : players) { std::string playerType; switch (player.second.getPlayerType()) { case EPlayerType::AI: playerType = "AI"; AIplayers++; break; case EPlayerType::COMP_ONLY: playerType = "computer only"; cpuOnlyPlayers++; break; case EPlayerType::HUMAN: playerType = "human only"; humanPlayers++; break; default: assert(false); } logGlobal->trace("Player %d: %s", player.second.getColor(), playerType); } setCompOnlyPlayerCount(cpuOnlyPlayers); //human players are set automaticlaly (?) logGlobal->info("Final player config: %d total, %d cpu-only", players.size(), (int)getCompOnlyPlayerCount()); }