⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tank.h

📁 C语言游戏编程
💻 H
📖 第 1 页 / 共 2 页
字号:

if(l==1)
{
if(kbhit()||all_key!=0)
{
k=1;
dx=dy=0;
if(all_key==0)
all_key=get_key=getch();
else
{
get_key=all_key;
all_key=0;
}
if(get_key==sprite->key.up)
{
sprite_direction=0;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.right)
{
sprite_direction=1;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.down)
{
sprite_direction=2;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.left)
{
sprite_direction=3;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}

if(get_key==sprite->key.quit)
{
Sprite_Delete(sprite);

Sheer();
Set_Video_Mode(TEXT_MODE);
exit(1);
}
if(get_key==sprite->key.fight)
{
if(sprite->bullet.flag!=1)
{
sprite->bullet.flag=1;
if(sprite_direction==0)
{
sprite->bullet.direction.y=-1;
sprite->bullet.direction.x=0;
sprite->bullet.x=sprite->x+7;
sprite->bullet.y=sprite->y-1;
}
else if(sprite_direction==1)
{
sprite->bullet.direction.x=1;
sprite->bullet.direction.y=0;
sprite->bullet.x=sprite->x+16;
sprite->bullet.y=sprite->y+7;
}
else if(sprite_direction==2)
{
sprite->bullet.direction.y=1;
sprite->bullet.direction.x=0;
sprite->bullet.x=sprite->x+8;
sprite->bullet.y=sprite->y+16;
}
else if(sprite_direction==3)
{
sprite->bullet.direction.x=-1;
sprite->bullet.direction.y=0;
sprite->bullet.x=sprite->x-1;
sprite->bullet.y=sprite->y+8;
}
sprite->bullet.color=15;
}
}

sprite->x+=(int)(dx+.5);
if(sprite->x>319-(int)SPRITE_WIDTH)
sprite->x=319-(int)SPRITE_WIDTH;
else if(sprite->x<0)
sprite->x=0;

sprite->y-=(int)(dy+.5);



if(sprite->y>199-(int)SPRITE_HEIGHT)
sprite->y=199-(int)SPRITE_HEIGHT;
else if(sprite->y<0)
sprite->y=0;
sprite->curr_frame=sprite_direction;
}

if(k==0)
if(get_key!=sprite->key.stop)
{
sprite->x+=(int)(dxx+.5);
if(sprite->x>319-(int)SPRITE_WIDTH)
sprite->x=319-(int)SPRITE_WIDTH;
else if(sprite->x<0)
sprite->x=0;

sprite->y-=(int)(dyy+.5);
if(sprite->y>199-(int)SPRITE_HEIGHT)
sprite->y=199-(int)SPRITE_HEIGHT;
else if(sprite->y<0)
sprite->y=0;
sprite->curr_frame=sprite_direction;

}
}

else
{
j=-j;
sprite->curr_frame=sprite_direction+2+j;
}

Behind_Sprite(sprite);

if(sprite->bullet.flag==1)
	sprite->bullet.color_gd=Get_Pixel(sprite->bullet.x,sprite->bullet.y);

Draw_Sprite(sprite);

if(sprite->bullet.flag==1)
Plot_Pixel_Fast(sprite->bullet.x,sprite->bullet.y,sprite->bullet.color);

Delay(2);

}

