-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironmentobject.cpp
More file actions
66 lines (54 loc) · 1.14 KB
/
Copy pathenvironmentobject.cpp
File metadata and controls
66 lines (54 loc) · 1.14 KB
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
#include "environmentobject.h"
EnvironmentObject::EnvironmentObject(QObject *parent,qreal speed,const QPointF &position)
: QObject{parent},m_speed(speed),m_position(position),m_isOut(false)
{}
QPixmap EnvironmentObject::img()
{
return m_img;
}
void EnvironmentObject::setImg(QPixmap &pic)
{
m_img=pic;
}
qreal EnvironmentObject::speed() const
{
return m_speed;
}
void EnvironmentObject::setSpeed(const qreal s)
{
m_speed=s;
}
QPointF EnvironmentObject::position() const
{
return m_position;
}
void EnvironmentObject::setPosition(const QPointF &pos)
{
m_position=pos;
}
bool EnvironmentObject::isOut() const
{
return m_isOut;
}
void EnvironmentObject::setOut(const bool out)
{
m_isOut=out;
}
void EnvironmentObject::shift()
{
m_position.rx()-=m_speed;
if (m_position.rx()+m_img.width()<0)
{
m_isOut=true;
}
}
void EnvironmentObject::paint(QPainter& painter)
{
painter.drawPixmap(m_position,m_img);
}
Cloud::Cloud(QObject *parent, qreal speed, const QPointF &position):EnvironmentObject(parent,speed,position)
{
//图片初始化
QPixmap pic(":/images/cloud.png");
m_img=pic;
}