Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/3DPacman_FS18/src/modules/Pacman/3DPacman.cc @ 11859

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

Moving ghosts

  • Property svn:executable set to *
File size: 3.6 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 "3DPacman.h"
35#include "core/CoreIncludes.h"
36#include "PacmanGelb.h"
37#include "PacmanGhost.h"
38#include "PacmanPointSphere.h"
39
40namespace orxonox
41{
42    RegisterUnloadableClass(3DPacman);
43
44    3DPacman::3DPacman(Context* context) : Deathmatch(context)
45    {
46        RegisterObject(3DPacman);
47
48        lives = 3;
49        point = 0:
50        level = 1;
51
52    }
53
54    void 3DPacman::levelUp()
55    {
56        this->end();
57    }
58
59
60    PacmanGhost[4] ghosts;
61    PacmanPointSphere[1] spheres;
62
63
64    void 3DPacman::tick(float dt)
65    {
66        int i = 0;
67        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
68            ghosts[i] = nextghost;
69            i++;
70        }
71
72        i = 0:
73        for(PacmanPointSphere* nextsphere : ObjectList<PacmanPointSphere>()){
74            spheres[i] = nextsphere;
75            i++;
76        }
77
78        player = this->getPlayer();
79        if (player != nullptr)
80        {
81            currentPosition = player->getWorldPosition();
82        }
83
84        bool bcolli = false;
85        for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){
86            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition)
87        }
88        if(collis){
89            this->catched();
90        }
91
92        SUPER(3DPacman, tick, dt);
93
94    }
95
96
97
98    bool 3DPacman::collis(Vector3 one, Vector3 other){
99        if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1))
100            return true;
101        return false;
102    }
103
104    void 3DPacman::catched(){
105        if(lives) this->end();
106        --lives;
107        this->posreset();
108    } 
109
110    void 3DPacman::posreset(){
111        int i = 0;
112        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
113            ghosts[i] = nextghost;
114            i++;
115        }
116       
117    }
118
119
120    PacmanGelb* 3DPacman::getPlayer()
121    {
122        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
123        {
124            return ship;
125        }
126        return nullptr;
127    }
128
129
130    void 3DPacman::start()
131    {
132        orxout() << "start" << endl;
133       
134        Deathmatch::start();
135    }
136
137    void 3DPacman::playerPreSpawn(PlayerInfo* player)
138    {
139        this->playerInfo_ = player;
140        if(lives <= 0)
141        {
142            this->end();
143        }
144    }
145
146
147    void 3DPacman::end()
148    {
149        // DON'T CALL THIS!
150        //      Deathmatch::end();
151        // It will misteriously crash the game!
152        // Instead startMainMenu, this won't crash.
153        if (Highscore::exists())
154        {
155            int score = this->getPoints();
156            Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
157        }
158        GSLevel::startMainMenu();
159    }
160}
Note: See TracBrowser for help on using the repository browser.