-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamescene.h
83 lines (72 loc) · 1.76 KB
/
gamescene.h
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
#ifndef GAMESCENE_H
#define GAMESCENE_H
#include<QGraphicsScene>
#include<QList>
#include"gift.h"
//前向声明
class QMediaPlayer;
class AbstractPlank;
class AbstractBall;
class AbstractBrick;
class GameScene : public QGraphicsScene
{
Q_OBJECT
//游戏状态
enum GameState
{
ready,
start,
pause
};
public:
//场景
GameScene(QObject* parent=nullptr);
signals:
//信号
void gameWin();
void gameLose();
void gamePause();
void gameContinue();
void upScore(int score);
//槽
public slots:
void selectGameLevel(int level);
void randSetGift();
protected:
//键盘按键事件
void keyPressEvent(QKeyEvent *e)override;
void keyReleaseEvent(QKeyEvent *e)override;
private slots:
// void gameStart();
//
void ballCollided(QList<QGraphicsItem*> items,AbstractBall* ball);
void giftCollided(QList<QGraphicsItem*> items, Gift* gift);
void offsetBall(qreal xOff,qreal yOff,QGraphicsItem* ball);
//控制球,砖块,板子和礼物
void monitorBall(AbstractBall* ball);
void monitorBrick(AbstractBrick *brick);
void monitorPlank(AbstractPlank* plank);
void monitorGift(Gift* gift);
//球消失,砖块被击碎
void ballDestroyed();
void brickDestroyed();
private:
void analysisGift(Gift* gift);
//增加球,增加砖块
void addBall(AbstractBall* ball,QPointF pos);
void addBrick(AbstractBrick* brick,QPointF pos);
void convertPlank(AbstractPlank* newPlank);
//初始化边界
void initBorder();
AbstractPlank *plank;
//音效和音乐
QMediaPlayer * brickCollidedPlayer;
QMediaPlayer * brickDestroyedPlayer;
QMediaPlayer * ballAddedPlayer;
QMediaPlayer * plankCollidedPlayer;
//球和砖的数量,游戏状态
int ballAmount;
int brickAmount;
GameState gameState;
};
#endif // GAMESCENE_H