憤怒的小豬設(shè)計(jì)_第1頁
憤怒的小豬設(shè)計(jì)_第2頁
憤怒的小豬設(shè)計(jì)_第3頁
憤怒的小豬設(shè)計(jì)_第4頁
憤怒的小豬設(shè)計(jì)_第5頁
已閱讀5頁,還剩116頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

目錄

1引言.............................................................1

1.1背景..........................................................1

1.2參考資料......................................................1

2需求分析.........................................................1

2.1需求分析......................................................1

2.1.1軟件需求.....................................錯誤!未定義書簽。

2.1.2軟件功能.....................................錯誤!未定義書簽。

2.2運(yùn)行環(huán)境.....................................................2

3系統(tǒng)設(shè)計(jì).........................................................3

3.1功能需求描述..................................................3

3.2軟件結(jié)構(gòu)......................................................3

3.3程序模塊劃分..................................................5

4組員分工及時(shí)間安排..............................................10

4.1組員分工.....................................................12

4.2時(shí)間安排.....................................................13

5系統(tǒng)詳細(xì)設(shè)計(jì)....................................................14

5.1主要數(shù)據(jù)結(jié)構(gòu)說明.............................................14

5.2主要函數(shù)說明.................................................15

5.3主要算法說明.................................................21

6總結(jié)............................................................26

6.1組員A總結(jié)...................................................26

6.2組員B總結(jié)...................................................26

7源代碼清單......................................................27

7.1XXX.C文件...................................................27

7.2XXX.H文件...................................................27

C語言程序設(shè)計(jì)報(bào)告

1引言

1.1背景

交通模擬導(dǎo)航系統(tǒng)是基于C語言開發(fā)的類似GPS汽車導(dǎo)航的系統(tǒng)。

憤怒的小鳥(AngryBirds)這款游戲的故事相當(dāng)有趣,為了報(bào)復(fù)偷走鳥蛋的肥豬們,鳥兒以自

己的身體為武器,仿佛炮彈一樣去攻擊肥豬們的堡壘。游戲是十分卡通的2D畫面,看著憤怒的紅色

小鳥,奮不顧身的往綠色的肥豬的堡壘砸去,那種奇妙的感覺還真是令人感到很歡樂。而游戲的配

樂同樣充滿了歡樂的感覺,輕松的節(jié)奏,歡快的風(fēng)格。不過在進(jìn)行游戲的時(shí)候卻沒有這樣的音樂,

有點(diǎn)可惜。但是將鳥兒們彈射出去時(shí),鳥兒的叫聲倒是給人很好笑的感覺。

因?yàn)閼嵟男▲B具有高度的可玩性,所以受到了大量玩家的熱愛,但是因?yàn)樗且豢钌虡I(yè)軟件,

正版需要付費(fèi)才可以玩到,對于學(xué)生而言是一筆不小的費(fèi)用,因此我們可以自己開發(fā)出一款與之相

似的非商業(yè)游戲來滿足我們興趣。

并且憤怒的小豬在編程過程中,可以很好的鍛煉編程者的圖形動畫制作能力,可以有效的提高

編程者對DOS下圖形編輯能力的了解,為日后制作其他圖形軟件打下較好的基礎(chǔ)。

1.2參考資料

1.王士元C高級實(shí)用程序設(shè)計(jì).北京:清華大學(xué)出版社.1996

2.周純杰,劉正林等標(biāo)準(zhǔn)C語言程序及應(yīng)用.武漢:華中科技大學(xué)出版社.2005

3.C語言高級編程技術(shù).

4.浦濱C游戲編程從入門到精通

5.李軍最新VESASVGA圖形圖像編程秘技

2需求分析

2.1需求分析

憤怒的小豬作為一款游戲,所以是一款以面向?qū)ο鬄橹鞯某绦?,它必須要有良好的人機(jī)交互模式,豐

富的關(guān)卡,并且要對加入小豬不同的特殊效果,只有這樣才可以保證高度的可玩性,并且為了體現(xiàn)游戲的

真實(shí)性與可玩性,小豬、小鳥、箱子都應(yīng)大致符合物理定律,最后,如果時(shí)間充裕應(yīng)盡量擴(kuò)展游戲的功能,

以增加游戲的趣味性。

憤怒的小豬的四個主要關(guān)卡為:

1.第一關(guān)

◎本關(guān)中小豬為普通小豬,無特殊能力。

◎本關(guān)卡中共有6個箱子,2只小鳥。

◎小豬的數(shù)量為4只

I

C語言程序設(shè)計(jì)報(bào)告

2.第二關(guān)

◎本關(guān)中小豬為頭盔小豬,特殊能力為:在飛行中,按下鼠標(biāo)按鍵后,它的速度會加為兩倍,使得

更快的接近目標(biāo)。

◎本關(guān)卡中共有6個箱子,3只小鳥。

