Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11537


Ignore:
Timestamp:
Nov 6, 2017, 3:32:04 PM (7 years ago)
Author:
pascscha
Message:

Death

Location:
code/branches/FlappyOrx_HS17/src/modules/flappyorx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc

    r11533 r11537  
    7474
    7575    void FlappyOrx::updatePlayerPos(int x){
     76
    7677        if(this->tubes.size()==0||x-this->tubes.back()-tubeOffsetX>spawnDistance){
    7778            spawnTube();
     
    8283            levelUp();
    8384            point++;
     85        }
     86        while((this->asteroids.front())->getPosition().x<x-300){
     87            MovableEntity* deleteMe = asteroids.front();
     88            asteroids.pop();
     89            deleteMe->destroy();
    8490        }
    8591    }
     
    144150    }
    145151
     152    void deleteAsteroid(MovableEntity* asteroid){
     153        //center_->getContext().getObjectList().removeElement(asteroid);
     154    }
     155
    146156    void FlappyOrx::createAsteroid(Circle &c){
    147157        orxout() << "created Asteroid at x="<<c.x<<" y="<<c.y << std::endl;
     158
    148159        MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
     160
     161
    149162        if(c.r<=5)
    150163            newAsteroid->addTemplate(Asteroid5[rand()%6]);
     
    160173        newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
    161174
     175        asteroids.push(newAsteroid);
     176
     177
    162178    }
    163179
     
    169185    void FlappyOrx::costLife()
    170186    {
    171         lives--;
    172         multiplier = 1;
    173         // end the game in 30 seconds.
    174         if (lives <= 0)
    175             enemySpawnTimer.setTimer(30.0f, false, createExecutor(createFunctor(&FlappyOrx::end, this)));
     187       
    176188    };
    177189
     
    206218            point += numPoints * multiplier;
    207219            b_combo = true;
     220        }
     221    }
     222
     223    void FlappyOrx::death(){
     224        if (Highscore::exists()){
     225                    int score = this->getPoints();
     226                    if(score > Highscore::getInstance().getHighestScoreOfGame("Orxonox Arcade"))
     227                        Highscore::getInstance().storeHighscore("Orxonox Arcade",score);
     228
     229        }
     230        point = 0;
     231        while (!tubes.empty())
     232        {
     233            tubes.pop();
     234        }
     235        while (!asteroids.empty())
     236        {
     237            MovableEntity* deleteMe = asteroids.front();
     238            asteroids.pop();
     239            deleteMe->destroy();
    208240        }
    209241    }
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h

    r11533 r11537  
    6868            virtual void start() override;
    6969            virtual void end() override;
     70            virtual void death();
    7071            virtual void addBots(unsigned int amount) override{} //<! overwrite function in order to bypass the addbots command
    7172
     
    9293            bool bShowLevel;
    9394            std::queue<int> tubes;
     95            std::queue<MovableEntity*> asteroids;
    9496            int spawnDistance;
    9597            int tubeOffsetX;
     
    146148            int point;
    147149            bool b_combo;
    148             std::string Asteroid5[6] = {"Asteroid3_1","Asteroid3_2","Asteroid3_3","Asteroid3_4","Asteroid3_5","Asteroid3_6"};
    149             std::string Asteroid10[6] = {"Asteroid6_1","Asteroid6_2","Asteroid6_3","Asteroid6_4","Asteroid6_5","Asteroid6_6"};
    150             std::string Asteroid15[6] = {"Asteroid9_1","Asteroid9_2","Asteroid9_3","Asteroid9_4","Asteroid9_5","Asteroid9_6"};
    151             std::string Asteroid20[6] = {"Asteroid12_1","Asteroid12_2","Asteroid12_3","Asteroid12_4","Asteroid12_5","Asteroid12_6"};
     150
     151            const std::string Asteroid5[6] = {"Asteroid3_1","Asteroid3_2","Asteroid3_3","Asteroid3_4","Asteroid3_5","Asteroid3_6"};
     152            const std::string Asteroid10[6] = {"Asteroid6_1","Asteroid6_2","Asteroid6_3","Asteroid6_4","Asteroid6_5","Asteroid6_6"};
     153            const std::string Asteroid15[6] = {"Asteroid9_1","Asteroid9_2","Asteroid9_3","Asteroid9_4","Asteroid9_5","Asteroid9_6"};
     154            const std::string Asteroid20[6] = {"Asteroid12_1","Asteroid12_2","Asteroid12_3","Asteroid12_4","Asteroid12_5","Asteroid12_6"};
     155           
    152156
    153157
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxAsteroid.cc

    r11530 r11537  
    1 /*
    2  *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net <
    4  *
    5  *
    6  *   License notice:
    7  *
    8  *   This program is free software; you can redistribute it and/or
    9  *   modify it under the terms of the GNU General Public License
    10  *   as published by the Free Software Foundation; either version 2
    11  *   of the License, or (at your option) any later version.
    12  *
    13  *   This program is distributed in the hope that it will be useful,
    14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
    17  *
    18  *   You should have received a copy of the GNU General Public License
    19  *   along with this program; if not, write to the Free Software
    20  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    21  *
    22  *   Author:
    23  *      Florian Zinggeler
    24  *   Co-authors:
    25  *      ...
    26  *
    27  */
    28 
    29 /**
    30     @file FlappyOrxAsteroid.h
    31     @brief Declaration of the FlappyOrxAsteroid class.
    32 */
    33 
    34 #include "FlappyOrxAsteroid.h"
    35 
    36 #include "core/CoreIncludes.h"
    37 #include "FlappyOrx.h"
    38 #include "FlappyOrxShip.h"
    39 
    40 namespace orxonox
    41 {
    42     RegisterClass(FlappyOrxAsteroid);
    43 
    44     FlappyOrxAsteroid::FlappyOrxAsteroid(Context* context) : Pawn(context)
    45     {
    46         RegisterObject(FlappyOrxAsteroid);
    47         enableCollisionCallback();
    48         lifetime = 0;
    49     }
    50 
    51     void FlappyOrxAsteroid::tick(float dt)
    52     {
    53         lifetime += dt;
    54         // die after 5 seconds.
    55         if (lifetime > 5000)
    56             removeHealth(2000);
    57 
    58         if (player != nullptr)
    59         {
    60             float newZ = 2/(pow(std::abs(getPosition().x - player->getPosition().x) * 0.01f, 2) + 1) * (player->getPosition().z - getPosition().z);
    61             setVelocity(Vector3(1000.f - level * 100 , 0, newZ));
    62         }
    63         SUPER(FlappyOrxAsteroid, tick, dt);
    64     }
    65 
    66     inline bool FlappyOrxAsteroid::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
    67     {
    68         if(orxonox_cast<FlappyOrxShip*>(otherObject))
    69             removeHealth(2000);
    70         return false;
    71     }
    72 
    73     FlappyOrx* FlappyOrxAsteroid::getGame()
    74     {
    75         if (game == nullptr)
    76         {
    77             for (FlappyOrx* flappyOrx : ObjectList<FlappyOrx>())
    78                 game = flappyOrx;
    79         }
    80         return game;
    81     }
    82 
    83     void FlappyOrxAsteroid::damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    84     {
    85         Pawn::damage(damage, healthdamage, shielddamage, originator, cs);
    86         if (getGame() && orxonox_cast<FlappyOrxShip*>(originator) != nullptr && getHealth() <= 0)
    87             getGame()->addPoints(42);
    88     }
    89 }
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxAsteroid.h

    r11530 r11537  
    1 /*
    2  *   ORXONOX - the hottest 3D action shooter ever to exist
    3  *                    > www.orxonox.net <
    4  *
    5  *
    6  *   License notice:
    7  *
    8  *   This program is free software; you can redistribute it and/or
    9  *   modify it under the terms of the GNU General Public License
    10  *   as published by the Free Software Foundation; either version 2
    11  *   of the License, or (at your option) any later version.
    12  *
    13  *   This program is distributed in the hope that it will be useful,
    14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16  *   GNU General Public License for more details.
    17  *
    18  *   You should have received a copy of the GNU General Public License
    19  *   along with this program; if not, write to the Free Software
    20  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
    21  *
    22  *   Author:
    23  *      Florian Zinggeler
    24  *   Co-authors:
    25  *      ...
    26  *
    27  */
    28 
    29 /**
    30     @file FlappyOrxAsteroid.h
    31     @brief Declaration of the FlappyOrxAsteroid class.
    32 */
    33 
    34 #ifndef _FlappyOrxAsteroid_H__
    35 #define _FlappyOrxAsteroid_H__
    36 
    37 #include "flappyorx/FlappyOrxPrereqs.h"
    38 
    39 #include "worldentities/pawns/Pawn.h"
    40 
    41 namespace orxonox
    42 {
    43     class _FlappyOrxExport FlappyOrxAsteroid : public Pawn
    44     {
    45         public:
    46             FlappyOrxAsteroid(Context* context);
    47 
    48             virtual void tick(float dt) override;
    49             virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
    50             virtual void damage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs) override;
    51             virtual void setFlappyOrxPlayer(FlappyOrxShip* player){this->player = player;}
    52 
    53             int level;
    54         protected:
    55             FlappyOrx* getGame();
    56             WeakPtr<FlappyOrx> game;
    57             WeakPtr<FlappyOrxShip> player;
    58             Camera* camera;
    59             bool isFireing;
    60             float speed, damping;
    61             float lastTimeFront, lastTimeLeft;
    62             float lifetime;
    63             struct Velocity
    64             {
    65                 float x;
    66                 float y;
    67             } velocity, desiredVelocity;
    68 
    69     };
    70 }
    71 
    72 #endif /* _FlappyOrxAsteroid_H__ */
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc

    r11529 r11537  
    7070            if(getHealth()<0){
    7171                 getGame()->costLife();
    72                  getGame()->end();
     72                 getGame()->death();
     73                 death();
    7374            }
    7475            Vector3 pos = getPosition();
     
    151152    void FlappyOrxShip::death()
    152153    {
    153 
     154        Vector3 pos = getPosition();
     155        pos.x = 0;
     156        setPosition(pos);
    154157    }
    155158}
Note: See TracChangeset for help on using the changeset viewer.