设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 4121|回复: 2
打印 上一主题 下一主题

[交流讨论] 有关于八方向移动的整合

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
89 小时
注册时间
2017-3-31
帖子
27
跳转到指定楼层
1
发表于 2017-4-25 10:22:29 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
先感谢https://rpg.blue/forum.php?mod=viewthread&tid=386342 写出八方向/待机脚本的@VIPArcher 以及提出增强方案的 @doranikofu 大大。
简单测试了一下,由san shiro写的的analog move可以和8方向脚本重叠使用(SAN_AnalogMove要在方向脚本上面),另外SAN_AnalogMove2这个脚本与八方向脚本完全不兼容……

抛砖引玉,论坛有没有高手大大能使之兼容,优化成一个脚本?

整合.rar

29.93 KB, 下载次数: 212

八方向移动解决方案

Lv2.观梦者

梦石
0
星屑
676
在线时间
224 小时
注册时间
2006-12-7
帖子
839
2
发表于 2017-5-1 02:46:29 | 只看该作者
没看这个rar不过八向和analog是不冲突的
唯一要改的核心代码就是analog里面这段 注释掉之后analog插件就不会强制把人物八向专为四向
  1. // 内部4方向を更新
  2. Game_AnalogMove.prototype.updateDir4 = function(thisCharacter) {
  3.     this._dir4 = thisCharacter.direction();
  4. //doranikofu edit for 8dir    this._dir4 = this.dir8ToDir4(this.radianToDir8(this._directionRadian));
  5.     this._dir4 = this.radianToDir8(this._directionRadian);
  6. };
复制代码


然后要注意一下行走图的素材规格,analog的方向是
789
456
123
跟八向的默认好像不太一样

