-
Notifications
You must be signed in to change notification settings - Fork 0
/
particle.cpp
63 lines (60 loc) · 1.61 KB
/
particle.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
56
57
58
59
60
61
62
63
#include "particle.h"
#include <cmath>
#include <windows.h>
#include "util.h"
namespace Tmpl8
{
void Particle::update(float _dt)
{
pos += vel * _dt;
lifetime -= _dt;
switch (type)
{
case 0: // enemy splatter
{
vel *= pow(0.00015f, _dt); // dampening
break;
}
case 1: // powerup consumed
{
vel *= pow(0.0005f, _dt); // dampening
break;
}
case 2: // player heal
{
vel.y -= 50.0f * _dt;
break;
}
}
}
void Particle::render(const Surface* _screen) const
{
//sprite->DrawScaled(pos.x, pos.y, size.x * scale, size.y * scale, _screen, false); // draw sprite centered around point
switch (type) {
case 0: // enemy splatter
{
const float alpha = min(1.0f, lifetime) * 0.9f;
_screen->CircleShadow({ pos.x - 5, pos.y + 5 }, scale * radius * 1.3f, 0.25f * alpha * 2);
const int color = pastels[id % static_cast<int>(pastels.size())];
_screen->CircleFull(pos, 0, scale * radius * 1.3f, color, alpha * 2);
break;
}
case 1: // powerup consumed
{
const float alpha = min(1.0f, lifetime) * 0.9f;
_screen->CircleShadow({ pos.x - 5, pos.y + 5 }, scale * radius * 1.3f, 0.25f * alpha);
const int color = rgbCombine(randint(0xdd, 0xff), randint(0xcd, 0xe7), 0x00);
_screen->CircleFull(pos, 0, scale * radius * 1.3f, color, alpha);
break;
}
case 2: // player heal
{
const float alpha = min(1.0f, lifetime) * 0.85f;
_screen->CircleShadow({ pos.x - 5, pos.y + 5 }, scale * radius * 1.3f, 0.25f * alpha);
constexpr int color = 0xe80000;
_screen->CircleFull(pos, 0, scale * radius * 1.3f, color, alpha);
break;
}
}
}
};