二维游戏编程基础.ppt
上传人:qw****27 上传时间:2024-09-12 格式:PPT 页数:81 大小:9MB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

二维游戏编程基础.ppt

二维游戏编程基础.ppt

预览

免费试读已结束,剩余 71 页请下载文档后查看

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

2D游戏编程基础主要内容课程目标1.初始化2.进入游戏循环3.查询用户输入状态4.执行游戏逻辑和AI判断5.绘制图像6.循环7.退出1.初始化2.进入游戏循环3.查询用户输入状态4.执行游戏逻辑和AI判断5.绘制图像6.循环7.退出//definesforgameloopstates#defineGAME_INIT1//thegameisinitializing#defineGAME_MENU2//thegameisinthemenu#defineGAME_STARTING3//thegameisabouttorun#defineGAME_RUN4//thegameisnowrunning#defineGAME_RESTART5//thegameisgoingtorestart#defineGAME_EXIT6//thegameisexiting//gameglobalsintgame_state=GAME_INIT;//startoffinthisstateInterror=0;//usedtosenderrorsbacktoOS//mainbeginshereVoidmain(){//implementationofmaingameloopWhile(game_state!=GAME_EXIT){//implementationofmaingameloopswitch(game_state){caseGAME_INIT://thegameisinitializing{//allocateallmemoryandresourcesInit();game_state=GAME_MENU;}break;caseGAME_MENU://thegameisinthemenu{//callthemainmenufunctionandletitswitchstatesgame_state=Menu();//note:wecouldforceaRUNstatehere}break;caseGAME_STARTING://thegameisabouttorun{//thisstateisoptional,butusuallyusedtosetthingsupright//beforethegameisrunyoumightdoalittlemorehousekeepingSetup_For_Run();//switchtorunstategame_state=GAME_RUN;}break;caseGAME_RUN://thegameisnowrunning{//thissectioncontainstheentiregamelogicloopClear();//clearthedisplayGet_Input();//gettheinputDo_Logic();//performlogicandAIRender_Frame();//displaythenextframeofanimationWait();//synchronizethedisplay//theonlywaythatstatecanbechangedisthruuserinteraction//intheinputsectionorbymaybelosingthegame.}break;caseGAME_RESTART://thegameisrestarting{//thissectionisacleanupstateusedtofixupanylooseends//beforerunningagainFixup();//switchstatesbacktothemenugame_state=GAME_MENU;}break;caseGAME_EXIT://thegameisexiting{//ifthegameisinthisstatethenit’stimetobail,killeverything//andcrossyourfingersRelease_And_Cleanup();error=0;//settheerrorwordtowhatever//note:wedonothavet