Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Game playable

  • Property svn:executable set to *
File size: 3.5 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        lives = 10;
47        point = 0;
48        level = 1;
49
50    }
51
52    void Pacman::levelUp()
53    {
54        this->end();
55    }
56
57
58    PacmanGhost* ghosts[4];
59
60
61    void Pacman::tick(float dt)
62    {
63        SUPER(Pacman, tick, dt);
64
65        int i = 0;
66        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
67            ghosts[i] = nextghost;
68            i++;
69        }
70
71        player = this->getPlayer();
72        if (player != nullptr)
73        {
74            currentPosition = player->getWorldPosition();
75        }
76
77
78        bcolli = false;
79        for(int nrghost = 0; (nrghost<3) && (!bcolli); ++nrghost){
80            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition);
81            //orxout() << "GHOST" << nrghost << ghosts[nrghost]->getPosition() << endl;
82        }
83
84        if(bcolli){
85          this->catched();
86        }
87
88        i = 0;
89        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
90            if(collis(nextsphere->getPosition(), currentPosition)){
91                takePoint(nextsphere);
92            }
93        }
94
95    }
96
97
98    bool Pacman::collis(Vector3 one, Vector3 other){
99        if((abs(one.x-other.x)<7) && (abs(one.y-other.y)<7) && (abs(one.z-other.z)<7))
100            return true;
101        return false;
102    }
103
104    void Pacman::catched(){
105        if(!lives) this->end();
106        --lives;
107        this->posreset();
108    } 
109
110    void Pacman::posreset(){
111        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
112            nextghost->resetGhost();
113        }
114        player->setPosition(startposplayer);
115    }
116
117    void Pacman::takePoint(PacmanPointSphere* taken){
118        ++point;
119        if(point == totallevelpoint) this->levelUp();
120        Vector3 postaken = taken->getPosition();
121        postaken.y = -50;
122        taken->setPosition(postaken);
123    }
124
125
126    PacmanGelb* Pacman::getPlayer()
127    {
128        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
129        {
130            return ship;
131        }
132        return nullptr;
133    }
134
135    int Pacman::getPoints(){
136        return point;
137    }
138
139
140    void Pacman::start()
141    {
142        Deathmatch::start();
143    }
144
145
146    void Pacman::end()
147    {
148        if (Highscore::exists())
149        {
150            //int score = this->getPoints();
151            //Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
152        }
153        GSLevel::startMainMenu();
154    }
155}
Note: See TracBrowser for help on using the repository browser.