-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflag_object.cpp
38 lines (31 loc) · 968 Bytes
/
flag_object.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
#include "flag_object.h"
Flag_Object::Flag_Object(qreal x, qreal y, QGraphicsItem *parent): QGraphicsItemGroup(parent)
{
body = new QGraphicsPixmapItem();
body->setPixmap(QPixmap(":/sprites/world/flag-body.png"));
addToGroup(body);
flag = new QGraphicsPixmapItem();
flag->setZValue(20);
flag->setPixmap(QPixmap(":/sprites/world/flag.png"));
flag->setPos(x-26,y-280);
setPos(x,y-body->pixmap().height());
addToGroup(flag);
flag_slide = new QMediaPlayer(this);
flag_slide->setMedia(QUrl("qrc:/sounds/sounds/down_flagpole.wav"));
}
void Flag_Object::winning()
{
if(!win){
win = true;
flag_slide->play();
timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &Flag_Object::flag_going_down_animation);
timer->start(10);
}
}
void Flag_Object::flag_going_down_animation()
{
if(flag->y() > 250)
timer->stop();
flag->setPos(flag->x(), flag->y()+4);
}