area: fix compiler warnings
[Tsunagari.git] / src / entity.h
blob1060082122362a842e6b54806905d6e056ecfa7b
1 /******************************
2 ** Tsunagari Tile Engine **
3 ** entity.h **
4 ** Copyright 2011 OmegaSDG **
5 ******************************/
7 #ifndef SPRITE_H
8 #define SPRITE_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 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);
73 protected:
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);
83 bool loadPhases();
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();
93 Resourcer* rc;
95 boost::unordered_map<std::string, ImageRef> imgs;
96 ImageRef img;
97 bool redraw;
99 boost::unordered_map<std::string, SampleRef> sounds;
101 bool moving;
102 coord_t dest;
103 double speed;
105 Area* area;
106 coord_t c;
107 double rx, ry, rz; // real x,y position, holds partial pixel transversal
109 std::string descriptor;
111 //! SpriteValues XML Storage Struct
113 Main XML storage struct for Sprite.
115 struct SpriteValues {
116 std::string sheet;
117 coord_t tileSize; // z-coord not used
118 boost::unordered_map<std::string, unsigned> phases;
119 } xml;
122 #endif