00001 00002 // Copyright (C) 2004-2007 by The Allacrost Project 00003 // All Rights Reserved 00004 // 00005 // This code is licensed under the GNU GPL version 2. It is free software 00006 // and you may modify it and/or redistribute it under the terms of this license. 00007 // See http://www.gnu.org/copyleft/gpl.html for details. 00009 00016 #ifndef __MAP_OBJECTS_HEADER__ 00017 #define __MAP_OBJECTS_HEADER__ 00018 00019 #include "utils.h" 00020 #include "defs.h" 00021 00022 #include "video.h" 00023 00024 namespace hoa_map { 00025 00026 namespace private_map { 00027 00032 const uint8 PHYSICAL_TYPE = 0; 00033 const uint8 VIRTUAL_TYPE = 1; 00034 const uint8 SPRITE_TYPE = 2; 00035 const uint8 ENEMY_TYPE = 3; 00037 00053 class MapObject { 00054 public: 00061 int16 object_id; 00062 00076 uint32 context; 00077 00090 uint16 x_position, y_position; 00091 float x_offset, y_offset; 00093 00103 float img_half_width, img_height; 00104 00117 float coll_half_width, coll_height; 00118 00120 bool updatable; 00121 00123 bool visible; 00124 00133 bool no_collision; 00134 00139 bool draw_on_second_pass; 00140 00141 std::string filename; 00142 00143 // ---------- Methods 00144 00145 MapObject(); 00146 00147 virtual ~MapObject() 00148 {} 00149 00156 virtual void Update() = 0; 00157 00163 virtual void Draw() = 0; 00164 00173 bool DrawHelper(); 00174 00183 float ComputeXLocation() const 00184 { return (static_cast<float>(x_position) + x_offset); } 00185 00186 float ComputeYLocation() const 00187 { return (static_cast<float>(y_position) + y_offset); } 00189 00195 void SetObjectID(int16 id = 0) 00196 { object_id = id; } 00197 00198 void SetContext(uint32 ctxt) 00199 { context = ctxt; } 00200 00201 void SetXPosition(uint16 x, float offset) 00202 { x_position = x; x_offset = offset; } 00203 00204 void SetYPosition(uint16 y, float offset) 00205 { y_position = y; y_offset = offset; } 00206 00207 void SetImgHalfWidth(float width) 00208 { img_half_width = width; } 00209 00210 void SetImgHeight(float height) 00211 { img_height = height; } 00212 00213 void SetCollHalfWidth(float collision) 00214 { coll_half_width = collision; } 00215 00216 void SetCollHeight(float collision) 00217 { coll_height = collision; } 00218 00219 void SetUpdatable(bool update) 00220 { updatable = update; } 00221 00222 void SetVisible(bool vis) 00223 { visible = vis; } 00224 00225 void SetNoCollision(bool coll) 00226 { no_collision = coll; } 00227 00228 void SetDrawOnSecondPass(bool pass) 00229 { draw_on_second_pass = pass; } 00230 00231 int16 GetObjectID() const 00232 { return object_id; } 00233 00234 uint32 GetContext() const 00235 { return context; } 00236 00237 void GetXPosition(uint16 &x, float &offset) const 00238 { x = x_position; offset = x_offset; } 00239 00240 void GetYPosition(uint16 &y, float &offset) const 00241 { y = y_position; offset = y_offset; } 00242 00243 float GetImgHalfWidth() const 00244 { return img_half_width; } 00245 00246 float GetImgHeight() const 00247 { return img_height; } 00248 00249 float GetCollHalfWidth() const 00250 { return coll_half_width; } 00251 00252 float GetCollHeight() const 00253 { return coll_height; } 00254 00255 bool IsUpdatable() const 00256 { return updatable; } 00257 00258 bool IsVisible() const 00259 { return visible; } 00260 00261 bool IsNoCollision() const 00262 { return no_collision; } 00263 00264 bool IsDrawOnSecondPass() const 00265 { return draw_on_second_pass; } 00266 00267 uint8 GetType() const 00268 { return _object_type; } 00270 00271 protected: 00273 uint8 _object_type; 00274 00275 }; // class MapObject 00276 00277 00282 struct MapObject_Ptr_Less { 00283 const bool operator()(const MapObject * a, const MapObject * b) { 00284 return (a->y_position + a->y_offset) < (b->y_position + b->y_offset); 00285 } 00286 }; 00287 00288 00301 class PhysicalObject : public MapObject { 00302 public: 00304 uint8 current_animation; 00305 00311 std::vector<hoa_video::AnimatedImage> animations; 00312 00313 PhysicalObject(); 00314 00315 ~PhysicalObject(); 00316 00318 void Update(); 00319 00321 void Draw(); 00322 00328 void AddAnimation(hoa_video::AnimatedImage new_img) 00329 { animations.push_back(new_img); } 00330 00331 void SetCurrentAnimation(uint8 current) 00332 { animations[current_animation].SetTimeProgress(0); current_animation = current; } 00333 00334 void SetAnimationProgress(uint32 progress) 00335 { animations[current_animation].SetTimeProgress(progress); } 00336 00337 uint8 GetCurrentAnimation() const 00338 { return current_animation; } 00340 }; // class PhysicalObject : public MapObject 00341 00342 } // namespace private_map 00343 00344 } // namespace hoa_map 00345 00346 #endif
1.5.1