-
Notifications
You must be signed in to change notification settings - Fork 1
/
PaddleAI.cpp
51 lines (42 loc) · 1.7 KB
/
PaddleAI.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
#include "PaddleAI.h"
PaddleAI::PaddleAI(Paddle *p, int room_size) {
paddle = p;
rS = room_size;
difficulty = 1.2;
minDetectionDistance = -250;
maxDetectionDistance = 2000;
}
Ogre::Vector3 PaddleAI::Seek(Ball *b) {
float distance = b->ballNode->getPosition().z - paddle->translationNode->getPosition().z;
if(distance > -minDetectionDistance && distance < maxDetectionDistance) {
Vector3 newPos = b->ballNode->getPosition();
newPos.z = -1000;
Vector3 bounds = paddle->translationNode->getPosition();
if( bounds.x > rS*1.2+97 || bounds.x < -rS*1.2-70 ||
bounds.y > rS-150 || bounds.y < -(rS-150)){
if(bounds.x > rS*1.2+97)
paddle->translationNode->setPosition(rS*1.2+97, bounds.y, bounds.z);
else if(bounds.x < -rS*1.2-70)
paddle->translationNode->setPosition(-rS*1.2-70, bounds.y, bounds.z);
else if(bounds.y > rS-150)
paddle->translationNode->setPosition(bounds.x, rS-150, bounds.z);
else if(bounds.y < rS-150)
paddle->translationNode->setPosition(bounds.x, -(rS-150), bounds.z);
}else{
Vector3 to_ball = b->ballNode->getPosition() - paddle->translationNode->getPosition();
to_ball.z = 0;
to_ball = to_ball.normalisedCopy();
paddle->translationNode->translate(to_ball*difficulty);
}
paddle->updateTransform();
}
}
void PaddleAI::setDifficulty(int d) {
difficulty = d;
}
void PaddleAI::setMinDetectionDistance(int v) {
minDetectionDistance = v;
}
void PaddleAI::setMaxDetectionDistance(int v) {
maxDetectionDistance = v;
}