-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile_map.hpp
65 lines (48 loc) · 2.08 KB
/
tile_map.hpp
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
#ifndef TILE_MAP_HPP_INCLUDED
#define TILE_MAP_HPP_INCLUDED
#include "tile.hpp"
#include "tile_manager.hpp"
#include "a10_common.hpp"
class TileMap
{
vector2<int> size, tile_size;
MapCoords start_pos;
list<MapCoords> enemy_positions;
//vector< Tile* > tiles;
TileSet* tiles;
Tile** data; ///< two dimensional array of pointers to tiles ;)
void deleteData();
public:
TileMap(int w, int h, int tile_w, int tile_h, TileSet* ts)
: size(w,h), tile_size(tile_w, tile_h),
start_pos(0,0), tiles(ts)
{
assert(w>0 and h>0);
assert(tile_w>0 and tile_h>0);
assert(tiles);
data = new Tile* [size.x * size.y];
setNULL(data, size.x * size.y);
};
TileMap() : tiles(NULL), data(NULL) {};
void loadFromFile(string map_file_path, boost::function<TileSet*(string)> tileset_factory);
~TileMap();
FNumber getDistToNearestBlock(CBoxEdge<FNumber>& e, FNumber maxdist, int dim, uint32_t flag);
bool collides(CBox<FNumber> box, uint32_t flag);
bool collides(CBoxEdge<FNumber> edge, uint32_t flag);
bool collides(ScreenCoords point, uint32_t flag);
bool collides(MapCoords point, uint32_t flag);
inline int tileSize(const int dim) {assert(valid_dim(dim)); return this->tile_size[dim];};
inline Tile* getData(int x, int y){assert(x>=0 and x<size.x); assert(y>=0 and y<size.y); assert(data); return data[y*size.x + x];}
inline Tile* getData(MapCoords pos){return getData(pos.x,pos.y);}
inline int getWidth(){return this->size.x;}
inline int getHeight(){return this->size.y;}
inline int getTileW(){return this->tile_size.x;}
inline int getTileH(){return this->tile_size.y;}
inline int getPixelSize(int dim){assert(valid_dim(dim)); return (dim==1?this->getPixelWidth():this->getPixelHeight());}
inline int getPixelWidth() {return this->size.x*this->tile_size.x;}
inline int getPixelHeight(){return this->size.y*this->tile_size.y;}
inline ScreenCoords getStartPosScr(){return this->toScreenCoords(this->start_pos)+(this->tile_size.cast<Vect::T>()/2);}
MapCoords toMapCoords(ScreenCoords v);
ScreenCoords toScreenCoords(MapCoords v);
};
#endif // TILE_MAP_HPP_INCLUDED