◎小豬的數(shù)量為4只。

3.第三關(guān)

◎本關(guān)中小豬為國王小豬,特殊能力為:在飛行中,按下鼠標(biāo)按鍵后,它的運(yùn)動方向?qū)淖儯?/p>

得以較好的角度擊中目標(biāo)。

◎本關(guān)卡中共有9個箱子,3只小鳥。

◎小豬的數(shù)量為4只。

4.第四關(guān)

◎本關(guān)中小豬為老豬,特殊能力為:在飛行中,按下鼠標(biāo)按鍵后,或在它消失時(shí),它將會發(fā)生爆炸,

炸毀一定范圍的目標(biāo)。

◎本關(guān)卡中共有9個箱子,3只小鳥。

◎小豬的數(shù)量為4只

另外,憤怒的小豬的兩個小游戲?yàn)椋?/p>

1.自設(shè)地圖

◎通過編輯界面,編輯自定義地圖。

◎通過自定義游戲按鍵,進(jìn)入自定義關(guān)卡。

◎本模式中共有6個箱子,2只小鳥可以進(jìn)行拖動編輯。

◎小豬的數(shù)量為4只

2.對戰(zhàn)模式

◎本模式中兩位玩家分別扮演紅方與藍(lán)方。

◎游戲的操作為輪流操作。

◎兩位玩家分別拖動自己的小豬攻擊對方小鳥,先消滅對方所有小鳥者獲勝。

◎本關(guān)卡中每一方有9個箱子,3只小鳥。

另外,游戲中將實(shí)現(xiàn)排行榜功能,以激勵玩家多多游戲,刷新紀(jì)錄,增加游戲的挑戰(zhàn)性。

2.2運(yùn)行環(huán)境

憤怒的小豬是一款XP及win732位系統(tǒng)下的游戲,系統(tǒng)的開發(fā)基于C語言,其設(shè)計(jì)環(huán)境要求,是在

DOS環(huán)境下用C語言編程實(shí)現(xiàn),使用TC或BC開發(fā)軟件,因此,憤怒的小豬能夠在絕大多數(shù)計(jì)算機(jī)系統(tǒng)

上運(yùn)行,包括常見的windowsXP操作系統(tǒng)及windows732位機(jī)上運(yùn)行,但是由于BC在64位的windows

7下無法運(yùn)行,且BC或TC在windows7下不能較好地解決全屏問題,因而,推薦在windowsXP的環(huán)境

下測試運(yùn)行此交通模擬導(dǎo)航系統(tǒng)。

本軟件設(shè)計(jì)中加入了鼠標(biāo),因此操作過程必須依賴鼠標(biāo)才能實(shí)現(xiàn)所有功能,具有良好的人機(jī)交互性。

本軟件主要操作是通過鼠標(biāo)選擇我們給出的漢化界面選項(xiàng)。輸出信息也將采用漢化的界面展示給玩家。

C語言程序設(shè)計(jì)報(bào)告

3系統(tǒng)設(shè)計(jì)

3.1功能需求描述

運(yùn)行程序,先出現(xiàn)歡迎動畫,按任意鍵可退出歡迎動畫。

進(jìn)入主界面,可以有開始游戲、排行榜、幫助、退出以及2個小游戲的按鍵,可以進(jìn)入相應(yīng)的界面。

在點(diǎn)擊開始游戲后,將會進(jìn)入關(guān)卡的選擇界面,在選擇界面中可以通過各關(guān)卡按鍵到達(dá)已解鎖的游

戲關(guān)卡,通過重置按鍵重置關(guān)卡,并且在此頁面可以查看相應(yīng)關(guān)卡的最高分;

在點(diǎn)擊排行榜后,將會進(jìn)入排行榜界面,在排行榜界面中可以查看各關(guān)卡的分?jǐn)?shù)排行情況;

在點(diǎn)擊退出后,將會退出游戲;

在點(diǎn)擊對戰(zhàn)模式后,將會進(jìn)入對戰(zhàn)模式界面,開始對戰(zhàn)模式游戲;

在點(diǎn)擊自設(shè)關(guān)卡后,將會進(jìn)入自設(shè)關(guān)卡界面,開始自設(shè)關(guān)卡游戲。

3.2軟件結(jié)構(gòu)(流程圖)

C語言程序設(shè)計(jì)報(bào)告

C語言程序設(shè)計(jì)報(bào)告

3.3功能和操作簡介

主菜單

有6個按鈕,可通過按鈕分別為開始游戲,查看幫助,查看排行榜,進(jìn)入對戰(zhàn)模式,進(jìn)入自設(shè)地圖,退出

游戲。

排行榜

在這個界面之中,可以點(diǎn)擊Ievell;level2,level3jevel4可以查看相應(yīng)關(guān)卡的分?jǐn)?shù)記錄與排行,重置按鍵可以

