Changeset 11595 for code/branches/FlappyOrx_HS17/src/modules
- Timestamp:
- Nov 27, 2017, 2:03:45 PM (7 years ago)
- 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 21 21 * 22 22 * Author: 23 * Florian Zinggeler 24 * Co-authors: 25 * ... 23 * Leo Mehr Holz 24 * Pascal Schärli 26 25 * 27 26 */ … … 60 59 { 61 60 RegisterObject(FlappyOrx); 62 this->numberOfBots_ = 0; //sets number of default bots temporarly to 063 61 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 70 63 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 76 71 77 72 void FlappyOrx::updatePlayerPos(int x){ 78 73 74 //Spawn a new Tube when the spawn distance is reached 79 75 if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){ 80 76 spawnTube(); 81 77 this->tubes.push(x+tubeOffsetX); 82 78 } 79 //Delete Tubes when we pass through them 83 80 if(this->tubes.size()!=0&&x>this->tubes.front()){ 84 81 this->tubes.pop(); 85 82 levelUp(); 86 83 } 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){ 88 86 MovableEntity* deleteMe = asteroids.front(); 89 87 asteroids.pop(); … … 92 90 } 93 91 94 void FlappyOrx::levelUp()95 {92 //Gets called when we pass through a Tube 93 void FlappyOrx::levelUp(){ 96 94 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){ 107 102 for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) { 108 103 player = ship; … … 112 107 } 113 108 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(){ 119 111 if (getPlayer() == nullptr) 120 112 return; 121 113 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 122 117 Vector3 pos = player->getPosition(); 123 118 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 128 125 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 133 130 Circle newAsteroid = Circle(); 134 131 newAsteroid.x=x; 135 132 newAsteroid.y=y; 136 133 newAsteroid.r=r; 137 addIfPossible(newAsteroid); 134 addIfPossible(newAsteroid); //Add Asteroid at peak 135 136 //Fill up triangle with asteroids 138 137 while(r>0){ 139 138 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 141 140 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 143 142 144 143 newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope; 145 144 newAsteroid.r=r; 146 145 147 int i = addIfPossible(newAsteroid); 146 int i = addIfPossible(newAsteroid); //Add Asteroid if it doesn't collide 148 147 if(i==0) 149 148 noadd++; … … 157 156 } 158 157 159 void deleteAsteroid(MovableEntity* asteroid){ 160 //center_->getContext().getObjectList().removeElement(asteroid); 161 } 162 158 //Create a new Asteroid 163 159 void FlappyOrx::createAsteroid(Circle &c){ 164 160 MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext()); 165 161 166 162 //Add Model fitting the Size of the Asteroid 167 163 if(c.r<=5) 168 164 newAsteroid->addTemplate(Asteroid5[rand()%NUM_ASTEROIDS]); … … 174 170 newAsteroid->addTemplate(Asteroid20[rand()%NUM_ASTEROIDS]); 175 171 172 //Set position 176 173 newAsteroid->setPosition(Vector3(c.x, 0, c.y)); 174 175 //Randomize orientation 177 176 newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360)); 178 177 newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360)); 179 178 179 //add to Queue (so that we can delete it again) 180 180 asteroids.push(newAsteroid); 181 182 183 } 184 185 void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center) 186 { 181 } 182 183 void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center){ 187 184 this->center_ = center; 188 185 } 189 190 void FlappyOrx::costLife()191 {192 193 };194 186 195 187 bool FlappyOrx::isDead(){ … … 201 193 if(not value){ 202 194 point = -1; 203 level=-1;204 195 levelUp(); 205 196 } … … 221 212 } 222 213 223 214 //RIP 224 215 void FlappyOrx::death(){ 225 216 bIsDead = true; 226 217 firstGame = false; 227 218 219 //Set randomized deathmessages 228 220 if(point<10) sDeathMessage = DeathMessage10[rand()%(DeathMessage10.size())]; 229 221 else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())]; … … 231 223 else sDeathMessage = DeathMessageover50[rand()%(DeathMessageover50.size())]; 232 224 233 orxout()<<"message: "<<sDeathMessage<<std::endl; 234 235 225 //Update Highscore 236 226 if (Highscore::exists()){ 237 227 int score = this->getPoints(); … … 239 229 Highscore::getInstance().storeHighscore("Flappy Orx",score); 240 230 } 241 while (!tubes.empty()) 242 { 231 232 //Delete all Tubes and asteroids 233 while (!tubes.empty()){ 243 234 tubes.pop(); 244 235 } 245 while (!asteroids.empty()) 246 { 236 while (!asteroids.empty()){ 247 237 MovableEntity* deleteMe = asteroids.front(); 248 238 asteroids.pop(); -
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
r11589 r11595 90 90 bool isDead(); 91 91 void setDead(bool value); 92 93 FlappyOrxShip* getPlayer(); 92 94 93 95 int lives; … … 102 104 int spawnDistance; 103 105 int tubeOffsetX; 104 106 105 107 private: 106 108 void toggleShowLevel(){bShowLevel = !bShowLevel;} … … 144 146 145 147 146 FlappyOrxShip* getPlayer();147 148 WeakPtr<FlappyOrxCenterPoint> center_; 148 149 WeakPtr<FlappyOrxShip> player; -
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc
r11589 r11595 104 104 break; 105 105 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."; 107 111 break; 108 112 } -
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc
r11576 r11595 40 40 #include "weapons/projectiles/Projectile.h" 41 41 #include <math.h> 42 #include <ctime> 42 43 43 44 namespace orxonox … … 53 54 this->gravity = 1; 54 55 isDead = true; 56 deathTime = 0; 55 57 56 58 } … … 128 130 void FlappyOrxShip::moveRightLeft(const Vector2& value){} 129 131 132 int FlappyOrxShip::timeUntilRespawn(){ 133 return 2-time(0)+deathTime; 134 } 135 130 136 void FlappyOrxShip::boost(bool boost){ 131 if(isDead){ 137 138 139 if(isDead&&timeUntilRespawn()<=0){ 132 140 isDead = false; 133 141 getGame()->setDead(false); … … 156 164 { 157 165 isDead = true; 166 167 deathTime = time(0); 168 169 orxout()<<"death time: "<<deathTime<<std::endl; 158 170 Vector3 pos = getPosition(); 159 171 pos.x = 0; -
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h
r11565 r11595 74 74 { return this->UpwardThrust; } 75 75 virtual void updateLevel(); 76 virtual int timeUntilRespawn(); 77 76 78 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 77 79 … … 85 87 bool isDead; 86 88 float speed, UpwardThrust, gravity; 89 long deathTime; 87 90 struct Velocity 88 91 {
Note: See TracChangeset
for help on using the changeset viewer.