void tank2(sprite_ptr sprite)
{
static int sprite_direction=0;
static float dx,dy,dxx=0,dyy=0,angle;
static int i,j=2,k,l=1;
char get_key;
l=-l;
k=0;

Erase_Sprite(sprite);

if(sprite->bullet.flag==1)
{
Plot_Pixel_Fast(sprite->bullet.x,sprite->bullet.y,sprite->bullet.color_gd);
sprite->bullet.x+=sprite->bullet.direction.x*16;
sprite->bullet.y+=sprite->bullet.direction.y*16;
if(sprite->bullet.x>336||sprite->bullet.x<-16||sprite->bullet.y>184||sprite->bullet.y<-16)
{
sprite->bullet.flag=0;
sprite->bullet.x=sprite->bullet.y=400;
}
}


if(l==1)
{
if(kbhit()||all_key!=0)
{
k=1;
dx=dy=0;
if(all_key==0)
all_key=get_key=getch();
else
{
get_key=all_key;
all_key=0;
}
if(get_key==sprite->key.up)
{
sprite_direction=0;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.right)
{
sprite_direction=1;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.down)
{
sprite_direction=2;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}
if(get_key==sprite->key.left)
{
sprite_direction=3;
angle=(90+360-360/(MAX_SPRITE_FRAMES/2)*(float)sprite_direction);
dxx=dx=sprite_SPEED*cos(PI*angle/180);
dyy=dy=sprite_SPEED*sin(PI*angle/180);
}

if(get_key==sprite->key.quit)
{
Sprite_Delete(sprite);

Sheer();
Set_Video_Mode(TEXT_MODE);
exit(1);
}
if(get_key==sprite->key.fight)
{
if(sprite->bullet.flag!=1)
{
sprite->bullet.flag=1;
if(sprite_direction==0)
{
sprite->bullet.direction.y=-1;
sprite->bullet.direction.x=0;
sprite->bullet.x=sprite->x+7;
sprite->bullet.y=sprite->y-1;
}
else if(sprite_direction==1)
{
sprite->bullet.direction.x=1;
sprite->bullet.direction.y=0;
sprite->bullet.x=sprite->x+16;
sprite->bullet.y=sprite->y+7;
}
else if(sprite_direction==2)
{
sprite->bullet.direction.y=1;
sprite->bullet.direction.x=0;
sprite->bullet.x=sprite->x+8;
sprite->bullet.y=sprite->y+16;
}
else if(sprite_direction==3)
{
sprite->bullet.direction.x=-1;
sprite->bullet.direction.y=0;
sprite->bullet.x=sprite->x-1;
sprite->bullet.y=sprite->y+8;
}
sprite->bullet.color=15;
}
}

sprite->x+=(int)(dx+.5);
if(sprite->x>319-(int)SPRITE_WIDTH)
sprite->x=319-(int)SPRITE_WIDTH;
else if(sprite->x<0)
sprite->x=0;

sprite->y-=(int)(dy+.5);



if(sprite->y>199-(int)SPRITE_HEIGHT)
sprite->y=199-(int)SPRITE_HEIGHT;
else if(sprite->y<0)
sprite->y=0;
sprite->curr_frame=sprite_direction;
}

if(k==0)
if(get_key!=sprite->key.stop)
{
sprite->x+=(int)(dxx+.5);
if(sprite->x>319-(int)SPRITE_WIDTH)
sprite->x=319-(int)SPRITE_WIDTH;
else if(sprite->x<0)
sprite->x=0;

sprite->y-=(int)(dyy+.5);
if(sprite->y>199-(int)SPRITE_HEIGHT)
sprite->y=199-(int)SPRITE_HEIGHT;
else if(sprite->y<0)
sprite->y=0;
sprite->curr_frame=sprite_direction;

}
}

else
{
j=-j;
sprite->curr_frame=sprite_direction+2+j;
}

Behind_Sprite(sprite);

if(sprite->bullet.flag==1)
	sprite->bullet.color_gd=Get_Pixel(sprite->bullet.x,sprite->bullet.y);

Draw_Sprite(sprite);

if(sprite->bullet.flag==1)
Plot_Pixel_Fast(sprite->bullet.x,sprite->bullet.y,sprite->bullet.color);

Delay(2);

}
void Judge_Sprite(void)
{
sprite_ptr sprite;
sprite=head;
do{
	sprite->spr(sprite);
sprite=sprite->next;
}while(sprite!=NULL);
}

void Judge_Died(void)
{
sprite_ptr tank1,tank2;
tank1=head;
do{
	tank2=tank1->next;
	while(tank2!=NULL)
	{
		if(Sprite_Collide(tank1,tank2)||bullet_Collide(tank2,(bullet_ptr)&tank1->bullet)||bullet_Collide(tank1,(bullet_ptr)&tank2->bullet))
		{
			Sprite_Free();
			Sheer();
			Set_Video_Mode(TEXT_MODE);
			exit(1);
		}
		tank2=tank2->next;
	}
tank1=tank1->next;
}while(tank1!=NULL);
}

void Sprite_Build(void)
{
int index;
pcx_picture objects_pcx;
char key[2][7]={'8','2','4','6','5','q','0','w','x','a','d','s','q','z'};
PCX_Init((pcx_picture_ptr)&objects_pcx);
PCX_Load("attank2.pcx",(pcx_picture_ptr)&objects_pcx,1);

now=pre=(struct sprite *)malloc(sizeof(struct sprite_type));
head=now;
Sprite_Init(now,0,0,0,0,0,0,tank1,key[0]);
for(index=0;index<MAX_SPRITE_FRAMES;index++)
{
 PCX_Grab_Bitmap((pcx_picture_ptr)&objects_pcx,now,index,index,0);
}

now=(struct sprite *)malloc(sizeof(struct sprite_type));
pre->next=now;
pre=now;

Sprite_Init(now,0,100,0,0,0,0,tank2,key[1]);
for(index=0;index<MAX_SPRITE_FRAMES;index++)
{
 PCX_Grab_Bitmap((pcx_picture_ptr)&objects_pcx,now,index,index,1);
}
pre->next=NULL;

PCX_Delete((pcx_picture_ptr)&objects_pcx);

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -