-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameView.cpp
More file actions
43 lines (39 loc) · 1.02 KB
/
Copy pathgameView.cpp
File metadata and controls
43 lines (39 loc) · 1.02 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
#include "gameView.h"
#include "movePacman.h"
#include "Map.h"
#include <QDebug>
#include "moveGhosts.h"
#include "MovePacman.h"
GameView::GameView(QWidget *parent)
: QGraphicsView(parent), movePacman(nullptr), gameMap(nullptr) {
setFocusPolicy(Qt::StrongFocus);
}
void GameView::setMovePacman(MovePacman* mover) {
movePacman = mover;
}
void GameView::setMap(Map* mapPtr) {
gameMap = mapPtr;
}
void GameView::keyPressEvent(QKeyEvent *event) {
if (!movePacman || !gameMap) {
QGraphicsView::keyPressEvent(event);
return;
}
switch (event->key()) {
case Qt::Key_Up:
movePacman->move(0, -1, gameMap->getGameMap());
break;
case Qt::Key_Down:
movePacman->move(0, 1, gameMap->getGameMap());
break;
case Qt::Key_Left:
movePacman->move(-1, 0, gameMap->getGameMap());
break;
case Qt::Key_Right:
movePacman->move(1, 0, gameMap->getGameMap());
break;
default:
QGraphicsView::keyPressEvent(event);
break;
}
}