Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

laser appears after five pointsphere are eaten

  • 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
[12380]90
91         
92        }
93
94        //ingame loop
95        else{
96            if(point > 5){
[12365]97             
98                for(PacmanPointSphere* pointer : ObjectList<PacmanPointSphere>()){
[12380]99                    Vector3 pointSpherePosition = pointer->getPosition();
[12365]100
101                     if(pointSpherePosition.y > 0){
[12380]102
103                        PacmanLaser* pos = *(ObjectList<PacmanLaser>().begin());
[12365]104                        pos->setPosition(pointSpherePosition);
[12380]105                        orxout()<<"hellooooo" <<endl;
[12365]106                        break;
107                    }
108
109
110                }
111
112            }
[11954]113
[11984]114            //Register ghosts
115            int i = 0;
[12365]116            for(PacmanGhost* nextghost: ObjectList<PacmanGhost>()){
[11984]117                ghosts[i] = nextghost;
118                i++;
[11939]119            }
[11984]120            //Switch ghost to not-catchable, if timer is zero
121            if(afraid){
122                timer = timer - dt;
123                if(timer<=0){
124                    setNormal();
125                }
126            }
[11976]127
[11984]128            //Get position of player
129            player = this->getPlayer();
130            if (player != nullptr)
131            {
132                currentPosition = player->getWorldPosition();
133            }
[11898]134
[11984]135            //Check for collision with ghosts
136            bcolli = false;
137            for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){
138                bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
139            }
[11898]140
[11984]141            if(bcolli){
142                this->catched(dt);
143            }
[11915]144
[11984]145            //Check for collision with PointSpheres and PacmanPointAfraid
146            for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
[12003]147                 if(nextsphere->taken(currentPosition))
148                    takePoint(nextsphere);
[11898]149            }
150
[11984]151            for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
152                if(next->taken(currentPosition))
153                  setAfraid();
[11933]154            }
155
[11979]156        } 
[11976]157
[11898]158    }
159
[11984]160    //Check for collisions between to objects (compare float numbers)
[11898]161    bool Pacman::collis(Vector3 one, Vector3 other){
[12338]162        if((abs(one.x-other.x)<19) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<19))
[11898]163            return true;
164        return false;
165    }
166
[11984]167    //Decrease live or resetghost
[11976]168    void Pacman::catched(float dt){
[11933]169
[11984]170    if(!this->afraid) {
171        if(!this->lives){
[11976]172          deathtime = 5;
173          this->dead(dt); 
174        }
[11898]175        --lives;
176        this->posreset();
[11933]177        }
178    else{
[11945]179        for(int nrghost = 0; nrghost<8; ++nrghost){
[11984]180            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
181            if(bcolli) ghosts[nrghost]->resetGhost();
182                bcolli = false;
[11933]183        }
184      }
185    }
186
[11984]187    //Change ghost design (to afraid)
[11944]188    void Pacman::setAfraid(){
[11945]189
[11944]190        timer = 10; //Set timer to 10 seconds
[11945]191
192        //Change normal Ghosts with afraid ones
193        if(!afraid){
194            ghosts[0]->changewith(ghosts[4]);
195            ghosts[1]->changewith(ghosts[5]);
196            ghosts[2]->changewith(ghosts[6]);
197            ghosts[3]->changewith(ghosts[7]);
198        }
199
200        afraid = true; 
[11898]201    } 
202
[11984]203    //Change ghost design (to not afraid)
[11945]204    void Pacman::setNormal(){
205
206        timer = 0;
207
208        //Change normal Ghosts with afraid ones
209            ghosts[4]->changewith(ghosts[0]);
210            ghosts[5]->changewith(ghosts[1]);
211            ghosts[6]->changewith(ghosts[2]);
212            ghosts[7]->changewith(ghosts[3]);
213
214        afraid = false; 
215    } 
216
[11984]217    //Reset ghosts and plazer
[11898]218    void Pacman::posreset(){
[11956]219        for(int i = 0; i<4; ++i){
220            ghosts[i]->resetGhost();
[11898]221        }
222        player->setPosition(startposplayer);
223    }
224
[11984]225    //Collision with PointSphere
[11898]226    void Pacman::takePoint(PacmanPointSphere* taken){
227        ++point;
[12380]228       
[11979]229        if(point == totallevelpoint){ 
230            this->levelUp();
231            return;
232        }
[11898]233    }
234
235
236    PacmanGelb* Pacman::getPlayer()
237    {
238        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
239        {
240            return ship;
241        }
242        return nullptr;
243    }
244
[11984]245    //Getter
246    bool Pacman::getAfraid(){
247        return afraid;
248    }
249    //Getter
250    int Pacman::getTimer(){
251        return timer;
252    }
253    //Getter
254    int Pacman::getLevel(){
255        return level;
256    }
257    //Getter
[11898]258    int Pacman::getPoints(){
259        return point;
260    }
[11984]261    //Getter
[11978]262    int Pacman::getLives(){
263        return lives;
264    }
[11984]265    //Getter
266    bool Pacman::isdead(){
267        return death;
268    }
[11992]269    //Getter
270    int Pacman::getTotalpoints(){
271        return totallevelpoint;
272    }
[11898]273
[11978]274
[11898]275    void Pacman::start()
276    {
277        Deathmatch::start();
[11954]278
[11984]279        //Hide afraided ghosts under map
[11954]280        int i = 0;
281        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
282            if(3<i){ 
283                nextghost->setPosition(0,-20,0);
284                nextghost->dontmove =  true;
285            };
286            i++;
287        }
[11956]288
[11984]289        //Set maximum of points of first level
[11956]290        totallevelpoint = ObjectList<PacmanPointSphere>().size();
291
[11898]292    }
293
[11976]294    void Pacman::dead(float dt){
295        death = true;
296
297        deathtime = deathtime-dt;
298
299        if(deathtime<0)
300            this->end();
301    }
302
[11898]303    void Pacman::end()
304    {
305        GSLevel::startMainMenu();
306    }
[12380]307}
Note: See TracBrowser for help on using the repository browser.