-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathPlayer.h
More file actions
42 lines (33 loc) · 837 Bytes
/
Player.h
File metadata and controls
42 lines (33 loc) · 837 Bytes
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
#ifndef PLAYER_H
#define PLAYER_H
// inheriting from:
#include <QGraphicsRectItem>
#include <QObject>
// using:
class QKeyEvent;
class QGraphicsItem;
class Game;
class Player: public QObject, public QGraphicsRectItem {
Q_OBJECT
public:
// constructor
Player(Game* game, int stepSize, QGraphicsItem* parent = nullptr);
// nested enum class - describes the direction the player is moving towards
enum class Direction {UP, DOWN, LEFT, RIGHT, NONE};
// event handlers
void keyPressEvent(QKeyEvent* keyPress);
public slots:
void move();
private:
// main private attributes
Direction movementDirection_;
int stepSize_;
Game* game_;
// helper functions
void moveUp();
void moveDown();
void moveLeft();
void moveRight();
bool frontBlocked();
};
#endif // PLAYER_H