重置排行榜界面是分?jǐn)?shù)清零,單擊主菜單按鍵可以返回主菜單。

C語言程序設(shè)計(jì)報(bào)告

Highscore

關(guān)卡選擇

在這個界面之中,己解鎖的關(guān)卡可以點(diǎn)擊進(jìn)入游戲,未解鎖的游戲點(diǎn)擊后無效,可以點(diǎn)擊關(guān)卡區(qū)域可以進(jìn)

入相應(yīng)的關(guān)卡,可以查看相應(yīng)關(guān)卡的最高分?jǐn)?shù),重置按鍵可以重置關(guān)卡的解鎖信息,單擊返回按鍵可以返

回主菜單。

C語言程序設(shè)計(jì)報(bào)告

幫助界面

介紹游戲的基本操作

自設(shè)游戲界面

通過該界面選擇界面的編輯與進(jìn)入自定義游戲。

C語言程序設(shè)計(jì)報(bào)告

編輯界面

可以通過鼠標(biāo)拖動小鳥與箱子確定其初始位置,編輯完成后點(diǎn)擊左上角完成編輯。

自定義界面

根據(jù)編輯界面時(shí)確定的箱子與鳥的初始位置初始化游戲界面,其操作與正常游戲關(guān)卡相同,但是給關(guān)卡完

成之后,得到的分?jǐn)?shù)將不會被記錄。

C語言程序設(shè)計(jì)報(bào)告

游戲界面

游戲界面的左上角可以暫停游戲,左二按鈕可以重新開始游戲,從右上角可以查看游戲中所得的分?jǐn)?shù),中

間的綠豬代表剩余的機(jī)會,在點(diǎn)擊了暫停按鈕之后,可以通過下拉菜單重新開始游戲,回到關(guān)卡選擇,回

到主菜單。

對戰(zhàn)界面

對戰(zhàn)界面本模式中兩位玩家分別扮演紅方與藍(lán)方,游戲的操作為輪流操作,兩位玩家分別拖動自己

的小豬攻擊對方小鳥,先消滅對方所有小鳥者獲勝。

C語言程序設(shè)計(jì)報(bào)告

3.4程序模塊劃分

1.界面模塊

a.游戲模塊

b.菜單模塊(包括主菜單、關(guān)卡選擇菜單等)

c.動畫模塊

2.鼠標(biāo)模塊

a.鼠標(biāo)圖形函數(shù)

b.鼠標(biāo)狀態(tài)(位置,點(diǎn)擊)判別函數(shù)

c.鼠標(biāo)位置更新函數(shù)

d.鼠標(biāo)顯示隱藏函數(shù)

3.自定義關(guān)卡模塊

a.地圖編輯

b.自定義游戲畫面

4.運(yùn)動模塊

a.拖動模塊

b.碰撞檢測模塊

c.運(yùn)動模塊

5.文件模塊

a.記錄當(dāng)前各關(guān)卡的分?jǐn)?shù)

b.記錄各關(guān)卡的解鎖情況

6.漢化模塊

a.漢字輸出

7.英化模塊

a.英文輸出

b.數(shù)字輸出

8.位圖調(diào)用模塊

a.顯示位圖

3.5程序中的名詞定義和注釋

1.對文件名(*.CPP)的解釋

MAIN.CPP主函數(shù)

MAINMENU.CPP主菜單函數(shù)

LEVEL.CPP關(guān)卡選擇

LEVEL1.CPP關(guān)1<-

LEVEL2.CPP關(guān)卡二

C語言程序設(shè)計(jì)報(bào)告

LEVEL3.CPP關(guān)卡三

LEVEL4.CPP關(guān)卡四

SELFSET.CPP自設(shè)游戲界面(調(diào)動編輯,進(jìn)入游戲)

LEVELZDY.CPP自定義游戲游戲界面函數(shù)

VS.CPP對戰(zhàn)模式函數(shù)

HELP.CPP幫助界面

HIGHSCORE.CPP排行榜界面

STARTDONGHUA.CPP開始動畫函數(shù)

OUT_HZ.CPP漢化函數(shù)

MOUSE.CPP鼠標(biāo)函數(shù)

WORD.CPP英文與數(shù)字輸出函數(shù)

BIANJI.CPP編輯自設(shè)模式下的地圖

VESA24B.CPPVESA模式下圖形的調(diào)用

PAIHANGBANG.CPP排行榜功能函數(shù)

HIT.CPP碰撞檢測函數(shù)

2.對其他文件的解釋

TUPIAN調(diào)用圖片文件夾

FILE存放各種文件的文件夾

HZK存放漢字庫的文件

LEVEL1.TXT第一關(guān)的分?jǐn)?shù)記錄

LEVEL2.TXT第二關(guān)的分?jǐn)?shù)記錄

