fix redraw at top-left of map
[Tsunagari.git] / src / entity.h
blob0c9856d3285dba96321d0b0cbcc997c89ab7095e
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** entity.h **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #ifndef ENTITY_H
8 #define ENTITY_H
10 #include <string>
12 #include <boost/unordered_map.hpp>
13 #include <libxml/parser.h>
15 #include "common.h"
16 #include "resourcer.h"
18 class Area;
19 class Resourcer;
21 namespace Gosu {
22 class Bitmap;
23 class Image;
26 //! An Entity represents one 'thing' that will be rendered to the screen.
27 /*!
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
36 direction.
38 class Entity
40 public:
41 Entity(Resourcer* rc, Area* area);
42 ~Entity();
44 //! Entity Initializer
45 bool init(const std::string& descriptor);
47 //! Gosu Callback
48 void draw();
49 bool needsRedraw() const;
51 void update(unsigned long dt);
53 //! Change the graphic. Returns true if it was changed to something
54 // different.
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);
65 //! Move within Area.
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);
73 protected:
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);
96 Resourcer* rc;
98 boost::unordered_map<std::string, Animation> phases;
99 Animation* phase;
100 bool redraw;
101 std::string facing;
103 boost::unordered_map<std::string, SampleRef> sounds;
105 bool moving;
106 coord_t dest;
107 double speed;
109 Area* area;
110 coord_t c;
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 {
120 std::string sheet;
121 coord_t tileSize;
122 boost::unordered_map<std::string, unsigned> phases;
123 } xml;
126 #endif