Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 4, 2017, 5:04:59 PM (8 years ago)
Author:
vyang
Message:

Spawn Funktion fuer die Asteroiden veraendert

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.cc

    r11516 r11528  
    6464        point = 0;
    6565
     66        // Pre-set the timer, but don't start it yet.
     67        this->enemySpawnTimer_.setTimer(5.0, true, createExecutor(createFunctor(&Asteroids::spawnStone, this)));
    6668    }
    6769
     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    }
    68137
    69138    AsteroidsShip* Asteroids::getPlayer()
     
    87156        lives = 0;
    88157    };
    89 
    90158    void Asteroids::start()
    91159    {
    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.
    96161        {
    97             orxout(internal_error) << "Invader: No Centerpoint specified." << endl;
     162            orxout(internal_error) << "Asteroids: No Centerpoint specified." << endl;
    98163            GSLevel::startMainMenu();
    99164            return;
    100165        }
     166
     167        // Set variable to temporarily force the player to spawn.
     168        bool temp = this->bForceSpawn_;
     169        this->bForceSpawn_ = true;
     170
    101171        // Call start for the parent class.
    102172        Deathmatch::start();
     173
     174        // Reset the variable.
     175        this->bForceSpawn_ = temp;
    103176    }
    104177
Note: See TracChangeset for help on using the changeset viewer.