-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
107 lines (81 loc) · 2.72 KB
/
Copy pathBullet.cpp
File metadata and controls
107 lines (81 loc) · 2.72 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
#include "Bullet.h"
namespace SSJServer{
Bullet::Bullet(){
this->bulletPosition = ownerPosition;
}
Bullet::~Bullet(){
}
void Bullet::update(){
if( (pow(this->getMapPosition().x - ownerPosition.x, 2) + pow(this->getMapPosition().y - ownerPosition.y, 2)) <= pow(this->range, 2)){
this->checkColision();
this->setMapPosition(CalcNewPosition());
this->activity = true;
}
else{
if(this->blastFire){
this->blastFire = false;
}
this->activity = false;
this->setSyncNow();
}
}
void Bullet::Blast(){
}
void Bullet::Hit(){
}
Point Bullet::CalcNewPosition(){
Point newPosition = this->getMapPosition();
Degrees tempDegrees = this->angle;
float s = this->velocity *100 * DataContainer::DeltaTime.asSeconds();
float px = sin(tempDegrees.getRadians()) * s;
float py = cos(tempDegrees.getRadians()) * s;
newPosition.x += px;
newPosition.y -= py;
return newPosition;
}
WeaponType Bullet::getType() const
{
return type;
}
void Bullet::setType(const WeaponType &value)
{
type = value;
}
void Bullet::checkColision()
{
map<string, Object*>::iterator it; // teraz it jest wskaznikiem do zbioru
for( it=DataContainer::PlayerList.begin(); it!=DataContainer::PlayerList.end(); ++it )
// cout <<it->second->syncId << " " << this->OwnerId << endl;
if(it->second->syncId != this->OwnerId){
if(Helpers::checkCollision(sf::FloatRect(this->mapPosition.x,this->mapPosition.y, 2.f,2.f),
sf::FloatRect(it->second->getMapPosition().x,it->second->getMapPosition().y,80.f,80.f))){
((DynamicObject*)it->second)->decreaseHp(10);
}
}
// cout << "?" << endl;
}
Degrees Bullet::getAngle() const
{
return angle;
}
void Bullet::setAngle(const Degrees &value)
{
angle = value;
}
Json::Value Bullet::serialize()
{
Json::Value object;
object[_J(_objectName)] = _Bullet;
object[_J(_mapPositionX)] = this->getMapPosition().x;
object[_J(_mapPositionY)] = this->getMapPosition().y;
object[_J(_activity)] = this->activity;
object[_J(_angle)] = this->getAngle().getDegrees();
object[_J(_targetAngle)] = this->targetAngle.getDegrees();
object[_J(_name)] = this->name;
object[_J(_weaponType)] = this->getType();
object[_J(_syncId)] = this->syncId;
if(this->syncEventActive)
this->syncNow = false;
return object;
}
}