前不久,我刚升级EGE图形库,就小试身手(主要太激动了)做了一款小游戏。
上代码
#include#include #include #include #include #include #include #include #pragma comment(lib,"Winmm.lib") PIMAGE Gameone; PIMAGE Gametwo; PIMAGE Gamethree; PIMAGE Gamefour; PIMAGE Gamefive; PIMAGE human; PIMAGE GameUI1; PIMAGE GameUI2; PIMAGE GameUI3; PIMAGE GameUI4; PIMAGE img0; PIMAGE img1; PIMAGE img2; PIMAGE img3; PIMAGE img4; PIMAGE img5; PIMAGE img6; PIMAGE img7; PIMAGE img8; int hand=3; char ch,ch1; int choose,X,Y; int printmap() { setinitmode(1); initgraph(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN)); img0 = newimage(); img1 = newimage(); img2 = newimage(); img3 = newimage(); img4 = newimage(); img5 = newimage(); img6 = newimage(); img7 = newimage(); img8 = newimage(); human = newimage(); GameUI1 = newimage(); GameUI2 = newimage(); GameUI3 = newimage(); GameUI4 = newimage(); Gameone = newimage(); Gametwo = newimage(); Gamethree = newimage(); Gamefour = newimage(); Gamefive = newimage(); getimage(human,"\image\human.bmp",0,0); getimage(img0,"\image\0.bmp",0,0); getimage(img1,"\image\1.bmp",0,0); getimage(img2,"\image\2.bmp",0,0); getimage(img3,"\image\3.bmp",0,0); getimage(img4,"\image\4.bmp",0,0); getimage(img5,"\image\5.bmp",0,0); getimage(img6,"\image\6.bmp",0,0); getimage(img7,"\image\7.bmp",0,0); getimage(img8,"\image\8.bmp",0,0); getimage(GameUI1,"\image\GameUI1.bmp",0,0); getimage(GameUI2,"\image\GameUI2.bmp",0,0); getimage(GameUI3,"\image\GameUI3.bmp",0,0); getimage(GameUI4,"\image\GameUI4.bmp",0,0); getimage(Gameone,"\image\OnePrint.bmp",0,0); getimage(Gametwo,"\image\TwoPrint.bmp",0,0); getimage(Gamethree,"\image\ThreePrint.bmp",0,0); getimage(Gamefour,"\image\FourPrint.bmp",0,0); getimage(Gamefive,"\image\FivePrint.bmp",0,0); putimage(0,0,Gameone); getch(); putimage(0,0,Gametwo); choose=2; while(1) { ch=getch(); if(ch=='a') { putimage(0,0,Gamethree); choose=1; } if(ch=='d') { putimage(0,0,Gametwo); choose=2; } if(ch==' ') { if(choose==1) { break; } if(choose==2) { putimage(0,0,Gamefour); getch(); putimage(0,0,Gametwo); } } } putimage(0,0,GameUI3); while(Y<22) { Y++; putimage(X,64,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,128,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,192,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,256,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,320,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,320,img0); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,384,img1); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,448,img8); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,512,img8); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,576,img8); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,640,img8); X=X+64; } X=0; Y=0; while(Y<22) { Y++; putimage(X,704,img8); X=X+64; } putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); putimage(0,320,human); X=0; Y=320; return 0; } int printUI() { if(hand==1) { putimage(0,0,GameUI1); } if(hand==2) { putimage(0,0,GameUI2); } if(hand==3) { putimage(0,0,GameUI3); } if(hand==4) { putimage(0,0,GameUI4); } return 0; } int getinput() { printmap(); while(1) { if(Y<=64) { Y=64; printUI(); putimage(X,Y,human); } if(X<=0) { X=0; printUI(); putimage(X,Y,human); } if(Y>=704) { Y=704; printUI(); putimage(X,Y,human); } if(X>=1280) { X=1280; printUI(); putimage(X,Y,human); putimage(1344,Y,img0); } putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); ch=getch(); printUI(); if(ch==0x1B) { while(1) { putimage(0,0,Gamefive); ch1=getch(); if(ch1==' ') { if(hand==1) { putimage(0,0,GameUI1); break; } if(hand==2) { putimage(0,0,GameUI2); break; } if(hand==3) { putimage(0,0,GameUI3); break; } if(hand==4) { putimage(0,0,GameUI4); break; } } if(ch1==0x1B) { exit(0); } } } if(ch==' ') { putimage(X,Y,img0); Y=Y-64; putimage(X,Y,human); putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); Sleep(250); putimage(X,Y,img0); Y=Y+64; printUI(); putimage(X,Y,human); putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); } if(ch=='d') { putimage(X,Y,img0); X=X+64; printUI(); putimage(X,Y,human); putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); } if(ch=='a') { putimage(X,Y,img0); X=X-64; printUI(); putimage(X,Y,human); putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); } if(ch=='s') { putimage(X,Y,img0); Y=Y+64; printUI(); putimage(X,Y,human); putimage(296,128,img3); putimage(360,128,img4); putimage(824,128,img5); putimage(888,128,img6); } if(ch=='w') { if(hand==1) { putimage(X,Y,img0); putimage(X,Y,img1); Y=Y-64; putimage(X,Y,human); } if(hand==2) { putimage(X,Y,img0); putimage(X,Y,img2); Y=Y-64; putimage(X,Y,human); } if(hand==3) { putimage(X,Y,img0); putimage(X,Y,img7); Y=Y-64; putimage(X,Y,human); } if(hand==4) { putimage(X,Y,img0); putimage(X,Y,img8); Y=Y-64; putimage(X,Y,human); } } if(ch=='1') { hand=1; putimage(0,0,GameUI1); } if(ch=='2') { hand=2; putimage(0,0,GameUI2); } if(ch=='3') { hand=3; putimage(0,0,GameUI3); } if(ch=='4') { hand=4; putimage(0,0,GameUI4); } if(ch=='l') { if(hand==1) { X=X+64; putimage(X,Y,img1); X=X-64; printUI(); } if(hand==2) { X=X+64; putimage(X,Y,img2); X=X-64; printUI(); } if(hand==3) { X=X+64; putimage(X,Y,img7); X=X-64; printUI(); } if(hand==4) { X=X+64; putimage(X,Y,img8); X=X-64; printUI(); } } if(ch=='j') { if(hand==1) { X=X-64; putimage(X,Y,img1); X=X+64; printUI(); } if(hand==2) { X=X-64; putimage(X,Y,img2); X=X+64; printUI(); } if(hand==3) { X=X-64; putimage(X,Y,img7); X=X+64; printUI(); } if(hand==4) { X=X-64; putimage(X,Y,img8); X=X+64; printUI(); } } if(ch=='i') { if(hand==1) { Y=Y-64; putimage(X,Y,img1); Y=Y+64; printUI(); } if(hand==2) { Y=Y-64; putimage(X,Y,img2); Y=Y+64; printUI(); } if(hand==3) { Y=Y-64; putimage(X,Y,img7); Y=Y+64; printUI(); } if(hand==4) { Y=Y-64; putimage(X,Y,img8); Y=Y+64; printUI(); } } if(ch=='k') { if(hand==1) { Y=Y+64; putimage(X,Y,img1); Y=Y-64; printUI(); } if(hand==2) { Y=Y+64; putimage(X,Y,img2); Y=Y-64; printUI(); } if(hand==3) { Y=Y+64; putimage(X,Y,img7); Y=Y-64; printUI(); } if(hand==4) { Y=Y+64; putimage(X,Y,img8); Y=Y-64; printUI(); } } } closegraph(); return 0; } int main() { getinput(); return 0; }
图片自己配,放在文件目录下image文件夹里
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)