-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphicsview.cpp
54 lines (42 loc) · 1.31 KB
/
graphicsview.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
#include "graphicsview.h"
#include <QKeyEvent>
#include <iostream>
using namespace std;
/* Constructor for a blue shell, sets velocity to 1
@param scene A QGraphicsScene that is passed to the QGraphicsView constuctor
@param mario The main player that is passed to the item to allow for the moving of the mario
@param p A Widget that can be used to pass in the MainWindow that is there for experimentation by Prof. Redekopp **/
GraphicsView :: GraphicsView(QGraphicsScene* scene, Mario* mario, QWidget* p) : QGraphicsView(scene, p)
{
mainPlayer = mario;
}
/* Default destructor **/
GraphicsView :: ~GraphicsView () {}
/* Handles the arrow key presses, sets the appririate velocity, picture and moves the Mario that was passed in to the constructor **/
void GraphicsView:: keyPressEvent(QKeyEvent *event)
{
QGraphicsView:: keyPressEvent(event);
switch(event->key())
{
case Qt::Key_Left:
mainPlayer->setVel(-8,0);
mainPlayer->setPic(4);
mainPlayer->move_();
break;
case Qt::Key_Right:
mainPlayer->setVel(8,0);
mainPlayer->setPic(2);
mainPlayer->move_();
break;
case Qt::Key_Up:
mainPlayer->setVel(0,-8);
mainPlayer->setPic(1);
mainPlayer->move_();
break;
case Qt::Key_Down:
mainPlayer->setVel(0,8);
mainPlayer->setPic(3);
mainPlayer->move_();
break;
}
}