-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.h
55 lines (46 loc) · 1.04 KB
/
particle.h
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
#pragma once
# include "vector2.h"
# include "atlas.h"
# include "camera.h"
# include "util.h"
class Particle
{
public:
Particle() = default;
Particle(const Vector2& position, Atlas* atlas, int lifespan)
:position(position), atlas(atlas), lifespan(lifespan) {}
~Particle() = default;
void set_atlas(Atlas* atlas) {
this->atlas = atlas;
}
void set_position(const Vector2& position) {
this->position = position;
}
void set_lifespan(int ms) {
lifespan = ms;
}
bool check_valid() const{
return valid;
}
void on_update(int delta) {
timer += delta;
if (timer >= lifespan) {
timer = 0;
idx_frame++;
if (idx_frame >= atlas->get_size() - 1) {
idx_frame = atlas->get_size() - 1;
valid = false;
}
}
}
void on_draw(const Camera& camera)const {
ut::putimage_alpha(camera, position.x, position.y, atlas->get_image(idx_frame));
}
private:
int timer = 0;
int lifespan = 0;
int idx_frame = 0;
Vector2 position;
bool valid = true;
Atlas* atlas = nullptr;
};