-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectile.cpp
31 lines (26 loc) · 867 Bytes
/
Projectile.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
//
// Created by samuel on 12/6/21.
//
#include "Projectile.h"
int Projectile::count = 0;
Projectile::Projectile(sf::Texture &t, float x, float y, float angle, float radius, float speed): Object(x, y, angle, radius), speed(speed) {
count++;
sprite.setTexture(t);
spriteWidth = t.getSize().x;
spriteHeight = t.getSize().y;
sprite.setOrigin(spriteWidth / 2, spriteHeight / 2);
name = "projectile";
coordsDelta = {0, 0};
}
int& Projectile::GetCount() const {
return count;
}
void Projectile::update() {
coordsDelta.first = std::cos(angle * DTR) * speed;
coordsDelta.second = std::sin(angle * DTR) * speed;
coords.first += coordsDelta.first;
coords.second += coordsDelta.second;
if(coords.first > windowWidth || coords.first < 0 || coords.second > windowHeight || coords.second < 0) {
life = false;
}
}