Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Spawn Funktion fuer die Asteroiden veraendert

Location:
code/branches/Asteroid_HS17/src/modules/asteroids
Files:
9 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
  • code/branches/Asteroid_HS17/src/modules/asteroids/Asteroids.h

    r11516 r11528  
    6161            void addPoints(int numPoints);
    6262
     63            void spawnStone();
     64
    6365            int lives;
    6466            bool bEndGame;
     
    6668        private:
    6769            void toggleShowLevel(){bShowLevel = !bShowLevel;}
     70            void cleanup(void); //!< Cleans up the Gametype by destroying the ball and the bats.
    6871            AsteroidsShip* getPlayer();
    6972            WeakPtr<AsteroidsCenterPoint> center_;
    7073            WeakPtr<AsteroidsShip> player;
    7174            WeakPtr<Camera> camera;
     75            WeakPtr<AsteroidsStones> stones_;
    7276
    7377            Timer enemySpawnTimer;
    74             Timer comboTimer;
    75             Timer showLevelTimer;
    7678            //Context* context;
    7779            int level;
    7880            int point;
    7981            bool b_combo;
     82
     83            Timer starttimer_; //!< A timer to delay the start of the game.
    8084    };
    8185}
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.cc

    r11516 r11528  
    4646        RegisterObject(AsteroidsCenterPoint);
    4747
     48
     49        //Werte ausprobieren und testen!
     50        this->width_ = 500;
     51        this->height_= 300;
     52
    4853        this->checkGametype();
    4954    }
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsCenterPoint.h

    r11516 r11528  
    4747            AsteroidsCenterPoint(Context* context); //checks whether the gametype is actually Invader.
    4848
     49                        /**
     50            @brief Set the dimensions of the playing field.
     51            @param dimension A vector with the width of the playing field as first component and the height as second.
     52            */
     53            void setFieldDimension(const Vector2& dimension)
     54                { this->width_ = dimension.x; this->height_ = dimension.y; }
     55            /**
     56            @brief Get the dimensions of the playing field.
     57            @return Returns a vector with the width of the playing field as first component and the height as second.
     58            */
     59            Vector2 getFieldDimension() const
     60                { return Vector2(this->width_, this->height_); }
     61
    4962        private:
    5063            void checkGametype();
     64            //Spielfeld liegt in x-z Ebene, x ist LeftRight(Horizontale), z ist UpDown (Vertikale)
     65            float width_;
     66            float height_;
    5167
    5268    };
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.cc

    r11516 r11528  
    55#include "Asteroids.h"
    66#include "graphics/Camera.h"
    7 #include "asteroids/AsteroidStone"
     7#include "asteroids/AsteroidStone.h"
    88#include "weapons/projectiles/Projectile.h"
     9#include "asteroids/AsteroidsCenterpoint.h"
    910
    1011
     
    108109
    109110            pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
     111
    110112        }
    111113
    112114
    113         // Camera
     115
     116        //Camera ticken? Bleibt eigentlich am selben Ort...irgendwo initialisieren
    114117        Camera* camera = this->getCamera();
    115118        if (camera != nullptr)
     
    132135        SUPER(AsteroidsShip, tick, dt);
    133136    }
    134    
     137
     138    void AsteroidsShip::moveFrontBack(const Vector2& value)
     139    {
     140
     141
     142    }
     143
     144    void AsteroidsShip::moveFrontBack(const Vector2& value)
     145    {
     146
     147    }
     148    void AsteroidsShip::moveFrontBack(const Vector2& value)
     149    {
     150
     151    }
     152
    135153    Asteroids* AsteroidsShip::getGame()
    136154    {
     
    143161    }
    144162
    145     void InvaderShip::death()
     163    void AsteroidsShip::death()
    146164    {
    147165        getGame()->costLife();
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsShip.h

    r11516 r11528  
    5656            virtual void moveFrontBack(const Vector2& value) override;
    5757            virtual void moveRightLeft(const Vector2& value) override;
     58            virtual void moveUpDown(const Vector2& value) override;
    5859
    5960            // Starts or stops fireing
     
    6162
    6263
    63             void setCenterpoint(DodgeRaceCenterPoint* center)
     64            void setCenterpoint(AsteroidsCenterPoint* center)
    6465                       { this->center_ = center; }
     66
     67
    6568            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    6669
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.cc

    r11516 r11528  
    4242{
    4343    RegisterClass(AsteroidsStone);
    44 
    45     AsteroidsStone::AsteroidsStone(Context* context) : MovableEntity(context)
     44    //pawn kann sterben -> nach dem Tot sollen aber 2 Asteroiden spawnen
     45    AsteroidsStone::AsteroidsStone(Context* context) : Pawn(context)
    4646    {
    4747        RegisterObject(AsteroidsStone);
     48
     49
    4850
    4951        maxspeed = 50.0f;
  • code/branches/Asteroid_HS17/src/modules/asteroids/AsteroidsStone.h

    r11516 r11528  
    2828
    2929/**
    30     @file InvaderEnemy.h
    31     @brief Declaration of the InvaderEnemy class.
     30    @file AsteroidsStone.h
     31    @brief Declaration of the AsteroidsStone class.
    3232*/
    3333
     
    3737#include "asteroids/AsteroidsPrereqs.h"
    3838
    39 #include "worldentities/MovableEntity.h"
     39#include "worldentities/Pawn.h"
    4040
    4141namespace orxonox
    4242{
    43     class _AsteroidsExport AsteroidsStone : public MovableEntity
     43    class _AsteroidsExport AsteroidsStone : public Pawn
    4444    {
    4545        public:
     
    4747            virtual void tick(float dt) override;
    4848
     49            //Radius of the asteroid
    4950            float r;
    5051            int level;
     52            virtual void setAsteroidsPlayer(AsteroidsShip* player){this->player = player;}
     53
    5154        protected:
    52             float fieldWidth_;
    53             float fieldHeight_;
     55
     56            //herausfinden->ueber Kamera Einstellung wie bei Pong?
     57            float fieldWidth_=500;
     58            float fieldHeight_=700;
    5459            Vector2 velocity;
    5560            float maxspeed;
    56 
    57 
    58 
    5961    };
    6062}
    6163
    62 #endif /* _InvaderEnemy_H__ */
     64#endif /* _AsteroidsStone_H__ */
  • code/branches/Asteroid_HS17/src/modules/asteroids/CMakeLists.txt

    r11516 r11528  
    33  Asteroids.cc
    44  AsteroidsCenterPoint.cc
    5   InvaderShip.cc
     5  AsteroidsShip.cc
    66  AsteroidsStone.cc
    77  AsteroidsWeapon.cc
Note: See TracChangeset for help on using the changeset viewer.