-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmystery_block.cpp
77 lines (64 loc) · 1.82 KB
/
mystery_block.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
#include "mystery_block.h"
extern Game * game;
Mystery_Block::Mystery_Block(ISubject &gLoop, int surprise, QGraphicsItem *parent): QGraphicsPixmapItem(parent), gameLoop(gLoop)
{
setPixmap(QPixmap(":/sprites/blocks/mystery-box/1.png"));
surprise_selected = surprise;
sprite_animation_1();
bump = new QMediaPlayer(this);
bump->setMedia(QUrl("qrc:/sounds/sounds/bump.wav"));
}
void Mystery_Block::open_box()
{
if(!broken){
bump->play();
broken = true;
setPixmap(QPixmap(":/sprites/blocks/mystery-box/open.png"));
open_animation_start();
}
}
void Mystery_Block::open_animation_start()
{
setPos(x(), y()-6);
switch (surprise_selected) {
case mushroom:
game->scene->addItem(new Mushroom_Object(x(), y(), gameLoop));
break;
case coin:
game->scene->addItem(new Coin_Object(x(), y()));
break;
}
QTimer::singleShot(200, this, &Mystery_Block::open_animation_end);
}
void Mystery_Block::open_animation_end()
{
setPos(x(), y()+6);
}
void Mystery_Block::sprite_animation_1()
{
if(!broken){
setPixmap(QPixmap(":/sprites/blocks/mystery-box/1.png"));
QTimer::singleShot(500, this, &Mystery_Block::sprite_animation_2);
}
}
void Mystery_Block::sprite_animation_2()
{
if(!broken){
setPixmap(QPixmap(":/sprites/blocks/mystery-box/2.png"));
QTimer::singleShot(150, this, &Mystery_Block::sprite_animation_3);
}
}
void Mystery_Block::sprite_animation_3()
{
if(!broken){
setPixmap(QPixmap(":/sprites/blocks/mystery-box/3.png"));
QTimer::singleShot(150, this, &Mystery_Block::sprite_animation_4);
}
}
void Mystery_Block::sprite_animation_4()
{
if(!broken){
setPixmap(QPixmap(":/sprites/blocks/mystery-box/2.png"));
QTimer::singleShot(150, this, &Mystery_Block::sprite_animation_1);
}
}