Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS18/src/modules/pacman/Pacman.cc @ 11979

Last change on this file since 11979 was 11979, checked in by dreherm, 6 years ago

Debugged levelup

  • Property svn:executable set to *
File size: 6.1 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 *      Florian Zinggeler
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//Test
37
38namespace orxonox
39{
40    RegisterClass(Pacman);
41
42    Pacman::Pacman(Context* context) : Deathmatch(context)
43    {
44        RegisterObject(Pacman);
45
46        lives = 3;
47        point = 0;
48        level = 1;
49
50    }
51
52    void Pacman::levelUp()
53    {
54        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
55                nextsphere->resetPacmanPointSphere();
56        }
57
58        for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
59            next->resetPacmanPointAfraid();
60        }
61
62        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
63            nextghost->levelupvelo(); 
64        }
65        this->posreset();
66
67        totallevelpoint = ObjectList<PacmanPointSphere>().size() + totallevelpoint;
68        level++;
69    }
70
71
72    PacmanGhost* ghosts[4];
73
74
75    void Pacman::tick(float dt)
76    {
77        SUPER(Pacman, tick, dt);
78
79        if(deathtime != 0){
80            dead(dt);
81        }
82
83        else{
84
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        }
128
129        } 
130
131    }
132
133
134    bool Pacman::collis(Vector3 one, Vector3 other){
135        if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10))
136            return true;
137        return false;
138    }
139
140    void Pacman::catched(float dt){
141
142    if(!afraid) {
143        if(!lives){
144          deathtime = 5;
145          this->dead(dt); 
146        }
147        --lives;
148        this->posreset();
149        }
150    else{
151        for(int nrghost = 0; nrghost<8; ++nrghost){
152        bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
153        if(bcolli) ghosts[nrghost]->resetGhost();
154        bcolli = false;
155        }
156      }
157    }
158
159    void Pacman::setAfraid(){
160
161        timer = 10; //Set timer to 10 seconds
162
163        //Change normal Ghosts with afraid ones
164        if(!afraid){
165            ghosts[0]->changewith(ghosts[4]);
166            ghosts[1]->changewith(ghosts[5]);
167            ghosts[2]->changewith(ghosts[6]);
168            ghosts[3]->changewith(ghosts[7]);
169        }
170
171        afraid = true; 
172    } 
173
174    void Pacman::setNormal(){
175
176        timer = 0;
177
178        //Change normal Ghosts with afraid ones
179            ghosts[4]->changewith(ghosts[0]);
180            ghosts[5]->changewith(ghosts[1]);
181            ghosts[6]->changewith(ghosts[2]);
182            ghosts[7]->changewith(ghosts[3]);
183
184        afraid = false; 
185    } 
186
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
199    void Pacman::posreset(){
200        for(int i = 0; i<4; ++i){
201            ghosts[i]->resetGhost();
202        }
203        player->setPosition(startposplayer);
204    }
205
206    void Pacman::takePoint(PacmanPointSphere* taken){
207        ++point;
208        if(point == totallevelpoint){ 
209            this->levelUp();
210            return;
211        }
212        Vector3 postaken = taken->getPosition();
213        postaken.y = -50;
214        taken->setPosition(postaken);
215    }
216
217
218    PacmanGelb* Pacman::getPlayer()
219    {
220        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
221        {
222            return ship;
223        }
224        return nullptr;
225    }
226
227    int Pacman::getPoints(){
228        return point;
229    }
230
231    int Pacman::getLives(){
232        return lives;
233    }
234
235
236    void Pacman::start()
237    {
238        Deathmatch::start();
239
240        int i = 0;
241        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
242            if(3<i){ 
243                nextghost->setPosition(0,-20,0);
244                nextghost->dontmove =  true;
245            };
246            i++;
247        }
248
249        totallevelpoint = ObjectList<PacmanPointSphere>().size();
250
251    }
252
253    bool Pacman::isdead(){
254        return death;
255    }
256
257    void Pacman::dead(float dt){
258        death = true;
259
260        deathtime = deathtime-dt;
261
262        if(deathtime<0)
263            this->end();
264    }
265
266    void Pacman::end()
267    {
268
269        /*
270        if (Highscore::exists())
271        {
272            //int score = this->getPoints();
273            //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
274        }
275        */
276        GSLevel::startMainMenu();
277    }
278}
Note: See TracBrowser for help on using the repository browser.