You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

46 lines
1.0 KiB

#include "game.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include "MyRect.h"
#include <QTimer>
#include <QMediaPlayer>
Game::Game(QWidget *parent)
: QGraphicsView{parent}
{
scene = new QGraphicsScene();
scene->setSceneRect(0,0,800,600);
setBackgroundBrush(QBrush(QImage(":/images/bg.png")));
setScene(scene);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(800,600);
player = new MyRect();
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);
//scene->addWidget(this);
//view->show();
//view->setFixedSize(800,600);
// spawn enemies
QTimer* timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()), player, SLOT(spawn()));
timer->start(2000);
show();
}