LEVEL3.TXT第三關(guān)的分?jǐn)?shù)記錄

C語言程序設(shè)計(jì)報(bào)告

LEVEL4.TXT第四關(guān)的分?jǐn)?shù)記錄

LOCK.TXT各關(guān)卡的解鎖情況

ZDYBIRD.TXT自設(shè)模式下小鳥的坐標(biāo)

ZDYBOX.TXT自設(shè)模式下箱子的坐標(biāo)

4組員分工及時(shí)間安排

4.1組員分工

張昱:

1.菜單模塊:

Help.cpp

Hit.cpp

Levell.cpp

Level2.cpp

Level3.cpp

Vs.cpp

嚴(yán)浩:

Main.cpp

MAINMENU.CPP

Highscore.cpp

Level.cpp

Level4.cpp

c語言程序設(shè)計(jì)報(bào)告

Bianji.cpp

Selfset.cpp

Levelzdy.cpp

Paihangbang.cpp

Word.cpp

Out_hz.cpp

VESA模式下圖形的調(diào)用模塊,鼠標(biāo)的驅(qū)動模塊非二人編寫,不算入代碼量

4.2時(shí)間安排

任務(wù)

第1周系統(tǒng)需求分析與設(shè)計(jì)報(bào)告

第2周界面設(shè)計(jì),算法設(shè)計(jì)

第3周鍵盤、鼠標(biāo)接口設(shè)計(jì),算法設(shè)計(jì)

第4周編碼實(shí)現(xiàn)

第5周編碼實(shí)現(xiàn)

第6周編碼實(shí)現(xiàn)

第7周編碼實(shí)現(xiàn)、調(diào)試

第8周編碼實(shí)現(xiàn)、調(diào)試

第9周調(diào)試、驗(yàn)收、提交報(bào)告

C語言程序設(shè)計(jì)報(bào)告

5系統(tǒng)詳細(xì)設(shè)計(jì)

5.1主要數(shù)據(jù)結(jié)構(gòu)說明

structdata

(

charname[15];

unsignedintgrade;

};〃排行榜中對象的姓名與分?jǐn)?shù)

typedefstructtagPIG

(

charbmp[25];

intlife;

intx;

inty;

floatvx;

floatvy;

}PIG;〃小豬的參數(shù)

typedefstructtagBOX

(

intlife;

intx;

inty;

floatvx;

floatvy;

}BOX;〃箱子的參數(shù)

typedefstructtagBIRD

{

intlife;

intx;

inty;

floatvx;

floatvy;

}BIRD;〃小鳥的參數(shù)

C語言程序設(shè)計(jì)報(bào)告

5.2主要函數(shù)說明

Angrypig.h中主要函數(shù):

/*功能*/

voiddrawbox(BOX*box,inti);

voiddrawbird(BIRD*bird,inti);

voiddrawpig(PIG*pigl);

voidhitcheckpig(BOX*box,PIG*pigl,BIRD*bird,inti,intj,unsignedint*score);

voidhitcheckbox(BIRD*bird,BOX*box,inti,intn,unsignedint*score);

voidcheckunder(BIRD*bird,BOX*box,inti,intn);

voidmovepig(PIG*pigl);

voidmovebox(BOX*box,inti);

voidmovebird(BIRD*bird,inti);

intstopcheckbox(BOX*box,inti);

intstopcheckbird(BIRD*bird,inti);

voidstopbox(BOX*box,inti);

voidstoppig(PIG*pigl);

voidstopbird(BIRD*bird,inti);

intispass(BIRD*bird,inti);

voidputin(intxmi,intymi,char*s);

voidboom(intxjnty);

voidboompig(intx,inty);

voidcheckboxbz(BOX*box,unsignedint*score);

voidcheckbirdbz(BIRD*bird,unsignedint*score);

C語言程序設(shè)計(jì)報(bào)告

voidlaunch(int*mx,int*my,int*mbutt,PIG*pigl);

/*界面*/

voidstartdonghua();

voidmainmenu();

voidhelp();

voidlevel();

voidlevell();

voidIevel2();

voidIevel3();

voidIevel4();

voidvs();

voidhighscore();

voidceshi();

/*鼠標(biāo)*/

voidcursor(intx,inty);

intinit(intxmijntxmajntymi,intyma);

intread(int*mx,int*my,int*mbutt);

voidnewxy(int*mx,int*my,int*mbutt);

/*輸出*/

voidout_hz(intxO,intyO,char*s,unsignedlong_color,intwidthjnttimes);

voidtextxy(intx,inty,char*str,unsignedlong_color,intn);

C語言程序設(shè)計(jì)報(bào)告

/*排行榜*/

voidfilestart();

voidlockstart();

intcompare(unsignedintscore,char*s);

voidpaixu(charname[15],unsignedintscore,char*s);

/*自設(shè)地圖*/

