欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言 90后懷舊游戲超級瑪麗的實現(xiàn)流程

 更新時間:2021年11月22日 09:57:35   作者:MAX在碼字  
90后最風(fēng)靡的游戲是什么?第一個聯(lián)想到的肯定是插卡游戲機或者VCD加光盤運行在電視機上的超級瑪麗了,它的經(jīng)典絕對可以排在第一位,長大后的我們今天來用C語言重溫一下

在你的童年記憶里,是否有一個蹦跳、頂蘑菇的小人已經(jīng)被遺忘?

如果你回憶起了它,你定然會覺得現(xiàn)在它幼稚、無聊,畫面不漂亮,游戲不精彩……但請你記?。哼@才是真正的游戲,它給了你無限的歡樂!許多人只玩過紅白機或者網(wǎng)上玩家自己制作的幾個破Flash小游戲就還以為任天堂所驕傲的“馬里奧”系列就這樣子的,你們真的以為超級馬里奧就是1985年的“踩蘑菇/采蘑菇”么?也許大家都管馬里奧叫超級瑪麗,踩蘑菇,這是誰宣傳的?

誰認為馬里奧就1個游戲?誰說馬里奧沒有一個是2000年后出的!

從32K的ROM卡帶到4.3G的特制光盤,從1.79MHZ的8位處理器到主頻數(shù)G的次世代主機,從畫面簡陋的2D時代到音色俱佳的3D動畫……你們才知道多少就說什么“超級瑪麗”是所謂的幼稚游戲呢?一點也不亞于怪物獵人,極品飛車,火影忍者等等!在華麗的3D游戲、CG 動畫大行其道的今天,你們應(yīng)該想想,游戲是為了看畫面還是為了讓你快樂,請你回想馬里奧在以前給你帶來的快樂,它不是最真實、最純樸的快樂么?

所有曾經(jīng)的馬迷,如果你渴望重新找回超級馬里奧在以前給你帶來的快樂,那么,試試在百度上打 超級馬里奧 吧!超級瑪麗只是一個人們習(xí)慣性的叫法,任天堂出的這款游戲是馬里奧系列.

有一些人說"超級瑪麗"說只有1個游戲.連一點意思都沒有.還說馬里奧是美國出的.是美國1970年出的下流東西。這對馬里奧的忠實者會造成很大的傷害.

根據(jù)我們的不完全統(tǒng)計,在周圍的游戲玩家中:

知道馬里奧的人 100%

對馬里奧說成超級瑪麗的人:95%

知道馬里奧有其他游戲的人 5%

其實馬里奧不包括同人游戲已經(jīng)出了上百款了,加上HACK ROM【改版】那就更多了。

初次登場開始兩年后,還默默無聞的馬里奧又出現(xiàn)在《大金剛Jr.》中。游戲中馬里奧反串了綁架大金剛的綁匪,是一個使用鞭子操縱著怪物的角色。之后在《網(wǎng)球》和《PUNCH OUT》游戲中還客串過裁判。馬里奧的名字第一次出現(xiàn)在游戲標(biāo)題中是《馬里奧兄弟》這款游戲,而且他的弟弟路易也初次登場。漸漸地,馬里奧的個性也開始顯現(xiàn)出來。而且也是在這個時候,他開始作為游戲的主人公,并開始獨當(dāng)一面了。到了1985年,把馬里奧捧成明星的決定之作《超級馬里奧兄弟》登場。保留了用頭頂、用腳踩等基本動作系統(tǒng)的同時,更是加入了身體變大、發(fā)射火炮等多彩的系統(tǒng)。因此,馬里奧也就成了真正的動作英雄。特別是吃到蘑菇后,身體變大的系統(tǒng),給人強烈的震撼。一時間本作成為廣大玩家的寵兒,馬里奧也終于坐上了明星的寶座。從此馬里奧的動作英雄傳說,便一發(fā)而不可收。續(xù)篇2代、3代,也是一經(jīng)推出,便馬上熱銷。之后,更是進入了馬里奧的顛峰時代。不只是動作游戲,作為醫(yī)生的《馬里奧醫(yī)生》和高爾夫球手《馬里奧高爾夫》,已經(jīng)完全確立了馬里奧在當(dāng)時整個日本游戲界的地位。隨著《超級馬里奧USA》等國際版本的推出,馬里奧的人氣在全世界開始爆發(fā)。1990年在美國進行的調(diào)查顯示,美國人對馬里奧的認知度甚至超過了美國本土的明星米老鼠。一個游戲角色能達到如此出名的地步,就連宮本茂也沒有想到。

我們今天就來看看我們自己能不能寫出這樣一個游戲呢?

來,話不多說,直接開始,gogogo

代碼有點多,有一千多行吧,請耐心觀看,好好看好好學(xué)?。。?/p>

首先就是我們的各種結(jié)構(gòu)體(子彈、硬幣等等)

struct ROLE
{
	int id;
    int x;//橫坐標(biāo)
    int y;//縱坐標(biāo)
    int w;//圖片寬度
    int h;//圖片高度
    int xleft;//水平運動的左界限 
    int xright;//水平運動的右界限
    int turn;//精靈的運動方向
    int jump;//精靈是否跳躍
    int iframe;//加載第幾副精靈圖,這樣就能讓精靈看上去動起來了
};
struct MAP        //儲存地圖的結(jié)構(gòu)體
{
	int id;
	int x;
	int y;
};
struct BULLET      //子彈的結(jié)構(gòu)體
{
	int x;
	int y;
	int turn;
	int iframe;
	int id;
};
struct COINT      //硬幣的結(jié)構(gòu)體
{
	int x;
	int y;
	double iframe;
};
struct ENEMY      //敵人的結(jié)構(gòu)體
{
	int id;
	int x;
	int y;
	int turn;
	int iframe;
};

