




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、捕鱼达人项目开发过程文档一、游戏资源文件UI图片image图片:包括火炮,鱼,子弹,渔网,金币,数字,背景图片以及其它CCFish类:实现鱼的曲线路线的移动与各种鱼捕捉概率的设置UINumber 类与 UIRollNumber 类二、游戏基本结构确定及搭建SysMenu(scene)GameMain(scene)Setting(layer)Help(scene)图1.1依次在项目中创建如有图类完成项目结构,在总体上把握项目实现内容、详细设计与各功能模块的实现程序编写流程1.系统菜单场景:1)2)3)添加初始化方法添加菜单添加菜单选项方法2.游戏场景1)2)3)4)5)6)添加初始化方法添加纹理
2、图集载入方法添加UI设计方法添加触摸事件处理方法 添加自动补充鱼更新方法 添加碰撞检测方法二 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.设置页面帮助场景游戏重要模块详细实现1 .纹理图集的使用与加载要点:精灵处于界面中的层次关系,如下为纹理图集加载代码CCSpriteFrameCache sharedSpriteFrameCache addSpriteFramesWithFile :"fish.plist"fishSheet = CCSpriteBatchNode batchNodeWithFile :&quo
4、t;fish.png"self addChild :fishSheet 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. 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 ;初始化金币数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.触摸事件模块要点:子弹、大炮的跟随转向,子弹射出速度设置,越界判定(移动出画面)- (void) setAngle:( CGPoint )point sprite:( CCSprite *)sp /CCLOG("setAngle"); |/设置旋转角度”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); /设置武器旋转角度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; 发射完毕还原武器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.鱼类精灵的添加(使用纹理图集批量渲染) 要点:设置鱼的的动作,鱼的随机产生-(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,碰撞检测的处理要点:渔网与鱼,子弹和鱼的检测方式(点面触碰与面面触碰区别),鱼,网,子弹见逻辑关系(碰撞标志的设置),-(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"); |添加网CCNet * netCatch = CCNet spriteWithSpriteFrameName :NSStringstringWithFormat :"net0%i.png" ,cannonLevel ;netCatch. position = bullet. position ;netSheet
32、 addChild :netCatch; |/CCLOG("add net over"); |网的动作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. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 租车策划方案范文
- 厂房承租合同协议书范本
- 石家庄彩妆项目商业计划书
- 2025年矮生盆栽番茄种子行业深度研究分析报告
- 【课件】第6课+凝神造像-中国传统雕塑+课件高中美术人教版(2019)美术鉴赏
- 加盟合同续费协议书怎么写
- 农村木屋买卖合同协议书
- 代购买股票合同协议书
- 安全教育饮食安全课件
- 2025年流体机械市场发展现状
- JTT663-2006 公路桥梁板式橡胶支座规格系列
- 学生退学家长委托书
- 高速公路投诉培训课件
- 交通劝导员上岗培训课件
- 本科毕业论文写作指导讲座课件
- TCACM 1524-2023 中医体重管理临床指南
- 校外培训机构办学申请书范文
- 村民心理知识知识讲座
- 管工基础知识培训课件
- 气体灭火系统介绍
- 粮食仓储监管管理制度
评论
0/150
提交评论