voidselfset();

voidbianji();

voidlevelzdy();

/*bianji.cpp*/

voidyidongbird(int*mx,int*my,int*mbutt);

voidyidongbox(int*mx,int*my,int*mbutt);

voidbianjimouse(BOX*box,BIRD*bird);

/*鼠標(biāo)*/

voidhelpmouse();

voidhsmouse();

voidlevelmouse(intaljnta2,inta3,inta4);

voidlevellmouse(BOX*box,PIG*pigl,BIRD*bird,unsignedint*score);

voidlevel2mouse(BOX*box,PIG*pigl,BIRD*bird,unsignedint*score);

voidlevel3mouse(BOX*box,PIG*pigl,BIRD*bird,unsignedint*score);

voidlevel4mouse(BOX*box,PIG*pigl,BIRD*bird,unsignedint*score);

voidlevelzdymouse(BOX*box,PIG*pigl,BIRD*bird,unsignedint*score);

voidmainmouse();

C語言程序設(shè)計(jì)報(bào)告

voidselfsetmouse();

voidvsmousel(BOX*boxl,PIG*pigl,BIRD*birdl,BOX*box2,PIG*pig2,BIRD

*bird2);

voidvsmouse2(BOX*boxl,PIG*pigl,BIRD*birdl,BOX*box2,PIG*pig2,BIRD

*bird2);

/*highscore.cpp*/

voidxianshiO();

voidxianshi(char*s);

/*levell.cpp*/

voidcheckscorel(unsignedintscore);

voidcheckscoreunl(unsignedintscore);

voidflyl(int*mx,int*my,int*buttons,BOX*box,PIG*pigl,BIRD*bird,unsignedint

*score);

voidunpassl(int*x,int*y,int*buttons);

voidpassl(int*x,int*y,int*buttons,unsignedint*score,jnti);

voidzantingl(int*x,int*y,int"buttons);

voidpassmousel(int*x,int*y,int*buttons);

/*level2.cpp*/

voidcheckscore2(unsignedintscore);

voidcheckscoreun2(unsignedintscore);

voidfly2(int*mx,int*my,int*buttons,BOX*box,PIG*pigl,BIRD*bird,unsignedint

*score);

voidunpass2(int*x,lnt*y,int*buttons);

C語言程序設(shè)計(jì)報(bào)告

voidpass2(int*x,int*y,int"buttons,unsignedint*score,inti);

voidzanting2(int*x,int*y,int"buttons);

voidpassmouse2(int*x,int*y,int*buttons);

/*level3.cpp*/

voidcheckscore3(unsignedintscore);

voidcheckscoreun3(unsignedintscore);

voidfly3(int*mx,int*myjnt*buttons,BOX*box,PIG*pigl,BIRD*bird,unsignedint

*score);

voidunpass3(int*x,int*y,int*buttons);

voidpass3(int*x,int*y,int*buttons,unsignedint*score,inti);

voidzanting3(int*x,int*y,int*buttons);

voidpassmouse3(int*x,int*y,int*buttons);

voidhuixuan(PIG*pigl);

/*level4.cpp*/

voidcheckscore4(unsignedintscore);

voidcheckscoreun4(unsignedintscore);

voidfly4(int*mx,int*my,int*buttons,BOX*box,PIG*pigl,BIRD*bird,unsignedint

*score);

voidunpass4(int*x,int*y,int*buttons);

voidpass4(int*x,int*y,int*buttons,unsignedint*score,inti);

voidzanting4(int*x,int*y,int?buttons);

voidpassmouse4(int*x,int*y,int*buttons);

voidbaozha(intx,inty);

C語言程序設(shè)計(jì)報(bào)告

voidbaozhacheck(PIG*pigl,BOX*box,BIRD*bird,inti,intj,unsignedint*score);

voidstoppig4(PIG*pigl,BOX*box,BIRD*bird,unsignedint*score);

voidhitcheckpig4(BOX*box,PIG*pigl,BIRD*bird,intijntj,unsignedint*score);

/*levelzdy*/

voidcheckscorezdy(unsignedintscore);

voidcheckscoreunzdy(unsignedintscore);

voidflyzdy(int*mx,int*myjnt*buttons,BOX*box,PIG*pigl,BIRD*bird,unsigned

int*score);

voidunpasszdy(int*x,int*y,int*buttons);

voidpasszdy(int*x,int*y,int*buttons,unsignedint*score,inti);

voidzantingzdy(int*x,int*y,int*buttons);

voidpassmousezdy(int*x,int*y,int*buttons);

/*vs.cpp*/

voidvsflyl(int*mx,int*my,int*buttons,BOX*box,PIG*pigl,BIRD*bird);

voidvsfly2(int*mx,int*my,int*buttons,BOX*box,PIG*pigl,BIRD*bird);

voidvszanting(int*x,int*y,int*buttons);

voidvshitcheckpig(BOX*box,PIG*pigl,BIRD*bird,inti,intj);

voidvshitcheckbox(BIRD*bird,BOX*box,inti,intn);

voidvscheckboxbz(BOX*box);

voidvscheckbirdbz(BIRD*bird);

voidvslaunchl(int*mx,int*my,int*mbutt,PIG*pigl);

voidvslaunch2(int*mx,int*my,int*mbutt,PIG*pigl);

voidvswinmouse();

c語言程序設(shè)計(jì)報(bào)告

intiswin(BIRD*bird,inti);

5.3主要算法說明

附:5.1主要數(shù)據(jù)結(jié)構(gòu)說明

structdata

(

charname[15];〃破紀(jì)錄者姓名

unsignedintgrade;〃破記錄者分?jǐn)?shù)

};〃排行榜中對象的姓名與分?jǐn)?shù)

