-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlawnmower.cpp
More file actions
50 lines (38 loc) · 922 Bytes
/
lawnmower.cpp
File metadata and controls
50 lines (38 loc) · 922 Bytes
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
#include "lawnmower.h"
#include <QDebug>
LawnMower::LawnMower(QRect *tile, int scene_width)
{
lawnMowerImage = new QPixmap(":/Images/lawnMower");
this->setPos(tile->x()-lawnMowerImage->width(),
tile->y() + 20);
xVelocity = 7;
isActivated = false;
sceneEnd = scene_width;
}
LawnMower::~LawnMower()
{
delete lawnMowerImage;
}
void LawnMower::activateMovement()
{
isActivated = true;
}
QRectF LawnMower::boundingRect() const
{
return QRectF(0,0,lawnMowerImage->width(),lawnMowerImage->height());
}
void LawnMower::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{
painter->drawPixmap(boundingRect(),*lawnMowerImage,boundingRect());
}
void LawnMower::advance(int phase)
{
if(!phase) return;
if(isActivated)
this->setX(this->x() + xVelocity);
if(this->x() >= sceneEnd)
{
delete this;
return;
}
}