-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.cpp
More file actions
83 lines (72 loc) · 2.48 KB
/
menu.cpp
File metadata and controls
83 lines (72 loc) · 2.48 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "menu.h"
Menu::Menu(QWidget *parent)
{
const int x_size=1024, y_size=768;
//create a scene
scene = new QGraphicsScene();
scene->setSceneRect(0,0,x_size,y_size);
scene->setBackgroundBrush(QBrush(QImage(":/graphic/SpaceInvader/background.png").scaled(x_size,y_size)));
// add a view to visualize the scene
view = new QGraphicsView(scene);
view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
view->setFixedSize(x_size,y_size);
//create an item to put into the scene
ship = new Fighter();
player = new ShipGui(ship,":/graphic/fighter.png");
//add item to the scene
scene->addItem(player);
player->setPos(view->width()/2, view->height() - 250);
//add buttons for starting the game, etc
startButton = new QPushButton("&Start Game", view);
startButton->setGeometry(QRect(QPoint(50, 50), QSize(150, 50)));
connect(startButton,SIGNAL(released()), this, SLOT(handleStart()));
quitButton = new QPushButton("&Quit game", view);
quitButton->setGeometry(QRect(QPoint(50, 150), QSize(150, 50)));
connect(quitButton, SIGNAL(released()), this, SLOT(handleQuit()));
chgShipButton = new QPushButton("&Change ship", view);
chgShipButton->setGeometry(QRect(QPoint(320, 690), QSize(150, 50)));
connect(chgShipButton, SIGNAL(released()), this, SLOT(handleShipChg()));
view->show();
quitButton->show();
startButton->show();
chgShipButton->show();
}
void Menu::handleStart()
{
quitButton->hide();
startButton->hide();
chgShipButton->hide();
scene->installEventFilter(ship);
game = new GameGui(this->scene, this->view, this->player);
}
void Menu::handleQuit()
{
QCoreApplication::quit();
}
void Menu::handleShipChg()
{
if (default_ship){
//create an item to put into the scene
scene->removeItem(player);
delete player;
delete ship;
ship= new Fighter();
player = new ShipGui(ship,":/graphic/fighter.png");
scene->addItem(player);
player->setPos(view->width()/2, view->height() - 250);
view->show();
default_ship=false;
}
// else{
// scene->removeItem(player);
// delete player;
// delete ship;
// ship = new Cruiser();
// player = new ShipGui(ship);
// scene->addItem(player);
// player->setPos(view->width()/2, view->height() - 250);
// view->show();
// default_ship=true;
// }
}