-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamebase.cpp
46 lines (35 loc) · 1.1 KB
/
gamebase.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
#include "gamebase.h"
#include <QTimer>
#include <QGraphicsTextItem>
#include <QFont>
#include <QGraphicsScene>
#include "enemy.h"
#include "myplayer.h"
#include <QMediaPlayer>
GameBase::GameBase()
{
scene = new QGraphicsScene();
scene->setSceneRect(0,0,800,600);
setBackgroundBrush(QBrush(QImage(":/new/images/resource/images/bg_game.jpg")));
setScene(scene);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(800,600);
player = new MyPlayer();
player->setPos(400,500);
player->setFlag(QGraphicsItem::ItemIsFocusable);
player->setFocus();
scene->addItem(player);
score = new Score();
scene->addItem(score);
health = new Health();
health->setPos(health->x(),health->y()+25);
scene->addItem(health);
QTimer * timer = new QTimer();
QObject::connect(timer,SIGNAL(timeout()),player,SLOT(spawn()));
timer->start(2000);
QMediaPlayer *music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/new/sounds/resource/sounds/war_sound.mp3"));
music->play();
show();
}