Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | Related Pages

objects_common.h

00001 #ifndef DEF_OBJECTS_COMMON_H 00002 #define DEF_OBJECTS_COMMON_H 1 00003 00004 //Object types 00005 //dense types are the same as directions (that fact is beeing used) 00006 #define OTYPE_DENSE_R 0x00000001 00007 #define OTYPE_DENSE_L 0x00000002 00008 #define OTYPE_DENSE_U 0x00000004 00009 #define OTYPE_DENSE_D 0x00000008 00010 #define OTYPE_DENSE 0x0000000F 00011 #define OTYPE_COMMON 0x00000010 00012 #define OTYPE_TOUCH 0x00000020 00013 #define OTYPE_ENTER 0x00000040 00014 #define OTYPE_CHARACTER 0x00000080 00015 #define OTYPE_PLAYER 0x00000100 00016 #define OTYPE_MONSTER 0x00000200 00017 #define OTYPE_ITEM 0x00000400 00018 #define OTYPE_PROJ 0x00000800 00019 00020 //Event states 00021 //busy: can't do anything interactively 00022 #define ESTATE_BUSY 0x00001000 00023 //abort: can do anything, event is canceled in case of another event 00024 #define ESTATE_ABORT 0x00002000 00025 //run: default, equivalent to event != NULL 00026 #define ESTATE_RUN 0x00004000 00027 //anim: an animation is beeing played, don't run updateAnimState... 00028 #define ESTATE_ANIM 0x00008000 00029 00030 //OBSOLETE: attack anim (remove this once the attack anim is done) 00031 #define STATE_ATTACK 0x10000000 00032 00038 class Object { 00039 public: 00040 Object(Sint16 xpos=0, Sint16 ypos=0, const ParameterMap& param=ParameterMap()); 00041 virtual ~Object(); 00042 static ParameterMap default_parameters; 00046 bool setPos(Sint16 xcord,Sint16 ycord); 00049 SDL_Rect getCenter() const { 00050 SDL_Rect tmprect; 00051 tmprect.x=pos.x+Uint16(pos.w/2); 00052 tmprect.y=pos.y+Uint16(pos.h/2); 00053 tmprect.w=0; 00054 tmprect.h=0; 00055 return tmprect; 00056 } 00062 bool isIn(const SDL_Rect& rect, bool touch=false) const; 00063 SDL_Rect* getPos() { 00064 return &pos; 00065 } 00066 SDL_Rect getDrawPos() const; 00067 const Frame getFrame() const; 00069 Uint16 getType() const { 00070 return otype; 00071 } 00072 void setType(Uint16 newtype) { 00073 otype|=newtype; 00074 } 00075 void unsetType(Uint16 oldtype) { 00076 otype&=~oldtype; 00077 } 00078 void switchType(Uint16 newtype) { 00079 otype^=newtype; 00080 } 00082 string getName() { 00083 return name; 00084 } 00086 00087 00088 bool updateAnim(Uint16 dt); 00093 bool setAnim(EmptyAnimationPtr anim, bool start=false); 00095 virtual void resetAnimState(); 00096 bool isRunning() const; 00098 00099 00100 void mark_delete() { 00101 delete_flag=true; 00102 } 00103 bool isDeleted() { 00104 return delete_flag; 00105 } 00106 virtual void destroy() { 00107 delete this; 00108 } 00110 00111 EmptyAnimationPtr loadAnimation(string anim_name, 00112 double scale_factor=1, 00113 BasePointType abp_type=BP_MD, 00114 Uint16 aanimation_type=ATYPE_LOOP, 00115 double afps=0, 00116 AllignType aallign_type=AT_MD); 00118 EmptyAnimationPtr loadAnimation(const Image& abase_image, 00119 Uint16 aframes=1, 00120 BasePointType abp_type=BP_MD, 00121 Uint16 aanimation_type=ATYPE_LOOP, 00122 double afps=0, 00123 Uint16 astart_pos=0, 00124 AllignType aallign_type=AT_MD); 00126 EmptyAnimationPtr loadAnimation(const ParameterMap& param=ParameterMap()); 00127 //Events (triggered animations/effects) 00129 00130 00131 00132 void clearEvents(); 00135 virtual void setEvent(Event* ev); 00139 Uint16 updateEvents(Uint16 dt); 00141 void cancelEvent(); 00143 void stopEvent(); 00145 //states 00147 bool getState(Uint32 cstate) const { 00148 return (state&cstate); 00149 } 00150 void setState(Uint32 cstate) { 00151 state|=cstate; 00152 } 00153 void switchState(Uint32 cstate) { 00154 state^=cstate; 00155 } 00156 void unsetState(Uint32 cstate) { 00157 state&=~cstate; 00158 } 00160 //VIRTUAL METHODS 00162 00163 00164 virtual bool act(Object*) { return false; } 00167 virtual void touch(Object*) { } 00170 virtual void enter(Object*) { } 00173 virtual void untouch(Object*) { } 00176 virtual void leave(Object*) { } 00179 virtual void idle(Uint16) { } 00181 bool operator<(const Object& obj) const; 00182 Uint32 onum; 00183 protected: 00184 ParameterMap parameters; 00185 Uint32 state; 00186 Event* event; 00189 SDL_Rect pos; 00190 //Object type 00191 Uint16 otype; 00192 //Object name, can be used as an id 00193 string name; 00194 //delete me flag 00195 bool delete_flag; 00196 EmptyAnimationPtr anim_orig; 00197 EmptyAnimationPtr animation; 00198 }; 00199 00205 class Item : public Object { 00206 public: 00207 Item(Sint16 xpos=0, Sint16 ypos=0, const ParameterMap& param=ParameterMap()); 00208 virtual ~Item(); 00209 static ParameterMap default_parameters; 00210 virtual bool act(Object*) { return false; } 00212 void setOwner(Player* plr) { 00213 owner=plr; 00214 } 00215 protected: 00216 Player* owner; 00217 }; 00218 00222 class Background : public Object { 00223 public: 00224 Background(const ParameterMap& param=ParameterMap()); 00225 virtual ~Background(); 00226 static ParameterMap default_parameters; 00227 }; 00228 00229 #endif

Generated on Sun Feb 5 13:02:35 2006 for Lost Penguins by doxygen 1.3.8