-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinteractiveobject.cpp
69 lines (59 loc) · 1.63 KB
/
interactiveobject.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "interactiveobject.h"
namespace SSJ {
InteractiveObject::InteractiveObject() : Object()
{
this->maxHP = 100;
this->hp = 100;
}
void InteractiveObject::setHP(const int hp)
{
if(this->maxHP >= hp && hp >= 0)
this->hp = hp;
}
void InteractiveObject::setMaxHP(const int hp)
{
this->maxHP = hp;
}
void InteractiveObject::addHP(int hp)
{
if(this->maxHP <= this->hp+hp && this->hp+hp >= 0)
this->hp += hp;
}
void InteractiveObject::subHP(int hp)
{
if(this->maxHP <= this->hp-hp && this->hp-hp >= 0)
this->hp -= hp;
}
int InteractiveObject::getHP() const
{
return this->hp;
}
int InteractiveObject::getMaxHP() const
{
return this->maxHP;
}
bool InteractiveObject::isDead() const{
if(this->hp == 0)
return true;
else
return false;
}
void InteractiveObject::SynchronizationObject(Json::Value jsonObject)
{
if(jsonObject.isMember(_J(_mapPositionX))){
this->mapPosition.x = jsonObject[_J(_mapPositionX)].asFloat();
}
if(jsonObject.isMember(_J(_mapPositionY))){
this->mapPosition.y = jsonObject[_J(_mapPositionY)].asFloat();
}
if(jsonObject.isMember(_J(_activity))){
this->activity = jsonObject[_J(_activity)].asBool();
}
if(jsonObject.isMember(_J(_hp))){
this->hp = jsonObject[_J(_hp)].asUInt();
}
if(jsonObject.isMember(_J(_maxHP))){
this->maxHP = jsonObject[_J(_maxHP)].asUInt();
}
}
}