typedefstructtagPIG

(

charbmp[25];〃儲存小豬圖像的路徑

intlife;〃小豬的生命

intx;〃小豬的x坐標(biāo)

inty;〃小豬的y坐標(biāo)

floatvx;//小豬的x向速度

floatvy;〃小豬的y向速度

}PIG;〃小豬的參數(shù)

typedefstructtagBOX

(

intlife;〃箱子的生命

intx;//箱子的x坐標(biāo)

inty;//箱子的y坐標(biāo)

floatvx;〃箱子的x向速度

floatvy;//箱子的y向速度

}BOX;〃箱子的參數(shù)

typedefstructtagBIRD

(

intlife;//小鳥的生命

intx;//小鳥的x坐標(biāo)

inty;〃小鳥的y坐標(biāo)

floatvx;//小鳥的x向速度

floatvy;//小鳥的y向速度

}BIRD;〃小鳥的參數(shù)

C語言程序設(shè)計(jì)報(bào)告

5.4主要算法說明

voidhitcheckpig(BOX*box,PIG*pigl,BIRD*bird,inti,int^unsignedint*score)〃小豬的碰撞檢測

(

if(pigl->life>O)

(

for(;i>0;i-,box++)

(

if(box->life>0)

(

if(abs(box->x-pigl->x)<36&&abs(box->y-pigl->y)<36)

(

if(box->y-pigl->y>30)

(

if(fabs(pigl->vy)<40)

(

pigl->vy=pigl->vy*(-0.5);

box->life=box->life-30;

checkboxbz(box,score);

}

else

(

pigl->vx=pigl->vx*0.5;

pigl->vy=pigl->vy*0.5;

box->life=0;

checkboxbz(box,score);

)

}

else

(

if(fabs(pigl->vx)<35)

(

pigl->vx=pigl->vx*(-0.5);

box->life=box->life-50;

checkboxbzfbox^core);

)

elseif(fabs(pigl->vx)<90)

(

box->vx=pigl->vx*(0.5);

pigl->vx=pigl->vx*(-0.5);

box->life=box->life-60;

checkboxbz(box,score);

else

pigl->vx=pigl->vx*0.6;

C語言程序設(shè)計(jì)報(bào)告

pigl->vy=pigl->vy*1.5;

box->life=0;

checkboxbz(box,score);

}

}

break;

)

)

}

for(;j>0;j-,bird++)

(

if(bird->life>0)

(

if(abs(bird->x-pigl->x)<30&&abs(bird->y-pigl->y)<30)

(

pigl->vy=pigl->vy*(-0.7);

pigl->vx=pigl->vx*0.5;

bird->life=O;

checkbirdbz(birdzscore);

)

)

}

pigl->vy=pigl->vy-7*0.1;

stoppig(pigl);

)

}

voidhitcheckbox(BIRD*bird,BOX*box,inti,intn,unsignedint*score)//箱子的碰撞檢我!]

(

intj=i,k=i,a;

BOX*start=box,*temp=box;

BIRD*birdtemp;

for(;i>0;i-,box++)

(

if(box->life>0)

(

for(birdtemp=bird,a=n;a>0;a-,birdtemp++)

(

if(birdtemp->life>0&&abs(box->x-birdtemp->x)<35&&(birdtemp->y-box->y<35)&&(birdtemp->y-box->y>2

0))

(

birdtemp->life=O;

checkbirdbzfbirdtemp,score);

)

)

C語言程序設(shè)計(jì)報(bào)告

if(box->life>0&&box->vx!=0)

(

for(birdtemp=bird/a=n;a>0;a-/birdtemp++)

(

if(abs(box->x-birdtemp->x)<33&&abs(box->y-birdtemp->y)<33&&birdtemp->life>0)

(

box->life=0;

checkboxbz(box,score);

birdtemp->life=O;

checkbirdbz(birdtempzscore);

break;

)

)

for(j=k/temp=start;j>0;j-/temp++)

(

if(temp->life>0)

(

if(abs(box->x-temp->x)<40&&abs(box->y-temp->y)<30&&((box->x-temp->x)!=0||(box->y-temp->y)!=0))

(

box->life=0;

checkboxbz(box,score);

break;

)

}

)

if(box->x<20||box->x>1004)

(

box->life=0;

checkboxbzfbox,score);

)

)

)

)

