Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Tes Game 8

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