0
我正在嘗試做一個簡單的彈跳球代碼,我的代碼下面並沒有反彈球,它只是使它在輸入按鈕被使用時移動,我能做些什麼來使球彈跳自我程序運行?如何使用graphics.h函數來實現使用c的彈跳球?
#include<alloc.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
void main()
{
int d=DETECT,m;
initgraph(&d,&m,"H:\\tc\\bgi");
int l=getmaxx()/2,t=0;
int x=1,y=1;
int xstep=1,ystep=1;
while(!kbhit())
{
cleardevice();
circle(l,t,18);
delay(5);
circle(l,t,18);
if(l>=getmaxx()||l<=0)
{
x*=-1;
xstep=x*(random(4)+1);
ystep=y*(random(3)+1);
if (l<=0)
t=0;
else
l=getmaxx();
}
if(t>=getmaxy()||t<=0)
{
y*=-1;
ystep=(y*random(4)+1);
xstep=(x*random(3)+1);
if(t<=0)
t=0;
else
t=getmaxy();
}
l+=x+xstep;
t+=y+ystep ;
getch();
}
closegraph();
}
您可以用刪除了'的getch()' – nabulke
這是真的採用Turbo-C爲DOS開始建造?留下深刻印象,如果這就是你正在學習的東西。 –
從物理引擎中解開DOS風格的I/O,並自行測試引擎。 – Beta