voidcheckunder(BIRD*bird,BOX*box,intijntn)〃底部障礙物檢測

(

intj=i,k=i,m=i;

BOX*start=boxz*temp=box;

for(;i>0;i-,box++)

(

if(box->life>0)

for(j=k,temp=start;j>0;j-,temp++)

C語言程序設(shè)計(jì)報(bào)告

if(temp->life>0)

(

if(abs(temp->x-box->x)<=20&&(temp->y-box->y)<41&&(temp->y-box->y)>20)

(

box->vy=0;

break;

}

if(box->y>=565)

(

box->vx=0;

box->vy=0;

break;

}

)

)

if(j==O)

(

box->vy=box->vy+0.9;

)

}

)

for(;n>0;n-,bird++)

(

for(box=start,k=m;k>0;k-/box++)

(

if(box->life>0)

(

if(bird->life>0)

(

if(abs(bird->x-box->x)<20&&box->y-bird->y<38&&box->y-bird->y>32)

(

bird->vy=O;

break;

}

)

)

if(bird->y>569)

(

bird->vy=O;

break;

)

}

if(k==O)

bird->vy=bird->vy+0.7;

C語言程序設(shè)計(jì)報(bào)告

)

)

6總結(jié)

6.1組員張昱總結(jié)

1、要特別注意數(shù)據(jù)的類型,如我們在寫游戲界面的鼠標(biāo)時(shí),鼠標(biāo)的坐標(biāo)是int型,但在一個判斷語句中將

其進(jìn)行運(yùn)算后,有時(shí)運(yùn)算結(jié)果的值超出了int的范圍,這種問題編譯時(shí)不會提示,游戲運(yùn)行時(shí)也只是偶爾

出現(xiàn),并且這方面問題很難引起注意,debug很困難,應(yīng)特別注意。

2、當(dāng)程序中出現(xiàn)多層for循環(huán)嵌套時(shí),應(yīng)特別注意里層循環(huán)的初始條件每次循環(huán)前都應(yīng)初始化,這種問題

只是偶爾暴露,且易被忽視,也應(yīng)特別注意。

6.2組員嚴(yán)浩總結(jié)

1、在使用文件存儲的相關(guān)函數(shù)時(shí),容易出現(xiàn)錯誤的是文件的指針!應(yīng)時(shí)刻記住對文件里的數(shù)據(jù)進(jìn)行操作

時(shí),都是從文件指針開始進(jìn)行?用fscanf跟fprintf函數(shù)就可以對頂點(diǎn)的編號進(jìn)行簡單存儲,打開文件后

記得關(guān)閉文件。

2、指針的使用需要非常小心,因?yàn)橹羔槙r(shí)常會指到一些非法的區(qū)域,這種錯誤會造成程序崩潰,甚至是

系統(tǒng)崩潰.

3、在dos的編程環(huán)境下,因?yàn)槠渲荒芊峙?4K的內(nèi)存,所以其內(nèi)存的使用應(yīng)十分小心,使用完后應(yīng)立即

回收資源。

C語言程序設(shè)計(jì)報(bào)告

7源代碼清單

7.1*.CPP文件

MAIN.CPP

#include"angrypig.h"

voidmain()

