-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameview.cpp
More file actions
75 lines (65 loc) · 2.37 KB
/
Copy pathgameview.cpp
File metadata and controls
75 lines (65 loc) · 2.37 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
#include "gameview.h"
#include "mainwindow.h"
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <turret.h>
#include <enemy.h>
#include <iostream>
#include "score.h"
#include "ufo.h"
using namespace std;
GameView::GameView()
{
nbEnnemies = 0;
QGraphicsScene *myScene = new QGraphicsScene();
myScene->setSceneRect(0, 0, 800, 600);
QColor bgColor(0,0,0);
myScene->setBackgroundBrush(bgColor);
Turret *myTurret = new Turret(QString(":/tourelle.png"));
myTurret->setPos(myScene->width()/2, myScene->height() - myTurret->boundingRect().height());
myScene->addItem(myTurret);
Score *myScore = new Score();
myScene->addItem(myScore);
for (int pos = 40; pos < myScene->width()-40; pos+=60){
Enemy *myEnemy = new Enemy(QString(":/alien2.png"));
myEnemy->setPos(pos , 20);
QObject::connect(myEnemy, SIGNAL(killed(int)), myScore, SLOT(increaseScore(int)));
QObject::connect(myEnemy, SIGNAL(killed(int)), this, SLOT(deathToll()));
QObject::connect(myEnemy, SIGNAL(touchTurret()), this, SLOT(gameOver()));
myScene->addItem(myEnemy);
nbEnnemies ++;
}
for (int pos = 40; pos < myScene->width()-40; pos+=60){
Enemy *myEnemy = new Enemy(QString(":/alien3.png"));
myEnemy->setPos(pos , 80);
QObject::connect(myEnemy, SIGNAL(killed(int)), myScore, SLOT(increaseScore(int)));
QObject::connect(myEnemy, SIGNAL(killed(int)), this, SLOT(deathToll()));
QObject::connect(myEnemy, SIGNAL(touchTurret()), this, SLOT(gameOver()));
myScene->addItem(myEnemy);
nbEnnemies ++;
}
Ufo *myUfo = new Ufo();
QObject::connect(myUfo, SIGNAL(killed(int)), myScore, SLOT(increaseScore(int)));
myScene->addItem(myUfo);
setScene(myScene);
setFixedSize(800, 600);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
}
void GameView::deathToll(){
nbEnnemies--;
if(nbEnnemies == 0){
QMessageBox message;
message.setText("Victory");
message.setIcon(QMessageBox::Information);
message.exec();
}
}
void GameView::gameOver(){
QMessageBox message;
message.setText("Game over");
message.setIcon(QMessageBox::Information);
message.exec();
}