The Game Engine
1
Main Page
Related Pages
Classes
Files
File List
File Members
WorldObject.h
Go to the documentation of this file.
1
#ifndef __WORLDOBJECT_H__
2
#define __WORLDOBJECT_H__
3
#include "
fns.h
"
4
#include "
CollisionObject.h
"
5
6
// predeclared for build
7
class
CollisionObject
;
8
19
class
WorldObject
20
{
21
public
:
22
WorldObject
(std::string name,
Point2D
pos =
Point2D
(),
int
z = 0);
23
28
enum
WorldObjectType
{
29
SPRITE
,
30
BACKGROUND
,
31
MENU
,
32
TEXT
,
33
PARTICLESYSTEM
34
};
35
39
virtual
void
draw
() = 0;
40
44
virtual
void
drawCollisions
();
45
49
void
drawCollisions
(vector<CollisionObject*>& vec,
const
Point2D
& pos);
50
55
virtual
void
update
();
56
60
virtual
void
runBehavior
();
61
65
void
setPosition
(
double
x,
double
y) {
mPos
.
x
= x;
mPos
.
y
= y;}
66
70
void
setPosition
(
Point2D
pos) {
mPos
= pos; }
71
75
void
setBasePosition
(
double
x,
double
y) {
Point2D
bPos =
getBasePos
();
mPos
.
x
= x - bPos.
x
;
mPos
.
y
= y - bPos.
y
;}
76
80
void
setBasePosition
(
Point2D
pos) {
Point2D
bPos =
getBasePos
();
mPos
.
x
= pos.
x
- bPos.
x
;
mPos
.
y
= pos.
y
- bPos.
y
;}
81
85
void
setCenterPosition
(
double
x,
double
y) {
Point2D
cPos =
getCenterPos
();
mPos
.
x
= x - cPos.
x
;
mPos
.
y
= y - cPos.
y
;}
86
90
void
setCenterPosition
(
Point2D
pos) {
Point2D
cPos =
getCenterPos
();
mPos
.
x
= pos.
x
- cPos.
x
;
mPos
.
y
= pos.
y
- cPos.
y
;}
91
97
void
move
(
double
dx=0.0,
double
dy=0.0){
mPos
.
x
+=dx;
mPos
.
y
+=dy;}
98
103
virtual
void
move
(
Point2D
direction) {
mPos
+= direction; }
104
109
virtual
void
moveTowards
(
Point2D
direction);
110
114
Point2D
getPosition
() {
return
mPos
; }
115
120
void
setTransparency
(
float
f) {
mTransparency
= f>1?1:f<0?0:f;}
121
125
float
getTransparency
() {
return
mTransparency
;}
126
131
void
setAngle
(
float
a) {
mAngle
= a;
while
(a>360)a-=360;}
132
136
float
getAngle
() {
return
mAngle
;}
137
142
void
setVelocity
(
Point2D
vel) {
143
mVelocity
= vel;
144
if
(
mMaxVelocity
< vel){
145
setMaxVelocity
(vel);
146
}
147
}
148
154
void
setVelocity
(
double
xVel,
double
yVel) {
155
mVelocity
.
x
= xVel;
156
mVelocity
.
y
= yVel;
157
if
(
mMaxVelocity
<
mVelocity
){
158
setMaxVelocity
(
mVelocity
);
159
}
160
}
161
165
Point2D
getVelocity
() {
return
mVelocity
;}
166
171
void
setMaxVelocity
(
Point2D
vel) {
mMaxVelocity
= vel; }
172
178
void
setMaxVelocity
(
double
vel,
Point2D
dir) {
179
mMaxVelocity
= dir.
unitVec
();
180
mMaxVelocity
*= vel;
181
}
182
187
void
setMaxSpeed
(
double
vel) {
188
if
(abs(
mMaxVelocity
.
lengthSquared
()) < numeric_limits<double>::epsilon()){
//if the velocity is 0
189
mMaxSpeed
= vel;
190
}
191
else
{
192
setMaxVelocity
(vel,
mVelocity
);
193
}
194
}
195
199
Point2D
getMaxVelocity
() {
return
mMaxVelocity
;}
200
204
double
getMaxSpeed
();
205
209
double
getMaxSpeedSquared
();
210
215
void
setAcceleration
(
Point2D
accel) {
mAcceleration
= accel; }
216
220
Point2D
getAcceleration
() {
return
mAcceleration
;}
221
222
void
setZOrder
(
int
i) {
ZOrder
=i; }
223
int
getZOrder
() {
return
ZOrder
; }
224
228
std::string
getName
() {
return
mName
; }
229
233
bool
operator<
(
WorldObject
&rhs) {
return
ZOrder
== rhs.
getZOrder
() ?
getBasePos
().
y
< rhs.
getBasePos
().
y
:
ZOrder
< rhs.
getZOrder
(); }
234
238
virtual
Point2D
getBasePos
() = 0;
239
243
virtual
Point2D
getCenterPos
() = 0;
244
248
virtual
WorldObjectType
getType
() = 0;
249
250
protected
:
252
std::string
mName
;
254
Point2D
mPos
;
256
Point2D
mVelocity
;
258
Point2D
mMaxVelocity
;
260
double
mMaxSpeed
;
262
Point2D
mAcceleration
;
264
bool
mVisible
;
266
float
mTransparency
;
268
float
mAngle
;
270
float
mScale
;
272
int
ZOrder
;
274
long
mLastUpdate
;
276
long
mLastDraw
;
278
bool
mUnused
;
280
Behavior
mBehavior
;
281
};
282
#endif
WorldObject.h
Generated on Tue Apr 16 2013 02:32:41 for The Game Engine by
1.8.3.1