-
Notifications
You must be signed in to change notification settings - Fork 0
/
MapLoader.h
59 lines (49 loc) · 1.32 KB
/
MapLoader.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
#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <sfml\System\Vector2.hpp>
#include <sfml\Graphics\Rect.hpp>
//structure of each tile in the isometric grid
struct Tile
{
int x, y;
char tileSymbol;
Tile();
Tile(int xPos, int yPos, char tileSymbolID) : x(xPos), y(yPos), tileSymbol(tileSymbolID) {}; //constructor
inline char checkSymbol(){ return tileSymbol; }
inline bool checkPassable()
{
if (checkSymbol() == '@' || checkSymbol() == 'O' || checkSymbol() == 'T' || checkSymbol() == 'W')
return false;
else
return true;
}
inline sf::Vector2i getPos(){ return sf::Vector2i(x, y); }
};
class MapLoader
{
public:
static MapLoader& getInstance()
{
static MapLoader instance;
// Instantiated on first use.
return instance;
}
void LoadMap(std::string filepath);
inline Tile* GetMap(){ return mapArray; }
inline int GetMapHeight(){ return mapHeight; }
inline int GetMapWidth(){ return mapWidth; }
inline sf::IntRect GetMapRect(){ return boundsRect; }
private:
MapLoader();
// technique of deleting the methods we don't want.
MapLoader(MapLoader const&) = delete;
void operator=(MapLoader const&) = delete;
Tile mapArray[512*512]; //defaults to a 512x512 map, but this can be reallocated
int mapWidth;
int mapHeight;
sf::IntRect boundsRect;
};