YAPOG
0.0.1
Yet Another Pokemon Online Game
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
WorldObject.cpp
Go to the documentation of this file.
1
#include "
YAPOG/Game/World/Map/WorldObject.hpp
"
2
#include "
YAPOG/Game/World/Map/Physics/CollidableArea.hpp
"
3
#include "
YAPOG/Game/World/Map/Physics/BoundingBox.hpp
"
4
5
namespace
yap
6
{
7
WorldObject::WorldObject
(
const
ID
&
id
)
8
: id_ (id)
9
, spatial3Info_ ()
10
, physicsBoundingBoxes_ ()
11
{
12
}
13
14
WorldObject::~WorldObject
()
15
{
16
}
17
18
WorldObject::WorldObject
(
const
WorldObject
& copy)
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
35
void
WorldObject::SetCollidableArea
(
CollidableArea
* collidableArea)
36
{
37
physicsBoundingBoxes_
.
SetCollidableArea
(*
this
, collidableArea);
38
39
HandleSetCollidableArea
(collidableArea);
40
}
41
42
void
WorldObject::AddPhysicsBoundingBox
(
BoundingBox
* boundingBox)
43
{
44
AdjustCollidablePosition
(*boundingBox);
45
46
physicsBoundingBoxes_
.
AddPhysicsBoundingBox
(boundingBox);
47
}
48
49
void
WorldObject::RemovePhysicsBoundingBox
(
BoundingBox
* boundingBox)
50
{
51
physicsBoundingBoxes_
.
RemovePhysicsBoundingBox
(boundingBox);
52
}
53
54
bool
WorldObject::CollidesWith
(
55
const
CollidableArea
& collidableArea,
56
const
Vector2
& offset)
const
57
{
58
return
physicsBoundingBoxes_
.
CollidesWithArea
(collidableArea, offset);
59
}
60
61
const
Vector2
&
WorldObject::GetPosition
()
const
62
{
63
return
spatial3Info_
.
GetPosition
();
64
}
65
66
const
Vector2
&
WorldObject::GetSize
()
const
67
{
68
spatial3Info_
.
SetSize
(
HandleGetSize
());
69
70
return
spatial3Info_
.
GetSize
();
71
}
72
73
const
Vector2
&
WorldObject::GetTopLeft
()
const
74
{
75
return
spatial3Info_
.
GetTopLeft
();
76
}
77
78
const
Vector2
&
WorldObject::GetBottomRight
()
const
79
{
81
GetSize
();
82
83
return
spatial3Info_
.
GetBottomRight
();
84
}
85
86
const
Vector2
&
WorldObject::GetCenter
()
const
87
{
89
GetSize
();
90
91
return
spatial3Info_
.
GetCenter
();
92
}
93
94
const
sf::FloatRect
&
WorldObject::GetRectangle
()
const
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
{
114
spatial3Info_
.
SetSize
(
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
164
bool
WorldObject::CollidesWith
(
165
const
ICollidable
& other,
166
const
Vector2
& offset)
const
167
{
168
return
physicsBoundingBoxes_
.
CollidesWith
(other, offset);
169
}
170
171
const
PhysicsBoundingBoxCollection
&
172
WorldObject::GetPhysicsBoundingBoxes
()
const
173
{
174
return
physicsBoundingBoxes_
;
175
}
176
177
void
WorldObject::AdjustCollidablePosition
(
ICollidable
& collidable)
const
178
{
179
collidable.
Move
(
GetPosition
());
180
}
181
182
void
WorldObject::HandleSetCollidableArea
(
CollidableArea
* collidableArea)
183
{
184
}
185
186
Vector2
WorldObject::HandleGetSize
()
const
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
201
void
WorldObject::HandleSetZ
(
int
z)
202
{
203
physicsBoundingBoxes_
.
SetZ
(z);
204
}
205
206
void
WorldObject::HandleSetH
(
int
h)
207
{
208
physicsBoundingBoxes_
.
SetH
(h);
209
}
210
}
// namespace yap
YAPOG
src
YAPOG
Game
World
Map
WorldObject.cpp
Generated on Mon Sep 17 2012 22:24:25 for YAPOG by
1.8.1.1