Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2018, 2:25:15 PM (6 years ago)
Author:
dreherm
Message:

Added level info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/3DPacman_FS18/src/modules/pacman/Pacman.cc

    r11979 r11984  
    2121 *
    2222 *   Author:
    23  *      Florian Zinggeler
     23 *      Marc Dreher
    2424 *   Co-authors:
    2525 *      ...
     
    3434#include "Pacman.h"
    3535#include "core/CoreIncludes.h"
    36 //Test
    3736
    3837namespace orxonox
     
    5251    void Pacman::levelUp()
    5352    {
     53        //Reset each object
    5454        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
    5555                nextsphere->resetPacmanPointSphere();
     
    6060        }
    6161
     62        //Level up ghosts
    6263        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
    6364            nextghost->levelupvelo();
    6465        }
     66        //Reset ghosts and player
    6567        this->posreset();
    6668
     69        //Increase maximum of points and level
    6770        totallevelpoint = ObjectList<PacmanPointSphere>().size() + totallevelpoint;
    6871        level++;
     
    7780        SUPER(Pacman, tick, dt);
    7881
     82        //Needed for gameover
    7983        if(deathtime != 0){
    8084            dead(dt);
    8185        }
    8286
     87        //ingame loop
    8388        else{
    8489
    85         if(afraid){
    86         timer = timer - dt;
    87             if(timer<=0){
    88                 setNormal();
    89             }
    90         }
    91 
    92 
    93         int i = 0;
    94         for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
    95             ghosts[i] = nextghost;
    96             i++;
    97         }
    98 
    99         player = this->getPlayer();
    100         if (player != nullptr)
    101         {
    102             currentPosition = player->getWorldPosition();
    103         }
    104 
    105 
    106         bcolli = false;
    107         for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){
    108             bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
    109             //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl;
    110         }
    111 
    112         if(bcolli){
    113           this->catched(dt);
    114         }
    115 
    116         i = 0;
    117         for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
    118             if(collis(nextsphere->getPosition(), currentPosition)){
    119                 takePoint(nextsphere);
    120             }
    121         }
    122 
    123         for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
    124             if(next->taken(currentPosition)){
    125                 setAfraid();
    126             }
    127         }
     90            //Register ghosts
     91            int i = 0;
     92            for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     93                ghosts[i] = nextghost;
     94                i++;
     95            }
     96
     97            //Switch ghost to not-catchable, if timer is zero
     98            if(afraid){
     99                timer = timer - dt;
     100                if(timer<=0){
     101                    setNormal();
     102                }
     103            }
     104
     105            //Get position of player
     106            player = this->getPlayer();
     107            if (player != nullptr)
     108            {
     109                currentPosition = player->getWorldPosition();
     110            }
     111
     112            //Check for collision with ghosts
     113            bcolli = false;
     114            for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){
     115                bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
     116            }
     117
     118            if(bcolli){
     119                this->catched(dt);
     120            }
     121
     122            //Check for collision with PointSpheres and PacmanPointAfraid
     123            i = 0;
     124            for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
     125                if(collis(nextsphere->getPosition(), currentPosition))
     126                 takePoint(nextsphere);
     127            }
     128
     129            for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
     130                if(next->taken(currentPosition))
     131                  setAfraid();
     132            }
    128133
    129134        }
     
    131136    }
    132137
    133 
     138    //Check for collisions between to objects (compare float numbers)
    134139    bool Pacman::collis(Vector3 one, Vector3 other){
    135140        if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10))
     
    138143    }
    139144
     145    //Decrease live or resetghost
    140146    void Pacman::catched(float dt){
    141147
    142     if(!afraid) {
    143         if(!lives){
     148    if(!this->afraid) {
     149        if(!this->lives){
    144150          deathtime = 5;
    145151          this->dead(dt); 
     
    150156    else{
    151157        for(int nrghost = 0; nrghost<8; ++nrghost){
    152         bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
    153         if(bcolli) ghosts[nrghost]->resetGhost();
    154         bcolli = false;
     158            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
     159            if(bcolli) ghosts[nrghost]->resetGhost();
     160                bcolli = false;
    155161        }
    156162      }
    157163    }
    158164
     165    //Change ghost design (to afraid)
    159166    void Pacman::setAfraid(){
    160167
     
    172179    }
    173180
     181    //Change ghost design (to not afraid)
    174182    void Pacman::setNormal(){
    175183
     
    185193    }
    186194
    187     bool Pacman::getAfraid(){
    188         return afraid;
    189     }
    190 
    191     int Pacman::getTimer(){
    192         return timer;
    193     }
    194 
    195     int Pacman::getLevel(){
    196         return level;
    197     }
    198 
     195    //Reset ghosts and plazer
    199196    void Pacman::posreset(){
    200197        for(int i = 0; i<4; ++i){
     
    204201    }
    205202
     203    //Collision with PointSphere
    206204    void Pacman::takePoint(PacmanPointSphere* taken){
    207205        ++point;
     
    210208            return;
    211209        }
     210        //Set PointSphere under map
    212211        Vector3 postaken = taken->getPosition();
    213212        postaken.y = -50;
     
    225224    }
    226225
     226    //Getter
     227    bool Pacman::getAfraid(){
     228        return afraid;
     229    }
     230    //Getter
     231    int Pacman::getTimer(){
     232        return timer;
     233    }
     234    //Getter
     235    int Pacman::getLevel(){
     236        return level;
     237    }
     238    //Getter
    227239    int Pacman::getPoints(){
    228240        return point;
    229241    }
    230 
     242    //Getter
    231243    int Pacman::getLives(){
    232244        return lives;
    233245    }
     246    //Getter
     247    bool Pacman::isdead(){
     248        return death;
     249    }
    234250
    235251
     
    238254        Deathmatch::start();
    239255
     256        //Hide afraided ghosts under map
    240257        int i = 0;
    241258        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     
    247264        }
    248265
     266        //Set maximum of points of first level
    249267        totallevelpoint = ObjectList<PacmanPointSphere>().size();
    250268
    251     }
    252 
    253     bool Pacman::isdead(){
    254         return death;
    255269    }
    256270
     
    258272        death = true;
    259273
     274        //if (Highscore::exists())
     275          //  Highscore::getInstance().storeScore("3DPacman", this->getPoints(), this->playerInfo_);
     276
    260277        deathtime = deathtime-dt;
    261278
     
    266283    void Pacman::end()
    267284    {
    268 
    269         /*
    270         if (Highscore::exists())
    271         {
    272             //int score = this->getPoints();
    273             //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
    274         }
    275         */
    276285        GSLevel::startMainMenu();
    277286    }
Note: See TracChangeset for help on using the changeset viewer.