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 deltac
);
67 void moveByTile(coord_t deltac
);
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 bool processDescriptor();
77 bool processSprite(const xmlNode
* sprite
);
78 bool processPhases(const xmlNode
* phases
);
79 bool processPhase(xmlNode
* phase
);
80 bool processSounds(const xmlNode
* sounds
);
81 bool processSound(xmlNode
* sound
);
84 Gosu::Image
* loadImage(const Gosu::Bitmap
& src
, unsigned pos
);
86 //! Called right before starting to moving onto another tile.
87 virtual void preMove(coord_t dest
);
89 //! Called after we've arrived at another tile.
90 virtual void postMove();
95 boost::unordered_map
<std::string
, ImageRef
> imgs
;
99 boost::unordered_map
<std::string
, SampleRef
> sounds
;
107 double rx
, ry
, rz
; // real x,y position: hold partial pixel transversal
109 std::string descriptor
;
111 //! SpriteValues XML Storage Struct
113 Main XML storage struct for Sprite.
115 struct SpriteValues
{
118 boost::unordered_map
<std::string
, unsigned> phases
;