萌新求助!!
已经生成的release版本exe文件,单独运行时图形移动很慢,但是打开vs2019后,运行马上正常。
只需要打开vs2019,哪怕不进行任何操作,移动速度都会马上恢复正常。关闭后,速度又会变慢。
#include <graphics.h>
#include <conio.h>
#include <math.h>
double GetDistance(double a, double b, double c, double d)
{
int m, n;
m = pow(fabs(a - c), 2.0);
n = pow(fabs(b - d), 2.0);
return sqrt(m+n);
}
int main(void)
{
double x, y, vx, vy, x1, y1, vx1, vy1;
x = 320.0;
y = 240.0;
vx = 1.0;
vy = 1.0;
x1 = 100.0;
y1 = 150.0;
vx1 = 1.0;
vy1 = 1.0;
initgraph(640, 480);
BeginBatchDraw();
while (1)
{
setcolor(BLUE);
setfillcolor(GREEN);
fillcircle(x, y, 20.0);
fillcircle(x1, y1, 20.0);
FlushBatchDraw();
Sleep(3);
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(x, y, 20.0);
fillcircle(x1, y1, 20.0);
x = x + vx;
y = y + vy;
x1 = x1 - vx1;
y1 = y1 - vy1;
if (x == 620.0 || x == 20.0)
{
vx = -1 * vx;
}
if (y == 460.0 || y == 20.0)
{
vy = -1 * vy;
}
if (x1 == 620.0 || x1 == 20.0)
{
vx1 = -1 * vx1;
}
if (y1 == 460.0 || y1 == 20.0)
{
vy1 = -1 * vy1;
}
if (GetDistance(x,y,x1,y1) <= 40.0)
{
vx = -1 * vx;
vy = -1 * vy;
vx1 = -1 * vx1;
vy1 = -1 * vy1;
}
}
EndBatchDraw();
closegraph();
return 0;
}