//To break the asteroid into smaller ones before it is deleted. std::vector <Asteroid> Asteroid::destroy() const { std::vector <Asteroid> asteroids; unsigned int numAsteroids = circle.getRadius()/10; for(unsigned int i = 0; i < numAsteroids; ++i) { unsigned int toModX=rand()%10 + 1; unsigned int toModY=rand()%10 + 1; if(toModX < 5) toModX = -1; else toModX = 1; if(toModY < 5) toModY = -1; else toModY = 1; Vector newVelocity = Vector(rand() % 80 + 41,rand()%360+1)+velocity; unsigned int newRadius = rand()%int(circle.getRadius())+1; long double newX = rand()%10*toModX + x; long double newY = rand()%10*toModY + y; asteroids.push_back(Asteroid(newVelocity, newRadius, newX, newY)); } return asteroids; }
void Menu::playGame(){ int player_score; std::string player_name = "LaughingCabbage"; Game Asteroid(menuWindow); Asteroid.setup(); Asteroid.gameLoop(player_score, player_name); if(player_name.size() >= 2){ std::cout << "name okay\n"; HsManager.writeScore(player_score, player_name); } }
void Asteroids::start(Difficulty difficulty) { for (auto p : players) { p->position = glm::vec2(1920 / 2, 1080 / 2) + 400.0f * blib::math::fromAngle(glm::radians(360.0f / players.size() * p->index)); p->rotation = 360.0f / players.size() * p->index + 180; } for (int i = 0; i < 25; i++) asteroids.push_back(Asteroid()); //add an asteroid }
void ManagerModel::AddAsteroid(int type, int length, Vec2 scale, Vec2 startPosition) { for (int i = 0; i != length; ++i) { Asteroid *asteroid = DBG_NEW Asteroid(); asteroid->OnInit(this); asteroid->mType = type; asteroid->SetType(type); asteroid->Cleavage(startPosition, scale); mEntities.push_back(asteroid); for (auto *view : mViews) { view->OnAsteroidSpawned((Asteroid*)asteroid); } } }
void AsteroidsGame::resetAsteroids(){ asteroids.erase(asteroids.begin(), asteroids.end()); for(int i = 0; i<3 ; i++) { asteroids.push_back(Asteroid()); Asteroid & asteroid = asteroids[asteroids.size()-1] ; asteroid.setPos(centre - ofVec2f(100,0)); asteroid.setVel(ofVec2f(1,0.1)); if(i==1) { asteroid.vel = -asteroid.vel; asteroid.pos.x = centre.x + 100; }else if(i==2) { asteroid.vel.y = -asteroid.vel.x; asteroid.pos = centre; } asteroid.setRadius(100); for(int j = 0; j<300; j++) asteroid.pos-=asteroid.vel; } }
void Game::MakeAsteroids(int surftex) { int asteroidCount = 2 + level*2 + rand()%(level+3); if (asteroidCount > MAX_ASTEROIDS) asteroidCount = MAX_ASTEROIDS; cout << " Asteroids: " << asteroidCount << endl; asteroids_.clear(); for (int i = 0; i < asteroidCount; i++) { // Allocate space, check for timeout int x, y, width = rand() % (Asteroid::MAX_ASTEROID_WIDTH - 4) + 4; if (!objgrid.AllocFreeSpace(x, y, width, 4)) { // Failed to allocate space so don't make any more asteroids break; } // Generate the asteroid asteroids_.push_back(Asteroid(x, y, width, surftex)); } }
void ManagerModel::Init(Vec2 screen, int asteroidType1, int asteroidType2, int maxScore, int level) { this->maxScore = maxScore; SetPlayArea(screen); if (level > 0) { isHealthPackageRespawnActivated = true; } Player *player = DBG_NEW Player(); mEntities.push_back(player); ScoreKeeper *scoreKeeper = DBG_NEW ScoreKeeper(); scoreKeeper->mScore = 0; mEntities.push_back(scoreKeeper); HealthKeeper *healthKeeper = DBG_NEW HealthKeeper(); healthKeeper->mHealth = player->defaultHealth; healthKeeper->mMaxHealth = player->defaultHealth; mEntities.push_back(healthKeeper); if (level == 0 || level == 1) { Asteroid *asteroid = DBG_NEW Asteroid(); asteroid->SetType(asteroidType1); mEntities.push_back(asteroid); Asteroid *asteroid2 = DBG_NEW Asteroid(); asteroid2->SetType(asteroidType2); mEntities.push_back(asteroid2); } else if (level == 2) { EnemieBoss *enemieBoss = DBG_NEW EnemieBoss(); mEntities.push_back(enemieBoss); } else { //TODO! Add new game elements for levels > 2... } for (Entity *e : mEntities) { e->OnInit(this); switch (e->Type()) { case ENTITY_PLAYER: for (auto *view : mViews) { view->OnPlayerSpawned((Player*)e); } break; case ENTITY_ASTEROID: for (View::ManagerView *view : mViews) { view->OnAsteroidSpawned((Asteroid*)e); } break; case ENTITY_HP: for (View::ManagerView *view : mViews) { view->OnHPInit((HealthKeeper*)e); } break; case ENTITY_SCORE: for (View::ManagerView *view : mViews) { view->OnScoreInit((ScoreKeeper*)e); } break; case ENTITY_ENEMIEBOSS: for (auto *view : mViews) { view->OnEnemieBossSpawned((EnemieBoss*)e); } break; } } }