-
Notifications
You must be signed in to change notification settings - Fork 0
/
DivingMovingBehavior.h
43 lines (31 loc) · 1.01 KB
/
DivingMovingBehavior.h
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
#pragma once
#include "MovingBehavior.h"
class DivingMovingBehavior : public MovingBehavior {
public:
DivingMovingBehavior() {
this->SetDirection(Direction{ 2.25, -1 });
}
Position GetPostitionToAimTarget(
GameObject* source,
GameObject* target,
Position minStartPositions,
Position maxStartPositions
) override {
Position position;
position.y = (maxStartPositions.y + minStartPositions.y) / 2.0;
Position targetPos = target->GetPosition();
CSize targetSize = target->GetSize();
Position targetCenter = { targetPos.x + targetSize.cx / 2.0, targetPos.y + targetSize.cy / 2.0 };
double yDelta = position.y + source->GetSize().cy / 2.0 - targetCenter.y;
double xDelta = yDelta * (this->GetDirection().x / this->GetDirection().y) - source->GetSize().cx / 2.0;
double xPos = targetCenter.x + xDelta;
if (xPos < minStartPositions.x) {
xPos = minStartPositions.x;
}
else if (maxStartPositions.x < xPos) {
xPos = maxStartPositions.x;
}
position.x = xPos;
return position;
}
};