Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Afraid Test 7

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