1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
13 #include <boost/unordered_map.hpp>
14 #include <libxml/parser.h>
16 #include "area-structs.h" // for enum TileEventTriggers
18 #include "resourcer.h"
29 //! An Entity represents one 'thing' that will be rendered to the screen.
31 An Entity might be a dynamic game object such as a monster, NPC, or
32 item. Entity can handle animated images that cycle through their
33 frames over time. It also has the capacity to switch between a couple
34 different images on demand.
36 For example, you might have a Entity for a player character with
37 animated models for walking in each possible movement direction (up,
38 down, left, right) along with static standing-still images for each
44 Entity(Resourcer
* rc
, Area
* area
, ClientValues
* conf
);
47 //! Entity Initializer
48 bool init(const std::string
& descriptor
);
52 bool needsRedraw() const;
54 void update(unsigned long dt
);
56 //! Change the graphic. Returns true if it was changed to something
58 bool setPhase(const std::string
& name
);
60 //! Retrieve position within Area.
61 coord_t
getCoordsByPixel() const;
62 coord_t
getCoordsByTile() const;
64 //! Set location within Area.
65 void setCoordsByPixel(coord_t c
);
66 void setCoordsByTile(coord_t c
);
69 void moveByPixel(coord_t delta
);
70 void moveByTile(coord_t delta
);
72 //! Sets the Area object this entity will ask when looking for
73 // nearby Tiles. Doesn't change x,y,z position.
74 void setArea(Area
* area
);
77 // Lua callback targets
80 //! Move to the upper left corner. Sets x,y tile positions to 1,1.
81 void gotoRandomTile();
84 //! Get the Tile we are standing on.
87 SampleRef
getSound(const std::string
& name
);
89 //! Calculate which way to face based upon a movement delta.
90 void calculateFacing(coord_t delta
);
92 //! Called right before starting to moving onto another tile.
93 virtual void preMove(coord_t delta
);
94 virtual void preMoveLua();
96 //! Called after we have arrived at another tile.
97 virtual void postMove();
98 virtual void postMoveLua();
100 void tileScripts(Tile
& tile
, std::vector
<TileEvent
>& events
, TileEventTriggers trigger
);
101 void runTileLua(Tile
& tile
, const std::string
& script
);
103 // XML parsing functions used in constructing an Entity
104 bool processDescriptor();
105 bool processSprite(const xmlNode
* sprite
);
106 bool processPhases(const xmlNode
* phases
);
107 bool processPhase(xmlNode
* phase
, const TiledImage
& tiles
);
108 bool processMember(xmlNode
* phase
, Animation
& anim
,
109 const TiledImage
& tiles
);
110 bool processSounds(const xmlNode
* sounds
);
111 bool processSound(xmlNode
* sound
);
112 void processScripts(const xmlNode
* scripts
);
113 void processScript(xmlNode
* script
);
118 boost::unordered_map
<std::string
, Animation
> phases
;
123 boost::unordered_map
<std::string
, SampleRef
> sounds
;
124 boost::unordered_map
<std::string
, std::string
> scripts
;
133 double rx
, ry
, rz
; // real x,y position: hold partial pixel transversal
135 std::string descriptor
;
139 //! SpriteValues XML Storage Struct
141 Main XML storage struct for Sprite.
143 struct SpriteValues
{
146 boost::unordered_map
<std::string
, unsigned> phases
;