Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS19/src/modules/pacman/Pacman.cc @ 12365

Last change on this file since 12365 was 12365, checked in by rueegseb, 5 years ago

Laser boom boom

  • Property svn:executable set to *
File size: 7.3 KB
RevLine 
[11898]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[11984]23 *      Marc Dreher
[11898]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30    @file 3DPacman.cc
31    @brief Implementation of the 3DPacman class.
32*/
33
34#include "Pacman.h"
35#include "core/CoreIncludes.h"
36
37namespace orxonox
38{
[11915]39    RegisterClass(Pacman);
[11898]40
[12313]41    int PACMAN_INTERNAL_PACMAN_POSITION;
42
[11898]43    Pacman::Pacman(Context* context) : Deathmatch(context)
44    {
45        RegisterObject(Pacman);
46
[11978]47        lives = 3;
[11898]48        point = 0;
49        level = 1;
50
51    }
52
53    void Pacman::levelUp()
54    {
[11984]55        //Reset each object
[11958]56        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
57                nextsphere->resetPacmanPointSphere();
58        }
59
60        for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
61            next->resetPacmanPointAfraid();
62        }
63
[11984]64        //Level up ghosts
[11958]65        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
66            nextghost->levelupvelo(); 
67        }
[11984]68        //Reset ghosts and player
[11958]69        this->posreset();
[11979]70
[11984]71        //Increase maximum of points and level
[11979]72        totallevelpoint = ObjectList<PacmanPointSphere>().size() + totallevelpoint;
73        level++;
[11898]74    }
75
76
[12316]77    PacmanGhost* ghosts[8];
[11898]78
79
80    void Pacman::tick(float dt)
81    {
[12316]82
[11915]83        SUPER(Pacman, tick, dt);
84
[12316]85
[11984]86        //Needed for gameover
[11976]87        if(deathtime != 0){
88            dead(dt);
[12365]89
90            if(point > 230){
91             
92                for(PacmanPointSphere* pointer : ObjectList<PacmanPointSphere>()){
93                     pointSpherePosition = pointer->getPosition();
94
95                     if(pointSpherePosition.y > 0){
96                        PacmanLaser* pos = ObjectList<PacmanLaser>(); //to do
97                        pos->setPosition(pointSpherePosition);
98                        break;
99                    }
100
101
102                }
103
104            }
105         
[11976]106        }
[11954]107
[11984]108        //ingame loop
[11976]109        else{
[11954]110
[11984]111            //Register ghosts
112            int i = 0;
[12365]113            for(PacmanGhost* nextghost: ObjectList<PacmanGhost>()){
[11984]114                ghosts[i] = nextghost;
115                i++;
[11939]116            }
[11984]117            //Switch ghost to not-catchable, if timer is zero
118            if(afraid){
119                timer = timer - dt;
120                if(timer<=0){
121                    setNormal();
122                }
123            }
[11976]124
[11984]125            //Get position of player
126            player = this->getPlayer();
127            if (player != nullptr)
128            {
129                currentPosition = player->getWorldPosition();
130            }
[11898]131
[11984]132            //Check for collision with ghosts
133            bcolli = false;
134            for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){
135                bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
136            }
[11898]137
[11984]138            if(bcolli){
139                this->catched(dt);
140            }
[11915]141
[11984]142            //Check for collision with PointSpheres and PacmanPointAfraid
143            for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
[12003]144                 if(nextsphere->taken(currentPosition))
145                    takePoint(nextsphere);
[11898]146            }
147
[11984]148            for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
149                if(next->taken(currentPosition))
150                  setAfraid();
[11933]151            }
152
[11979]153        } 
[11976]154
[11898]155    }
156
[11984]157    //Check for collisions between to objects (compare float numbers)
[11898]158    bool Pacman::collis(Vector3 one, Vector3 other){
[12338]159        if((abs(one.x-other.x)<19) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<19))
[11898]160            return true;
161        return false;
162    }
163
[11984]164    //Decrease live or resetghost
[11976]165    void Pacman::catched(float dt){
[11933]166
[11984]167    if(!this->afraid) {
168        if(!this->lives){
[11976]169          deathtime = 5;
170          this->dead(dt); 
171        }
[11898]172        --lives;
173        this->posreset();
[11933]174        }
175    else{
[11945]176        for(int nrghost = 0; nrghost<8; ++nrghost){
[11984]177            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
178            if(bcolli) ghosts[nrghost]->resetGhost();
179                bcolli = false;
[11933]180        }
181      }
182    }
183
[11984]184    //Change ghost design (to afraid)
[11944]185    void Pacman::setAfraid(){
[11945]186
[11944]187        timer = 10; //Set timer to 10 seconds
[11945]188
189        //Change normal Ghosts with afraid ones
190        if(!afraid){
191            ghosts[0]->changewith(ghosts[4]);
192            ghosts[1]->changewith(ghosts[5]);
193            ghosts[2]->changewith(ghosts[6]);
194            ghosts[3]->changewith(ghosts[7]);
195        }
196
197        afraid = true; 
[11898]198    } 
199
[11984]200    //Change ghost design (to not afraid)
[11945]201    void Pacman::setNormal(){
202
203        timer = 0;
204
205        //Change normal Ghosts with afraid ones
206            ghosts[4]->changewith(ghosts[0]);
207            ghosts[5]->changewith(ghosts[1]);
208            ghosts[6]->changewith(ghosts[2]);
209            ghosts[7]->changewith(ghosts[3]);
210
211        afraid = false; 
212    } 
213
[11984]214    //Reset ghosts and plazer
[11898]215    void Pacman::posreset(){
[11956]216        for(int i = 0; i<4; ++i){
217            ghosts[i]->resetGhost();
[11898]218        }
219        player->setPosition(startposplayer);
220    }
221
[11984]222    //Collision with PointSphere
[11898]223    void Pacman::takePoint(PacmanPointSphere* taken){
224        ++point;
[12365]225        }
[11979]226        if(point == totallevelpoint){ 
227            this->levelUp();
228            return;
229        }
[11898]230    }
231
232
233    PacmanGelb* Pacman::getPlayer()
234    {
235        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
236        {
237            return ship;
238        }
239        return nullptr;
240    }
241
[11984]242    //Getter
243    bool Pacman::getAfraid(){
244        return afraid;
245    }
246    //Getter
247    int Pacman::getTimer(){
248        return timer;
249    }
250    //Getter
251    int Pacman::getLevel(){
252        return level;
253    }
254    //Getter
[11898]255    int Pacman::getPoints(){
256        return point;
257    }
[11984]258    //Getter
[11978]259    int Pacman::getLives(){
260        return lives;
261    }
[11984]262    //Getter
263    bool Pacman::isdead(){
264        return death;
265    }
[11992]266    //Getter
267    int Pacman::getTotalpoints(){
268        return totallevelpoint;
269    }
[11898]270
[11978]271
[11898]272    void Pacman::start()
273    {
274        Deathmatch::start();
[11954]275
[11984]276        //Hide afraided ghosts under map
[11954]277        int i = 0;
278        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
279            if(3<i){ 
280                nextghost->setPosition(0,-20,0);
281                nextghost->dontmove =  true;
282            };
283            i++;
284        }
[11956]285
[11984]286        //Set maximum of points of first level
[11956]287        totallevelpoint = ObjectList<PacmanPointSphere>().size();
288
[11898]289    }
290
[11976]291    void Pacman::dead(float dt){
292        death = true;
293
294        deathtime = deathtime-dt;
295
296        if(deathtime<0)
297            this->end();
298    }
299
[11898]300    void Pacman::end()
301    {
302        GSLevel::startMainMenu();
303    }
304}
Note: See TracBrowser for help on using the repository browser.