自己做的时候加了点别的增强触发事件判定/朝向的,其实也不太好用,仅供参考
  1. //===========================char direction for diagonal
  2. Game_Character.prototype.turnTowardCharacter = function(character) {
  3.     var sx = this.deltaXFrom(character._realX);
  4.     var sy = this.deltaYFrom(character._realY);
  5.         var radian = Math.atan2(sx,sy) + Math.PI;
  6.         this.setDirection(
  7.         radian < Math.PI / 8.0 *  1.0 ? 2 :
  8.         radian < Math.PI / 8.0 *  3.0 ? 3 :
  9.         radian < Math.PI / 8.0 *  5.0 ? 6 :
  10.         radian < Math.PI / 8.0 *  7.0 ? 9 :
  11.         radian < Math.PI / 8.0 *  9.0 ? 8 :
  12.         radian < Math.PI / 8.0 * 11.0 ? 7 :
  13.         radian < Math.PI / 8.0 * 13.0 ? 4 :
  14.         radian < Math.PI / 8.0 * 15.0 ? 1 : 2
  15.                 );
  16. };

  17. Game_Character.prototype.turnAwayFromCharacter = function(character) {
  18.     var sx = this.deltaXFrom(character._realX);
  19.     var sy = this.deltaYFrom(character._realY);
  20.         var radian = Math.atan2(sx,sy) + Math.PI;
  21.         this.setDirection(
  22.         radian < Math.PI / 8.0 *  1.0 ? 8 :
  23.         radian < Math.PI / 8.0 *  3.0 ? 7 :
  24.         radian < Math.PI / 8.0 *  5.0 ? 4 :
  25.         radian < Math.PI / 8.0 *  7.0 ? 1 :
  26.         radian < Math.PI / 8.0 *  9.0 ? 2 :
  27.         radian < Math.PI / 8.0 * 11.0 ? 3 :
  28.         radian < Math.PI / 8.0 * 13.0 ? 6 :
  29.         radian < Math.PI / 8.0 * 15.0 ? 9 : 8
  30.                 );
  31. };

  32. Game_Map.prototype.roundXWithDirection = function(x, d) {
  33.     return this.roundX(x + (d%3 == 0 ? 1 : (d+2)%3 == 0 ? -1 : 0));
  34. };

  35. Game_Map.prototype.roundYWithDirection = function(y, d) {
  36.     return this.roundY(y + (d < 4 ? 1 : d > 6 ? -1 : 0));
  37. };


  38. //expand trigger region, look to left
  39. Game_Map.prototype.roundXWithDirectionL = function(x, d) {
  40.                 switch(d) {
  41.                         case 1:   
  42.                                 return this.roundX(x+1);
  43.                                 break;
  44.                         case 2:   
  45.                                 return this.roundX(x+1);
  46.                                 break;
  47.                         case 8:   
  48.                                 return this.roundX(x-1);
  49.                                 break;
  50.                         case 9:   
  51.                                 return this.roundX(x-1);
  52.                                 break;
  53.                         default :
  54.                                 return this.roundX(x);
  55.                 };
  56. };

  57. Game_Map.prototype.roundYWithDirectionL = function(y, d) {
  58.                 switch(d) {
  59.                         case 3:   
  60.                                 return this.roundY(y-1);
  61.                                 break;
  62.                         case 4:   
  63.                                 return this.roundY(y+1);
  64.                                 break;
  65.                         case 6:   
  66.                                 return this.roundY(y-1);
  67.                                 break;
  68.                         case 7:   
  69.                                 return this.roundY(y+1);
  70.                                 break;
  71.                         default :
  72.                                 return this.roundY(y);
  73.                 };
  74. };
  75. //look to right
  76. Game_Map.prototype.roundXWithDirectionR = function(x, d) {
  77.                 switch(d) {
  78.                         case 2:   
  79.                                 return this.roundX(x-1);
  80.                                 break;
  81.                         case 3:   
  82.                                 return this.roundX(x-1);
  83.                                 break;
  84.                         case 7:   
  85.                                 return this.roundX(x+1);
  86.                                 break;
  87.                         case 8:   
  88.                                 return this.roundX(x+1);
  89.                                 break;
  90.                         default :
  91.                                 return this.roundX(x);
  92.                 };
  93. };

  94. Game_Map.prototype.roundYWithDirectionR = function(y, d) {
  95.                 switch(d) {
  96.                         case 1:   
  97.                                 return this.roundY(y-1);
  98.                                 break;
  99.                         case 4:   
  100.                                 return this.roundY(y-1);
  101.                                 break;
  102.                         case 6:   
  103.                                 return this.roundY(y+1);
  104.                                 break;
  105.                         case 9:   
  106.                                 return this.roundY(y+1);
  107.                                 break;
  108.                         default :
  109.                                 return this.roundY(y);
  110.                 };
  111. };

  112. //set 1/2 scroll for reduced map size --doranikofu
  113. Game_Map.prototype.parallaxOx = function() {
  114.     if (this._parallaxZero) {
  115.         return Math.floor(this._parallaxX * this.tileWidth());
  116.     } else if (this._parallaxLoopX) {
  117.         return this._parallaxX * this.tileWidth() / 2;
  118.     } else {
  119.         return 0;
  120.     }
  121. };

  122. Game_Map.prototype.parallaxOy = function() {
  123.     if (this._parallaxZero) {
  124.         return Math.floor(this._parallaxY * this.tileHeight());
  125.     } else if (this._parallaxLoopY) {
  126.         return this._parallaxY * this.tileHeight() / 2;
  127.     } else {
  128.         return 0;
  129.     }
  130. };

  131. Game_Player.prototype.checkEventTriggerHere = function(triggers) {
  132.     if (this.canStartLocalEvents()) {
  133.         this.startMapEvent(Math.round(this._realX), Math.round(this._realY), triggers, false);
  134.     }
  135. };


  136. Game_Player.prototype.checkEventTriggerThere = function(triggers) {
  137.     if (this.canStartLocalEvents()) {
  138.         var direction = this.direction();
  139.         var x1 = Math.round(this._realX);
  140.         var y1 = Math.round(this._realY);
  141.         var x2 = Math.floor($gameMap.roundXWithDirection(x1, direction));
  142.         var y2 = Math.floor($gameMap.roundYWithDirection(y1, direction));
  143.         this.startMapEvent(x2, y2, triggers, true);
  144.         if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x2, y2)) {
  145.             var x3 = Math.floor($gameMap.roundXWithDirectionL(x2, direction));
  146.             var y3 = Math.floor($gameMap.roundYWithDirectionL(y2, direction));
  147.             this.startMapEvent(x3, y3, triggers, true);
  148.                         if (!$gameMap.isAnyEventStarting() && $gameMap.isCounter(x3, y3)) {
  149.                                 var x4 = Math.floor($gameMap.roundXWithDirectionR(x2, direction));
  150.                                 var y4 = Math.floor($gameMap.roundYWithDirectionR(y2, direction));
  151.                                 this.startMapEvent(x4, y4, triggers, true);
  152.                         }
  153.         }
  154.     }
  155. };

  156. Game_Player.prototype.triggerTouchAction = function() {
  157.     if ($gameTemp.isDestinationValid()){
  158.         var direction = this.direction();
  159.         var x1 = this.x;
  160.         var y1 = this.y;
  161.         var x2 = $gameMap.roundXWithDirection(x1, direction);
  162.         var y2 = $gameMap.roundYWithDirection(y1, direction);
  163.         var x3 = $gameMap.roundXWithDirectionL(x2, direction);
  164.         var y3 = $gameMap.roundYWithDirectionL(y2, direction);
  165.         var x4 = $gameMap.roundXWithDirectionR(x2, direction);
  166.         var y4 = $gameMap.roundYWithDirectionR(y2, direction);
  167.         var destX = $gameTemp.destinationX();
  168.         var destY = $gameTemp.destinationY();
  169.         if (destX === x1 && destY === y1) {
  170.             return this.triggerTouchActionD1(x1, y1);
  171.         } else if (destX === x2 && destY === y2) {
  172.             return this.triggerTouchActionD2(x2, y2);
  173.         } else if (destX === x3 && destY === y3) {
  174.             return this.triggerTouchActionD3(x2, y2);
  175.         } else if (destX === x4 && destY === y4) {
  176.             return this.triggerTouchActionD3(x2, y2);
  177.         }
  178.     }
  179.     return false;
  180. };

复制代码


再一个问题就是斜向行动的时候地图上事件可能会抖动,浮点数计算的问题感觉不太好处理,试了一些办法都没彻底解决
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
89 小时
注册时间
2017-3-31
帖子
27
3
 楼主| 发表于 2017-5-7 11:12:29 | 只看该作者
doranikofu 发表于 2017-5-1 02:46
没看这个rar不过八向和analog是不冲突的
唯一要改的核心代码就是analog里面这段 注释掉之后analog插件就不 ...

非常感谢分享……大大的仙剑奇侠续传也有玩过,非常用心制作的良品。
移动时的浮动问题我也注意到了,会影响游戏体验……就好像自己折腾贴膜但是始终有灰……
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-13 04:11

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表