-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.cpp
51 lines (38 loc) · 1.35 KB
/
game.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
#include "game.h"
#include <QGraphicsScene>
#include <QTimer>
#include <QMediaPlayer>
#include <QImage>
#include <QBrush>
#include <QMediaPlaylist>
Game::Game(QWidget *parent) : QGraphicsView(parent)
{
scene = new QGraphicsScene();
setScene(scene);
setFixedSize(1210,905);
scene->setSceneRect(0,0,1200,900);
setBackgroundBrush(QBrush(QImage(":/images/background1.png")));
player = new Player();
scene->addItem(player);
score = new Score();
scene->addItem(score);
health = new Health();
health->setPos(health->x(), health->y()+35);
scene->addItem(health);
player->setFlag(QGraphicsItem::ItemIsFocusable);
player->setFocus();
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
player->setPos(width()/2 - player->pixmap().width()/2, height() - player->pixmap().height()-5);
QTimer * timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()), player, SLOT(spawn()));
timer->start(2000);
QMediaPlaylist * bgmusiclist = new QMediaPlaylist;
bgmusiclist->setPlaybackMode(QMediaPlaylist::Loop);
bgmusiclist->addMedia(QUrl("qrc:bgmusic/PowerPunch_80-1.wav"));
bgmusiclist->setCurrentIndex(1);
QMediaPlayer * music = new QMediaPlayer();
music->setPlaylist(bgmusiclist);
music->setVolume(88);
music->play();
}