1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
12 #include <boost/unordered_map.hpp>
13 #include <libxml/parser.h>
16 #include "resourcer.h"
26 //! An Entity represents one 'thing' that will be rendered to the screen.
28 An Entity might be a dynamic game object such as a monster, NPC, or
29 item. Entity can handle animated images that cycle through their
30 frames over time. It also has the capacity to switch between a couple
31 different images on demand.
33 For example, you might have a Entity for a player character with
34 animated models for walking in each possible movement direction (up,
35 down, left, right) along with static standing-still images for each
41 Entity(Resourcer
* rc
, Area
* area
);
44 //! Entity Initializer
45 bool init(const std::string
& descriptor
);
49 bool needsRedraw() const;
51 void update(unsigned long dt
);
53 //! Change the graphic. Returns true if it was changed to something
55 bool setPhase(const std::string
& name
);
57 //! Retrieve position within Area.
58 coord_t
getCoordsByPixel() const;
59 coord_t
getCoordsByTile() const;
61 //! Set location within Area.
62 void setCoordsByPixel(coord_t c
);
63 void setCoordsByTile(coord_t c
);
66 void moveByPixel(coord_t delta
);
67 void moveByTile(coord_t delta
);
69 //! Sets the Area object this entity will ask when looking for
70 // nearby Tiles. Doesn't change x,y,z position.
71 void setArea(Area
* area
);
74 SampleRef
getSound(const std::string
& name
);
76 //! Calculate which way to face based upon a movement delta.
77 void calculateFacing(coord_t delta
);
79 //! Called right before starting to moving onto another tile.
80 virtual void preMove(coord_t delta
);
82 //! Called after we've arrived at another tile.
83 virtual void postMove();
85 bool processDescriptor();
86 bool processSprite(const xmlNode
* sprite
);
87 bool processPhases(const xmlNode
* phases
);
88 bool processPhase(xmlNode
* phase
, const TiledImage
& tiles
);
89 bool processMember(xmlNode
* phase
, Animation
& anim
,
90 const TiledImage
& tiles
);
91 bool processSounds(const xmlNode
* sounds
);
92 bool processSound(xmlNode
* sound
);
98 boost::unordered_map
<std::string
, Animation
> phases
;
103 boost::unordered_map
<std::string
, SampleRef
> sounds
;
111 double rx
, ry
, rz
; // real x,y position: hold partial pixel transversal
113 std::string descriptor
;
115 //! SpriteValues XML Storage Struct
117 Main XML storage struct for Sprite.
119 struct SpriteValues
{
122 boost::unordered_map
<std::string
, unsigned> phases
;