|
1楼 http://post.baidu.com/f?kz=4276396 扫雷游戏 http://post.baidu.com/f?kz=3651013 做游戏常用到的一些函数 http://post.baidu.com/f?kz=5416486 赛车游戏的完整图 http://post.baidu.com/f?kz=5417016 简单打飞碟小游戏 http://post.baidu.com/f?kz=3650980 坦克大战小游戏 http://post.baidu.com/f?kz=3650938 吃豆小游戏 http://post.baidu.com/f?kz=3651039 |
|
|
|
|
2楼 http://post.baidu.com/f?kz=5416399 |
|
|
|
|
4楼 在这里我用圆实现运动 方块实现静止 代码如下: #include <graphics.h> #include <stdlib.h> #include <stdio.h> #include <conio.h> int main(void) { int gdriver = DETECT, gmode; void *ball; int x, y,maxx; unsigned int size; initgraph(&gdriver, &gmode, ""); maxx = getmaxx(); x = 0; y = 200; rectangle(x,y+11,x+20,y+31); circle(x+10,y,10); size = imagesize(x, y-10, x+20, y+10); ball = malloc(size); setfillstyle(SOLID_FILL, BLACK); while (!kbhit()) { cleardevice(); x += 10; if (x >= maxx) x = 0; rectangle(0,211,20,231); circle(x+10,y,10); delay(100); } free(ball); closegraph(); return 0; } |
|
|
|
|
5楼 我上面给大家可以说是从第一步:制作简单的场景和玩家的赛车 到第二步:进一步完善场景, 大家可能已经有所领会 下面我们就把它做成一个简单的游戏 代码如下: #include <math.h> #include <conio.h> #include <stdio.h> #include <stdlib.h> #include <graphics.h> static int c=1; static int e=0; static int u=0; static int v=0; static int x=1; static int y=0; static int j=-21; static int i; static int b; void begin(void) { int xmax, ymax; int startx,starty,endx,endy; setbkcolor(WHITE); xmax = getmaxx(); ymax = getmaxy(); endx=20;endy=20; startx=10;starty=10; setcolor(RED); settextstyle(1,HORIZ_DIR,4); outtextxy(10,240,"Bus Bus Bus"); outtextxy(300,300,"Made by PU BIN."); setlinestyle(SOLID_LINE,0,3); setwritemode(XOR_PUT); setcolor(GREEN); while(startx<xmax&&starty<ymax) { rectangle(startx,starty,endx,endy); delay(4); rectangle(startx,starty,endx,endy); startx+=2; starty+=startx*startx/2000; endx=startx+10; endy=starty+10; sound(startx*10); delay(10); nosound(); } getch(); cleardevice(); } void road(void) { int h; for(h=0;h<4;h++) line(150+h*100,0,150+h*100,472); for(h=0;h<3;h++) { setlinestyle(3,0,1); line(200+h*100,0,200+h*100,472); settextstyle(1,HORIZ_DIR,3); } settextstyle(1,HORIZ_DIR,4); setcolor(RED); outtextxy(40,40,"PASS"); outtextxy(40,80,"1"); setcolor(10); setlinestyle(SOLID_LINE,0,3); rectangle(150,400,450,460); outtextxy(160,410,"Ready,Begin!"); } void math(void) { settextstyle(1,HORIZ_DIR,4); setcolor(RED); if(x==2) { outtextxy(40,80,"1"); outtextxy(40,80,"2"); } else if(x==3) { outtextxy(40,80,"2"); outtextxy(40,80,"3"); } else if(x==4) { outtextxy(40,80,"3"); outtextxy(40,80,"4"); }else if(x==5){ outtextxy(40,80,"4"); outtextxy(40,80,"5"); }else if(x==6){ outtextxy(40,80,"5"); outtextxy(40,80,"6"); }else if(x==7){ outtextxy(40,80,"6"); outtextxy(40,80,"7"); }else if(x==8){ outtextxy(40,80,"7"); outtextxy(40,80,"8"); }else if(x==9){ outtextxy(40,80,"8"); outtextxy(40,80,"9"); }else if(x==10){ outtextxy(40,80,"9"); outtextxy(40,80,"10"); }else if(x==11){ outtextxy(40,80,"10"); outtextxy(40,80,"11"); }else if(x==12){ outtextxy(40,80,"11"); outtextxy(40,80,"12"); }else if(x==13){ outtextxy(40,80,"12"); outtextxy(40,80,"13"); }else if(x==14){ outtextxy(40,80,"13"); outtextxy(40,80,"14"); }else if(x==15){ outtextxy(40,80,"14"); outtextxy(40,80,"15"); }else if(x==16){ outtextxy(40,80,"15"); outtextxy(40,80,"16"); }else if(x==17){ outtextxy(40,80,"16"); outtextxy(40,80,"17"); }else if(x==18){ outtextxy(40,80,"17"); outtextxy(40,80,"18"); }else if(x==19){ outtextxy(40,80,"18"); outtextxy(40,80,"19"); }else if(x==20){ outtextxy(40,80,"19"); outtextxy(40,80,"20"); }else if(x==21){ outtextxy(40,80,"20"); outtextxy(40,80,"21"); }else if(x==22){ outtextxy(40,80,"21"); outtextxy(40,80,"22"); }else if(x==23){ outtextxy(40,80,"22"); |
|
|
|
|
6楼 }else if(x==24){ outtextxy(40,80,"23"); outtextxy(40,80,"24"); }else if(x==25){ outtextxy(40,80,"24"); outtextxy(40,80,"25"); y=1; v=1; } } void bus2(void) { setcolor(BLUE); rectangle(180+c*100,350,220+c*100,390); rectangle(170+c*100,340,230+c*100,350); rectangle(190+c*100,320,210+c*100,340); rectangle(170+c*100,390,230+c*100,400); setcolor(5); line(190+c*100,350,190+c*100,390); line(200+c*100,350,200+c*100,390); line(210+c*100,350,210+c*100,390); line(200+c*100,300,200+c*100,320); line(185+c*100,300,215+c*100,300); if((b==0x4b00)&&(c>0)) c--; else if((b==0x4d00)&&(c<2)) c++; else if((b==0x5000)&&(c<2)) sleep(1); setcolor(BLUE); rectangle(180+c*100,350,220+c*100,390); rectangle(170+c*100,340,230+c*100,350); rectangle(190+c*100,320,210+c*100,340); rectangle(170+c*100,390,230+c*100,400); setcolor(5); line(190+c*100,350,190+c*100,390); line(200+c*100,350,200+c*100,390); line(210+c*100,350,210+c*100,390); line(200+c*100,300,200+c*100,320); line(185+c*100,300,215+c*100,300); setcolor(BLUE); } void light(void) { rectangle(535,65,565,155); floodfill(545,100,BLUE); setfillstyle(1,RED); fillellipse(550,80,10,10); sound(650); delay(300); nosound(); delay(100); setfillstyle(1,YELLOW); fillellipse(550,110,10,10); sound(650); delay(300); nosound(); delay(100); setfillstyle(1,GREEN); fillellipse(550,140,10,10); sound(650); delay(300); nosound(); delay(100); setcolor(10); setlinestyle(SOLID_LINE,0,3); rectangle(150,400,450,460); outtextxy(160,410,"Ready,Begin!"); } void brock(void) { if((c==i)&&(j>4)&&(j<38)) e=1; } void tree(void) { int w; int poly[14]; setcolor(10); for (w=-3;w<3;w=w+2) { line(85,-25+u*15+w*157,85,35+u*15+w*157); line(95,-25+u*15+w*157,95,35+u*15+w*157); line(105,-25+u*15+w*157,105,35+u*15+w*157); line(115,-25+u*15+w*157,115,35+u*15+w*157); line(75,-9+u*15+w*157,75,19+u*15+w*157); line(125,-9+u*15+w*157,125,19+u*15+w*157); } for (w=-2;w<3;w=w+2) { poly[0] = 530; poly[1] = u*15+w*157; poly[2] =515; poly[3] = 25+u*15+w*157; poly[4] =485; poly[5] =25+u*15+w*157 ; poly[6] =470; poly[7] =u*15+w*157 ; poly[8] =485; poly[9] =-25+u*15+w*157; poly[10] =515; poly[11] =-25+u*15+w*157 ; poly[12] = poly[0]; poly[13] = poly[1]; drawpoly(7,poly); } } void bus1(void) { randomize(); i=random(3); setlinestyle(SOLID_LINE,0,3); do { do { if((x!=7)&&(x!=16)&&(x!=23)) setcolor(x); else setcolor(2); rectangle(170+i*100,j*10,230+i*100,60+j*10); rectangle(160+i*100,70+j*10,240+i*100,260+j*10); line(180+i*100,70+j*10,180+i*100,260+j*10); line(200+i*100,70+j*10,200+i*100,260+j*10); line(220+i*100,70+j*10,220+i*100,260+j*10); tree(); sound(j*10); delay(10); nosound(); if((x!=7)&&(x!=16)&&(x!=23)) setcolor(x); else setcolor(2); rectangle(170+i*100,j*10,230+i*100,60+j*10); rectangle(160+i*100,70+j*10,240+i*100,260+j*10); line(180+i*100,70+j*10,180+i*100,260+j*10); line(200+i*100,70+j*10,200+i*100,260+j*10); line(220+i*100,70+j*10,220+i*100,260+j*10); tree(); u++; j++; brock(); if(e==1) { j=48; y=1; u=63; v=0; } }while((bioskey(1)==0)&&(j<=47)&&(u<=62)); if((j<=47)&&(u<=62)) /* function 0 returns the key that is waiting */ { b= bioskey(0); bus2(); } else if(u<=62) { j=-21; randomize(); i=rand()%3; x++; math(); setcolor(x); } else u=0; }while(y!=1); } void end() { if (v==1) { for(j=0;j<94;j++) { rectangle(150,j*5,450,60+j*5); settextstyle(1,HORIZ_DIR,4); outtextxy(160,10+j*5,"STOP! You win!"); sound(500+j*10); delay(2); nosound(); setlinestyle(SOLID_LINE,0,3); rectangle(150,j*5,450,60+j*5); outtextxy(160,10+j*5,"STOP! You win!"); } closegraph(); printf("\n\nyou win!"); } else if(v==0 ) { closegraph(); printf("\n\nYou lose."); } printf("\n\n\nCome back again.\n\n Made by YOU LIAO working house. pubingk@citiz.net"); getch(); getch(); } void car() { setcolor(BLUE); setlinestyle(SOLID_LINE,0,3); rectangle(280,350,320,390); rectangle(270,340,330,350); rectangle(290,320,310,340); rectangle(270,390,330,400); setcolor(5); line(290,350,290,390); line(300,300,300,320); line(300,350,300,390); line(310,350,310,390); line(285,300,315,300); setcolor(BLUE); } void main(void) { int gdriver = DETECT , gmode; initgraph(&gdriver, &gmode, ""); begin(); setbkcolor(7); setcolor(WHITE); setwritemode(XOR_PUT); road(); car(); light(); bus1(); end(); } |
|
|
|
| 202.116.27.* |
7楼 |
|
|
| 222.76.27.* |
8楼 |
|
|
| 202.114.25.* |
9楼 |
|
|
|
10楼 音效在游戏里是非常重要的 这里介绍用pc喇叭产生的最简单的声音,以后在给大家介绍如何驱动声卡使音箱发声 c语言函数库提供了两个声音函数 sound(),nosound()和延迟函数delay() sound()函数中频率参数的单位是(Hz),根据测试,调用参数18Hz以上的sound() 函数可以被人耳识别,以下是一个利用循环改变声音频率的例子,发出来的生音频率从低到高 代码如下: #include <dos.h> void main(void) { int i; for(i=0;i<=1000;i++) { sound(i); delay(1000); nosound(); } } 在游戏中sound()函数通常在某一游戏动画图像画好后处于延迟的时候使用 这里使用delay()延迟函数一举两得,即使游戏动画图像进行了一定时间的停留 ,又使声音进行了一定时间的播放 需要提醒大家的是: 不同的机器在使用delay()延迟函数时延迟时间不同,这是因为受cpu速度的影响 最终我们将不使用delay()函数作为延迟函数。 |
|
|
|
| 221.232.72.* |
11楼 |
|
|
| 218.7.17.* |
12楼
|
|
|
| 210.76.56.* |
13楼 |
|
|
| 220.178.33.* |
14楼 |
|
|
|
15楼 #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]; |
|
|
|
|
16楼 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(10); } getch(); Set_Video_Mode(TEXT_MODE); } |
|
|
|
|
18楼 #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> #include<process.h> #define WINDOWS 0 #define BUTTON 1 #define BUTTON_PRESS 2 #define BUTTON_SMALL 3 #define BUTTON_SMALL_PRESS 4 #define BUTTON_CLOSE 5 #define BUTTON_CLOSE_PRESS 6 #define BUTTON_MENU 7 #define BUTTON_COLOR 24 #define BUTTON_COLOR_LIGHT 7 #define BUTTON_COLOR_DARK 8 #define BUTTON_X 35 #define BUTTON_Y 10 #define BUTTON_XY 8 #define WINDOWS_X 50 #define WINDOWS_Y 50 #define WINDOWS_X_MOVE 240 #define WINDOWS_Y_MOVE 150 #define WINDOWS_COLOR_OUT 24 #define WINDOWS_COLOR_IN 15 #define WINDOWS_COLOR_LIGHT 7 #define WINDOWS_COLOR_DARK 8 #define WINDOWS_COLOR_TITLE 12 #define MAX 0 #define MIN 1 #define ACTIVE 1 #define NOACTIVE 0 #define ACTIVE_COLOR 1 #define NOACTIVE_COLOR 8 #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 #define CHAR_HEIGHT 8 #define CHAR_WIDTH 8 #define MOUSE_INT 0x33 #define MOUSE_RESET 0x00 #define MOUSE_SHOW 0x01 #define MOUSE_HIDE 0x02 #define MOUSE_BUTT_POS 0x03 #define MOUSE_SET_SENSITIVITY 0x1A #define MOUSE_MOTION_REL 0x0B #define MOUSE_LEFT_BUTTON 0x01 #define MOUSE_RIGHT_BUTTON 0x02 #define MOUSE_CENTER_BUTTON 0x04 typedef struct{ int mak[2][16]; int hor; int ver; }mscurstype; mscurstype handcurs={-7681,-7681,-7681,-7681,-7681,-8192,-8192,-8192, 0, 0, 0, 0, 0, 0, 0, 0, 7680,4608,4608,4608,4608,5119,4681,4681,4681, -28671,-28671,-28671,-22767,-32767,-32767,-1,4,0}; mscurstype arrow={0x3fff,0x1fff,0x0fff,0x07ff, 0x03ff,0x01ff,0x00ff,0x007f, 0x003f,0x00ff,0x01ff,0x10ff, 0x30ff,0xf87f,0xf87f,0xfc3f, 0x0000,0x4000,0x6000,0x7000, 0x7800,0x7c00,0x7e00,0x7f00, 0x7f80,0x7e00,0x7c00,0x4600, 0x0600,0x0300,0x0300,0x0180,0,0}; mscurstype lin={0xe3e3,0xe3e3,0xe3e3,0xe3e3, 0x8080, 0x8080,0x8080,0xe3e3, 0xc1c1, 0x8080,0x0000,0x2323, 0xe3e3,0xe3e3,0xe3e3, 0xe3e3, 0x0000,0x0808,0x0808,0x0808, 0x0808,0x3e3e,0x0808,0x0808, 0x1c1c,0x2a2a,0x4848,0x0808, 0x0808,0x0808,0x0808,0x0000,2,0}; mscurstype qi={0xff89,0xff88,0xff8e,0x8001, 0x8001,0x8001,0x8d8f,0x8c8c, 0x8d8c,0x8d88,0x8009,0x8983, 0x9542,0x1540,0x39b0,0x7d79, 0x0000,0x0020,0x0020,0x0020, 0x3ffc,0x2020,0x2020,0x2020, 0x2020,0x2020,0x2020,0x2020, 0x0000,0x4008,0x0004,0x0000,16,0}; mscurstype arrowcurs={16383,8191,4095,2047,1023,511,225,127,63, 31,511,4351,12543,-1921,-1921,-961,0,16348, 24576,28672,30720,31744,32256,32512,32640, 32704,31744,17920,17920,768,384,192,-1,-1}; int Squeeze_Mouse(int command,int *x,int *y,int *buttons) { union REGS inregs,outregs; switch(command) { case MOUSE_RESET: { inregs.x.ax=0x00; int86(MOUSE_INT,&inregs,&outregs); *buttons=outregs.x.bx; return(outregs.x.ax); |
|
|
|
|
19楼 case MOUSE_SHOW: { inregs.x.ax=0x01; int86(MOUSE_INT,&inregs,&outregs); return(1); }break; case MOUSE_HIDE: { inregs.x.ax=0x02; int86(MOUSE_INT,&inregs,&outregs); return(1); }break; case MOUSE_BUTT_POS: { inregs.x.ax=0x03; int86(MOUSE_INT,&inregs,&outregs); *x=outregs.x.cx; *y=outregs.x.dx; *buttons=outregs.x.bx; return(1); }break; case MOUSE_MOTION_REL: { inregs.x.ax=0x03; int86(MOUSE_INT,&inregs,&outregs); *x=outregs.x.cx; *y=outregs.x.dx; return(1); }break; case MOUSE_SET_SENSITIVITY: { inregs.x.ax=0x04; inregs.x.bx=*buttons; inregs.x.cx=*x; inregs.x.dx=*y; int86(MOUSE_INT,&inregs,&outregs); return(1); }break; default:break; } } void setcurshape(mscurstype mask) { union REGS r; struct SREGS s; r.x.ax=9; r.x.bx=mask.hor; r.x.cx=mask.ver; r.x.dx=FP_OFF(&mask); s.es=FP_SEG(&mask); int86x(0x33,&r,&r,&s); } void mscurson(mscurstype shape) { int msvisible; union REGS r; struct SREGS s; setcurshape(shape); r.x.ax=1; msvisible=1; int86x(0x33,&r,&r,&s); } typedef struct point { int x; int y; }point; typedef struct windows { int kind; point top; point move; char *word; int color; int bk_color; int status; // char *ico; // void (far *build)(); char *hotkey; void (far *windows)(struct windows *win); char far *background; int bk_flag; struct windows *next; struct windows *father; int active; } windows, *windows_ptr; windows_ptr head; windows_ptr now; windows_ptr pre; windows_ptr win_now; windows_ptr last; 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; unsigned char far *rom_char_set=(char far *)0xF000FA6EL; float sin_look[361]; float cos_look[361]; void men(windows_ptr win); 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; |
|
|
|
|
20楼 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 Rectangle(int x1,int y1,int x2,int y2,int color) { H_Line(x1,x2,y1,color); H_Line(x1,x2,y2,color); V_Line(y1,y2,x1,color); V_Line(y1,y2,x2,color); } void Fill_Rectangle(int x1,int y1,int x2,int y2,int color) { int i; for(i=y1;i<=y2;i++) { H_Line(x1,x2,i,color); } } void Circle(int x,int y,int r,int color) { int x0,y0,x1,y1,index; x0=y0=r; 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; 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,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_Screen(int value) { _fmemset(video_buffer,(char)value,SCREEN_WIDTH*SCREEN_HEIGHT+1); } void Fill_Screen_Size(int value,int x0,int y0,int x1,int y1) { int x,y; long i=0,height,width; height=y1-y0+1; width=x1-x0+1; x=x0; while(i<height*width) { y=y0+i/width; i=i+width; _fmemset(video_buffer+x+y*SCREEN_WIDTH,(char)value,width); } } void Blit_Char(int xc,int yc,char c,int color,int trans_flag) { int offset,x,y; char far *work_char; unsigned char bit_mask=0x80; work_char=rom_char_set+c*CHAR_HEIGHT; offset=(yc<<8)+(yc<<6)+xc; for(y=0;y<CHAR_HEIGHT;y++) { bit_mask=0x80; for(x=0;x<CHAR_WIDTH;x++) { if((*work_char&bit_mask)) video_buffer[offset+x]=color; else if(!trans_flag) video_buffer[offset+x]=0; bit_mask=(bit_mask>>1); } offset+=SCREEN_WIDTH; work_char++; } } void Blit_String(int x,int y,int color,char *string,int trans_flag) |
|
|
|
|
21楼 int index; for(index=0;string[index]!=0;index++) { Blit_Char(x+(index<<3),y,string[index],color,trans_flag); } } void Draw_Windows(windows_ptr win) { switch(win->kind) { case WINDOWS: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,WINDOWS_COLOR_DARK); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_LIGHT); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,WINDOWS_COLOR_OUT); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+10,WINDOWS_COLOR_TITLE); if(win->active==ACTIVE) Blit_String(win->top.x+2,win->top.y+2,win->color,win->word,1); else Blit_String(win->top.x+2,win->top.y+2,NOACTIVE_COLOR,win->word,1); Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-2,win->top.y+win->move.y-2,WINDOWS_COLOR_LIGHT); Fill_Rectangle(win->top.x+2,win->top.y+22,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_DARK); Fill_Rectangle(win->top.x+3,win->top.y+23,win->top.x+win->move.x-3,win->top.y+win->move.y-3,WINDOWS_COLOR_IN); break; } case BUTTON_MENU: { if(win->active==ACTIVE) Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1); else Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1); break; } case BUTTON: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); if(win->active==ACTIVE) Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1); else Blit_String(win->top.x+2,win->top.y+1,NOACTIVE_COLOR,win->word,1); break; } case BUTTON_PRESS: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); Blit_String(win->top.x+2,win->top.y+1,win->color,win->word,1); break; } case BUTTON_CLOSE: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); if(win->active==ACTIVE) { Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color); Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color); } else { Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR); |
|
|
|
|
22楼 } break; } case BUTTON_CLOSE_PRESS: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); Bline(win->top.x+2,win->top.y+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color); Bline(win->top.x+win->move.x-2,win->top.y+2,win->top.x+2,win->top.y+win->move.y-2,win->color); break; } case BUTTON_SMALL: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); if(win->active==ACTIVE) H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color); else H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,NOACTIVE_COLOR); break; } case BUTTON_SMALL_PRESS: { Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x,win->top.y+win->move.y,BUTTON_COLOR_LIGHT); Fill_Rectangle(win->top.x,win->top.y,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR_DARK); Fill_Rectangle(win->top.x+1,win->top.y+1,win->top.x+win->move.x-1,win->top.y+win->move.y-1,BUTTON_COLOR); H_Line(win->top.x+2,win->top.x+win->move.x-2,win->top.y+win->move.y-2,win->color); break; } default:break; } } void Object_Init(windows_ptr ptr,int kind,int x,int y,int move_x,int move_y,char *word,int color,int bk_color,int status,char *hotkey,int bk_flag,void (far *windows),int active) { ptr->kind=kind; ptr->top.x=x; ptr->top.y=y; ptr->move.x=move_x; ptr->move.y=move_y; ptr->word=word; ptr->color=color; ptr->bk_color=bk_color; ptr->status=status; ptr->hotkey=hotkey; ptr->windows=windows; ptr->bk_flag=bk_flag; if(bk_flag==1) ptr->background=(char far *)malloc( (move_x+1)* (move_y+1)+1); ptr->active=active; } void Behind_Button(windows_ptr win) { char far *work_back; int work_offset=0,offset,y; work_back = win->background; offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x; for (y=0; y<BUTTON_Y; y++) { _fmemmove((void far *)&work_back[work_offset], (void far *)&video_buffer[offset], BUTTON_X); offset += SCREEN_WIDTH; work_offset += BUTTON_X; } } void Erase_Button(windows_ptr win) { char far *work_back; int work_offset=0,offset,y; work_back = win->background; offset = (win->top.y << 8) + (win->top.y << 6) + win->top.x; for (y=0; y<BUTTON_Y; y++) { _fmemmove((void far *)&video_buffer[offset], (void far *)&work_back[work_offset], BUTTON_X); offset += SCREEN_WIDTH; |
|
|
|
|
23楼 } } void Object_Delete(windows_ptr win) { int index; if(win->bk_flag==1) free(win->background); free(&win); } void win(windows_ptr win) { // printf("\n\n\n\n\nwindows fuction is in use\n"); } void clo(windows_ptr win) { win->kind=BUTTON_CLOSE_PRESS; Draw_Windows(win); Delay(5); win->kind=BUTTON_CLOSE; Draw_Windows(win); Delay(5); Set_Video_Mode(TEXT_MODE); exit(1); } void bt1(windows_ptr win) { int x,y,fcolor; long i; win->kind=BUTTON_PRESS; Draw_Windows(win); Delay(5); win->kind=BUTTON; Draw_Windows(win); men(win->father); for(i=0;i<1000000;i++) { x=rand()%(WINDOWS_X_MOVE-20); y=rand()%(WINDOWS_Y_MOVE-40); fcolor=rand()%(256)+1; Plot_Pixel_Fast(WINDOWS_X+10+x,WINDOWS_Y+30+y,fcolor); } } void bt2(windows_ptr win) { win->kind=BUTTON_PRESS; Draw_Windows(win); Delay(5); win->kind=BUTTON; Draw_Windows(win); Delay(5); Set_Video_Mode(TEXT_MODE); exit(1); } void sma(windows_ptr win) { win->kind=BUTTON_SMALL_PRESS; Draw_Windows(win); Delay(5); win->kind=BUTTON_SMALL; Draw_Windows(win); Blit_String(WINDOWS_X+10,WINDOWS_Y+30,0,"small button is in use",1); /* if(win->status==MAX) { Fill_Screen_Size(0,win_now.top.x,win_now.top.y,win_now.top.x+win_now.move.x,win_now.top.y+win_now.move.y); win->status=MIN; } else(win->status==MIN); */ } void men(windows_ptr win) { windows *restore; if(win->status==MIN) { now=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,BUTTON,WINDOWS_X+4,WINDOWS_Y+BUTTON_Y+13,BUTTON_X-1,BUTTON_Y-1,"game",0,24,0,"",1,bt1,ACTIVE); now->father=win; Behind_Button(now); Draw_Windows(now); last->next=now; pre=now; now=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,BUTTON,WINDOWS_X+4,WINDOWS_Y+BUTTON_Y*2+13,BUTTON_X-1,BUTTON_Y-1,"exit",0,24,0,"",1,bt2,ACTIVE); now->father=win; Behind_Button(now); Draw_Windows(now); // getch(); // Erase_Button(*now); // getch(); pre->next=now; pre=now; pre->next=NULL; win->status=MAX; } else if(win->status==MAX) { restore=head; if(restore->bk_flag==1) { Erase_Button(restore); Object_Delete(restore); } do{ restore=restore->next; if(restore->bk_flag==1) { Erase_Button(restore); Object_Delete(restore); } }while(restore->next!=NULL); last->next=NULL; win->status=MIN; } } void Judge_Object(void) { int xmouse,ymouse,btnmouse; static int btn=-1; windows_ptr test; Squeeze_Mouse(MOUSE_BUTT_POS,&xmouse,&ymouse,&btnmouse); if(btnmouse==btn) return; else btn=btnmouse; xmouse=xmouse/2; ymouse=ymouse; if(btnmouse==1) { test=head; if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&& (ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y)) { Squeeze_Mouse(MOUSE_HIDE,0,0,0); if(test->active==ACTIVE) test->windows(test); Squeeze_Mouse(MOUSE_SHOW,0,0,0); } do{ test=test->next; if((xmouse>=test->top.x&&xmouse<=test->top.x+test->move.x)&& (ymouse>=test->top.y&&ymouse<=test->top.y+test->move.y)) { Squeeze_Mouse(MOUSE_HIDE,0,0,0); if(test->active==ACTIVE) test->windows(test); Squeeze_Mouse(MOUSE_SHOW,0,0,0); } }while(test->next!=NULL); } } void main(void) { windows_ptr test; Set_Video_Mode(VGA256); now=pre=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,WINDOWS,WINDOWS_X,WINDOWS_Y,WINDOWS_X_MOVE,WINDOWS_Y_MOVE,"This is a game desktop",0,24,0,"",0,win,ACTIVE); win_now=now; Draw_Windows(now); head=now; now=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,BUTTON_MENU,WINDOWS_X+2,WINDOWS_Y+11,BUTTON_X-1,BUTTON_Y-1,"Menu",0,24,MIN,"",0,men,ACTIVE); Draw_Windows(now); pre->next=now; pre=now; now=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,BUTTON_SMALL,WINDOWS_X+WINDOWS_X_MOVE-(BUTTON_XY+2)*2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,MAX,"",0,sma,NOACTIVE); Draw_Windows(now); pre->next=now; pre=now; now=(struct windows *)malloc(sizeof(struct windows)); Object_Init(now,BUTTON_CLOSE,WINDOWS_X+WINDOWS_X_MOVE-BUTTON_XY-2,WINDOWS_Y+2,BUTTON_XY-1,BUTTON_XY-1,"",0,24,0,"",0,clo,ACTIVE); Draw_Windows(now); pre->next=now; pre=now; pre->next=NULL; last=pre; /* getch(); test=head; test->windows(*test); getch(); do{ test=test->next; test->windows(*test); getch(); }while(test->next!=NULL); */ Squeeze_Mouse(MOUSE_RESET,0,0,0); mscurson(handcurs); while(1){ Judge_Object(); } } |
|
|
|
|
25楼 |
|
|
|
| 61.152.217.* |
27楼 |
|
|
| 221.234.27.* |
28楼 |
|
|
| 218.95.40.* |
29楼 |
|
|

