-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparticle.cpp
More file actions
73 lines (56 loc) · 1.82 KB
/
Copy pathparticle.cpp
File metadata and controls
73 lines (56 loc) · 1.82 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "particle.h"
Particle::Particle(const Vec2 pos_, const Vec2 vel, const float rad_, const float mass_, const int health, const QColor initColor_)
: pos(pos_), velocity(vel), rad(rad_), mass(mass_), expPos(pos_), initColor(initColor_), maxCollisions(health), color(initColor_), nbCollisions(0) {}
Particle::Particle()
: pos(Vec2{0,0}), velocity(Vec2{0,0}), mass(0.0), rad(1.0), expPos(Vec2{0,0}), maxCollisions(50), color(Qt::gray), nbCollisions(0) {}
const Vec2 Particle::getPos() const {
return pos;
}
void Particle::setPos(const Vec2 newPos) {
this->pos = newPos;
}
const Vec2 Particle::getVelocity() const {
return velocity;
}
void Particle::setVelocity(const Vec2 newVel){
this->velocity=newVel;
}
const Vec2 Particle::getExpPos() const {
return expPos;
}
void Particle::setExpPos(const Vec2 newExpPos) {
this-> expPos = newExpPos;
}
const float Particle::getX() const {
return pos.getX();
}
const float Particle::getY() const {
return pos.getY();
}
const float Particle::getMass() const {
return mass;
}
const float Particle::getRad() const {
return rad;
}
const QColor Particle::getColor() const {
return color;
}
void Particle::updateColor() {
const float coeff = float(nbCollisions)/float(maxCollisions);
const int red = round(initColor.red()+coeff*(destrColor.red()-initColor.red()));
const int green = round(initColor.green()+coeff*(destrColor.green()-initColor.green()));
const int blue = round(initColor.blue()+coeff*(destrColor.blue()-initColor.blue()));
color = QColor(red, green, blue);
}
void Particle::addCollision() {
nbCollisions++;
updateColor();
}
void Particle::removeCollision() {
nbCollisions = std::max(0, nbCollisions-2);
updateColor();
}
const bool Particle::checkNbCollisions() const{
return nbCollisions > maxCollisions;
}