




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、文档来源为:从网络收集整理.word版本可编辑.欢迎下载支持.捕鱼达人项目开发过程文档 一、游戏资源文件image图片:包括火炮,鱼,子弹,渔网,金币,数字,背景图片以及其它UI图片CCFish类:实现鱼的曲线路线的移动与各种鱼捕捉概率的设置UINumber 类与 UIRollNumber 类二、游戏基本结构确定及搭建GameMain(scene)图1.1依次在项目中创建如有图类完成项目结构,在总体上把握项目实现内容 三、详细设计与各功能模块的实现程序编写流程1 .系统菜单场景:1)添加初始化方法2)添加菜单3)添加菜单选项方法2 .游戏场景1)添加初始化方法2)添加纹理图集载入方法3)添加U
2、I设计方法4)添加触摸事件处理方法5)添加自动补充鱼更新方法6)添加碰撞检测方法3 .设置页面4 .帮助场景游戏重要模块详细实现1 .纹理图集的使用与加载要点:精灵处于界面中的层次关系,如下为纹理图集加载代码CCSpriteFrameCache sharedSpriteFrameCache addSpriteFramesWithFile :"fish.plist"fishSheet = CCSpriteBatchNode batchNodeWithFile :"fish.png"self addChild :fishSheet z:100;2 . UI设
3、计的细节实现要点:各个 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;添加能量槽CCSprit
4、e *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);ener
5、gyPointer .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 a
6、ddChild :bgExp z:101;添加底框CCSprite *bgNum = CCSprite spriteWithFile :"ui_box_02.png"bgNum. position = ccp(, 0);bgNum. anchorPoint = ccp(0.5f,0);self addChild :bgNum z:101;添加武器cannnon = CCCannon spriteWithSpriteFrameName : NSStringstringWithFormat :"actor_cannon1_%i1.png" ,1;cannno
7、n .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 ;|/添加牛",上"按钮(待改)CCMenultemFont setFontSize :32;CCMenultemFont setFontName :"A
8、rial"CCMenultem * addItem = CCMenultemFont itemFromString : "+" target:self elector :selector (addCannonLeave); |/addItem.scale = 1.5; |CCMenu * addMenu = CCMenu menuWithltems :addItem, nil;addMenu. position = ccp (winSize. width*0.5+30, 10);addMenu alignItemsVertically ;self addChild
9、 :addMenu z:102 ;CCMenuItem * reduceltem = CCMenuItemFont itemFromString : "-" target:self | selector: selector (reduceCannonLeave);CCMenu * reduceMenu = CCMenu menuWithltems :reduceltem, nil;reduceMenu. position = ccp (winSize. width*0.5-30, 10);reduceMenu alignltemsVertically ;self addCh
10、ild :reduceMenu z:102 ; 初始化金币数gold = UlRollNumber allocinit;gold setNumber :originGold ;gold setPosition :ccp(168, 10);self addChild :gold z:102 ;-(void )addCannonLeaveCGSize winSize = CCDirector sharedDirector winSize ; cannonLevel +;lf( cannonLevel = 8) cannonLevel = 1; /remove cannon |CCScaleTo *
11、 narrow = CCScaleT o 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 ne
12、w cannon | cannnon = CCCannon spriteWithSpriteFrameName :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
13、;CCScaleTo * appear = CCScaleT o actionWithDuration :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&qu
14、ot;); | CCCannon * sp = sender; cannonSheet removeChild :sp cleanup :YES;3.触摸事件模块要点:子弹、大炮的跟随转向,子弹射出速度设置,越界判定(移动出画面)-(void) setAngle:( CGPoint )pointsprite:( CCSprite *)sp/CCLOG("setAngle"); |/设置旋转角度”int offX = point. x - cannnon .position .x;int offY = point. y - cannnon . position .y;if (
15、offY <= 0) return ;float ratio = ( float)offY /(float )offX;/直角三角形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 . ro
16、tation ;#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 <=return ;if (cannnon .cannonType = laser) 如果当前为超级武器, else
17、 cannnon setDisplayFrame : CCSpriteFrameCache sharedSpriteFrameCache | spriteFrameByName :NSStringstringWithFormat :"actor_cannon1_%i2.png" ,cannnon .cannonLevel ;self setAngle :pos sprite :nil;- (void)ccTouchesMoved:( NSSet *)touches withEvent:( UIEvent *)event |for (UITouch *touch in tou
18、ches) 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 touches) | CGSize winSize = CCDirector sharedDirector winSize;CGPoint po
19、s = 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) 用超级能量捕捉动物(待改) cannnon .cannonType = nomal; 发射完毕还原武器 else *(待改)*gold setNu
20、mber :(gold getNumber -cannnon .cannonType );/每次损耗 CCBullet *bullet = CCBullet spriteWithSpriteFrameName :NSString | stringWithFormat :"bullet0%i.png" ,cannnon .cannonLevel ;添加子弹bullet. position = cannnon .position ;bullet. isHit = NO;self setAngle :pos sprite :bullet; |/ Determine where w
21、e wish to shoot the projectile to | int realY = winSize. height + ;float ratio = (float) offX / (float) offY; |int realX = (realY - ratio + cannnon .position .x; CGPoint realDest = ccp(realX, realY); |/子弹会于一个恒定的速率按照射击方向前进 int offRealX = realX - cannnon .position .x;|int offRealY = realY - cannnon .p
22、osition .y;|float length = sqrtf(offRealX*offRealX)+(offRealY*offRealY);一旦我们有了距离,我们只是除以速度,以获得所需的时间。这是因为速度=距离/时间,或换句话说 时间=距离/速度。float velocity = 240/1; / 480pixels/1sec Ifloat realMoveDuration = length/velocity;移除子弹的动作CCMoveTo *move = CCMoveTo actionWithDuration :realMoveDuration position :realDest;C
23、CCallFuncO * removeBullet = CCCallFuncO actionWithTarget :self selector :selector (removeNet:) object:bullet;CCSequence * bulletSequence = CCSequence actions :move,removeBullet, nil;bullet. rotation = cannnon .rotation ;bullet runAction :bulletSequence;bulletSheet addChild :bullet; |删除子弹用于碰撞后及自动消失-
24、(void )removeNet:( id)sender |CCLOG("removeNet");CCNet * sp = ( CCNet *)sender; |bulletSheet removeChild :sp cleanup :YES ;4 .鱼类精灵的添加(使用纹理图集批量渲染) 要点:设置鱼的的动作,鱼的随机产生-(void) updateFish |while (fishSheet children count < maxNumberOfFish ) self addFish ;-(void)addFish |int type = rand ()%9+1
25、;NSMutableArray * oneFish = NSMutableArray array ;int number = 10;for (int i = 1; i < number; i+) |oneFish addObject :CCSpriteFrameCache sharedSpriteFrameCache spriteFrameByName :NSString |stringWithFormat :"fish0%i_0%i.png" ,type,i;CCRepeat * fishAction = CCRepeatForever actionWithActi
26、on :CCAnimate actionWithAnimation :CCAnimation animationWithFrames :oneFish delay :0.2f restoreOriginalFrame : YES;CCFish * fish = CCFish spriteWithSpriteFrameName : NSStringstringWithFormat :"fish0%i_0%i.png" ,type, 1 ;fish. scale = 0.6f;fish. fishLevel = type;fish. isCatch = NO;/默认为未被抓fi
27、sh runAction :fishAction;fish addPath ; 添加路线fish run;fishSheet addChild :fish z:100;5 .碰撞检测的处理要点:渔网与鱼,子弹和鱼的检测方式(点面触碰与面面触碰区别),鱼,网,子弹见逻辑关系(碰撞标志的设置),-(void) updateHit | CGSize winSize = CCDirector sharedDirector winSize;CCFish * fish;CCNet * net; |CCBullet * bullet;CCScaleTo * scale。= CCScaleTo actionW
28、ithDuration :0.3 scale:1.1;CCScaleTo * scalel = CCScaleTo actionWithDuration :0.3 scale:0.8; CCARRAY_FOREACH (bulletSheet children, bullet) 遍历子弹 if (bullet isHit ) continue ;if (bullet. position .x > (winSize. width + | bullet. position .x < (0- continue ;CCARRAY_FOREACH (fishSheet children, f
29、ish)if (bullet isHit) continue ;if (CGRectContainsPoint (fish boundingBox , bullet. position ) 子弹碰撞 bullet. isHit = YES;/shownet,remove bullet/CCLOG("remove bullet"); |bulletSheet removeChild :bullet cleanup :NO;/CCLOG("remove over"); |添加网CCNet * netCatch = CCNet spriteWithSprite
30、FrameName :NSString stringWithFormat :"net0%i.png" ,cannonLevel ;netCatch. position = bullet. position ;netSheet addChild :netCatch; |/CCLOG("add net over"); |网的动作CCCallFuncO * scaleNetAfterShow = CCCallFuncO actionWithTarget :self| selector :selector (afterShowNet:) object:netCa
31、tch;CCSequence * netSequence = CCSequenceactions :scale0,scale1,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 ) contin
32、ue ;if (CGRectContainsPoint (net boundingBox , fish. position ) if (!(fish randomCatch :cannonLevel ) continue ; elsefish. isCatch = YES;self updateEnergy :fish.fishLevel ;NSMutableArray * fishes = NSMutableArray array; int number; | if (fish. fishLevel < 8) number = 3;else number = 5;for (int i
33、= 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 :CCAnimate actionWithAnimation :CCAnimation animationWithFrames :fishes delay :0.2f times :2;CCSequence * animalSequence = CCSequence actions :fish_catch_act, CCCallFuncO ac
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年光伏发电项目电力安全施工合作协议
- 2025年夏季临时工劳务派遣服务合同
- 2025年酒店客房租赁及清洁服务合同
- 2025版脱温鸡冷链物流配送与购销合作合同
- 2025年北京幼儿园教育设施装饰装修建设合同
- 2025房地产项目增值服务与代理合作协议
- 2025版建筑垃圾处理与土石方工程综合服务合同
- 2025年定制化车辆租赁与市场推广服务合同
- 2025版山东建筑劳务分包合同
- 2025年食品配料员保密协议及离职后商业秘密保护责任书
- 护理事业近五年发展规划(2026-2030)
- 2025年工商管理硕士考试试卷及答案
- 2025餐饮劳动合同书 电子版
- 交通运输工程课件
- 中级消防设施操作员(维保检测方向)理论考试题及答案
- 2025年新辅警招聘考试题库(附答案)
- 2025年叉车安全培训考试题及答案
- 幼儿园大班科学《奇妙的盐》教案
- 广东省广州市2025届八年级英语第二学期期末教学质量检测试题含答案
- 学校法律服务协议书
- 夫妻流产同意协议书
评论
0/150
提交评论