File tree Expand file tree Collapse file tree 6 files changed +27
-1
lines changed Expand file tree Collapse file tree 6 files changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
1
#include " Airplane.h"
2
2
3
+ #include " Target.h"
4
+ #include " World.h"
5
+
3
6
const Ogre::String Airplane::SCENE_NODE_NAME = " Airplane" ;
4
7
5
8
static const float MINIMUM_TIME_STEP = 0 .01f ;
@@ -220,6 +223,8 @@ void Airplane::checkGroundCollision() {
220
223
if (state.position .y < Y_MIN) {
221
224
if (state.velocity .y < -LANDING_ROD_MAX || getPitch () < LANDING_PITCH_MIN)
222
225
crash ();
226
+ else
227
+ land ();
223
228
224
229
state.position .y = Y_MIN;
225
230
state.velocity .y = 0 .0f ;
@@ -237,6 +242,11 @@ void Airplane::crash() {
237
242
238
243
}
239
244
245
+ void Airplane::land () {
246
+ if (game->getWorld ()->getTarget ()->inRange (this ))
247
+ game->win ();
248
+ }
249
+
240
250
void Airplane::stopEngine () {
241
251
if (!engineOn){
242
252
return ;
Original file line number Diff line number Diff line change @@ -59,6 +59,7 @@ class Airplane : public Object {
59
59
static float dragCoefficient (float aoa);
60
60
61
61
void checkGroundCollision ();
62
+ void land ();
62
63
void crash ();
63
64
64
65
void updateSound ();
Original file line number Diff line number Diff line change @@ -153,6 +153,8 @@ bool Game::setup() {
153
153
}
154
154
155
155
void Game::startLevel (int index) {
156
+ currentLevelIndex = index;
157
+
156
158
world.reset (new World (this ));
157
159
currentLevel = levels[index].get ();
158
160
currentLevel->populate (world.get ());
@@ -192,9 +194,13 @@ bool Game::checkBreak() {
192
194
193
195
void Game::lose () {
194
196
cameraNode->translate (Ogre::Vector3 (0 .0f , 10 .0f , 50 .0f ));
195
- std::cerr << " FAIL\n " ;
196
197
}
197
198
199
+ void Game::win () {
200
+ startLevel ((currentLevelIndex + 1 ) % levels.size ());
201
+ }
202
+
203
+
198
204
bool Game::loadWavFile (ALuint * buffer, std::string file) {
199
205
200
206
#ifdef LINUX
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class Game {
37
37
Ogre::String levelPath;
38
38
Ogre::String audioPath;
39
39
std::vector<std::tr1::shared_ptr<const Level> > levels;
40
+ int currentLevelIndex;
40
41
const Level *currentLevel;
41
42
std::auto_ptr<World> world;
42
43
std::auto_ptr<Display> display;
@@ -67,6 +68,7 @@ class Game {
67
68
68
69
void startLevel (int index);
69
70
void lose ();
71
+ void win ();
70
72
private:
71
73
bool setup ();
72
74
bool loadWavFile (ALuint *buffer, std::string file);
Original file line number Diff line number Diff line change 2
2
3
3
#include " Airplane.h"
4
4
5
+ static const float RANGE = 50 .0f ;
6
+
5
7
Target::Target (Ogre::SceneNode * sceneNode) : sceneNode(sceneNode){
6
8
7
9
Ogre::SceneManager * sceneManager = sceneNode->getCreator ();
@@ -17,4 +19,8 @@ Target::~Target() { }
17
19
18
20
Ogre::Vector3 Target::displacement (const Airplane * airplane) const {
19
21
return sceneNode->getPosition () - airplane->getPosition ();
22
+ }
23
+
24
+ bool Target::inRange (const Airplane * airplane) const {
25
+ return airplane->getPosition ().squaredDistance (sceneNode->getPosition ()) < RANGE * RANGE;
20
26
}
Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ class Target{
8
8
~Target ();
9
9
10
10
Ogre::Vector3 displacement (const Airplane *) const ;
11
+ bool inRange (const Airplane *) const ;
11
12
};
You can’t perform that action at this time.
0 commit comments