-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhazard.cpp
83 lines (72 loc) · 1.87 KB
/
hazard.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "hazard.h"
Monster::Monster(QTimer * t)
{
timer = t;
setPixmap(QPixmap(":/hazard/images/monster1.png"));
setZValue(2);
beHitSound = new QMediaPlayer();
beHitSound->setMedia(QUrl("qrc:/sound/resource/monsterhit.mp3"));
}
Monster::~Monster()
{
if(scene()){
scene()->removeItem(this);
}
}
void Monster::collide(Player * player)
{
if (player->getVel() > 0) {
if(player->pos().y() < this->pos().y()){
if(player->doodlejump->getTurnOnSound()) {
if(beHitSound->state() == QMediaPlayer::PlayingState){
beHitSound->setPosition(0);
} else if(beHitSound->state() == QMediaPlayer::StoppedState) {
beHitSound->play();
}
}
connect(timer, SIGNAL(timeout()), this, SLOT(move()));
}
player->setVel();
} else {
player->setVel(0);
player->hitByMonster();
}
}
void Monster::hit()
{
if(scene()) {
scene()->removeItem(this);
}
}
void Hazard::move()
{
setY(pos().y() + 33);
}
Hole::Hole(QTimer * t)
{
timer = t;
setPixmap(QPixmap(":/hazard/images/hole.png"));
setZValue(2);
sound = new QMediaPlayer();
sound->setMedia(QUrl("qrc:/sound/resource/Hole.mp3"));
}
Hole::~Hole()
{
if(scene()){
scene()->removeItem(this);
}
}
void Hole::collide(Player * player)
{
if(player->doodlejump->getTurnOnSound()) {
if(sound->state() == QMediaPlayer::PlayingState){
sound->setPosition(0);
} else if(sound->state() == QMediaPlayer::StoppedState) {
sound->play();
}
}
player->stop();
player->setPos(pos().x() + 50, pos().y() + 50);
player->hitByHole();
connect(timer, SIGNAL(timeout()), player, SLOT(hitByHole()));
}