您好,欢迎访问三七文档
当前位置:首页 > 临时分类 > funcode矿工捕鱼学长自打
//-----------------------------------------------------------------------------////-----------------------------------------------------------------------------#includeCommonAPI.h#includeLessonX.h#includestdlib.h#includestdio.h#includestring.h#includetime.hintg_iGamestate=0;//游戏状态,0表示未开始(此时拍子不随鼠标移动),1表//示倒计时阶段,2表示开始拍子可以随鼠标移动并拍打floatg_fScreenLeft=0.f;//屏幕左边界值floatg_fScreenRight=0.f;//右floatg_fScreenTop=0.f;//上floatg_fScreenBottom=0.f;//下floatg_fHookRotation=0.f;//钩子与地面的夹角intg_igamestate=0;//游戏状态,0表示钩子旋转,1表示释放绳索,后面还会定义其他状态floatg_fEmptyHookSpeed=15.f;floatg_fHookStartPosX;//存储钩子的初始X位置floatg_fHookStartPosY;//存储钩子的初始Y位置charszGotyuName[20];//当前抓到鱼的名称ggintflag=0;intg_fishnumber=8;intl=0;intcountdown=50;intscore=0;intb;inta;charcommand;charc;floatfTimeDelta;//统计经过的时间,并存储到countPassedTime//游戏状态,0表示未开始(此时拍子不随鼠标移动),1表//示倒计时阶段,2表示开始拍子可以随鼠标移动并拍打intcountPassedTime;///////////////////////////////////////////////////////////////////////////////////////////////主函数入口////////////////////////////////////////////////////////////////////////////////////////////intPASCALWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow){//初始化游戏引擎if(!dInitGameEngine(hInstance,lpCmdLine))return0;g_fScreenLeft=dGetScreenLeft();g_fScreenRight=dGetScreenRight();g_fScreenTop=dGetScreenTop();g_fScreenBottom=dGetScreenBottom();dSetSpriteCollisionSend(goldhook,1);dSetSpriteCollisionReceive(fish_muban1,1);dSetSpriteCollisionReceive(fish_muban2,1);intscore=0;floatcountPassedTime=0.f;constfloatfRotateSpeed=45.f;//摇摆速度,单位度/秒intiHookRotToLeft=1;//钩子摆动的方向:1←;0→dSetSpriteVisible(lose,false);dSetSpriteVisible(youwin,false);dSetSpriteVisible(number,false);dSetSpriteVisible(score1,false);dSetSpriteVisible(ming,true);//Todo:在此使用API更改窗口标题dSetWindowTitle(矿工捕鱼);//引擎主循环,处理屏幕图像刷新等工作while(dEngineMainLoop()){if(g_iGamestate==1&&!flag){for(inti=0;i3;i++){charszName[128];floatfPosX,fPosY;floatfSpeedX;sprintf(szName,fish%d,i);dCloneSprite(fish_muban1,szName);fPosX=dRandomRange(g_fScreenLeft+10.f,g_fScreenRight-10.f);fPosY=dRandomRange(g_fScreenTop+20.f,g_fScreenBottom-20.f);dSetSpritePosition(szName,fPosX,fPosY);fSpeedX=dRandomRange(10,20);dSetSpriteLinearVelocity(szName,fSpeedX,0);dSetSpriteWorldLimit(szName,WORLD_LIMIT_NULL,g_fScreenLeft-20.f,g_fScreenTop,g_fScreenRight+20.f,g_fScreenBottom);}for(inti=0;i4;i++){charszName[128];floatfPosX,fPosY;floatfSpeedX;sprintf(szName,fish%d,i+4);dCloneSprite(fish_muban2,szName);fPosX=dRandomRange(g_fScreenLeft+10.f,g_fScreenRight-10.f);fPosY=dRandomRange(g_fScreenTop+20.f,g_fScreenBottom-20.f);dSetSpritePosition(szName,fPosX,fPosY);fSpeedX=dRandomRange(10,20);dSetSpriteLinearVelocity(szName,fSpeedX,0);dSetSpriteWorldLimit(szName,WORLD_LIMIT_NULL,g_fScreenLeft-20.f,g_fScreenTop,g_fScreenRight+20.f,g_fScreenBottom);}dSetSpriteWorldLimit(goldhook,WORLD_LIMIT_NULL,g_fScreenLeft,g_fScreenTop,g_fScreenRight,g_fScreenBottom);g_fHookStartPosX=dGetSpritePositionX(goldhook);//获取钩子的初始X坐标g_fHookStartPosY=dGetSpritePositionY(goldhook);//获取钩子的初始Y坐标flag=1;}//获取两次调用之间的时间差,传递给游戏逻辑处理floatfTimeDelta=dGetTimeDelta();if(g_igamestate==0&&g_iGamestate!=0){floatfThisRotate=fRotateSpeed*fTimeDelta;if(iHookRotToLeft){g_fHookRotation+=fThisRotate;if(g_fHookRotation=180.f){g_fHookRotation=180.f;iHookRotToLeft=0;}}else{g_fHookRotation-=fThisRotate;if(g_fHookRotation=0.f){g_fHookRotation=0.f;iHookRotToLeft=1;}}dSetSpriteRotation(goldhook,g_fHookRotation);}elseif(g_igamestate==2){//获取钩子X方向的速度floatfSpeedX=dGetSpriteLinearVelocityX(goldhook);//获取钩子Y方向的速度floatfSpeedY=dGetSpriteLinearVelocityY(goldhook);//当速度接近为0时,即可判定其已到达初始点if(fSpeedX0.00001f&&fSpeedX-0.00001f&&fSpeedY0.00001f&&fSpeedY-0.00001f){//解除金块与钩子的锚定if(l){dSpriteDismount(szGotyuName);l=0;//删除获取的金块dDeleteSprite(szGotyuName);}//回拉结束,设定状态为0g_igamestate=0;//播放矿工的动画,即准备拉金子的动画dAnimateSpritePlayAnimation(GoldMan,GolderManAnimation2,0);}}//首先,从矿工精灵上获取一个缆绳链接点作为绳子的起始点(该链接点在编辑器里编辑好)floatfStartX=dGetSpriteLinkPointPosX(GoldMan,1);floatfStartY=dGetSpriteLinkPointPosY(GoldMan,1);//绳子终点在钩子精灵上获取(该链接点在编辑器里编辑好)floatfEndX=dGetSpriteLinkPointPosX(GoldHook,1);floatfEndY=dGetSpriteLinkPointPosY(GoldHook,1);//在这两点之间划线.线的颜色红绿蓝值都为50,即灰色;255表示不透明,2.0f表示线的粗细,0表示所在的层dDrawLine(fStartX,fStartY,fEndX,fEndY,2.f,0,50,50,50,255);//g_igamestate为1时才执行if(g_iGamestate==1){countPassedTime+=fTimeDelta;//统计经过的时间,并存储到countPassedTimedSetTextValue(countdown,countdown-countPassedTime);if(countPassedTime=countdown){//经过的时间超过countdowndSetSpriteVisible(countdown,false);//隐藏countdowncountdown=60;//重置经过的时间,为下一轮游戏做准备for(inti=0;i7;i++){charszName[128];sprintf(szName,fish%d,i);dSetSpriteLinearVelocity(szName,0,0);dSetSpriteWorldLimit(szName,WORLD_LIMIT_NULL,g_fScreenLeft-20.f,g_fScreenTop,g_fScreenRight+20.f,g_fScreenBottom);}dSetSpriteVisible(lose,true);dSetSpriteVisible(score1,true);dSetTextValue(score1,b);}}//执行游戏主循环GameMainLoop(fTimeDelta);};
本文标题:funcode矿工捕鱼学长自打
链接地址:https://www.777doc.com/doc-2872800 .html