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 | if((level_%10)==0){ |
---|
146 | --counter; |
---|
147 | } |
---|
148 | int z_ = 0; |
---|
149 | |
---|
150 | orxout() << "level up called" << endl; |
---|
151 | this->playerScored(this->player_);// add points |
---|
152 | |
---|
153 | this->createWall(); |
---|
154 | |
---|
155 | for(OrxoBloxStones* stone : ObjectList<OrxoBloxStones>()){ |
---|
156 | if (stone->isA(Class(OrxoBloxStones))) { |
---|
157 | int x_=(stone->getPosition()).x; |
---|
158 | int y_=(stone->getPosition()).y; |
---|
159 | z_=(stone->getPosition()).z; |
---|
160 | //if(z_==90)this->end(); |
---|
161 | |
---|
162 | stone->setPosition(x_,y_,z_+9.0f); |
---|
163 | if( z_ >= 45){ |
---|
164 | orxout() << "calling end() function" << endl; |
---|
165 | this->end(); |
---|
166 | return; |
---|
167 | } |
---|
168 | } |
---|
169 | else { |
---|
170 | orxout() << "WTF IS THIS SHIT?!?!?!" << endl; |
---|
171 | } |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | void OrxoBlox::createWall(){ |
---|
176 | this->futureWall_ = new OrxoBloxWall(this->center_->getContext()); |
---|
177 | // Apply the stone template to the stone. |
---|
178 | this->futureWall_->addTemplate(this->center_->getWallTemplate()); |
---|
179 | |
---|
180 | // Attach the brick to the Centerpoint and set the position of the brick to be at the left side. |
---|
181 | this->center_->attach(this->futureWall_); |
---|
182 | |
---|
183 | this->futureWall_->setPosition(0, 0, 0); |
---|
184 | this->futureWall_->setGame(this); |
---|
185 | } |
---|
186 | |
---|
187 | |
---|
188 | void OrxoBlox::playerPreSpawn(PlayerInfo* player) |
---|
189 | { |
---|
190 | this->player_ = player; |
---|
191 | } |
---|
192 | |
---|
193 | void OrxoBlox::tick(float dt) |
---|
194 | { |
---|
195 | SUPER(OrxoBlox, tick, dt); |
---|
196 | } |
---|
197 | |
---|
198 | void OrxoBlox::count() { |
---|
199 | if(++(this->counter) >= this->max_counter) { |
---|
200 | this->LevelUp(); |
---|
201 | counter = 0; |
---|
202 | return; |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | |
---|
207 | } |
---|