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

下載本文檔

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

文檔簡介

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

2、圖集載入方法3) 添加UI設計方法4) 添加觸摸事件處理方法5) 添加自動補充魚更新方法6) 添加碰撞檢測方法3. 設置頁面4. 幫助場景游戲重要模塊詳細實現1. 紋理圖集的使用與加載要點:精靈處于界面中的層次關系,如下為紋理圖集加載代碼 CCSpriteFrameCache sharedSpriteFrameCache addSpriteFramesWithFile:"fish.plist" fishSheet = CCSpriteBatchNode batchNodeWithFile:"fish.png" self addChild:fishShee

3、t z:100;2. UI設計的細節實現要點:各個UI部件(精靈)的層次,位置調整以及武器的更換動作設置,下面為UI實現代碼-(void) initUI CGSize winSize = CCDirector sharedDirector winSize; CCSprite * background = CCSprite spriteWithFile:"bj00.jpg" background.position = ccp(winSize.width * 0.5, winSize.height * 0.5); self addChild:background z:0; /添

4、加能量槽 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" energyPointer.anchorPoint = ccp(0.5,0.5

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.height); bgExp.anchorPoint = ccp(0.5f,1.0f); self

6、 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 spriteWithSpriteFrameName: NSString stringWithFormat:"actor_can

7、non1_%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; /添加“”,“”按鈕(待改)CCMenuItemFont setFontSize:32;CCMenuItemFont setFont

8、Name:"Arial"CCMenuItem * addItem = CCMenuItemFont itemFromString: "+" target:self elector:selector(addCannonLeave);/addItem.scale = 1.5;CCMenu * addMenu = CCMenu menuWithItems:addItem,nil;addMenu.position = ccp(winSize.width*0.5+30, 10);addMenu alignItemsVertically;self addChild:

9、addMenu z:102 ;CCMenuItem * reduceItem = CCMenuItemFont itemFromString: "-" target:self selector:selector(reduceCannonLeave);CCMenu * reduceMenu = CCMenu menuWithItems:reduceItem,nil;reduceMenu.position = ccp(winSize.width*0.5-30, 10);reduceMenu alignItemsVertically;self addChild:reduceMen

10、u z:102;/初始化金幣數gold = UIRollNumber allocinit; gold setNumber:originGold; gold setPosition:ccp(168, 10); self addChild:gold z:102;-(void)addCannonLeave CGSize winSize = CCDirector sharedDirector winSize; cannonLevel+; If(cannonLevel = 8) cannonLevel = 1; /remove cannon CCScaleTo * narrow = CCScaleTo

11、actionWithDuration:0.1f scale:0.1;CCCallFuncO * removeCannon = CCCallFuncO actionWithTarget:self selector:selector(removeCannon:) object:cannnon; CCSequence *bowDismissSequence = CCSequence actions:narrow,removeCannon,nil; cannnon runAction:bowDismissSequence; /add a new cannon cannnon = CCCannon sp

12、riteWithSpriteFrameName:NSString stringWithFormat:"actor_cannon1_%i1.png",cannonLevel; cannnon.cannonLevel = cannonLevel; cannnon.position = ccp(winSize.width*0.5,30); cannnon.scale = 0.1f; CCDelayTime * delayTime = CCDelayTime actionWithDuration:0.1f; CCScaleTo * appear = CCScaleTo action

13、WithDuration:0.1f scale:cannon_scale; CCSequence * bowAppearSequence = CCSequence actions:delayTime,appear,nil; cannnon runAction:bowAppearSequence; cannonSheet addChild:cannnon z:100;/刪除武器 用于武器改變-(void)removeCannon:(id)sender /CCLOG("removeBow"); CCCannon * sp = sender; cannonSheet remove

14、Child:sp cleanup:YES;3. 觸摸事件模塊要點:子彈、大炮的跟隨轉向,子彈射出速度設置,越界判定(移動出畫面)-(void) setAngle:(CGPoint)point sprite:(CCSprite *)sp /CCLOG("setAngle");/設置“旋轉角度”int offX = point.x - cannnon.position.x;int offY = point.y - cannnon.position.y;if (offY <= 0) return;float ratio = (float)offY /(float)offX;

15、/直角三角形float angle = atanf(ratio)/M_PI*180;/三角形正切值獲得角度if (angle < 0) cannnon.rotation = -(90+angle);/設置武器旋轉角度sp.rotation = cannnon.rotation; else if (angle > 0) cannnon.rotation = 90 - angle;sp.rotation = cannnon.rotation;#pragma touch menthed- (void)ccTouchesBegan:(NSSet *)touches withEvent:(U

16、IEvent *)event for (UITouch *touch in touches) CGPoint pos = touch locationInView:touch.view; pos = CCDirector sharedDirector convertToGL:pos; if (pos.y <= cannnon.position.y) return; if (cannnon.cannonType = laser) /如果當前為超級武器, else cannnon setDisplayFrame:CCSpriteFrameCache sharedSpriteFrameCach

