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.

38 lines
1.1 KiB

2 years ago
#include "game.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include "MyRect.h"
#include <QTimer>
Game::Game(QWidget *parent)
: QGraphicsView{parent}
{
MyRect* player = new MyRect();
player->setRect(0,0,100,100);
player->setFlag(QGraphicsItem::ItemIsFocusable);
player->setFocus();
QGraphicsScene* scene = new QGraphicsScene();
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);
this->setScene(scene);
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
this->setFixedSize(800,600);
//view->show();
//view->setFixedSize(800,600);
scene->setSceneRect(0,0,800,600);
player->setPos(this->width()/2, this->height() - player->rect().height());
// spawn enemies
QTimer* timer = new QTimer();
QObject::connect(timer, SIGNAL(timeout()), player, SLOT(spawn()));
timer->start(2000);
}