-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
55 lines (43 loc) · 1.67 KB
/
mainwindow.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
51
52
53
54
55
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, scene(new QGraphicsScene(this))
{
ui->setupUi(this);
// Set up the scene
ui->graphicsView->setScene(scene);
scene->setSceneRect(0, 0, 650, 550); // Adjust as needed
QPixmap background(":/Background1.svg");
background = background.scaled(scene->sceneRect().size().toSize(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation);
QGraphicsPixmapItem *backgroundItem = new QGraphicsPixmapItem(background);
backgroundItem->setPos(0, 0); // Position at the top-left
backgroundItem->setZValue(-1); // Ensure it stays behind other items
scene->addItem(backgroundItem); // Add to scene
controller = new GameController(scene, this);
// Connect signals to update UI labels
connect(controller, &GameController::livesChanged, this, [=](int lives){
ui->lives->display(lives);
});
connect(controller, &GameController::scoreChanged, this, [=](int score){
ui->score->display(score);
});
connect(controller, &GameController::bestScoreChanged, this, [=](int bestScore){
ui->bestScore->display(bestScore);
});
// // Initialize labels
// ui->livesLabel->setText(QString("Lives: %1").arg(controller->getLives()));
// ui->scoreLabel->setText(QString("Score: %1").arg(controller->getScore()));
// ui->graphicsView->setFocus();
}
MainWindow::~MainWindow()
{
delete ui;
}
// void MainWindow::keyPressEvent(QKeyEvent *event) {
// controller->keyPressEvent(event);
// }