-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTileset.cpp
More file actions
33 lines (28 loc) · 835 Bytes
/
Tileset.cpp
File metadata and controls
33 lines (28 loc) · 835 Bytes
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
#include "ConsoleGraphics.h"
Tileset::Tileset() {
}
void Tileset::addTile(ref<Tile> tile) {
tileData.push_back(tile);
}
Tile::Tile(ref<Image> source, unsigned offsetX, unsigned offsetY, unsigned width, unsigned height)
: width(width), height(height) {
pixelData = new Pixel[width * height];
if (pixelData) {
Pixel *ptr = pixelData;
for (unsigned j = offsetY; j < offsetY + height; j++)
for (unsigned i = offsetX; i < offsetX + width; i++)
*ptr++ = source->getPixel(i, j);
} else {
width = height = 0;
}
}
bool Tile::compareTo(ref<Tile> otherTile) {
if (otherTile->width == width && otherTile->height == height &&
!memcmp(otherTile->pixelData, pixelData, sizeof(Pixel) * width * height))
return true;
return false;
}
Tile::~Tile() {
if (pixelData)
delete[] pixelData;
}