-
Notifications
You must be signed in to change notification settings - Fork 0
/
CParaMove.cpp
executable file
·88 lines (69 loc) · 1.18 KB
/
CParaMove.cpp
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
77
78
79
80
81
82
83
84
85
86
87
#include "CParaMove.h"
#include <stdio.h> /* printf */
#include <math.h>
CParaMove::CParaMove(int floor, int top, int start, bool offset, int n) : CMotion()
{
double delta, f, range;
int i;
int mid = n / 2;
mFloor = floor;
mNPoints = n;
mPoints = new int[n];
range = sqrt(floor - top + 1);
delta = range / mid;
f = -range;
for (i = 0; i< mid; i++)
{
mPoints[i] = top + (int)(f * f);
mPoints[n - 1 - i] = top + (int)(f * f);
f = f + delta;
}
mVelocity = 1;
mStart = start;
mIndex = start;
mOffset = offset;
}
void CParaMove::Reset()
{
mIndex = mStart;
}
void CParaMove::Init()
{
mIndex = mStart;
}
void CParaMove::SetPos(int x, int y)
{
CMotion::SetPos(x, y);
mStartY = y;
}
void CParaMove::Welcome(int x, int y, int w, int h, int v)
{
mX = x;
mY = y;
mStartY = y;
mW = w;
mH = h;
mVelocity = v;
}
void CParaMove::Tick()
{
int y;
if (mState)
{
y = mPoints[mIndex];
mIndex = mIndex + mVelocity;
if (mIndex >= mNPoints)
{
mIndex = 0;
mState = false;
if (mOffset == false)
y = mFloor;
}
if (mIndex + mVelocity >= mNPoints)
mIndex = mNPoints - mVelocity;
if (mOffset == true)
mY = mStartY + y;
else
mY = y;
}
}