#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm,i,j,size
void *buffer
initgraph(&gd,&gm,"")
registerbgidriver(EGAVGA_driver)
setcolor(BROWN)
circle(100,100,5)
circle(80,100,5)
setfillstyle(1,RED)
bar(72,88,107,95)
setfillstyle(1,GREEN)
bar(80,80,100,88)
size=imagesize(71,79,108,106)
buffer=malloc(size)
getimage(71,79,108,106,buffer)
cleardevice()
putimage(1,1,buffer,COPY_PUT)
do
{
for(j=0j<=450j+=90) /*改变90,可以改变下降的大小*/
{
cleardevice()
for(i=0i<=640i++)
putimage(i+1,j+1,buffer,COPY_PUT)
cleardevice()
}
}while(!kbhit())/*按任意键退出,不过要等全部走完一遍才会退出*/
closegraph()
}
第二种方法(用背景色覆盖):
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i
registerbgidriver(EGAVGA_driver)
initgraph(&gd,&gm,"")
setfillstyle(1,GREEN)
bar(50,230,60,240)
while(!kbhit())
{
for(i=0i<30i++)
{
delay(10000)
bar(50+(i+1)*10,230,60+(i+1)*10,240)
setfillstyle(1,0)
bar(50+i*10,230,60+i*10,240)
setfillstyle(1,GREEN)
}
cleardevice()
}
closegraph()
}
control(){
p->x= rand()%60
p->y= rand()%20
gotoxy(p->x,p->y)
printf("%c",2)
Sleep(500)
system("cls")
gotoxy(p->x,p->y)
return control()
}
//你对照一下吧,你的想,y没有初始化#include<stdio.h>
#include<windows.h>
#include<stdlib.h>
#include<conio.h>
void gotoxy(short x, short y)
{
COORD c={x,y}
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c)
}
struct node
{
int x,y
struct node *next
}
struct node *p
control()
{
int key
key=getch()
switch(key)
{
case 'a':(p->x)--
break
case 'd':(p->x)++
break
case 's':(p->y)++
break
case 'w':(p->y)--
}
//gotoxy(p->x,p->y)
printf("%c",2)
//Sleep(100)
//system("cls")
gotoxy(p->x,p->y)
return control()
}
void main()
{
p=(struct node*)malloc(sizeof(struct node))
p->x=p->y=0
control()
}