為了方便大家,我就把函數(shù)全寫在一個類里面啦

class game        //整個游戲只設(shè)置了這一個類
{
private:
	ROLE role;
	MAP map[350];
	BULLET bullet[20];
	COINT coint[50];
	ENEMY enemy[20];
	IMAGE img_mapsky,img_p,img_map,img_ani,img_mapbk,img_home;
	int xmapsky;           //背景天空的起始橫坐標(biāo)
	int xmap;              //地圖的起始坐標(biāo)
	double v0;             //精靈跳躍的初速度             
	double h;              //精靈跳躍的高度
	double t;              //精靈跳躍的時間
	int ibullet;           //第幾顆子彈
	int xbullet;           //子彈的x坐標(biāo)
	int ybullet;           //子彈的y坐標(biāo)
	int get_bullet;        //是否獲得武器,0表示沒有獲得,1表示已獲得
	POINT icoint;          //儲存硬幣的坐標(biāo)
	POINT bomb[20];        //儲存哪些地方爆炸了的坐標(biāo)
	POINT temp;            //臨時坐標(biāo)。儲存哪些地方爆炸了的坐標(biāo)
	double score_frame;    //下面3個double型的變量用于控制各自圖片的幀,以實現(xiàn)動畫的效果。如畫面中的流水
	double bomb_frame;
	double mapbk_frame;
	int win;               //玩家是否過關(guān)
	int pause;             //玩家是否按Esc(暫停鍵)
public:
	game();
	~game();
	void start();          //處理游戲開始的界面,和按暫停鍵后的界面
	void init();           //初始化各項變量
	void move();           //控制主角移動
	void show();           //顯示畫面
	int isdie();           //判斷主角是否已死
	int  GetCommand();	   // 獲取控制命令。參閱easyx
	void left();           //主角向左運動
	void right();          //主角向右運動
	void up();             //主角跳躍
	void init_shoot();     //初始化發(fā)射子彈
	void fall();	       //主角自由落體或者向上跳躍
	int is_l_touch(int id);//主角的左邊是否碰到墻或敵人,以及敵人是否碰到陸地的左邊界
	int is_r_touch(int id);//主角的右邊是否碰到墻或敵人,以及敵人是否碰到陸地的右邊界
	int is_t_touch();      //主角的頭是否碰到墻
	int is_b_touch(int id);//主角是否踩到敵人。
	int is_touch();        //主角是否吃到金幣
	int is_land(ENEMY e);  //敵人是否站在陸地上
	void getbullet();      //獲取子彈
	void shoot();          //發(fā)射子彈
	int eat(BULLET b);     //子彈是否打到敵人或者墻壁
	void end();            //處理游戲結(jié)束
};

接下來就是我們的常見的函數(shù)了——游戲初始化函數(shù)

