4 Element::Element(SCENE
* scene
, const QPoint
& point
)
5 : m_position(point
- size() / 2.0)
8 m_item
= new KGameCanvasRectangle(Qt::red
, QSize(size().x(), size().y()), scene
);
9 m_item
->moveTo(point
- size() / 2);
12 m_item
= scene
->addRect(QRect(QPoint(0, 0), QSize(size().x(), size().y())), Qt::NoPen
, Qt::red
);
13 m_item
->setPos(point
- size() / 2);
16 m_velocity
.setX(((double)rand() / RAND_MAX
) * 0.1);
17 m_velocity
.setY(((double)rand() / RAND_MAX
) * 0.1);
20 Element::~Element() { delete m_item
; }
22 QPointF
Element::position() const { return m_position
; }
24 QPointF
Element::velocity() const { return m_velocity
; }
26 void Element::setPosition(const QPointF
& pos
) {
29 m_item
->moveTo(m_position
.toPoint() - size() / 2);
31 m_item
->setPos(m_position
- size() / 2);
35 void Element::setVelocity(const QPointF
& vel
) {
39 QPoint
Element::size() const {
40 return QPoint(30, 30);