Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Tes Game 4

  • Property svn:executable set to *
File size: 3.9 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#include "PacmanGelb.h"
37#include "PacmanGhost.h"
38#include "PacmanPointSphere.h"
39#include "Highscore.h"
40
41namespace orxonox
42{
43    RegisterUnloadableClass(Pacman);
44
45    Pacman::Pacman(Context* context) : Deathmatch(context)
46    {
47        RegisterObject(Pacman);
48
49        lives = 3;
50        point = 0;
51        level = 1;
52        Vector3 startposplayer = Vector3(0,10,245);
53
54    }
55
56    void Pacman::levelUp()
57    {
58        this->end();
59    }
60
61
62    PacmanGhost[4] ghosts;
63    PacmanPointSphere[1] spheres;
64
65
66    void Pacman::tick(float 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        bcolli = false;
81        for(int nrghost = 0, (nrghost<3) && (!bcolli), ++nrghost){
82            bcolli = collis(ghosts[nrghost]->getPosition(), currentPosition)
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        SUPER(Pacman, tick, dt);
96
97    }
98
99
100    bool Pacman::collis(Vector3 one, Vector3 other){
101        if((abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1) && (abs(one.x-other.x)<0.1))
102            return true;
103        return false;
104    }
105
106    void Pacman::catched(){
107        if(!lives) this->end();
108        --lives;
109        this->posreset();
110    } 
111
112    void Pacman::posreset(){
113        int i = 0;
114        for(PacmanGhost* nextghost : ObjectList<PacmanGhost>()){
115            nextghost.resetGhost();
116            i++;
117        }
118        player.setPosition(startposplayer);
119    }
120
121    void Pacman::takePoint(PacmanPointSphere* taken){
122        ++point;
123        if(point == totallevelpoint) this->levelUp;
124
125        Vector3 postaken = taken.getPosition();
126        postaken.y = -50;
127        taken.setPosition(postaken);
128    }
129
130
131    PacmanGelb* Pacman::getPlayer()
132    {
133        for (PacmanGelb* ship : ObjectList<PacmanGelb>())
134        {
135            return ship;
136        }
137        return nullptr;
138    }
139
140    int Pacman::getPoints(){
141        return point;
142    }
143
144
145    void Pacman::start()
146    {
147        orxout() << "start" << endl;
148       
149        Deathmatch::start();
150    }
151
152    void Pacman::playerPreSpawn(PlayerInfo* player)
153    {
154        this->playerInfo_ = player;
155        if(lives <= 0)
156        {
157            this->end();
158        }
159    }
160
161
162    void Pacman::end()
163    {
164        if (Highscore::exists())
165        {
166            int score = this->getPoints();
167            Highscore::getInstance().storeScore("3DPacman", score, this->playerInfo_);
168        }
169        GSLevel::startMainMenu();
170    }
171}
Note: See TracBrowser for help on using the repository browser.