Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Asteroids2D erfolgreich als Minigame eingebunden, Dimensionen des Spielfeldes werden im CenterPoint gesetzt.

Location:
code/branches/Asteroid_HS17/src/modules/asteroids2D
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.cc

    r11593 r11608  
    3535#include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header!
    3636#include "core/CoreIncludes.h"
    37 
     37#include "Highscore.h"
    3838
    3939namespace orxonox
     
    4444    {
    4545        RegisterObject(Asteroids2D);
    46         this->bEndGame = false;
    4746
     47        bEndGame = false;
     48        lives = 1;
     49        level = 1;
     50        point = 0;
     51        bShowLevel = false;
     52        multiplier = 1;
     53        b_combo = false;
     54        counter = 5000;
     55        pattern = 1;
     56        lastPosition = 0;
     57        // spawn enemy every 3.5 seconds
     58        //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&Asteroids2D::spawnEnemy, this)));
     59        this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
     60        this->center_ = nullptr;
     61        this->setHUDTemplate("Asteroids2DHUD");
     62    }
     63
     64    void Asteroids2D::levelUp()
     65    {
     66        level++;
     67        if (getPlayer() != nullptr)
     68        {
     69            for (int i = 0; i < 7; i++)
     70            {
     71                WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
     72                chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
     73                chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
     74                chunk5->setScale(10);
     75                chunk5->setEffect1("Orxonox/explosion2b");
     76                chunk5->setEffect2("Orxonox/smoke6");
     77                chunk5->Explode();
     78
     79            }
     80        }
     81        addPoints(multiplier * 42);
     82        multiplier *= 2;
     83        toggleShowLevel();
     84        showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this)));
    4885    }
    4986
    5087    void Asteroids2D::tick(float dt)
    5188    {
    52 
     89       
    5390        SUPER(Asteroids2D, tick, dt);
    5491    }
     
    66103    }
    67104
     105    void Asteroids2D::costLife()
     106    {
     107        //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this)));
     108        lives = 0;
     109    };
     110
    68111    void Asteroids2D::start()
    69112    {
    70113        orxout() << "start" << endl;
    71        
     114
    72115        // Set variable to temporarily force the player to spawn.
    73116        this->bForceSpawn_ = false;
     
    83126    }
    84127
     128    void Asteroids2D::playerPreSpawn(PlayerInfo* player)
     129    {
     130        if(lives <= 0)
     131        {
     132            this->end();
     133        }
     134    }
     135
     136    void Asteroids2D::addPoints(int numPoints)
     137    {
     138        if (!bEndGame)
     139        {
     140            point += numPoints * multiplier;
     141            b_combo = true;
     142        }
     143    }
     144
    85145    void Asteroids2D::end()
    86146    {
     
    89149        // It will misteriously crash the game!
    90150        // Instead startMainMenu, this won't crash.
    91         orxout() << "Asteroids2D Game has ended" << endl;
     151        if (Highscore::exists()){
     152                    int score = this->getPoints();
     153                    if(score > Highscore::getInstance().getHighestScoreOfGame("Dodge Race"))
     154                        Highscore::getInstance().storeHighscore("Dodge Race",score);
     155
     156          }
    92157        GSLevel::startMainMenu();
    93158    }
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2D.h

    r11593 r11608  
    5050#include "gamestates/GSLevel.h"
    5151#include "chat/ChatManager.h"
    52 
     52#include <vector>
    5353
    5454// ! HACK
     
    5858
    5959#include "gametypes/Deathmatch.h"
     60#include "tools/Timer.h"
    6061
    6162namespace orxonox
     
    6970            virtual void start() override;
    7071            virtual void end() override;
     72
    7173            virtual void tick(float dt) override;
     74
     75            virtual void playerPreSpawn(PlayerInfo* player) override;
     76
     77            void levelUp();
     78
     79            int getLives(){return this->lives;}
     80            int getLevel(){return this->level;}
     81            int getPoints(){return this->point;}
     82            int getMultiplier(){return this->multiplier;}
    7283
    7384            void setCenterpoint(Asteroids2DCenterPoint* center)
    7485                       { this->center_ = center; }
     86            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    7587
    76             virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
     88            // checks if multiplier should be reset.
     89            void costLife();
     90
    7791            bool bEndGame;
     92            bool bShowLevel;
     93            int lives;
     94            int multiplier;
     95            float counter;
     96            int pattern;
     97            float currentPosition;
     98            float lastPosition;
    7899
    79100       private:
    80 
     101            Timer endGameTimer;
    81102
    82103            Asteroids2DShip* getPlayer();
    83104            WeakPtr<Asteroids2DShip> player;
     105            std::vector<Asteroids2DCube*> cubeList;
     106            void toggleShowLevel(){bShowLevel = !bShowLevel;}
     107            void addPoints(int numPoints);
     108
    84109            WeakPtr<Asteroids2DCenterPoint> center_;
     110            int level;
     111            int point;
     112            bool b_combo;
     113
     114            Timer enemySpawnTimer;
     115            Timer comboTimer;
     116            Timer showLevelTimer;
    85117
    86118
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DCenterPoint.cc

    r11593 r11608  
    3535
    3636#include "core/CoreIncludes.h"
     37#include "core/XMLPort.h"
    3738
    3839#include "Asteroids2D.h"
     
    4748
    4849        this->checkGametype();
     50        this->width_ = 200;
     51        this->height_ = 120;
    4952    }
     53    /**
     54    @brief
     55        Method to create a Asteroids2DCenterpoint through XML.
     56    */
     57    void Asteroids2DCenterPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     58    {
     59        SUPER(Asteroids2DCenterPoint, XMLPort, xmlelement, mode);
    5060
     61        XMLPortParam(Asteroids2DCenterPoint, "dimension", setFieldDimension, getFieldDimension, xmlelement, mode);
     62    }
    5163    void Asteroids2DCenterPoint::checkGametype()
    5264    {
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DCenterPoint.h

    r11593 r11608  
    4949        public:
    5050            Asteroids2DCenterPoint(Context* context); //checks whether the gametype is actually Asteroids2D.
     51            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Method to create a PongCenterpoint through XML.
     52            /**
     53            @brief Set the dimensions of the playing field.
     54            @param dimension A vector with the width of the playing field as first component and the height as second.
     55            */
     56            void setFieldDimension(const Vector2& dimension)
     57                { this->width_ = dimension.x; this->height_ = dimension.y; }
     58            /**
     59            @brief Get the dimensions of the playing field.
     60            @return Returns a vector with the width of the playing field as first component and the height as second.
     61            */
     62            Vector2 getFieldDimension() const
     63                { return Vector2(this->width_, this->height_); }
    5164
    5265        private:
    5366            void checkGametype();
     67            float width_, height_;
    5468
    5569    };
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DHUDinfo.cc

    r11593 r11608  
    2525 */
    2626
    27 #include "DodgeRaceHUDinfo.h"
     27#include "Asteroids2DHUDinfo.h"
    2828
    2929#include "core/CoreIncludes.h"
    3030#include "core/XMLPort.h"
    3131#include "util/Convert.h"
    32 //#include "DodgeRace.h"
     32//#include "Asteroids2D.h"
    3333
    3434namespace orxonox
    3535{
    36     RegisterClass(DodgeRaceHUDinfo);
     36    RegisterClass(Asteroids2DHUDinfo);
    3737
    38     DodgeRaceHUDinfo::DodgeRaceHUDinfo(Context* context) : OverlayText(context)
     38    Asteroids2DHUDinfo::Asteroids2DHUDinfo(Context* context) : OverlayText(context)
    3939    {
    40         RegisterObject(DodgeRaceHUDinfo);
     40        RegisterObject(Asteroids2DHUDinfo);
    4141
    42         this->DodgeRaceGame = nullptr;
     42        this->Asteroids2DGame = nullptr;
    4343        this->bShowPoints_ = true;
    4444    }
    4545
    46     void DodgeRaceHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     46    void Asteroids2DHUDinfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    4747    {
    48         SUPER(DodgeRaceHUDinfo, XMLPort, xmlelement, mode);
     48        SUPER(Asteroids2DHUDinfo, XMLPort, xmlelement, mode);
    4949
    50         XMLPortParam(DodgeRaceHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false);
     50        XMLPortParam(Asteroids2DHUDinfo,"showPoints", setShowPoints, getShowPoints, xmlelement, mode).defaultValues(false);
    5151    }
    5252
    53     void DodgeRaceHUDinfo::tick(float dt)
     53    void Asteroids2DHUDinfo::tick(float dt)
    5454    {
    55         SUPER(DodgeRaceHUDinfo, tick, dt);
     55        SUPER(Asteroids2DHUDinfo, tick, dt);
    5656
    5757
    5858        if(this->bShowPoints_)
    5959        {
    60             const std::string& points = multi_cast<std::string>(this->DodgeRaceGame->getPoints());
    61             if (this->DodgeRaceGame->lives <= 0)
     60            const std::string& points = multi_cast<std::string>(this->Asteroids2DGame->getPoints());
     61            if (this->Asteroids2DGame->lives <= 0)
    6262            {
    6363                setTextSize(0.2);
     
    7676    }
    7777
    78     void DodgeRaceHUDinfo::changedOwner()
     78    void Asteroids2DHUDinfo::changedOwner()
    7979    {
    80         SUPER(DodgeRaceHUDinfo, changedOwner);
     80        SUPER(Asteroids2DHUDinfo, changedOwner);
    8181
    8282        if (this->getOwner() && this->getOwner()->getGametype())
    8383        {
    84             this->DodgeRaceGame = orxonox_cast<DodgeRace*>(this->getOwner()->getGametype());
     84            this->Asteroids2DGame = orxonox_cast<Asteroids2D*>(this->getOwner()->getGametype());
    8585        }
    8686        else
    8787        {
    88             this->DodgeRaceGame = nullptr;
     88            this->Asteroids2DGame = nullptr;
    8989        }
    9090    }
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.cc

    r11593 r11608  
    5555    void Asteroids2DShip::tick(float dt)
    5656    {
    57         Vector3 pos = getPosition();
    58 
    59         //Movement calculation
    60         lastTimeFront += dt * damping;
    61         lastTimeLeft += dt * damping;
    62         lastTime += dt;
    63 
    64         velocity.x = interpolate(clamp(lastTimeLeft, 0.0f, 1.0f), desiredVelocity.x, 0.0f);
    65         velocity.y = interpolate(clamp(lastTimeFront, 0.0f, 1.0f), desiredVelocity.y, 0.0f);
    66 
    67         //Execute movement
    68         if (this->hasLocalController())
    69         {
    70             float dist_y = velocity.y * dt;
    71             //float dist_x = velocity.x * dt;
    72             if(dist_y + posforeward > -42*3 && dist_y + posforeward < 42*6)
    73                 posforeward += dist_y;
    74             else
    75             {
    76                 velocity.y = 0;
    77                 // restart if game ended
    78 /*
    79                 if (getGame())
    80                     if (getGame()->bEndGame)
    81                     {
    82                         getGame()->start();
    83                         return;
    84                     }*/
    85             }
    86 
    87             pos += Vector3(1000 + velocity.y, 0, velocity.x) * dt;
    88         }
    89 
    90         // bring back on track!
    91         if(pos.y != 0)
    92         {
    93             pos.y = 0;
    94         }
    95 
    96         setPosition(pos);
    97         setOrientation(Vector3::UNIT_Y, Degree(270));
    98 
    9957        SUPER(Asteroids2DShip, tick, dt);
    10058    }
    10159
    102     void Asteroids2DShip::moveFrontBack(const Vector2& value)
     60    void Asteroids2DShip::updateLevel()
     61    {
     62        lastTime = 0;
     63        if (getGame())
     64            getGame()->levelUp();
     65    }
     66
     67/*    void Asteroids2DShip::moveFrontBack(const Vector2& value)
    10368    {
    10469        //lastTimeFront = 0;
    10570        //desiredVelocity.y = value.y * speed * 42;
    106 
     71        orxout() << "FrontBack" << endl;
     72        SUPER(Asteroids2DShip, moveFrontBack, value);
    10773    }
    10874
    10975    void Asteroids2DShip::moveRightLeft(const Vector2& value)
    11076    {
    111         lastTimeLeft = 0;
    112         desiredVelocity.x = value.x * speed;
     77        //lastTimeLeft = 0;
     78        //desiredVelocity.x = value.x * speed;
     79        orxout() << "RightLeft" << endl;
     80        SUPER(Asteroids2DShip, moveFrontBack, value);       
    11381    }
     82 */
    11483    void Asteroids2DShip::boost(bool bBoost)
    11584    {
     
    139108    void Asteroids2DShip::death()
    140109    {
    141         //getGame()->costLife();
     110        getGame()->costLife();
    142111        SpaceShip::death();
    143112    }
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/Asteroids2DShip.h

    r11593 r11608  
    5555
    5656            // overwrite for 2d movement
    57             virtual void moveFrontBack(const Vector2& value) override;
    58             virtual void moveRightLeft(const Vector2& value) override;
     57            //virtual void moveFrontBack(const Vector2& value) override;
     58            //virtual void moveRightLeft(const Vector2& value) override;
    5959
    6060            // Starts or stops fireing
     
    6262
    6363            //no rotation!
     64            virtual void rotateYaw(const Vector2& value) override{};
    6465            virtual void rotatePitch(const Vector2& value) override{};
    6566
    6667            //return to main menu if game has ended.
    6768            virtual void rotateRoll(const Vector2& value) override{if (getGame()) if (getGame()->bEndGame) getGame()->end();};
     69
     70            virtual void updateLevel();
    6871
    6972            virtual inline bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
  • code/branches/Asteroid_HS17/src/modules/asteroids2D/CMakeLists.txt

    r11593 r11608  
    1 SET_SOURCE_FILES(Asteroids2D_SRC_FILES
     1SET_SOURCE_FILES(MINIGAMESTEST_SRC_FILES
    22Asteroids2D.cc
    33Asteroids2DCenterPoint.cc
    44Asteroids2DShip.cc
     5Asteroids2DCube.cc
     6Asteroids2DHUDinfo.cc
    57)
    68
     
    1113    orxonox
    1214    overlays
    13   SOURCE_FILES ${ASTEROIDS2D_SRC_FILES}
     15  SOURCE_FILES ${MINIGAMESTEST_SRC_FILES}
    1416)
Note: See TracChangeset for help on using the changeset viewer.