[Orxonox-commit 6957] r11578 - code/branches/SOBv2_HS17/src/modules/superorxobros

varxth at orxonox.net varxth at orxonox.net
Mon Nov 20 16:06:44 CET 2017


Author: varxth
Date: 2017-11-20 16:06:43 +0100 (Mon, 20 Nov 2017)
New Revision: 11578

Modified:
   code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.cc
   code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.h
Log:
abgleich

Modified: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.cc
===================================================================
--- code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.cc	2017-11-20 15:05:27 UTC (rev 11577)
+++ code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.cc	2017-11-20 15:06:43 UTC (rev 11578)
@@ -61,33 +61,37 @@
         gravityAcceleration_ = 350.0;
 
         //Vars for movement of player
-        moveUpPressed_ = false;
-        moveDownPressed_ = false;
-        moveLeftPressed_ = false;
-        moveDownPressed_ = false;
-        firePressed_ = false;
-        collDisZ_ = 0;
+        moveUpPressed_      = false;
+        moveDownPressed_    = false;
+        moveLeftPressed_    = false;
+        moveDownPressed_    = false;
+        firePressed_        = false;
+        collDisZ_           = 0;
 
         //Times and turning
-        timeSinceLastFire_ = 0.0;
-        lastSpeed_z = 0.0;
-        pitch_ = 0.0;
-        timeCounter_ = 0;
+        timeSinceLastFire_  = 0.0;
+        lastSpeed_z         = 0.0;
+        pitch_              = 0.0;
+        timeCounter_        = 0;
 
         //Properties of player
-        gotPowerUp_ = false;
-        isColliding_ = true;
-        particlespawner_ = NULL;
 
+        isColliding_        = true;
+        particlespawner_    = NULL;
+
         //Properties of players life
-        predead_ = false;
-        dead_ = false;
-        lvlEnded_ = false;
+        predead_            = false;
+        dead_               = false;
+        lvlEnded_           = false;
         reachedLvlEndState_ = 0;
 
+        // Properties concerning PowerUps and items
+        PowerUpCounter_     = 0;
+        maxPowerUp_         = 2;
+        FireballPower       = 2;
         //Properties of fireing Fireballs, NOTE! fireballs are fired with the moveUP Key, not with the fire key
-        fireallowed_=true;
-        firecooldown_=0;
+        fireallowed_        = true;
+        firecooldown_       = 0;
 
         
         setAngularFactor(0.0); //Means player doesn't turn on collision, so he doesn't fall over while walking over the ground
@@ -109,19 +113,22 @@
         SOBFlagstone*   flagstone   = orxonox_cast<SOBFlagstone*>   (otherObject);
         SOBCastlestone* castlestone = orxonox_cast<SOBCastlestone*> (otherObject);
         SOBFireball* fireball       = orxonox_cast<SOBFireball*>    (otherObject);
+        SOB* SOBGame                = orxonox_cast<SOB*>            (getGametype()); 
 
-        //Check if otherObject is a powerup
+
+        //Check if otherObject is a powerup-mushroom
         if (mush != nullptr && !(mush->hasCollided_)) {
             otherObject->destroyLater();
-            gotPowerUp_ = true;
-            SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); //Get the Gametype
+
+            PowerUpCounter_++;
+            if(PowerUpCounter_ > maxPowerUp_)   PowerUpCounter_ = maxPowerUp_; // you had already the max
+            else                                this->changeClothes();
+
             SOBGame->addMushroom(); // Tell the gametype to increase points
             mush->hasCollided_ = true; // needed because of destroyLater takes some time and player should receive points only once
 
-            // now, change the clothes of the Figure to red
-            std::string name = "orxo_material_gross";
-            this->changeClothes(name);
             
+            
         }
         
 
