-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBullet.cpp
More file actions
43 lines (39 loc) · 979 Bytes
/
Bullet.cpp
File metadata and controls
43 lines (39 loc) · 979 Bytes
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
#include "Bullet.h"
Bullet::Bullet(int x, int y, float bulletSpeed, std::string spritePath, double textureX, double textureY): pos(x,y),bulletSpeed(bulletSpeed),textureX(textureX),textureY(textureY) {
bulletTexture.loadFromFile(spritePath);
bulletSprite.setTexture(bulletTexture);
bulletSprite.setTextureRect(sf::IntRect(0,0,textureX,textureY));
bulletSprite.setScale(1.5, 1.5);
exists = true;
type = "normal";
}
bool Bullet::getExists() {
return exists;
}
void Bullet::move(bool state) {
if (!state) {
pos.set(bulletSpeed);
if (pos.pos[0] > 945) {
exists = false;
}
}
}
void Bullet::draw(sf::RenderWindow& window,bool state){
if (exists) {
bulletSprite.setPosition(pos.pos[0], pos.pos[1]);
window.draw(bulletSprite);
this->move(state);
}
}
void Bullet::toggleExists() {
exists = !exists;
}
void Bullet::setType(std::string t) {
type = t;
}
std::string Bullet::getType() {
return type;
}
sf::Sprite* Bullet::getSprite() {
return &bulletSprite;
}