-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspark.cpp
45 lines (33 loc) · 879 Bytes
/
spark.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
#include "spark.h"
#include <QGraphicsRectItem>
#include <math.h>
#include "game.h"
#include <QDebug>
extern Game * game;
Spark::Spark(int x, int y, int spread)
{
setColor();
setPen(Qt::NoPen);
double r = (rand() % (spread * 2)) - spread;
double theta = rand() % 360;
setRect(x + sin(theta) * r + 38, y + cos(theta) * r + 38, 4, 4);
xSpeed = (rand() % (speedSpread * 1000)) / 500 - speedSpread + xSpeedOffset;
ySpeed = (rand() % (speedSpread * 1000)) / 500 - speedSpread;
setZValue(39);
}
void Spark::setColor()
{
setBrush(QColor(-pow(255, 0.02 * age) + 255, -5.1 * age + 255, pow(255, -age/50.0 + 1)));
}
void Spark::fall()
{
setPos(x() + xSpeed, y() + ySpeed);
ySpeed += yAccel;
age += 1;
if(age > j || isObscured()){
scene()->removeItem(this);
delete this;
}else{
setColor();
}
}