-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbird.cpp
More file actions
54 lines (46 loc) · 943 Bytes
/
Copy pathbird.cpp
File metadata and controls
54 lines (46 loc) · 943 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
50
51
52
53
54
#include"bird.h"
#include"gamecontroller.h"
#include"constants.h"
Bird::Bird(GameController& controller):
controller(controller)
{
pos.setX(400);
pos.setY(300);
speed=0;
tickCounter=0;
}
void Bird::paint(QPainter& painter){
painter.drawImage(QRectF(pos.x()-24,pos.y()-24,48,48),QImage(QString(":/images/bird%1").arg(tickCounter)));
}
QRectF Bird::boundingRect(){
QRectF bound=QRectF(pos.x()-18,pos.y()-14,37,28);
return bound;
}
void Bird::advance(){
tickCounter=(tickCounter+1)%3;
if(controller.get_mode()==WEIGHTLESS)speed+=low_g;
else
speed+=g;
if(pos.y()>=0){
pos.setY(pos.y()+speed);
}
else{
speed=2;
pos.setY(0);
}
}
void Bird::goUp(){
if(pos.y()>=0)
{
speed=-5;
pos.setY(pos.y()-20);
}
}
QPointF Bird::getPos(){
return pos;
}
void Bird::reset(){
pos.setX(400);
pos.setY(300);
speed=0;
}