1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
14 #include <boost/scoped_ptr.hpp>
15 #include <boost/shared_ptr.hpp>
21 #include "resourcer.h"
40 typedef boost::shared_ptr
<Area
> AreaPtr
;
42 //! This class is responsible for each map, or area in a Tsunagari World.
44 The Area class handles the parsing of TMX-format Area descriptor files,
45 the initialization, placement, and drawing of tiles, and various
46 Area-related functionality.
52 Area(Resourcer
* rc
, World
* world
, Viewport
* view
, Player
* player
,
53 Music
* music
, const std::string
& filename
);
58 //! Function that must be called after the constructor.
62 void buttonDown(const Gosu::Button btn
);
63 void buttonUp(const Gosu::Button btn
);
69 bool needsRedraw() const;
72 void update(unsigned long dt
);
74 icoord
getDimensions() const;
75 ivec2
getTileDimensions() const;
76 int depthIndex(double depth
) const;
77 double indexDepth(int idx
) const;
78 const Tile
& getTile(icoord c
) const;
79 Tile
& getTile(icoord c
);
80 bool tileExists(icoord c
) const;
81 icube_t
visibleTiles() const;
83 bool loopsInX() const;
84 bool loopsInY() const;
87 //! Calculate frame to show for each type of tile
88 void updateTileAnimations();
89 bool inBounds(int x
, int y
, int z
) const;
90 void drawTiles() const;
91 void drawTile(const Tile
& tile
, int x
, int y
, double depth
) const;
95 //! XML descriptor parsing function.
96 bool processDescriptor();
98 //! Allocate all Tile objects for one layer in 'dim' sized map.
99 void allocateMapLayer();
101 //! XML descriptor parsing function.
102 bool processMapProperties(XMLNode node
);
104 //! XML descriptor parsing function.
105 bool processTileSet(XMLNode node
);
107 //! XML descriptor parsing function.
108 bool processTileType(XMLNode node
, TiledImage
& img
, int id
);
110 //! XML descriptor parsing function.
111 bool processLayer(XMLNode node
);
113 //! XML descriptor parsing function.
114 bool processLayerProperties(XMLNode node
, double* depth
);
116 //! XML descriptor parsing function.
117 bool processLayerData(XMLNode node
, int z
);
119 //! XML descriptor parsing function.
120 bool processObjectGroup(XMLNode node
);
122 //! XML descriptor parsing function.
123 bool processObjectGroupProperties(XMLNode node
, double* depth
);
125 //! XML descriptor parsing function.
126 bool processObject(XMLNode node
, int z
);
128 //! Split a tile's flags into individuals.
129 unsigned splitTileFlags(const std::string strOfFlags
);
131 //! Process a door convenience trigger.
132 Door
parseDoor(const std::string dest
);
140 const std::string descriptor
;
142 typedef std::vector
<Tile
> row_t
;
143 typedef std::vector
<row_t
> grid_t
;
144 typedef std::vector
<grid_t
> tilematrix_t
;
146 //! 3-dimensional array of the tiles that make up the map.
149 //! 3-dimensional length of map.
152 //! Pixel size for each tile in area. All tiles in an Area must be the
156 //! Properties shared by all tiles of a type.
157 std::vector
<TileType
> tileTypes
;
159 //! Maps virtual float-point depths to an index in our map array.
160 std::map
<double, int> depth2idx
;
162 //! Maps an index in our map array to a virtual float-point depth.
163 std::vector
<double> idx2depth
;
171 std::string onLoadEvents
;