捕鱼达人游戏项目开发过程文档_第1页
捕鱼达人游戏项目开发过程文档_第2页
捕鱼达人游戏项目开发过程文档_第3页
捕鱼达人游戏项目开发过程文档_第4页
捕鱼达人游戏项目开发过程文档_第5页
已阅读5页,还剩4页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

捕鱼达人项目开发过程文档游戏资源文件image图片:包括火炮,鱼,子弹,渔网,金币,数字,背景图片以及其它UI图片CCFish类:实现鱼的曲线路线的移动与各种鱼捕捉概率的设置UINumber类与UIRollNumber类游戏基本结构确定及搭建SysMenuSysMenu(scene)GameMain(scene)Setting(layer)Help(scene)图1.1依次在项目中创建如有图类完成项目结构,在总体上把握项目实现内容详细设计与各功能模块的实现程序编写流程系统菜单场景:添加初始化方法添加菜单添加菜单选项方法游戏场景添加初始化方法添加纹理图集载入方法添加UI设计方法添加触摸事件处理方法添加自动补充鱼更新方法添加碰撞检测方法设置页面帮助场景 游戏重要模块详细实现纹理图集的使用与加载要点:精灵处于界面中的层次关系,如下为纹理图集加载代码[[CCSpriteFrameCachesharedSpriteFrameCache]addSpriteFramesWithFile:@"fish.plist"];fishSheet=[CCSpriteBatchNodebatchNodeWithFile:@"fish.png"];[selfaddChild:fishSheetz:100];UI设计的细节实现要点:各个UI部件(精灵)的层次,位置调整以及武器的更换动作设置,下面为UI实现代码 -(void)initUI { CGSizewinSize=[[CCDirectorsharedDirector]winSize]; CCSprite*background=[CCSpritespriteWithFile:@"bj00.jpg"]; background.position=ccp(winSize.width*0.5,winSize.height*0.5); [selfaddChild:backgroundz:0]; //添加能量槽 CCSprite*engryBox=[CCSpritespriteWithFile:@"ui_2p_004.png"]; engryBox.anchorPoint=ccp(0.5,0.5); engryBox.position=ccp(winSize.width/2,10); [selfaddChild:engryBoxz:10]; //添加能量箭头 energyPointer=[CCSpritespriteWithFile:@"ui_2p_005.png"]; energyPointer.anchorPoint=ccp(0.5,0.5); energyPointer.position=ccp(winSize.width/2,10); energyPointer.rotation=minEnergyRotation; [selfaddChild:energyPointerz:12]; //添加顶部框体 CCSprite*bgExp=[CCSpritespriteWithFile:@"ui_box_01.png"]; bgExp.position=ccp(winSize.width/2,winSize.height); bgExp.anchorPoint=ccp(0.5f,1.0f); [selfaddChild:bgExpz:101]; //添加底框 CCSprite*bgNum=[CCSpritespriteWithFile:@"ui_box_02.png"]; bgNum.position=ccp(bgNum.contentSize.width/2,0); bgNum.anchorPoint=ccp(0.5f,0); [selfaddChild:bgNumz:101]; //添加武器cannnon=[CCCannonspriteWithSpriteFrameName:[NSStringstringWithFormat:@"actor_cannon1_%i1.png",1]]; cannnon.cannonLevel=1; cannonLevel=1; cannnon.anchorPoint=ccp(0.5f,0.5f); cannnon.position=ccp(winSize.width/2,30); cannnon.scale=cannon_scale; cannnon.cannonType=nomal; [cannonSheetaddChild:cannnon]; //添加“+”,“-”按钮(待改) [CCMenuItemFontsetFontSize:32]; [CCMenuItemFontsetFontName:@"Arial"]; CCMenuItem*addItem=[CCMenuItemFontitemFromString:@"+"target:selfelector:@selector(addCannonLeave)]; //addItem.scale=1.5; CCMenu*addMenu=[CCMenumenuWithItems:addItem,nil]; addMenu.position=ccp(winSize.width*0.5+30,10); [addMenualignItemsVertically]; }触摸事件模块要点:子弹、大炮的跟随转向,子弹射出速度设置,越界判定(移动出画面) -(void)setAngle:(CGPoint)pointsprite:(CCSprite*)sp { //CCLOG(@"setAngle"); //设置“旋转角度” intoffX=point.x-cannnon.position.x; intoffY=point.y-cannnon.position.y; if(offY<=0){ return; } floatratio=(float)offY/(float)offX; //直角三角形 floatangle=atanf(ratio)/M_PI*180; //三角形正切值获得角度 if(angle<0){ cannnon.rotation=-(90+angle); //设置武器旋转角度 sp.rotation=cannnon.rotation; }elseif(angle>0){ cannnon.rotation=90-angle; sp.rotation=cannnon.rotation; } } #pragmatouchmenthed -(void)ccTouchesBegan:(NSSet*)toucheswithEvent:(UIEvent*)event { for(UITouch*touchintouches) { CGPointpos=[touchlocationInView:touch.view]; pos=[[CCDirectorsharedDirector]convertToGL:pos]; if(pos.y<=cannnon.position.y){ return; } if(cannnon.cannonType==laser){ //如果当前为超级武器, }else{ [cannnonsetDisplayFrame:[[CCSpriteFrameCachesharedSpriteFrameCache]spriteFrameByName:[NSStringstringWithFormat:@"actor_cannon1_%i2.png",cannnon.cannonLevel]]]; } [selfsetAngle:possprite:nil]; } } -(void)ccTouchesMoved:(NSSet*)toucheswithEvent:(UIEvent*)event { for(UITouch*touchintouches){ CGPointpos=[touchlocationInView:touch.view]; pos=[[CCDirectorsharedDirector]convertToGL:pos]; [selfsetAngle:possprite:nil]; } } -(void)ccTouchesEnded:(NSSet*)toucheswithEvent:(UIEvent*)event { for(UITouch*touchintouches) { CGSizewinSize=[[CCDirectorsharedDirector]winSize]; CGPointpos=[touchlocationInView:touch.view]; pos=[[CCDirectorsharedDirector]convertToGL:pos]; intoffX=pos.x-cannnon.position.x; intoffY=pos.y-cannnon.position.y; if(offY<=0){ return; } if(cannnon.cannonType==laser) { //用超级能量捕捉动物(待改) cannnon.cannonType=nomal; //发射完毕还原武器 } else { //***************(待改)******************* [goldsetNumber:([goldgetNumber]-cannnon.cannonType)];//每次损耗CCBullet*bullet=[CCBulletspriteWithSpriteFrameName:[NSStringstringWithFormat:@"bullet0%i.png",cannnon.cannonLevel]]; //添加子弹 bullet.position=cannnon.position; bullet.isHit=NO; [selfsetAngle:possprite:bullet]; //Determinewherewewishtoshoottheprojectileto intrealY=winSize.height+bullet.contentSize.height*0.5; floatratio=(float)offX/(float)offY; intrealX=(realY-cannnon.position.y)*ratio+cannnon.position.x; CGPointrealDest=ccp(realX,realY); //子弹会于一个恒定的速率按照射击方向前进 intoffRealX=realX-cannnon.position.x; intoffRealY=realY-cannnon.position.y; floatlength=sqrtf((offRealX*offRealX)+(offRealY*offRealY)); //一旦我们有了距离,我们只是除以速度,以获得所需的时间。这是因为速度=距离/时间,或换句话说时间=距离/速度。 floatvelocity=240/1;//480pixels/1sec floatrealMoveDuration=length/velocity; //移除子弹的动作 CCMoveTo*move=[CCMoveToactionWithDuration:realMoveDurationposition:realDest];CCCallFuncO*removeBullet=[CCCallFuncOactionWithTarget:selfselector:@selector(removeNet:)object:bullet]; CCSequence*bulletSequence=[CCSequenceactions:move,removeBullet,nil]; bullet.rotation=cannnon.rotation; [bulletrunAction:bulletSequence]; [bulletSheetaddChild:bullet]; } } } //删除子弹用于碰撞后及自动消失 -(void)removeNet:(id)sender { //CCLOG(@"removeNet"); CCNet*sp=(CCNet*)sender; [bulletSheetremoveChild:spcleanup:YES]; }鱼类精灵的添加(使用纹理图集批量渲染)要点:设置鱼的的动作,鱼的随机产生-(void)updateFish{while([[fishSheetchildren]count]<maxNumberOfFish){[selfaddFish];}}-(void)addFish{ inttype=rand()%9+1; NSMutableArray*oneFish=[NSMutableArrayarray];intnumber=10; for(inti=1;i<number;i++) { [oneFishaddObject:[[CCSpriteFrameCachesharedSpriteFrameCache] spriteFrameByName:[NSStringstringWithFormat:@"fish0%i_0%i.png",type,i]]]; } CCRepeat*fishAction=[CCRepeatForeveractionWithAction:[CCAnimateactionWithAnimation:[CCAnimationanimationWithFrames:oneFishdelay:0.2f]restoreOriginalFrame:YES]];CCFish*fish=[CCFishspriteWithSpriteFrameName:[NSStringstringWithFormat:@"fish0%i_0%i.png",type,1]];fish.scale=0.6f;fish.fishLevel=type;fish.isCatch=NO;//默认为未被抓[fishrunAction:fishAction];[fishaddPath]; //添加路线 [fishrun];[fishSheetaddChild:fishz:100];}碰撞检测的处理要点:渔网与鱼,子弹和鱼的检测方式(点面触碰与面面触碰区别),鱼,网,子弹见逻辑关系(碰撞标志的设置),-(void)updateHit{CGSizewinSize=[[CCDirectorsharedDirector]winSize];CCFish*fish;CCNet*net;CCBullet*bullet;CCScaleTo*scale0=[CCScaleToactionWithDuration:0.3scale:1.1];CCScaleTo*scale1=[CCScaleToactionWithDuration:0.3scale:0.8];CCARRAY_FOREACH([bulletSheetchildren],bullet)//遍历子弹{if([bulletisHit]){continue;}if(bullet.position.x>(winSize.width+bullet.contentSize.width)||bullet.position.x<(0-bullet.contentSize.width)){continue;}CCARRAY_FOREACH([fishSheetchildren],fish){if([bulletisHit]){continue;}if(CGRectContainsPoint([fishboundingBox],bullet.position)){//子弹碰撞bullet.isHit=YES;//shownet,removebullet//CCLOG(@"removebullet");[bulletSheetremoveChild:bulletcleanup:NO];//CCLOG(@"removeover");//添加网CCNet*netCatch=[CCNetspriteWithSpriteFrameName:[NSStringstringWithFormat:@"net0%i.png",cannonLevel]];netCatch.position=bullet.position;[netSheetaddChild:netCatch];//CCLOG(@"addnetover");//网的动作CCCallFuncO*scaleNetAfterShow=[CCCallFuncOactionWithTarget:selfselector:@selector(afterShowNet:)object:netCatch];CCSequence*netSequence=[CCSequenceactions:scale0,scale1,scale0,scale1,scaleNetAfterShow,nil];[netCatchrunAction:netSequence];//CCLOG(@"addnetover");}}}CCARRAY_FOREACH([netSheetchildren],net){if([netisHit]){continue;}CCARRAY_FOREACH([fishSheetchildren],fish){if([fishisCatch]){continue;}if(CGRectContainsPoint([netboundingBox],fish.position)){if(!([fishrandomCatch:cannonLevel])){continue;}else{fish.isCatch=YES;[selfupdateEnergy:fish.fishLevel];NSMutableArray*fishes=[NSMutableArrayarray];intnumber;if(fish.fishLevel<8){number=3;}else{number=5;}for(inti=1;i<number;i++){[fishesaddObject:[[CCSpriteFrameCachesharedSpriteFrameCache]spriteFrameByName:[NSStringstringWithFormat:@"fish0%i_catch_0%i.png",fish.fishLevel,i]]];}CCActionInterval*fish_catch_act=[CCRepeatactionWithAction:[CCAnimateactionWithAnimation:[CCAnimationanimationWithFrames:fishesdelay:0.2f]]times:2];CCSequence*animalSequence=[CCSequenceactions:fish_catch_act,[CCCallFuncOactionWithTarget:selfselector:@selector(afterCatch:)object:fish],n

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论