<stdio.h> <dos.h> <stdlib.h> <conio.h> <mem.h> <time.h> <math.h> <alloc.h> MAX_STAR 80 MAX_OBJ 30 MAXY 169 ulong; far *VideoBuf=( far*)0xa0000000L, *MemBuf; keys[128]; KEY_UP=72,KEY_DOWN=80,KEY_LEFT=75,KEY_RIGHT=77,KEY_ESC=1,KEY_CTRL=29; interrupt far (*OldInt9)(); interrupt NewInt9(); GameStart(); TStars { x,y,v; } Stars[MAX_STAR]; TObj { mode,type,index,next,x,y; } Objs[MAX_OBJ]; GameScore=0; fly_pic[260]={ 16,0,16,0,0,0,0,29,25,0,0,0,0,25,29,196,0,0,0,0,0,0,0,25,25,0,0,0,0,25,0,196,0, 0,0,0,112,112,0,25,196,40,40,29,112,112,40,112,0,112,112,112,40,40,112,112,40,40, 25,25,112,40,40,112,112,112,112,112,112,40,112,25,40,40,112,112,112,40,40,25, 40,112,112,0,0,112,112,25,40,40,40,112,40,40,40,25,40,112,0,0,0,0,112,25,40, 112,40,112,112,112,40,25,112,0,0,0,0,0,0,29,112,0,40,0,112,0,112,29,0,0,0,0, 0,0,0,29,112,0,40,54,112,0,112,29,0,0,0,0,0,0,0,29,0,0,40,54,112,0,0,29,0,0, 0,0,0,0,0,0,0,40,112,25,112,112,0,0,0,0,0,0,0,0,0,0,0,40,112,25,112,112,0,0, 0,0,0,0,0,0,0,0,0,40,112,112,112,112,0,0,0,0,0,0,0,0,0,0,0,0,40,112,112,0,0, 0,0,0,0,0,0,0,0,0,0,0,40,25,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,112,0,0,0,0,0,0,0, 0}; copyright() { printf("Game Over. your score %ld/n",GameScore); printf("Thank you for play it, if you have any question please call me/n"); printf("(0871)7167710 or [email protected], Lin Wei/n"); } game_init(); game_restore(); main() { (!game_init()) ; printf(" - STAR WAR -/r"); GameStart(); game_restore(); copyright(); } game_init() { i; REGS regs; MemBuf=( far*)farmalloc(320L*(MAXY+1)); (!MemBuf) { printf("not enough memory/n"); 0; } memset(MemBuf,0,320L*(MAXY+1)); randomize(); (i=0;i<128;i++) keys[i]=0; (i=0;i<MAX_STAR;i++) { Stars[i].x=random(320); Stars[i].y=-20+random(250); Stars[i].v=1; (i<MAX_STAR/3) Stars[i].v++; } (i=0;i<MAX_OBJ;i++) Objs[i].mode=0; OldInt9=getvect(9); disable(); setvect(9,NewInt9); enable(); regs.x.ax=0x13; int86(0x10,®s,®s); 1; } game_restore() { REGS regs; disable(); setvect(9,OldInt9); enable(); regs.x.ax=3; int86(0x10,®s,®s); farfree(MemBuf); 0; } interrupt NewInt9() { key; key=inportb(0x60); (key<0x80) keys[key]=1; keys[key&0x7f]=0; key=inportb(0x61); key|=0x80; outportb(0x61,key); outportb(0x61,key&0x7f); outportb(0x20,0x20); } pixel( x, y, c) { (x>=320||y>MAXY) ; MemBuf[(y<<8)+(y<<6)+x]=c; } show() { offset=(199-MAXY)*160; memcpy(VideoBuf+offset,MemBuf,320L*(MAXY+1)); } clear() { memset(MemBuf,0,320L*(MAXY+1)); } putimage( x, y, *b, mode) { len, wid, i, j; len = b[0] + ()b[1] * 256; wid = b[2] + ()b[3] * 256; x-=len/2; y-=wid/2; (j=0,b=b+4;j<wid;j++) (i=0;i<len;i++,b++) { (*b&&!mode) pixel(x+i,y+j,*b); (*b&&mode) pixel(x+i,y+wid-j-1,*b); } } drawfire( x, y) { i,j; (i=-6;i<6;i++) { pixel(x-5,y+i,9); pixel(x+3,y+i,9); } } timepass; GameOver, Sound=0; fly_x=160,fly_y=MAXY*2/3,fly_flag=1,fire_flag=1; drivers(); control(); AllocObj() { i=0; (i<MAX_OBJ&&Objs[i].mode) i++; (i>=MAX_OBJ) i=MAX_OBJ-1; i; } CheckHit( x1, y1, x2, y2, r) { (abs(x1-x2)<=r&&abs(y1-y2)<=r) 1; 0; } ulong fclock() { ulong t; disable(); outportb(0x43,0); t=inportb(0x40); t+=(inportb(0x40)<<8); t=0xffff^t; enable(); (clock()<<16)+t; } GameStart() { ulong start=0; timepass=0; (!GameOver) { (fclock()-start<=45000L); start=fclock(); clear(); timepass++; control(); drivers(); show(); (--Sound<=0) nosound(); ((timepass&3)==0) printf("%d/r",GameScore); (keys[KEY_ESC]) GameOver=1; } sound(105); delay(700); nosound(); 1; } control() { i,j,x,y, ok; (i=0;i<MAX_STAR;i++) { Stars[i].y+=Stars[i].v; (Stars[i].y>MAXY) { Stars[i].x=random(320); Stars[i].y=-random(60); } (Stars[i].v==1) pixel(Stars[i].x,Stars[i].y,23); pixel(Stars[i].x,Stars[i].y,28); } (i=0;i<MAX_OBJ;i++) { x=Objs[i].x; y=Objs[i].y; ok=1; (Objs[i].mode) { 1: (Objs[i].index==0) { (Objs[i].type) { 0: (!random(30)) Objs[i].type=1; ; 1: (x<fly_x) x++; (x>fly_x) x--; (!random(40)) Objs[i].type=2; ; 2: : (!random(3)) y+=3; ; } (CheckHit(x,y,fly_x,fly_y,15)) fly_flag=0; putimage(x,y,fly_pic,0); } { ((Objs[i].index&3)==0) putimage(x,y,fly_pic,0); (++Objs[i].index>50) Objs[i].mode=0; } y++; (y>MAXY) Objs[i].mode=0; ; 2: y-=4; (y<-20) Objs[i].mode=0; drawfire(x,y); (j=0;j<MAX_OBJ;j++) (Objs[j].mode==1&&CheckHit(x,y,Objs[j].x,Objs[j].y,15)&& !Objs[j].index&&ok) { Objs[j].index=1; ok=0; Objs[i].mode=0; sound(220); Sound=10; GameScore+=10; } ; } Objs[i].x=x; Objs[i].y=y; } (keys[KEY_UP]) (--fly_y<0) fly_y=0; (keys[KEY_DOWN]) (++fly_y>MAXY) fly_y=MAXY; (keys[KEY_LEFT]) (--fly_x<0) fly_x=0; (keys[KEY_RIGHT]) (++fly_x>319) fly_x=319; (keys[KEY_CTRL]&&fire_flag) { i=AllocObj(); Objs[i].x=fly_x, Objs[i].y=fly_y-10, Objs[i].mode=2; fire_flag=0; } (!keys[KEY_CTRL]) fire_flag=1; putimage(fly_x,fly_y,fly_pic,1); (!fly_flag) GameOver=1; } drivers() { (random(30)==0) { i=AllocObj(); Objs[i].x=random(320); Objs[i].y=-random(20); Objs[i].mode=1; Objs[i].type=Objs[i].index=0; (!random(20)) Objs[i].type=2; } }
MINI-FOOLFLY 遊戲代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.