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