1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
13 #include <boost/scoped_ptr.hpp>
14 #include <Gosu/Graphics.hpp> // for Gosu::Transform
15 #include <libxml/tree.h>
18 #include "resourcer.h"
34 //! This class is responsible for each map, or area in a Tsunagari World.
36 The Area class handles the parsing of TMX-format Area descriptor files,
37 the initialization, placement, and drawing of tiles, and various
38 Area-related functionality.
44 // when changing TileFlags, be sure to make updates to Area::splitTileFlags()
45 //! List of possible flags that can be attached to a tile.
47 Flags are attached to tiles, and denote special behavior for
48 the tile they are bound to.
52 player_nowalk
= 0x0002,
54 player_event
= 0x0008,
59 //! List of possible triggers for tile events.
61 Triggers describe the conditions for the activation of a
62 tile-bound event script funtion.
64 enum TileEventTriggers
{
71 //! Stores info for an event attached to a tile.
73 Events are attached to tiles, and parsed into this struct from a
74 TMX-format area descriptor file. The event is executed when the
75 condition for its trigger is met. The event function name and
76 the function's arguments are stored in argv.
79 TileEventTriggers trigger
;
80 std::string argv
; // Function name and arguments.
83 //! Convenience trigger for inter-area teleportation.
85 Tiles with a door trigger attached can teleport the player to a
86 new area in the World. The Door struct contains the destination
94 //! Contains the properties shared by all tiles of a certain type.
96 This struct contains global tile properties for a tile of a
97 certain type. As opposed to local properties for a single tile,
98 all tiles of this type will share the defined characteristics.
101 std::vector
<Gosu::Image
*> graphics
;
102 bool animated
; // Is the tile animated?
103 double ani_speed
; // Speed of animation in hertz
104 std::vector
<TileEvent
> events
;
105 unsigned flags
; // bitflags for each option in TileFlags enum
109 //! Contains properties unique to this tile.
111 This struct contains local tile properties for a single tile in
112 the area. As opposed to global properties which apply to all
113 tiles of the same type, these properties will only apply to one
118 std::vector
<TileEvent
> events
;
119 unsigned flags
; // bitflags for each option in TileFlags enum
125 Area(Resourcer
* rc
, World
* world
, Entity
* player
, const std::string
& filename
);
130 //! Function that must be called after the constructor.
134 void buttonDown(const Gosu::Button btn
);
140 bool needsRedraw() const;
145 coord_t
getDimensions() const;
146 Tile
* getTile(coord_t c
);
151 Stores info for a tileset, and global settings for tiles.
154 Gosu::Bitmap
* source
; // TODO: make shared_ptr for memory sureness, also delete after done loading tileset
155 coord_t tiledim
; // Dimensions per tile
156 std::vector
<TileType
> defaults
; // Global tile properties
161 Stores info for the intro or main music files.
165 std::string filename
;
168 //! XML descriptor parsing function.
169 bool processDescriptor();
171 //! XML descriptor parsing function.
172 bool processMapProperties(xmlNode
* node
);
174 //! Constructs a tile of default type.
175 TileType
defaultTileType(const Gosu::Bitmap
* source
, coord_t tiledim
,
178 //! XML descriptor parsing function.
179 bool processTileset(xmlNode
* node
);
181 //! XML descriptor parsing function.
182 bool processTileType(xmlNode
* node
, Tileset
& ts
);
184 //! XML descriptor parsing function.
185 bool processLayer(xmlNode
* node
);
187 //! XML descriptor parsing function.
188 bool processLayerProperties(xmlNode
* node
);
190 //! XML descriptor parsing function.
191 bool processLayerData(xmlNode
* node
);
193 //! XML descriptor parsing function.
194 bool processObjectGroup(xmlNode
* node
);
196 //! XML descriptor parsing function.
197 bool processObjectGroupProperties(xmlNode
* node
, int* zpos
);
199 //! XML descriptor parsing function.
200 bool processObject(xmlNode
* node
, int zpos
);
202 //! Split a tile's flags into individuals.
203 unsigned splitTileFlags(const std::string strOfFlags
);
205 //! Process a door convenience trigger.
206 Door
* parseDoor(const std::string dest
);
208 Gosu::Transform
translateCoords();
214 const std::string descriptor
;
217 SampleRef introMusic
, mainMusic
;
218 boost::scoped_ptr
<Gosu::SampleInstance
> musicInst
;
220 typedef std::vector
<Tile
*> row_t
;
221 typedef std::vector
<row_t
> grid_t
;
222 typedef std::vector
<grid_t
> tilematrix_t
;
224 /* All layers in the map must be in the range of [0, n]. There cannot be
232 std::vector
<Tileset
> tilesets
;
234 std::string onLoadEvents
;