Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 20, 2018, 12:14:40 AM (6 years ago)
Author:
landauf
Message:

merged Presentation_HS17_merge back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/superorxobros/SOBFigure.cc

    • Property svn:eol-style set to native
    r11420 r11783  
    2323 *      Julien Kindle
    2424 *   Co-authors:
     25 *      Noah Zarro
     26 *      Theo von Arx
    2527 *     
    2628 *
     
    3941#include "graphics/Camera.h"
    4042#include "graphics/ParticleSpawner.h"
     43#include <OgreMath.h>
    4144
    4245#include "SOBMushroom.h"
    4346#include "SOBGumba.h"
     47#include "SOBGumbaBoss.h"
     48#include "SOBFireball.h"
    4449#include "SOB.h"
    4550#include "SOBFlagstone.h"
    4651#include "SOBCastlestone.h"
     52#include "SOBFireball.h"
     53#include "Highscore.h"
    4754#include <BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
    4855
     
    5966
    6067        //Vars for movement of player
    61         moveUpPressed_ = false;
    62         moveDownPressed_ = false;
    63         moveLeftPressed_ = false;
    64         moveDownPressed_ = false;
    65         firePressed_ = false;
    66         collDisZ_ = 0;
     68        moveUpPressed_      = false;
     69        moveDownPressed_    = false;
     70        moveLeftPressed_    = false;
     71        moveRightPressed_    = false;
     72        firePressed_        = false;
     73        collDisZ_           = 0;
     74
    6775        //Times and turning
    68         timeSinceLastFire_ = 0.0;
    69         lastSpeed_z = 0.0;
    70         pitch_ = 0.0;
    71         timeCounter_ = 0;
     76        timeSinceLastFire_  = 0.0;
     77        lastSpeed_z         = 0.0;
     78        timeCounter_        = 0;
    7279
    7380        //Properties of player
    74         gotPowerUp_ = false;
    75         isColliding_ = true;
    76         particlespawner_ = NULL;
     81
     82        isColliding_        = true;
     83        particlespawner_    = NULL;
    7784
    7885        //Properties of players life
    79         predead_ = false;
    80         dead_ = false;
    81         lvlEnded_ = false;
     86        predead_            = false;
     87        dead_               = false;
     88        lvlEnded_           = false;
    8289        reachedLvlEndState_ = 0;
     90
     91        // Properties concerning PowerUps and items
     92        PowerUpCounter_     = 0;
     93        maxPowerUp_         = 2;
     94        FireballPower       = 2;
     95        //Properties of fireing Fireballs, NOTE! fireballs are fired with the moveUP Key, not with the fire key
     96        fireallowed_        = true;
     97        firecooldown_       = 0;
    8398
    8499       
     
    97112
    98113        //Orxocast returns object with casted type if otherObject has that class, and if not a nullptr
    99         SOBMushroom* mush = orxonox_cast<SOBMushroom*>(otherObject);
    100         SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject);
    101         SOBFlagstone* flagstone = orxonox_cast<SOBFlagstone*>(otherObject);
    102         SOBCastlestone* castlestone = orxonox_cast<SOBCastlestone*>(otherObject);
    103 
    104         //Check if otherObject is a powerup
     114        SOBMushroom*    mush        = orxonox_cast<SOBMushroom*>    (otherObject);
     115        SOBGumba*       gumba       = orxonox_cast<SOBGumba*>       (otherObject);
     116        SOBGumbaBoss*   gumbaBoss   = orxonox_cast<SOBGumbaBoss*>   (otherObject);
     117        SOBFlagstone*   flagstone   = orxonox_cast<SOBFlagstone*>   (otherObject);
     118        SOBCastlestone* castlestone = orxonox_cast<SOBCastlestone*> (otherObject);
     119        SOBFireball*    fireball    = orxonox_cast<SOBFireball*>    (otherObject);
     120        SOB* SOBGame                = orxonox_cast<SOB*>            (getGametype());
     121
     122
     123        //Check if otherObject is a powerup-mushroom
    105124        if (mush != nullptr && !(mush->hasCollided_)) {
    106125            otherObject->destroyLater();
    107             gotPowerUp_ = true;
    108             SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); //Get the Gametype
     126
     127            PowerUpCounter_++;
     128            if(PowerUpCounter_ > maxPowerUp_)   PowerUpCounter_ = maxPowerUp_; // you had already the max
     129            else                                this->changeClothes();
     130
    109131            SOBGame->addMushroom(); // Tell the gametype to increase points
    110132            mush->hasCollided_ = true; // needed because of destroyLater takes some time and player should receive points only once
     133           
     134           
     135        }
     136
     137       
    111138
    112139        //Check if otherObject is a Gumba (that walking enemies)
    113         } else if (gumba != nullptr && !(gumba->hasCollided_)) {
    114 
    115             //If player jumps on its head, kill it, else, kill the player
     140
     141         else if (gumba != nullptr && gumbaBoss == nullptr && !(gumba->hasCollided_)) {
     142
     143            //If player jumps on its head, kill the Gumba, else, kill the player
    116144            if (getVelocity().z >= -20) {
    117               Vector3 vel = getVelocity();
    118               vel.y = -80;
    119               vel.z = 200;
    120               setVelocity(vel);
    121               predead_=true;
    122               SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    123               SOBGame->setDone(true);
     145                // If player hasn't a power up, he dies. Else he shrinks and the gumba dies.
     146                if(PowerUpCounter_ == 0){
     147                    this->die();
     148                }
     149                else{
     150                    PowerUpCounter_--;
     151                    this->changeClothes();
     152
     153                    gumba->destroyLater();
     154                    gumba->hasCollided_ = true;
     155                }
    124156
    125157          } else {
    126158            gumba->destroyLater();
    127159            gumba->hasCollided_ = true;
    128             SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    129160            SOBGame->addGumba();
    130161
    131162
    132         }
    133     }
     163            }
     164        }
     165        else if (gumbaBoss != nullptr && !(gumbaBoss->hasCollided_)) {
     166            if (getVelocity().z >= -20) {
     167                // If player hasn't a power up, he dies. Else he dies directly.
     168                this->die();
     169            }
     170
     171            else {
     172                gumbaBoss->destroyLater();
     173                gumbaBoss->hasCollided_ = true;
     174                SOBGame->addGumbaBoss();
     175                }
     176        }
     177        else if (fireball != nullptr && !(fireball->hasCollided_)){
     178            if(PowerUpCounter_ == 0){
     179                    this->die();
     180                }
     181            PowerUpCounter_--;
     182            this->changeClothes();
     183            fireball->destroyLater();
     184        }
    134185
    135186    //Purpose is that if player hits the flag, he should walk into the castle at the end of the level. For that we use SOBCastlestone
     
    137188        flagstone->hasCollided_ = true;
    138189        reachedLvlEndState_ = 1;
    139         SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     190
    140191        SOBGame->setDone(true);
    141192        SOBGame->addPoints(flagstone->getPoints());
     
    159210}
    160211
     212//Function to spawn the Fireball
     213void SOBFigure::spawnFireball() {
     214        SOBCenterpoint* center_ = ((SOB*)getGametype())->center_;
     215
     216         SOBFireball* ball = new SOBFireball(center_->getContext());
     217         Vector3 spawnpos = this->getWorldPosition();
     218         spawnpos.z += 0;
     219
     220        if (ball != nullptr && center_ != nullptr)
     221        {
     222            ball->addTemplate("fireball");
     223            bool direction = ((this->getWorldOrientation().getRoll().valueRadians())>-1.6&&(this->getWorldOrientation().getRoll().valueRadians()<1.6));
     224            ball->setDirection(direction);
     225            if(direction)
     226            {
     227                spawnpos.x+=10;
     228            }
     229            else
     230            {
     231                spawnpos.x-=10;
     232            }
     233            ball->setPosition(spawnpos);
     234
     235        }
     236     }
     237
    161238//For those of you who don't have an idea: the tick function is called about 50 times/sec
    162239void SOBFigure::tick(float dt)
     
    166243
    167244    bool inputAllowed = true;
     245    //SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    168246
    169247    //the particle spawner that generates the fire from the backpack when pressed
     
    174252            particlespawner_ = object;
    175253        }
    176     }
     254
     255    }
     256   
    177257
    178258
     
    190270    //if input blocked, then cancel every movement operation
    191271    if (!inputAllowed) {
    192         moveUpPressed_ = false;
    193         moveDownPressed_ = false;
    194         moveLeftPressed_ = false;
    195         moveRightPressed_ = false;
     272        moveUpPressed_      = false;
     273        moveDownPressed_    = false;
     274        moveLeftPressed_    = false;
     275        moveRightPressed_   = false;
    196276    }
    197277
     
    204284    if (hasLocalController())
    205285    {
     286        SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    206287        Vector3 velocity = getVelocity();
    207288        Vector3 position = getPosition();
     
    212293        if (position.z < -100) {
    213294            dead_ = true;
    214             SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    215295            SOBGame->setDone(true);
    216296        }
     
    221301            velocity.z = 0;
    222302            setVelocity(velocity);
    223             SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     303           
    224304            if (firePressed_)
    225305                SOBGame->restart();
     
    242322        else
    243323            particlespawner_->setVisible(false);
    244 
     324       
    245325
    246326        //If player hits space and collides against an object under him then jump
    247         if (inputAllowed && firePressed_ && isColliding_ && (collDisZ_ >= 7.75 && collDisZ_ <+ 8.25)) {
    248             gravityAcceleration_ = 100.0;
    249             velocity.z = 110;
     327        if (inputAllowed && firePressed_ && isColliding_ && (collDisZ_ >= 0 && collDisZ_ <+ 10)) {
     328            gravityAcceleration_ = 350;
     329            velocity.z = 175;
    250330        }
    251331
     
    274354        }
    275355
     356        //If moveUp pressed, fire a fireball
     357        if(moveUpPressed_ && (PowerUpCounter_ >= FireballPower) && fireallowed_)
     358        {
     359            spawnFireball();
     360            fireallowed_  = false;
     361            firecooldown_ = 0;
     362        }
     363
     364        //Increase the firecooldown
     365        if(firecooldown_> 0.5)
     366        {
     367            fireallowed_ = true;
     368        }
     369        if(!fireallowed_)
     370        {
     371            firecooldown_ += dt;
     372        }
    276373
    277374        //Again another EndOfLevel behavior
     
    283380            velocity.x = 0;
    284381            velocity.y = 20;
     382            setOrientation(Vector3::UNIT_Z, Degree(90));
    285383        }
    286384        if (reachedLvlEndState_ == 4) {
     385            //Highscore
     386            if (Highscore::exists())
     387            {
     388                int score = SOBGame->getPoints();
     389                bool isHighScore = Highscore::getInstance().storeScore("Super Orxo Bros.", score, this->getPlayer());
     390                SOBGame->newHighscore = isHighScore;
     391            }
    287392            lvlEnded_ = true;
    288393            dead_ = true;
     
    307412        }
    308413
    309 
    310 
    311 
    312     }
    313 
    314 
     414    }
    315415
    316416    // Reset key variables
    317     moveUpPressed_ = false;
    318     moveDownPressed_ = false;
    319     moveLeftPressed_ = false;
    320     moveRightPressed_ = false;
     417    moveUpPressed_      = false;
     418    moveDownPressed_    = false;
     419    moveLeftPressed_    = false;
     420    moveRightPressed_   = false;
    321421
    322422    isColliding_ = false;
     
    364464
    365465
    366 }
     466
     467// PRE: name is an existing name of a material. Example orxo_material for orxo_material.material in data_extern/materials
     468//      !!! PowerUpCounter_ has to be modified before changing the clothes!!!
     469// POST: clothes of body of player are changed to name
     470void SOBFigure::changeClothes(){
     471            // clothes: white (basic), red (one PowerUp), orange (Fireball enabled)
     472            std::string clothes[] = {"orxo_material", "orxo_material_gross", "orxo_material_fire"};
     473
     474            std::set<WorldEntity*> attachedObjects = this->getAttachedObjects();
     475            std::set<WorldEntity*>::iterator it;
     476            for (it = attachedObjects.begin(); it != attachedObjects.end(); ++it)
     477            {
     478                Model* FiguresModel = orxonox_cast<Model*>(*it);
     479                if (FiguresModel != nullptr)
     480                {
     481                    FiguresModel->setSubMaterial(clothes[PowerUpCounter_] , 4); // 4 is the body
     482                }
     483            }   
     484}
     485// PRE:
     486// POST: Player jumps out of the game, game is finished and can be restarted.
     487void SOBFigure::die(){
     488    Vector3 vel = getVelocity();
     489    vel.y = -80;
     490    vel.z = 200;
     491    setVelocity(vel);
     492    predead_= true;
     493    SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     494    SOBGame->setDone(true);
     495}
     496
     497}
Note: See TracChangeset for help on using the changeset viewer.