Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Afraid Ghosts

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