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

📄 radar.c

📁 C语言编写的10几个游戏
💻 C
字号:
#include<io.h>
#include<stdio.h>
#include<dos.h>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<bios.h>
#include<mem.h>
#include<fcntl.h>
#include<stdlib.h>
#include<conio.h>

#define VGA256 0x13
#define TEXT_MODE 0x03
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 200
#define PALETTE_MASK 0x3c6
#define PALETTE_REGISTER_RD 0x3c7
#define PALETTE_REGISTER_WR 0x3c8
#define PALETTE_DATA 0x3c9

typedef struct RGB_color_typ
{
    unsigned char red;
    unsigned char green;
    unsigned char blue;
}RGB_color,*RGB_color_ptr;

unsigned char far *video_buffer=(char far *)0xA0000000L;
float sin_look[361];
float cos_look[361];

void Delay(int clicks)
{
unsigned int far *clock=(unsigned int far *)0x0000046CL;
unsigned int now;
now=*clock;
while(abs(*clock-now)<clicks){}
}

void Create_Tables(void)
{
int index;
for(index=0;index<=360;index++)
{
cos_look[index]=(float)cos((double)(index*3.14159/180));
sin_look[index]=(float)sin((double)(index*3.14159/180));
}
}

void Set_Palette_Register(int index,RGB_color_ptr color)
{
    outp(PALETTE_MASK,0xff);
    outp(PALETTE_REGISTER_WR,index);
    outp(PALETTE_DATA,color->red);
    outp(PALETTE_DATA,color->green);
    outp(PALETTE_DATA,color->blue);
}
void Get_Palette_Register(int index,RGB_color_ptr color)
{
    outp(PALETTE_MASK,0xff);
    outp(PALETTE_REGISTER_RD,index);
    color->red=inp(PALETTE_DATA);
    color->green=inp(PALETTE_DATA);
    color->blue=inp(PALETTE_DATA);

}

void Set_Video_Mode(int mode)
{
    union REGS inregs,outregs;
    inregs.h.ah=0;
    inregs.h.al=(unsigned char)mode;
    int86(0x10,&inregs,&outregs);
}

void Plot_Pixel_Fast(int x,int y,char color)
{
video_buffer[((y<<8)+(y<<6))+x]=color;
}

void BPlot_Pixel_Fast(int x,int y,char color)
{
video_buffer[((y<<8)+(y<<6))+x]=color;
video_buffer[((y<<8)+(y<<6))+x-1]=color;
video_buffer[((y<<8)+(y<<6))+x-320]=color;
video_buffer[((y<<8)+(y<<6))+x-321]=color;
}

void Bline(int x0,int y0,int x1,int y1,unsigned char color)
{
int dx,dy,x_inc,y_inc,error=0,index;
unsigned char far *vb_start=video_buffer;
vb_start=vb_start+((unsigned int )y0<<6)+((unsigned int)y0<<8)+(unsigned int)x0;
dx=x1-x0;
dy=y1-y0;
if(dx>=0)
{
x_inc=1;
}
else
{
x_inc=-1;
dx=-dx;
}
if(dy>=0)
{
y_inc=320;
}
else
{
y_inc=-320;
dy=-dy;
}
if(dx>dy)
{
for(index=0;index<=dx;index++)
{
*vb_start=color;
error+=dy;
if(error>dx)
{
error-=dx;
vb_start+=y_inc;
}
vb_start+=x_inc;
}
}
else
{
for(index=0;index<=dy;index++)
{
*vb_start=color;
error+=dx;
if(error>0)
{
error-=dy;
vb_start+=x_inc;
}
vb_start+=y_inc;
}
}
}

void H_Line(int x1,int x2,int y,unsigned int color)
{
    memset( (char far *) (video_buffer + ( (y<<8) + (y<<6) ) + x1) , color , x2-x1+1 );
}

void V_Line(int y1,int y2,int x,unsigned int color)
{
    int i;
    for(i=y1;i<y2;i++)
        video_buffer[ (i<<8) + (i<<6) + x]=color;
}

void Circle(int x,int y,int r,int color)
{
    int x0,y0,x1,y1,index;
    x0=y0=r/sqrt(2);
    for(index=0;index<=360;index++)
    {
        x1=x0*cos_look[index]-y0*sin_look[index];
        y1=x0*sin_look[index]+y0*cos_look[index];
        Plot_Pixel_Fast(x+x1,y+y1,color);
    }

}
void BCircle(int x,int y,int r,int color)
{
    int x0,y0,x1,y1,index;
    x0=y0=r/sqrt(2);
    for(index=0;index<=360;index++)
    {
        x1=x0*cos_look[index]-y0*sin_look[index];
        y1=x0*sin_look[index]+y0*cos_look[index];
        Plot_Pixel_Fast(x+x1,y+y1,color);
        Plot_Pixel_Fast(x+x1-1,y+y1,color);
        Plot_Pixel_Fast(x+x1,y+y1-1,color);
        Plot_Pixel_Fast(x+x1+1,y+y1,color);
        Plot_Pixel_Fast(x+x1,y+y1+1,color);
        Plot_Pixel_Fast(x+x1-1,y+y1-1,color);
        Plot_Pixel_Fast(x+x1+1,y+y1-1,color);
        Plot_Pixel_Fast(x+x1+1,y+y1+1,color);
        Plot_Pixel_Fast(x+x1-1,y+y1+1,color);
    }

}

