Skip to content

Commit e727548

Browse files
author
Tom Stellard
committed
Merge branch 'master' of git://github.com/lukemaurer/cs510fly
2 parents 7b67287 + 2ea5c96 commit e727548

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed

Airplane.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "Airplane.h"
22

3+
#include "Target.h"
4+
#include "World.h"
5+
36
const Ogre::String Airplane::SCENE_NODE_NAME = "Airplane";
47

58
static const float MINIMUM_TIME_STEP = 0.01f;
@@ -220,6 +223,8 @@ void Airplane::checkGroundCollision() {
220223
if (state.position.y < Y_MIN) {
221224
if (state.velocity.y < -LANDING_ROD_MAX || getPitch() < LANDING_PITCH_MIN)
222225
crash();
226+
else
227+
land();
223228

224229
state.position.y = Y_MIN;
225230
state.velocity.y = 0.0f;
@@ -237,6 +242,11 @@ void Airplane::crash() {
237242

238243
}
239244

245+
void Airplane::land() {
246+
if (game->getWorld()->getTarget()->inRange(this))
247+
game->win();
248+
}
249+
240250
void Airplane::stopEngine() {
241251
if(!engineOn){
242252
return;

Airplane.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class Airplane : public Object {
5959
static float dragCoefficient(float aoa);
6060

6161
void checkGroundCollision();
62+
void land();
6263
void crash();
6364

6465
void updateSound();

Game.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ bool Game::setup() {
153153
}
154154

155155
void Game::startLevel(int index) {
156+
currentLevelIndex = index;
157+
156158
world.reset(new World(this));
157159
currentLevel = levels[index].get();
158160
currentLevel->populate(world.get());
@@ -192,9 +194,13 @@ bool Game::checkBreak() {
192194

193195
void Game::lose() {
194196
cameraNode->translate(Ogre::Vector3(0.0f, 10.0f, 50.0f));
195-
std::cerr << "FAIL\n";
196197
}
197198

199+
void Game::win() {
200+
startLevel((currentLevelIndex + 1) % levels.size());
201+
}
202+
203+
198204
bool Game::loadWavFile(ALuint * buffer, std::string file) {
199205

200206
#ifdef LINUX

Game.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Game {
3737
Ogre::String levelPath;
3838
Ogre::String audioPath;
3939
std::vector<std::tr1::shared_ptr<const Level> > levels;
40+
int currentLevelIndex;
4041
const Level *currentLevel;
4142
std::auto_ptr<World> world;
4243
std::auto_ptr<Display> display;
@@ -67,6 +68,7 @@ class Game {
6768

6869
void startLevel(int index);
6970
void lose();
71+
void win();
7072
private:
7173
bool setup();
7274
bool loadWavFile(ALuint *buffer, std::string file);

Target.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "Airplane.h"
44

5+
static const float RANGE = 50.0f;
6+
57
Target::Target(Ogre::SceneNode * sceneNode) : sceneNode(sceneNode){
68

79
Ogre::SceneManager * sceneManager = sceneNode->getCreator();
@@ -17,4 +19,8 @@ Target::~Target() { }
1719

1820
Ogre::Vector3 Target::displacement(const Airplane * airplane) const {
1921
return sceneNode->getPosition() - airplane->getPosition();
22+
}
23+
24+
bool Target::inRange(const Airplane * airplane) const {
25+
return airplane->getPosition().squaredDistance(sceneNode->getPosition()) < RANGE * RANGE;
2026
}

Target.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ class Target{
88
~Target();
99

1010
Ogre::Vector3 displacement(const Airplane *) const;
11+
bool inRange(const Airplane *) const;
1112
};

0 commit comments

Comments
 (0)