Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

HUD first commit

  • Property svn:executable set to *
File size: 4.4 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    }
99
100
101    bool Pacman::collis(Vector3 one, Vector3 other){
102        if((abs(one.x-other.x)<10) && (abs(one.y-other.y)<10) && (abs(one.z-other.z)<10))
103            return true;
104        return false;
105    }
106
107    void Pacman::catched(){
108        if(!lives) this->end();
109        --lives;
110        this->posreset();
111    } 
112
113    void Pacman::posreset(){
114        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
115            nextghost->resetGhost();
116        }
117        player->setPosition(startposplayer);
118    }
119
120    void Pacman::takePoint(PacmanPointSphere* taken){
121        ++point;
122        if(point == totallevelpoint) this->levelUp();
123        Vector3 postaken = taken->getPosition();
124        postaken.y = -50;
125        taken->setPosition(postaken);
126    }
127
128
129    PacmanGelb* Pacman::getPlayer()
130    {
131        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
132        {
133            return ship;
134        }
135        return nullptr;
136    }
137
138    int Pacman::getPoints(){
139        return point;
140    }
141
142
143    void Pacman::start()
144    {
145        Deathmatch::start();
146    }
147
148
149    void Pacman::end()
150    {
151        /*
152        firstGame = false;
153       
154        //Set randomized deathmessages
155        if(point<7)         sDeathMessage = DeathMessage7[rand()%(DeathMessage7.size())];
156        else if(point<20)   sDeathMessage = DeathMessage20[rand()%(DeathMessage20.size())];
157        else if(point<30)   sDeathMessage = DeathMessage30[rand()%(DeathMessage30.size())];
158        else                sDeathMessage = DeathMessageover30[rand()%(DeathMessageover30.size())];
159       
160        //Update Highscore
161        if (Highscore::exists())
162        {
163            int score = this->getPoints();
164            Highscore::getInstance().storeScore("Pacman", score, this->getPlayer()->getPlayer());
165        }
166
167
168        if (Highscore::exists())
169        {
170            //int score = this->getPoints();
171            //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
172        }
173        */
174        GSLevel::startMainMenu();
175    }
176}
Note: See TracBrowser for help on using the repository browser.