-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRockProjectile.cpp
More file actions
59 lines (49 loc) · 1.75 KB
/
Copy pathRockProjectile.cpp
File metadata and controls
59 lines (49 loc) · 1.75 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "RockProjectile.hpp"
#include "Player.hpp"
RockProjectile::RockProjectile(Map* map, sf::Vector2f pos, directions dir) : Weapon(map, pos, dir) {
_sprite.setTexture(Resources::overEnemies);
_description = Resources::descriptions[rockProjDescription];
_sprite.setTextureRect(_description[0][0]);
_bounds = RockProjectile::bounds();
_damage = 0.5;
_speed = sf::Vector2f(40,40);
_angle = 0;
_transform = sf::Transform::Identity;
_timerToDead = -1;
_collisionMask = collisionMapMask::water | collisionMapMask::ground | collisionMapMask::passage;
}
RockProjectile::~RockProjectile() {}
void RockProjectile::update(float deltaTime) {
Weapon::update(deltaTime);
_transform = sf::Transform::Identity;
_angle += 90*deltaTime;
sf::IntRect bounds = RockProjectile::bounds();
_transform.rotate(_angle,
_sprite.getPosition().x +bounds.left+bounds.width/2,
_sprite.getPosition().y +bounds.top+bounds.height/2);
if (_timerToDead > 0 && _timerToDead < deltaTime) _dead = true;
_timerToDead -= deltaTime;
}
void RockProjectile::draw(sf::RenderTarget* target) {
target->draw(_sprite, _transform);
}
void RockProjectile::hit() {
_dead = true;
}
void RockProjectile::intersectsWith(Collisionable* c) {
Player* player = dynamic_cast<Player*>(c);
if (player != nullptr) {
if (!counterDirection(getDirection(),player->getDirection()) || player->isAttacking()) hit();
else {
_speed = getRandBounce(_speed.x,_dir);
_dir = directions::none;
_timerToDead = 0.5;
_bounds = sf::IntRect(0,0,0,0);
}
return;
}
Weapon::intersectsWith(c);
}
sf::IntRect RockProjectile::bounds() {
return sf::IntRect(1,2,6,6);
}