Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 11598


Ignore:
Timestamp:
Nov 27, 2017, 3:00:47 PM (6 years ago)
Author:
pascscha
Message:

faster asteroid spawning

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

Legend:

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

    r11595 r11598  
    6666        spawnDistance=200;                  //distance between tubes
    6767        tubeOffsetX=500;                    //tube offset (so that we can't see them spawn)
     68
     69        circlesUsed=0;
    6870        setHUDTemplate("FlappyOrxHUD");
    6971    }
     
    127129        int noadd = 0;  //how many times we failed to add a new asteroid
    128130
    129         ClearAsteroids();   //Delete Asteroids
     131        clearCircles();   //Delete Circles (we use circles to make sure we don't spawn two asteroids on top of eachother)
    130132        Circle newAsteroid = Circle();
    131133        newAsteroid.x=x;
     
    135137
    136138        //Fill up triangle with asteroids
    137         while(r>0){
     139        while(noadd<5&&circlesUsed<nCircles){
    138140            if(slope>0)
    139141                newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;   //create asteroid on bottom
     
    148150                noadd++;
    149151            else if(i==2)
    150                 r=0;
    151             if(noadd>=5){
    152                 noadd=0;
    153                 r-=5;
    154             }
     152                noadd=5;
    155153        }
    156154    }
     
    179177        //add to Queue (so that we can delete it again)
    180178        asteroids.push(newAsteroid);
     179    }
     180
     181    //Deletes Asteroids array which stores all the circles used to make sure no asteroids collide when spawning
     182    void FlappyOrx::clearCircles(){
     183        circlesUsed=0;
     184        for(int i = 0; i<this->nCircles; i++){
     185            circles[i].r=0;
     186        }
     187    }
     188
     189    //checks if two circles collide
     190    bool FlappyOrx::circleCollision(Circle &c1, Circle &c2){
     191        if(c1.r<=0 || c2.r<=0)
     192            return false;
     193        int x = c1.x - c2.x;
     194        int y = c1.y - c2.y;
     195        int r = c1.r + c2.r;
     196
     197        return x*x+y*y<r*r*1.5;
     198    }
     199
     200    //Adds a circle if its not colliding
     201    int FlappyOrx::addIfPossible(Circle c){
     202        int i;
     203        for(i=0; i<this->nCircles && this->circles[i].r!=0 && c.r>0;i++){
     204            while(circleCollision(c,this->circles[i])){
     205                c.r-=5; //when it collides, try to make it smaller
     206            }
     207        }
     208        if(c.r<=0){
     209            return 0;
     210        }
     211        circlesUsed++;
     212        this->circles[i].x=c.x;
     213        this->circles[i].y=c.y;
     214        this->circles[i].r=c.r;
     215        createAsteroid(c);
     216        return 1;
    181217    }
    182218
  • code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h

    r11596 r11598  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
    24  *   Co-authors:
    25  *      ...
     23 *      Leo Mehr Holz
     24 *      Pascal Schärli
    2625 *
    2726 */
     
    3938
    4039#include "gametypes/Deathmatch.h"
    41 #include "tools/Timer.h"
    4240#include <vector>
    4341
     
    7775            void setCenterpoint(FlappyOrxCenterPoint* center);
    7876
    79             int getLives(){return this->lives;}
    80             int getLevel(){return this->level;}
    8177            int getPoints(){return this->point;}
    82             int getMultiplier(){return this->multiplier;}
    83 
    84             void costLife();
     78           
    8579            void levelUp();
    86             void addPoints(int numPoints);
    87             // checks if multiplier should be reset.
    88             void comboControll();
    89 
     80           
    9081            bool isDead();
    9182            void setDead(bool value);
     
    9384            FlappyOrxShip* getPlayer();
    9485           
    95             int lives;
    96             int multiplier;
    9786            bool bEndGame;
    98             bool bShowLevel;
    9987            bool bIsDead;
    10088            bool firstGame;
     
    10694           
    10795        private:
    108             void toggleShowLevel(){bShowLevel = !bShowLevel;}
    109            
    110             const static int nAst = 7;
    111             Circle Asteroids[nAst];
     96             
     97            const static int nCircles = 6;
     98            int circlesUsed;
     99            Circle circles[nCircles];
    112100
    113             void ClearAsteroids(){
    114                 for(int i = 0; i<this->nAst; i++){
    115                     Asteroids[i].r=0;
    116                 }
    117             }
    118 
    119            
    120             bool Collision(Circle &c1, Circle &c2){
    121                 if(c1.r==0 || c2.r==0)
    122                     return false;
    123                 int x = c1.x - c2.x;
    124                 int y = c1.y - c2.y;
    125                 int r = c1.r + c2.r;
    126 
    127                 return x*x+y*y<r*r*1.5;
    128             }
    129 
    130             int addIfPossible(Circle c){
    131                 int i;
    132                 for(i=0; i<this->nAst && this->Asteroids[i].r!=0;i++){
    133                     if(Collision(c,this->Asteroids[i])){
    134                         return 0;
    135                     }
    136                 }
    137                 if(i==nAst)
    138                     return 2;
    139                 this->Asteroids[i].x=c.x;
    140                 this->Asteroids[i].y=c.y;
    141                 this->Asteroids[i].r=c.r;
    142                 createAsteroid(c);
    143                 return 1;
    144             }
    145            
    146            
     101            void clearCircles();
     102            bool circleCollision(Circle &c1, Circle &c2);
     103            int addIfPossible(Circle c);
    147104
    148105            WeakPtr<FlappyOrxCenterPoint> center_;
    149106            WeakPtr<FlappyOrxShip> player;
    150107
    151             Timer enemySpawnTimer;
    152             Timer comboTimer;
    153             Timer showLevelTimer;
    154             //Context* context;
    155108            int level;
    156109            int point;
Note: See TracChangeset for help on using the changeset viewer.