-
Notifications
You must be signed in to change notification settings - Fork 1
/
Brick.cpp
80 lines (57 loc) · 1.52 KB
/
Brick.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "Brick.h"
Brick::Brick(QGraphicsItem *parent)
{
QGraphicsItem::setParentItem(parent);
width=0.8;
height=0.4;
color=QColor(156, 44, 44); // QColor(qrand() % 256, qrand() % 256, qrand() % 256);
flagToRemove=false;
}
QRectF Brick::boundingRect() const
{
qreal halhWidth=width/2.0;
qreal halhHeight=height/2.0;
return QRectF(-halhWidth, -halhHeight, width, height);
}
QPainterPath Brick::shape() const
{
QPainterPath path;
path.addRect( boundingRect() );
return path;
}
void Brick::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
// Заливка
painter->setBrush(color);
// Граница
QPen pen;
pen.setWidth(0.1);
pen.setBrush(Qt::white);
painter->setPen(pen);
painter->drawRect( boundingRect() );
}
void Brick::putToPhysicsWorld()
{
b2BodyDef bodyDef;
bodyDef.type=b2_staticBody;
bodyDef.position.Set(this->x(), this->y());
b2Body *body=physicsWorld->CreateBody(&bodyDef);
b2PolygonShape polygonShape;
polygonShape.SetAsBox(width/2.0, height/2.0);
body->CreateFixture(&polygonShape, 0.0);
// Запоминается настроенное тело
physicsBody=body;
}
void Brick::setSize(const qreal iWidth, const qreal iHeight)
{
width=iWidth;
height=iHeight;
}
void Brick::setToRemove()
{
flagToRemove=true; // Кирпич подготавливается к уничтожению с игрового поля
}
bool Brick::isToRemove() const
{
return flagToRemove;
}