-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bullet.h
32 lines (27 loc) · 799 Bytes
/
Bullet.h
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
#pragma once
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <cmath>
const double PIE = acos(-1.0);
class Bullet
{
public:
sf::Sprite object;
double bulletMulX;
double bulletMulY;
double dis;
Bullet(sf::Texture *texture, sf::Vector2f position, sf::Vector2i click)
{
object.setTexture(*texture);
object.setScale(.06, .06);
object.setPosition(position);
bulletMulX = click.x - position.x;
bulletMulY = click.y - position.y;
dis = sqrt(pow(bulletMulX, 2) + pow(bulletMulY, 2)); //sets bullet y asix and x axis velocity
bulletMulX /= dis;
bulletMulY /= dis;
float angle = atan((click.y - position.y) / (click.x - position.x)) * 180 / PIE;
object.setRotation(angle); //sets bullet texture rotation based on click location
}
~Bullet() {}
};