|
|
@ -10,30 +10,37 @@ |
|
|
|
Game::Game(QWidget *parent) |
|
|
|
Game::Game(QWidget *parent) |
|
|
|
: QGraphicsView{parent} |
|
|
|
: QGraphicsView{parent} |
|
|
|
{ |
|
|
|
{ |
|
|
|
MyRect* player = new MyRect(); |
|
|
|
|
|
|
|
player->setRect(0,0,100,100); |
|
|
|
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->setFlag(QGraphicsItem::ItemIsFocusable); |
|
|
|
player->setFocus(); |
|
|
|
player->setFocus(); |
|
|
|
QGraphicsScene* scene = new QGraphicsScene(); |
|
|
|
|
|
|
|
scene->addItem(player); |
|
|
|
scene->addItem(player); |
|
|
|
|
|
|
|
|
|
|
|
score = new Score(); |
|
|
|
score = new Score(); |
|
|
|
scene->addItem(score); |
|
|
|
scene->addItem(score); |
|
|
|
health = new Health(); |
|
|
|
health = new Health(); |
|
|
|
health->setPos(health->x(), health->y()+25); |
|
|
|
health->setPos(health->x(), health->y()+25); |
|
|
|
scene->addItem(health); |
|
|
|
scene->addItem(health); |
|
|
|
//scene->addWidget(this);
|
|
|
|
//scene->addWidget(this);
|
|
|
|
this->setScene(scene); |
|
|
|
|
|
|
|
this->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
this->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
|
|
|
|
|
|
this->setFixedSize(800,600); |
|
|
|
|
|
|
|
//view->show();
|
|
|
|
//view->show();
|
|
|
|
//view->setFixedSize(800,600);
|
|
|
|
//view->setFixedSize(800,600);
|
|
|
|
scene->setSceneRect(0,0,800,600); |
|
|
|
|
|
|
|
player->setPos(this->width()/2, this->height() - player->rect().height()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// spawn enemies
|
|
|
|
// spawn enemies
|
|
|
|
QTimer* timer = new QTimer(); |
|
|
|
QTimer* timer = new QTimer(); |
|
|
|
QObject::connect(timer, SIGNAL(timeout()), player, SLOT(spawn())); |
|
|
|
QObject::connect(timer, SIGNAL(timeout()), player, SLOT(spawn())); |
|
|
|
timer->start(2000); |
|
|
|
timer->start(2000); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|