-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCBoxBounce.cpp
More file actions
executable file
·76 lines (62 loc) · 953 Bytes
/
CBoxBounce.cpp
File metadata and controls
executable file
·76 lines (62 loc) · 953 Bytes
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "CBoxBounce.h"
CBoxBounce::CBoxBounce(int x1, int y1, int x2, int y2) :CMotion()
{
mX1 = x1;
mY1 = y1;
mX2 = x2;
mY2 = y2;
mVelocity = 1;
mAbsX = mXVel = mVelocity;
mAbsY = mYVel = mVelocity;
mXv = 1;
}
void CBoxBounce::Welcome(int x, int y, int w, int h, int v)
{
mX = x;
mY = y;
mW = w;
mH = h;
mVelocity = v;
mXVel = mVelocity;
mYVel = mVelocity;
//mDir = mDir;
}
void CBoxBounce::Tick()
{
int x, y;
if (mState)
{
x = mX + mXVel;
if (x > mX2 - mW || x<0)
{
mXVel = mXVel * -1;
mXv = mXv * -1;
}
else
{
mX = x;
}
y = mY + mYVel;
if (y > mY2 - mH || y<0)
{
mYVel = mYVel * -1;
}
else
{
mY = y;
}
}
}
void CBoxBounce::SetPos(int x, int y)
{
CMotion::SetPos(x, y);
mX = x;
mY = y;
}
void CBoxBounce::SetVelocity(int v)
{
CMotion::SetVelocity(v);
mVelocity = v;
mXVel = mVelocity;
mYVel = mVelocity;
}