-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPointAnimation.cpp
More file actions
59 lines (46 loc) · 1.24 KB
/
Copy pathPointAnimation.cpp
File metadata and controls
59 lines (46 loc) · 1.24 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 "PointAnimation.h"
#include <Windows.h>
using namespace std;
using namespace sf;
PointAnimation::PointAnimation()
:lifetime(5)
{
}
PointAnimation::~PointAnimation()
{
}
void PointAnimation::add(string n_label, Vector2f n_pos)
{
data.push_back(new Point(n_label, n_pos));
data.back() -> clock_points_food.restart();
}
void PointAnimation::update()
{
for (unsigned int i = 0; i < data.size(); i++)
{
if (data[i]->clock_points_food.getElapsedTime().asSeconds() > lifetime)
{
delete data[i];
data.erase(data.begin() + i);
i--;
continue;
}
}
}
void PointAnimation::drawPoint(RenderWindow &window)
{
for (unsigned int i = 0; i < data.size(); i++)
{
Vector2f labelPos;
float time = data[i]->clock_points_food.getElapsedTime().asSeconds();
labelPos.x = data[i]->pos.x + sin(time * 3)*(10 - time / 2) * 5;
labelPos.y = data[i]->pos.y - time * 15;
float scaleFactor = 1.f;
if (time > 0.5f * lifetime) scaleFactor = (lifetime - time) / (lifetime * 0.5f );
data[i]->label2.setString(data[i]->label);
data[i]->label2.setPosition(labelPos);
data[i]->label2.setColor(Color(255, 0, 0, static_cast<Uint8>(255.f * scaleFactor)));
data[i] -> label2.setScale(scaleFactor, scaleFactor);
window.draw(data[i]->label2);
}
}