-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDamagableObject.cpp
More file actions
112 lines (87 loc) · 2.2 KB
/
Copy pathDamagableObject.cpp
File metadata and controls
112 lines (87 loc) · 2.2 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "DamagableObject.h"
DamagableObject::DamagableObject()
{
health_ = 0;
damage_ = {};
type_ = WALL;
}
DamagableObject::DamagableObject(ObjectType type, int health, DamageMap damage)
{
type_ = type;
health_ = health;
damage_ = damage;
}
ObjectType DamagableObject::getType()
{
return type_;
}
int DamagableObject::typeDamage(ObjectType type)
{
if (damage_.count(type) == 0){
return 0;
}
return damage_[type];
}
void DamagableObject::setHealth(int health)
{
health_ = health;
if (health_ <= 0){
emit death();
emit disactivate();
}
//qDebug() << this << " " << health_;
}
void DamagableObject::addHealth(int param)
{
setHealth(getHealth() + param);
}
int DamagableObject::getHealth()
{
return health_;
}
BodyAssociated::BodyAssociated(AbstractBody * body, ObjectType type, int health, DamageMap damage) : DamagableObject(type,health,damage)
{
body_ = body;
QObject::connect(this,SIGNAL(death()),body,SLOT(disactivate()));
QObject::connect(body_,&Activity::disactivated,this,&Activity::disactivate);
}
QPointF BodyAssociated::getPosition() const
{
return body_->getPosition();
}
double BodyAssociated::getRadius() const
{
return body_->getRadius();
}
QPointF BodyAssociated::collisionCenter(const DamagableObject &) const
{
return body_->getPosition();
}
AbstractBody *BodyAssociated::getBody()
{
return body_;
}
CurveAssociated::CurveAssociated(PolynomCurve * curve, ObjectType type, int health, DamageMap damage) : DamagableObject(type,health,damage)
{
curve_ = curve;
QObject::connect(this,&DamagableObject::death,curve,&PolynomCurve::disactivate );
QObject::connect(curve_,&Activity::disactivated,this,&Activity::disactivate);
}
QPointF CurveAssociated::getPosition() const
{
return QPoint(0,0);
}
double CurveAssociated::getRadius() const
{
return 0;
}
QPointF CurveAssociated::collisionCenter(const DamagableObject & obj) const
{
double radius = obj.getRadius();
QPointF pos = obj.getPosition();
std::optional<QPointF> param = curve_->nearestTangent(pos);
if (!param.has_value()){
return QPointF(radius*3,radius*3) + pos;
}
return param.value();
}