I'm making a program, that moves a dot, from the startx, starty to endx, endy.
(我正在编写一个程序,该程序将一个点从startx,starty移到endx,endy。)
But it moves continuously, even after the x and the y are bigger than endx and endy. (但是,即使x和y大于endx和endy,它也会连续移动。)
Here is the code: (这是代码:)
int x, y;
x = startx; y = starty;
if(startx<goalx){
if (starty < goaly) {
while (startx < goalx || starty < goaly) {
x += sqrt(2)*speedx;
y += sqrt(2)*speedy;
}
}
else {
while (startx < goalx || starty > goaly) {
x += sqrt(2)*speedx;
y -= sqrt(2)*speedy;
}
}
}
else {
if (starty < goaly) {
while (startx > goalx || starty < goaly) {
x -= sqrt(2)*speedx;
y += sqrt(2)*speedy;
}
}
else {
while (startx > goalx || starty > goaly) {
x -= sqrt(2)*speedx;
y -= sqrt(2)*speedy;
}
}
}
cout << x << ", " << y << endl;
startx, starty, goalx and goaly are user inputs.
(startx,starty,goalx和Goaly是用户输入。)
ask by Gerg? Szabó translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…