-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbird.cpp
More file actions
34 lines (29 loc) · 751 Bytes
/
bird.cpp
File metadata and controls
34 lines (29 loc) · 751 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
#include "bird.h"
#include <QGraphicsScene>
Bird::Bird() : velocity(0), gravity(0.5), lift(-10) {
setPixmap(QPixmap(":/assets/images/bluebird-midflap.png").scaled(40, 40));
setPos(100, 300);
}
void Bird::flap() {
velocity = lift;
setPixmap(QPixmap(":/assets/images/bluebird-upflap.png").scaled(40, 40));
}
void Bird::updatePosition() {
velocity += gravity;
setY(y() + velocity);
// 限制鸟的活动范围
if (y() < 0) {
setY(0);
velocity = 0;
}
else if (y() > 560) {
setY(560);
velocity = 0;
}
setPixmap(QPixmap(":/assets/images/bluebird-downflap.png").scaled(40, 40));
}
void Bird::reset()
{
setPixmap(QPixmap(":/assets/images/bluebird-midflap.png").scaled(40, 40));
setPos(100, 300);
}