Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 11, 2017, 3:18:27 PM (8 years ago)
Author:
jkindle
Message:

Added the animation for the level end (walk into castle), Coins for the blocks, Castleblocks and Flagblocks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/SuperOrxoBros_FS17/src/modules/superorxobros/SOBFigure.cc

    r11412 r11416  
    2121 *
    2222 *   Author:
    23  *      Fabien Vultier
     23 *      Julien Kindle
    2424 *   Co-authors:
    25  *      ...
     25 *     
    2626 *
    2727 */
     
    4444#include "SOB.h"
    4545#include "SOBFlagstone.h"
     46#include "SOBCastlestone.h"
    4647
    4748namespace orxonox
     
    5455
    5556        // initialize variables
    56 
     57        gravityAcceleration_ = 350.0;
     58
     59        //Vars for movement of player
    5760        moveUpPressed_ = false;
    5861        moveDownPressed_ = false;
     
    6063        moveDownPressed_ = false;
    6164        firePressed_ = false;
     65       
     66        //Times and turning
    6267        timeSinceLastFire_ = 0.0;
    6368        lastSpeed_z = 0.0;
     69        pitch_ = 0.0;
     70        timeCounter_ = 0;
     71
     72        //Properties of player
     73        gotPowerUp_ = false;
    6474        isColliding_ = true;
    6575        particlespawner_ = NULL;
    6676
    67         gravityAcceleration_ = 350.0;
    68         pitch_ = 0.0;
    69 
     77        //Properties of players life
    7078        predead_ = false;
    7179        dead_ = false;
    72         gotPowerUp_ = false;
     80        lvlEnded_ = false;
     81        reachedLvlEndState_ = 0;
     82
    7383       
    74         setAngularFactor(0.0);
    75         this->enableCollisionCallback();
     84        setAngularFactor(0.0); //Means player doesn't turn on collision, so he doesn't fall over while walking over the ground
     85        this->enableCollisionCallback(); // Turns on that on every collision function collidesAgainst is executed
    7686    }
    7787
     
    8191
    8292        isColliding_ = true;
     93
     94        //Orxocast returns object with casted type if otherObject has that class, and if not a nullptr
    8395        SOBMushroom* mush = orxonox_cast<SOBMushroom*>(otherObject);
    8496        SOBGumba* gumba = orxonox_cast<SOBGumba*>(otherObject);
    8597        SOBFlagstone* flagstone = orxonox_cast<SOBFlagstone*>(otherObject);
    86 
     98        SOBCastlestone* castlestone = orxonox_cast<SOBCastlestone*>(otherObject);
     99
     100        //Check if otherObject is a powerup
    87101        if (mush != nullptr && !(mush->hasCollided_)) {
    88102            otherObject->destroyLater();
    89103            gotPowerUp_ = true;
    90             SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    91             SOBGame->addMushroom();
    92             mush->hasCollided_ = true;
    93 
     104            SOB* SOBGame = orxonox_cast<SOB*>(getGametype()); //Get the Gametype
     105            SOBGame->addMushroom(); // Tell the gametype to increase points
     106            mush->hasCollided_ = true; // needed because of destroyLater takes some time and player should receive points only once
     107
     108        //Check if otherObject is a Gumba (that walking enemies)
    94109        } else if (gumba != nullptr && !(gumba->hasCollided_)) {
    95110
     111            //If player jumps on its head, kill it, else, kill the player
    96112            if (getVelocity().z >= -20) {
    97113              Vector3 vel = getVelocity();
     
    100116              setVelocity(vel);
    101117              predead_=true;
     118
    102119          } else {
    103120            gumba->destroyLater();
     
    110127    }
    111128
    112      if (flagstone != nullptr && !(flagstone->hasCollided_)) {
    113             flagstone->hasCollided_ = true;
    114 
    115      }
     129    //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
     130    if (reachedLvlEndState_ == 0 && flagstone != nullptr && !(flagstone->hasCollided_)) {
     131        flagstone->hasCollided_ = true;
     132        reachedLvlEndState_ = 1;
     133        SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     134        SOBGame->addPoints(flagstone->getPoints());
     135
     136    }
     137    if (castlestone != nullptr && !(castlestone->hasCollided_)) {
     138        castlestone->hasCollided_ = true;
     139        reachedLvlEndState_++;
     140
     141    }
    116142
    117143    return true;
     
    119145
    120146
    121 
    122 void SOBFigure::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    123 {
    124     SUPER(SOBFigure, XMLPort, xmlelement, mode);
    125 
    126 }
    127 
    128 
     147//Self implemented sign function that returns either 1 or -1 (and never 0)
    129148int SOBFigure::sgn(float x) {
    130 
    131149    if (x < 0.0) return -1;
    132150    return 1;
    133151}
    134152
     153//For those of you who don't have an idea: the tick function is called about 50 times/sec
    135154void SOBFigure::tick(float dt)
    136155{
    137156    SUPER(SOBFigure, tick, dt);
    138157
     158
     159    bool inputAllowed = true;
     160
     161    //the particle spawner that generates the fire from the backpack when pressed
    139162    if (particlespawner_ == NULL) {
    140163        for (WorldEntity* object : this->getAttachedObjects())
    141164        {
    142          if (object->isA(Class(ParticleSpawner)))
     165           if (object->isA(Class(ParticleSpawner)))
    143166            particlespawner_ = object;
    144 
    145     }
    146 
    147 }
    148 
    149 
    150 
    151 
    152 
    153 
    154 if (firePressed_ == false) {
    155  gravityAcceleration_ = 350.0;
    156 
    157 }
    158 
    159 if (hasLocalController())
    160 {
    161   Vector3 velocity = getVelocity();
    162   Vector3 position = getPosition();
    163 
    164   if (!predead_)
    165     velocity.y = 0;
    166 if (position.z < -100) {
    167     dead_ = true;
    168 
    169 }
    170 
    171 if (dead_) {
    172     velocity.x = 0;
    173     velocity.z = 0;
    174     setVelocity(velocity);
    175     SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
    176     if (firePressed_)
    177         SOBGame->restart();
    178     return;
    179 }
    180 
    181 
    182 int maxvelocity_x = 100;
    183 int speedAddedPerTick = 5;
    184 int camMaxOffset = 25;
    185 
    186 timeSinceLastFire_ += dt;
    187 lastSpeed_z = velocity.z;
     167        }
     168    }
     169
     170
     171    //Behavior on level end - this is like described above for the movement from the player when hit the flag. He moves then into the castle
     172    if (reachedLvlEndState_ != 0) {
     173        timeCounter_+= dt;
     174        inputAllowed = false;
     175    }
     176    if (reachedLvlEndState_ == 1 && timeCounter_ >= 1.5) {
     177        timeCounter_ = 0;
     178        reachedLvlEndState_ = 2;
     179    }
     180
     181
     182    //if input blocked, then cancel every movement operation
     183    if (!inputAllowed) {
     184        moveUpPressed_ = false;
     185        moveDownPressed_ = false;
     186        moveLeftPressed_ = false;
     187        moveRightPressed_ = false;
     188    }
     189
     190    //set the gravityto standard 350
     191    if (firePressed_ == false) {
     192        gravityAcceleration_ = 350.0;
     193
     194    }
     195
     196    if (hasLocalController())
     197    {
     198        Vector3 velocity = getVelocity();
     199        Vector3 position = getPosition();
     200
     201        if (!predead_)
     202            velocity.y = 0;
     203        if (position.z < -100) {
     204            dead_ = true;
     205        }
     206
     207
     208        if (dead_) {
     209            velocity.x = 0;
     210            velocity.z = 0;
     211            setVelocity(velocity);
     212            SOB* SOBGame = orxonox_cast<SOB*>(getGametype());
     213            if (firePressed_)
     214                SOBGame->restart();
     215            return;
     216        }
     217
     218
     219        int maxvelocity_x = 100;
     220        int speedAddedPerTick = 5;
     221        int camMaxOffset = 25;
     222
     223        timeSinceLastFire_ += dt;
     224        lastSpeed_z = velocity.z;
    188225
    189226
    190227
    191228        //Handle the rocket fire from the jetpack
    192 if (velocity.z > 40)
    193     particlespawner_->setVisible(true);
    194 else
    195     particlespawner_->setVisible(false);
     229        if (velocity.z > 40)
     230            particlespawner_->setVisible(true);
     231        else
     232            particlespawner_->setVisible(false);
     233
    196234
    197235        //If player hits space and does not move in z-dir
    198 if (firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) {
    199     gravityAcceleration_ = 100.0;
     236        if (inputAllowed && firePressed_ && isColliding_ && std::abs(velocity.z) < 0.1 && std::abs(lastSpeed_z) < 0.1) {
     237            gravityAcceleration_ = 100.0;
    200238            velocity.z = 110; //150
    201239        }
    202 
    203       // rotate(1,getOrientation()* WorldEntity::FRONT)
    204240
    205241
    206242        //Left-right movement with acceleration
    207243        float rot = getOrientation().getRoll().valueDegrees();
    208         orxout() << rot << endl;
    209244        if (moveRightPressed_) {
    210245            if (!(rot < 5.0 && -5.0 < rot))
    211246                setOrientation(Vector3::UNIT_Z, getOrientation().getRoll() - sgn(rot)*dt*Radian(6));
    212 
    213247
    214248            if (std::abs(velocity.x) < maxvelocity_x) {
     
    230264
    231265
     266        //Again another EndOfLevel behavior
     267        if (reachedLvlEndState_ == 1)
     268            velocity.x = -2;
     269        if (reachedLvlEndState_ == 2)
     270            velocity.x = 30;
     271        if (reachedLvlEndState_ == 3) {
     272            velocity.x = 0;
     273            velocity.y = 20;
     274        }
     275        if (reachedLvlEndState_ == 4) {
     276            lvlEnded_ = true;
     277            dead_ = true;
     278        }
     279
     280        //velocity = acc. * time
    232281        velocity.z -= gravityAcceleration_*dt;
    233282        setVelocity(velocity);
    234283
    235284
    236         //Camera operation
     285        //Camera operation - the camera should always follow the player in a specific region
    237286        Camera* cam = getCamera();
    238287        Vector3 campos = cam->getPosition();
     
    252301    }
    253302
    254         // Move through the left and right screen boundaries
    255 
    256         //setPosition(position);
    257 
    258         // Reset key variables
     303
     304
     305    // Reset key variables
    259306    moveUpPressed_ = false;
    260307    moveDownPressed_ = false;
    261308    moveLeftPressed_ = false;
    262309    moveRightPressed_ = false;
    263     moveDownPressed_ = false;
     310
    264311    isColliding_ = false;
    265312
     
    270317
    271318
    272 
     319//The following functions read the input of the player and then set the bools for the movement
    273320void SOBFigure::moveFrontBack(const Vector2& value)
    274321{
     
    299346}
    300347
    301 
    302 
    303 
    304 
    305348void SOBFigure::boost(bool boost)
    306349{
    307350    firePressed_ = boost;
    308351}
    309 }
     352
     353
     354}
Note: See TracChangeset for help on using the changeset viewer.