tile animations!
[Tsunagari.git] / src / entity.h
blobb3f192ac6644c5b325f0ac232cb880383d5eba27
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/scoped_ptr.hpp>
13 #include <boost/unordered_map.hpp>
14 #include <libxml/parser.h>
16 #include "common.h"
17 #include "resourcer.h"
19 class Area;
20 class Resourcer;
22 namespace Gosu {
23 class Bitmap;
24 class Image;
27 //! Entity Class
28 /*!
29 This class handles dynamic game objects, such as monsters, NPCs, and
30 items.
33 /**
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
39 * demand.
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.
46 class Entity
48 public:
49 Entity(Resourcer* rc, Area* area);
50 ~Entity();
52 //! Entity Initializer
53 bool init(const std::string& descriptor);
55 //! Gosu Callback
56 void draw();
57 bool needsRedraw() const;
59 //! Change the graphic. Returns true if it was changed to something
60 // different.
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);
71 //! Move within Area.
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);
81 protected:
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);
89 bool loadPhases();
90 Gosu::Image* loadImage(const Gosu::Bitmap& src, unsigned pos);
92 virtual void postMove();
95 Resourcer* rc;
97 boost::unordered_map<std::string, SampleRef> sounds;
98 boost::unordered_map<std::string, ImageRef> imgs;
99 ImageRef img;
100 bool redraw;
102 Area* area;
103 coord_t c;
105 std::string descriptor;
107 //! SpriteValues XML Storage Struct
109 Main XML storage struct for Sprite.
111 struct SpriteValues {
112 std::string sheet;
113 coord_t tileSize; // z-coord not used
114 boost::unordered_map<std::string, unsigned> phases;
115 } xml;
118 #endif