{

,,,,,

char*s[4]={"file\\levell.txt/"file\\level2.txt;file\\level3.txt"/"file\\level4.txt"};

inti;

if(fopen("file\\lock.txt"z"rt")==NULL)

lockstart();

for(i=0;i<4;i++)

(

if(fopen(s[i]/,rb,,)==NULL)

filestart();

)

startdonghua();

mainmenu();

}

mainmenu.CPP

#includeHangrypig.h"

voidmainmouse();

voidmainmenuO

(

RGBBMP24color;

VesaSetWriteMode(VESA_COPY);

color.r=255;

color.g=255;

color,b=255;

VesaSetColor(*(unsignedlong*)&color);

ShowBmp24B(0,767/".\\tupian\\mainmenu.bmp");

VesaRect(415z283,628,337);

VesaRect(415,370,628,429);

VesaRect(415,463,628,520);

VesaRect(415,558,628,609);

VesaRect(740,425,870,465);

VesaRect(155,420,280,460);

mainmouse();

)

C語言程序設(shè)計(jì)報(bào)告

voidmainmouse()

(

intxmin,xmax,ymin,ymax,x_max=1023,y_max=767;/*lt匕處原為全局變量*/

intbuttons,xm,ym,xO,yO,x,y;

xmin=l;

xmax=x_max-l;

ymin=l;

ymax=y_max-2;

VesaSetWriteMode(VESA_XOR);

if(init(xminzxmax/yminzymax)==O)/*調(diào)用init函數(shù)對鼠標(biāo)器初始化*/

(

printf("MouseorMouseDriverAbsent,Pleaseinstall!");

delay(5000);

exit⑴;

)

x=20;y=20;

cursor(x,y);/*置光標(biāo)在屏幕中心。*/

for(;;)

(

newxy(&x,&y,&buttons);

if(x>=415&&x<=628&&y>=283&&y<=337&&buttons)

(

delay(lOO);

level();

)

if(x>=415&&x<=628&&y>=370&&y<=429&&buttons)

(

delay(lOO);

highscore();

}

if(x>=415&&x<=628&&y>=463&&y<=520&&buttons)

(

delay(lOO);

help();

)

if(x>=415&&x<=628&&y>=558&&y<=609&&buttons)

(

delay(lOO);

exit(O);

)

if(x>=740&&x<=870&&y>=425&&y<=465&&buttons)

delay(lOO);

c語言程序設(shè)計(jì)報(bào)告

selfset();

if(x>=155&&x<=280&&y>=420&&y<=460&&buttons)

(

delay(lOO);

VS();

)

}

)

help.CPP

#include"angrypig.h"

voidhelpmouse();

voidhelp()

(

VesaSetWriteMode(VESA_COPY);

ShowBmp24B(0,767J.\\tupianWhelp.bmp");

RGBBMP24color;

color.r=0;

color.g=0;

color.b=0;

VesaSetColor(*(unsignedlong*)&color);

out_hz(200,240,“按鍵:鼠標(biāo)操作”,"(unsignedlong*)&color,10,2);

out_hz(200,285,“操作:鼠標(biāo)左鍵按住小豬拖動,”「(unsignedlong*)&color,10,2);

out_hz(328,330,”調(diào)節(jié)發(fā)射角度,力度,”/(unsignedlong*)&color,10,2);

out_hz(328,375,“松開鼠標(biāo)發(fā)射,*(unsignedlong*)&color,10,2);

color.r=100;

color.g=200;

color.b=50;

VesaSetColor(*(unsignedlong*)&color);

VesaBar(600z460,735,500);

color,r=0;

color.g=0;

color,b=0;

VesaSetColor(*(unsignedlong*)&color);

out_hz(610,465,“主菜單","(unsignedlong*)&color,10,2);

helpmouse();

}

voidhelpmouse()

(

intxmin,xmax,ymin,ymax,x_max=1024,y_max=768;/*此處原為全局變量*/

intbuttons,xm,ym,xO,yO,x,y;;

xmin=l;

xmax=x_max-l;

C語言程序設(shè)計(jì)報(bào)告

ymin=l;

ymax=y_max-2;

VesaSetWriteMode(VESA_XOR);

調(diào)用函數(shù)對鼠標(biāo)器初始化*/

if(init(xminzxmax,ymin/ymax)==O)/*init

(

printf("MouseorMouseDriverAbsent,Pleaseinstall!");

delay(5000);

exit⑴;

)

x=100;y=40;

cursor(x,y);/*置光標(biāo)在屏幕中心。*/

for(;;)

(

newxy(&x,&y,&buttons);

if(x>=600&&x<=735&&y>=460&&y<=500&&buttons)

(

delay(lOO);

mainmenu();

}

)

}

highscore.CPP

#include"angrypig.h"

voidhsmouse();

voidxianshiO();

voidxianshi(char*s);

voidhighscore()

(

VesaSetWriteMode(VESA_COPY);

ShowBmp24B(0,767JtupianWpaihangl.bmp”);

xianshiO();

xianshi("file\\levell.txt");

hsmouse();

voidhsmouse()

(

intxmin,xmax,ymin,ymax,x_max=1024,y_max=768;/*止匕處原為全局變量*/

intbuttons,xm,ym,x,y;;

xmin=l;

xmax=x_max-l;

ymin=l;

ymax=y_max-2;

C語言程序設(shè)計(jì)報(bào)告

VesaSetWriteMode(VESA_XOR);

調(diào)用函數(shù)對鼠標(biāo)器初始化*/

if(init(xmin/xmax/ymin/ymax)==O)/*init

(

printf("MouseorMouseDriverAbsentzPleaseinstall!");

delay(5000);

exit⑴;

}

x=100;y=40;

cursor(x,y);/*置光標(biāo)在屏幕中心。*/

for(;;)

(

newxy(&x,&y,&buttons);

if(x>=0&&x<=243&&y>=106&&y<=222&&buttons)

(

VesaSetWriteMode(VESA_COPY);

ShowBmp24B(0,767,"tupianWpaihangl.bmp");

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論