-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectile.cpp
More file actions
41 lines (35 loc) · 1.21 KB
/
Copy pathProjectile.cpp
File metadata and controls
41 lines (35 loc) · 1.21 KB
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
#include "Projectile.h"
#include "Entity.h"
#include <SFML/Graphics.hpp>
#include <cmath>
#include <iostream>
Projectile::Projectile() : Projectile(0, sf::Vector2(0.f, 0.f), sf::Color::Black, 0, sf::Vector2(0.f, 0.f), false, 0) {}
// Or statement to change the colour depending on if the projectile is a player or not
Projectile::Projectile(int r, sf::Vector2f position, sf::Color Colour, float speed,
sf::Vector2f destination, bool isPlayer, int damage)
: Entity(r, position, isPlayer ? sf::Color::Cyan : sf::Color::Red,
speed, destination, isPlayer),
damage(damage) {}
std::string Projectile::getType()
{
return "Projectile";
}
int Projectile::getDamage()
{
return damage;
}
void Projectile::move(){
Entity::move();
sf::Vector2f distance = getPosition() - destination;
// If the projectile is close enough to its destination, destroy it
if (std::sqrt(distance.x*distance.x + distance.y*distance.y) < speed/2)
{
isDestroyed = true;
}
}
void Projectile::handleCollision(Entity *entity) {
// Destroy projectile if it collides with any entity of different isPlayer status
if(Entity::checkCollision(entity)) {
isDestroyed = true;
}
}