捕魚達人游戲項目開發(fā)過程文檔_第1頁
捕魚達人游戲項目開發(fā)過程文檔_第2頁
捕魚達人游戲項目開發(fā)過程文檔_第3頁
捕魚達人游戲項目開發(fā)過程文檔_第4頁
捕魚達人游戲項目開發(fā)過程文檔_第5頁
免費預覽已結(jié)束,剩余4頁可下載查看

下載本文檔

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

文檔簡介

1、捕魚達人項目開發(fā)過程文檔一、游戲資源文件UI圖片image圖片:包括火炮,魚,子彈,漁網(wǎng),金幣,數(shù)字,背景圖片以及其它CCFish類:實現(xiàn)魚的曲線路線的移動與各種魚捕捉概率的設(shè)置UINumber 類與 UIRollNumber 類二、游戲基本結(jié)構(gòu)確定及搭建SysMenu(scene)GameMain(scene)Setting(layer)Help(scene)圖1.1依次在項目中創(chuàng)建如有圖類完成項目結(jié)構(gòu),在總體上把握項目實現(xiàn)內(nèi)容、詳細設(shè)計與各功能模塊的實現(xiàn)程序編寫流程1.系統(tǒng)菜單場景:1)2)3)添加初始化方法添加菜單添加菜單選項方法2.游戲場景1)2)3)4)5)6)添加初始化方法添加紋理

2、圖集載入方法添加UI設(shè)計方法添加觸摸事件處理方法 添加自動補充魚更新方法 添加碰撞檢測方法二 1 Twr.EL 805 SDK E ClMsihwiig-kla iter L_ 熱i> TSer(h|hSc ttin t; LJive r .mh| GBrtiiMainLjavtr.h e| GiimrMdfcmLiviFi mh j UHMLiinrb>eF h m UlMLi-rirber m h|1叫5根M用UE,E h | 匚匚匚口 Rmsn.fi e| CCCar*ion.h| CCNeth aril CCNec h| CCVyllfeT h 川 CSuIbctE lh|

3、 匚UFIssh.hh 9八Mn| Si-Mcnu e h A S'pOi' l-e qan- a n m 科口01七華1虻M hl< r. hReS-DluTCJE-S3.4.設(shè)置頁面幫助場景游戲重要模塊詳細實現(xiàn)1 .紋理圖集的使用與加載要點:精靈處于界面中的層次關(guān)系,如下為紋理圖集加載代碼CCSpriteFrameCache sharedSpriteFrameCache addSpriteFramesWithFile :"fish.plist"fishSheet = CCSpriteBatchNode batchNodeWithFile :&quo

4、t;fish.png"self addChild :fishSheet z:100;2 . UI設(shè)計的細節(jié)實現(xiàn)要點:各個 UI部件(精靈)的層次,位置調(diào)整以及武器的更換動作設(shè)置,下面為UI實現(xiàn)代碼-(void) initUI |CGSize winSize = CCDirector sharedDirector winSize;CCSprite * background = CCSprite spriteWithFile :"bj00.jpg"background. position = ccp(winSize. width * 0.5, winSize. hei

5、ght * 0.5);self addChild :background z:0;添加能量槽CCSprite *engryBox = CCSprite spriteWithFile :"ui_2p_004.png"engryBox. anchorPoint = ccp(0.5,0.5);engryBox. position = ccp (winSize. width /2,10);self addChild :engryBox z:10; |添加能量箭頭energyPointer = CCSprite spriteWithFile :"ui_2p_005.png&

6、quot;energyPointer .anchorPoint = ccp (0.5,0.5);energyPointer .position = ccp(winSize. width/2,10);energyPointer .rotation = minEnergyRotation ;self addChild :energyPointer z:12;|添加頂部框體CCSprite *bgExp = CCSprite spriteWithFile :"ui_box_01.png"bgExp. position = ccp(winSize. width/2, winSize

7、. height);bgExp. anchorPoint = ccp(0.5f ,1.0f);self addChild :bgExp z:101;添加底框CCSprite *bgNum = CCSprite spriteWithFile :"ui_box_02.png"bgNum. position = ccp(bgNum.contentSize. width/2, 0);bgNum. anchorPoint = ccp(0.5f,0);self addChild :bgNum z:101;添加武器cannnon = CCCannon spriteWithSpriteFr

8、ameName : 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;cannonSheet addChild :cannnon ;|/添加牛",

9、上"按鈕(待改)CCMenultemFont setFontSize :32;CCMenultemFont setFontName :"Arial"CCMenultem * addItem = CCMenultemFont itemFromString : "+" target:self elector :selector (addCannonLeave); |/addItem.scale = 1.5;CCMenu * addMenu = CCMenu menuWithltems :addItem, nil;addMenu. position

10、= ccp (winSize. width*0.5+30, 10);addMenu alignItemsVertically ;self addChild :addMenu z:102 ;CCMenuItem * reduceltem = CCMenuItemFont itemFromString : "-" target:self | selector: selector (reduceCannonLeave); |CCMenu * reduceMenu = CCMenu menuWithltems :reduceltem, nil;reduceMenu. positio

