-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBullet.cpp
151 lines (119 loc) · 5.01 KB
/
Bullet.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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#include "Bullet.h"
namespace SSJ{
Bullet::Bullet(){
//this->setMapPosition(this->ownerPosition);
this->sprite.AddTexture("bullet", "./bullet.png");
/*Animation *pocisk = new Animation("pocisk");
pocisk->AddFrame("./bullet.png");
sprite.AddAnimation(pocisk);*/
/*if(this->blastFire){
Animation * animation = new Animation("wybuch");
animation->setAlphaMask(sf::Color::Black);
//animation->setSmooth(true);
// animation->setDefaultFrameBreakTime(sf::milliseconds(300));
animation->setDefaultFrame(0);
animation->AddFrame("./sprite/wybuchAnimacja/blast01.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast02.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast03.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast1.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast2.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast3.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast4.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast5.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast6.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast7.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast8.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast9.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast10.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast11.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast12.png", sf::milliseconds(50));
animation->AddFrame("./sprite/wybuchAnimacja/blast13.png", sf::milliseconds(50));
animation->setAnimateOnce(true);
this->sprite.AddAnimation(animation);
}*/
//this->sprite.ActiveAnimation("pocisk");
this->setOwnerPosition(DataContainer::MainPlayer->getMapPosition());
this->wasFirst = false;
}
Bullet::~Bullet(){
}
void Bullet::draw(){
this->sprite.getSprite()->setPosition(this->getScreenPosition().x, this->getScreenPosition().y);
DataContainer::window->draw(*(this->sprite.getSprite()));
}
void Bullet::update(){
this->getSprite()->Update();
if( (pow(this->getMapPosition().x - ownerPosition.x, 2) + pow(this->getMapPosition().y - ownerPosition.y, 2)) <= pow(this->range, 2)){
this->setMapPosition(CalcNewPosition());
}
this->sprite.getSprite()->setOrigin(this->sprite.getSprite()->getTexture()->getSize().x/2,this->sprite.getSprite()->getTexture()->getSize().y/2 );
this->sprite.getSprite()->setRotation(this->angle.getDegrees()-180);
}
void Bullet::Blast(){
this->sprite.getSprite()->setPosition(this->getScreenPosition().x, this->getScreenPosition().y);
DataContainer::window->draw(*(this->sprite.getSprite()));
this->getSprite()->getAnimation("wybuch")->start();
}
void Bullet::Hit(){
}
Point Bullet::CalcNewPosition(){
Point newPosition = this->getMapPosition();
SSJ::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;
}
void Bullet::setOwnerPosition(const Point ownerPosition){
this->ownerPosition = ownerPosition;
}
void Bullet::setRange(const int range){
this->range = range;
}
void Bullet::setName(const string name){
this->name = name;
}
void Bullet::setDamage(const int damage){
this->damage = damage;
}
void Bullet::setBlastFire(const bool blastFire){
this->blastFire = blastFire;
}
void Bullet::setBlastRange(const int blastRange){
this->blastRange = blastRange;
}
WeaponType Bullet::getType() const
{
return type;
}
void Bullet::setType(const WeaponType &value)
{
type = value;
}
void Bullet::SynchronizationObject(Json::Value jsonObject)
{
if(!wasFirst){
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(_angle))){
this->angle = jsonObject[_J(_angle)].asFloat();
}
if(jsonObject.isMember(_J(_targetAngle))){
this->targetAngle = jsonObject[_J(_targetAngle)].asFloat();
}
if(jsonObject.isMember(_J(_syncId))){
this->syncId = jsonObject[_J(_syncId)].asInt();
}
wasFirst = true;
}
}
}