This repository was archived by the owner on Sep 29, 2024. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathship.cpp
More file actions
63 lines (59 loc) · 1.86 KB
/
Copy pathship.cpp
File metadata and controls
63 lines (59 loc) · 1.86 KB
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
#include "ship.h"
#include "service_locator.h"
#include "emath.h"
Ship::Ship(sf::Vector2f position, unsigned int hp, unsigned int radarRadious, unsigned int weaponRadious, unsigned int attack, unsigned int rateOfFire, float mass,
unsigned int speed) :
Enemy(servLoc.getResourceManager()->getTextureRect("ship"), position, attack, rateOfFire, weaponRadious, 6666, speed, mass, hp),
radarRadious(radarRadious), weaponRadious(weaponRadious)
{
this->hp = hp;
this->fullHP = hp;
}
void Ship::updateAI()
{
Enemy::updateAI();
sf::Vector2f targetVec = target - representation.getPosition();
float targetVecLen = ezo::vecLength(targetVec.x, targetVec.y);
switch(state)
{
case State::stay:
if(targetVecLen < radarRadious)
{
if(hp < fullHP/2)
state = State::escape;
else if(targetVecLen < weaponRadious)
state = State::fire;
else
state = State::chase;
}
else
steeringMode = SteeringMode::Stay;
break;
case State::escape:
if(targetVecLen > radarRadious)
state = State::stay;
steeringMode = SteeringMode::Flee;
break;
case State::chase:
if(targetVecLen > radarRadious)
state = State::stay;
else if(hp < fullHP/2)
state = State::escape;
else if(targetVecLen < weaponRadious)
state = State::fire;
else
steeringMode = SteeringMode::Seek;
break;
case State::fire:
if(targetVecLen > radarRadious)
state = State::stay;
else if(hp < fullHP/2)
state = State::escape;
else if(targetVecLen > weaponRadious / 3)
state = State::chase;
else
steeringMode = SteeringMode::Stay;
fire();
break;
}
}