Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Added Ghostchange

  • Property svn:executable set to *
File size: 5.9 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       // firstGame = true;                   //needed for the HUD
47        lives = 10;
48        point = 0;
49        level = 1;
50
51       // setHUDTemplate("PacmanOrxHUD");
52       // scoreboardTemplate_ = "";
53    }
54
55    void Pacman::levelUp()
56    {
57        this->end();
58    }
59
60
61    PacmanGhost* ghosts[4];
62
63
64    void Pacman::tick(float dt)
65    {
66        SUPER(Pacman, tick, dt);
67
68        //orxout() << timer << endl;
69        //orxout() << afraid << endl;
70
71
72        if(afraid){
73            timer = timer - dt;
74            if(timer<=0){
75                setNormal();
76            }
77        }
78
79        int i = 0;
80        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
81            ghosts[i] = nextghost;
82            i++;
83        }
84
85        player = this->getPlayer();
86        if (player != nullptr)
87        {
88            currentPosition = player->getWorldPosition();
89        }
90
91
92        bcolli = false;
93        for(int nrghost = 0; (nrghost<8) && (!bcolli); ++nrghost){
94            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
95            //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl;
96        }
97
98        if(bcolli){
99          this->catched();
100        }
101
102        i = 0;
103        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
104            if(collis(nextsphere->getPosition(), currentPosition)){
105                takePoint(nextsphere);
106            }
107        }
108
109        for(PacmanPointAfraid* next : ObjectList<PacmanPointAfraid>()){
110            if(next->taken(currentPosition)){
111                setAfraid();
112            }
113        }
114
115    }
116
117
118    bool Pacman::collis(Vector3 one, Vector3 other){
119        if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10))
120            return true;
121        return false;
122    }
123
124    void Pacman::catched(){
125
126    if(!afraid) {
127        if(!lives) this->end();
128        --lives;
129        this->posreset();
130        }
131    else{
132        for(int nrghost = 0; nrghost<8; ++nrghost){
133        bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
134        if(bcolli) ghosts[nrghost]->resetGhost();
135        bcolli = false;
136        }
137      }
138    }
139
140    void Pacman::setAfraid(){
141
142        timer = 10; //Set timer to 10 seconds
143
144        //Change normal Ghosts with afraid ones
145        if(!afraid){
146            ghosts[0]->changewith(ghosts[4]);
147            ghosts[1]->changewith(ghosts[5]);
148            ghosts[2]->changewith(ghosts[6]);
149            ghosts[3]->changewith(ghosts[7]);
150        }
151
152        afraid = true; 
153    } 
154
155    void Pacman::setNormal(){
156
157        timer = 0;
158
159        //Change normal Ghosts with afraid ones
160            ghosts[4]->changewith(ghosts[0]);
161            ghosts[5]->changewith(ghosts[1]);
162            ghosts[6]->changewith(ghosts[2]);
163            ghosts[7]->changewith(ghosts[3]);
164
165        afraid = false; 
166    } 
167
168    void Pacman::posreset(){
169        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
170            nextghost->resetGhost();
171        }
172        player->setPosition(startposplayer);
173    }
174
175    void Pacman::takePoint(PacmanPointSphere* taken){
176        ++point;
177        if(point == totallevelpoint) this->levelUp();
178        Vector3 postaken = taken->getPosition();
179        postaken.y = -50;
180        taken->setPosition(postaken);
181    }
182
183
184    PacmanGelb* Pacman::getPlayer()
185    {
186        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
187        {
188            return ship;
189        }
190        return nullptr;
191    }
192
193    int Pacman::getPoints(){
194        return point;
195    }
196
197
198    void Pacman::start()
199    {
200        Deathmatch::start();
201
202        int i = 0;
203        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
204            if(3<i){ 
205                nextghost->setPosition(0,-20,0);
206                nextghost->dontmove =  true;
207            };
208           
209            i++;
210        }
211    }
212
213
214    void Pacman::end()
215    {
216        /*
217        firstGame = false;
218       
219        //Set randomized deathmessages
220        if(point<7)         sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())];
221        else if(point<20)   sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())];
222        else if(point<30)   sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())];
223        else                sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())];
224       
225        //Update Highscore
226        if (Highscore::exists())
227        {
228            int score = this->getPoints();
229            Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer());
230        }
231
232
233        if (Highscore::exists())
234        {
235            //int score = this->getPoints();
236            //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
237        }
238        */
239        GSLevel::startMainMenu();
240    }
241}
Note: See TracBrowser for help on using the repository browser.