Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11595


Ignore:
Timestamp:
Nov 27, 2017, 2:03:45 PM (6 years ago)
Author:
pascscha
Message:

cleanup

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

Legend:

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

    r11589 r11595  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
    24  *   Co-authors:
    25  *      ...
     23 *      Leo Mehr Holz
     24 *      Pascal Schärli
    2625 *
    2726 */
     
    6059    {
    6160        RegisterObject(FlappyOrx);
    62         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    6361        this->center_ = nullptr;
    64         bEndGame = false;
    65         lives = 1;
    66         level = 0;
    67         point = 0;
    68         bShowLevel = false;
    69         sDeathMessage = "Welcome to FlappyOrx";
     62        point = 0;                          //number of cleared tubes
    7063        bIsDead = true;
    71         this->spawnDistance=200;
    72         this->tubeOffsetX=500;
    73         this->setHUDTemplate("FlappyOrxHUD");
    74         firstGame = true;
    75     }
     64        firstGame = true;                   //needed for the HUD
     65
     66        spawnDistance=200;                  //distance between tubes
     67        tubeOffsetX=500;                    //tube offset (so that we can't see them spawn)
     68        setHUDTemplate("FlappyOrxHUD");
     69    }
     70
    7671
    7772    void FlappyOrx::updatePlayerPos(int x){
    7873
     74        //Spawn a new Tube when the spawn distance is reached
    7975        if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){
    8076            spawnTube();
    8177            this->tubes.push(x+tubeOffsetX);
    8278        }
     79        //Delete Tubes when we pass through them
    8380        if(this->tubes.size()!=0&&x>this->tubes.front()){
    8481            this->tubes.pop();
    8582            levelUp();
    8683        }
    87         while((this->asteroids.front())->getPosition().x<x-300){
     84        //Delete Asteroids which are not visible anymore
     85        while((this->asteroids.front())->getPosition().x<x-tubeOffsetX){
    8886            MovableEntity* deleteMe = asteroids.front();
    8987            asteroids.pop();
     
    9290    }
    9391
    94     void FlappyOrx::levelUp()
    95     {
     92    //Gets called when we pass through a Tube
     93    void FlappyOrx::levelUp(){
    9694        point++;
    97         spawnDistance = 300-3*point;
    98         getPlayer()->setSpeed(100+.5*point);
    99         toggleShowLevel();
    100         //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
    101     }
    102 
    103     FlappyOrxShip* FlappyOrx::getPlayer()
    104     {
    105         if (player == nullptr)
    106         {
     95        spawnDistance = 300-3*point;            //smaller spawn Distance
     96        getPlayer()->setSpeed(100+.5*point);    //increase speed
     97    }
     98
     99    //Returns our Ship
     100    FlappyOrxShip* FlappyOrx::getPlayer(){
     101        if (player == nullptr){
    107102            for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) {
    108103                player = ship;
     
    112107    }
    113108
    114     void FlappyOrx::spawnTube()
    115     {
    116         int space = 120;
    117         int height = (float(rand())/RAND_MAX-0.5)*(280-space);
    118            
     109    //Spawn new Tube
     110    void FlappyOrx::spawnTube(){
    119111        if (getPlayer() == nullptr)
    120112            return;
    121113
     114        int space = 120;    //vertical space between top and bottom tube
     115        int height = (float(rand())/RAND_MAX-0.5)*(280-space);  //Randomize height
     116           
    122117        Vector3 pos = player->getPosition();
    123118
    124         asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);
    125         asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8);   
    126     }
    127 
     119        //create the two Asteroid fields (Tubes)
     120        asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);  //bottom 
     121        asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8); //top
     122    }
     123
     124    //Creates a new asteroid Field
    128125    void FlappyOrx::asteroidField(int x, int y, float slope){
    129         int r = 20;
    130         int noadd = 0;
    131 
    132         ClearAsteroids();
     126        int r = 20;     //Radius of added Asteroids
     127        int noadd = 0;  //how many times we failed to add a new asteroid
     128
     129        ClearAsteroids();   //Delete Asteroids
    133130        Circle newAsteroid = Circle();
    134131        newAsteroid.x=x;
    135132        newAsteroid.y=y;
    136133        newAsteroid.r=r;
    137         addIfPossible(newAsteroid);
     134        addIfPossible(newAsteroid); //Add Asteroid at peak
     135
     136        //Fill up triangle with asteroids
    138137        while(r>0){
    139138            if(slope>0)
    140                 newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;
     139                newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;   //create asteroid on bottom
    141140            else
    142                 newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;
     141                newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;     //create asteroid on top
    143142           
    144143            newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope;
    145144            newAsteroid.r=r;
    146145           
    147             int i = addIfPossible(newAsteroid);
     146            int i = addIfPossible(newAsteroid); //Add Asteroid if it doesn't collide
    148147            if(i==0)
    149148                noadd++;
     
    157156    }
    158157
    159     void deleteAsteroid(MovableEntity* asteroid){
    160         //center_->getContext().getObjectList().removeElement(asteroid);
    161     }
    162 
     158    //Create a new Asteroid
    163159    void FlappyOrx::createAsteroid(Circle &c){
    164160        MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
    165161
    166 
     162        //Add Model fitting the Size of the Asteroid
    167163        if(c.r<=5)
    168164            newAsteroid->addTemplate(Asteroid5[rand()%NUM_ASTEROIDS]);
     
    174170            newAsteroid->addTemplate(Asteroid20[rand()%NUM_ASTEROIDS]);
    175171       
     172        //Set position
    176173        newAsteroid->setPosition(Vector3(c.x, 0, c.y));
     174
     175        //Randomize orientation
    177176        newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360));
    178177        newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
    179178
     179        //add to Queue (so that we can delete it again)
    180180        asteroids.push(newAsteroid);
    181 
    182 
    183     }
    184 
    185     void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center)
    186     {
     181    }
     182
     183    void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center){
    187184        this->center_ = center;
    188185    }
    189 
    190     void FlappyOrx::costLife()
    191     {
    192        
    193     };
    194186
    195187    bool FlappyOrx::isDead(){
     
    201193        if(not value){
    202194            point = -1;
    203             level=-1;
    204195            levelUp();
    205196        }
     
    221212    }
    222213
    223 
     214    //RIP
    224215    void FlappyOrx::death(){
    225216        bIsDead = true;
    226217        firstGame = false;
    227218       
     219        //Set randomized deathmessages
    228220        if(point<10)        sDeathMessage = DeathMessage10[rand()%(DeathMessage10.size())];
    229221        else if(point<30)   sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())];
     
    231223        else                sDeathMessage = DeathMessageover50[rand()%(DeathMessageover50.size())];
    232224       
    233         orxout()<<"message: "<<sDeathMessage<<std::endl;
    234 
    235 
     225        //Update Highscore
    236226        if (Highscore::exists()){
    237227                    int score = this->getPoints();
     
    239229                        Highscore::getInstance().storeHighscore("Flappy Orx",score);
    240230        }
    241         while (!tubes.empty())
    242         {
     231
     232        //Delete all Tubes and asteroids
     233        while (!tubes.empty()){
    243234            tubes.pop();
    244235        }
    245         while (!asteroids.empty())
    246         {
     236        while (!asteroids.empty()){
    247237            MovableEntity* deleteMe = asteroids.front();
    248238            asteroids.pop();
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h

    r11589 r11595  
    9090            bool isDead();
    9191            void setDead(bool value);
     92
     93            FlappyOrxShip* getPlayer();
    9294           
    9395            int lives;
     
    102104            int spawnDistance;
    103105            int tubeOffsetX;
    104 
     106           
    105107        private:
    106108            void toggleShowLevel(){bShowLevel = !bShowLevel;}
     
    144146           
    145147
    146             FlappyOrxShip* getPlayer();
    147148            WeakPtr<FlappyOrxCenterPoint> center_;
    148149            WeakPtr<FlappyOrxShip> player;
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc

    r11589 r11595  
    104104                            break;
    105105                            case 3:
    106                                 message = "Press space to restart.";
     106                                int time = this->FlappyOrxGame->getPlayer()->timeUntilRespawn();
     107                                if(time<=0)
     108                                    message = "Press space to restart.";
     109                                else
     110                                    message = "Please wait "+multi_cast<std::string>(time)+" seconds.";
    107111                            break;
    108112                        }
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc

    r11576 r11595  
    4040#include "weapons/projectiles/Projectile.h"
    4141#include <math.h>
     42#include <ctime>
    4243
    4344namespace orxonox
     
    5354        this->gravity = 1;
    5455        isDead = true;
     56        deathTime = 0;
    5557       
    5658    }
     
    128130    void FlappyOrxShip::moveRightLeft(const Vector2& value){}
    129131
     132    int FlappyOrxShip::timeUntilRespawn(){
     133        return 2-time(0)+deathTime;
     134    }
     135
    130136    void FlappyOrxShip::boost(bool boost){
    131         if(isDead){
     137
     138   
     139        if(isDead&&timeUntilRespawn()<=0){
    132140            isDead = false;
    133141            getGame()->setDead(false);
     
    156164    {
    157165        isDead = true;
     166
     167        deathTime = time(0);
     168
     169        orxout()<<"death time: "<<deathTime<<std::endl;
    158170        Vector3 pos = getPosition();
    159171        pos.x = 0;
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h

    r11565 r11595  
    7474                { return this->UpwardThrust; }
    7575            virtual void updateLevel();
     76            virtual int timeUntilRespawn();
     77           
    7678            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    7779
     
    8587            bool isDead;
    8688            float speed, UpwardThrust, gravity;
     89            long deathTime;
    8790            struct Velocity
    8891            {
Note: See TracChangeset for help on using the changeset viewer.