-
Notifications
You must be signed in to change notification settings - Fork 3
/
pipe.cpp
65 lines (58 loc) · 1.29 KB
/
pipe.cpp
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
#include "pipe.h"
#include "widget.h"
Pipe::Pipe(double _y)
{
init(sys->pipe_up,sys->GetMainWidget()->width()+150,_y,sys->GetMainWidget()->ground->vx,0,LAYER_PIPE);
space=150;
y_up=_y+space+sys->pipe_down.height();
}
void Pipe::frame()
{
if(CheckColli())
{
sys->GetMainWidget()->tools->SetBlink();
sys->GetMainWidget()->bird->Drop();
sys->GetMainWidget()->GameOver();
}
else
{
DefaultAction();
if(colli&&x+img->width()/2<sys->GetMainWidget()->bird->x)
{
sys->GetMainWidget()->socre->ScoreAdd();
colli=false;
}
if(del_flag)
{
sys->GetMainWidget()->bird->pipelist.pop_front();
}
}
}
void Pipe::show(QPainter &p)
{
QPixmap & p1=sys->pipe_down;
QPixmap & p2=sys->pipe_up;
DrawPixmapAtCenter(x,y,p1,p);
DrawPixmapAtCenter(x,y_up,p2,p);
}
void Pipe::gameover()
{
task=false;
colli=false;
}
void Pipe::restart()
{
del_flag=true;
}
bool Pipe::CheckColli()
{
auto & bird=sys->GetMainWidget()->bird;
if(bird->x+COLLI_SIZE>x-img->width()/2&&
bird->x-COLLI_SIZE<x+img->width()/2&&
(bird->y-COLLI_SIZE<y+img->height()/2||
bird->y+COLLI_SIZE>y_up-img->height()/2))
{
return true;
}
return false;
}