-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.h
executable file
·51 lines (39 loc) · 1.59 KB
/
Level.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
#pragma once
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <string>
#include <vector>
#include <array>
#include "config.h"
#include "Pacman.h"
class Level
{
public:
enum node_type{CHECKPOINT, ENTRANCE, SPAWN, TELEPORT};
private:
std::vector<QPoint> _nodes; // graph nodes
std::vector < std::array<int, 4> > _neighbors; // each node has up to 4 neighbors, -1 where there is no neighbor
std::vector<node_type> _nodeTypes; // store type of each node
int _houseEntranceNode; // house entrance/exit node
int _pacmanSpawnNode; // spawn node for Pacman
int _ghostSpawnNode[4]; // spawn node for the 4 ghosts
std::vector <QGraphicsItem*> _graph; // graph for visual debug
// utility methods
void loadGraph(const std::string & imgPath, QGraphicsScene* scene);
void loadBalls(const std::string & imgPath, QGraphicsScene* scene);
public:
// Singleton design pattern
static Level* instance();
// load all items from the given map in the given scene
// also returns the player object
Pacman* load(std::string map_name, QGraphicsScene * scene);
// getters
const std::vector<QPoint> & nodes(){return _nodes;}
const std::vector < std::array<int, 4> > & neighbors(){return _neighbors;}
bool isTeleport(int index){return _nodeTypes[index] == TELEPORT;}
int ghostSpawnNode(int index){return _ghostSpawnNode[index];}
int pacmanSpawnNode(){return _pacmanSpawnNode;}
int houseEntranceNode(){return _houseEntranceNode;}
// tooglers
void toogleGraph(){for(auto &i : _graph) i->setVisible(!i->isVisible());}
};