void Fill_Circle(int x,int y,int r,int color)
{
    int index;
    for(index=r;index>0;index--)
    {
        BCircle(x,y,index,color);
    }
}

void main(void)
{
    int index,x0=160,y0=100,x1=50,y1=50,x2,y2,curr_color=1,i,flag=0,son=0;
    RGB_color color,color_1,color_2;
    Create_Tables();
    Set_Video_Mode(VGA256);
        color.red=0;
        color.green=0;
        color.blue=5;
        Set_Palette_Register(0,(RGB_color_ptr)&color);

    for(index=1;index<=255;index++)
    {
        color.red=0;
        color.green=10;
        color.blue=0;
        Set_Palette_Register(index,(RGB_color_ptr)&color);
    }
    color.red=0;
    color.green=30;
    color.blue=0;
    Set_Palette_Register(182,(RGB_color_ptr)&color);
    color.red=0;
    color.green=10;
    color.blue=0;
    Set_Palette_Register(183,(RGB_color_ptr)&color);
    for(index=184;index<=188;index++)
    {
        color.red=0;
        color.green=30+(index-184)*10;
        color.blue=0;
        Set_Palette_Register(index,(RGB_color_ptr)&color);
    }

        Fill_Circle(160,100,73,183);
    for(index=0;index<=360;index++)
    {
        x2=x1*cos_look[index]-y1*sin_look[index];
        y2=x1*sin_look[index]+y1*cos_look[index];
        Bline(x0,y0,x0+x2,y0+y2,index/2+1);
    }
    V_Line(22,178,160,182);
    H_Line(82,238,100,182);
    for(index=0;index<4;index++)
        BCircle(160,100,73+index,184+index);

    for(index=0;index<4;index++)
        BCircle(160,100,76+index,187-index);

    for(index=1;index<=158;index=index+5)
    {
        Plot_Pixel_Fast(81+index,99,182);
        Plot_Pixel_Fast(161,21+index,182);
    }
    for(index=0;index<10;index++)
    {
        BPlot_Pixel_Fast(143+index*8,140-index*2,190+index);
        Plot_Pixel_Fast(116-index*2,72+index*5,190+index);
        Plot_Pixel_Fast(122+index*2,145-index*3,190+index);
        BPlot_Pixel_Fast(190-index*8,150-index*2,190+index);
        Plot_Pixel_Fast(136+index*2,152-index*5,190+index);
        Plot_Pixel_Fast(172-index*2,145-index*3,190+index);

    }
        color_1.red=0;
        color_1.green=10;
        color_1.blue=0;
        color_2.red=255;
        color_2.green=0;
        color_2.blue=0;
        color.red=0;
        color.blue=0;

    while(!kbhit())
        for(index=1;index<=181;index++)
        {
            for(i=0;i<15;i++)
         {
                color.green=20+i*2;
                if(index+i>181)
                    Set_Palette_Register(index+i-181,(RGB_color_ptr)&color);
                else
                    Set_Palette_Register(index+i,(RGB_color_ptr)&color);
         }
            color.green=255;
            if(index+i>181)
                Set_Palette_Register(index+i-181,(RGB_color_ptr)&color);
            else
                Set_Palette_Register(index+i,(RGB_color_ptr)&color);

            Set_Palette_Register(index,(RGB_color_ptr)&color_1);

            if(index==181)
         {
            flag=0;
            if(flag==0)
         {
            flag=1;
            son=(son)%10+1;
            Set_Palette_Register(189+son-1,(RGB_color_ptr)&color_1);
            Set_Palette_Register(189+son,(RGB_color_ptr)&color_2);
         }
         }
            else if(flag==1)
         {
                if(son!=10)
                    flag=2;
                else
                    flag=0;
                Set_Palette_Register(189+son,(RGB_color_ptr)&color_1);
         }
            else if(flag==2)
         {
                flag=1;
                Set_Palette_Register(189+son,(RGB_color_ptr)&color_2);
         }
            delay(500);
        }
    getch();
    Set_Video_Mode(TEXT_MODE);
}

⌨️ 快捷键说明

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