void GameState::createDollar() { std::list<Player*>::const_iterator it_player = Player::s_playerList.begin(); while (Dollar::s_dollarList.size() < unsigned(Player::alivePlayers)) { Dollar* newDollar = new Dollar(config::path + config::D_SRC, 0, 0); int newDollar_xPos = 0; int newDollar_yPos = 0; bool valid = false; while(!valid) { //Loop until valid pos is found valid = true; newDollar_xPos = rand() % (config::W_WIDTH - newDollar->getWidth()) ; newDollar_yPos = rand() % (config::W_HEIGHT - newDollar->getHeight()) ; while(it_player != Player::s_playerList.end()) { if(Entity::collides((*it_player), newDollar)) { valid = false; break; } it_player++; } } newDollar->setXPos(static_cast<float>(newDollar_xPos)); newDollar->setYPos(static_cast<float>(newDollar_yPos)); Dollar::s_dollarList.push_back(newDollar); } }
void GameState::createDollar() { auto& dollarList = entityManager->getAll<Dollar>(); Config& config = Config::getInstance(); while (dollarList.size() < unsigned(Player::getAlivePlayerCount())) { Dollar* newDollar = entityManager->create<Dollar>(atlas->findRegion(config.getDollarRegion()), 0.f, 0.f, config.getDollarWidth(), config.getDollarHeight()); int newDollar_xPos = 0; int newDollar_yPos = 0; bool valid = false; while (!valid) { //Loop until valid pos is found valid = true; newDollar_xPos = rand() % (config.getGameWidth() - (int)newDollar->getWidth()); newDollar_yPos = rand() % (config.getGameHeight() - (int)newDollar->getHeight()); newDollar->setX((float)newDollar_xPos); newDollar->setY((float)newDollar_yPos); for (auto& e : entityManager->getAll<Player>()) { Player* p = reinterpret_cast<Player*>(e); if (AbstractEntity::collides(p, newDollar)) { valid = false; break; } } } newDollar->setX((float)newDollar_xPos); newDollar->setY((float)newDollar_yPos); newDollar->copyDataForInterpolation(); } }