11、n = ccp (winSize. width*0.5-30, 10);reduceMenu alignltemsVertically ;self addChild :reduceMenu z:102 ;初始化金幣數(shù)gold = UlRollNumber allocinit;gold setNumber :originGold ;gold setPosition :ccp(168, 10);self addChild :gold z:102 ;-(void )addCannonLeave |CGSize winSize = CCDirector sharedDirector winSize ;

12、cannonLevel +;lf( cannonLevel = 8)cannonLevel = 1;/remove cannon |CCScaleTo * narrow = CCScaleT o actionWithDuration :0.1f scale :0.1;CCCallFuncO * removeCannon = CCCallFuncO actionWithTarget :self selector:selector (removeCannon:) | object :cannnon ;CCSequence *bowDismissSequence = CCSequence actio

13、ns :narrow,removeCannon, nil;cannnon runAction :bowDismissSequence; | /add a new cannon |cannnon = CCCannon spriteWithSpriteFrameName :NSString stringWithFormat :"actor_cannon1_%i1.png" ,cannonLevel ; cannnon .cannonLevel = cannonLevel ;cannnon .position = ccp(winSize. width*0.5,30);cannno

14、n .scale = 0.1f;CCDelayTime * delayTime = CCDelayTime actionWithDuration :0.1f;CCScaleTo * appear = CCScaleT o actionWithDuration :0.1f scale:cannon scale ;CCSequence * bo = CCSequence actions :delayTime,appear, nil;cannnon runAction :bo;cannonSheet addChild :cannnon z: 100;刪除武器用于武器改變-(void )removeC

15、annon:( id)sender | /CCLOG("removeBow"); | CCCannon * sp = sender; cannonSheet removeChild :sp cleanup :YES;3.觸摸事件模塊要點:子彈、大炮的跟隨轉(zhuǎn)向,子彈射出速度設(shè)置,越界判定(移動出畫面)- (void) setAngle:( CGPoint )point sprite:( CCSprite *)sp /CCLOG("setAngle"); |/設(shè)置旋轉(zhuǎn)角度”int offX = point. x - cannnon .position .x;

16、int offY = point. y - cannnon . position .y;if (offY <= 0) return ;float ratio = ( float)offY /(float )offX;/直角三角形float angle = atanf(ratio)/ M_PI *180;三角形正切值獲得角度if (angle < 0) |cannnon . rotation = -(90+angle); /設(shè)置武器旋轉(zhuǎn)角度sp. rotation = cannnon . rotation ; else if (angle > 0) |cannnon . rot

17、ation = 90 - angle; |sp. rotation = cannnon . rotation ;#pragma touch menthed- (void)ccTouchesBegan:( NSSet *)touches withEvent:( UIEvent *)event |for (UITouch *touch in touches) |CGPoint pos = touch locationInView :touch. view;pos = CCDirector sharedDirector convertToGL :pos;if (pos. y <= cannno

18、n .position .y) return ;if (cannnon .cannonType = laser) 如果當前為超級武器, else cannnon setDisplayFrame : CCSpriteFrameCache sharedSpriteFrameCache | spriteFrameByName :NSStringstringWithFormat :"actor_cannon1_%i2.png" ,cannnon .cannonLevel ;self setAngle :pos sprite :nil;- (void)ccTouchesMoved:(

19、 NSSet *)touches withEvent:( UIEvent *)eventfor (UITouch *touch in touches) CGPoint pos = touch locationInView :touch. view;pos = CCDirector sharedDirector convertToGL :pos;self setAngle :pos sprite :nil;-(void)ccTouchesEnded:( NSSet *)touches withEvent:( UIEvent *)event|for (UITouch *touch in touch

20、es)CGSize winSize = CCDirector sharedDirector winSize;CGPoint pos = touch locationInView :touch. view;pos = CCDirector sharedDirector convertToGL :pos;int offX = pos. x - cannnon .position .x;int offY = pos. y - cannnon .position.y;if (offY <= 0) return ;if(cannnon .cannonType = laser)用超級能量捕捉動物(待

21、改)cannnon .cannonType = nomal; 發(fā)射完畢還原武器else*(待改)*gold setNumber :(gold getNumber -cannnon .cannonType );/每次損耗 CCBullet *bullet = CCBullet spriteWithSpriteFrameName :NSString | stringWithFormat :"bullet0%i.png" ,cannnon .cannonLevel ; 添加子彈 bullet. position = cannnon .position ;bullet. isHit

22、 = NO;self setAngle :pos sprite :bullet; |/ Determine where we wish to shoot the projectile to |int realY = winSize. height + bullet. contentSize .height *0.5;|float ratio = (float) offX / (float) offY; Iint realX = (realY - cannnon .position .y)* ratio + cannnon . position .x; CGPoint realDest = cc

