#include
#include
#include
#include
#include
#include
struct BALL
{
int x;
int y;
int speed;
int number;
int style;
};
char pr[1],scorepointer[3],ch;
float d;
int add=10,score=0;
BALL Ball[10];
struct Smile
{
int x,y;
}smile;
void Welcome();
void Ballstart();
void main( )
{
smile.x=320;
smile.y=240;
initgraph(640,480);
settextcolor(RED);
srand((unsigned)time(NULL));
Welcome();
Ballstart();
closegraph();
}
void Ballstart()
{
for(int i=0;i<10;i++)
{
Ball[i].x=-(rand()%400);
Ball[i].y=7+rand()%380;
Ball[i].speed=rand()%2;
Ball[i].number=rand()%10+1;
}
DWORD p=GetImageBuffer();
BeginBatchDraw();
setfillstyle(0);
settextcolor(YELLOW);
while(TRUE)
{
if(!kbhit())
{
ch=getch();
if(ch=='w')smile.y-=add;
if(ch=='s')smile.y+=add;
if(ch=='a')smile.x-=add;
if(ch=='d')smile.x+=add;
}
fillcircle(smile.x,smile.y,50);
for(int i=0;i<10;i++)
{
d=sqrt((Ball[i].x-smile.x)(Ball[i].x-smile.x)+(Ball[i].y-smile.y)*(Ball[i].y-smile.y));
if(d<=55)
{
score+=Ball[i].number;
itoa(score,scorepointer,10);
outtextxy(245,405,scorepointer);
Ball[i].x=-(rand()%400);
Ball[i].y=7+rand()%380;
Ball[i].speed=rand()%5;
Ball[i].number=rand()%10+1;
}
}
for(i=0;i
{
itoa(Ball[i].number,pr,10);
outtextxy(Ball[i].x,Ball[i].y,pr);
circle(Ball[i].x,Ball[i].y,5);
fillcircle(Ball[i].x,Ball[i].y,5);
}
for(i=640*2;i
{
p[i] = RGB(
(GetRValue(p[i]) + GetRValue(p[i - 640]) + GetRValue(p[i - 1]) + GetRValue(p[i + 1]) + GetRValue(p[i + 640])+GetRValue(p[i+640*2])+GetRValue(p[i-640*2]))/7.7,
(GetGValue(p[i]) + GetGValue(p[i - 640]) + GetGValue(p[i - 1]) + GetGValue(p[i + 1]) + GetGValue(p[i + 640])+GetGValue(p[i+640*2])+GetGValue(p[i-640*2]))/7.7 ,
(GetBValue(p[i]) + GetBValue(p[i - 640]) + GetBValue(p[i - 1]) + GetBValue(p[i + 1]) + GetBValue(p[i + 640])+GetBValue(p[i+640*2])+GetBValue(p[i-640*2]))/7.7);
}
FlushBatchDraw();
for(i=0;i
for(i=0;i
if((Ball[i].x>=633))
{
Ball[i].x=-(rand()%400);
Ball[i].y=7+rand()%380;
Ball[i].speed=rand()%5;
Ball[i].number=rand()%10+1;
}
}
EndBatchDraw();
}
void Welcome()
{
line(140,300,500,300);
line(140,350,500,350);
line(140,300,140,350);
line(500,300,500,350);
outtextxy(450,430,"made by: 123");
for(int i=141;i<=500;i++)
{
line(i,300,i,350);
Sleep(1);
}
outtextxy(200,380,"press any key to continue");
getch();
cleardevice();
line(5,5,635,5);
line(5,5,5,475);
line(5,475,635,475);
line(635,5,635,475);
line(5,400,635,400);
outtextxy(10,405,"Íæ¼Ò£º");
outtextxy(200,405,"×Ü·Ö£º");
outtextxy(350,405,"ÓÃʱ£º");
outtextxy(490,405,"Ê£Óàʱ¼ä£º");
rectangle(20,435,80,465);
outtextxy(38,442,"¿ªÊ¼");
rectangle(130,435,190,465);
outtextxy(148,442,"½áÊø");
rectangle(240,435,330,465);
outtextxy(258,442,"´æ»ý·Ö°ñ");
rectangle(380,435,510,465);
outtextxy(398,442,"ÏÔʾ´æ»ý·Ö°ñ");
rectangle(560,435,620,465);
outtextxy(570,442,"Í˳ö");
}
代码运行之后为什么键盘只能控制一段时间(几次),然后中央的白球就停在那里了,但是左侧的球依旧照常飞出,请问这是为什么?应该怎么改改比较好呢?
我用的是VC6 安装的EASYX