YAPOG  0.0.1
Yet Another Pokemon Online Game
WorldObject.cpp
Go to the documentation of this file.
4 
5 namespace yap
6 {
8  : id_ (id)
9  , spatial3Info_ ()
10  , physicsBoundingBoxes_ ()
11  {
12  }
13 
15  {
16  }
17 
19  : id_ (copy.id_)
20  , spatial3Info_ (copy.spatial3Info_)
21  , physicsBoundingBoxes_ (copy.physicsBoundingBoxes_)
22  {
23  }
24 
25  const ID& WorldObject::GetID () const
26  {
27  return id_;
28  }
29 
30  void WorldObject::SetID (const ID& id)
31  {
32  id_ = id;
33  }
34 
36  {
37  physicsBoundingBoxes_.SetCollidableArea (*this, collidableArea);
38 
39  HandleSetCollidableArea (collidableArea);
40  }
41 
43  {
44  AdjustCollidablePosition (*boundingBox);
45 
47  }
48 
50  {
52  }
53 
55  const CollidableArea& collidableArea,
56  const Vector2& offset) const
57  {
58  return physicsBoundingBoxes_.CollidesWithArea (collidableArea, offset);
59  }
60 
62  {
63  return spatial3Info_.GetPosition ();
64  }
65 
66  const Vector2& WorldObject::GetSize () const
67  {
69 
70  return spatial3Info_.GetSize ();
71  }
72 
74  {
75  return spatial3Info_.GetTopLeft ();
76  }
77 
79  {
81  GetSize ();
82 
83  return spatial3Info_.GetBottomRight ();
84  }
85 
87  {
89  GetSize ();
90 
91  return spatial3Info_.GetCenter ();
92  }
93 
95  {
97  GetSize ();
98 
99  return spatial3Info_.GetRectangle ();
100  }
101 
102  void WorldObject::Move (const Vector2& offset)
103  {
104  if (offset == Vector2 ())
105  return;
106 
107  spatial3Info_.SetPosition (GetPosition () + offset);
108 
109  HandleMove (offset);
110  }
111 
112  void WorldObject::Scale (const Vector2& factor)
113  {
115  Vector2 (
116  GetSize ().x * factor.x,
117  GetSize ().y * factor.y));
118 
119  HandleScale (factor);
120  }
121 
122  void WorldObject::SetPosition (const Vector2& position)
123  {
124  Move (position - GetPosition ());
125  }
126 
127  void WorldObject::SetSize (const Vector2& size)
128  {
129  Scale (
130  Vector2 (
131  size.x / GetSize ().x,
132  size.y / GetSize ().y));
133  }
134 
135  const int& WorldObject::GetZ () const
136  {
137  return spatial3Info_.GetZ ();
138  }
139 
140  void WorldObject::SetZ (int z)
141  {
142  spatial3Info_.SetZ (z);
143 
144  HandleSetZ (z);
145  }
146 
147  const int& WorldObject::GetH () const
148  {
149  return spatial3Info_.GetH ();
150  }
151 
152  void WorldObject::SetH (int h)
153  {
154  spatial3Info_.SetH (h);
155 
156  HandleSetH (h);
157  }
158 
159  bool WorldObject::CollidesWith (const ICollidable& other) const
160  {
161  return CollidesWith (other, VECTOR2_ZERO);
162  }
163 
165  const ICollidable& other,
166  const Vector2& offset) const
167  {
168  return physicsBoundingBoxes_.CollidesWith (other, offset);
169  }
170 
173  {
174  return physicsBoundingBoxes_;
175  }
176 
178  {
179  collidable.Move (GetPosition ());
180  }
181 
183  {
184  }
185 
187  {
188  return spatial3Info_.GetSize ();
189  }
190 
191  void WorldObject::HandleMove (const Vector2& offset)
192  {
193  physicsBoundingBoxes_.Move (offset);
194  }
195 
196  void WorldObject::HandleScale (const Vector2& factor)
197  {
198  physicsBoundingBoxes_.Scale (factor);
199  }
200 
202  {
204  }
205 
207  {
209  }
210 } // namespace yap