-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsuperball.cpp
53 lines (47 loc) · 1.21 KB
/
superball.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
#include "superball.h"
#include"abstractbrick.h"
#include<QPainter>
const QImage SuperBall::outlook(":/Ball/image/ball/superBall.png");
SuperBall::SuperBall(QGraphicsItem* parent):
AbstractBall(1,parent),
collidingOutLookActiveTime(0)
{
}
QRectF SuperBall::boundingRect() const
{
return QRectF(-10,-10,20,20);
}
void SuperBall::handleCollision()
{
bool collidedWithBrick=false;
for(auto& i:this->collidingItems(Qt::IntersectsItemBoundingRect))
{
if(dynamic_cast<AbstractBrick*>(i))
{
static_cast<AbstractBrick*>(i)->deleteLater();
collidedWithBrick=true;
}
}
if(!collidedWithBrick)
{
AbstractBall::handleCollision();
}
}
void SuperBall::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
static QBrush brush(outlook.scaled(this->boundingRect().size().toSize()));
Q_UNUSED(option)
Q_UNUSED(widget)
if(collidingOutLookActiveTime>0)
{
painter->setOpacity(0.5);
collidingOutLookActiveTime--;
}
else if(collidingState==collided)
{
collidingOutLookActiveTime=20;
}
painter->setRenderHint(QPainter::Antialiasing,true);
painter->setBrushOrigin(this->boundingRect().topLeft());
painter->fillRect(this->boundingRect(),brush);
}