YAPOG  0.0.1
Yet Another Pokemon Online Game
BoundingBoxCollection.cpp
Go to the documentation of this file.
5 
6 namespace yap
7 {
9  : spatial3Info_ ()
10  , boundingBoxes_ ()
11  , collidableArea_ (nullptr)
12  {
13  }
14 
16  {
17  for (BoundingBox* boundingBox : boundingBoxes_)
18  delete boundingBox;
19  }
20 
22  const BoundingBoxCollection& copy)
23  : spatial3Info_ (copy.spatial3Info_)
24  , boundingBoxes_ ()
25  , collidableArea_ (nullptr)
26  {
27  }
28 
30  {
31  boundingBoxes_.Add (boundingBox);
32 
33  AddBoundingBoxToCollidableArea (boundingBox);
34  }
35 
37  {
38  boundingBoxes_.Remove (boundingBox);
39 
41  }
42 
44  {
45  return boundingBoxes_.begin ();
46  }
47 
49  {
50  return boundingBoxes_.begin ();
51  }
52 
54  {
55  return boundingBoxes_.end ();
56  }
57 
59  {
60  return boundingBoxes_.end ();
61  }
62 
64  {
65  return spatial3Info_.GetPosition ();
66  }
67 
69  {
70  return spatial3Info_.GetSize ();
71  }
72 
74  {
75  return spatial3Info_.GetTopLeft ();
76  }
77 
79  {
80  return spatial3Info_.GetBottomRight ();
81  }
82 
84  {
85  return spatial3Info_.GetCenter ();
86  }
87 
89  {
90  return spatial3Info_.GetRectangle ();
91  }
92 
93  void BoundingBoxCollection::Move (const Vector2& offset)
94  {
96 
98 
99  for (BoundingBox* boundingBox : boundingBoxes_)
100  boundingBox->Move (offset);
101 
103  }
104 
106  {
108  Vector2 (
109  GetSize ().x * factor.x,
110  GetSize ().y * factor.y));
111 
113 
114  for (BoundingBox* boundingBox : boundingBoxes_)
115  boundingBox->Scale (factor);
116 
118  }
119 
121  {
122  Move (position - GetPosition ());
123  }
124 
126  {
127  Scale (
128  Vector2 (
129  size.x / GetSize ().x,
130  size.y / GetSize ().y));
131  }
132 
133  const int& BoundingBoxCollection::GetZ () const
134  {
135  return spatial3Info_.GetZ ();
136  }
137 
139  {
140  int offset = z - GetZ ();
141 
142  spatial3Info_.SetZ (z);
143 
145 
146  for (BoundingBox* boundingBox : boundingBoxes_)
147  boundingBox->SetZ (boundingBox->GetZ () + offset);
148 
150  }
151 
152  const int& BoundingBoxCollection::GetH () const
153  {
154  return spatial3Info_.GetH ();
155  }
156 
158  {
159  int factor = h / GetH ();
160 
161  spatial3Info_.SetH (h);
162 
164 
165  for (BoundingBox* boundingBox : boundingBoxes_)
166  boundingBox->SetH (boundingBox->GetH () * factor);
167 
169  }
170 
172  {
173  return CollidesWith (other, Vector2 (0.0f, 0.0f));
174  }
175 
177  const ICollidable& other,
178  const Vector2& offset) const
179  {
180  for (BoundingBox* boundingBox : boundingBoxes_)
181  if (boundingBox->CollidesWith (other, offset))
182  return true;
183 
184  return false;
185  }
186 
188  BoundingBox* boundingBox)
189  {
190  if (collidableArea_ == nullptr)
191  return;
192 
194  }
195 
197  BoundingBox* boundingBox)
198  {
199  if (collidableArea_ == nullptr)
200  return;
201 
203  }
204 
206  {
207  return *collidableArea_;
208  }
209 
211  CollidableArea* collidableArea)
212  {
213  if (collidableArea_ == collidableArea)
214  return;
215 
217 
218  collidableArea_ = collidableArea;
219 
221  }
222 
225  {
226  return boundingBoxes_;
227  }
228 
230  {
231  if (collidableArea_ == nullptr)
232  return;
233 
234  for (BoundingBox* boundingBox : boundingBoxes_)
235  AddBoundingBoxToCollidableArea (boundingBox);
236  }
237 
239  {
240  if (collidableArea_ == nullptr)
241  return;
242 
243  for (BoundingBox* boundingBox : boundingBoxes_)
245  }
246 } // namespace yap