1 | #include "OrxoBlox.h" |
---|
2 | #include "Highscore.h" |
---|
3 | |
---|
4 | #include "core/CoreIncludes.h" |
---|
5 | #include "core/EventIncludes.h" |
---|
6 | #include "core/command/Executor.h" |
---|
7 | |
---|
8 | |
---|
9 | #include "core/config/ConfigValueIncludes.h"//Remove?? |
---|
10 | |
---|
11 | #include "gamestates/GSLevel.h" |
---|
12 | |
---|
13 | |
---|
14 | #include "chat/ChatManager.h"//Remove? |
---|
15 | |
---|
16 | #include "OrxoBloxCenterpoint.h" |
---|
17 | #include "OrxoBloxStones.h" |
---|
18 | #include "OrxoBloxWall.h" |
---|
19 | #include "OrxoBloxShip.h" |
---|
20 | |
---|
21 | namespace orxonox |
---|
22 | { |
---|
23 | |
---|
24 | |
---|
25 | RegisterUnloadableClass(OrxoBlox); |
---|
26 | |
---|
27 | /** |
---|
28 | @brief |
---|
29 | Constructor. Registers and initializes the object. |
---|
30 | */ |
---|
31 | OrxoBlox::OrxoBlox(Context* context) : Deathmatch(context) |
---|
32 | { |
---|
33 | RegisterObject(OrxoBlox); |
---|
34 | |
---|
35 | this->center_ = nullptr; |
---|
36 | //this->ball_ = nullptr; |
---|
37 | this->futureWall_ = nullptr; |
---|
38 | this->player_ = nullptr; |
---|
39 | level_ = 0; |
---|
40 | this->counter = 0; |
---|
41 | |
---|
42 | this->setHUDTemplate("OrxoBloxHUD"); |
---|
43 | //Error when specified |
---|
44 | |
---|
45 | // Pre-set the timer, but don't start it yet. |
---|
46 | this->starttimer_.setTimer(1.0, false, createExecutor(createFunctor(&OrxoBlox::LevelUp, this))); |
---|
47 | this->starttimer_.stopTimer(); |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | @brief |
---|
55 | Destructor. Cleans up, if initialized. |
---|
56 | */ |
---|
57 | OrxoBlox::~OrxoBlox() |
---|
58 | { |
---|
59 | if (this->isInitialized()) |
---|
60 | this->cleanup(); |
---|
61 | } |
---|
62 | |
---|
63 | /** |
---|
64 | @brief |
---|
65 | Cleans up the Gametype by destroying the ball and the bats. |
---|
66 | */ |
---|
67 | void OrxoBlox::cleanup() |
---|
68 | { |
---|
69 | |
---|
70 | std::vector<OrxoBloxWall*> vyserion_targets; |
---|
71 | std::vector<OrxoBloxStones*> casterly_rocks; |
---|
72 | |
---|
73 | for (OrxoBloxWall* wall : ObjectList<OrxoBloxWall>()) { |
---|
74 | if(wall != nullptr) { |
---|
75 | vyserion_targets.push_back(wall); |
---|
76 | } |
---|
77 | } |
---|
78 | for (OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()) { |
---|
79 | if(stone != nullptr) { |
---|
80 | casterly_rocks.push_back(stone); |
---|
81 | } |
---|
82 | } |
---|
83 | for(unsigned int i = 0; i < vyserion_targets.size(); i++) { |
---|
84 | vyserion_targets.at(i)->destroy(); |
---|
85 | } |
---|
86 | for(unsigned int i = 0; i < casterly_rocks.size(); i++) { |
---|
87 | casterly_rocks.at(i)->destroy(); |
---|
88 | } |
---|
89 | |
---|
90 | } |
---|
91 | |
---|
92 | /** |
---|
93 | @brieftt |
---|
94 | Starts the OrxoBlox minigame. |
---|
95 | */ |
---|
96 | void OrxoBlox::start() |
---|
97 | |
---|
98 | { |
---|
99 | orxout() << "Orxoblox started" << endl; |
---|
100 | if (this->center_ != nullptr) // There needs to be a OrxoBloxCenterpoint, i.e. the area the game takes place. |
---|
101 | { |
---|
102 | level_= 1; |
---|
103 | } |
---|
104 | else // If no centerpoint was specified, an error is thrown and the level is exited. |
---|
105 | { |
---|
106 | orxout(internal_error) << "OrxoBlox: No Centerpoint specified." << endl; |
---|
107 | GSLevel::startMainMenu(); |
---|
108 | return; |
---|
109 | } |
---|
110 | this->starttimer_.startTimer(); |
---|
111 | |
---|
112 | this->bForceSpawn_ = false; |
---|
113 | Deathmatch::start(); |
---|
114 | } |
---|
115 | |
---|
116 | /** |
---|
117 | @brief |
---|
118 | Ends the OrxoBlox minigame. |
---|
119 | */ |
---|
120 | void OrxoBlox::end() |
---|
121 | { |
---|
122 | ChatManager::message("You suck!!"); |
---|
123 | |
---|
124 | if (Highscore::exists()) |
---|
125 | { |
---|
126 | int score = this->getScore(this->getPlayer()); |
---|
127 | Highscore::getInstance().storeScore("OrxoBlox", score, this->getPlayer()); |
---|
128 | } |
---|
129 | |
---|
130 | this->cleanup(); |
---|
131 | |
---|
132 | // Call end for the parent class. |
---|
133 | Deathmatch::end(); |
---|
134 | //GSLevel::startMainMenu(); |
---|
135 | } |
---|
136 | |
---|
137 | PlayerInfo* OrxoBlox::getPlayer() |
---|
138 | { |
---|
139 | return this->player_; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | void OrxoBlox::LevelUp(){ |
---|
144 | level_++; |
---|
145 | int z_ = 0; |
---|
146 | |
---|
147 | orxout() << "level up called" << endl; |
---|
148 | this->playerScored(this->player_);// add points |
---|
149 | |
---|
150 | this->createWall(); |
---|
151 | |
---|
152 | for(OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()){ |
---|
153 | if (stone->isA(Class(OrxoBloxStones))) { |
---|
154 | int x_=(stone->getPosition()).x; |
---|
155 | int y_=(stone->getPosition()).y; |
---|
156 | z_=(stone->getPosition()).z; |
---|
157 | //if(z_==90)this->end(); |
---|
158 | |
---|
159 | stone->setPosition(x_,y_,z_+9.0f); |
---|
160 | if( z_ >= 45){ |
---|
161 | orxout() << "calling end() function" << endl; |
---|
162 | this->end(); |
---|
163 | return; |
---|
164 | } |
---|
165 | } |
---|
166 | else { |
---|
167 | orxout() << "WTF IS THIS SHIT?!?!?!" << endl; |
---|
168 | } |
---|
169 | } |
---|
170 | } |
---|
171 | |
---|
172 | void OrxoBlox::createWall(){ |
---|
173 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
174 | // Apply the stone template to the stone. |
---|
175 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
176 | |
---|
177 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
178 | this->center_->attach(this->futureWall_); |
---|
179 | |
---|
180 | this->futureWall_->setPosition(0, 0, 0); |
---|
181 | this->futureWall_->setGame(this); |
---|
182 | } |
---|
183 | |
---|
184 | |
---|
185 | void OrxoBlox::playerPreSpawn(PlayerInfo* player) |
---|
186 | { |
---|
187 | this->player_ = player; |
---|
188 | } |
---|
189 | |
---|
190 | void OrxoBlox::tick(float dt) |
---|
191 | { |
---|
192 | SUPER(OrxoBlox, tick, dt); |
---|
193 | } |
---|
194 | |
---|
195 | void OrxoBlox::count() { |
---|
196 | if(++(this->counter) >= this->max_counter) { |
---|
197 | this->LevelUp(); |
---|
198 | counter = 0; |
---|
199 | return; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | } |
---|