Cocos2D:塔防游戏制作之旅(十五)
2015-11-17 09:46
429 查看
Yes,貌似添加了好多的代码啊 ;] ,在你添加更多代码时,你可能注意到一些Xcode中的一些警告.首先你先忽略这些警告,我们先添加少量最终缺失的部分,然后再来解释上面代码做了什么!
在Enemy.m中修改如下:
代码中最重要的部分是Tower中的update方法.炮塔将定时检查是否敌人进入了攻击范围,如果是,我们的炮塔将旋转然后开始向敌人开火.
一旦一个敌人被标记为被攻击,一个方法将被调度执行用之前初始的攻击频率去发射子弹.轮流的,每个敌人保持攻击自身炮塔的一个列表,所以当该敌人被摧毁时那些炮塔可以得到信号去停止攻击.
在Enemy.m中修改如下:
// Add the following at the beginning of initWithTheGame: (within the "if" condition) attackedBy = [[NSMutableArray alloc] initWithCapacity:5]; // Replace the contents of getRemoved method with the following: -(void)getRemoved { for(Tower * attacker in attackedBy) { [attacker targetKilled]; } [self.parent removeChild:self cleanup:YES]; [theGame.enemies removeObject:self]; //Notify the game that we killed an enemy so we can check if we can send another wave [theGame enemyGotKilled]; } // Add the following methods -(void)getAttacked:(Tower *)attacker { [attackedBy addObject:attacker]; } -(void)gotLostSight:(Tower *)attacker { [attackedBy removeObject:attacker]; } -(void)getDamaged:(int)damage { currentHp -=damage; if(currentHp <=0) { [self getRemoved]; } }
代码中最重要的部分是Tower中的update方法.炮塔将定时检查是否敌人进入了攻击范围,如果是,我们的炮塔将旋转然后开始向敌人开火.
一旦一个敌人被标记为被攻击,一个方法将被调度执行用之前初始的攻击频率去发射子弹.轮流的,每个敌人保持攻击自身炮塔的一个列表,所以当该敌人被摧毁时那些炮塔可以得到信号去停止攻击.
相关文章推荐
- cocos2dx骨骼动画Armature源码剖析(一)
- cocos2dx骨骼动画Armature源码剖析(二)
- 教你如何解决XCODE升级后插件不能用问题
- 浅谈Xcode 开发工具 XCActionBar
- 剖析iOS开发中Cocos2d-x的内存管理相关操作
- xcode 4 制作静态库图文详解
- 解决 Xcode 6-Beta2 智能提示bug
- XCode编译速度慢的处理方法
- mac git xcrun error active developer path 错误
- Xcode使用教程详细讲解(全)
- Cocos2d开发1:Xcode与TexturePacker的集成
- windows下objective-c的cocoa框架编程,可以有图形界面哟
- iOS 5 cocos2d 游戏开发 3ff8 实战:第4章 你的第一个游戏
- quick-cocos2d-x for mac开发环境安装配置
- OSX下Xcode更新后,Git提示确认证书
- Unity3D上路_01-2D太空射击游戏
- Unity3D上路_02-第一视角射击游戏
- Unity3D上路_03-塔防游戏
- Unity3D上路_04-基础资源介绍
- Unity3D上路_05-网络相关