1 /******************************
2 ** Tsunagari Tile Engine **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
12 #include <boost/scoped_ptr.hpp>
13 #include <boost/unordered_map.hpp>
14 #include <libxml/parser.h>
17 #include "resourcer.h"
29 This class handles dynamic game objects, such as monsters, NPCs, and
34 * Sprite is an image model for displaying 2D video game entities.
36 * Each Sprite represents one 'thing' that will be rendered to the screen.
37 * Sprite can handle animated images that cycle through their frames over time.
38 * It also has the capacity to switch between a couple different images on
41 * For example, you might have a Sprite for a player character with animated
42 * models for walking in each possible movement direction (up, down, left,
43 * right) along with static standing-still images for each direction. This
44 * could all be handled by one Sprite.
49 Entity(Resourcer
* rc
, Area
* area
);
52 //! Entity Initializer
53 bool init(const std::string
& descriptor
);
57 bool needsRedraw() const;
59 //! Change the graphic. Returns true if it was changed to something
61 bool setPhase(const std::string
& name
);
63 //! Retrieve position within Area.
64 coord_t
getCoordsByPixel() const;
65 coord_t
getCoordsByTile() const;
67 //! Set location within Area.
68 void setCoordsByPixel(coord_t c
);
69 void setCoordsByTile(coord_t c
);
72 void moveByPixel(coord_t deltac
);
73 void moveByTile(coord_t deltac
);
75 //! Sets the Area object this entity will ask when looking for
76 // nearby Tiles. Doesn't change x,y,z position.
77 void setArea(Area
* area
);
79 SampleRef
getSound(const std::string
& name
);
82 bool processDescriptor();
83 bool processSprite(const xmlNode
* sprite
);
84 bool processPhases(const xmlNode
* phases
);
85 bool processPhase(xmlNode
* phase
);
86 bool processSounds(const xmlNode
* sounds
);
87 bool processSound(xmlNode
* sound
);
90 Gosu::Image
* loadImage(const Gosu::Bitmap
& src
, unsigned pos
);
92 virtual void postMove();
97 boost::unordered_map
<std::string
, SampleRef
> sounds
;
98 boost::unordered_map
<std::string
, ImageRef
> imgs
;
105 std::string descriptor
;
107 //! SpriteValues XML Storage Struct
109 Main XML storage struct for Sprite.
111 struct SpriteValues
{
113 coord_t tileSize
; // z-coord not used
114 boost::unordered_map
<std::string
, unsigned> phases
;