forked from clickteam-plugin/TileMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLayer.h
112 lines (82 loc) · 2.39 KB
/
Layer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#pragma once
#include <map>
#include <new>
#include <string>
#include <vector>
using std::vector;
using std::map;
using std::string;
#include "Property.h"
#include "SubLayer.h"
#include "Tile.h"
struct SubLayerLink {
unsigned char tileset;
unsigned char animation;
unsigned char animationFrame;
SubLayerLink() : tileset(0xff), animation(0xff), animationFrame(0xff) {}
};
struct LayerSettings {
// Scrolling offset in pixels
int offsetX;
int offsetY;
// Scrolling coefficient for parallax
float scrollX;
float scrollY;
// Wrapping
bool wrapX;
bool wrapY;
// Rendering settings
bool visible;
float opacity;
/* Tileset and collision indices */
unsigned char tileset;
unsigned char collision;
// Tile size (pixels)
unsigned short tileWidth;
unsigned short tileHeight;
// Sub-layer link indices
SubLayerLink subLayerLink;
LayerSettings()
: offsetX(0), offsetY(0), scrollX(1.0), scrollY(1.0), wrapX(false), wrapY(false),
visible(true), opacity(1.0), tileset(0), collision(-1), tileWidth(16), tileHeight(16)
{
}
};
class Layer {
// Tile data
Tile * data;
// Tile count (map size)
unsigned width;
unsigned height;
public:
// Modiyable layer settings
LayerSettings settings;
// User properties
map<string, Property> properties;
// Sub-layers
vector<SubLayer> subLayers;
// Constructor/destructor
Layer() : width(0), height(0), data(0) {}
Layer(const Layer & src);
~Layer() { delete[] data; }
// Check if a layer is usable
bool isValid() const { return width > 0 && height > 0 && data != 0; }
// Check if a coordinate is valid
bool isValid(unsigned x, unsigned y) const
{
return isValid() && x < width && y < height;
}
// Get a tile within the layer array
Tile * getTile(unsigned x, unsigned y) { return data + x + width * y; }
Tile * getDataPointer() { return data; }
unsigned getWidth() const { return width; }
unsigned getHeight() const { return height; }
unsigned getByteSize() const { return width * height * sizeof(Tile); }
// Resize layer, new tiles are empty
void resize(unsigned newWidth, unsigned newHeight);
// For viewport rendering
float getScreenX(float cameraX);
float getScreenY(float cameraY);
int getScreenWidth();
int getScreenHeight();
};