-
Notifications
You must be signed in to change notification settings - Fork 2
/
map.h
103 lines (82 loc) · 2.51 KB
/
map.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#ifndef MAP_H
#define MAP_H
#include <QVector>
#include <QObject>
#include <QPoint>
#include <QColor>
#include <QJsonObject>
#include <QUrl>
class Map : public QObject
{
Q_OBJECT
Q_PROPERTY(int width READ width() NOTIFY mapChanged)
Q_PROPERTY(int height READ height() NOTIFY mapChanged)
Q_PROPERTY(QString name READ name() NOTIFY mapChanged)
Q_PROPERTY(int pelletsLeft READ pelletsLeft NOTIFY pelletsLeftChanged)
Q_PROPERTY(int totalPellets MEMBER m_totalPellets NOTIFY totalPelletsChanged)
public:
enum TileCorner {
UpperLeft,
UpperRight,
BottomLeft,
BottomRight
};
Q_ENUM(TileCorner)
enum Powerup {
NoPowerup = 0,
NormalPellet = 1,
SuperPellet = 2
};
Q_ENUM(Powerup)
enum TileType {
FloorTile = 0,
WallTile,
DoorTile,
PelletTile,
SuperPelletTile,
InvalidTile = -1
};
Q_ENUM(TileType)
explicit Map(QObject *parent);
Q_INVOKABLE bool loadMap(const QUrl &fileUrl) { return loadMap(fileUrl.toLocalFile()); }
Q_INVOKABLE bool loadMap(const QString &filepath);
Q_INVOKABLE QString parseError() const { return m_parseError; }
Q_INVOKABLE QStringList availableMaps();
void resetPowerups();
int width() const { return m_width; }
int height() const { return m_height; }
bool isNull() const;
bool isValid() const;
bool isValidPosition(int x, int y) const;
bool isWithinBounds(int x, int y) const;
QString name() const;
Q_INVOKABLE Powerup powerupAt(int x, int y) const;
Powerup takePowerup(int x, int y);
Q_INVOKABLE QString tileSprite(int x, int y, TileCorner corner) const;
Q_INVOKABLE QString powerupSprite(int x, int y) const;
int pelletsLeft() const { return m_pelletsLeft; }
QVector<QPoint> startingPositions() const { return m_startingPositions; }
QPoint monsterSpawn() const { return m_monsterSpawn; }
QJsonObject getSerialized() const;
signals:
void mapChanged();
void powerupChanged(int x, int y);
void powerupVisibleChanged(int x, int y, bool visible);
void pelletsLeftChanged();
void totalPelletsChanged();
private:
TileType tileAt(int x, int y) const;
int m_width;
int m_height;
QVector<Powerup> m_powerups;
QVector<TileType> m_tiles;
QVector<QPoint> m_startingPositions;
QPoint m_monsterSpawn;
QString m_name;
int m_pelletsLeft;
int m_totalPellets;
int m_arenaTop;
int m_arenaBottom;
QString m_parseError;
};
#endif // MAP_H