实验内容:大一C语言程序设计-游戏-SuperMario | |
实验工具:codeblocks & ege | |
代码内容: | |
#include<stdio.h> | |
#include<graphics.h> | |
#include<windows.h> | |
#include<time.h> | |
#include<pthread.h> | |
#include<mmsystem.h> | |
#pragma comment(lib,"WINMM.LIB") | |
pthread_t BGM; | |
PIMAGE mapimage,mari[8],ar[3],wal[5],ques,water,moguimage,mar[2],map1image[4],map2image[4],mon, goldi[4],bg,di,star[4],prin,love,bad1,ambulen[4],lunyiboy[2],mushroom,monster[2],tor[2]; | |
/****强行标记所用***/ | |
int gamelevel = 0; // 计算关卡 | |
int itime, mark = 100 ; // 开始游戏否 | |
int temp ; | |
int conting=1; | |
int alpha = 0, da = 1; // 淡入 淡出标记 | |
int gameState = 0; | |
int music_control = 1; | |
int music_num=0; | |
int music_begin = 1; | |
int sign =100; // 标记音效 | |
int map_sign = 0; //判断第二关摔了没 | |
int te = 0; | |
int am = 0; | |
/***** 初始值 **********/ | |
int life_num=3; | |
int score_num=0; | |
int game_score=0; | |
int second; | |
/***** 金币的转圈 地图的转动 ******/ | |
int g=0; | |
int k = 0; | |
/***** 地图的的显示****/ | |
int map[18][30]; | |
int map2[18][30]; | |
void init_map() | |
{ | |
int i =0,j=0; | |
if(gamelevel == 1) | |
{ | |
int map1[18][30]= | |
{ | |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | |
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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{ | |
for(j=0; j<30; j++) | |
{ | |
map[i][j] = map3[i][j]; | |
} | |
} | |
} | |
} | |
PIMAGE wel[5],starimage[2], marion[2],bgl,mu,img,situa; | |
mouse_msg ms; | |
void init_wel() | |
{ | |
int i; | |
initgraph(1024,768); | |
for(i=0; i<5; i++) | |
{ | |
wel[i] = newimage(); | |
} | |
for(i=0; i<2; i++) | |
{ | |
starimage[i] = newimage(); | |
marion[i] = newimage(); | |
} | |
bgl = newimage(); | |
bad1 = newimage(); | |
mu = newimage(); | |
img = newimage(); | |
situa=newimage(); | |
getimage(situa,"c\\welcom\\situation2.png"); | |
getimage(img,"c\\welcom\\1.png"); | |
getimage(bad1,"c\\bad\\bad1.png"); | |
getimage(wel[0],"c\\welcom\\wel1.0.jpg"); | |
getimage(wel[1],"c\\welcom\\wel1.1.jpg"); | |
getimage(wel[2],"c\\welcom\\wel1.2.jpg"); | |
getimage(wel[3],"c\\welcom\\wel1.3.jpg"); | |
getimage(wel[4],"c\\welcom\\wel1.4.jpg"); | |
getimage(starimage[0],"c\\welcom\\star.png"); | |
getimage(starimage[1],"c\\welcom\\star1.png"); | |
getimage(marion[0],"c\\welcom\\mario1.png"); | |
getimage(marion[1],"c\\welcom\\mario2.png"); | |
getimage(bgl,"c\\welcom\\bgl.png"); | |
getimage(mu,"c\\welcom\\music.png"); | |
} | |
void* play_clickmusic(void *ret) | |
{ | |
int temp=*(int *)ret; | |
if(temp==0) | |
{ | |
mciSendString(TEXT("open music\\jump.mp3 alias jump"), NULL, 0, NULL); | |
mciSendString(TEXT("play jump"), NULL, 0, NULL); | |
} | |
if(temp == 1) | |
{ | |
mciSendString(TEXT("open music\\vic.mp3 alias vic"), NULL, 0, NULL); | |
mciSendString(TEXT("play vic"), NULL, 0, NULL); | |
} | |
if(temp == 2) | |
{ | |
mciSendString(TEXT("open music\\glod.mp3 alias gold"), NULL, 0, NULL); | |
mciSendString(TEXT("play gold"), NULL, 0, NULL); | |
} | |
if(temp == 3) | |
{ | |
mciSendString(TEXT("open music\\die.mp3 alias die"), NULL, 0, NULL); | |
mciSendString(TEXT("play die"), NULL, 0, NULL); | |
} | |
if(temp == 4) | |
{ | |
mciSendString(TEXT("open music\\change.mp3 alias change"), NULL, 0, NULL); | |
mciSendString(TEXT("play change"), NULL, 0, NULL); | |
} | |
if(temp == 7) | |
{ | |
mciSendString(TEXT("open music\\monsfeat.mp3 alias monsfeat"), NULL, 0, NULL); | |
mciSendString(TEXT("play monsfeat"), NULL, 0, NULL); | |
} | |
} | |
void show_situation() | |
{ | |
while(1) | |
{ | |
bar(0,0,1024,768); | |
putimage_transparent(NULL,marion[1],0,0,BLACK); | |
/***介绍游戏玩法****/ | |
putimage(0,0,situa); | |
setfillcolor(BLACK); | |
bar(80,700,200,750,NULL); | |
setfont(40, 0,"宋体"); | |
setbkmode(TRANSPARENT); | |
setcolor(WHITE); | |
outtextxy(100,700,"Back"); | |
while(mousemsg()) // 检测当时是否有鼠标消息 | |
{ | |
ms=getmouse(); | |
if(ms.x>80 && ms.x<200 && ms.y >700 && ms.y <750) | |
{ | |
setfillcolor(LIGHTGRAY); | |
bar(80,700,200,750,NULL); | |
setfont(40, 0,"宋体"); | |
setbkmode(TRANSPARENT); | |
setcolor(BLUE); | |
outtextxy(100,700,"Back"); | |
} | |
} | |
delay_fps(60); | |
ms=getmouse(); | |
if(ms.is_left() && ms.x>80 && ms.x<200 && ms.y >700 && ms.y <750) | |
{ | |
gameState = 0; | |
break; | |
} | |
} | |
} | |
void TIME() | |
{ | |
int time; | |
time = clock(); | |
second = time/1000; | |
} | |
typedef struct Stone | |
{ | |
int x,y; | |
int alive; | |
} stone; | |
stone sto[2], gold[20]; | |
typedef struct Role | |
{ | |
int x,y; | |
int arrow; | |
int dex; | |
int speed; | |
int high; | |
int alive; | |
int victory; | |
//int lun; | |
} role; | |
role mario, mogu, qu[2], prins,monste; | |
enum arrow | |
{right, left}; | |
void init_pic() | |
{ | |
initgraph(800,500); | |
int i; | |
mapimage = newimage(); | |
for(i=0; i<8; i++) | |
{ | |
mari[i] = newimage(); | |
} | |
for(i=0; i<2; i++) | |
{ | |
mar[i] = newimage(); | |
lunyiboy[i] = newimage(); | |
monster[i] = newimage(); | |
tor[i] = newimage(); | |
} | |
for(i=0; i<5; i++) | |
{ | |
wal[i] = newimage(); | |
} | |
for(i=0; i<4; i++) | |
{ | |
goldi[i] = newimage(); | |
star[i] = newimage(); | |
map1image[i] = newimage(); | |
map2image[i] = newimage(); | |
ambulen[i] = newimage(); | |
} | |
for(i=0;i<3;i++) | |
{ | |
ar[i] = newimage(); | |
} | |
ques = newimage(); | |
water = newimage(); | |
moguimage = newimage(); | |
prin=newimage(); | |
mon= newimage(); | |
bg = newimage(); | |
di = newimage(); | |
love = newimage(); | |
mushroom = newimage(); | |
getimage(mushroom,"c\\underground\\mon1.png"); | |
getimage(monster[0],"c\\ground1\\mons.png"); | |
getimage(monster[1],"c\\ground1\\mons2.png"); | |
getimage(tor[0],"c\\ground1\\torr.png"); | |
getimage(tor[1],"c\\ground1\\torl.png"); | |
getimage(ar[0],"c\\ground1\\al.png"); | |
getimage(ar[1],"c\\ground1\\au.png"); | |
getimage(ar[2],"c\\ground1\\ad.png"); | |
getimage(mapimage,"c\\ground1\\map1.jpg"); | |
/* getimage(lunyiboy[0],"c\\underground\\lunyi.png"); | |
getimage(lunyiboy[1],"c\\underground\\lunyi2.png");*/ | |
getimage(lunyiboy[0],"c\\underground\\lunyi6.png"); | |
getimage(lunyiboy[1],"c\\underground\\lunyi61.png"); | |
getimage(prin,"c\\ground1\\prin.png"); | |
getimage(love,"c\\ground1\\over.png"); | |
getimage(map1image[0],"c\\underground\\map1.0.png"); | |
getimage(map1image[1],"c\\underground\\map1.1.png"); | |
getimage(map1image[2],"c\\underground\\map1.3.png"); | |
getimage(map1image[3],"c\\underground\\map1.2.png"); | |
getimage(map2image[0],"c\\underground\\map2.0.png"); | |
getimage(map2image[1],"c\\underground\\map2.1.png"); | |
getimage(map2image[2],"c\\underground\\map2.3.png"); | |
getimage(map2image[3],"c\\underground\\map2.2.png"); | |
getimage(ambulen[0],"c\\underground\\m1.0.png"); | |
getimage(ambulen[1],"c\\underground\\m1.1.png"); | |
getimage(ambulen[2],"c\\underground\\m1.2.png"); | |
getimage(ambulen[3],"c\\underground\\m1.3.png"); | |
getimage(bg,"c\\underground\\bg.png"); | |
getimage(mari[0],"c\\ground1\\mariol.1.png"); //0 ×óÒ» | |
getimage(mari[1],"c\\ground1\\mariol.2.png"); //1 ×ó¶þ | |
getimage(mari[2],"c\\ground1\\marior.1.png"); //2 ÓÒÒ» | |
getimage(mari[3],"c\\ground1\\marior.2.png"); //3 ÓÒ¶þ | |
getimage(mari[4],"c\\ground1\\jump1.png"); | |
getimage(mari[5],"c\\ground1\\jumpd.png"); | |
getimage(mari[6],"c\\underground\\jumpdie.png"); | |
getimage(mari[7],"c\\underground\\jumpdiele.png"); | |
getimage(wal[0],"c\\ground1\\wal.jpg"); | |
getimage(wal[1],"c\\underground\\wal.jpg"); | |
getimage(wal[2],"c\\underground\\walb.png"); | |
getimage(wal[3],"c\\ground1\\walb.png"); | |
getimage(wal[4],"c\\ground1\\walo.png"); | |
getimage(ques,"c\\ground1\\ques.jpg"); | |
getimage(water,"c\\ground1\\water.png"); | |
getimage(moguimage,"c\\ground1\\mogu.png"); | |
getimage(mar[0],"c\\ground1\\mar.png"); // you | |
getimage(mar[1],"c\\ground1\\mal.png"); // zuo | |
getimage(mon,"c\\underground\\mon2.png"); | |
getimage(goldi[0],"c\\ground1\\gold.png"); | |
getimage(goldi[1],"c\\ground1\\goldiif.png"); | |
getimage(goldi[2],"c\\ground1\\goldif.png"); | |
getimage(goldi[3],"c\\ground1\\goldf.png"); | |
getimage(di,"c\\bad\\die.png"); | |
getimage(star[0],"c\\ground1\\starr.png"); | |
getimage(star[1],"c\\ground1\\starr1.png"); | |
getimage(star[2],"c\\ground1\\starr2.png"); | |
getimage(star[3],"c\\ground1\\starr4.png"); | |
} | |
void init() | |
{ | |
int i; | |
init_map(); | |
itime =0; | |
init_pic(); | |
conting = 1; | |
mario.alive =1; | |
mario.victory = 0; | |
if(mario.speed != 2) | |
map_sign = 0; | |
//lun = 0; | |
am = 0; | |
if(mark !=1 ) | |
{ | |
return; | |
} | |
mario.x=1; | |
mario.y=15; | |
mario.arrow = right; | |
mario.high = 0; | |
mario.dex =0; | |
/**** 一关怪物 二关蘑菇 ***/ | |
if(gamelevel == 2) | |
{ | |
monste.x = 3; | |
monste.y = 3; | |
monste.alive = 0; | |
} | |
if(gamelevel == 1) | |
{ | |
monste.y = 11; | |
超级玛丽C语言
最新推荐文章于 2025-02-03 13:14:54 发布