forked from tstellar/cs510fly
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWorld.cpp
73 lines (56 loc) · 2.03 KB
/
World.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "World.h"
#include "Airplane.h"
#include "Target.h"
#include "Enemy.h"
#include "BasicEnemy.h"
const Ogre::String World::GROUND_NODE_NAME = "Ground";
World::World(Game * game) : Object(game, game->getSceneManager()->getRootSceneNode()), player(NULL), target(NULL) {
}
World::~World() {
game->getSceneManager()->clearScene();
if (player != NULL)
delete player;
if (target != NULL)
delete target;
for (std::vector<Enemy *>::iterator it = enemies.begin(); it != enemies.end(); it++)
delete *it;
}
Ogre::SceneNode * World::getRootNode() {
return getSceneNode();
}
const Ogre::SceneNode * World::getRootNode() const {
return getSceneNode();
}
Ogre::SceneNode * World::newNode(const Ogre::Vector3& position, const Ogre::Quaternion& orientation, const Ogre::String& name) {
return getRootNode()->createChildSceneNode(name, position, orientation);
}
Airplane * World::addPlayer(const AirplaneState& state) {
assert(player == NULL);
Ogre::SceneNode * playerNode = newNode(state.position, state.orientation, "Player");
player = new Airplane(game, playerNode, state);
return player;
}
Target * World::addTarget(const Ogre::Vector3& position) {
assert(target == NULL);
Ogre::SceneNode * targetNode = newNode(position, Ogre::Quaternion::IDENTITY, "Target");
target = new Target(targetNode);
return target;
}
Enemy * World::addEnemy(const AirplaneState& state, const Ogre::String& name) {
Ogre::SceneNode * enemyNode = newNode(state.position, state.orientation, name);
Enemy * enemy = new BasicEnemy(game, enemyNode, state.position, name);
enemies.push_back(enemy);
return enemy;
}
void World::update(float dt) {
std::vector<Enemy*>::iterator it;
for (it = enemies.begin(); it != enemies.end(); ++it)
(*it)->update(player, dt);
player->update(dt);
//collision detection
for (it = enemies.begin(); it != enemies.end(); ++it){
if((*it)->inRange(player->getPosition())){
player->stopEngine();
}
}
}