Changeset 11598 for code/branches/FlappyOrx_HS17/src/modules
- Timestamp:
- Nov 27, 2017, 3:00:47 PM (7 years ago)
- 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 66 66 spawnDistance=200; //distance between tubes 67 67 tubeOffsetX=500; //tube offset (so that we can't see them spawn) 68 69 circlesUsed=0; 68 70 setHUDTemplate("FlappyOrxHUD"); 69 71 } … … 127 129 int noadd = 0; //how many times we failed to add a new asteroid 128 130 129 ClearAsteroids(); //Delete Asteroids131 clearCircles(); //Delete Circles (we use circles to make sure we don't spawn two asteroids on top of eachother) 130 132 Circle newAsteroid = Circle(); 131 133 newAsteroid.x=x; … … 135 137 136 138 //Fill up triangle with asteroids 137 while( r>0){139 while(noadd<5&&circlesUsed<nCircles){ 138 140 if(slope>0) 139 141 newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150; //create asteroid on bottom … … 148 150 noadd++; 149 151 else if(i==2) 150 r=0; 151 if(noadd>=5){ 152 noadd=0; 153 r-=5; 154 } 152 noadd=5; 155 153 } 156 154 } … … 179 177 //add to Queue (so that we can delete it again) 180 178 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; 181 217 } 182 218 -
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
r11596 r11598 21 21 * 22 22 * Author: 23 * Florian Zinggeler 24 * Co-authors: 25 * ... 23 * Leo Mehr Holz 24 * Pascal Schärli 26 25 * 27 26 */ … … 39 38 40 39 #include "gametypes/Deathmatch.h" 41 #include "tools/Timer.h"42 40 #include <vector> 43 41 … … 77 75 void setCenterpoint(FlappyOrxCenterPoint* center); 78 76 79 int getLives(){return this->lives;}80 int getLevel(){return this->level;}81 77 int getPoints(){return this->point;} 82 int getMultiplier(){return this->multiplier;} 83 84 void costLife(); 78 85 79 void levelUp(); 86 void addPoints(int numPoints); 87 // checks if multiplier should be reset. 88 void comboControll(); 89 80 90 81 bool isDead(); 91 82 void setDead(bool value); … … 93 84 FlappyOrxShip* getPlayer(); 94 85 95 int lives;96 int multiplier;97 86 bool bEndGame; 98 bool bShowLevel;99 87 bool bIsDead; 100 88 bool firstGame; … … 106 94 107 95 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]; 112 100 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); 147 104 148 105 WeakPtr<FlappyOrxCenterPoint> center_; 149 106 WeakPtr<FlappyOrxShip> player; 150 107 151 Timer enemySpawnTimer;152 Timer comboTimer;153 Timer showLevelTimer;154 //Context* context;155 108 int level; 156 109 int point;
Note: See TracChangeset
for help on using the changeset viewer.