Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Afraid Test 4

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