23、p(realX, realY); |/子彈會于一個恒定的速率按照射擊方向前進int offRealX = realX - cannnon .position .x;int offRealY = realY - cannnon .position .y;float length = sqrtf(offRealX*offRealX)+(offRealY*offRealY);一旦我們有了距離,我們只是除以速度,以獲得所需的時間。這是因為速度 =距離/時間,或換句話說 時間=距離/速度。float velocity = 240/1; / 480pixels/1sec |float realMoveDu

24、ration = length/velocity;|移除子彈的動作CCMoveTo *move = CCMoveTo actionWithDuration :realMoveDuration position :realDest; | CCCallFuncO * removeBullet = CCCallFuncO actionWithTarget :self selector :selector (removeNet:) object:bullet; | CCSequence * bulletSequence = CCSequence actions :move,removeBullet,

25、nil;bullet. rotation = cannnon .rotation ;bullet runAction :bulletSequence;bulletSheet addChild :bullet; |刪除子彈用于碰撞后及自動消失-(void )removeNet:( id)sender |CCLOG("removeNet");CCNet * sp = ( CCNet *)sender; |bulletSheet removeChild :sp cleanup :YES ; 4.魚類精靈的添加(使用紋理圖集批量渲染) 要點:設(shè)置魚的的動作,魚的隨機產(chǎn)生-(void

26、) updateFish | while (fishSheet children count < maxNumberOfFish ) self addFish ;,-(void)addFish |int type = rand ()%9+1;NSMutableArray * oneFish = NSMutableArray array ;int number = 10;for (int i = 1; i < number; i+) oneFish addObject :CCSpriteFrameCache sharedSpriteFrameCache spriteFrameByNa

27、me :NSString stringWithFormat :"fish0%i_0%i.png" ,type,i;CCRepeat * fishAction = CCRepeatForever actionWithAction :CCAnimate actionWithAnimation :CCAnimationanimationWithFrames :oneFish delay :0.2f restoreOriginalFrame : YES;CCFish * fish = CCFish spriteWithSpriteFrameName : NSString strin

28、gWithFormat :"fish0%i_0%i.png" ,type, 1 ;fish. scale = 0.6f;fish. fishLevel = type; |fish. isCatch = NO;/默認為未被抓fish runAction :fishAction; |fish addPath ; 添加路線fish run;fishSheet addChild :fish z:100;5,碰撞檢測的處理要點:漁網(wǎng)與魚,子彈和魚的檢測方式(點面觸碰與面面觸碰區(qū)別),魚,網(wǎng),子彈見邏輯關(guān)系(碰撞標志的設(shè)置),-(void) updateHit |CGSize winS

29、ize = CCDirector sharedDirector winSize;CCFish * fish;CCNet * net; |CCBullet * bullet;CCScaleTo * scaleO = CCScaleTo actionWithDuration :0.3 scale:1.1;CCScaleTo * scalel = CCScaleTo actionWithDuration :0.3 scale:0.8;CCARRAY_FOREACH (bulletSheet children, bullet) 遍歷子彈 if (bullet isHit ) continue ;if

30、(bullet. position .x > (winSize. width + bullet. contentSize .width) | |bullet. position .x < (0-bullet. contentSize .width) continue ;CCARRAY_FOREACH (fishSheet children, fish)if (bullet isHit) continue ;if (CGRectContainsPoint (fish boundingBox , bullet. position ) 子彈碰撞 bullet. isHit = YES;/

31、shownet,remove bullet |/CCLOG("remove bullet");bulletSheet removeChild :bullet cleanup :NO;/CCLOG("remove over"); |添加網(wǎng)CCNet * netCatch = CCNet spriteWithSpriteFrameName :NSStringstringWithFormat :"net0%i.png" ,cannonLevel ;netCatch. position = bullet. position ;netSheet

32、 addChild :netCatch; |/CCLOG("add net over"); |網(wǎng)的動作CCCallFuncO * scaleNetAfterShow = CCCallFuncO actionWithTarget :self selector ©selector (afterShowNet:) object:netCatch; |CCSequence * netSequence = CCSequence |actions :scale0,scale1,scale0,scale1,scaleNetAfterShow, nil;netCatch runA

33、ction :netSequence;/CCLOG("add net over"); |CCARRAY_FOREACH (netSheet children, net)if (net isHit) continue ;CCARRAY_FOREACH (fishSheet children, fish)if (fish isCatch ) continue ;if (CGRectContainsPoint (net boundingBox , fish. position ) if (!(fish randomCatch :cannonLevel ) continue ; e

34、lsefish. isCatch = YES;self updateEnergy :fish.fishLevel ;NSMutableArray * fishes = NSMutableArray array; int number; |if (fish. fishLevel < 8) number = 3;else number = 5;for (int i = 1; i < number; i+) fishes addObject :CCSpriteFrameCache sharedSpriteFrameCache spriteFrameByName :NSString stringWithFormat :"fish0%i_catch_0%i.png" ,fish. fishLevel ,i; CCActionInterval * fish_catch_act = CCRepeat actionWithAction :CCAnimateactionWithAnimation :CCAnimation animationWithFrames :fishes delay :0.2f times :2;CCSeq

溫馨提示

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

評論

0/150

提交評論