00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef PHYSICAL_OBJECT_H
00028 #define PHYSICAL_OBJECT_H
00029
00030 #include "physics.h"
00031 #include "../tool/point.h"
00032 #include "../tool/rectangle.h"
00033
00034
00035 typedef enum
00036 {
00037 ALIVE,
00038 DEAD,
00039 GHOST,
00040 DROWNED
00041 } alive_t;
00042
00043 extern const double PIXEL_PER_METER;
00044
00045 double MeterDistance (const Point2i &p1, const Point2i &p2);
00046
00047 class PhysicalObj : public Physics
00048 {
00049 private:
00050
00051 bool m_goes_through_wall;
00052 bool m_collides_with_characters;
00053 bool m_collides_with_objects;
00054
00055 Point2i m_rebound_position;
00056 protected:
00057 PhysicalObj* m_overlapping_object;
00058
00059 virtual void CheckOverlapping();
00060
00061 protected:
00062 std::string m_name;
00063
00064
00065 uint m_test_left, m_test_right, m_test_top, m_test_bottom;
00066
00067
00068 uint m_width, m_height;
00069
00070 std::string m_rebound_sound;
00071
00072 alive_t m_alive;
00073 int life_points;
00074
00075 bool m_allow_negative_y;
00076
00077 public:
00078 PhysicalObj (const std::string &name, const std::string &xml_config="");
00079 virtual ~PhysicalObj ();
00080
00081
00082
00083
00084 void SetX (int x);
00085 void SetY (int y);
00086 void SetXY(const Point2i &position);
00087 int GetX() const;
00088 int GetY() const;
00089 const Point2i GetPosition() const;
00090
00091
00092 void SetSize(const Point2i &newSize);
00093 int GetWidth() const;
00094 int GetHeight() const;
00095 Point2i GetSize() const;
00096
00097
00098 void SetTestRect (uint left, uint right, uint top, uint bottom);
00099 const Rectanglei GetTestRect() const;
00100 int GetTestWidth() const;
00101 int GetTestHeight() const;
00102
00103
00104 virtual const std::string &GetName() const { return m_name; }
00105 int GetCenterX() const;
00106 int GetCenterY() const;
00107 const Point2i GetCenter() const;
00108 const Rectanglei GetRect() const;
00109 bool GoesThroughWall() const { return m_goes_through_wall; }
00110
00111
00112
00113
00114 void UpdatePosition();
00115
00116
00117 bool PutOutOfGround();
00118 bool PutOutOfGround(double direction);
00119
00120
00121
00122 void SetCollisionModel(bool goes_through_wall,
00123 bool collides_with_characters,
00124 bool collides_with_objects);
00125 void SetOverlappingObject(PhysicalObj* obj);
00126 virtual bool IsOverlapping(const PhysicalObj* obj) const;
00127
00128 bool IsInVacuumXY(const Point2i &position, bool check_objects = true) const;
00129 bool IsInVacuum(const Point2i &offset, bool check_objects = true) const;
00130 PhysicalObj* CollidedObjectXY(const Point2i & position) const;
00131 PhysicalObj* CollidedObject(const Point2i & offset) const;
00132 bool FootsInVacuumXY(const Point2i & position) const;
00133 bool FootsInVacuum() const;
00134
00135 bool FootsOnFloor(int y) const;
00136
00137 bool IsInWater() const;
00138
00139
00140 bool IsOutsideWorldXY(Point2i position) const;
00141 bool IsOutsideWorld(const Point2i &offset) const;
00142
00143
00144 virtual void Refresh() = 0;
00145
00146
00147 virtual void Draw() = 0;
00148
00149
00150 void AddDamage(uint damage_points);
00151
00152
00153 void Init();
00154 void Ghost();
00155 void Drown();
00156 void GoOutOfWater();
00157
00158 virtual bool IsImmobile() const;
00159 bool IsDead() const;
00160 bool IsGhost() const;
00161 bool IsDrowned() const;
00162
00163
00164 bool ObjTouche(const PhysicalObj &b) const;
00165
00166
00167 bool ObjTouche(const Point2i &p) const;
00168
00169 bool PutRandomly(bool on_top_of_world, double min_dst_with_characters);
00170
00171 protected:
00172 virtual void SignalRebound();
00173 virtual void SignalObjectCollision(PhysicalObj * obj);
00174 virtual void SignalGroundCollision();
00175 virtual void SignalCollision();
00176 virtual void SignalOutOfMap();
00177
00178 private:
00179
00180
00181 bool ContactPoint (int &x, int &y);
00182
00183 void NotifyMove(Point2d oldPos, Point2d newPos);
00184
00185
00186 void DirectFall();
00187
00188
00189 void CheckRebound();
00190 };
00191
00192 #endif