为了正常的体验网站,请在浏览器设置里面开启Javascript功能!
首页 > (精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】

(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】

2018-03-20 8页 doc 22KB 7阅读

用户头像

is_637320

暂无简介

举报
(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】 ?òµ??ò?ɵúÐ?ÓÎÏ? #include #include #include #include #define KEY_ESC 0x01 #define KEY_SPACE 0x39 #define KEY_UP 0x48 #define KEY_LEFT 0x4b #define KEY_RIGHT 0x4d #define KEY_DOWN 0x50 int gamespeed=1200;/*×Ô?º?ÄÓÎÏ?µÄËÙ?È*...
(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】
(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】 ?òµ??ò?ɵúÐ?ÓÎÏ? #include #include #include #include #define KEY_ESC 0x01 #define KEY_SPACE 0x39 #define KEY_UP 0x48 #define KEY_LEFT 0x4b #define KEY_RIGHT 0x4d #define KEY_DOWN 0x50 int gamespeed=1200;/*×Ô?º?ÄÓÎÏ?µÄËÙ?È*/ int speed;/*?ɵúÒÆ??ËÙ?È*/ int col;/*ÖÐÐÄ×ø?ê*/ int score=0;/*µÃ?Ö*/ char key_state[128],key_pressed[128];/*?üÅÌ?Ù×?ÓõÄ?äÁ?*/ void Init();/*?õÊ?*/ void Close();/*?Ø?Õ*/ void PlayGame();/*ÓÎÏ??ý?Ì*/ void PrScore();/*Êä?ö?É??*/ void DrawM(int x,int y,int color);/*?,Ãé×?Æ?*/ void Win();/*Êä?ö×îºó?á?û*/ int GetKey(int ScanCode);/*ÕâÀï?ªÊ???ÊÇ???üº?Êý*/ void interrupt far (*OldInt9Handler)(); void far interrupt NewInt9(); void InstallKeyboard(); void ShutDownKeyboard(); DrawFly(int x,int y,int color);/*?,?ɵú*/ void main(void) { Init(); PlayGame(); Close(); } void PrScore()/*Êä?ö?É??*/ { char s[10]; setfillstyle(SOLID_FILL,BLACK); bar(30,0,100,50); setcolor(6); settextstyle(0,0,2); sprintf(s,"%d",score); outtextxy(30,20,s); } void DrawM(int x,int y,int color)/*?,Ãé×?Æ?*/ { setcolor(color); rectangle(x-10,y-10,x+10,y+10); line(x-8,y,x+8,y); line(x,y-8,x,y+8); } void Win()/*Êä?ö×îºó?á?û*/ { settextstyle(0,0,4); setcolor(RED); if(score>18) outtextxy(200,200,"VERY GOOD"); else if(score>10) outtextxy(250,200,"GOOD"); else outtextxy(250,200,"~@_@~"); } void PlayGame()/*ÓÎÏ??ý?Ì*/ { float x,y;/*?ɵúµÄ×ø?ê*/ int mx,my; int i,num=0; for(i=40;i<640;i+=30) DrawFly(i,65,WHITE); mx=my=300; setcolor(15); line(0,80,640,80); randomize(); while(num<20) { PrScore();/*Êä?ö?É??*/ col=random(10);/*ÖÐÐÄ×ø?êËæ?ú*/ col=col*20+200; speed=2+random(2);/*?ɵúËÙ?ÈËæ?ú*/ for(x=-250;x<=250;x+=speed)/*?ɵúÒÆ??È??ý?Ì*/ { y=pow((x/10),2)+200;/*Çóy×ø?ê*/ DrawFly(x,y,WHITE); DrawM(mx,my,YELLOW); delay(gamespeed);/*?ä?ô*/ DrawM(mx,my,BLACK); DrawFly(x,y,BLACK); if(GetKey(KEY_ESC))/*?áÊøÓÎÏ?*/ break; if(GetKey(KEY_LEFT)) mx-=4; if(GetKey(KEY_RIGHT)) mx+=4; if(GetKey(KEY_DOWN)) my+=4; if(GetKey(KEY_UP)&&my>100) my-=4; if(GetKey(KEY_SPACE))/*??×Óµ?*/ { if(((x+col+10)>=(mx-2)&&x<=(mx+2))&&(y>=(my-2)&&y<=(my+2)))/*ÕâÀï? ØÖÆ??È??È*/ { score++; DrawFly(x,y,BLACK); DrawM(mx,my,YELLOW); PrScore(); DrawM(mx,my,BLACK); break; } } if(y>490&&col+x>col)/*×Ô??ÏûÊ?*/ break; } if(y<490) { setcolor(RED); line(40+num*30-10,55,40+num*30+10,75); line(40+num*30-10,75,40+num*30+10,55); } num++; if(GetKey(KEY_ESC))/*?áÊøÓÎÏ?*/ break; } Win(); while(1) { if(GetKey(KEY_ESC)) break; } } void Init()/*{ int gd=DETECT,gm; initgraph(&gd,&gm,"c:\\tc"); cleardevice(); InstallKeyboard(); } void Close()/*?Ø?Õ*/ { ShutDownKeyboard(); closegraph(); } DrawFly(int x,int y,int color)/*?,?ɵú*/ { setcolor(BLACK); setfillstyle(SOLID_FILL,color); fillellipse(col+x,y,10,6); } void far interrupt NewInt9(void) { unsigned char ScanCode,temp; ScanCode=inportb(0x60); temp=inportb(0x61); outportb(0x61,temp | 0x80); outportb(0x61,temp & 0x7f); if(ScanCode&0x80) { ScanCode&=0x7f; key_state[ScanCode]=0; } else { key_state[ScanCode]=1; key_pressed[ScanCode]=1; } outportb(0x20,0x20); } void InstallKeyboard(void) { int i; for(i=0;i<128;i++) key_state[i]=key_pressed[i]=0; OldInt9Handler=getvect(9); /*ÖÐ?ÏÏòÁ?Öµ*/ setvect(9,NewInt9); /*ÖÐ?Ï?ÌÐòNewInt9µØÖ??æÈëÖ???µÄÖÐ?ÏÏòÁ??íÖÐINT 09H*/ } void ShutDownKeyboard(void) { setvect(9,OldInt9Handler); } int GetKey(int ScanCode) { int res; res=key_state[ScanCode]|key_pressed[ScanCode]; key_pressed[ScanCode]=0; return res; }
/
本文档为【(精品)初学者天地-游戏制作-简单打飞碟小游戏【整理】】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索