-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sun.cpp
48 lines (37 loc) · 1.04 KB
/
Sun.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
#include "Sun.h"
#include <cstdlib>
Sun::Sun(QGraphicsScene * sunScene , Score * sunScore ,
QGraphicsItem * parent , QTimer * timer)
: QObject() , QGraphicsPixmapItem(parent) ,
sunScene(sunScene) , sunScore(sunScore) ,
timeIntervals(0)
{
//set Picture
setPixmap(QPixmap(":/images/sun1.png"));
// add to scene
sunScene->addItem(this);
// setPos( rand() % 750 , 0);
// connect timer to move
connect(timer , SIGNAL(timeout()) , this , SLOT(move()));
}
void Sun::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
// add score
sunScore->addToScore(25);
// play sound
sunScore->scorePlayer->play();
// remove and delete
sunScene->removeItem(this);
delete this;
}
void Sun::move() {
// increment timeIntervals each 50 milisec / if (timeIntervals == 40), it is 2 seconds
timeIntervals++;
// move downward
setPos(x() , y() + 5);
// remove and delete
if(timeIntervals == 40 || y() > 500){
sunScene->removeItem(this);
delete this;
}
}