-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasteroid.cpp
55 lines (45 loc) · 1.05 KB
/
asteroid.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
#include "asteroid.h"
#include "game.h"
#include "shard.h"
#include "spark.h"
extern Game * game;
Asteroid::Asteroid()
{
setPixmap(QPixmap(":/images/asteroid.png"));
setPos(game->gameWidth, (rand() % (game->gameHeight - 80)));
}
void Asteroid::move()
{
setPos(x() - motionSpeed, y());
if(x() < -80){
scene()->removeItem(this);
delete this;
}
}
void Asteroid::destroy()
{
if(game->enableParticles){
//Burst of asteroid shards
for(int i = 0; i < 30; i ++){
Shard * a = new Shard(x(), y(), true);
scene()->addItem(a);
connect(game, SIGNAL(frame()), a, SLOT(fall()));
}
//Burst of sparks
for(int j = 0; j < 40; j ++){
Spark * s = new Spark(x(), y(), 50);
scene()->addItem(s);
connect(game, SIGNAL(frame()), s, SLOT(fall()));
}
}
//Get rid of the asteroid
scene()->removeItem(this);
delete this;
}
void Asteroid::decreaseHealth()
{
health -= 1;
if(health == 0){
destroy();
}
}