-
Notifications
You must be signed in to change notification settings - Fork 9
/
WeaponPostEffects.cpp
55 lines (54 loc) · 1.32 KB
/
WeaponPostEffects.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "WeaponPostEffects.h"
#include "Tank.h"
#include "utilities.h"
#include "Application.h"
Explosion::Explosion(AnimationType animType,sf::Vector2f pos,int r) :
WorldObject(WeaponPostEffectType),
expCircle(r),
expAnim(AnimationCreator::create(animType,pos))
{
expCircle.setOrigin(r,r);
expCircle.setPosition(pos);
Application::getGame().incCounter();
}
Explosion::~Explosion()
{
Application::getGame().decCounter();
}
void Explosion::handleCollision(WorldObject &b)
{
switch(b.type)
{
case WorldObject::TankType:
{
Tank &t = static_cast<Tank&>(b);
bool &tankActed = tanksActedOn[&t];
if(tankActed == false && intersects(expCircle,t.getTankRect()))
{
sf::Vector2f vec = expCircle.getPosition() - t.getTankRect().getPosition();
float blowPower = 50*(1-std::hypot(vec.x,vec.y)/(expCircle.getRadius()+t.getTankRect().getLocalBounds().width/2));
t.weapAct(blowPower);
tankActed = true;
}
}
break;
default:
break;
}
}
void Explosion::draw(sf::RenderTarget &target)
{
if(expAnim->selfDestruct == true)
{
selfDestruct = true;
}
expAnim->draw(target);
}
void Explosion::step(float dt)
{
expAnim->step(dt);
}
void Explosion::reset()
{
selfDestruct = true;
}