-
Notifications
You must be signed in to change notification settings - Fork 5
/
tilemap.cpp
71 lines (58 loc) · 1.22 KB
/
tilemap.cpp
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 "tilemap.h"
TileMap::TileMap(int SizeX, int SizeY)
{
Map.fill(QVector<int>().fill(0,SizeX),SizeY);
WorldSizeX=SizeX;
WorldSizeY=SizeY;
}
TileMap::~TileMap()
{
Map.clear();
}
void TileMap::setWorldSize(int x, int y)
{
WorldSizeX=x;
WorldSizeY=y;
Map.resize(y);
for (int i=0;i<y;i++)
Map[i].resize(x);
}
int TileMap::getTileAt(int x, int y)
{
if (x>=WorldSizeX) return 0;
if (y>=WorldSizeY) return 0;
return Map.at(y).at(x);
}
void TileMap::setTileAt(int x, int y, int Tile)
{
Map[y][x] = Tile;
}
int TileMap::getSizeX() const
{
if (WorldSizeX > 100000)
return 1;
return WorldSizeX;
}
int TileMap::getSizeY() const
{
if (WorldSizeY > 100000)
return 1;
return WorldSizeY;
}
void TileMap::saveLayerAsText(QTextStream &stream)
{
stream << "MAP SIZE X: " << QString::number(this->getSizeX()) << endl;
stream << "MAP SIZE Y: " << QString::number(this->getSizeY()) << endl << endl;
for (int j=0;j<this->getSizeY(); j++)
{
for (int i=0;i<this->getSizeX(); i++)
{
stream << QString::number( this->getTileAt(i,j) ) << " ";
}
stream << endl;
}
}
void TileMap::clear()
{
Map.clear();
}