-
Notifications
You must be signed in to change notification settings - Fork 0
/
circle.cpp
62 lines (54 loc) · 1.56 KB
/
circle.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
56
57
58
59
60
61
62
#include "circle.h"
#include "gamecontroller.h"
#include <QPainter>
#include <QDebug>
Circle::Circle(GameController &controller):
controller(controller),
cur(0)
{
setData(GD_type, GO_Circle);
pixMap.load("://images/Circle.png");
int w = pixMap.width() * 0.7, h = pixMap.height() * 0.7;
path = new QPainterPath;
path->addEllipse(QRectF(-w/2, -h/2, w, h));
}
QRectF Circle::boundingRect() const
{
int w = pixMap.width() * 0.7, h = pixMap.height() * 0.7;
return QRectF(-w/2, -h/2, w, h);
}
void Circle::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option); Q_UNUSED(widget);
if(!pixMap.isNull()) {
painter->save();
qreal sc = qMin((1.0+controller.getRank()/10.0), 2.0);
painter->scale(0.7 * sc, 0.7 * sc);
int w = pixMap.width(), h = pixMap.height();
painter->rotate(cur);
painter->drawPixmap(QPoint(-w/2, -h/2), pixMap);
painter->restore();
}
}
void Circle::advance(int phace)
{
if(!phace) return;
cur = (cur + 15) % 360;
handleCollisions();
}
QPainterPath Circle::shape()
{
return *path;
}
void Circle::handleCollisions()
{
QList<QGraphicsItem *> collisions = collidingItems();
foreach (QGraphicsItem *item, collisions) {
auto t = item->data(GD_type);
if(t == GO_Ball || t == GO_Enemy || t == GO_BossBall) {
controller.removeItem(item);
controller.ariseCollision(item->pos());
return;
}
}
}