Repository navigation
Expand file tree
/
Copy pathMap.cpp
More file actions
68 lines (46 loc) · 1.58 KB
/
Copy pathMap.cpp
File metadata and controls
68 lines (46 loc) · 1.58 KB
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
#include <fstream>
#include "Map.hpp"
#include "Game.hpp"
#include "ECS/ECS.hpp"
#include "ECS/Components.hpp"
extern Manager manager;
Map::Map(std::string texID, int mScale, int tSize, int mSizeX, int mSizeY)
: textureID(texID), mapScale(mScale), tileSize(tSize), sizeX(mSizeX), sizeY(mSizeY) {
scaledSize = mScale * tSize;
}
Map::~Map() { }
void Map::LoadMap(std::string path) {
char tile;
std::ifstream mapFile(path);
int srcX, srcY;
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) {
mapFile.get(tile);
srcY = atoi(&tile) * tileSize;
mapFile.get(tile);
srcX = atoi(&tile) * tileSize;
AddTile(srcX, srcY, x * scaledSize, y * scaledSize);
mapFile.ignore();
}
}
mapFile.ignore();
for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) {
mapFile.get(tile);
if (tile == '1') {
auto& tCol(manager.addEntity());
tCol.addComponent<ColliderComponent>("terrain", x * scaledSize, y * scaledSize, scaledSize);
tCol.addGroup(Game::groupColliders);
}
mapFile.ignore();
}
}
mapFile.close();
}
void Map::AddTile(int srcX, int srcY, int xpos, int ypos) {
auto& tile(manager.addEntity());
tile.addComponent<TileComponent>(srcX, srcY, xpos, ypos, tileSize, mapScale, textureID);
if (srcX == 1 * tileSize && srcY == 2 * tileSize)
tile.addGroup(Game::groupGrasses);
else tile.addGroup(Game::groupMap);
}