17、e spriteFrameByName:NSString stringWithFormat:"actor_cannon1_%i2.png",cannnon.cannonLevel; self setAngle:pos sprite:nil; - (void)ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event for (UITouch *touch in touches) CGPoint pos = touch locationInView:touch.view;pos = CCDirector sharedD

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

19、int offX = pos.x - cannnon.position.x; int offY = pos.y - cannnon.position.y; if (offY <= 0) return; if(cannnon.cannonType = laser) /用超級能量捕捉動物(待改) cannnon.cannonType = nomal;/發射完畢還原武器 else /*(待改)* gold setNumber:(gold getNumber-cannnon.cannonType);/每次損耗 CCBullet *bullet = CCBullet spriteWithSprit

20、eFrameName:NSString stringWithFormat:"bullet0%i.png",cannnon.cannonLevel;/添加子彈 bullet.position = cannnon.position; bullet.isHit = 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 rati

21、o = (float) offX / (float) offY; int realX = (realY - cannnon.position.y)* ratio + cannnon.position.x; CGPoint realDest = ccp(realX, realY); / 子彈會于一個恒定的速率按照射擊方向前進 int offRealX = realX - cannnon.position.x; int offRealY = realY - cannnon.position.y; float length = sqrtf(offRealX*offRealX)+(offRealY*o

22、ffRealY); /一旦我們有了距離,我們只是除以速度,以獲得所需的時間。這是因為速度=距離/時間,或換句話說 時間=距離/速度。 float velocity = 240/1; / 480pixels/1sec float realMoveDuration = length/velocity; /移除子彈的動作 CCMoveTo *move = CCMoveTo actionWithDuration:realMoveDuration position:realDest;CCCallFuncO * removeBullet = CCCallFuncO actionWithTarget:sel

23、f selector:selector(removeNet:) object:bullet; CCSequence* bulletSequence = CCSequence actions:move,removeBullet, nil; bullet.rotation = cannnon.rotation; bullet runAction:bulletSequence; bulletSheet addChild:bullet; /刪除子彈 用于碰撞后及自動消失-(void)removeNet:(id)sender /CCLOG("removeNet");CCNet * s

24、p = (CCNet *)sender;bulletSheet removeChild:sp cleanup:YES;4. 魚類精靈的添加(使用紋理圖集批量渲染)要點:設置魚的的動作,魚的隨機產生-(void) updateFish while (fishSheet children count < maxNumberOfFish) self addFish; -(void)addFishint type = rand()%9+1;NSMutableArray * oneFish = NSMutableArray array; int number = 10;for (int i = 1

25、; i < number; i+) oneFish addObject:CCSpriteFrameCache sharedSpriteFrameCache spriteFrameByName:NSString stringWithFormat:"fish0%i_0%i.png",type,i;CCRepeat * fishAction = CCRepeatForever actionWithAction:CCAnimate actionWithAnimation:CCAnimation animationWithFrames:oneFish delay:0.2f re

26、storeOriginalFrame:YES; CCFish * fish = CCFish spriteWithSpriteFrameName: NSString stringWithFormat:"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. 碰撞檢測的處理要

27、點:漁網與魚,子彈和魚的檢測方式(點面觸碰與面面觸碰區別),魚,網,子彈見邏輯關系(碰撞標志的設置),-(void) updateHit CGSize winSize = CCDirector sharedDirector winSize; CCFish * fish; CCNet * net; CCBullet * bullet; CCScaleTo * scale0 = CCScaleTo actionWithDuration:0.3 scale:1.1; CCScaleTo * scale1 = CCScaleTo actionWithDuration:0.3 scale:0.8; CC

28、ARRAY_FOREACH(bulletSheet children, bullet)/遍歷子彈 if (bullet isHit) continue; if (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 (CGRectContainsP

29、oint(fish boundingBox, bullet.position) /子彈碰撞 bullet.isHit = YES; /shownet,remove bullet /CCLOG("remove bullet"); bulletSheet removeChild:bullet cleanup:NO; /CCLOG("remove over"); /添加網 CCNet * netCatch = CCNet spriteWithSpriteFrameName:NSString stringWithFormat:"net0%i.png&q

30、uot;,cannonLevel; netCatch.position = bullet.position ; netSheet addChild:netCatch; /CCLOG("add net over"); /網的動作 CCCallFuncO * scaleNetAfterShow = CCCallFuncO actionWithTarget:self selector:selector(afterShowNet:) object:netCatch; CCSequence * netSequence = CCSequence actions:scale0,scale

31、1,scale0,scale1,scaleNetAfterShow,nil; netCatch runAction: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 (

32、!(fish randomCatch:cannonLevel) continue; else fish.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 sharedSprite

33、FrameCache spriteFrameByName:NSString stringWithFormat:"fish0%i_catch_0%i.png",fish.fishLevel,i; CCActionInterval * fish_catch_act = CCRepeat actionWithAction:CCAnimate actionWithAnimation:CCAnimation animationWithFrames:fishes delay:0.2f times:2; CCSequence * animalSequence = CCSequence actions:fish_catc

溫馨提示

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

評論

0/150

提交評論