-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathgalaga.cpp
More file actions
68 lines (51 loc) · 1.63 KB
/
galaga.cpp
File metadata and controls
68 lines (51 loc) · 1.63 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
#include <QTimer>
#include <QGraphicsTextItem>
#include <QFont>
#include "enemy.h"
#include "galaga.h"
#include <QBrush>
#include <QImage>
#include <QDebug>
#include <QMediaPlayer>
Galaga::Galaga(QWidget*parent){
//creating a scene
scene = new QGraphicsScene();
setBackgroundBrush(QBrush(QImage(":/images/background.png")));
//creating an item
p = new player();
//sets the player at the bottom middle of the screen
p->setPos(250,650);
//create score
score = new Score();
scene->addItem(score);
//create health
health = new Health();
health->setPos(health->x(),health->y()+30);
scene->addItem(health);
//create level
level = new Level();
level->setPos(400,700);
scene->addItem(level);
//adding item to scene
scene->addItem(p);
//making the item focusable
p->setFlag(QGraphicsItem::ItemIsFocusable);
p->setFocus();
//the view won't get bigger as something moves in it
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
//adding scene to the view
setScene(scene);
//showing the view and setting the scene and view to a certain size
setFixedSize(525,750);
scene->setSceneRect(0,0,525,750);
//spawn enemies every 2 seconds
QTimer * timer = new QTimer();
QObject::connect(timer,SIGNAL(timeout()),p,SLOT(spawn()));
timer->start(2000);
//background music
QMediaPlayer * music = new QMediaPlayer();
music->setMedia(QUrl("qrc:/sounds/galaga.mp3"));
music->play();
show();
}