[Orxonox-commit 6974] r11595 - code/branches/FlappyOrx_HS17/src/modules/flappyorx
pascscha at orxonox.net
pascscha at orxonox.net
Mon Nov 27 14:03:45 CET 2017
Author: pascscha
Date: 2017-11-27 14:03:45 +0100 (Mon, 27 Nov 2017)
New Revision: 11595
Modified:
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc
code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h
Log:
cleanup
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc 2017-11-27 13:02:42 UTC (rev 11594)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.cc 2017-11-27 13:03:45 UTC (rev 11595)
@@ -20,9 +20,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Florian Zinggeler
- * Co-authors:
- * ...
+ * Leo Mehr Holz
+ * Pascal Schärli
*
*/
@@ -59,32 +58,31 @@
FlappyOrx::FlappyOrx(Context* context) : Deathmatch(context)
{
RegisterObject(FlappyOrx);
- this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
this->center_ = nullptr;
- bEndGame = false;
- lives = 1;
- level = 0;
- point = 0;
- bShowLevel = false;
- sDeathMessage = "Welcome to FlappyOrx";
+ point = 0; //number of cleared tubes
bIsDead = true;
- this->spawnDistance=200;
- this->tubeOffsetX=500;
- this->setHUDTemplate("FlappyOrxHUD");
- firstGame = true;
+ firstGame = true; //needed for the HUD
+
+ spawnDistance=200; //distance between tubes
+ tubeOffsetX=500; //tube offset (so that we can't see them spawn)
+ setHUDTemplate("FlappyOrxHUD");
}
+
void FlappyOrx::updatePlayerPos(int x){
+ //Spawn a new Tube when the spawn distance is reached
if(this->tubes.size()==0||x-tubes.back()+tubeOffsetX>spawnDistance){
spawnTube();
this->tubes.push(x+tubeOffsetX);
}
+ //Delete Tubes when we pass through them
if(this->tubes.size()!=0&&x>this->tubes.front()){
this->tubes.pop();
levelUp();
}
- while((this->asteroids.front())->getPosition().x<x-300){
+ //Delete Asteroids which are not visible anymore
+ while((this->asteroids.front())->getPosition().x<x-tubeOffsetX){
MovableEntity* deleteMe = asteroids.front();
asteroids.pop();
deleteMe->destroy();
@@ -91,19 +89,16 @@
}
}
- void FlappyOrx::levelUp()
- {
+ //Gets called when we pass through a Tube
+ void FlappyOrx::levelUp(){
point++;
- spawnDistance = 300-3*point;
- getPlayer()->setSpeed(100+.5*point);
- toggleShowLevel();
- //showLevelTimer.setTimer(3.0f, false, createExecutor(createFunctor(&FlappyOrx::toggleShowLevel, this)));
+ spawnDistance = 300-3*point; //smaller spawn Distance
+ getPlayer()->setSpeed(100+.5*point); //increase speed
}
- FlappyOrxShip* FlappyOrx::getPlayer()
- {
- if (player == nullptr)
- {
+ //Returns our Ship
+ FlappyOrxShip* FlappyOrx::getPlayer(){
+ if (player == nullptr){
for (FlappyOrxShip* ship : ObjectList<FlappyOrxShip>()) {
player = ship;
}
@@ -111,40 +106,44 @@
return player;
}
- void FlappyOrx::spawnTube()
- {
- int space = 120;
- int height = (float(rand())/RAND_MAX-0.5)*(280-space);
-
+ //Spawn new Tube
+ void FlappyOrx::spawnTube(){
if (getPlayer() == nullptr)
return;
+ int space = 120; //vertical space between top and bottom tube
+ int height = (float(rand())/RAND_MAX-0.5)*(280-space); //Randomize height
+
Vector3 pos = player->getPosition();
- asteroidField(pos.x+tubeOffsetX,height-space/2,0.8);
- asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8);
+ //create the two Asteroid fields (Tubes)
+ asteroidField(pos.x+tubeOffsetX,height-space/2,0.8); //bottom
+ asteroidField(pos.x+tubeOffsetX,height+space/2,-0.8); //top
}
+ //Creates a new asteroid Field
void FlappyOrx::asteroidField(int x, int y, float slope){
- int r = 20;
- int noadd = 0;
+ int r = 20; //Radius of added Asteroids
+ int noadd = 0; //how many times we failed to add a new asteroid
- ClearAsteroids();
+ ClearAsteroids(); //Delete Asteroids
Circle newAsteroid = Circle();
newAsteroid.x=x;
newAsteroid.y=y;
newAsteroid.r=r;
- addIfPossible(newAsteroid);
+ addIfPossible(newAsteroid); //Add Asteroid at peak
+
+ //Fill up triangle with asteroids
while(r>0){
if(slope>0)
- newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150;
+ newAsteroid.y=float(rand())/RAND_MAX*(150+y)-150; //create asteroid on bottom
else
- newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y;
+ newAsteroid.y=float(rand())/RAND_MAX*(150-y)+y; //create asteroid on top
newAsteroid.x=x+(float(rand())/RAND_MAX-0.5)*(y-newAsteroid.y)/slope;
newAsteroid.r=r;
- int i = addIfPossible(newAsteroid);
+ int i = addIfPossible(newAsteroid); //Add Asteroid if it doesn't collide
if(i==0)
noadd++;
else if(i==2)
@@ -156,14 +155,11 @@
}
}
- void deleteAsteroid(MovableEntity* asteroid){
- //center_->getContext().getObjectList().removeElement(asteroid);
- }
-
+ //Create a new Asteroid
void FlappyOrx::createAsteroid(Circle &c){
MovableEntity* newAsteroid = new MovableEntity(this->center_->getContext());
-
+ //Add Model fitting the Size of the Asteroid
if(c.r<=5)
newAsteroid->addTemplate(Asteroid5[rand()%NUM_ASTEROIDS]);
else if(c.r<=10)
@@ -173,25 +169,21 @@
else
newAsteroid->addTemplate(Asteroid20[rand()%NUM_ASTEROIDS]);
+ //Set position
newAsteroid->setPosition(Vector3(c.x, 0, c.y));
+
+ //Randomize orientation
newAsteroid->setOrientation(Vector3::UNIT_Z, Degree(rand()%360));
newAsteroid->setOrientation(Vector3::UNIT_Y, Degree(rand()%360));
+ //add to Queue (so that we can delete it again)
asteroids.push(newAsteroid);
-
-
}
- void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center)
- {
+ void FlappyOrx::setCenterpoint(FlappyOrxCenterPoint* center){
this->center_ = center;
}
- void FlappyOrx::costLife()
- {
-
- };
-
bool FlappyOrx::isDead(){
return bIsDead;
}
@@ -200,7 +192,6 @@
bIsDead = value;
if(not value){
point = -1;
- level=-1;
levelUp();
}
}
@@ -220,30 +211,29 @@
Deathmatch::start();
}
-
+ //RIP
void FlappyOrx::death(){
bIsDead = true;
firstGame = false;
+ //Set randomized deathmessages
if(point<10) sDeathMessage = DeathMessage10[rand()%(DeathMessage10.size())];
else if(point<30) sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())];
else if(point<50) sDeathMessage = DeathMessage50[rand()%(DeathMessage50.size())];
else sDeathMessage = DeathMessageover50[rand()%(DeathMessageover50.size())];
- orxout()<<"message: "<<sDeathMessage<<std::endl;
-
-
+ //Update Highscore
if (Highscore::exists()){
int score = this->getPoints();
if(score > Highscore::getInstance().getHighestScoreOfGame("Flappy Orx"))
Highscore::getInstance().storeHighscore("Flappy Orx",score);
}
- while (!tubes.empty())
- {
+
+ //Delete all Tubes and asteroids
+ while (!tubes.empty()){
tubes.pop();
}
- while (!asteroids.empty())
- {
+ while (!asteroids.empty()){
MovableEntity* deleteMe = asteroids.front();
asteroids.pop();
deleteMe->destroy();
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h 2017-11-27 13:02:42 UTC (rev 11594)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrx.h 2017-11-27 13:03:45 UTC (rev 11595)
@@ -89,6 +89,8 @@
bool isDead();
void setDead(bool value);
+
+ FlappyOrxShip* getPlayer();
int lives;
int multiplier;
@@ -101,7 +103,7 @@
std::queue<MovableEntity*> asteroids;
int spawnDistance;
int tubeOffsetX;
-
+
private:
void toggleShowLevel(){bShowLevel = !bShowLevel;}
@@ -143,7 +145,6 @@
- FlappyOrxShip* getPlayer();
WeakPtr<FlappyOrxCenterPoint> center_;
WeakPtr<FlappyOrxShip> player;
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc 2017-11-27 13:02:42 UTC (rev 11594)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxHUDinfo.cc 2017-11-27 13:03:45 UTC (rev 11595)
@@ -103,7 +103,11 @@
" Local High Score: "+multi_cast<std::string>(Highscore::getInstance().getHighestScoreOfGame("Flappy Orx"));
break;
case 3:
- message = "Press space to restart.";
+ int time = this->FlappyOrxGame->getPlayer()->timeUntilRespawn();
+ if(time<=0)
+ message = "Press space to restart.";
+ else
+ message = "Please wait "+multi_cast<std::string>(time)+" seconds.";
break;
}
this->setCaption(message);
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc 2017-11-27 13:02:42 UTC (rev 11594)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.cc 2017-11-27 13:03:45 UTC (rev 11595)
@@ -39,6 +39,7 @@
#include "graphics/Camera.h"
#include "weapons/projectiles/Projectile.h"
#include <math.h>
+#include <ctime>
namespace orxonox
{
@@ -52,6 +53,7 @@
this->speed = 1;
this->gravity = 1;
isDead = true;
+ deathTime = 0;
}
@@ -127,8 +129,14 @@
void FlappyOrxShip::moveRightLeft(const Vector2& value){}
+ int FlappyOrxShip::timeUntilRespawn(){
+ return 2-time(0)+deathTime;
+ }
+
void FlappyOrxShip::boost(bool boost){
- if(isDead){
+
+
+ if(isDead&&timeUntilRespawn()<=0){
isDead = false;
getGame()->setDead(false);
}
@@ -155,6 +163,10 @@
void FlappyOrxShip::death()
{
isDead = true;
+
+ deathTime = time(0);
+
+ orxout()<<"death time: "<<deathTime<<std::endl;
Vector3 pos = getPosition();
pos.x = 0;
pos.z = 0;
Modified: code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h
===================================================================
--- code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h 2017-11-27 13:02:42 UTC (rev 11594)
+++ code/branches/FlappyOrx_HS17/src/modules/flappyorx/FlappyOrxShip.h 2017-11-27 13:03:45 UTC (rev 11595)
@@ -73,6 +73,8 @@
inline float getUpwardThrust()
{ return this->UpwardThrust; }
virtual void updateLevel();
+ virtual int timeUntilRespawn();
+
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
protected:
@@ -84,6 +86,7 @@
bool isFlapping;
bool isDead;
float speed, UpwardThrust, gravity;
+ long deathTime;
struct Velocity
{
float x;
More information about the Orxonox-commit
mailing list