void game::init()
{
	if(pause==1)
		return;
	role.id=1;
	role.x=X;
	role.y=Y;
	role.w=W;
	role.h=H;
	role.xleft=0;
	role.xright=role.w*6+STEP;
	role.iframe=1;
	role.turn=1;
	role.jump=0;
 
	xmapsky=0;
	xmap=0;
	v0=0;
	h=0;
	t=0;
	ibullet=-1;
	icoint.x=-1;
	icoint.y=-1;
	score_frame=0;
	bomb_frame=1;
	mapbk_frame=1;
	temp.x=-1;
	temp.y=-1;
	xbullet=41*role.w-10;
	ybullet=4*role.h-25;
	get_bullet=0;
	win=0;
	pause=0;
	score=0;
	int i;
	for(i=0;i<350;i++)
    {
		map[i].id=0;
		map[i].x=-1;
		map[i].y=-1;
		if(i<50)
		{
			coint[i].x=-1;
			coint[i].y=-1;
			coint[i].iframe=1;
		}
		if(i<20)
		{
			bullet[i].id=0;
			bullet[i].x=-1;
	        bullet[i].y=-1;
	        bullet[i].iframe=1;
	        bullet[i].turn=-1;  
 
			enemy[i].id=0;
   			enemy[i].x=-1;
	        enemy[i].y=-1;
         	enemy[i].turn=1;
	        enemy[i].iframe=1;
 
			bomb[i].x=-1;
			bomb[i].y=-1;
	 	}
	}
	loadimage(&img_mapsky,"res\\mapsky.bmp",XSIZE,YSIZE*4);
	loadimage(&img_p,"res\\role.bmp");
	loadimage(&img_map,"res\\map.bmp");
	loadimage(&img_ani,"res\\ani.bmp");
	loadimage(&img_mapbk,"res\\mapbk.bmp");
	loadimage(&img_home,"res\\home.bmp",XSIZE,YSIZE*5);
 
    mciSendString("open 背景音樂.mp3 alias mymusic1", NULL, 0, NULL);
	mciSendString("open 子彈.mp3 alias mymusic2", NULL, 0, NULL);
	mciSendString("open 金幣.mp3 alias mymusic3", NULL, 0, NULL);
	mciSendString("open 跳.mp3 alias mymusic4", NULL, 0, NULL);
	mciSendString("open 子彈打到敵人.mp3 alias mymusic5", NULL, 0, NULL);
	mciSendString("open 子彈撞墻.mp3 alias mymusic6", NULL, 0, NULL);
	mciSendString("open 踩敵人.mp3 alias mymusic7", NULL, 0, NULL);
	mciSendString("open 吃到武器.mp3 alias mymusic8", NULL, 0, NULL);	
	mciSendString("open 勝利.mp3 alias mymusic9", NULL, 0, NULL);
	mciSendString("open 死亡1.mp3 alias mymusic10", NULL, 0, NULL);
	mciSendString("open 死亡2.mp3 alias mymusic11", NULL, 0, NULL);
	                                       
	for(i=0;i<300;i++)                 //以下都是編輯地圖
	{
		map[i].id=1;
		map[i].x=i%100*role.w;
		if(i<100)
			map[i].y=9*role.h;
		else if(i>=100&&i<200)
			map[i].y=10*role.h;
		else
			map[i].y=11*role.h;
	}
	map[15].id=1,map[15].x=18*role.w,map[15].y=8*role.h;
	map[115].id=1,map[115].x=19*role.w,map[115].y=8*role.h;
	map[215].id=1,map[215].x=20*role.w,map[215].y=8*role.h;
 
	map[16].id=1,map[16].x=21*role.w,map[16].y=8*role.h;
	map[116].id=1,map[116].x=22*role.w,map[116].y=8*role.h;
	map[216].id=1,map[216].x=23*role.w,map[216].y=8*role.h;
 
	map[17].id=1,map[17].x=24*role.w,map[17].y=8*role.h;
	map[117].id=1,map[117].x=25*role.w,map[117].y=8*role.h;
	map[217].id=1,map[217].x=26*role.w,map[217].y=8*role.h;
 
	map[300].id=2,map[300].x=10*role.w,map[300].y=6*role.h;
	map[301].id=2,map[301].x=11*role.w,map[301].y=6*role.h;
	map[302].id=2,map[302].x=12*role.w,map[302].y=6*role.h;
 
	map[303].id=3,map[303].x=36*role.w,map[303].y=7*role.h;
	map[304].id=3,map[304].x=44*role.w,map[304].y=7*role.h;
 
	map[305].id=2,map[305].x=40*role.w,map[305].y=4*role.h;
	map[306].id=2,map[306].x=41*role.w,map[306].y=4*role.h;
	map[307].id=2,map[307].x=42*role.w,map[307].y=4*role.h;
 
	map[308].id=2,map[308].x=13*role.w,map[308].y=6*role.h;
 
	map[309].id=4,map[309].x=15*role.w,map[309].y=10*role.h;
 
	map[310].id=5,map[310].x=19*role.w,map[310].y=6*role.h;
	map[311].id=5,map[311].x=23*role.w,map[311].y=6*role.h;
	map[312].id=5,map[312].x=32*role.w,map[312].y=7*role.h;
	map[313].id=5,map[313].x=48*role.w,map[313].y=7*role.h;
	map[314].id=5,map[314].x=52*role.w,map[314].y=7*role.h;
	map[315].id=5,map[315].x=56*role.w,map[315].y=7*role.h;
 
	map[316].id=3,map[316].x=80*role.w,map[316].y=7*role.h;
	map[317].id=3,map[317].x=90*role.w,map[317].y=7*role.h;
 
	map[318].id=2,map[318].x=62*role.w,map[318].y=6*role.h;
 
	map[319].id=2,map[319].x=65*role.w,map[319].y=3*role.h;
	map[320].id=2,map[320].x=66*role.w,map[320].y=3*role.h;
	map[321].id=2,map[321].x=67*role.w,map[321].y=3*role.h;
	map[322].id=2,map[322].x=68*role.w,map[322].y=3*role.h;
	map[323].id=2,map[323].x=69*role.w,map[323].y=3*role.h;
 
	map[349].id=6,map[349].x=97*role.w,map[349].y=7*role.h;
 
	for(i=64;i<300;i+=100)
	{
		map[i].id=0;map[i].x=-1;map[i].y=-1;
		map[i+1].id=0;map[i+1].x=-1;map[i+1].y=-1;
		map[i+2].id=0;map[i+2].x=-1;map[i+2].y=-1;
 
		map[i+7].id=0;map[i].x=-1;map[i].y=-1;
		map[i+8].id=0;map[i+1].x=-1;map[i+1].y=-1;
		map[i+9].id=0;map[i+1].x=-1;map[i+1].y=-1;
 
		map[i+11].id=0;map[i].x=-1;map[i].y=-1;
		map[i+12].id=0;map[i+1].x=-1;map[i+1].y=-1;
		map[i+13].id=0;map[i+1].x=-1;map[i+1].y=-1;
	}
	map[64].id=4,map[64].x=64*role.w,map[64].y=10*role.h;
	map[71].id=4,map[71].x=71*role.w,map[71].y=10*role.h;
	map[75].id=4,map[75].x=75*role.w,map[75].y=10*role.h;
 
	enemy[0].id=1;enemy[0].x=6*role.w;enemy[0].y=8*role.h;enemy[0].turn=1;enemy[0].iframe=1;
	enemy[1].id=1;enemy[1].x=8*role.w;enemy[1].y=8*role.h;enemy[1].turn=1;enemy[1].iframe=1;
	enemy[2].id=1;enemy[2].x=27*role.w;enemy[2].y=8*role.h;enemy[2].turn=1;enemy[2].iframe=1;
	enemy[3].id=1;enemy[3].x=29*role.w;enemy[3].y=8*role.h;enemy[3].turn=1;enemy[3].iframe=1;
	enemy[4].id=1;enemy[4].x=31*role.w;enemy[4].y=8*role.h;enemy[4].turn=1;enemy[4].iframe=1;
	enemy[5].id=1;enemy[5].x=33*role.w;enemy[5].y=8*role.h;enemy[5].turn=1;enemy[5].iframe=1;
	enemy[6].id=1;enemy[6].x=35*role.w;enemy[6].y=8*role.h;enemy[6].turn=1;enemy[6].iframe=1;
	enemy[7].id=1;enemy[7].x=40*role.w;enemy[7].y=8*role.h;enemy[7].turn=1;enemy[7].iframe=1;
	enemy[8].id=1;enemy[8].x=82*role.w;enemy[8].y=8*role.h;enemy[8].turn=1;enemy[8].iframe=1;
	enemy[9].id=1;enemy[9].x=65*role.w;enemy[9].y=2*role.h;enemy[9].turn=1;enemy[9].iframe=1;
	enemy[10].id=1;enemy[10].x=69*role.w;enemy[10].y=2*role.h;enemy[10].turn=1;enemy[10].iframe=1;
	enemy[11].id=1;enemy[11].x=85*role.w;enemy[11].y=8*role.h;enemy[11].turn=1;enemy[11].iframe=1;
 
	for(i=0;i<4;i++)
	{
		coint[i].x=(10+i)*role.w;
	    coint[i].y=5*role.h;
 
		coint[i+4].x=(67+i)*role.w;
		coint[i+4].y=8*role.w;
 
		coint[i+8].x=74*role.w;
		coint[i+8].y=(4+i)*role.w;
	}
	for(i=12;i<18;i++)
	{
		coint[i].x=(83-12+i)*role.w;
	    coint[i].y=6*role.h;
 
		coint[i+6].x=(83-12+i)*role.w;
		coint[i+6].y=7*role.w;
	}
}