@@ -132,15 +139,13 @@
             //If player jumps on its head, kill the Gumba, else, kill the player
             if (getVelocity().z >= -20) {
                 // If player hasn't a power up, he dies. Else he shrinks and the gumba dies.
-                if(!gotPowerUp_){
+                if(PowerUpCounter_ == 0){
                     this->die();
-                } else{
-                    gotPowerUp_ = false;
-                    
-                   
-           // now, change the clothes of the Figure to old ones
-            std::string name = "orxo_material";
-            this->changeClothes(name);
+                } 
+                else{
+                    PowerUpCounter_--;
+                    this->changeClothes();
+
                     gumba->destroyLater();
                     gumba->hasCollided_ = true;
                 }
@@ -148,7 +153,6 @@
           } else {
             gumba->destroyLater();
             gumba->hasCollided_ = true;
-            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
             SOBGame->addGumba();
 
 
@@ -163,7 +167,7 @@
     if (reachedLvlEndState_ == 0 && flagstone != nullptr && !(flagstone->hasCollided_)) {
         flagstone->hasCollided_ = true;
         reachedLvlEndState_ = 1;
-        SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
+
         SOBGame->setDone(true);
         SOBGame->addPoints(flagstone->getPoints());
         
@@ -236,10 +240,10 @@
 
     //if input blocked, then cancel every movement operation
     if (!inputAllowed) {
-        moveUpPressed_ = false;
-        moveDownPressed_ = false;
-        moveLeftPressed_ = false;
-        moveRightPressed_ = false;
+        moveUpPressed_      = false;
+        moveDownPressed_    = false;
+        moveLeftPressed_    = false;
+        moveRightPressed_   = false;
     }
 
     //set the gravityto standard 350
@@ -250,6 +254,7 @@
 
     if (hasLocalController())
     {
+        SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
         Vector3 velocity = getVelocity();
         Vector3 position = getPosition();
 
@@ -258,7 +263,6 @@
         //If player falls in a hole
         if (position.z < -100) {
             dead_ = true;
-            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
             SOBGame->setDone(true);
         }
 
@@ -267,7 +271,7 @@
             velocity.x = 0;
             velocity.z = 0;
             setVelocity(velocity);
-            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
+           
             if (firePressed_)
                 SOBGame->restart();
             return;
@@ -321,21 +325,21 @@
         }
 
         //If moveUp pressed, fire a fireball
-        if(moveUpPressed_ && gotPowerUp_ && fireallowed_)
+        if(moveUpPressed_ && (PowerUpCounter_ >= FireballPower) && fireallowed_)
         {
             spawnFireball();
-            fireallowed_=false;
-            firecooldown_=0;
+            fireallowed_  = false;
+            firecooldown_ = 0;
         }
 
         //Increase the firecooldown
-        if(firecooldown_>0.5)
+        if(firecooldown_> 0.5)
         {
-            fireallowed_=true;
+            fireallowed_ = true;
         }
         if(!fireallowed_)
         {
-            firecooldown_+=dt;
+            firecooldown_ += dt;
         }
 
         //Again another EndOfLevel behavior
@@ -370,18 +374,13 @@
             cam->setPosition(campos);
         }
 
-
-
-
     }
 
-
-
     // Reset key variables
-    moveUpPressed_ = false;
-    moveDownPressed_ = false;
-    moveLeftPressed_ = false;
-    moveRightPressed_ = false;
+    moveUpPressed_      = false;
+    moveDownPressed_    = false;
+    moveLeftPressed_    = false;
+    moveRightPressed_   = false;
 
     isColliding_ = false;
     collDisZ_ = 0;
@@ -429,8 +428,12 @@
 
 
 // PRE: name is an existing name of a material. Example orxo_material for orxo_material.material in data_extern/materials
+//      !!! PowerUpCounter_ has to be modified before changing the clothes!!!
 // POST: clothes of body of player are changed to name
-void SOBFigure::changeClothes(std::string& name){
+void SOBFigure::changeClothes(){
+            // clothes: white (basic), red (one PowerUp), orange (Fireball enabled)
+            std::string clothes[] = {"orxo_material", "orxo_material_gross", "orxo_material_fire"};
+
             std::set<WorldEntity*> attachedObjects = this->getAttachedObjects();
             std::set<WorldEntity*>::iterator it;
             for (it = attachedObjects.begin(); it != attachedObjects.end(); ++it)
@@ -438,19 +441,18 @@
                 Model* FiguresModel = orxonox_cast<Model*>(*it);
                 if (FiguresModel != nullptr)
                 {
-
-                    FiguresModel->setSubMaterial(name, 4); // 4 is the body
-
+                    FiguresModel->setSubMaterial(clothes[PowerUpCounter_] , 4); // 4 is the body
                 }
             }   
 }
-
+// PRE:
+// POST: Player jumps out of the game, game is finished and can be restarted.
 void SOBFigure::die(){
     Vector3 vel = getVelocity();
     vel.y = -80;
     vel.z = 200;
     setVelocity(vel);
-    predead_=true; 
+    predead_= true; 
     SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     SOBGame->setDone(true);
 }

Modified: code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.h
===================================================================
--- code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.h	2017-11-20 15:05:27 UTC (rev 11577)
+++ code/branches/SOBv2_HS17/src/modules/superorxobros/SOBFigure.h	2017-11-20 15:06:43 UTC (rev 11578)
@@ -45,7 +45,7 @@
             virtual void moveRightLeft(const Vector2& value) override; //!< Overloaded the function to steer the figure up and down.
             virtual void boost(bool boost) override;
             virtual  bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
-            void changeClothes(std::string& name);
+            void changeClothes();
             void spawnFireball();
             void die();
 
@@ -57,7 +57,7 @@
 
             //Soooo many declarations
             bool fireallowed_;
-            bool gotPowerUp_;
+
             bool moveUpPressed_;
             bool moveDownPressed_;
             bool moveLeftPressed_;
@@ -71,6 +71,9 @@
             float pitch_;
             bool isColliding_;
             WorldEntity* particlespawner_;
+            int PowerUpCounter_;
+            int maxPowerUp_;
+            int FireballPower;
             int sgn(float x);
             int reachedLvlEndState_;
             float timeCounter_;



More information about the Orxonox-commit mailing list