-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovingObject.cpp
More file actions
executable file
·57 lines (44 loc) · 1.2 KB
/
Copy pathmovingObject.cpp
File metadata and controls
executable file
·57 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "movingObject.h"
movingObject::movingObject()
{
mPushedRightWall = false;
mPushesRightWall = false;
mPushedLeftWall = false;
mPushesLeftWall = false;
mWasOnGround = false;
mOnGround = false;
mWasAtCeiling = false;
mAtCeiling = false;
}
bool movingObject::Overlaps(AABB other)
{
if(abs(mAABB.center.x - other.center.x) > (mAABB.halfsize.x + other.halfsize.x)) return false;
if(abs(mAABB.center.y - other.center.y) > (mAABB.halfsize.y + other.halfsize.y)) return false;
return true;
}
void movingObject::UpdatePhysics()
{
//Save the previous frame's data.
mOldPosition = mPosition;
mOldSpeed = mSpeed;
mWasOnGround = mOnGround;
mPushedRightWall = mPushesRightWall;
mPushedLeftWall = mPushesLeftWall;
mWasAtCeiling = mAtCeiling;
//Update the position.
mPosition.x += (int)(mSpeed.x * timeStep);
mPosition.y += (int)(mSpeed.y * timeStep);
//Check if it's on ground.
if(mPosition.y >= GROUND)
{
mPosition.y = GROUND;
mOnGround = true;
}
else
{
mOnGround = false;
}
//Update the center with the new position.
mAABB.center.x = mPosition.x + mAABBOffset.center.x;
mAABB.center.y = mPosition.y + mAABBOffset.center.y;
}