-
Notifications
You must be signed in to change notification settings - Fork 0
/
skystar.cpp
52 lines (45 loc) · 1.48 KB
/
skystar.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
#include "skystar.h"
#include <QRandomGenerator>
#include <QPainter>
SkyStar::SkyStar()
{
size = QRandomGenerator::global()->bounded(1,3);
speed = QRandomGenerator::global()->bounded(1,6);
color = QColor(QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255));
rect = QRect(QRandomGenerator::global()->bounded(0,600),QRandomGenerator::global()->bounded(-120,700),size,size);
if(rect.top() < 0){
lives = 15;
}
else{
lives = 0;
}
lives = lives + QRandomGenerator::global()->bounded(25,40);
}
void SkyStar::reborn()
{
speed = QRandomGenerator::global()->bounded(1,6);
color = QColor(QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255),QRandomGenerator::global()->bounded(0,255));
rect = QRect(QRandomGenerator::global()->bounded(0,600),QRandomGenerator::global()->bounded(-120,700),this->size,this->size);
if(rect.top() < 0){
lives = 15;
}
else{
lives = 0;
}
lives = lives + QRandomGenerator::global()->bounded(25,40);
}
void SkyStar::move()
{
rect = QRect(rect.left(),rect.top()+qRound(speed),rect.width(),rect.height());
this-> hurt();
}
QColor SkyStar::getColor()
{
return color;
}
void SkyStar::draw(std::shared_ptr<QPainter> painter)
{
QBrush brush(this->getColor());
painter->setBrush(brush);
painter->drawRect(this->rect);
}