捕魚達人游戲項目開發(fā)過程文檔_第1頁
捕魚達人游戲項目開發(fā)過程文檔_第2頁
捕魚達人游戲項目開發(fā)過程文檔_第3頁
捕魚達人游戲項目開發(fā)過程文檔_第4頁
捕魚達人游戲項目開發(fā)過程文檔_第5頁
已閱讀5頁,還剩4頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

捕魚達人項目開發(fā)過程文檔游戲資源文件image圖片:包括火炮,魚,子彈,漁網,金幣,數(shù)字,背景圖片以及其它UI圖片CCFish類:實現(xiàn)魚的曲線路線的移動與各種魚捕捉概率的設置UINumber類與UIRollNumber類游戲基本結構確定及搭建SysMenuSysMenu(scene)GameMain(scene)Setting(layer)Help(scene)圖1.1依次在項目中創(chuàng)建如有圖類完成項目結構,在總體上把握項目實現(xiàn)內容詳細設計與各功能模塊的實現(xiàn)程序編寫流程系統(tǒng)菜單場景:添加初始化方法添加菜單添加菜單選項方法游戲場景添加初始化方法添加紋理圖集載入方法添加UI設計方法添加觸摸事件處理方法添加自動補充魚更新方法添加碰撞檢測方法設置頁面幫助場景 游戲重要模塊詳細實現(xiàn)紋理圖集的使用與加載要點:精靈處于界面中的層次關系,如下為紋理圖集加載代碼[[CCSpriteFrameCachesharedSpriteFrameCache]addSpriteFramesWithFile:@"fish.plist"];fishSheet=[CCSpriteBatchNodebatchNodeWithFile:@"fish.png"];[selfaddChild:fishSheetz:100];UI設計的細節(jié)實現(xiàn)要點:各個UI部件(精靈)的層次,位置調整以及武器的更換動作設置,下面為UI實現(xiàn)代碼 -(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; //發(fā)射完畢還原武器 } 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];}碰撞檢測的處理要點:漁網與魚,子彈和魚的檢測方式(點面觸碰與面面觸碰區(qū)別),魚,網,子彈見邏輯關系(碰撞標志的設置),-(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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
  • 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論