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 Asteroids2D.cc |
---|
31 | @brief Implementation of the Asteroids2D class. |
---|
32 | */ |
---|
33 | |
---|
34 | #include "Asteroids2D.h" |
---|
35 | #include "Asteroids2DShip.h" // Necessary for getPlayer function. Do NOT include this in Header! |
---|
36 | #include "core/CoreIncludes.h" |
---|
37 | #include "Highscore.h" |
---|
38 | |
---|
39 | namespace orxonox |
---|
40 | { |
---|
41 | RegisterUnloadableClass(Asteroids2D); |
---|
42 | |
---|
43 | Asteroids2D::Asteroids2D(Context* context) : Deathmatch(context) |
---|
44 | { |
---|
45 | RegisterObject(Asteroids2D); |
---|
46 | |
---|
47 | bEndGame = false; |
---|
48 | lives = 1; |
---|
49 | level = 1; |
---|
50 | point = 0; |
---|
51 | bShowLevel = false; |
---|
52 | multiplier = 1; |
---|
53 | b_combo = false; |
---|
54 | counter = 5000; |
---|
55 | pattern = 1; |
---|
56 | lastPosition = 0; |
---|
57 | this->numberOfBots_ = 0; //sets number of default bots temporarly to 0 |
---|
58 | this->center_ = nullptr; |
---|
59 | this->setHUDTemplate("Asteroids2DHUD"); |
---|
60 | } |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | void Asteroids2D::levelUp() |
---|
65 | { |
---|
66 | level++; |
---|
67 | if (getPlayer() != nullptr) |
---|
68 | { |
---|
69 | for (int i = 0; i < 7; i++) |
---|
70 | { |
---|
71 | WeakPtr<ExplosionPart> chunk5 = new ExplosionPart(this->center_->getContext()); |
---|
72 | chunk5->setPosition(Vector3(600, 0, 100.f * i - 300)); |
---|
73 | chunk5->setVelocity(Vector3(1000, 0, 0)); //player->getVelocity() |
---|
74 | chunk5->setScale(10); |
---|
75 | chunk5->setEffect1("Orxonox/explosion2b"); |
---|
76 | chunk5->setEffect2("Orxonox/smoke6"); |
---|
77 | chunk5->Explode(); |
---|
78 | |
---|
79 | } |
---|
80 | } |
---|
81 | addPoints(multiplier * 42); |
---|
82 | multiplier *= 2; |
---|
83 | toggleShowLevel(); |
---|
84 | showLevelTimer.setTimer(1.0f, false, createExecutor(createFunctor(&Asteroids2D::toggleShowLevel, this))); |
---|
85 | } |
---|
86 | |
---|
87 | void Asteroids2D::tick(float dt) |
---|
88 | { |
---|
89 | |
---|
90 | SUPER(Asteroids2D, tick, dt); |
---|
91 | } |
---|
92 | |
---|
93 | Asteroids2DShip* Asteroids2D::getPlayer() |
---|
94 | { |
---|
95 | if (player == nullptr) |
---|
96 | { |
---|
97 | for (Asteroids2DShip* ship : ObjectList<Asteroids2DShip>()) |
---|
98 | { |
---|
99 | player = ship; |
---|
100 | } |
---|
101 | } |
---|
102 | return player; |
---|
103 | } |
---|
104 | |
---|
105 | void Asteroids2D::costLife() |
---|
106 | { |
---|
107 | //endGameTimer.setTimer(8.0f, false, createExecutor(createFunctor(&Asteroids2D::end, this))); |
---|
108 | lives = 0; |
---|
109 | }; |
---|
110 | |
---|
111 | void Asteroids2D::start() |
---|
112 | { |
---|
113 | orxout() << "start" << endl; |
---|
114 | |
---|
115 | // Set variable to temporarily force the player to spawn. |
---|
116 | this->bForceSpawn_ = false; |
---|
117 | |
---|
118 | if (this->center_ == nullptr) // abandon mission! |
---|
119 | { |
---|
120 | orxout(internal_error) << "Asteroids2D: No Centerpoint specified." << endl; |
---|
121 | GSLevel::startMainMenu(); |
---|
122 | return; |
---|
123 | } |
---|
124 | // Call start for the parent class. |
---|
125 | Deathmatch::start(); |
---|
126 | } |
---|
127 | |
---|
128 | void Asteroids2D::playerPreSpawn(PlayerInfo* player) |
---|
129 | { |
---|
130 | if(lives <= 0) |
---|
131 | { |
---|
132 | this->end(); |
---|
133 | } |
---|
134 | } |
---|
135 | |
---|
136 | void Asteroids2D::addPoints(int numPoints) |
---|
137 | { |
---|
138 | if (!bEndGame) |
---|
139 | { |
---|
140 | point += numPoints * multiplier; |
---|
141 | b_combo = true; |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | void Asteroids2D::end() |
---|
146 | { |
---|
147 | // DON'T CALL THIS! |
---|
148 | // Deathmatch::end(); |
---|
149 | // It will misteriously crash the game! |
---|
150 | // Instead startMainMenu, this won't crash. |
---|
151 | if (Highscore::exists()){ |
---|
152 | int score = this->getPoints(); |
---|
153 | if(score > Highscore::getInstance().getHighestScoreOfGame("Dodge Race")) |
---|
154 | Highscore::getInstance().storeHighscore("Dodge Race",score); |
---|
155 | |
---|
156 | } |
---|
157 | GSLevel::startMainMenu(); |
---|
158 | } |
---|
159 | } |
---|