-
Notifications
You must be signed in to change notification settings - Fork 2
/
Bullet.cpp
36 lines (29 loc) · 891 Bytes
/
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
#include "Bullet.h"
Bullet::Bullet(int _x, int _y, float _angle, sf::Vector2i _mousepos) :
dynamicEntity("resources/graphics/Items/bullet.png", _x, _y)
{
angle = _angle;
sprite.setRotation(angle);
mousepos = _mousepos;
bulletcount++;
}
void Bullet::extraBodySettings()
{
body->SetFixedRotation(true);
body->SetTransform(b2Vec2(x/30, y/30), angle*(b2_pi/180));
body->SetBullet(true);
body->SetGravityScale(0.f);
body->SetUserData((void*)++bulletcount);
b2Fixture* f = body->GetFixtureList();
f->SetUserData((void*)"bullet");
}
void Bullet::update(double t)
{
float x = body->GetPosition().x;
float y = body->GetPosition().y;
sf::IntRect rect = sprite.getTextureRect();
setPosition(x*scale, y*scale);
//std::cout<<"("<<mousepos.x<<","<<mousepos.y<<")"<<std::endl;
body->ApplyForceToCenter(b2Vec2((mousepos.x-330)/2,(mousepos.y-222)/2));
}
int Bullet::bulletcount = 0;