1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
13 #include <Gosu/Graphics.hpp> // for Gosu::Transform
14 #include <libxml/parser.h>
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;
142 coord_t
getDimensions() const;
143 Tile
* getTile(coord_t c
);
148 Stores info for a tileset, and global settings for tiles.
151 Gosu::Bitmap
* source
; // TODO: make shared_ptr for memory sureness, also delete after done loading tileset
152 coord_t tiledim
; // Dimensions per tile
153 std::vector
<TileType
> defaults
; // Global tile properties
158 Stores info for the intro or main music files.
162 std::string filename
;
165 //! XML descriptor parsing function.
166 bool processDescriptor();
168 //! XML descriptor parsing function.
169 bool processMapProperties(xmlNode
* node
);
171 //! Constructs a tile of default type.
172 TileType
defaultTileType(const Gosu::Bitmap
* source
, coord_t tiledim
,
175 //! XML descriptor parsing function.
176 bool processTileset(xmlNode
* node
);
178 //! XML descriptor parsing function.
179 bool processTileType(xmlNode
* node
, Tileset
& ts
);
181 //! XML descriptor parsing function.
182 bool processLayer(xmlNode
* node
);
184 //! XML descriptor parsing function.
185 bool processLayerProperties(xmlNode
* node
);
187 //! XML descriptor parsing function.
188 bool processLayerData(xmlNode
* node
);
190 //! XML descriptor parsing function.
191 bool processObjectGroup(xmlNode
* node
);
193 //! XML descriptor parsing function.
194 bool processObjectGroupProperties(xmlNode
* node
, int* zpos
);
196 //! XML descriptor parsing function.
197 bool processObject(xmlNode
* node
, int zpos
);
199 //! Split a tile's flags into individuals.
200 unsigned splitTileFlags(const std::string strOfFlags
);
202 //! Process a door convenience trigger.
203 Door
* parseDoor(const std::string dest
);
205 Gosu::Transform
translateCoords();
211 const std::string descriptor
;
213 Gosu::SampleInstance
* music_inst
;
215 typedef std::vector
<Tile
*> row_t
;
216 typedef std::vector
<row_t
> grid_t
;
217 typedef std::vector
<grid_t
> tilematrix_t
;
219 /* All layers in the map must be in the range of [0, n]. There cannot be
227 std::vector
<Tileset
> tilesets
;
231 std::string onLoadEvents
;