-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathMap.h
185 lines (155 loc) · 5.15 KB
/
Map.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef MAP_H
#define MAP_H
#include "TmxMapMessage.pb.h"
#include "wx/string.h"
#include "wx/image.h"
#include "MpcDecode.hpp"
#include "TmxReaderClient.h"
struct Name32b
{
char Name[32];
};
struct ImgData
{
long width;
long height;
unsigned char *data; //RGBA
ImgData()
: width(0)
, height(0)
, data(nullptr)
{
}
~ImgData()
{
Free();
}
void Free()
{
if(data != nullptr)
{
free(data);
data = nullptr;
};
width=0;
height=0;
}
};
struct Tile
{
unsigned char fir_frm_no;
unsigned char fir_mpc_no;
unsigned char sec_frm_no;
unsigned char sec_mpc_no;
unsigned char thr_frm_no;
unsigned char thr_mpc_no;
unsigned char barrer_type;
unsigned char trap_index;
};
class Map
{
public:
Map();
virtual ~Map();
enum MapType
{
JXQY,
TMX
};
static const unsigned char LAYER1 = 0x01;
static const unsigned char LAYER2 = 0x02;
static const unsigned char LAYER3 = 0x04;
static const unsigned char BARRER = 0x08;
static const unsigned char TRAP = 0x10;
long getCol() const {return mCol;}
long getRow() const {return mRow;}
long getPixelWidth() const {return mPixelWidth;}
long getPixelHeight() const {return mPixelHeight;}
//returned wxImage must deleted
wxImage* getImage(unsigned char layer = LAYER1 | LAYER2 | LAYER3, bool hasAlpha = true);
// wxImage* getImage(int beginPosX, int beginPosY, int width, int height, unsigned char layer = LAYER1 | LAYER2 | LAYER3);
/**
input: the map's pixel position
output: the map's corresponding tile position(Column, Row)
return: true - pixelX,pixelY is in map size range;
false - out of map size, Column,Row is unchanged
**/
bool GetTilePosition(int pixelX, int pixelY, int *Column, int *Row);
bool static GetTilePosition(int *Column, int *Row,int pixelX, int pixelY);
/**
input: the map's tile position
output: the map's corresponding pixel position(top-left)
return: true - Column,Row is in map size range;
false - out of map size, pixelX,pixelY is unchanged
**/
bool GetPixelPosition(int Column, int Row, int *pixelX, int *pixelY);
bool static GetPixelPosition(int *pixelX, int *pixelY,int Column, int Row);
bool GetTileCenterPixelPosition(int Column, int Row, int *pixelX, int *pixelY);
bool static GetTileCenterPixelPosition(int *pixelX, int *pixelY,int Column, int Row);
bool IsTileBarrer(int tileX, int tileY);
bool IsTileBarrerTrans(int tileX, int tileY);
unsigned char GetTileBarrerCode(int tileX, int tileY);
unsigned char GetTileBarrerCode(int index);
unsigned char GetTrapIndex(int tileIndex);
bool IsObstacleForCharacter(int tileX, int tileY);
bool ReadFile(const wxString FilePath);
void ShutDownClient();
protected:
private:
/**
Draw tile at Column,Row
TileWidth: in tile width in pixel
TileHeight: in tile height in pixel
TileData: in tile pixel data
**/
void DrawTile(long Column, long Row, long TileWidth, long TileHeight, unsigned char* TileData, wxImage *img);
void DrawTmxTile(long Column, long Row,const Proto::TmxMap::TileImg *tileImg, wxImage *img);
void DoDrawLayer(int index, wxImage* img);
/**
index: 1,2,3
tiles: (mCol * mRow) tiles data
mpcpaths: 255 mpc files path
**/
void DrawLayer(int index, Tile *tiles, MpcDecode *decode, wxImage* img);
void DrawTmxLayer(int index, wxImage* img);
/**
index: 1 - barrer, 2 - trap
**/
void DrawInfoLayer(int index, wxImage* img);
long Char2Long(const unsigned char* in) const
{
long temp = 0;
temp |= (unsigned long)in[0];
temp |= (((unsigned long)in[1]) << 8);
temp |= (((unsigned long)in[2]) << 16);
temp |= (((unsigned long)in[3]) << 24);
return temp;
}
void LoadResource();
void DestoryResource();
void AssignImgData(ImgData *imgdata, wxImage &img);
void DestoryData()
{
if(decode != NULL) delete[] decode;
if(tiles != NULL) delete[] tiles;
if(mTmxImgSrc != nullptr) delete[] mTmxImgSrc;
decode = NULL;
tiles = NULL;
mTmxImgSrc = NULL;
mCol = mRow = mPixelWidth = mPixelHeight = 0;
}
long mCol;
long mRow;
long mPixelWidth; // = (mCol + 1) * 64
long mPixelHeight;// = (mRow + 1) * 16
MpcDecode *decode;
Tile* tiles;
//0 - 透 1-跳透 2-障 3-跳障
ImgData mBarrer[4];
ImgData mTrap[19];
MapType mMapType;
TmxReaderClient mTmxReadClient;
Proto::TmxMap* mTmxMap;
ImgData *mTmxImgSrc;
};
#endif // MAP_H