这是一个界面动画的主题部分,头文件还有一些pi的预处理命令我都省了
希望给你参考一下,C语言的图形动画只能在TC下编写,运行
int a=DETECT,b; /切换到图形模式/
initgraph(&a,&b,"d:\\tc");
while(!kbhit())
{j+=10;
for(i=0;i<=2000;i++)
{
x=300+100cos(2ipi/1000)sin(ipi/1000+jpi/1000);
y=240+100cos(2ipi/1000)cos(ipi/1000+jpi/1000);
if(j%500==0) k++;
putpixel(x,y,k); /在指定位置画一像素/
}
delay(5000); /延时函数[毫秒数]/
cleardevice(); / 清除图形屏幕/
}
getch();
closegraph(); /切换到字符模式/
//贪吃蛇游戏,可以运行,我测试过
#include<stdioh>
#include<dosh>
#include<graphicsh>
#include<stdlibh>
#define UP 0x48
#define DOWN 0x50
#define LEFT 0x4b
#define RIGHT 0x4d
#define SPACE 0x39
#define ENTER 0x1c
#define ESC 0x1
#define SW 60
#define SL 20
#define Gsize 20
#define S 0
#define X 1
#define Z 2
#define Y 3
typedef struct SN{
int x;
int y;
int direction;
struct SN next;
}SNAKE;
SNAKE tail;
int rank=0;
int grilled[21][16]={0};
unsigned size,size1;
void buffer,buffer1;
void interrupt (oldtime)();
void interrupt newtime();
void install(void interrupt (haddr)());
int timer=0;
int getkey()
{
union REGS rg;
rghah=0;
int86(0x16,&rg,&rg);
return rghah;
}
SNAKE initmainwindow()
{
int i,j,k;
SNAKE p,w;
for(i=0;i<20;i++)
{
grilled[0]=1;
grilled[15]=1;
}
for(j=0;j<16;j++)
{
grilled[0][j]=1;
grilled[20][j]=1;
}
rectangle(SW+20,SL+20,SW+300,SL+400);
rectangle(SW+19,SL+19,SW+299,SL+399);
rectangle(SW+Gsize6,SL+Gsize6,SW+Gsize6+20,SL+Gsize6+20);
bar(SW+Gsize6+2,SL+Gsize6+2,SW+Gsize6+18,SL+Gsize6+18);
size=imagesize(SW+Gsize6,SL+Gsize6,SW+Gsize6+20,SL+Gsize6+20);
buffer=malloc(size);
getimage(SW+Gsize6,SL+Gsize6,SW+Gsize6+20,SL+Gsize6+20,buffer);
for(k=1;k<3;k++)
{
putimage(SW+Gsize6,SL+Gsize(6+k),buffer,XOR_PUT);
grilled[6+k][6]=1;
}
w=NULL;
for(k=2;k>=0;k--)
{
p=(SNAKE )malloc(sizeof(SNAKE));
p->x=6;p->y=6+k;
p->direction=S;
p->next=w;
w=p;
}
rectangle(SW+Gsize2,SL+Gsize4,SW+Gsize2+15,SL+Gsize4+15);
rectangle(SW+Gsize2+2,SL+Gsize4+2,SW+Gsize2+13,SL+Gsize4+13);
grilled[4][2]=2;
size1=imagesize(SW+Gsize2,SL+Gsize4,SW+Gsize2+15,SL+Gsize4+15);
buffer1=malloc(size1);
getimage(SW+Gsize2,SL+Gsize4,SW+Gsize2+15,SL+Gsize4+15,buffer1);
return w;
}
int main()
{
int driver=VGA,mode=VGAHI;
char key;
tail=NULL;
initgraph(&driver,&mode,"");
randomize();
tail=initmainwindow();
oldtime=getvect(0x1c);
while(1)
{
key=getkey();
switch(key)
{
case UP :
tail->direction=S;break;
case DOWN:
tail->direction=X;break;
case LEFT:
tail->direction=Z;break;
case RIGHT:
tail->direction=Y;break;
case ESC: closegraph();exit(1);
case SPACE :install(oldtime);break;
case ENTER :install(newtime);break;
}
}
}
void interrupt newtime()
{
int xx=1,yy=1;
char s[4];
SNAKE p,pend,pp;
p=(SNAKE )malloc(sizeof(SNAKE));
p->next=NULL;
if(timer++==3)
{
timer=0;
switch(tail->direction)
{
case S: if(grilled[tail->y-1][tail->x]==1) exit(1);
p->x=tail->x;p->y=tail->y-1;p->direction=tail->direction;p->next=NULL;
break;
case X: if(grilled[tail->y+1][tail->x]==1) exit(1);
p->x=tail->x;p->y=tail->y+1;p->direction=tail->direction;p->next=NULL;
break;
case Z: if(grilled[tail->y][tail->x-1]==1) exit(1);
p->x=tail->x-1;p->y=tail->y;p->direction=tail->direction;p->next=NULL;
break;
case Y: if(grilled[tail->y][tail->x+1]==1) exit(1);
p->x=tail->x+1;p->y=tail->y;p->direction=tail->direction;p->next=NULL;
break;
}
if(grilled[p->y][p->x]==2)
{
putimage(SW+Gsize(p->x),SL+Gsize(p->y),buffer1,XOR_PUT);
putimage(SW+Gsize(p->x),SL+Gsize(p->y),buffer,XOR_PUT);
grilled[p->y][p->x]=1;
p->next=tail;
tail=p;
rank++;
bar(375,390,400,420);
sprintf(s,"%d",rank);
setcolor(GREEN);
outtextxy(380,400,s);
do{
xx=random(14)+1;yy=random(19)+1;
}while((grilled[yy][xx]==1)||grilled[yy][xx]==2);
grilled[yy][xx]=2;
putimage(SW+Gsizexx,SL+Gsizeyy,buffer1,XOR_PUT);
}
else
{
putimage(SW+Gsize(p->x),SL+Gsize(p->y),buffer,XOR_PUT);
grilled[p->y][p->x]=1;
p->next=tail;
tail=p;
pend=tail;
while(pend->next) {pp=pend;pend=pend->next;}
putimage(SW+Gsize(pend->x),SL+Gsize(pend->y),buffer,XOR_PUT);
grilled[pend->y][pend->x]=0;
pp->next=NULL;
}
}
}
void install(void interrupt (hadder)())
{
disable();
setvect(0x1c,hadder);
enable();
}
#include <stdioh> void main()
{
int Password=0,Number=0,price=58,i=0; while( Password != 1234 )
{
if( i >= 3 )
return;
i++;
puts("Please input Password: ");
scanf("%d",&Password);
} i=0;
while( Number!=price )
{
do{
puts("Please input a number between 1 and 100: ");
scanf("%d",&Number);
printf("Your input number is %d\n",Number);
}while( !(Number>=1 && Number<=100) );
if( Number >= 90 )
{
printf("Too Bigger! Press any key to try again!\n");
}
else if( Number >= 70 && Number < 90 )
{
printf("Bigger!\n");
}
else if( Number >= 1 && Number <= 30 )
{
printf("Too Small! Press any key to try again!\n");
}
else if( Number > 30 && Number <= 50 )
{
printf("Small! Press any key to try again!\n");
}
else
{
if( Number == price )
{
printf("OK! You are right! Bye Bye!\n");
}
else if( Number < price )
{
printf("Sorry,Only a little smaller! Press any key to try again!\n"); }
else if( Number > price )
printf(" Sorry, Only a little bigger! Press any key to try again!\n");
}
getch();
}
}
学编程不能这样学的,就算解释清楚了每一步,要想看懂整个程序也是有很大困难的。还是一步步扎实的学吧。
再者,看程序应该是 tc20 的,先换一个好用点的编译器吧,比如 vc6,事半功倍。
以上就是关于用c语言编写一个欢迎界面动画,求教。全部的内容,包括:用c语言编写一个欢迎界面动画,求教。、用c语言编写一个简单的动画或休闲小游戏、c语言动画程序会挥动翅膀飞行的小鸟代码,Tc2.0下可运行!代码私信!等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)