经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 程序设计 » 游戏设计 » 查看文章
Cocos经典游戏教程之仿皇室战争
来源:cnblogs  作者:优梦创客  时间:2019/8/12 8:41:50  对本文有异议

版权声明:

  • 本文原创发布于博客园"优梦创客"的博客空间(网址:http://www.cnblogs.com/raymondking123/)以及微信公众号"优梦创客"
  • 您可以自由转载,但必须加入完整的版权声明!

客户端

实现军队降落状态

  • 将军队空闲状态会进入移动状态改为进入ArmyCallState状态
  1. OnEnter(){
  2. // TODO: 选择路点,进入ArmyCallState
  3. this.card.fsm.ChangeState(ArmyCallState);
  4. }
  • 在ArmyCallState脚本中实现了ArmyCallState类(就是编写了ArmyCallState脚本)

在军队移动状态中增加播放行走的动画的功能

  1. //取得军队移动方向与上方向之间的弧度
  2. let radian = dir.signAngle(cc.Vec2.UP);
  3. //将弧度转为角度
  4. let angle = cc.misc.radiansToDegrees(radian);
  5. //如果军队移动方向与上方向的夹角在 -45到45之间,说明军队移动的方向是偏向上方的
  6. if (angle > -45 && angle < 45) {
  7. let clip = this.animation.getClips()[0]; //取得往上走的动画片段
  8. if (this.animation.currentClip != clip) { //如果当前播放的动画不是往上走的动画
  9. this.animation.play(clip.name); //播放往上走的动画
  10. }
  11. }
  12. else if (angle > 135 || angle < -135) { //下
  13. let clip = this.animation.getClips()[1]; //下走
  14. if (this.animation.currentClip != clip) {
  15. this.animation.play(clip.name);
  16. }
  17. }
  18. else if (angle >= -135 && angle <= -45) { //左
  19. let clip = this.animation.getClips()[2]; //左走
  20. if (this.animation.currentClip != clip) {
  21. this.animation.play(clip.name);
  22. }
  23. }
  24. else if (angle >= 45 && angle <= 135) { //右
  25. let clip = this.animation.getClips()[3]; //右走
  26. if (this.animation.currentClip != clip) {
  27. this.animation.play(clip.name);
  28. }
  29. }

在军队移动状态中增加获取移动速度和路点索引

  1. //取得初始路点(桥)
  2. let initialWaypoint = WayMgr.instance.ways[this.wayIdx].nodes[0].position;
  3. //取得终点(国王塔位置)
  4. let destination = WayMgr.instance.ways[this.wayIdx].nodes[1].position;
  5. //如果玩家到国王塔的距离 小于 桥到国王塔的距离
  6. if(destination.sub(this.card.pos).mag()<destination.sub(initialWaypoint).mag()){
  7. this.wpIdx = 1; //就将路点索引设为1(就是直接往国王塔走)
  8. }
  9. let moveSpeed = this.card.propsTmp.mspd //获取模板属性中的移动速度(枚举值)
  10. if(moveSpeed == MoveSpeed.Invalid){ //如果速度是无效
  11. this.spd = 0;
  12. }
  13. else if(moveSpeed == MoveSpeed.VeryFast){ //非常快
  14. this.spd = 50;
  15. }
  16. else if(moveSpeed == MoveSpeed.Fast){ //快
  17. this.spd = 40;
  18. }
  19. else if(moveSpeed == MoveSpeed.Mid){ //正常
  20. this.spd = 30;
  21. }
  22. else if(moveSpeed == MoveSpeed.Slow){ //慢
  23. this.spd = 20;
  24. }
  25. else if(moveSpeed == MoveSpeed.VerySlow){ //非常慢
  26. this.spd = 10;
  27. }

在军队移动中添加追踪敌人功能

  • 获取敌方战斗玩家
  • 遍历敌方战斗玩家的战斗卡牌数组
  • 从敌方战斗卡牌数组中找到离this战斗卡牌最近的敌方战斗卡牌
  • 如果那个敌方战斗卡牌在this战斗卡牌的视野内就往敌方那里走
  • 如果那个敌方战斗卡牌在this战斗卡牌的攻击范围内就进入军队攻击状态

原文链接:http://www.cnblogs.com/raymondking123/p/11326265.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号