-
Notifications
You must be signed in to change notification settings - Fork 2
/
Enemy.cpp
30 lines (24 loc) · 1.06 KB
/
Enemy.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
#include "Enemy.h"
static const float DEATH_RANGE_SQUARED = 100.0f;
Enemy::Enemy(Game * const game) : game(game) { }
bool Enemy::inRange(const Ogre::Vector3& pos) {
return pos.squaredDistance(getPosition()) <= DEATH_RANGE_SQUARED;
}
bool Enemy::posBelow(const Ogre::Vector3& pos) {
return pos.y < getPosition().y;
}
bool Enemy::posLeft(const Ogre::Vector3& pos) {
return pos.x < getPosition().x;
}
bool Enemy::posInFront(const Ogre::Vector3& pos) {
const Ogre::Vector3& enemyPos = getPosition();
/* These vectors only need two components, but I am using a Vector3 here
* because the Vector3 class has better builtin fucntions and I am lazy.
*/
Ogre::Vector3 enemyToPlayer = Ogre::Vector3(
pos.x - enemyPos.x,
pos.z - enemyPos.z, 0);
Ogre::Vector3 enemyPosXZ = Ogre::Vector3(enemyPos.x, enemyPos.z, 0);
const Ogre::Radian& angleBetween = enemyToPlayer.angleBetween(enemyPosXZ);
return Ogre::Math::Abs(angleBetween) < Ogre::Radian(Ogre::Math::HALF_PI);;
}