Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 12, 2018, 4:12:25 PM (7 years ago)
Author:
dreherm
Message:

Moving ghosts

File:
1 edited

Legend:

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

    r11844 r11859  
    3434#include "3DPacman.h"
    3535#include "core/CoreIncludes.h"
     36#include "PacmanGelb.h"
     37#include "PacmanGhost.h"
     38#include "PacmanPointSphere.h"
    3639
    3740namespace orxonox
     
    4346        RegisterObject(3DPacman);
    4447
    45         bEndGame = false;
    46         lives = 1;
     48        lives = 3;
     49        point = 0:
    4750        level = 1;
    48         point = 0;
    49         bShowLevel = false;
    50         multiplier = 1;
    51         b_combo = false;
    52         counter = 5000;
    53         pattern = 1;
    54         lastPosition = 0;
    55         // spawn enemy every 3.5 seconds
    56         //enemySpawnTimer.setTimer(3.5f, true, createExecutor(createFunctor(&DodgeRace::spawnEnemy, this)));
    57         comboTimer.setTimer(3.0f, true, createExecutor(createFunctor(&DodgeRace::comboControll, this)));
    58         this->numberOfBots_ = 0; //sets number of default bots temporarly to 0
    59         this->center_ = nullptr;
    6051
    61         this->setHUDTemplate("DodgeRaceHUD");
    6252    }
    6353
    64     void DodgeRace::levelUp()
     54    void 3DPacman::levelUp()
    6555    {
    66         level++;
    67         if (getPlayer() != nullptr)
    68         {
    69             for (int i = 0; i < 7; i++)
    70             {
    71                 WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext());
    72                 chunk5->setPosition(Vector3(600, 0, 100.f * i - 300));
    73                 chunk5->setVelocity(Vector3(1000, 0, 0));  //player->getVelocity()
    74                 chunk5->setScale(10);
    75                 chunk5->setEffect1("Orxonox/explosion2b");
    76                 chunk5->setEffect2("Orxonox/smoke6");
    77                 chunk5->Explode();
    78 
    79             }
    80         }
    81         addPoints(multiplier * 42);
    82         multiplier *= 2;
    83         toggleShowLevel();
    84         showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&DodgeRace::toggleShowLevel, this)));
     56        this->end();
    8557    }
    8658
    87     void DodgeRace::tick(float dt)
     59
     60    PacmanGhost[4] ghosts;
     61    PacmanPointSphere[1] spheres;
     62
     63
     64    void 3DPacman::tick(float dt)
    8865    {
    89         DodgeRaceShip* player = this->getPlayer();
     66        int i = 0;
     67        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     68            ghosts[i] = nextghost;
     69            i++;
     70        }
     71
     72        i = 0:
     73        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
     74            spheres[i] = nextsphere;
     75            i++;
     76        }
     77
     78        player = this->getPlayer();
    9079        if (player != nullptr)
    9180        {
    92             currentPosition = player->getWorldPosition().x;
    93             counter = counter + (currentPosition - lastPosition);
    94             lastPosition = currentPosition;
    95             point = (int) currentPosition;
    96             player->speed = 830.0f - (point / 1000);
     81            currentPosition = player->getWorldPosition();
     82        }
    9783
    98             for(unsigned int i=0; i < cubeList.size();i++)
    99             {
    100                 if(cubeList.at(i)->getPosition().x < currentPosition-3000)
    101                 {
    102                     cubeList.at(i)->destroy();
    103                     cubeList.erase(cubeList.begin()+i);
    104                 }
    105             }
     84        bool bcolli = false;
     85        for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){
     86            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition)
     87        }
     88        if(collis){
     89            this->catched();
     90        }
    10691
    107             if(counter >= 3000)
    108             {
    109                 counter = 0;
    110                 for(int i = 0; i<6; i++)
    111                 {
    112                     DodgeRaceCube* cube = new DodgeRaceCube(this->center_->getContext());
    113                     cubeList.push_back(cube);
    114                     switch(pattern)
    115                     {
    116                     case 1: cube->addTemplate("DodgeRaceCube01");
    117                     break;
    118                     case 2: cube->addTemplate("DodgeRaceCube02");
    119                     break;
     92        SUPER(3DPacman, tick, dt);
    12093
    121                     }
    122 
    123                     cube->setPosition(player->getWorldPosition() + Vector3(5000.0f, 0.0f, -3600.0f + (i*1200)));
    124                     //stEntity->setScale3D(50,50,50);
    125                 }
     94    }
    12695
    12796
    128                 pattern %= 2;
    129                 pattern ++;
    13097
    131             }
    132 
    133         }
    134         SUPER(DodgeRace, tick, dt);
     98    bool 3DPacman::collis(Vector3 one, Vector3 other){
     99        if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1))
     100            return true;
     101        return false;
    135102    }
    136103
    137     DodgeRaceShip* DodgeRace::getPlayer()
     104    void 3DPacman::catched(){
     105        if(lives) this->end();
     106        --lives;
     107        this->posreset();
     108    }
     109
     110    void 3DPacman::posreset(){
     111        int i = 0;
     112        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
     113            ghosts[i] = nextghost;
     114            i++;
     115        }
     116       
     117    }
     118
     119
     120    PacmanGelb* 3DPacman::getPlayer()
    138121    {
    139         for (DodgeRaceShip* ship : ObjectList<DodgeRaceShip>())
     122        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
    140123        {
    141124            return ship;
     
    144127    }
    145128
    146     void DodgeRace::costLife()
    147     {
    148         //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&DodgeRace::end, this)));
    149         lives = 0;
    150     };
    151129
    152     void DodgeRace::comboControll()
    153     {
    154         if (b_combo)
    155             multiplier++;
    156         // if no combo was performed before, reset multiplier
    157         else
    158             multiplier = 1;
    159         b_combo = false;
    160     }
    161 
    162     void DodgeRace::start()
     130    void 3DPacman::start()
    163131    {
    164132        orxout() << "start" << endl;
    165         for(unsigned int i=0; i< cubeList.size();i++)
    166         {
    167             cubeList.at(i)->destroy();
    168             cubeList.erase(cubeList.begin()+i);
    169 
    170         }
    171         cubeList.clear();
    172         // Set variable to temporarily force the player to spawn.
    173         this->bForceSpawn_ = false;
    174 
    175         if (this->center_ == nullptr)  // abandon mission!
    176         {
    177             orxout(internal_error) << "DodgeRace: No Centerpoint specified." << endl;
    178             GSLevel::startMainMenu();
    179             return;
    180         }
    181         // Call start for the parent class.
     133       
    182134        Deathmatch::start();
    183135    }
    184136
    185     void DodgeRace::playerPreSpawn(PlayerInfo* player)
     137    void 3DPacman::playerPreSpawn(PlayerInfo* player)
    186138    {
    187139        this->playerInfo_ = player;
     
    190142            this->end();
    191143        }
    192 
    193         // Reset all the cubes
    194         /*
    195         orxout() << "prespawn" << endl;
    196         for(int i=0; i< cubeList.size();i++)
    197         {
    198             cubeList.at(i)->destroy();
    199             cubeList.erase(cubeList.begin()+i);
    200         }
    201         cubeList.clear();
    202         lives = 1;
    203         point = 0;
    204         lastPosition = 0;
    205         */
    206144    }
    207145
    208     void DodgeRace::addPoints(int numPoints)
    209     {
    210         if (!bEndGame)
    211         {
    212             point += numPoints * multiplier;
    213             b_combo = true;
    214         }
    215     }
    216146
    217     void DodgeRace::end()
     147    void 3DPacman::end()
    218148    {
    219149        // DON'T CALL THIS!
     
    224154        {
    225155            int score = this->getPoints();
    226             Highscore::getInstance().storeScore("Dodge Race", score, this->playerInfo_);
     156            Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
    227157        }
    228158        GSLevel::startMainMenu();
Note: See TracChangeset for help on using the changeset viewer.