- Timestamp:
- Nov 4, 2017, 5:04:59 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc
r11516 r11528 64 64 point = 0; 65 65 66 // Pre-set the timer, but don't start it yet. 67 this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this))); 66 68 } 67 69 70 //spawnt durch den Timer Asteroiden, denk dran, dass falls ein Asteroid stirbt er in 2 teile geteilt wird 71 Asteroids::spawnStone(){ 72 if(getPlayer() == nullptr){ 73 return; 74 } 75 76 AsteroidsStone* newStone; 77 newStone = new AsteroidsStone(this->center_->getContext()); 78 newStone->addTemplate("asteroidsstone"); 79 newStone->setAsteroidsPlayer(player); 80 } 81 82 void Invader::spawnEnemy() 83 { 84 if (getPlayer() == nullptr) 85 return; 86 87 for (int i = 0; i < (3*log10(static_cast<double>(level)) + 1); i++) 88 { 89 InvaderEnemy* newPawn; 90 if (rand() % 42/(1 + level*level) == 0) 91 { 92 newPawn = new InvaderEnemyShooter(this->center_->getContext()); 93 newPawn->addTemplate("enemyinvadershooter"); 94 } 95 else 96 { 97 newPawn = new InvaderEnemy(this->center_->getContext()); 98 newPawn->addTemplate("enemyinvader"); 99 } 100 newPawn->setInvaderPlayer(player); 101 newPawn->level = level; 102 // spawn enemy at random points in front of player. 103 newPawn->setPosition(player->getPosition() + Vector3(500.f + 100 * i, 0, float(rand())/RAND_MAX * 400 - 200)); 104 } 105 } 106 107 /** 108 @brief 109 Destructor. Cleans up, if initialized. 110 */ 111 Asteroids::~Asteroids() 112 { 113 if (this->isInitialized()) 114 this->cleanup(); 115 } 116 117 /** 118 @brief 119 Cleans up the Gametype by destroying all of the objects in the game - spaceship and asteroids. 120 */ 121 void Asteroids::cleanup() 122 { 123 if (this->stones_ != nullptr) // Destroy the ball, if present. 124 { 125 this->stones_->destroy(); 126 this->stones_ = nullptr; 127 } 128 129 // Destroy AsteroidsShip 130 131 if (this->player != nullptr) 132 { 133 this->player->destroy(); 134 this->player = nullptr; 135 } 136 } 68 137 69 138 AsteroidsShip* Asteroids::getPlayer() … … 87 156 lives = 0; 88 157 }; 89 90 158 void Asteroids::start() 91 159 { 92 // Set variable to temporarily force the player to spawn. 93 this->bForceSpawn_ = true; 94 95 if (this->center_ == nullptr) // abandon mission! 160 if (this->center_ == nullptr) // There needs to be a AsteroidsCenterpoint, i.e. the area the game takes place. If no centerpoint was specified, an error is thrown and the level is exited. 96 161 { 97 orxout(internal_error) << " Invader: No Centerpoint specified." << endl;162 orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl; 98 163 GSLevel::startMainMenu(); 99 164 return; 100 165 } 166 167 // Set variable to temporarily force the player to spawn. 168 bool temp = this->bForceSpawn_; 169 this->bForceSpawn_ = true; 170 101 171 // Call start for the parent class. 102 172 Deathmatch::start(); 173 174 // Reset the variable. 175 this->bForceSpawn_ = temp; 103 176 } 104 177
Note: See TracChangeset
for help on using the changeset viewer.