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
Line 
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:
23 *      Marc Dreher
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{
39    RegisterClass(Pacman);
40
41    int PACMAN_INTERNAL_PACMAN_POSITION;
42
43    Pacman::Pacman(Context* context) : Deathmatch(context)
44    {
45        RegisterObject(Pacman);
46
47        lives = 3;
48        point = 0;
49        level = 1;
50
51    }
52
53    void Pacman::levelUp()
54    {
55        //Reset each object
56        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
57                nextsphere->resetPacmanPointSphere();
58        }
59
60        for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
61            next->resetPacmanPointAfraid();
62        }
63
64        //Level up ghosts
65        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
66            nextghost->levelupvelo(); 
67        }
68        //Reset ghosts and player
69        this->posreset();
70
71        //Increase maximum of points and level
72        totallevelpoint = ObjectList<PacmanPointSphere>().size() + totallevelpoint;
73        level++;
74    }
75
76
77    PacmanGhost* ghosts[8];
78
79
80    void Pacman::tick(float dt)
81    {
82
83        SUPER(Pacman, tick, dt);
84
85
86        //Needed for gameover
87        if(deathtime != 0){
88            dead(dt);
89
90
91         
92        }
93
94        //ingame loop
95        else{
96            if(point > 5){
97             
98                for(PacmanPointSphere* pointer : ObjectList<PacmanPointSphere>()){
99                    Vector3 pointSpherePosition = pointer->getPosition();
100
101                     if(pointSpherePosition.y > 0){
102
103                        PacmanLaser* pos = *(ObjectList<PacmanLaser>().begin());
104                        pos->setPosition(pointSpherePosition);
105                        orxout()<<"hellooooo" <<endl;
106                        break;
107                    }
108
109
110                }
111
112            }
113
114            //Register ghosts
115            int i = 0;
116            for(PacmanGhost* nextghost: ObjectList<PacmanGhost>()){
117                ghosts[i] = nextghost;
118                i++;
119            }
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            }
127
128            //Get position of player
129            player = this->getPlayer();
130            if (player != nullptr)
131            {
132                currentPosition = player->getWorldPosition();
133            }
134
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            }
140
141            if(bcolli){
142                this->catched(dt);
143            }
144
145            //Check for collision with PointSpheres and PacmanPointAfraid
146            for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
147                 if(nextsphere->taken(currentPosition))
148                    takePoint(nextsphere);
149            }
150
151            for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
152                if(next->taken(currentPosition))
153                  setAfraid();
154            }
155
156        } 
157
158    }
159
160    //Check for collisions between to objects (compare float numbers)
161    bool Pacman::collis(Vector3 one, Vector3 other){
162        if((abs(one.x-other.x)<19) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<19))
163            return true;
164        return false;
165    }
166
167    //Decrease live or resetghost
168    void Pacman::catched(float dt){
169
170    if(!this->afraid) {
171        if(!this->lives){
172          deathtime = 5;
173          this->dead(dt); 
174        }
175        --lives;
176        this->posreset();
177        }
178    else{
179        for(int nrghost = 0; nrghost<8; ++nrghost){
180            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
181            if(bcolli) ghosts[nrghost]->resetGhost();
182                bcolli = false;
183        }
184      }
185    }
186
187    //Change ghost design (to afraid)
188    void Pacman::setAfraid(){
189
190        timer = 10; //Set timer to 10 seconds
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; 
201    } 
202
203    //Change ghost design (to not afraid)
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
217    //Reset ghosts and plazer
218    void Pacman::posreset(){
219        for(int i = 0; i<4; ++i){
220            ghosts[i]->resetGhost();
221        }
222        player->setPosition(startposplayer);
223    }
224
225    //Collision with PointSphere
226    void Pacman::takePoint(PacmanPointSphere* taken){
227        ++point;
228       
229        if(point == totallevelpoint){ 
230            this->levelUp();
231            return;
232        }
233    }
234
235
236    PacmanGelb* Pacman::getPlayer()
237    {
238        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
239        {
240            return ship;
241        }
242        return nullptr;
243    }
244
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
258    int Pacman::getPoints(){
259        return point;
260    }
261    //Getter
262    int Pacman::getLives(){
263        return lives;
264    }
265    //Getter
266    bool Pacman::isdead(){
267        return death;
268    }
269    //Getter
270    int Pacman::getTotalpoints(){
271        return totallevelpoint;
272    }
273
274
275    void Pacman::start()
276    {
277        Deathmatch::start();
278
279        //Hide afraided ghosts under map
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        }
288
289        //Set maximum of points of first level
290        totallevelpoint = ObjectList<PacmanPointSphere>().size();
291
292    }
293
294    void Pacman::dead(float dt){
295        death = true;
296
297        deathtime = deathtime-dt;
298
299        if(deathtime<0)
300            this->end();
301    }
302
303    void Pacman::end()
304    {
305        GSLevel::startMainMenu();
306    }
307}
Note: See TracBrowser for help on using the repository browser.