![]() |
Dragonfly 2.2
A text-based game engine
|
00001 /// 00002 /// The base object. 00003 /// 00004 00005 #ifndef __OBJECT_H__ 00006 #define __OBJECT_H__ 00007 00008 #include "Position.h" ///< Objects need a location. 00009 #include "Box.h" ///< Objects have a bounding box. 00010 #include "Event.h" ///< Objects can handle events. 00011 #include "Sprite.h" ///< Objects (often) have sprites. 00012 00013 class Object { 00014 00015 private: 00016 int id; ///< Globally unique id of object 00017 bool is_visible; ///< If true, object gets drawn. 00018 bool is_persistent; ///< If true, object are active all levels. 00019 00020 protected: 00021 string type; ///< User-defined identification. 00022 Position pos; ///< Position in the game world. 00023 Sprite *p_sprite; ///< The sprite associated with this object. 00024 bool sprite_center; ///< True if sprite is centered on object. 00025 int sprite_index; ///< Current index frame for sprite. 00026 int sprite_slowdown; ///< Slowdown rate (1 = no slowdown, 0 = stop). 00027 int sprite_slowdown_count; ///< Slowdown counter. 00028 Box box; ///< Box for sprite boundary & collisions. 00029 00030 public: 00031 Object(); 00032 virtual ~Object(); 00033 void setId(int new_id); 00034 int getId(); 00035 void setType(string new_type); 00036 string getType(); 00037 void setBox(Box new_box); 00038 Box getBox(); 00039 void setPosition(Position new_pos); 00040 Position getPosition(); 00041 00042 /// Set persistence of object. Returns 0. 00043 virtual int setPersistence(bool persistent); 00044 00045 /// Return persistence of object. Persistent objects are active across all 00046 /// levels. 00047 bool isPersistent(); 00048 00049 /// Set visibility of object. Objects not visible are not drawn. 00050 /// Return 0. 00051 virtual int setVisibility(bool visible); 00052 00053 /// Return visibility of object. Objects not visible are not drawn. 00054 bool isVisible(); 00055 00056 /// Handle event (default is to ignore everything). 00057 /// Return 0 if ignored, else 1 00058 virtual int eventHandler(Event *p_event); 00059 00060 /// Draw single sprite frame. 00061 /// Drawing accounts for: centering, slowdown, 00062 /// advancing Sprite Frame (as appropriate for each). 00063 virtual void draw(); 00064 00065 /// Set Sprite associated with this object to new one. 00066 /// Set bounding box to size of sprite. 00067 void setSprite(Sprite *p_new_sprite); 00068 00069 /// Set object Sprite to new one. 00070 /// If set_box is true, set bounding box to size of Sprite. 00071 void setSprite(Sprite *p_new_sprite, bool set_box); 00072 00073 /// Return pointer to Sprite associated with this object. 00074 Sprite *getSprite(); 00075 00076 /// Indicates if sprite is centered at object Position (pos). 00077 bool isCentered(); 00078 00079 /// Indicate sprite is to centered at object Position (pos). 00080 void setCentered(bool centered); 00081 00082 /// Return the index of current Sprite frame to be displayed. 00083 int getSpriteIndex(); 00084 00085 /// Set index of current Sprite frame to be displayed. 00086 void setSpriteIndex(int new_sprite_index); 00087 00088 /// Slows down sprite animations. 00089 /// new_sprite_slowdown is in multiples of WorldManager frame time. 00090 void setSpriteSlowdown(int new_sprite_slowdown); 00091 int getSpriteSlowdown(); 00092 void setSpriteSlowdownCount(int new_sprite_slowdown_count); 00093 int getSpriteSlowdownCount(); 00094 }; 00095 00096 #endif // __OBJECT_H__