子彈的移動函數(shù)(別放棄,加油)

void game::move()
{	
	MyTimer tt;
	int c;
	int k=0;                              //控制發(fā)射子彈的頻率和敵人的移動速度
	int n=0;                              //控制發(fā)射子彈的頻率
	while(true)
	{
		tt.Sleep(25);
		t=sqrt(2*HIGH/G)/14;		
		k++;
		if(k==1000)
	    	k=0;
		if(kbhit()&&win==0)
		{
			c=GetCommand();
	    	if(c&CMD_LEFT)
	    		left();
	    	if(c&CMD_RIGHT)
				right();
	    	if((c&CMD_UP)&&role.jump==0)
				up();
			if(c&CMD_ESC)
			{
				pause=1;
				break;
			}
			if(c&CMD_SHOOT&&get_bullet==1)
			{
				if(n==0)
			    {
			    	init_shoot();
			    	n=1;
			    }
				n++;
				if(k%10==0&&n>10)
			    {
			    	init_shoot();
			    }
			}
			else
			    n=0;
		}
		if(-xmap+role.x==97*role.w)
		{
		    mciSendString("stop mymusic1", NULL, 0, NULL);
			mciSendString("play mymusic9", NULL, 0, NULL);
		}
		if(-xmap+role.x>95*role.w)
		{
			
            win=1;
			role.x+=STEP;
			if(role.x-STEP>XSIZE)
				break;
		}
		if(is_b_touch(1)==0)
			role.jump=1;
		if(role.jump==1)
			fall();
		if(isdie()==1)
		{
			mciSendString("stop mymusic1", NULL, 0, NULL);
			mciSendString("play mymusic11", NULL, 0, NULL);
			life--;
			return;	
		}
		if(k%2==0)               //敵人的運動
		{
	    	for(int i=0;i<20;i++)
	    	{
		    	if(enemy[i].id==1)
		    	{
		            if(is_land(enemy[i])==1)
		            {
		    	        if(enemy[i].turn==1)
			    	        enemy[i].x+=STEP;
			            else
				            enemy[i].x-=STEP;
			    	}
		            if(is_land(enemy[i])==0||is_l_touch(3)==1||is_r_touch(3)==1)
		            {
		            	if(enemy[i].turn==1)
		            		enemy[i].x-=STEP;
		            	else
		            		enemy[i].x+=STEP;
		            	enemy[i].turn*=-1;
		            }
				    enemy[i].iframe*=-1;
			    }
	    	}
		}
		int boom=0;
		if(is_b_touch(2)==1)                     //如果主角“踩到”敵人
			boom=1;
		getbullet();                             //獲取子彈
		if(get_bullet==1)
			shoot();
 
		BeginBatchDraw();
		show();
		FlushBatchDraw();
 
		if((is_l_touch(2)==1||is_r_touch(2)==1))
		{
			mciSendString("stop mymusic1", NULL, 0, NULL);
			mciSendString("play mymusic10", NULL, 0, NULL);
			life--;
			pause=0;
			putimage(role.x,role.y,role.w,role.h,&img_p,2*role.w,role.h,SRCAND);
	        putimage(role.x,role.y,role.w,role.h,&img_p,2*role.w,0,SRCPAINT);
		    return;
		}
	}
}

游戲的顯示函數(shù)(人物、子彈、敵人、分數(shù)等等顯示),bug改了一大推,累的半死,希望同學(xué)能吸取教訓(xùn),別學(xué)我

