Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 11866 was 11862, checked in by dreherm, 7 years ago

Work on player

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