-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.cpp
More file actions
60 lines (52 loc) · 1.73 KB
/
Copy pathmap.cpp
File metadata and controls
60 lines (52 loc) · 1.73 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
#include "map.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>
#include <QGraphicsPixmapItem>
#include "gameView.h"
Map::Map() {
gameMap = {
{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'},
{'#','.','.','.','.','.','.','.','.','.','.','.','.','.','.','.','#'},
{'#','.','.','#','#','.','#','#','#','#','#','.','#','#','#','#','#'},
{'#','.','#','.','.','#','.','#','.','.','#','.','#','.','#','.','#'},
{'#','.','.','.','.','.','#','.','.','.','.','.','.','.','.','.','#'},
{'#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#','#'}
};
}
void Map::printMap() const {
for (auto const& row : gameMap) {
QString out;
out.reserve(row.size() * 2);
for (char ch : row) {
if (ch == '#')
out.append(QStringLiteral("🧱"));
else
out.append(ch);
}
qDebug() << out;
}
}
void Map::drawMap(QGraphicsScene* scene) {
const int tileSize = 32;
for (int y = 0; y < gameMap.size(); ++y) {
for (int x = 0; x < gameMap[y].size(); ++x) {
char ch = gameMap[y][x];
QPixmap tile;
if (ch == '#') {
tile.load(":/images/images/brown_block.png");
} else if (ch == '.' || ch == 'C') {
tile.load(":/images/images/Solid_black.png");
}
else {
continue;
}
QGraphicsPixmapItem* item = new QGraphicsPixmapItem(tile.scaled(tileSize, tileSize));
item->setPos(x * tileSize, y * tileSize);
scene->addItem(item);
}
}
}
const std::vector<std::vector<char>>& Map::getGameMap() const {
return gameMap;
}