void game::show()
{
	if(xmapsky==-XSIZE)
		xmapsky=0;
    putimage(xmapsky,0,&img_mapsky);     //顯示背景
	putimage(XSIZE+xmapsky,0,&img_mapsky);
 
	if(is_touch()==1)
		score_frame=1;
	if(score_frame!=0)                  //碰到硬幣,顯示得分
	{		
		switch((int)score_frame)
		{
		case 1:
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,0,11*role.h,SRCAND);
		    putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,0,10*role.h,SRCPAINT);
			break;
		case 2:
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,role.w,11*role.h,SRCAND);
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,role.w,10*role.h,SRCPAINT);
			break;
		case 3:
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,2*role.w,11*role.h,SRCAND);
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,2*role.w,10*role.h,SRCPAINT);
			break;
		case 4:
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,3*role.w,11*role.h,SRCAND);
			putimage(xmap+icoint.x,icoint.y,role.w,role.h,&img_ani,3*role.w,10*role.h,SRCPAINT);
			break;
		default:
			break;
		}	
		score_frame+=0.2;
	    if(score_frame==5)
		    score_frame=0;
	}
	int i;
	for(i=0;i<350;i++)             //顯示地圖,天空上的地圖和硬幣
	{
		if(map[i].id==1)
		{
			putimage(xmap+map[i].x,map[i].y,role.w,role.h,&img_map,0,0);
		}
		else if(map[i].id==2)
		{
			putimage(xmap+map[i].x,map[i].y,role.w,role.h,&img_map,0,role.h);
		}
		else if(map[i].id==3)
		{
			putimage(xmap+map[i].x,map[i].y,2*role.w,2*role.h,&img_map,0,9*role.h);
		}
		else
		{
		    if(map[i].id==4)
		    {
		    	switch((int)mapbk_frame)
		    	{
		    	case 1:
		    		putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,10*role.h,SRCAND);
		    	    putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,8*role.h,SRCPAINT);
		    		break;
		    	case 2:
		   	     	putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,10*role.h,SRCAND);
		     		putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,8*role.h,SRCPAINT);
			    	break;
	    		default:
	    			break;
	    		}	
		    }
			else if(map[i].id==5)
		    {
		    	switch((int)mapbk_frame)
		    	{
		    	case 1:
		    		putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,2*role.h,SRCAND);
		    	    putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,0,SRCPAINT);
		    		break;
		    	case 2:
		   	     	putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,2*role.h,SRCAND);
		     		putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,0,SRCPAINT);
			    	break;
	    		default:
	    			break;
	    		}	
		    }
			else if(map[i].id==6)
			{
				switch((int)mapbk_frame)
		    	{
		    	case 1:
		    		putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,6*role.h,SRCAND);
					putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,0,4*role.h,SRCPAINT);
		    		break;
		    	case 2:
		   	     	putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,6*role.h,SRCAND);
					putimage(xmap+map[i].x,map[i].y,3*role.w,2*role.h,&img_mapbk,3*role.w,4*role.h,SRCPAINT);
			    	break;
	    		default:
	    			break;
	    		}	
			}
			mapbk_frame+=0.003;
	        if(mapbk_frame>2.9)
	   		{
	   			mapbk_frame=1;
	   		}
		}
		if(i<50)
		{
			if(coint[i].x!=-1||coint[i].y!=-1)
			{
				switch((int)coint[i].iframe)
				{
				case 1:
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,0,9*role.h,SRCAND);
				    putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,0,8*role.h,SRCPAINT);
					break;
				case 2:
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,role.w,9*role.h,SRCAND);
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,role.w,8*role.h,SRCPAINT);
					break;
				case 3:
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,2*role.w,9*role.h,SRCAND);
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,2*role.w,8*role.h,SRCPAINT);
					break;
				case 4:
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,3*role.w,9*role.h,SRCAND);
					putimage(xmap+coint[i].x,coint[i].y,role.w,role.h,&img_ani,3*role.w,8*role.h,SRCPAINT);
					break;
				default:
					break;
				}	
				coint[i].iframe+=0.125;
			    if(coint[i].iframe==5)
				    coint[i].iframe=1;
			}
		}
	}
	if(get_bullet==0)
	{
 
		switch((int)mapbk_frame)
	 	{
		    case 1:
		   		putimage(xmap+xbullet,ybullet,52,25,&img_ani,0,12*role.h+25,SRCAND);
                putimage(xmap+xbullet,ybullet,52,25,&img_ani,0,12*role.h,SRCPAINT);
		    	break;
		    case 2:
     	     	putimage(xmap+xbullet,ybullet,52,25,&img_ani,52,12*role.h+25,SRCAND);
                putimage(xmap+xbullet,ybullet,52,25,&img_ani,52,12*role.h,SRCPAINT);
			   	break;
	    	default:
	    	    break;
	  	}	
 
	}
	for(i=0;i<20;i++)             //顯示子彈
	{
		if(get_bullet==1)
		{
		    if(bullet[i].id==1)
	        {
	            if(bullet[i].iframe==1)
    	        {
	            	putimage(bullet[i].x,bullet[i].y,role.w,role.h,&img_ani,0,3*role.h,SRCAND);
    		        putimage(bullet[i].x,bullet[i].y,role.w,role.h,&img_ani,0,2*role.h,SRCPAINT);
	            }
    	        else
    	        {
    	        	putimage(bullet[i].x,bullet[i].y,role.w,role.h,&img_ani,role.w,3*role.h,SRCAND);
    	        	putimage(bullet[i].x,bullet[i].y,role.w,role.h,&img_ani,role.w,2*role.h,SRCPAINT);
        	    }	
            }
		}
		if(enemy[i].id==1)
		{
	    	if(enemy[i].iframe==1)                           //顯示敵人
	        { 
		        putimage(xmap+enemy[i].x,enemy[i].y,role.w,role.h,&img_ani,0,role.h,SRCAND);
    	        putimage(xmap+enemy[i].x,enemy[i].y,role.w,role.h,&img_ani,0,0,SRCPAINT);
	        }
	        else
	        {
	        	putimage(xmap+enemy[i].x,enemy[i].y,role.w,role.h,&img_ani,role.w,role.h,SRCAND);
	        	putimage(xmap+enemy[i].x,enemy[i].y,role.w,role.h,&img_ani,role.w,0,SRCPAINT);
	        }
	        
		}
		if(bomb[i].x!=-1||bomb[i].y!=-1)
		{
			switch((int)bomb_frame)
			{
			case 1:
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,0,6*role.h,SRCAND);
			    putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,0,4*role.h,SRCPAINT);
				break;
			case 2:
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,2*role.w,6*role.h,SRCAND);
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,2*role.w,4*role.h,SRCPAINT);
				break;
			case 3:
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,4*role.w,6*role.h,SRCAND);
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,4*role.w,4*role.h,SRCPAINT);
				break;
			case 4:
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,6*role.w,6*role.h,SRCAND);
				putimage(xmap+bomb[i].x-role.w/2,bomb[i].y-role.h/2,2*role.w,2*role.h,&img_ani,6*role.w,4*role.h,SRCPAINT);
				break;
			default:
				break;
			}	
			bomb_frame+=0.25;
		    if(bomb_frame==5)
			{
				bomb[i].x=-1;
			    bomb[i].y=-1;
				bomb_frame=1;
			}
		}
	}
	int n=score;
	char s1[20]="當(dāng)前得分:";
	char s2[10];
	itoa(n,s2,10);
	RECT r1={10,10,110,40};
	RECT r2={110,10,150,40};
	setfont(20, 0,"宋體");
	drawtext(s1, &r1, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	drawtext(s2, &r2, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	if(role.iframe==1)                           //顯示主角
	{
		if(role.turn==1)
		{
		    putimage(role.x,role.y,role.w,role.h,&img_p,0,role.h,SRCAND);
    	    putimage(role.x,role.y,role.w,role.h,&img_p,0,0,SRCPAINT);
		}
		else
		{
			putimage(role.x,role.y,role.w,role.h,&img_p,4*role.w,role.h,SRCAND);
    	    putimage(role.x,role.y,role.w,role.h,&img_p,4*role.w,0,SRCPAINT);
		}
	}
	else
	{
		if(role.turn==1)
		{
			putimage(role.x,role.y,role.w,role.h,&img_p,role.w,role.h,SRCAND);
    	    putimage(role.x,role.y,role.w,role.h,&img_p,role.w,0,SRCPAINT);
		}
		else
		{
			putimage(role.x,role.y,role.w,role.h,&img_p,3*role.w,role.h,SRCAND);
    	    putimage(role.x,role.y,role.w,role.h,&img_p,3*role.w,0,SRCPAINT);
		}
	}
}  

馬里奧的碰撞檢測,這里當(dāng)時寫的時候,想了半天的邏輯

int game::is_l_touch(int id)
{
	int x,y;
	int i;
	if(id==1)                                    //id==1表示主角是否碰到id為1的地圖,及游戲中黃色的地圖
	{
    	x=-xmap+role.x;
    	y=role.y;
    	for(i=0;i<350;i++)
    	{
    		if(map[i].id!=0&&map[i].id<4)
    		{
    			POINT m[2];
 
			    m[0].x=map[i].x;
			    m[0].y=map[i].y;
 
		    	m[1].x=map[i].x+role.w;
		    	m[1].y=map[i].y;
 
				if(map[i].id==3)
				{
					if(((y-m[1].y)/role.h==0||(y-m[1].y-role.h)/role.h==0)&&x>m[1].x&&x<m[1].x+role.w)
			    	    return 1;
				}
				else
				{
					if((y-m[1].y)/role.h==0&&x>m[0].x&&x<m[1].x)
			    	    return 1;
				}
		    }
	    }
	    return 0;
	}
   	else if(id==2)                                 //id==2表示主角是否碰到敵人的左邊
   	{
        x=-xmap+role.x;
       	y=role.y;
       	for(i=0;i<20;i++)
		{
        	if(enemy[i].id!=0)
        	{
		    	POINT m[2];  
 
	    		m[0].x=enemy[i].x;
	    		m[0].y=enemy[i].y;
 
	    	   	m[1].x=enemy[i].x+role.w;
		    	m[1].y=enemy[i].y;
 
		    	if((y-m[1].y)/role.h==0&&x>m[0].x&&x<m[1].x)  		
	    			return 1;
			}
		}
	    return 0;
	}
	else                                        //id==3表示敵人是否碰到地圖的左邊
	{
		int j;
		for(j=0;j<20;j++)
		{
			if(enemy[j].id!=0)
			{
    	        x=enemy[j].x;
    	        y=enemy[j].y;
			
    	        for(i=0;i<350;i++)
		        {
            		if(map[i].id!=0&&map[i].id<4)
            		{
            			POINT m[2];
     
			            m[0].x=map[i].x;
	        		    m[0].y=map[i].y;
 
		            	m[1].x=map[i].x+role.w;
		            	m[1].y=map[i].y;
 
			         	if(map[i].id==3)
			           	{
			        		if(((y-m[1].y)/role.h==0||(y-m[1].y-role.h)/role.h==0)&&x>m[1].x&&x<m[1].x+role.w)
			    	            return 1;
		         		}   
			        	else
			        	{
			        		if((y-m[1].y)/role.h==0&&x>m[0].x&&x<m[1].x)
			    	            return 1;
				        }   
					}
				}
			}
		}
		return 0;
	}
}
int game::is_r_touch(int id)
{
	int x,y;
	int i;
	if(id==1)
	{    
	    x=-xmap+role.x+role.w;
	    y=role.y;
 
	    for(i=0;i<350;i++)
    	{
	    	if(map[i].id!=0&&map[i].id<4)
		    {
			    POINT m[2];
 
    			m[0].x=map[i].x;
    			m[0].y=map[i].y;
 
    			m[1].x=map[i].x+role.w;
    			m[1].y=map[i].y;
 
				if(map[i].id==3)
				{
					if(((y-m[0].y)/role.h==0||(y-m[0].y-role.h)/role.h==0)&&x>m[0].x&&x<m[1].x)
			    	    return 1;
				}
				else
				{
					if((y-m[0].y)/role.h==0&&x>m[0].x&&x<m[1].x)
		    		    return 1;
				}
		    }
	    }
	    return 0;
	}
	else if(id==2)
	{
	    x=-xmap+role.x+role.w;
	    y=role.y;
 
	    for(i=0;i<20;i++)
	    {
		    if(enemy[i].id!=0)
		    {
		    	POINT m[2];
 
			    m[0].x=enemy[i].x;
		    	m[0].y=enemy[i].y;
 
    			m[1].x=enemy[i].x+role.w;
    			m[1].y=enemy[i].y;
 
	    		if((y-m[0].y)/role.h==0&&x>m[0].x&&x<m[1].x)
		    		return 1;
	    	}
	    }
	    return 0;
	}
	else
	{
		int j;
		for(j=0;j<20;j++)
		{
			if(enemy[j].id!=0)
			{
			    x=enemy[j].x+role.w;
	            y=enemy[j].y;
			
	            for(i=0;i<350;i++)
		        {
	            	if(map[i].id!=0&&map[i].id<4)
        		    {
		        	    POINT m[2];
 
            			m[0].x=map[i].x;
            			m[0].y=map[i].y;
 
            			m[1].x=map[i].x+role.w;
    	        		m[1].y=map[i].y;
 
			        	if(map[i].id==3)
			        	{
				        	if(((y-m[0].y)/role.h==0||(y-m[0].y-role.h)/role.h==0)&&x>m[0].x&&x<m[1].x)
			    	            return 1;
				        }
				        else
				        {
					        if((y-m[0].y)/role.h==0&&x>m[0].x&&x<m[1].x)
		    		            return 1;
				        }
					}
	            }
			}
		}
		return 0;
	}
}
int game::is_t_touch()
{
	int x,y;
	x=-xmap+role.x;
	y=role.y;
 
	for(int i=0;i<350;i++)
	{
		if(map[i].id!=0&&map[i].id<4)
		{
			POINT m[2];
 
			m[0].x=map[i].x;
			m[0].y=map[i].y;
 
			m[1].x=map[i].x;
			m[1].y=map[i].y+role.h;
 
			if((x-m[1].x)/role.w==0&&y>m[0].y&&y<m[1].y)
				return 1;
		}
	}
	return 0;
}
int game::is_b_touch(int id)
{
	if(id==1)
	{
	    int x,y;
	    x=-xmap+role.x;
    	y=role.y+role.h;
 
	    for(int i=0;i<350;i++)
	    {
    		if(map[i].id!=0&&map[i].id<4)
    		{
    			POINT m[2];  
 
    			m[0].x=map[i].x;
	    		m[0].y=map[i].y;
 
	    		m[1].x=map[i].x; 
		    	m[1].y=map[i].y+role.h;
 
				if(map[i].id==3)
				{
					if(((x-m[0].x)/role.w==0||(x+role.w-m[0].x-2*role.w)/role.w==0)&&y>=m[0].y&&y<m[1].y)
			    	    return 1;
				}
				else
				{
					if((x-m[0].x)/role.w==0&&y>=m[0].y&&y<m[1].y)
			    	    return 1;
				}
			}
		}
	    return 0;
	}
	else if(id==2)
	{
		int x,y;
	    x=-xmap+role.x;
	    y=role.y+role.h;
 
    	for(int i=0;i<20;i++)
    	{
    		if(enemy[i].id!=0)
    		{
    			POINT m[2];
 
	    		m[0].x=enemy[i].x;
	    		m[0].y=enemy[i].y;
 
		    	m[1].x=enemy[i].x;
		    	m[1].y=enemy[i].y+role.h;
 
		    	if((x-m[0].x)/role.w==0&&y>m[0].y&&y<m[1].y)
				{
			    	mciSendString("play mymusic7 from 0", NULL, 0, NULL);
					score+=10;
					bomb[i].x=enemy[i].x;
		        	bomb[i].y=enemy[i].y;
					enemy[i].id=0;
			        enemy[i].iframe=-1;
			        enemy[i].turn=1;
		        	enemy[i].x=-1;
		        	enemy[i].y=-1;
		    		return 1;
				}
		    }
		}
	    return 0;
	}
	return 0;
}
int game::is_touch()
{
	int i,j;
	POINT r[2];
	r[0].x=-xmap+role.x;
	r[0].y=role.y;
	r[1].x=-xmap+role.x+role.w;
	r[1].y=role.y+role.h;
	for(i=0;i<50;i++)
	{
		if(coint[i].x!=-1||coint[i].y!=-1)
		{
			POINT c[4];
 
			c[0].x=coint[i].x;
			c[0].y=coint[i].y;
 
			c[1].x=coint[i].x+role.w;
			c[1].y=coint[i].y;
 
			c[2].x=coint[i].x;
			c[2].y=coint[i].y+role.h;
 
			c[3].x=coint[i].x+role.w;
			c[3].y=coint[i].y+role.h;
 
		    for(j=0;j<4;j++)
			{
				if(c[j].x>=r[0].x&&c[j].y>=r[0].y&&c[j].x<=r[1].x&&c[j].y<=r[1].y)
				{
			    	mciSendString("play mymusic3 from 0", NULL, 0, NULL);
					score+=20;
					icoint.x=coint[i].x;
					icoint.y=coint[i].y;
 
					coint[i].x=-1;
					coint[i].y=-1;
					coint[i].iframe=1;
 
					return 1;
				}
			}
		}
	}
	return 0;
}
int game::is_land(ENEMY e)
{
	POINT r[2];
	r[0].x=e.x;
	r[0].y=e.y+role.h;
 
	r[1].x=e.x+role.h;
	r[1].y=e.y+role.h;
 
	for(int i=0;i<350;i++)
	{
		if(map[i].id!=0&&map[i].id<4)
		{
			POINT m[3];
 
			m[0].x=map[i].x;
			m[0].y=map[i].y;
			
			m[1].x=map[i].x+role.w;
			m[1].y=map[i].y;
 
			m[2].x=map[i].x;
			m[2].y=map[i].y+role.h;
 
			if(e.turn==1)
			{
				if((r[1].x-m[0].x)/role.w==0&&r[1].y>=m[0].y&&r[1].y<m[2].y)
			    	return 1;
			}
			else
			{
				if((r[0].x-m[1].x)/role.w==0&&r[0].y>=m[0].y&&r[0].y<m[2].y)
			    	return 1;
			}
		}
	}
	return 0;
}

最后的游戲結(jié)束函數(shù),寫到這里的時候感受到了巨大的成就感

void game::end()
{
	MyTimer tt;
	EndBatchDraw();
	if(isdie()==1||win==1)
		pause=0;
	if(pause==1)
		return;
	if(win==1)
		tt.Sleep(5000);
	else
		tt.Sleep(2700);
	mciSendString("close all", NULL, 0, NULL);	
	tt.Sleep(1000);
	
	if(win==1)
	{
		pause=0;
		score=0;
		life=0;
		mciSendString("open 通關(guān).mp3 alias mymusic13", NULL, 0, NULL);
	    mciSendString("play mymusic13", NULL, 0, NULL);
		putimage(0,-3*YSIZE,&img_home);
		tt.Sleep(7000);
		mciSendString("close mymusic13", NULL, 0, NULL);
	}
	else
	{
		score=0;
		if(life==0)
		{
			mciSendString("open 游戲結(jié)束.mp3 alias mymusic12", NULL, 0, NULL);
	        mciSendString("play mymusic12", NULL, 0, NULL);
			putimage(0,-YSIZE,&img_home);
		    tt.Sleep(5500);
	        mciSendString("close mymusic12", NULL, 0, NULL);
		}
		else
		{
			cleardevice();
			outtextxy(XSIZE/2-43,YSIZE/3,"生命還剩下:");
			if(life==1)
				outtextxy(XSIZE/2,YSIZE/2-20,"1");
			else if(life==2)
				outtextxy(XSIZE/2,YSIZE/2-20,"2");
			tt.Sleep(2000);
		}
	}
	cleardevice();
}

最后用主函數(shù)進行調(diào)用

void main()
{
	game g;
	while(true)
	{
		g.start();
	    g.init();
		mciSendString("play mymusic1 repeat", NULL, 0, NULL);
	    g.show();
        g.move();
	    g.end();
	}
}

用時一個星期,終于把這個難啃的骨頭咽下去了,寫的時候時不時也會想起自己的童年,那真是一段不能忘記的時光,希望可以讓大家從中感受到編程的快樂,也希望大家可以給UP主一個關(guān)注,非常感謝大家了?。?!

到此這篇關(guān)于C語言 90后懷舊游戲超級瑪麗的實現(xiàn)流程 的文章就介紹到這了,更多相關(guān)C語言 超級瑪麗內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • C++實現(xiàn)簡單版圖書管理系統(tǒng)

    C++實現(xiàn)簡單版圖書管理系統(tǒng)

    這篇文章主要為大家詳細介紹了C++實現(xiàn)簡單版圖書管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-06-06
  • C語言各種操作符透徹理解上篇

    C語言各種操作符透徹理解上篇

    C 語言提供了豐富的操作符,有:算術(shù)操作符,移位操作符,位操作符,賦值操作符。讓我們通讀本篇來詳細了解吧
    2022-02-02
  • C++實現(xiàn)走迷宮小游戲

    C++實現(xiàn)走迷宮小游戲

    這篇文章主要為大家詳細介紹了C++實現(xiàn)走迷宮小游戲,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03
  • C++實現(xiàn)關(guān)系與關(guān)系矩陣的代碼詳解

    C++實現(xiàn)關(guān)系與關(guān)系矩陣的代碼詳解

    這篇文章主要介紹了C++實現(xiàn)關(guān)系與關(guān)系矩陣,功能實現(xiàn)包括關(guān)系的矩陣表示,關(guān)系的性質(zhì)判斷及關(guān)系的合成,本文結(jié)合示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • Mygui中文換行問題解決方案

    Mygui中文換行問題解決方案

    相信大家解決了中文輸入后一定會遇到如何解決中文輸入的問題,中文輸入換行問題是很多gui框架都存在的一個問題,需要的朋友可以了解下
    2012-11-11
  • 詳解C語言的void*空指針

    詳解C語言的void*空指針

    這篇文章主要為大家詳細介紹了C語言的void*空指針,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-03-03
  • C語言中的柔性數(shù)組你了解嗎

    C語言中的柔性數(shù)組你了解嗎

    這篇文章主要為大家詳細介紹了C99中的新語法——柔性數(shù)組的使用以及優(yōu)缺點,文中的示例代碼講解詳細,具有一定的學(xué)習(xí)價值,感興趣的可以了解一下
    2023-04-04
  • 變量定義與聲明的區(qū)別詳細解析

    變量定義與聲明的區(qū)別詳細解析

    外部變量(全局變量)的"定義"與外部變量的"聲明"是不相同的,外部變量的定義只能有一次,它的位置是在所有函數(shù)之外,而同一個文件中的外部變量聲明可以是多次的,它可以在函數(shù)之內(nèi)(哪個函數(shù)要用就在那個函數(shù)中聲明)也可以在函數(shù)之外(在外部變量的定義點之前)
    2013-09-09
  • C++中拷貝構(gòu)造函數(shù)的使用

    C++中拷貝構(gòu)造函數(shù)的使用

    大家好,本篇文章主要講的是C++中拷貝構(gòu)造函數(shù)的使用,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-02-02
  • C語言實現(xiàn)掃雷小游戲(適合初學(xué)者)

    C語言實現(xiàn)掃雷小游戲(適合初學(xué)者)

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)掃雷小游戲,適合初學(xué)者練習(xí),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-03-03

最新評論