查看: 8816|回复: 17

[原创发布] 像素移动

[复制链接]
梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-3-14
回帖
32
发表于 2016-6-7 17:25:25 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 moe2333 于 2016-6-7 17:35 编辑

暂时不支持座驾。
  1. //=============================================================================
  2. // PixelMovement.js
  3. //=============================================================================

  4. /*:
  5. * @plugindesc Like you don't know what this does.
  6. */

  7. (function () {
  8.     //-----------------------------------------------------------------------------

  9.     // An even number between 2 and 48, inclusive
  10.     var tileSection = 4;
  11.     // Gives you precise collision mask but can significantly compromise the performance
  12.     var analyzeTilesetBitmap = true;
  13.     // A section of the bitmap will be masked impassable if the valid pixel rate reaches this threshold
  14.     var bitmapAnalysisThreshold = 0.5;
  15.     // (x, y, width, height)
  16.     var characterCollisionBox = new Rectangle(1, 2, 2, 2);
  17.     // Tiles with this terrain tag are forced to be passable
  18.     var forcePassableTerrainTag = 3;
  19.     // Max distance between two followers
  20.     var followerDistance = 1;
  21.     // For debugging
  22.     var drawCollisionMask = true;
  23.     // [map, ladder, bush, counter, damageFloor, boat, ship], for debugging
  24.     var collisionMaskLayerColors = ['red', 'grey', 'green', 'yellow', 'crimson', 'lightBlue', 'blue'];

  25.     //-----------------------------------------------------------------------------
  26.     var toPixel = function (t) {
  27.         return t * tileSection;
  28.     };

  29.     var toTile = function (p) {
  30.         return p / tileSection;
  31.     };

  32.     //-----------------------------------------------------------------------------
  33.     // Table2

  34.     function Table2(xSize, ySize) {
  35.         this.initialize.apply(this, arguments);
  36.     }

  37.     Table2.prototype.initialize = function (xSize, ySize) {
  38.         this.xSize = xSize;
  39.         this.ySize = ySize;
  40.         this.data = [];
  41.     };

  42.     Table2.prototype.get = function (x, y) {
  43.         return this.data[y * this.xSize + x];
  44.     };

  45.     Table2.prototype.set = function (x, y, data) {
  46.         this.data[y * this.xSize + x] = data;
  47.     };

  48.     //-----------------------------------------------------------------------------
  49.     // Table3

  50.     function Table3() {
  51.         this.initialize.apply(this, arguments);
  52.     }

  53.     Table3.prototype.initialize = function (xSize, ySize, zSize) {
  54.         this.xSize = xSize;
  55.         this.ySize = ySize;
  56.         this.zSize = zSize;
  57.         this.data = [];
  58.     };

  59.     Table3.prototype.get = function (x, y, z) {
  60.         return this.data[z * this.ySize * this.xSize + y * this.xSize + x];
  61.     };

  62.     Table3.prototype.set = function (x, y, z, data) {
  63.         return this.data[z * this.ySize * this.xSize + y * this.xSize + x] = data;
  64.     };

  65.     //-----------------------------------------------------------------------------
  66.     // Bitmap

  67.     Bitmap.prototype.isOccupied = function (x, y, w, h, threshold) {
  68.         var data = this._context.getImageData(x, y, w, h).data;
  69.         var occupied = 0;
  70.         for (var i = 3; i < data.length; i += 4) {
  71.             if (data[i] === 255) {
  72.                 occupied++;
  73.             }
  74.         }
  75.         return (occupied / (data.length / 4)) > threshold;
  76.     };

  77.     //-----------------------------------------------------------------------------
  78.     // Tilemap

  79.     var aliasTilemapPrototypeUpdate = Tilemap.prototype.update;
  80.     Tilemap.prototype.update = function () {
  81.         aliasTilemapPrototypeUpdate.apply(this, arguments);
  82.         if (this._needRefreshCollisionMask && this.isReady()) {
  83.             this._needRefreshCollisionMask = false;
  84.             this.refreshCollisionMask();
  85.         }
  86.     };

  87.     var aliasTilemapPrototypeRefresh = Tilemap.prototype.refresh;
  88.     Tilemap.prototype.refresh = function () {
  89.         aliasTilemapPrototypeRefresh.apply(this, arguments);
  90.         this._needRefreshCollisionMask = true;
  91.     };

  92.     Tilemap.prototype.refreshCollisionMask = function () {
  93.         console.time('Collision Mask Generation');
  94.         $gameMap.collisionMask = new Table3($gameMap.widthPx(), $gameMap.heightPx(), 8);
  95.         this._tileCollisionMaskCaches = {};
  96.         for (var tx = 0; tx < this._mapWidth; tx++) {
  97.             for (var ty = 0; ty < this._mapHeight; ty++) {
  98.                 this.drawTileCollisionMask(tx, ty);
  99.             }
  100.         }
  101.         this._tileCollisionMaskCaches = null;
  102.         console.timeEnd('Collision Mask Generation');
  103.         if (drawCollisionMask) {
  104.             this.debugDrawCollisionMask();
  105.         }
  106.     };

  107.     Tilemap.prototype.drawTileCollisionMask = function (tx, ty) {
  108.         var forcePassable = $gameMap.terrainTag(tx, ty) === forcePassableTerrainTag;

  109.         var mcm = $gameMap.collisionMask;

  110.         var flags = this.flags;
  111.         var tileIds = $gameMap.layeredTiles(tx, ty);

  112.         var impassableSections = [];
  113.         var totalSections = tileSection * tileSection;

  114.         for (var tileId, flag, i = 0; i < tileIds.length; i++) {
  115.             tileId = tileIds[i];

  116.             if (!Tilemap.isVisibleTile(tileId)) {
  117.                 continue;
  118.             }

  119.             var tcm = this._tileCollisionMaskCaches[tileId];
  120.             if (tcm) {
  121.                 if (!forcePassable) {
  122.                     for (var sx = 0; sx < tileSection; sx++) {
  123.                         for (var sy = 0; sy < tileSection; sy++) {
  124.                             for (var z = 0; z < 8; z++) {
  125.                                 var bit = tcm.get(sx, sy, z);
  126.                                 if (bit === 1) {
  127.                                     mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, z, bit);
  128.                                     if (z === 0) { // tile collision layer
  129.                                         var sectionId = sy * tileSection + sx;
  130.                                         if (!impassableSections.contains(sectionId)) {
  131.                                             impassableSections.push(sectionId);
  132.                                         }
  133.                                     }
  134.                                 }
  135.                             }
  136.                         }
  137.                     }
  138.                     if (impassableSections.length >= totalSections) {
  139.                         break;
  140.                     } else {
  141.                         continue;
  142.                     }
  143.                 }
  144.             } else {
  145.                 tcm = new Table3(tileSection, tileSection, 8);
  146.                 this._tileCollisionMaskCaches[tileId] = tcm;
  147.             }

  148.             flag = flags[tileId];

  149.             // other layers of the collision mask
  150.             for (var bp = 5; bp < 9; bp++) { // ladder, bush, counter, damageFloor
  151.                 if ((flag & (1 << bp)) !== 0) {
  152.                     for (var sx = 0; sx < tileSection; sx++) {
  153.                         for (var sy = 0; sy < tileSection; sy++) {
  154.                             var z = bp - 4;
  155.                             mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, z, 1);
  156.                             tcm.set(sx, sy, z, 1);
  157.                         }
  158.                     }
  159.                 }
  160.             }
  161.             if (!forcePassable) {
  162.                 for (var bp = 9; bp < 12; bp++) { // boat, ship, airship
  163.                     if ((flag & (1 << bp)) === 0) {
  164.                         for (var sx = 0; sx < tileSection; sx++) {
  165.                             for (var sy = 0; sy < tileSection; sy++) {
  166.                                 var z = bp - 4;
  167.                                 mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, z, 1);
  168.                                 tcm.set(sx, sy, z, 1);
  169.                             }
  170.                         }
  171.                     }
  172.                 }
  173.             }

  174.             if (forcePassable) {
  175.                 break;
  176.             }

  177.             // 0th layer of the collision mask
  178.             if ((flag & 0xf) === 0xf) { // all dirs are not passable
  179.                 if (analyzeTilesetBitmap) {
  180.                     if (Tilemap.isAutotile(tileId)) { // TODO: need to check the collision masks for autotiles too
  181.                         for (var sx = 0; sx < tileSection; sx++) {
  182.                             for (var sy = 0; sy < tileSection; sy++) {
  183.                                 mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, 0, 1);
  184.                                 tcm.set(sx, sy, 0, 1);
  185.                             }
  186.                         }
  187.                         break;
  188.                     } else {
  189.                         var bitmap = this.bitmaps[Tilemap.isTileA5(tileId) ? 4 : 5 + Math.floor(tileId / 256)];
  190.                         var tw = this._tileWidth;
  191.                         var th = this._tileHeight;
  192.                         var sw = $gameMap.tileWidthPx();
  193.                         var sh = $gameMap.tileHeightPx();
  194.                         var bx = (Math.floor(tileId / 128) % 2 * 8 + tileId % 8) * tw;
  195.                         var by = (Math.floor(tileId % 256 / 8) % 16) * th;
  196.                         for (var sx = 0; sx < tileSection; sx++) {
  197.                             for (var sy = 0; sy < tileSection; sy++) {
  198.                                 if (bitmap.isOccupied(bx + sx * sw, by + sy * sh, sw, sh, bitmapAnalysisThreshold)) {
  199.                                     mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, 0, 1);
  200.                                     tcm.set(sx, sy, 0, 1);
  201.                                     var sectionId = sy * tileSection + sx;
  202.                                     if (!impassableSections.contains(sectionId)) {
  203.                                         impassableSections.push(sectionId);
  204.                                     }
  205.                                 }
  206.                             }
  207.                         }
  208.                         if (impassableSections.length >= totalSections) {
  209.                             break;
  210.                         }
  211.                     }
  212.                 } else {
  213.                     for (var sx = 0; sx < tileSection; sx++) {
  214.                         for (var sy = 0; sy < tileSection; sy++) {
  215.                             mcm.set(toPixel(tx) + sx, toPixel(ty) + sy, 0, 1);
  216.                             tcm.set(sx, sy, 0, 1);
  217.                         }
  218.                     }
  219.                     break;
  220.                 }
  221.             } else if ((flag & 0xf) !== 0) { // some dirs are passable, but not all
  222.                 for (var bp = 0; bp < 4; bp++) {
  223.                     if ((flag & (1 << bp)) !== 0) {
  224.                         switch (bp) {
  225.                             case 0: // down
  226.                                 for (var sx = 0; sx < tileSection; sx++) {
  227.                                     mcm.set(toPixel(tx) + sx, toPixel(ty) + tileSection - 1, 0, 1);
  228.                                     tcm.set(sx, tileSection - 1, 0, 1)
  229.                                 }
  230.                                 break;
  231.                             case 1: // left
  232.                                 for (var sy = 0; sy < tileSection; sy++) {
  233.                                     mcm.set(toPixel(tx), toPixel(ty) + sy, 0, 1);
  234.                                     tcm.set(0, sy, 0, 1)
  235.                                 }
  236.                                 break;
  237.                             case 2: // right
  238.                                 for (var sy = 0; sy < tileSection; sy++) {
  239.                                     mcm.set(toPixel(tx) + tileSection - 1, toPixel(ty) + sy, 0, 1);
  240.                                     tcm.set(tileSection - 1, sy, 0, 1)
  241.                                 }
  242.                                 break;
  243.                             case 3: // up
  244.                                 for (var sx = 0; sx < tileSection; sx++) {
  245.                                     mcm.set(toPixel(tx) + sx, toPixel(ty), 0, 1);
  246.                                     tcm.set(sx, 0, 0, 1)
  247.                                 }
  248.                                 break;
  249.                         }
  250.                     }
  251.                 }
  252.             }
  253.         }
  254.     };

  255.     Tilemap.prototype.debugDrawCollisionMask = function () {
  256.         var cm = $gameMap.collisionMask;
  257.         var sw = $gameMap.tileWidthPx();
  258.         var sh = $gameMap.tileHeightPx();
  259.         for (var layerIndex = 0; layerIndex < 7; layerIndex++) {
  260.             var sprite = new Sprite(new Bitmap(this._mapWidth * this._tileWidth, this._mapHeight * this._tileHeight));
  261.             sprite.pivot = this.origin;
  262.             sprite.opacity = 80;
  263.             for (var px = 0; px < cm.xSize; px++) {
  264.                 for (var py = 0; py < cm.ySize; py++) {
  265.                     if (cm.get(px, py, layerIndex) === 1) {
  266.                         sprite.bitmap.fillRect(px * sw, py * sh, sw, sh, collisionMaskLayerColors[layerIndex]);
  267.                     }
  268.                 }
  269.             }
  270.             this.parent.addChild(sprite);
  271.         }
  272.     };

  273.     //------------------------------------------------------------
  274.     // Game_Temp

  275.     var aliasGameTempPrototypeInitialize = Game_Temp.prototype.initialize;
  276.     Game_Temp.prototype.initialize = function () {
  277.         aliasGameTempPrototypeInitialize.apply(this, arguments);
  278.         this._destinationPx = null;
  279.         this._destinationPy = null;
  280.         this._route = null;
  281.     };

  282.     Game_Temp.prototype.isDestinationValid = function () {
  283.         return this._route && this._route.length > 0;
  284.     };

  285.     Game_Temp.prototype.setDestination = function (px, py) {
  286.         if (!this._route || px !== this._destinationPx || py !== this._destinationPy) {
  287.             this._destinationPx = px;
  288.             this._destinationPy = py;
  289.             this._route = $gamePlayer.findRouteTo(px, py);
  290.         }
  291.     };

  292.     Game_Temp.prototype.clearDestination = function () {
  293.         this._destinationPx = null;
  294.         this._destinationPy = null;
  295.         this._route = null;
  296.     };

  297.     Game_Temp.prototype.destinationPx = function () {
  298.         return this._destinationPx;
  299.     };

  300.     Game_Temp.prototype.destinationPy = function () {
  301.         return this._destinationPy;
  302.     };

  303.     Game_Temp.prototype.nextDirection = function () {
  304.         return this._route ? this._route.pop() : 0;
  305.     };

  306.     //------------------------------------------------------------
  307.     // Game_Actor
  308.    
  309.     /* TODO: Only damage characters that are on the damage floor
  310.     Game_Actor.prototype.checkFloorEffect = function () {
  311.         if ($gamePlayer.isOnDamageFloor()) {
  312.             this.executeFloorDamage();
  313.         }
  314.     };
  315.     */

  316.     //------------------------------------------------------------
  317.     // Game_Map

  318.     Object.defineProperty(Game_Map.prototype, 'collisionMask', {
  319.         get: function () {
  320.             return this._collisionMask;
  321.         },
  322.         set: function (value) {
  323.             this._collisionMask = value;
  324.         },
  325.         configurable: true
  326.     });

  327.     Game_Map.prototype.isCollisionMaskSet = function () {
  328.         return this._collisionMask !== null;
  329.     };

  330.     var aliasGameMapPrototypeInitialize = Game_Map.prototype.initialize;
  331.     Game_Map.prototype.initialize = function () {
  332.         aliasGameMapPrototypeInitialize.apply(this, arguments);
  333.         this._collisionMask = null;
  334.     };

  335.     Game_Map.prototype.tileWidthPx = function () {
  336.         return this.tileWidth() / tileSection;
  337.     };

  338.     Game_Map.prototype.tileHeightPx = function () {
  339.         return this.tileHeight() / tileSection;
  340.     };

  341.     Game_Map.prototype.widthPx = function () {
  342.         return $dataMap.width * tileSection;
  343.     };

  344.     Game_Map.prototype.heightPx = function () {
  345.         return $dataMap.height * tileSection;
  346.     };

  347.     Game_Map.prototype.adjustPx = function (px) {
  348.         return toPixel(this.adjustX(toTile(px)));
  349.     };

  350.     Game_Map.prototype.adjustPy = function (py) {
  351.         return toPixel(this.adjustY(toTile(py)));
  352.     };

  353.     Game_Map.prototype.roundPx = function (px) {
  354.         return this.isLoopHorizontal() ? px.mod(this.widthPx()) : px;
  355.     };

  356.     Game_Map.prototype.roundPy = function (py) {
  357.         return this.isLoopVertical() ? py.mod(this.heightPx()) : py;
  358.     };

  359.     Game_Map.prototype.pxWithDirection = function (px, d) {
  360.         return px + (d === 6 ? 1 : d === 4 ? -1 : 0);
  361.     };

  362.     Game_Map.prototype.pyWithDirection = function (py, d) {
  363.         return py + (d === 2 ? 1 : d === 8 ? -1 : 0);
  364.     };

  365.     Game_Map.prototype.roundPxWithDirection = function (px, d) {
  366.         return this.roundPx(px + (d === 6 ? 1 : d === 4 ? -1 : 0));
  367.     };

  368.     Game_Map.prototype.roundPyWithDirection = function (py, d) {
  369.         return this.roundPy(py + (d === 2 ? 1 : d === 8 ? -1 : 0));
  370.     };

  371.     Game_Map.prototype.deltaPx = function (px1, px2) {
  372.         var result = px1 - px2;
  373.         if (this.isLoopHorizontal() && Math.abs(result) > this.widthPx() / 2) {
  374.             result += result < 0 ? this.widthPx() : -this.widthPx();
  375.         }
  376.         return result;
  377.     };

  378.     Game_Map.prototype.deltaPy = function (py1, py2) {
  379.         var result = py1 - py2;
  380.         if (this.isLoopVertical() && Math.abs(result) > this.heightPx() / 2) {
  381.             result += result < 0 ? this.heightPx() : -this.heightPx();
  382.         }
  383.         return result;
  384.     };

  385.     Game_Map.prototype.distancePx = function (px1, py1, px2, py2) {
  386.         return Math.abs(this.deltaPx(px1, px2)) + Math.abs(this.deltaPy(py1, py2));
  387.     };

  388.     Game_Map.prototype.canvasToMapPx = function (x) {
  389.         return this.roundPx(Math.round((this._displayX * this.tileWidth() + x) / $gameMap.tileWidthPx()));
  390.     };

  391.     Game_Map.prototype.canvasToMapPy = function (y) {
  392.         return this.roundPy(Math.round((this._displayY * this.tileHeight() + y) / $gameMap.tileHeightPx()));
  393.     };

  394.     Game_Map.prototype.collidedEventsPx = function (px, py, cm) {
  395.         return this.events().filter(function (event) {
  396.             return $gameMap.areTwoCollisionMasksCollided(px, py, cm, event.px, event.py, event.collisionMask);
  397.         });
  398.     };

  399.     Game_Map.prototype.areTwoCollisionMasksCollided = function (px1, py1, cm1, px2, py2, cm2) {
  400.         var xs1 = cm1.xSize;
  401.         var ys1 = cm1.ySize;
  402.         var xs2 = cm2.xSize;
  403.         var ys2 = cm2.ySize;
  404.         var spx1 = px1 - xs1 / 2;
  405.         var spy1 = py1 - ys1;
  406.         var spx2 = px2 - xs2 / 2;
  407.         var spy2 = py2 - ys2;
  408.         if (spx1 > spx2 + xs2 || spx1 + xs1 < spx2 || spy1 > spy2 + ys2 || spy1 + ys1 < spy2) {
  409.             return false;
  410.         }
  411.         var mpw = this.widthPx();
  412.         var poses1 = [];
  413.         var poses2 = [];
  414.         for (var cmx1 = 0; cmx1 < xs1; cmx1++) {
  415.             for (var cmy1 = 0; cmy1 < ys1; cmy1++) {
  416.                 cm1.get(cmx1, cmy1) && poses1.push(this.roundPy(spy1 + cmy1) * mpw + this.roundPx(spx1 + cmx1));
  417.             }
  418.         }
  419.         for (var cmx2 = 0; cmx2 < xs2; cmx2++) {
  420.             for (var cmy2 = 0; cmy2 < ys2; cmy2++) {
  421.                 cm2.get(cmx2, cmy2) && poses2.push(this.roundPy(spy2 + cmy2) * mpw + this.roundPx(spx2 + cmx2));
  422.             }
  423.         }
  424.         for (var i = 0; i < poses1.length; i++) {
  425.             for (var j = 0; j < poses2.length; j++) {
  426.                 if (poses1[i] === poses2[j]) {
  427.                     return true;
  428.                 }
  429.             }
  430.         }
  431.         return false;
  432.     };

  433.     Game_Map.prototype.isValidPx = function (px, py) {
  434.         return px > -1 && px < this.widthPx() && py > -1 && py < this.heightPx();
  435.     };

  436.     Game_Map.prototype.isPassablePx = function (px, py) {
  437.         return !this._collisionMask.get(px, py, 0);
  438.     };

  439.     Game_Map.prototype.isPassableWithCollisionMask = function (px, py, cm) {
  440.         var spx = px - cm.xSize / 2;
  441.         var spy = py - cm.ySize;
  442.         for (var cmx = 0; cmx < cm.xSize; cmx++) {
  443.             for (var cmy = 0; cmy < cm.ySize; cmy++) {
  444.                 if (cm.get(cmx, cmy)) {
  445.                     var apx = this.roundPx(spx + cmx);
  446.                     var apy = this.roundPy(spy + cmy);
  447.                     if (!this.isValidPx(apx, apy) || !this.isPassablePx(apx, apy)) {
  448.                         return false;
  449.                     }
  450.                 }
  451.             }
  452.         }
  453.         return true;
  454.     };

  455.     Game_Map.prototype.isBoatPassablePx = function (px, py) {
  456.         return false;
  457.     };

  458.     Game_Map.prototype.isShipPassablePx = function (px, py) {
  459.         return false;
  460.     };

  461.     Game_Map.prototype.isAirshipLandOkPx = function (px, py) {
  462.         return false;
  463.     };

  464.     Game_Map.prototype.isLadderPx = function (px, py) {
  465.         if (!this.isCollisionMaskSet()) {
  466.             return false;
  467.         }
  468.         return this.isValidPx(px, py) && this._collisionMask.get(px, py, 1);
  469.     };

  470.     Game_Map.prototype.isBushPx = function (px, py) {
  471.         if (!this.isCollisionMaskSet()) {
  472.             return false;
  473.         }
  474.         return this.isValidPx(px, py) && this._collisionMask.get(px, py, 2);
  475.     };

  476.     Game_Map.prototype.isCounterPx = function (px, py) {
  477.         if (!this.isCollisionMaskSet()) {
  478.             return false;
  479.         }
  480.         return this.isValidPx(px, py) && this._collisionMask.get(px, py, 3);
  481.     };

  482.     Game_Map.prototype.isDamageFloorPx = function (px, py) {
  483.         if (!this.isCollisionMaskSet()) {
  484.             return false;
  485.         }
  486.         return this.isValidPx(px, py) && this._collisionMask.get(px, py, 4);
  487.     };

  488.     //------------------------------------------------------------
  489.     // Game_CharacterBase

  490.     Object.defineProperty(Game_CharacterBase.prototype, 'collisionMask', {
  491.         get: function () {
  492.             return this._collisionMask
  493.         },
  494.         set: function (value) {
  495.             this._collisionMask = value
  496.         },
  497.         configurable: true
  498.     });

  499.     Object.defineProperty(Game_CharacterBase.prototype, 'px', {
  500.         get: function () {
  501.             return this._px
  502.         },
  503.         configurable: true
  504.     });

  505.     Object.defineProperty(Game_CharacterBase.prototype, 'py', {
  506.         get: function () {
  507.             return this._py
  508.         },
  509.         configurable: true
  510.     });

  511.     var aliasGameCharacterBasePrototypeInitMembers = Game_CharacterBase.prototype.initMembers;
  512.     Game_CharacterBase.prototype.initMembers = function () {
  513.         aliasGameCharacterBasePrototypeInitMembers.apply(this, arguments);
  514.         this._px = 0;
  515.         this._py = 0;
  516.         this._realPx = 0;
  517.         this._realPy = 0;
  518.         this.createCollisionMask();
  519.     };

  520.     Game_CharacterBase.prototype.createCollisionMask = function () { // TODO: Support bitmap analysis and custom collision box
  521.         this._collisionMask = new Table2(tileSection, tileSection);
  522.         var box = characterCollisionBox;
  523.         for (var x = box.x; x < box.x + box.width; x++) {
  524.             for (var y = box.y; y < box.y + box.height; y++) {
  525.                 this._collisionMask.set(x, y, 1);
  526.             }
  527.         }
  528.     };

  529.     Game_CharacterBase.prototype.synchronizeTileCoordinate = function () {
  530.         this._realX = toTile(this._realPx);
  531.         this._realY = toTile(this._realPy);
  532.         this._x = Math.floor(this._realX);
  533.         this._y = Math.floor(this._realY);
  534.     };

  535.     Game_CharacterBase.prototype.isMoving = function () {
  536.         return this._realPx !== this._px || this._realPy !== this._py;
  537.     };

  538.     Game_CharacterBase.prototype.canPassPx = function (px, py, d) {
  539.         var npx = $gameMap.roundPxWithDirection(px, d);
  540.         var npy = $gameMap.roundPyWithDirection(py, d);
  541.         if (this.isThrough() || this.isDebugThrough()) {
  542.             return true;
  543.         }
  544.         if (!this.isMapPassablePx(px, py, d)) {
  545.             return false;
  546.         }
  547.         if (this.isCollidedWithCharactersPx(npx, npy)) {
  548.             return false;
  549.         }
  550.         return true;
  551.     };

  552.     Game_CharacterBase.prototype.canPassDiagonallyPx = function (px, py, horz, vert) {
  553.         var npx = $gameMap.roundPxWithDirection(px, horz);
  554.         var npy = $gameMap.roundPyWithDirection(py, vert);
  555.         if (this.canPassPx(px, py, vert) && this.canPassPx(px, npy, horz)) {
  556.             return true;
  557.         }
  558.         if (this.canPassPx(px, py, horz) && this.canPassPx(npx, py, vert)) {
  559.             return true;
  560.         }
  561.         return false;
  562.     };

  563.     Game_CharacterBase.prototype.isMapPassablePx = function (px, py, d) {
  564.         /*
  565.          var px2 = $gameMap.roundPxWithDirection(px, d);
  566.          var py2 = $gameMap.roundPyWithDirection(py, d);
  567.          return $gameMap.isPassableWithCollisionMask(px, py, this._collisionMask) && $gameMap.isPassableWithCollisionMask(px2, py2, this._collisionMask);
  568.          */
  569.         return $gameMap.isPassableWithCollisionMask($gameMap.roundPxWithDirection(px, d), $gameMap.roundPyWithDirection(py, d), this._collisionMask);
  570.     };

  571.     Game_CharacterBase.prototype.isCollidedWithCharactersPx = function (px, py) {
  572.         return this.isCollidedWithEventsPx(px, py) || this.isCollidedWithVehiclesPx(px, py);
  573.     };

  574.     Game_CharacterBase.prototype.isCollidedWithEventsPx = function (px, py) {
  575.         var events = $gameMap.events();
  576.         var cm = this._collisionMask;
  577.         var self = this;
  578.         return events.some(function (event) {
  579.             return event !== self && !event.isThrough() && event.isNormalPriority() && $gameMap.areTwoCollisionMasksCollided(px, py, cm, event.px, event.py, event.collisionMask);
  580.         });
  581.     };

  582.     Game_CharacterBase.prototype.isCollidedWithVehiclesPx = function (px, py) {
  583.         return false;
  584.     };

  585.     Game_CharacterBase.prototype.setPosition = function (tx, ty) {
  586.         this.setPositionPx(toPixel(tx) + tileSection / 2, toPixel(ty) + tileSection);
  587.     };
  588.     Game_CharacterBase.prototype.setPositionPx = function (px, py) {
  589.         this._px = Math.round(px);
  590.         this._py = Math.round(py);
  591.         this._realPx = px;
  592.         this._realPy = py;
  593.         this.synchronizeTileCoordinate();
  594.     };

  595.     Game_CharacterBase.prototype.copyPosition = function (character) {
  596.         this._direction = character._direction;
  597.         this._px = character._px;
  598.         this._py = character._py;
  599.         this._realPx = character._realPx;
  600.         this._realPy = character._realPy;
  601.         this.synchronizeTileCoordinate();
  602.     };

  603.     Game_CharacterBase.prototype.locate = function (tx, ty) {
  604.         this.locatePx(toPixel(tx) + tileSection / 2, toPixel(ty) + tileSection);
  605.     };
  606.     Game_CharacterBase.prototype.locatePx = function (px, py) {
  607.         this.setPositionPx(px, py);
  608.         this.straighten();
  609.         this.refreshBushDepth();
  610.     };

  611.     Game_CharacterBase.prototype.screenX = function () {
  612.         return Math.round(toPixel(this.scrolledX()) * $gameMap.tileWidthPx());
  613.     };

  614.     Game_CharacterBase.prototype.screenY = function () {
  615.         return Math.round(toPixel(this.scrolledY()) * $gameMap.tileHeightPx() - this.shiftY() - this.jumpHeight());
  616.     };

  617.     Game_CharacterBase.prototype.update = function() {
  618.         this.updateAnimation();
  619.         if (this.isStopping()) {
  620.             this.updateStop();
  621.         }
  622.         if (this.isJumping()) {
  623.             this.updateJump();
  624.         } else if (this.isMoving()) {
  625.             this.updateMove();
  626.         }
  627.     };

  628.     Game_CharacterBase.prototype.updateJump = function () {
  629.         this._jumpCount--;
  630.         this._realPx = (this._realPx * this._jumpCount + this._px) / (this._jumpCount + 1.0);
  631.         this._realPy = (this._realPy * this._jumpCount + this._py) / (this._jumpCount + 1.0);
  632.         this.refreshBushDepth();
  633.         if (this._jumpCount === 0) {
  634.             this._realPx = this._px = $gameMap.roundPx(this._px);
  635.             this._realPy = this._py = $gameMap.roundPy(this._py);
  636.         }
  637.         this.synchronizeTileCoordinate();
  638.     };

  639.     Game_CharacterBase.prototype.updateMove = function () {
  640.         var dpf = toPixel(this.distancePerFrame());
  641.         if (this._px < this._realPx) {
  642.             this._realPx = Math.max(this._realPx - dpf, this._px);
  643.         }
  644.         if (this._px > this._realPx) {
  645.             this._realPx = Math.min(this._realPx + dpf, this._px);
  646.         }
  647.         if (this._py < this._realPy) {
  648.             this._realPy = Math.max(this._realPy - dpf, this._py);
  649.         }
  650.         if (this._py > this._realPy) {
  651.             this._realPy = Math.min(this._realPy + dpf, this._py);
  652.         }
  653.         this.synchronizeTileCoordinate();
  654.         if (!this.isMoving()) {
  655.             this.refreshBushDepth();
  656.         }
  657.     };

  658.     Game_CharacterBase.prototype.isOnLadder = function () {
  659.         var cm = this._collisionMask;
  660.         var xs = cm.xSize;
  661.         var ys = cm.ySize;
  662.         var spx = this._px - xs / 2;
  663.         var spy = this._py - ys;
  664.         for (var cmx = 0; cmx < xs; cmx++) {
  665.             for (var cmy = 0; cmy < ys; cmy++) {
  666.                 if ($gameMap.isLadderPx(spx + cmx, spy + cmy)) {
  667.                     return true;
  668.                 }
  669.             }
  670.         }
  671.         return false;
  672.     };

  673.     Game_CharacterBase.prototype.isOnBush = function () {
  674.         var cm = this._collisionMask;
  675.         var xs = cm.xSize;
  676.         var ys = cm.ySize;
  677.         var spx = this._px - xs / 2;
  678.         var spy = this._py - ys;
  679.         for (var cmx = 0; cmx < xs; cmx++) {
  680.             for (var cmy = 0; cmy < ys; cmy++) {
  681.                 if (!$gameMap.isBushPx(spx + cmx, spy + cmy)) {
  682.                     return false;
  683.                 }
  684.             }
  685.         }
  686.         return true;
  687.     };

  688.     Game_CharacterBase.prototype.isOnDamageFloor = function () {
  689.         var cm = this._collisionMask;
  690.         var xs = cm.xSize;
  691.         var ys = cm.ySize;
  692.         var spx = this._px - xs / 2;
  693.         var spy = this._py - ys;
  694.         for (var cmx = 0; cmx < xs; cmx++) {
  695.             for (var cmy = 0; cmy < ys; cmy++) {
  696.                 if ($gameMap.isDamageFloorPx(spx + cmx, spy + cmy)) {
  697.                     return true;
  698.                 }
  699.             }
  700.         }
  701.         return false;
  702.     };

  703.     Game_CharacterBase.prototype.isFacingCounter = function () {
  704.         var cm = this._collisionMask;
  705.         var direction = this.direction();
  706.         var npx = $gameMap.roundPxWithDirection(this._px, direction);
  707.         var npy = $gameMap.roundPyWithDirection(this._py, direction);
  708.         var xs = cm.xSize;
  709.         var ys = cm.ySize;
  710.         var spx = npx - xs / 2;
  711.         var spy = npy - ys;
  712.         for (var cmx = 0; cmx < xs; cmx++) {
  713.             for (var cmy = 0; cmy < ys; cmy++) {
  714.                 if ($gameMap.isCounterPx(spx + cmx, spy + cmy)) {
  715.                     return true;
  716.                 }
  717.             }
  718.         }
  719.         return false;
  720.     };

  721.     Game_CharacterBase.prototype.checkEventTriggerTouchFrontPx = function (d) {
  722.         this.checkEventTriggerTouchPx($gameMap.roundPxWithDirection(this._px, d), $gameMap.roundPyWithDirection(this._py, d));
  723.     };

  724.     Game_CharacterBase.prototype.checkEventTriggerTouchPx = function (px, py) {
  725.         return false;
  726.     };

  727.     Game_CharacterBase.prototype.moveStraight = function (d) {
  728.         this.setMovementSuccess(this.canPassPx(this._px, this._py, d));
  729.         if (this.isMovementSucceeded()) {
  730.             this.setDirection(d);
  731.             this._px = $gameMap.roundPxWithDirection(this._px, d);
  732.             this._py = $gameMap.roundPyWithDirection(this._py, d);
  733.             this._realPx = $gameMap.pxWithDirection(this._px, this.reverseDir(d));
  734.             this._realPy = $gameMap.pyWithDirection(this._py, this.reverseDir(d));
  735.             this.increaseSteps();
  736.         } else {
  737.             this.setDirection(d);
  738.             this.checkEventTriggerTouchFrontPx(d);
  739.         }
  740.     };

  741.     Game_CharacterBase.prototype.moveDiagonally = function (horz, vert) {
  742.         this.setMovementSuccess(this.canPassDiagonallyPx(this._px, this._py, horz, vert));
  743.         if (this.isMovementSucceeded()) {
  744.             this._px = $gameMap.roundPxWithDirection(this._px, horz);
  745.             this._py = $gameMap.roundPyWithDirection(this._py, vert);
  746.             this._realPx = $gameMap.pxWithDirection(this._px, this.reverseDir(horz));
  747.             this._realPy = $gameMap.pyWithDirection(this._py, this.reverseDir(vert));
  748.             this.increaseSteps();
  749.         }
  750.         if (this._direction === this.reverseDir(horz)) this.setDirection(horz);
  751.         if (this._direction === this.reverseDir(vert)) this.setDirection(vert);
  752.     };

  753.     Game_CharacterBase.prototype.moveDir8 = function (d) {
  754.         switch (d) {
  755.             case 2:
  756.             case 4:
  757.             case 6:
  758.             case 8:
  759.                 this.moveStraight(d);
  760.                 break;
  761.             case 1:
  762.                 this.moveDiagonally(4, 2);
  763.                 break;
  764.             case 3:
  765.                 this.moveDiagonally(6, 2);
  766.                 break;
  767.             case 7:
  768.                 this.moveDiagonally(4, 8);
  769.                 break;
  770.             case 9:
  771.                 this.moveDiagonally(6, 8);
  772.                 break;
  773.         }
  774.     };

  775.     Game_CharacterBase.prototype.jump = function (xPlus, yPlus) {
  776.         if (Math.abs(xPlus) > Math.abs(yPlus)) {
  777.             if (xPlus !== 0) {
  778.                 this.setDirection(xPlus < 0 ? 4 : 6);
  779.             }
  780.         } else {
  781.             if (yPlus !== 0) {
  782.                 this.setDirection(yPlus < 0 ? 8 : 2);
  783.             }
  784.         }
  785.         this._px += toPixel(xPlus);
  786.         this._py += toPixel(yPlus);
  787.         var distance = Math.round(Math.sqrt(xPlus * xPlus + yPlus * yPlus));
  788.         this._jumpPeak = 10 + distance - this._moveSpeed;
  789.         this._jumpCount = this._jumpPeak * 2;
  790.         this.resetStopCount();
  791.         this.straighten();
  792.     };

  793.     //------------------------------------------------------------
  794.     // Game_Character
  795.     Game_Character.prototype.deltaPxFrom = function (px) {
  796.         return $gameMap.deltaPx(this._px, px);
  797.     };

  798.     Game_Character.prototype.deltaPyFrom = function (py) {
  799.         return $gameMap.deltaPy(this._py, py);
  800.     };

  801.     Game_Character.prototype.moveRandom = function () {
  802.         var d = 2 + Math.randomInt(4) * 2;
  803.         if (this.canPassPx(this.px, this.py, d)) {
  804.             this.moveStraight(d);
  805.         }
  806.     };

  807.     Game_Character.prototype.moveTowardCharacter = function (character) {
  808.         var dpx = this.deltaPxFrom(character.px);
  809.         var dpy = this.deltaPyFrom(character.py);
  810.         if (Math.abs(dpx) > Math.abs(dpy)) {
  811.             this.moveStraight(dpx > 0 ? 4 : 6);
  812.             if (!this.isMovementSucceeded() && dpy !== 0) {
  813.                 this.moveStraight(dpy > 0 ? 8 : 2);
  814.             }
  815.         } else if (dpy !== 0) {
  816.             this.moveStraight(dpy > 0 ? 8 : 2);
  817.             if (!this.isMovementSucceeded() && dpx !== 0) {
  818.                 this.moveStraight(dpx > 0 ? 4 : 6);
  819.             }
  820.         }
  821.     };

  822.     Game_Character.prototype.moveAwayFromCharacter = function (character) {
  823.         var dpx = this.deltaPxFrom(character.px);
  824.         var dpy = this.deltaPyFrom(character.py);
  825.         if (Math.abs(dpx) > Math.abs(dpy)) {
  826.             this.moveStraight(dpx > 0 ? 6 : 4);
  827.             if (!this.isMovementSucceeded() && dpy !== 0) {
  828.                 this.moveStraight(dpy > 0 ? 2 : 8);
  829.             }
  830.         } else if (dpy !== 0) {
  831.             this.moveStraight(dpy > 0 ? 2 : 8);
  832.             if (!this.isMovementSucceeded() && dpx !== 0) {
  833.                 this.moveStraight(dpx > 0 ? 6 : 4);
  834.             }
  835.         }
  836.     };

  837.     Game_Character.prototype.turnTowardCharacter = function (character) {
  838.         var dpx = this.deltaPxFrom(character.px);
  839.         var dpy = this.deltaPyFrom(character.py);
  840.         if (Math.abs(dpx) > Math.abs(dpy)) {
  841.             this.setDirection(dpx > 0 ? 4 : 6);
  842.         } else if (dpy !== 0) {
  843.             this.setDirection(dpy > 0 ? 8 : 2);
  844.         }
  845.     };

  846.     Game_Character.prototype.turnAwayFromCharacter = function (character) {
  847.         var dpx = this.deltaPxFrom(character.px);
  848.         var dpy = this.deltaPyFrom(character.py);
  849.         if (Math.abs(dpx) > Math.abs(dpy)) {
  850.             this.setDirection(dpx > 0 ? 6 : 4);
  851.         } else if (dpy !== 0) {
  852.             this.setDirection(dpy > 0 ? 2 : 8);
  853.         }
  854.     };

  855.     Game_Character.prototype.findRouteTo = function (goalPx, goalPy) {
  856.         var searchLimit = toPixel(Math.max($gameMap.screenTileX(), $gameMap.screenTileY()));

  857.         var px = this._px;
  858.         var py = this._py;

  859.         if (px === goalPx && py === goalPy) {
  860.             return [];
  861.         }

  862.         var makeNode = function (parent, px, py, gScore, fScore, direction) {
  863.             return {
  864.                 parent: parent,
  865.                 px: px,
  866.                 py: py,
  867.                 gScore: gScore,
  868.                 fScore: fScore,
  869.                 direction: direction
  870.             };
  871.         };
  872.         var makeId = function (px, py) {
  873.             return py * $gameMap.widthPx() + px;
  874.         };
  875.         var estimateCost = function (px1, py1, px2, py2) {
  876.             return $gameMap.distancePx(px1, py1, px2, py2);
  877.         };

  878.         var reconstructPath = function (node) {
  879.             var current = node;
  880.             var path = [current.direction];
  881.             while (current.parent !== start) {
  882.                 current = current.parent;
  883.                 path.push(current.direction);
  884.             }
  885.             return path;
  886.         };

  887.         var start = makeNode(null, px, py, 0, estimateCost(px, py, goalPx, goalPy), 0);

  888.         var openSet = [start];
  889.         var closedSet = [];

  890.         var reserveSet = []; // used when failed

  891.         while (openSet.length > 0) {
  892.             var current = openSet[0];
  893.             var currentIndex = 0;

  894.             for (var i = 1; i < openSet.length; i++) {
  895.                 if (openSet[i].fScore < current.fScore) {
  896.                     current = openSet[i];
  897.                     currentIndex = i;
  898.                 }
  899.             }

  900.             if (current.px === goalPx && current.py === goalPy) {
  901.                 return reconstructPath(current);
  902.             }

  903.             openSet.splice(currentIndex, 1);
  904.             closedSet.push(makeId(current.px, current.py));

  905.             reserveSet.push(current);

  906.             if (current.gScore > searchLimit) {
  907.                 continue;
  908.             }

  909.             for (var direction = 2; direction <= 8; direction += 2) {
  910.                 var npx = $gameMap.roundPxWithDirection(current.px, direction);
  911.                 var npy = $gameMap.roundPyWithDirection(current.py, direction);

  912.                 if (closedSet.indexOf(makeId(npx, npy)) > -1) {
  913.                     continue;
  914.                 }

  915.                 if (!this.canPassPx(current.px, current.py, direction)) {
  916.                     closedSet.push(makeId(npx, npy));
  917.                     continue;
  918.                 }

  919.                 var tentativeGScore = current.gScore + 1;

  920.                 var nodeFound = null;
  921.                 for (var i = 0; i < openSet.length; i++) {
  922.                     var node = openSet[i];
  923.                     if (node.px === npx && node.py === npy) {
  924.                         nodeFound = node;
  925.                     }
  926.                 }

  927.                 if (!nodeFound || tentativeGScore < nodeFound.gScore) {
  928.                     var neighbor;
  929.                     if (!nodeFound) {
  930.                         neighbor = {
  931.                             px: npx,
  932.                             py: npy
  933.                         };
  934.                         openSet.push(neighbor);
  935.                     } else {
  936.                         neighbor = nodeFound;
  937.                     }

  938.                     neighbor.parent = current;
  939.                     neighbor.gScore = tentativeGScore;
  940.                     neighbor.fScore = tentativeGScore + estimateCost(npx, npy, goalPx, goalPy);
  941.                     neighbor.direction = direction;
  942.                 }
  943.             }
  944.         }

  945.         // when failed
  946.         var closest = reserveSet[0];
  947.         for (var i = 1; i < reserveSet.length; i++) {
  948.             var current = reserveSet[i];
  949.             if (current.fScore - current.gScore < closest.fScore - closest.gScore) {
  950.                 closest = current;
  951.             }
  952.         }

  953.         var goalDirection;
  954.         var dpx = $gameMap.deltaPx(closest.px, goalPx);
  955.         var dpy = $gameMap.deltaPy(closest.py, goalPy);
  956.         if (Math.abs(dpx) > Math.abs(dpy)) {
  957.             goalDirection = dpx > 0 ? 4 : 6;
  958.         } else if (dpy !== 0) {
  959.             goalDirection = dpy > 0 ? 8 : 2;
  960.         }

  961.         if (closest === start) {
  962.             return [goalDirection];
  963.         } else {
  964.             var path = reconstructPath(closest);
  965.             path.unshift(goalDirection);
  966.             return path;
  967.         }
  968.     };

  969.     //------------------------------------------------------------
  970.     // Game_Player

  971.     Game_Player.prototype.moveByInput = function () {
  972.         if (!this.isMoving() && this.canMove()) {
  973.             var direction = this.getInputDirection();
  974.             if (direction > 0) {
  975.                 $gameTemp.clearDestination();
  976.             } else if ($gameTemp.isDestinationValid()) {
  977.                 direction = $gameTemp.nextDirection();
  978.             }
  979.             if (direction > 0) {
  980.                 this.executeMove(direction);
  981.                 if (!this.isMovementSucceeded()) {
  982.                     switch (direction) {
  983.                         case 2:
  984.                             this.executeMove(1);
  985.                             if (!this.isMovementSucceeded()) {
  986.                                 this.executeMove(3)
  987.                             }
  988.                             break;
  989.                         case 4:
  990.                             this.executeMove(1);
  991.                             if (!this.isMovementSucceeded()) {
  992.                                 this.executeMove(7)
  993.                             }
  994.                             break;
  995.                         case 6:
  996.                             this.executeMove(3);
  997.                             if (!this.isMovementSucceeded()) {
  998.                                 this.executeMove(9)
  999.                             }
  1000.                             break;
  1001.                         case 8:
  1002.                             this.executeMove(7);
  1003.                             if (!this.isMovementSucceeded()) {
  1004.                                 this.executeMove(9)
  1005.                             }
  1006.                             break;
  1007.                     }
  1008.                 }
  1009.             }
  1010.         }
  1011.     };

  1012.     Game_Player.prototype.getInputDirection = function () {
  1013.         return Input.dir8;
  1014.     };

  1015.     Game_Player.prototype.executeMove = function (direction) {
  1016.         this.moveDir8(direction);
  1017.     };

  1018.     Game_Player.prototype.updateNonmoving = function (wasMoving) {
  1019.         if (!$gameMap.isEventRunning()) {
  1020.             if (wasMoving) {
  1021.                 $gameParty.onPlayerWalk();
  1022.                 this.checkEventTriggerHere([1, 2]);
  1023.                 if ($gameMap.setupStartingEvent()) {
  1024.                     return;
  1025.                 }
  1026.             }
  1027.             if (this.triggerAction()) {
  1028.                 return;
  1029.             }
  1030.             if (wasMoving) {
  1031.                 this.updateEncounterCount();
  1032.             } else if (!$gameTemp.isDestinationValid()) {
  1033.                 $gameTemp.clearDestination();
  1034.             }
  1035.         }
  1036.     };

  1037.     Game_Player.prototype.triggerTouchAction = function () {
  1038.         return false;
  1039.     };

  1040.     Game_Player.prototype.checkEventTriggerHere = function (triggers) {
  1041.         if (this.canStartLocalEvents()) {
  1042.             this.startCollidedEventsPx(this._px, this._py, triggers, false);
  1043.         }
  1044.     };

  1045.     Game_Player.prototype.checkEventTriggerThere = function (triggers) { // front, literally
  1046.         if (this.canStartLocalEvents()) {
  1047.             var direction = this.direction();
  1048.             var npx = $gameMap.roundPxWithDirection(this._px, direction);
  1049.             var npy = $gameMap.roundPyWithDirection(this._py, direction);
  1050.             this.startCollidedEventsPx(npx, npy, triggers, true);
  1051.             if (!$gameMap.isEventRunning() && this.isFacingCounter()) {
  1052.                 if (direction === 2 || direction === 8) {
  1053.                     this.startCollidedEventsPx(npx, npy + (direction === 2 ? tileSection : -tileSection), triggers, true);
  1054.                 } else if (direction === 4 || direction === 6) {
  1055.                     this.startCollidedEventsPx(npx + (direction === 4 ? -tileSection : tileSection), npy, triggers, true);
  1056.                 }
  1057.             }
  1058.         }
  1059.     };

  1060.     Game_Player.prototype.checkEventTriggerTouchPx = function (px, py) {
  1061.         if (this.canStartLocalEvents()) {
  1062.             this.startCollidedEventsPx(px, py, [1, 2], true);
  1063.         }
  1064.     };

  1065.     Game_Player.prototype.startCollidedEventsPx = function (px, py, triggers, normal) {
  1066.         if (!$gameMap.isEventRunning()) {
  1067.             $gameMap.collidedEventsPx(px, py, this._collisionMask).forEach(function (event) {
  1068.                 if (event.isTriggerIn(triggers) && event.isNormalPriority() === normal) {
  1069.                     event.start();
  1070.                 }
  1071.             });
  1072.         }
  1073.     };

  1074.     Game_Player.prototype.isOnDamageFloor = function () {
  1075.         var cm = this._collisionMask;
  1076.         var xs = cm.xSize;
  1077.         var ys = cm.ySize;
  1078.         var spx = this._px - xs / 2;
  1079.         var spy = this._py - ys;
  1080.         for (var cmx = 0; cmx < xs; cmx++) {
  1081.             for (var cmy = 0; cmy < ys; cmy++) {
  1082.                 if ($gameMap.isDamageFloorPx(spx + cmx, spy + cmy)) {
  1083.                     return true;
  1084.                 }
  1085.             }
  1086.         }
  1087.         return false;
  1088.     };

  1089.     Game_Player.prototype.moveStraight = function (d) {
  1090.         Game_Character.prototype.moveStraight.call(this, d);
  1091.         if (this.isMovementSucceeded()) {
  1092.             this._followers.updateMove();
  1093.         }
  1094.     };

  1095.     Game_Player.prototype.moveDiagonally = function (horz, vert) {
  1096.         Game_Character.prototype.moveDiagonally.call(this, horz, vert);
  1097.         if (this.isMovementSucceeded()) {
  1098.             this._followers.updateMove();
  1099.         }
  1100.     };

  1101.     //------------------------------------------------------------
  1102.     // Game_Follower

  1103.     Game_Follower.prototype.canPassPx = function (px, py, d) {
  1104.         /*
  1105.          if (this.isThrough() || this.isDebugThrough()) {
  1106.          return true;
  1107.          }
  1108.          */
  1109.         if (!this.isMapPassablePx(px, py, d)) {
  1110.             return false;
  1111.         }
  1112.         if (this.isCollidedWithCharactersPx($gameMap.roundPxWithDirection(px, d), $gameMap.roundPyWithDirection(py, d))) {
  1113.             return false;
  1114.         }
  1115.         return true;
  1116.     };

  1117.     Game_Follower.prototype.chaseCharacter = function (character) {
  1118.         var dpx = this.deltaPxFrom(character.px);
  1119.         var dpy = this.deltaPyFrom(character.py);
  1120.         dpx = Math.abs(dpx) > followerDistance ? dpx : 0;
  1121.         dpy = Math.abs(dpy) > followerDistance ? dpy : 0;
  1122.         if (dpx !== 0 || dpy !== 0) {
  1123.             if (dpx !== 0 && dpy !== 0) {
  1124.                 this.moveDiagonally(dpx > 0 ? 4 : 6, dpy > 0 ? 8 : 2);
  1125.             } else if (dpx !== 0) {
  1126.                 this.moveStraight(dpx > 0 ? 4 : 6);
  1127.             } else if (dpy !== 0) {
  1128.                 this.moveStraight(dpy > 0 ? 8 : 2);
  1129.             }
  1130.             if (!this.isMovementSucceeded()) {
  1131.                 this.moveDir8(this.findChaseDirection(character));
  1132.             }
  1133.             this.setMoveSpeed($gamePlayer.realMoveSpeed());
  1134.         }
  1135.     };

  1136.     Game_Follower.prototype.findChaseDirection = function (character) {
  1137.         var nodes = [];

  1138.         var px = this._px;
  1139.         var py = this._py;

  1140.         var makeNode = function (px, py, gScore, fScore, direction) {
  1141.             return {
  1142.                 px: px,
  1143.                 py: py,
  1144.                 g: gScore,
  1145.                 f: fScore,
  1146.                 direction: direction
  1147.             };
  1148.         };

  1149.         for (var direction = 1; direction <= 9; direction++) {
  1150.             if (direction === 5) {
  1151.                 continue;
  1152.             }
  1153.             var npx = px;
  1154.             var npy = py;
  1155.             switch (direction) {
  1156.                 case 2:
  1157.                 case 4:
  1158.                 case 6:
  1159.                 case 8:
  1160.                     npx = $gameMap.roundPxWithDirection(npx, direction);
  1161.                     npy = $gameMap.roundPyWithDirection(npy, direction);
  1162.                     break;
  1163.                 case 1:
  1164.                     npx--;
  1165.                     npy++;
  1166.                     break;
  1167.                 case 3:
  1168.                     npx++;
  1169.                     npy++;
  1170.                     break;
  1171.                 case 7:
  1172.                     npx--;
  1173.                     npy--;
  1174.                     break;
  1175.                 case 9:
  1176.                     npx++;
  1177.                     npy--;
  1178.                     break;
  1179.             }
  1180.             if (direction % 2 === 0) {
  1181.                 if (!this.canPassPx(px, py, direction)) {
  1182.                     continue;
  1183.                 }
  1184.             } else {
  1185.                 if (!this.canPassDiagonallyPx(px, py, npx - px > 0 ? 6 : 4, npy - py > 0 ? 2 : 8)) {
  1186.                     continue;
  1187.                 }
  1188.             }
  1189.             nodes.push(makeNode(npx, npy, 1, 1 + $gameMap.distancePx(npx, npy, character.px, character.py), direction));
  1190.         }

  1191.         if (nodes.length < 1) {
  1192.             return 0;
  1193.         }

  1194.         var best = nodes[0];
  1195.         for (var i = 1; i < nodes.length; i++) {
  1196.             var current = nodes[i];
  1197.             if (current.f < best.f) {
  1198.                 best = current;
  1199.             }
  1200.         }
  1201.         return best.direction;
  1202.     };

  1203.     //-----------------------------------------------------------------------------
  1204.     // Game_Followers

  1205.     Game_Followers.prototype.jumpAll = function () {
  1206.         if ($gamePlayer.isJumping()) {
  1207.             for (var i = 0; i < this._data.length; i++) {
  1208.                 var follower = this._data[i];
  1209.                 var sx = toTile($gamePlayer.deltaPxFrom(follower.px));
  1210.                 var sy = toTile($gamePlayer.deltaPyFrom(follower.py));
  1211.                 follower.jump(sx, sy);
  1212.             }
  1213.         }
  1214.     };

  1215.     /*
  1216.      Game_Followers.prototype.isSomeoneCollided = function(x, y) {
  1217.      return this.visibleFollowers().some(function(follower) {
  1218.      return follower.pos(x, y);
  1219.      }, this);
  1220.      };
  1221.      */

  1222.     //-----------------------------------------------------------------------------
  1223.     // Game_Vehicle
  1224.    
  1225.     // TODO: Support vehicles
  1226.    
  1227.     //-----------------------------------------------------------------------------
  1228.     // Sprite_Character

  1229.     var aliasSpriteCharacterPrototypeSetCharacter = Sprite_Character.prototype.setCharacter;
  1230.     Sprite_Character.prototype.setCharacter = function () {
  1231.         aliasSpriteCharacterPrototypeSetCharacter.apply(this, arguments);
  1232.         if (drawCollisionMask && this._character) {
  1233.             this.debugDrawCollisionMask();
  1234.         }
  1235.     };

  1236.     Sprite_Character.prototype.debugDrawCollisionMask = function () {
  1237.         var sprite = new Sprite(new Bitmap($gameMap.tileWidth(), $gameMap.tileHeight()));
  1238.         sprite.anchor = this.anchor;
  1239.         sprite.opacity = 80;
  1240.         var cm = this._character.collisionMask;
  1241.         var sw = $gameMap.tileWidthPx();
  1242.         var sh = $gameMap.tileHeightPx();
  1243.         for (var sx = 0; sx < cm.xSize; sx++) {
  1244.             for (var sy = 0; sy < cm.ySize; sy++) {
  1245.                 if (cm.get(sx, sy)) {
  1246.                     sprite.bitmap.fillRect(sx * sw, sy * sh, sw, sh, this._character.isThrough() || !this._character.isNormalPriority() ? 'green' : 'red');
  1247.                 }
  1248.             }
  1249.         }
  1250.         this.addChild(sprite);
  1251.     };

  1252.     //------------------------------------------------------------
  1253.     // Sprite_Destination

  1254.     Sprite_Destination.prototype.updatePosition = function () {
  1255.         var dpx = $gameTemp.destinationPx();
  1256.         var dpy = $gameTemp.destinationPy();
  1257.         this.x = $gameMap.adjustX(toTile(dpx)) * tileSection * $gameMap.tileWidthPx();
  1258.         this.y = ($gameMap.adjustY(toTile(dpy)) * tileSection - 1) * $gameMap.tileHeightPx();
  1259.     };

  1260.     //------------------------------------------------------------
  1261.     // Scene_Map
  1262.     Scene_Map.prototype.processMapTouch = function () {
  1263.         if (TouchInput.isTriggered()) {
  1264.             $gameTemp.setDestination($gameMap.canvasToMapPx(TouchInput.x), $gameMap.canvasToMapPy(TouchInput.y));
  1265.         }
  1266.     };

  1267.     var aliasSceneMapPrototypeUpdate = Scene_Map.prototype.update;
  1268.     Scene_Map.prototype.update = function () {
  1269.         if ($gameMap.isCollisionMaskSet()) {
  1270.             aliasSceneMapPrototypeUpdate.apply(this, arguments);
  1271.         } else {
  1272.             Scene_Base.prototype.update.call(this);
  1273.         }
  1274.     };
  1275. })();
复制代码

评分

参与人数 1星屑 +66 收起 理由
MeowSnow + 66 叼叼叼

查看全部评分

梦石
0
星屑
97
在线时间
308 小时
注册时间
2014-1-16
回帖
397
发表于 2016-6-8 18:05:39 | 显示全部楼层
这个。。。有什么用?解释一下
回复

使用道具 举报

梦石
0
星屑
50
在线时间
491 小时
注册时间
2015-1-7
回帖
110
发表于 2016-6-8 21:30:43 | 显示全部楼层
现在的难道不是像素移动?

点评

明显不是。。。RM一直都是跑格子  发表于 2016-6-9 04:07
回复

使用道具 举报

梦石
0
星屑
1446
在线时间
6552 小时
注册时间
2010-12-30
回帖
8655
发表于 2016-6-9 00:48:37 | 显示全部楼层
傲游截图20160609004322.png 傲游截图20160609004733.png
_(:з」∠)_啊喏,虽然像素移动的效果很棒,但是火车队列变成了扭曲的效果呢……还有行走图上出现了不明的小方块,即使关了火车队列或者队伍中只有一个角色时,这些小方块也存在。
回复

使用道具 举报

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-3-14
回帖
32
 楼主| 发表于 2016-6-9 02:03:10 | 显示全部楼层
本帖最后由 moe2333 于 2016-6-9 02:25 编辑
MeowSnow 发表于 2016-6-9 00:48
_(:з」∠)_啊喏,虽然像素移动的效果很棒,但是火车队列变成了扭曲的效果呢……还有行走图上出现了不明的 ...


是我把火车队列定义成这样的:
只要一个跟随者跟随的角色的X距离或者Y距离不超过followerDistance这个follower就不会移动,我觉得这样会让队列更自然
关于小方块,那是角色的碰撞面具,把25行的drawCollisionMask设置为false就可以了。
因为测试的时候需要绘制碰撞面具所以默认是true的状态
至于为什么关了火车还会有是因为不管队伍里有多少队员默认状态下都会有3个follower跟着主角,队员不足或者不显示follower的时候MV做的只是把那几个follower的sprite隐藏掉了而已

哦,对了
告诉你一下还有什么是我没有做的:
1. 虽然优化了寻路的算法但是鼠标不能触发事件了(现在懒得弄所以直接禁用掉了,不过以后会弄的)
2. 暂时不支持交通工具,关于交通工具的一切(乘坐,移动...)都可能会有bug,不过bug长什么样子我没去看,总之即使坐上去了也不能移动。(其实交通工具需要的碰撞检测数据已经在refreshCollisionMask方法里生成了,所以要做应该也不是难事)
3. 暂时不支持autotile的位图分析,所以只要autotile的flag是0x0f的话那整个autotile都会被mask掉,不管位图长什么样子
4. 其他肯定还有很多bug和兼容的问题
5. 我好懒

最近pewdiepie有在搞一个rpg maker competition,我其实想参加的,但是一个人好像没什么动力,你们想不想一起来?如果有人帮忙的话我就去参加了

点评

之前一直在折腾碰撞检测引擎,看到也在折腾这块的感觉好亲切!!!【https://coding.net/u/shitake/p/box2d-ruby/git/blob/master/box2d.rb 以前折腾个一个  发表于 2016-6-9 16:58
你说的这些东西我都没有用上。也许你可以帮我改进一下  发表于 2016-6-9 15:52
你说的这些东西我都没有用上。也许你可以帮我改进一下  发表于 2016-6-9 15:51
话说难倒不是脏矩阵么。以及貌似是有AABB?OBB和sphere呢?有实现吗?  发表于 2016-6-9 13:20
(っ´ω`c) 要是做一个素材量不大的弹幕游戏的话,我愿意帮助菊苣做像素美术  发表于 2016-6-9 11:04
回复

使用道具 举报

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-3-14
回帖
32
 楼主| 发表于 2016-6-9 02:07:00 | 显示全部楼层
西姐 发表于 2016-6-8 21:30
现在的难道不是像素移动?

像素移动只是相对像素而已
默认状态下MV是48像素一个tile,这个脚本允许你把tile size设置得更小
具体参照tileSection
另外这个脚本还加入了更精确的碰撞检测以及自动分析tileset bitmap的功能
你可以新建一个工程看看效果
回复

使用道具 举报

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-3-14
回帖
32
 楼主| 发表于 2016-6-9 02:09:04 | 显示全部楼层
超音速 发表于 2016-6-8 18:05
这个。。。有什么用?解释一下

默认状态下MV一按方向键就走一整个大格,你想不想让移动更自由一点,比如说一小格一小格的移动呢?

点评

明白了  发表于 2016-6-9 12:14
回复

使用道具 举报

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2016-6-9 07:42:20 | 显示全部楼层
Quasi Movement 这个插件我觉得挺不错的,楼主可以参考一下
回复

使用道具 举报

梦石
0
星屑
22879
在线时间
8598 小时
注册时间
2011-12-31
回帖
3270
发表于 2016-6-9 08:34:36 | 显示全部楼层
本帖最后由 tseyik 于 2016-6-9 08:37 编辑

SAN_AnalogMove
  1. //=============================================================================
  2. // SAN_AnalogMove.js
  3. //=============================================================================
  4. // Copyright (c) 2015-2016 Sanshiro
  5. // Released under the MIT license
  6. // [url]http://opensource.org/licenses/mit-license.php[/url]
  7. //=============================================================================

  8. /*:
  9. * @plugindesc SAN_AnalogMove ver1.34 : Movement of 1 pixel unit.
  10. * Analog Stick and Touch Pad are supported.
  11. * @author Sanshiro [url]https://twitter.com/rev2nym[/url]
  12. *
  13. * @help
  14. * Change player's movement to 1 pixel movement that isn't depend tiles.
  15. * Arrow Key, Analog Stick and Touch Pad are supported.
  16. *
  17. * It's possible to commercial use, distribute, and modify under the MIT license.
  18. * But, don't eliminate and don't alter a comment of the beginning.
  19. * If it's good, please indicate an author name on credit.
  20. *
  21. * Author doesn't shoulder any responsibility in all kind of damage by using this.
  22. * And please don't expect support. X(
  23. *
  24. * Plugin Command
  25. *   AnalogMove ON            # Allow AnalogMove system working.
  26. *   AnalogMove OFF           # Disallow AnalogMove system working.
  27. *   AnalogMove Player ON     # Allow player and followers analog moving.
  28. *   AnalogMove Player OFF    # Disallow player and followers analog moving.
  29. *   
  30. * @param Valid
  31. * @desc Initial valid flag of AnalogMove system. ('ON' is valid)
  32. * @default OFF
  33. *
  34. * @param Player
  35. * @desc Initial valid flag of player and followers analog moving. ('ON' is valid)
  36. * @default OFF
  37. *
  38. */

  39. /*:ja
  40. * @plugindesc アナログムーブ ver1.34
  41. * 1ピクセル単位の移動 アナログスティック・タッチパッド対応
  42. * @author サンシロ [url]https://twitter.com/rev2nym[/url]
  43. * @version 1.34 2016/03/30 並んだプライオリティの異なる接触イベントの間をすり抜ける不具合を修正、1フレーム内に起動するイベントを1つだけにするよう変更
  44. * 1.33 2015/11/29 プラグインパラメータが反映されない不具合を修正
  45. * 1.32 2015/11/29 スルー有効時の挙動に関連してフォロワーの挙動を修正
  46. * 1.31 2015/11/28 コード整理、プレイヤーのスルー有効時の挙動、飛行艇時に決定ボタン・接触イベントが起動する不具合を修正
  47. * 1.30 2015/11/26 モジュール名をSAN_AnalogMove.jsに変更、名前空間の追加、乗り物に対応
  48. * 1.27a 2015/11/25 英語ドキュメント追加
  49. * 1.27 2015/11/24 MITライセンスに変更、セーブファイルから衝突マップを除外、ルート指定時の向き反映の不具合を修正
  50. * 1.26 2015/11/20 フォロワーの位置反映、イベント中の歩行アニメ、通行判定を暫定修正
  51. * 1.25 2015/11/16 フォロワーの向き固定移動の不具合と初期ON起動時にエラー終了する不具合を修正
  52. * 1.24 2015/11/15 機能有効フラグの状態をセーブファイルに保存するよう修正
  53. * 1.23 2015/11/14 通行不能タイルの接触イベント起動を追加、ルート指定移動の向き反映を修正
  54. * 1.22 2015/11/12 ウィンドウを閉じた後のマウス・タッチパッドの感度、座標指定移動の終了条件を調整
  55. * 1.21 2015/11/11 茂み表示、向き反映、プライオリティの異なるイベントの起動の不具合を修正
  56. * 1.20 2015/11/10 タッチパッドに対応、向き反映、イベント中の移動、マップ端の通行判定の不具合を修正
  57. * 1.10 2015/11/09 ランダムエンカウントに対応、プラグインパラメータ読込みの不具合を修正
  58. * 1.01 2015/11/08 角度の誤計算を修正、ループマップ使用可能
  59. * 1.00 2015/11/08 フォロワーの移動速度を微調整、リリースバージョンにアップ
  60. * 0.90 2015/11/08 プラグインパラメータ・コマンド、移動ルートの指定、フォロワー表示・集合などに対応
  61. * 0.12 2015/11/08 セーブ&ロードに暫定対応
  62. * 0.11 2015/11/07 複数のイベントに同時に接触したときエラー終了する不具合を修正
  63. * 0.10 2015/11/06 公開
  64. *
  65. * @help
  66. * プレイヤーキャラクターの移動をタイルによらない1ピクセル単位の移動に変更します。
  67. * 方向キー、アナログスティック、タッチパッド入力に対応しています。
  68. *
  69. * MITライセンスのもと、商用利用、改変、再配布が可能です。
  70. * ただし冒頭のコメントは削除や改変をしないでください。
  71. * よかったらクレジットに作者名を記載してください。
  72. *
  73. * これを利用したことによるいかなる損害にも作者は責任を負いません。
  74. * サポートは期待しないでください><。
  75. *
  76. * プラグインコマンド
  77. *   AnalogMove ON            # アナログムーブ機能有効化
  78. *   AnalogMove OFF           # アナログムーブ機能無効化
  79. *   AnalogMove Player ON     # プレイヤーとフォロワーのアナログムーブ有効化
  80. *   AnalogMove Player OFF    # プレイヤーとフォロワーのアナログムーブ無効化
  81. *
  82. * @param Valid
  83. * @desc アナログムーブ機能の有効フラグの初期値です。(ONで有効)
  84. * @default OFF
  85. *
  86. * @param Player
  87. * @desc プレイヤーとフォロワーのアナログムーブ有効フラグの初期値です。(ONで有効)
  88. * @default OFF
  89. *
  90. */

  91. var Imported = Imported || {};
  92. Imported.SAN_AnalogMove = true;

  93. var Sanshiro = Sanshiro || {};
  94. Sanshiro.Game_AnalogMove = Sanshiro.Game_AnalogMove || {};

  95. //-----------------------------------------------------------------------------
  96. // Game_AnalogMove
  97. //
  98. // アナログムーブクラス
  99. function Game_AnalogMove() {
  100.     this.initialize.apply(this, arguments);
  101. };

  102. // アナログムーブクラス初期化
  103. Game_AnalogMove.prototype.initialize = function(thisCharacter) {
  104.     this._crntRealX    = thisCharacter._realX;        // 現在マップ実 X 座標
  105.     this._nextRealX    = thisCharacter._realX;        // 次回マップ実 X 座標
  106.     this._crntRealY    = thisCharacter._realY;        // 現在マップ実 Y 座標
  107.     this._nextRealY    = thisCharacter._realY;        // 次回マップ実 Y 座標
  108.     this._targRealX    = undefined;                   // 目標マップ実 X 座標
  109.     this._targRealY    = undefined;                   // 目標マップ実 Y 座標
  110.     this._dir4         = thisCharacter.direction();   // キャラクターの向き
  111.     this._distancePerFrame = 0.0;                     // フレーム間移動距離(ピクセル)
  112.     this._directionRadian  = this.dir8ToRadian(thisCharacter.direction()); // 現在進行方位
  113.     this._targetRadian     = this.dir8ToRadian(thisCharacter.direction()); // 目標進行方位
  114.     this._directionRadianVariate = Math.PI*2.0;       // 進行方位変化量
  115.     this._encounterCount   = 0.0;                     // エンカウント歩数
  116.     this._collideEvents    = new Array();             // 接触イベント
  117.     this._isMoving         = false;                   // 移動中判定
  118.     this._isThrough        = false;                   // すり抜け判定
  119.     this._valid            = false;                   // アナログムーブ個別キャラクター有効フラグ
  120. };

  121. // アナログムーブ個別キャラクター有効フラグの設定
  122. Game_AnalogMove.prototype.setValid = function(valid) {
  123.     this._valid = valid;
  124. };

  125. // アナログムーブ個別キャラクター有効判定
  126. Game_AnalogMove.prototype.isValid = function() {
  127.     return $gameSystem.analogMoveValid() && this._valid;
  128. };

  129. // アナログムーブ移動可能判定
  130. Game_AnalogMove.canMove = function() {
  131.     return $gamePlayer.canMove() && !SceneManager.isSceneChanging();
  132. };

  133. // フレーム更新
  134. Game_AnalogMove.prototype.update = function(thisCharacter) {
  135.     this._crntRealX = thisCharacter._realX;
  136.     this._crntRealY = thisCharacter._realY;
  137.     this._nextRealX = thisCharacter._realX;
  138.     this._nextRealY = thisCharacter._realY;
  139.     this.updateDirectionRadian();
  140.     this.updateDir4(thisCharacter);
  141.     this.updateNextRealXY(thisCharacter);
  142.     this.updateTargetRealXY(thisCharacter);
  143.     this.updateIsMoving(thisCharacter);
  144.     this.updateIsThrough(thisCharacter);
  145.     this.updateEncounterCount(thisCharacter);
  146.     this.updateCharacterPosition(thisCharacter);
  147. };

  148. // 目標座標の更新
  149. Game_AnalogMove.prototype.updateTargetRealXY = function(thisCharacter) {
  150.     if (!Game_AnalogMove.canMove() ||
  151.             this.deltaXY(thisCharacter._realX, thisCharacter._realY, this._nextRealX, this._nextRealY) < this._distancePerFrame / 16.0) {
  152.         this._targRealX = undefined;
  153.         this._targRealY = undefined;
  154.     }
  155. }

  156. // エンカウント歩数の更新
  157. Game_AnalogMove.prototype.updateEncounterCount = function(thisCharacter) {
  158.     if (thisCharacter === $gamePlayer && Game_AnalogMove.canMove() && $gamePlayer.canEncounter()) {
  159.         this._encounterCount += Math.sqrt(
  160.                 Math.pow((thisCharacter._realX - this._nextRealX), 2) +
  161.                 Math.pow((thisCharacter._realY - this._nextRealY), 2));
  162.     }
  163. };

  164. // エンカウント歩数
  165. Game_AnalogMove.prototype.encounterCount = function() {
  166.     var encounterCount = this._encounterCount;
  167.     this._encounterCount = 0.0;
  168.     return encounterCount;
  169. };

  170. // キャラクター位置の更新
  171. Game_AnalogMove.prototype.updateCharacterPosition = function(thisCharacter) {
  172.     thisCharacter.setDirectionAnalog(this.dir4());
  173.     if (Game_AnalogMove.canMove() && this.isMoving()) {
  174.         thisCharacter._realX = this._nextRealX;
  175.         thisCharacter._realY = this._nextRealY;
  176.         thisCharacter._x = Math.round(thisCharacter._realX);
  177.         thisCharacter._y = Math.round(thisCharacter._realY);
  178.         thisCharacter.resetStopCount();
  179.     }
  180. };

  181. // キー入力による目標方位角度と移動速度の更新
  182. Game_AnalogMove.prototype.moveByInput = function(thisCharacter) {
  183.     if (!$gamePlayer.canMove()) {
  184.         this._distancePerFrame = 0.0;
  185.         return;
  186.     }
  187.     var stick = Input.leftStick();
  188.     if (TouchInput.isTriggered() || TouchInput.isRepeated()) {
  189.         this._targRealX = this.canvasToMapX(TouchInput.x);
  190.         this._targRealY = this.canvasToMapY(TouchInput.y);
  191.     }
  192.     if (stick !== undefined && stick.tilt !== 0.0) {
  193.         this._targetRadian = this.normalizeRadian(stick.direction);
  194.         this._distancePerFrame = thisCharacter.distancePerFrame() * stick.tilt;
  195.         this._targRealX = undefined;
  196.         this._targRealY = undefined;
  197.     } else if (this.dir8ToRadian(Input.dir8) !== undefined) {
  198.         this._targetRadian = this.dir8ToRadian(Input.dir8);
  199.         this._distancePerFrame = thisCharacter.distancePerFrame();
  200.         this._targRealX = undefined;
  201.         this._targRealY = undefined;
  202.     } else if (this._targRealX !== undefined && this._targRealY !== undefined) {
  203.         var distanceRate = Math.min(this.deltaXYFrom(this._targRealX, this._targRealY), 1.0);
  204.         distanceRate = (distanceRate < 0.1 ? 0.0 : distanceRate);
  205.         this._targetRadian = this.towardDirectionRadian(this._targRealX, this._targRealY);
  206.         this._distancePerFrame = thisCharacter.distancePerFrame() * distanceRate;
  207.         if (distanceRate === 0.0) {
  208.             this._targRealX = undefined;
  209.             this._targRealY = undefined;
  210.         }
  211.     } else {
  212.         this._distancePerFrame = 0.0;
  213.     }
  214. };

  215. // 画面 X 座標をマップ X 座標に変換
  216. Game_AnalogMove.prototype.canvasToMapX = function(x) {
  217.     var tileWidth = $gameMap.tileWidth();
  218.     var originX = $gameMap._displayX * tileWidth;
  219.     var mapX = (originX + x) / tileWidth;
  220.     return $gameMap.roundX(mapX);
  221. };

  222. // 画面 Y 座標をマップ Y 座標に変換
  223. Game_AnalogMove.prototype.canvasToMapY = function(y) {
  224.     var tileHeight = $gameMap.tileHeight();
  225.     var originY = $gameMap._displayY * tileHeight;
  226.     var mapY = (originY + y) / tileHeight;
  227.     return $gameMap.roundY(mapY);
  228. };

  229. // キャラクター追従による目標方位角度と移動速度の更新
  230. Game_AnalogMove.prototype.followCharacter = function(thisCharacter, targetCharacter) {
  231.     this._crntRealX = thisCharacter._realX;
  232.     this._crntRealY = thisCharacter._realY;
  233.     var deltaXYFromTarget = this.deltaXYFrom(targetCharacter._realX + 0.5, targetCharacter._realY + 0.5);
  234.     this._targetRadian = this.towardDirectionRadian(targetCharacter._realX + 0.5, targetCharacter._realY + 0.5);
  235.     if (deltaXYFromTarget <= 1.0) {
  236.         this._distancePerFrame = thisCharacter.distancePerFrame() * 0.0;
  237.     } else {
  238.         var distanceRate = deltaXYFromTarget;
  239.         distanceRate += Math.pow(distanceRate - 1.0, 2) - 0.125;
  240.         distanceRate = distanceRate > 2.0 ? 2.0 : distanceRate;
  241.         this._distancePerFrame = thisCharacter.distancePerFrame() * distanceRate;
  242.     }
  243. };

  244. // 目標方向に向けて進行方位を更新
  245. Game_AnalogMove.prototype.updateDirectionRadian = function() {
  246.     if (this._directionRadian === this._targetRadian) {
  247.         return;
  248.     }
  249.     var differentialRadian = this.normalizeRadian(this._targetRadian - this._directionRadian);
  250.     if (differentialRadian >= Math.PI) {
  251.         differentialRadian -= Math.PI * 2.0;
  252.     }
  253.     differentialRadian < 0 ?
  254.         this._directionRadian += Math.max(differentialRadian, -this._directionRadianVariate) :
  255.         this._directionRadian += Math.min(differentialRadian,  this._directionRadianVariate);
  256.     this._directionRadian = this.normalizeRadian(this._directionRadian);
  257. };

  258. // ラジアン角度を整形
  259. Game_AnalogMove.prototype.normalizeRadian = function(radian) {
  260.     while (radian < 0) radian += (Math.PI * 2.0);
  261.     return radian % (Math.PI * 2.0);
  262. };

  263. // クラス内部の実座標の更新
  264. Game_AnalogMove.prototype.updateNextRealXY = function(thisCharacter) {
  265.     this._collideEvents = new Array();
  266.     this._isMoving = false;
  267.     var evadeDirectionRadian = this._directionRadian;
  268.     var splitDistances = this.splitDistances();
  269.     splitDistances.forEach(function(splitDistance) {
  270.         this.calculateNextRealXY(splitDistance, this._directionRadian);
  271.         var collideCharacters = this.collideCharacters(thisCharacter, splitDistance);
  272.         var collideWallXY = this.collideWallXY(thisCharacter, splitDistance);
  273.         var collideCornerXY = this.collideCornerXY(thisCharacter, splitDistance);
  274.         if (collideCharacters.length === 0) {
  275.             if (collideCornerXY !== undefined) {
  276.                 evadeDirectionRadian = this.evadeDirectionRadian(collideCornerXY.x, collideCornerXY.y, this._directionRadian);
  277.                 splitDistance *= Math.abs(Math.cos(evadeDirectionRadian - this._directionRadian));
  278.                 this.calculateNextRealXY(splitDistance, evadeDirectionRadian);
  279.             }
  280.             if (collideWallXY.x !== undefined) {
  281.                 this._nextRealX = Math.round(this._nextRealX);
  282.             }
  283.             if (collideWallXY.y !== undefined) {
  284.                 this._nextRealY = Math.round(this._nextRealY);
  285.             }
  286.         } else if (collideCharacters.length === 1 && collideWallXY.x === undefined && collideWallXY.y === undefined && collideCornerXY === undefined) {
  287.             evadeDirectionRadian = this.evadeDirectionRadian(collideCharacters[0]._realX + 0.5, collideCharacters[0]._realY + 0.5, this._directionRadian);
  288.             splitDistance *= Math.abs(Math.cos(evadeDirectionRadian - this._directionRadian));
  289.             this.calculateNextRealXY(splitDistance, evadeDirectionRadian);
  290.             if (this.collideCharacters(thisCharacter, splitDistance).length !== 0) {
  291.                 this._nextRealX = this._crntRealX;
  292.                 this._nextRealY = this._crntRealY;
  293.             }
  294.         } else {
  295.             this._nextRealX = this._crntRealX;
  296.             this._nextRealY = this._crntRealY;
  297.         }
  298.         this._crntRealX = this._nextRealX = ((this._nextRealX + $gameMap.width())  % $gameMap.width());
  299.         this._crntRealY = this._nextRealY = ((this._nextRealY + $gameMap.height()) % $gameMap.height());
  300.     }, this);
  301.     // 衝突するイベントの更新
  302.     this._collideEvents = this._collideEvents.filter(function(character, i, characters) {
  303.         var eventId = $gameMap.events().indexOf(character);
  304.         return (characters.indexOf(character) === i && $gameMap.events().indexOf(character) !== -1);
  305.     });
  306. };

  307. // 分割フレーム間移動距離
  308. Game_AnalogMove.prototype.splitDistances = function() {
  309.     var unitDistanceVelocity = 1.0 / 4.0;
  310.     var distancePerFrame = this._distancePerFrame;
  311.     var distances = new Array();
  312.     while (distancePerFrame > 0.0) {
  313.         distances.push(Math.min(distancePerFrame, unitDistanceVelocity));
  314.         distancePerFrame -= unitDistanceVelocity;
  315.     }
  316.     return distances;
  317. };

  318. // クラス内部の次移動座標の計算
  319. Game_AnalogMove.prototype.calculateNextRealXY = function(distancePerFrame, directionRadian) {
  320.     var distanceX = - distancePerFrame * Math.sin(directionRadian);
  321.     var distanceY = - distancePerFrame * Math.cos(directionRadian);
  322.     this._nextRealX = this._crntRealX + distanceX;
  323.     this._nextRealY = this._crntRealY + distanceY;
  324. };

  325. // 指定座標への方位
  326. Game_AnalogMove.prototype.towardDirectionRadian = function(x, y) {
  327.     var deltaX = this.deltaXFrom(x);
  328.     var deltaY = this.deltaYFrom(y);
  329.     if (deltaX === 0.0) {
  330.         return (deltaY > 0 ? Math.PI * 0.0 : Math.PI * 1.0);
  331.     } else if (deltaY === 0.0) {
  332.         return (deltaX > 0 ? Math.PI * 0.5 : Math.PI * 1.5);
  333.     } else {
  334.         return Math.atan2(deltaX, deltaY);
  335.     }
  336. };

  337. // 指定座標を避ける方位角度
  338. Game_AnalogMove.prototype.evadeDirectionRadian = function(x, y, directionRadian) {
  339.     var towardDirectionRadian = this.towardDirectionRadian(x, y);
  340.     var differentialRadian = this.normalizeRadian(towardDirectionRadian - directionRadian);
  341.     if (differentialRadian > Math.PI) differentialRadian -= (Math.PI * 2.0);
  342.     towardDirectionRadian += (differentialRadian < 0 ? Math.PI / 2.0 : - Math.PI / 2.0);
  343.     return this.normalizeRadian(towardDirectionRadian);
  344. };

  345. // 衝突する全てのキャラクター
  346. Game_AnalogMove.prototype.collideCharacters = function(thisCharacter, distancePerFrame) {
  347.     if ($gamePlayer.isInAirship()) {
  348.         return [];
  349.     }
  350.     var collideCharacters = this.allCharacters();
  351.     collideCharacters = collideCharacters.filter(function(character) {
  352.         return character !== thisCharacter && !character.isThrough();
  353.     });
  354.     collideCharacters = collideCharacters.filter(function(character) {
  355.         var crntDistance = this.deltaXY(this._crntRealX, this._crntRealY, character._realX, character._realY)
  356.         var nextDistance = this.deltaXY(this._nextRealX, this._nextRealY, character._realX, character._realY);
  357.         if (nextDistance < crntDistance) {
  358.             if (nextDistance < 0.5 + distancePerFrame) {
  359.                 this._collideEvents.push(character);
  360.             } else if (nextDistance < 1.0 - distancePerFrame &&
  361.                 character._priorityType === thisCharacter._priorityType) {
  362.                 this._collideEvents.push(character);
  363.                 return true;
  364.             }
  365.         }
  366.         return false;
  367.     }, this);
  368.     var self = this;
  369.     collideCharacters.sort(function(character1, character2) {
  370.         var distance1 = self.deltaXYFrom(character1._realX + 0.5, character1._realY + 0.5);
  371.         var distance2 = self.deltaXYFrom(character2._realX + 0.5, character2._realY + 0.5);
  372.         return (distance2 - distance1);
  373.     });
  374.     if (this.isThrough()) {
  375.         return [];
  376.     }
  377.     return collideCharacters;
  378. };

  379. // マップ上の全てのキャラクター
  380. Game_AnalogMove.prototype.allCharacters = function() {
  381.     var player = [$gamePlayer];
  382.     var events = $gameMap.events();
  383.     var followers = $gamePlayer.followers().visibleFollowers();
  384.     return ([$gamePlayer].concat($gameMap.events(), $gamePlayer.followers().visibleFollowers()));
  385. };

  386. // 衝突するイベント
  387. Game_AnalogMove.prototype.collideEvents = function() {
  388.     return this._collideEvents;
  389. }

  390. // 衝突する壁の座標
  391. Game_AnalogMove.prototype.collideWallXY = function(thisCharacter, distancePerFrame) {
  392.     var nextCenterX = this._nextRealX + 0.5;
  393.     var nextCenterY = this._nextRealY + 0.5;
  394.     var x = (Math.floor(nextCenterX) + $gameMap.width()).mod($gameMap.width());
  395.     var y = (Math.floor(nextCenterY) + $gameMap.height()).mod($gameMap.height());
  396.     var tile5 = Game_CollideMap._tiles[x][y];
  397.     var wallX = undefined;
  398.     var wallY = undefined;
  399.     if (this._crntRealX >= this._nextRealX) {
  400.         // 左の壁
  401.         var x2 = $gameMap.roundX(Math.floor(nextCenterX - 0.5));
  402.         if (!$gameMap.isValid(x2, y)) {
  403.             wallX = tile5._x4;
  404.         } else {
  405.             var tile4 = Game_CollideMap._tiles[x2][y];
  406.             if (tile4._e6 && Math.abs(this.deltaX(nextCenterX, tile5._x4)) < 0.5 + distancePerFrame) {
  407.                 this._collideEvents.push.apply(this._collideEvents, $gameMap.eventsXy(x2, y));
  408.                 if (!this.isThrough()) {
  409.                     wallX = tile4._x6;
  410.                 }
  411.             }
  412.         }
  413.     } else {
  414.         // 右の壁
  415.         var x2 = $gameMap.roundX(Math.floor(nextCenterX + 0.5));
  416.         if (!$gameMap.isValid(x2, y)) {
  417.             wallX = tile5._x6;
  418.         } else {
  419.             var tile6 = Game_CollideMap._tiles[x2][y];
  420.             if (tile6._e4 && Math.abs(this.deltaX(nextCenterX, tile5._x6)) < 0.5 + distancePerFrame) {
  421.                 this._collideEvents.push.apply(this._collideEvents, $gameMap.eventsXy(x2, y));
  422.                 if (!this.isThrough()) {
  423.                     wallX = tile6._x4;
  424.                 }
  425.             }
  426.         }
  427.     }
  428.     if (this._crntRealY >= this._nextRealY) {
  429.         // 上の壁
  430.         var y2 = $gameMap.roundY(Math.floor(nextCenterY - 0.5));
  431.         if (!$gameMap.isValid(x, y2)) {
  432.             wallY = tile5._y8;
  433.         } else {
  434.             var tile8 = Game_CollideMap._tiles[x][y2];
  435.             if (tile8._e2 && Math.abs(this.deltaY(nextCenterY, tile5._y8)) < 0.5 + distancePerFrame) {
  436.                 this._collideEvents.push.apply(this._collideEvents, $gameMap.eventsXy(x, y2));
  437.                 if (!this.isThrough()) {
  438.                     wallY = tile8._y2;
  439.                 }
  440.             }
  441.         }
  442.     } else {
  443.         // 下の壁
  444.         var y2 = $gameMap.roundY(Math.floor(nextCenterY + 0.5));
  445.         if (!$gameMap.isValid(x, y2)) {
  446.             wallY = tile5._y2;
  447.         } else {
  448.             var tile2 = Game_CollideMap._tiles[x][y2];
  449.             if (tile2._e8 && Math.abs(this.deltaY(nextCenterY, tile5._y2)) < 0.5 + distancePerFrame) {
  450.                 this._collideEvents.push.apply(this._collideEvents, $gameMap.eventsXy(x, y2));
  451.                 if (!this.isThrough()) {
  452.                     wallY = tile2._y8;
  453.                 }
  454.             }
  455.         }
  456.     }
  457.     return {x: wallX, y: wallY};
  458. };

  459. // 衝突する角の座標
  460. Game_AnalogMove.prototype.collideCornerXY = function(thisCharacter, distancePerFrame) {
  461.     if (this.isThrough()) {
  462.         return undefined;
  463.     }
  464.     var nextCenterX = this._nextRealX + 0.5
  465.     var nextCenterY = this._nextRealY + 0.5
  466.     if (this._nextRealX < this._crntRealX || this._nextRealY < this._crntRealY) {
  467.         // 左上の角
  468.         var x = (Math.floor(nextCenterX - 0.5) + $gameMap.width()).mod($gameMap.width());
  469.         var y = (Math.floor(nextCenterY - 0.5) + $gameMap.height()).mod($gameMap.height());
  470.         var tile7 = Game_CollideMap._tiles[x][y];
  471.         if (tile7._a3 && this.deltaXY(nextCenterX, nextCenterY, tile7._x3, tile7._y3) < 0.5 - distancePerFrame) {
  472.             return { x: tile7._x3, y: tile7._y3 };
  473.         }
  474.     }
  475.     if (this._nextRealX < this._crntRealX || this._nextRealY > this._crntRealY) {
  476.         // 左下の角
  477.         var x = (Math.floor(nextCenterX - 0.5) + $gameMap.width()).mod($gameMap.width());
  478.         var y = (Math.floor(nextCenterY + 0.5) + $gameMap.height()).mod($gameMap.height());
  479.         var tile1 = Game_CollideMap._tiles[x][y];
  480.         if (tile1._a9 && this.deltaXY(nextCenterX, nextCenterY, tile1._x9, tile1._y9) < 0.5 - distancePerFrame) {
  481.             return { x: tile1._x9, y: tile1._y9 };
  482.         }
  483.     }
  484.     if (this._nextRealX > this._crntRealX || this._nextRealY < this._crntRealY) {
  485.         // 右上の角
  486.         var x = (Math.floor(nextCenterX + 0.5) + $gameMap.width()).mod($gameMap.width());
  487.         var y = (Math.floor(nextCenterY - 0.5) + $gameMap.height()).mod($gameMap.height());
  488.         var tile9 = Game_CollideMap._tiles[x][y];
  489.         if (tile9._a1 && this.deltaXY(nextCenterX, nextCenterY, tile9._x1, tile9._y1) < 0.5 - distancePerFrame) {
  490.             return { x: tile9._x1, y: tile9._y1 };
  491.         }
  492.     }
  493.     if (this._nextRealX > this._crntRealX || this._nextRealY > this._crntRealY) {
  494.         // 右下の角
  495.         var x = (Math.floor(nextCenterX + 0.5) + $gameMap.width()).mod($gameMap.width());
  496.         var y = (Math.floor(nextCenterY + 0.5) + $gameMap.height()).mod($gameMap.height());
  497.         var tile3 = Game_CollideMap._tiles[x][y];
  498.         if (tile3._a7 && this.deltaXY(nextCenterX, nextCenterY, tile3._x7, tile3._y7) < 0.5 - distancePerFrame) {
  499.             return { x: tile3._x7, y: tile3._y7 };
  500.         }
  501.     }
  502.     return undefined;
  503. };

  504. // 移動中判定の更新
  505. Game_AnalogMove.prototype.updateIsMoving = function(thisCharacter) {
  506.     this._isMoving = (thisCharacter._realX !== this._nextRealX || thisCharacter._realY !== this._nextRealY);
  507. };

  508. // 移動中判定
  509. Game_AnalogMove.prototype.isMoving = function() {
  510.     return this._isMoving;
  511. };

  512. // すり抜け判定の更新
  513. Game_AnalogMove.prototype.updateIsThrough = function(thisCharacter) {
  514.     this._isThrough = thisCharacter.isThrough() && (thisCharacter.constructor !== Game_Follower || $gamePlayer.isThrough());
  515. };

  516. // すり抜け判定
  517. Game_AnalogMove.prototype.isThrough = function() {
  518.     return this._isThrough;
  519. };

  520. // 目標方位角度の設定
  521. Game_AnalogMove.prototype.setTargetRadian = function(targetRadian) {
  522.     this._targetRadian = targetRadian;
  523. }

  524. // 水平方向の距離
  525. Game_AnalogMove.prototype.deltaX = function(x1, x2) {
  526.     return $gameMap.deltaX(x1, x2)
  527. };

  528. // 垂直方向の距離
  529. Game_AnalogMove.prototype.deltaY = function(y1, y2) {
  530.     return $gameMap.deltaY(y1, y2)
  531. };

  532. // 座標間の距離
  533. Game_AnalogMove.prototype.deltaXY = function(x1, y1, x2, y2) {
  534.     return Math.sqrt(Math.pow(this.deltaX(x1, x2), 2) + Math.pow(this.deltaY(y1, y2), 2));
  535. };

  536. // 現在座標との水平方向の距離
  537. Game_AnalogMove.prototype.deltaXFrom = function(x) {
  538.     return this.deltaX(this._crntRealX + 0.5, x);
  539. };

  540. // 現在座標との垂直方向の距離
  541. Game_AnalogMove.prototype.deltaYFrom = function(y) {
  542.     return this.deltaY(this._crntRealY + 0.5, y);
  543. };

  544. // 現在座標との距離
  545. Game_AnalogMove.prototype.deltaXYFrom = function(x, y) {
  546.     return this.deltaXY(this._crntRealX + 0.5, this._crntRealY + 0.5, x, y);
  547. };

  548. // 内部4方向を更新
  549. Game_AnalogMove.prototype.updateDir4 = function(thisCharacter) {
  550.     this._dir4 = thisCharacter.direction();
  551.     this._dir4 = this.dir8ToDir4(this.radianToDir8(this._directionRadian));
  552. };

  553. // 内部4方向を取得
  554. Game_AnalogMove.prototype.dir4 = function() {
  555.     return this._dir4;
  556. };

  557. // 8方向による方位角度の設定
  558. Game_AnalogMove.prototype.setDirectionRadianByDir8 = function(dir8) {
  559.     this._targetRadian = this.dir8ToRadian(dir8);
  560.     this._directionRadian = this._targetRadian;
  561. };

  562. // 8方向を4方向に変換
  563. Game_AnalogMove.prototype.dir8ToDir4 = function(dir8) {
  564.     if (dir8 % 2 === 0) {
  565.         return dir8;
  566.     }
  567.     switch (this._dir4) {
  568.     case 8:
  569.         switch (dir8) {
  570.         case 3:  return 6;
  571.         case 1:  return 4;
  572.         default: return 8;
  573.         }
  574.     case 6:
  575.         switch (dir8) {
  576.         case 1:  return 2;
  577.         case 7:  return 8;
  578.         default: return 6;
  579.         }
  580.     case 2:
  581.         switch (dir8) {
  582.         case 7:  return 4;
  583.         case 9:  return 6;
  584.         default: return 2;
  585.         }
  586.     case 4:
  587.         switch (dir8) {
  588.         case 9:  return 8;
  589.         case 3:  return 2;
  590.         default: return 4;
  591.         }
  592.     }
  593.     return undefined;
  594. };

  595. // 方向角度を8方向に変換
  596. Game_AnalogMove.prototype.radianToDir8 = function(radian) {
  597.     radian = this.normalizeRadian(radian);
  598.     return (
  599.         radian < Math.PI / 8.0 *  1.0 ? 8 :
  600.         radian < Math.PI / 8.0 *  3.0 ? 7 :
  601.         radian < Math.PI / 8.0 *  5.0 ? 4 :
  602.         radian < Math.PI / 8.0 *  7.0 ? 1 :
  603.         radian < Math.PI / 8.0 *  9.0 ? 2 :
  604.         radian < Math.PI / 8.0 * 11.0 ? 3 :
  605.         radian < Math.PI / 8.0 * 13.0 ? 6 :
  606.         radian < Math.PI / 8.0 * 15.0 ? 9 : 8
  607.     )
  608. };

  609. // 8方向を方向角度に変換
  610. Game_AnalogMove.prototype.dir8ToRadian = function(dir8) {
  611.     return (
  612.         dir8 === 8 ? Math.PI / 4.0  * 0.0 :
  613.         dir8 === 7 ? Math.PI / 4.0  * 1.0 :
  614.         dir8 === 4 ? Math.PI / 4.0  * 2.0 :
  615.         dir8 === 1 ? Math.PI / 4.0  * 3.0 :
  616.         dir8 === 2 ? Math.PI / 4.0  * 4.0 :
  617.         dir8 === 3 ? Math.PI / 4.0  * 5.0 :
  618.         dir8 === 6 ? Math.PI / 4.0  * 6.0 :
  619.         dir8 === 9 ? Math.PI / 4.0  * 7.0 : undefined
  620.     )
  621. };

  622. //-----------------------------------------------------------------------------
  623. // Game_CollideMap
  624. //
  625. // 衝突マップ
  626. Game_CollideMap = {};

  627. // 衝突マップのセットアップ
  628. Game_CollideMap.setup = function() {
  629.     this._mapId = $gameMap.mapId()
  630.     this._tiles = new Array();
  631.     for (var x = 0; x < $gameMap.width(); x++) {
  632.         this._tiles.push([]);
  633.         for (var y = 0; y < $gameMap.height(); y++) {
  634.             this._tiles[x].push(new Game_CollideTile(x, y));
  635.         }
  636.     }
  637. };

  638. //-----------------------------------------------------------------------------
  639. // Game_CollideTile
  640. //
  641. // 衝突タイルクラス
  642. function Game_CollideTile () {
  643.     this.initialize.apply(this, arguments);
  644. };

  645. // 衝突タイルクラスの初期化
  646. Game_CollideTile.prototype.initialize = function(x, y) {
  647.     this._x = Math.floor(x);
  648.     this._y = Math.floor(y);
  649.     this._x5 = this._x + 0.5;
  650.     this._y5 = this._y + 0.5;
  651.     this._x4 = this._x1 = this._x7 = this._x;
  652.     this._x6 = this._x3 = this._x9 = x + 1.0;
  653.     this._y8 = this._y7 = this._y9 = this._y;
  654.     this._y2 = this._y1 = this._y3 = y + 1;
  655.     this._e8 = !this.isPassable(this._x, this._y, 8);
  656.     this._e6 = !this.isPassable(this._x, this._y, 6);
  657.     this._e2 = !this.isPassable(this._x, this._y, 2);
  658.     this._e4 = !this.isPassable(this._x, this._y, 4);
  659.     this._a9 = (this._e8 || this._e6) && this.isCorner(9);
  660.     this._a3 = (this._e6 || this._e2) && this.isCorner(3);
  661.     this._a1 = (this._e2 || this._e4) && this.isCorner(1);
  662.     this._a7 = (this._e4 || this._e8) && this.isCorner(7);
  663. };

  664. // 衝突タイルクラス通行可能判定 辺
  665. Game_CollideTile.prototype.isPassable = function(x, y, d) {
  666.     var x2 = $gameMap.roundXWithDirection(x, d);
  667.     var y2 = $gameMap.roundYWithDirection(y, d);
  668.     var d2 = $gamePlayer.reverseDir(d);
  669.     return $gamePlayer.isMapPassable(x, y, d) && $gamePlayer.isMapPassable(x2, y2, d2) && $gameMap.isValid(x2, y2);
  670. };

  671. // 衝突タイルクラス通行可能判定 角
  672. Game_CollideTile.prototype.isCorner = function(d) {
  673.     switch (d) {
  674.     case 9:  return this.isPassable(this._x, this._y - 1, 6) && this.isPassable(this._x + 1, this._y, 8);
  675.     case 3:  return this.isPassable(this._x, this._y + 1, 6) && this.isPassable(this._x + 1, this._y, 2);
  676.     case 1:  return this.isPassable(this._x, this._y + 1, 4) && this.isPassable(this._x - 1, this._y, 2);
  677.     case 7:  return this.isPassable(this._x, this._y - 1, 4) && this.isPassable(this._x - 1, this._y, 8);
  678.     default: return false;
  679.     }
  680. };

  681. //-----------------------------------------------------------------------------
  682. // Game_Map
  683. //
  684. // マップクラス

  685. // マップクラスのセットアップ
  686. Sanshiro.Game_AnalogMove.Game_Map_setup = Game_Map.prototype.setup;
  687. Game_Map.prototype.setup = function(mapId) {
  688.     Sanshiro.Game_AnalogMove.Game_Map_setup.call(this, mapId);
  689.     Game_CollideMap.setup();
  690. };

  691. //-----------------------------------------------------------------------------
  692. // Game_System
  693. //
  694. // システムクラス

  695. // システムの初期化
  696. Sanshiro.Game_AnalogMove.Game_System_initialize = Game_System.prototype.initialize;
  697. Game_System.prototype.initialize = function() {
  698.     Sanshiro.Game_AnalogMove.Game_System_initialize.call(this);
  699.     this.setAnalogMoveValid(PluginManager.parameters('SAN_AnalogMove')['Valid'] === 'ON');
  700. };

  701. // システムの個別のアナログムーブ有効化フラグの設定
  702. Game_System.prototype.setAnalogMoveValid = function(valid) {
  703.     this._analogMoveValid = valid;
  704. };

  705. // システムの個別のアナログムーブ有効判定
  706. Game_System.prototype.analogMoveValid = function() {
  707.     return this._analogMoveValid;
  708. };

  709. //-----------------------------------------------------------------------------
  710. // Input
  711. //
  712. // インプットクラス

  713. // ゲームパッドステータスの更新
  714. Sanshiro.Game_AnalogMove.Input_updateGamepadState = Input._updateGamepadState;
  715. Input._updateGamepadState = function(gamepad) {
  716.     Sanshiro.Game_AnalogMove.Input_updateGamepadState.call(this, gamepad);
  717.     this._updateGamepadAxes(gamepad);
  718. };

  719. // アナログスティック値の更新
  720. Input._updateGamepadAxes = function(gamepad) {
  721.     this._axes = gamepad.axes;
  722. };

  723. // 左アナログスティック
  724. Input.leftStick = function() {
  725.     if (this._axes === undefined) {
  726.         return undefined;
  727.     }
  728.     var threshold = 0.1;
  729.     var x = this._axes[0];
  730.     var y = this._axes[1];
  731.     var tilt = (Math.pow(x, 2) + Math.pow(y, 2));
  732.     if (tilt < threshold) {
  733.         tilt = 0.0;
  734.     } else if (tilt > 1.0) {
  735.         tilt = 1.0;
  736.     }
  737.     var direction = 0.0
  738.     if (x === 0.0) {
  739.         direction = (-y > 0 ? Math.PI * 0.0 : Math.PI * 1.0);
  740.     } else if (y === 0.0) {
  741.         direction = (-x > 0 ? Math.PI * 0.5 : Math.PI * 1.5);
  742.     } else {
  743.         direction = Math.atan2(-x, -y);
  744.     }
  745.     return {tilt: tilt, direction: direction};
  746. };

  747. // 右アナログスティック
  748. Input.rightStick = function() {
  749.     if (this._axes === undefined) {
  750.         return undefined;
  751.     }
  752.     var threshold = 0.1;
  753.     var x = this._axes[2];
  754.     var y = this._axes[3];
  755.     var tilt = (Math.pow(x, 2) + Math.pow(y, 2));
  756.     if (tilt < threshold) {
  757.         tilt = 0.0;
  758.     } else if (tilt > 1.0) {
  759.         tilt = 1.0;
  760.     }
  761.     var direction = 0.0
  762.     if (x === 0.0) {
  763.         direction = (-y > 0 ? Math.PI * 0.0 : Math.PI * 1.0);
  764.     } else if (y === 0.0) {
  765.         direction = (-x > 0 ? Math.PI * 0.5 : Math.PI * 1.5);
  766.     } else {
  767.         direction = Math.atan2(-x, -y);
  768.     }
  769.     return {tilt: tilt, direction: direction};
  770. };

  771. //-----------------------------------------------------------------------------
  772. // Scene_Map
  773. //
  774. // マップシーンクラス

  775. // マップシーンクラスのメニューシーン呼び出し更新
  776. Sanshiro.Game_AnalogMove.Scene_Map_updateCallMenu = Scene_Map.prototype.updateCallMenu;
  777. Scene_Map.prototype.updateCallMenu = function() {
  778.     var isMoving = $gamePlayer.isMoving;
  779.     $gamePlayer.isMoving = function() { return false; };
  780.     Sanshiro.Game_AnalogMove.Scene_Map_updateCallMenu.call(this);
  781.     $gamePlayer.isMoving = isMoving;
  782. };

  783. // マップシーンクラスの開始処理
  784. Sanshiro.Game_AnalogMove.Scene_Map_start = Scene_Map.prototype.start;
  785. Scene_Map.prototype.start = function() {
  786.     Sanshiro.Game_AnalogMove.Scene_Map_start.call(this);
  787.     Game_CollideMap.setup();
  788. };

  789. //-----------------------------------------------------------------------------
  790. // Game_CharacterBase
  791. //
  792. // キャラクターベースクラス

  793. // キャラクターベースクラスのプロパティ初期化
  794. Sanshiro.Game_AnalogMove.Game_CharacterBase_initMembers = Game_CharacterBase.prototype.initMembers;
  795. Game_CharacterBase.prototype.initMembers = function() {
  796.     Sanshiro.Game_AnalogMove.Game_CharacterBase_initMembers.call(this);
  797.     this._analogMove = new Game_AnalogMove(this);
  798. };

  799. // キャラクターベースクラスの方向設定
  800. Sanshiro.Game_AnalogMove.Game_CharacterBase_setDirection = Game_CharacterBase.prototype.setDirection;
  801. Game_CharacterBase.prototype.setDirection = function(d) {
  802.     Sanshiro.Game_AnalogMove.Game_CharacterBase_setDirection.call(this, d);
  803.     if (!this.isDirectionFixed()) {
  804.         this._analogMove.setDirectionRadianByDir8(this._direction);
  805.     }
  806. };

  807. // キャラクターベースクラスのアナログムーブによる方向設定
  808. Game_CharacterBase.prototype.setDirectionAnalog = function(d) {
  809.     if (!this.isDirectionFixed()) {
  810.         this._direction = d;
  811.     }
  812. };
  813.    
  814. // キャラクターベースクラスの移動中判定
  815. Sanshiro.Game_AnalogMove.Game_CharacterBase_isMoving = Game_CharacterBase.prototype.isMoving;
  816. Game_CharacterBase.prototype.isMoving = function() {
  817.     if (this.isAnalogMoveValid()) {
  818.         return this._analogMove.isMoving() && Game_AnalogMove.canMove();
  819.     }
  820.     return Sanshiro.Game_AnalogMove.Game_CharacterBase_isMoving.call(this);
  821. };

  822. // キャラクターベースクラスのフレーム更新
  823. Sanshiro.Game_AnalogMove.Game_CharacterBase_update = Game_CharacterBase.prototype.update;
  824. Game_CharacterBase.prototype.update = function() {
  825.     if (this.isAnalogMoveValid()) {
  826.         this._analogMove.update(this);
  827.         var isMoving = this.isMoving;
  828.         this.isMoving = function() { return false; };
  829.         this.refreshBushDepth();
  830.         this.isMoving = isMoving;
  831.     }
  832.     return Sanshiro.Game_AnalogMove.Game_CharacterBase_update.call(this);
  833. };

  834. // キャラクターベースクラスの移動更新
  835. Sanshiro.Game_AnalogMove.Game_CharacterBase_updateMove = Game_CharacterBase.prototype.updateMove;
  836. Game_CharacterBase.prototype.updateMove = function() {
  837.     if (this.isAnalogMoveValid()) {
  838.         return;
  839.     }
  840.     return Sanshiro.Game_AnalogMove.Game_CharacterBase_updateMove.call(this)
  841. };

  842. // キャラクターベースクラスの個別のアナログムーブ有効化フラグの設定
  843. Game_CharacterBase.prototype.setAnalogMoveValid = function(valid) {
  844.     this._analogMove.setValid(valid);
  845. };

  846. // キャラクターベースクラスの個別のアナログムーブ有効判定
  847. Game_CharacterBase.prototype.isAnalogMoveValid = function() {
  848.     return this._analogMove.isValid();
  849. };

  850. //-----------------------------------------------------------------------------
  851. // Game_Character
  852. //
  853. // キャラクタークラス

  854. // キャラクタークラスのルート指定移動
  855. Sanshiro.Game_AnalogMove.Game_Character_updateRoutineMove = Game_Character.prototype.updateRoutineMove;
  856. Game_Character.prototype.updateRoutineMove = function() {
  857.     if (this.isAnalogMoveValid()) {
  858.         return;
  859.     }
  860.     return Sanshiro.Game_AnalogMove.Game_Character_updateRoutineMove.call(this);
  861. };

  862. // キャラクタークラスの個別のアナログムーブ有効判定
  863. Game_Character.prototype.isAnalogMoveValid = function() {
  864.     return Game_CharacterBase.prototype.isAnalogMoveValid.call(this) && !this._moveRouteForcing;
  865. };

  866. //-----------------------------------------------------------------------------
  867. // Game_Player
  868. //
  869. // プレイヤークラス

  870. // プレイヤークラスのプロパティ初期化
  871. Sanshiro.Game_AnalogMove.Game_Player_initMembers = Game_Player.prototype.initMembers;
  872. Game_Player.prototype.initMembers = function() {
  873.     Sanshiro.Game_AnalogMove.Game_Player_initMembers.call(this);
  874.     this.setAnalogMoveValid(PluginManager.parameters('SAN_AnalogMove')['Player'] === 'ON');
  875.     this._encounterCountAnalog = 0.0;
  876. };

  877. // プレイヤークラスのキー入力による移動
  878. Sanshiro.Game_AnalogMove.Game_Player_moveByInput = Game_Player.prototype.moveByInput;
  879. Game_Player.prototype.moveByInput = function() {
  880.     if (this.isAnalogMoveValid()) {
  881.         this._analogMove.moveByInput(this);
  882.         this.checkEventTriggerTouchAnalog();
  883.         this.checkEventTriggerActionAnalog();
  884.         return;
  885.     }
  886.     return Sanshiro.Game_AnalogMove.Game_Player_moveByInput.call(this);
  887. };

  888. // プレイヤークラスのダッシュ状態の更新
  889. Sanshiro.Game_AnalogMove.Game_Player_updateDashing = Game_Player.prototype.updateDashing;
  890. Game_Player.prototype.updateDashing = function() {
  891.     var isMoving = this.isMoving;
  892.     this.isMoving = function() { return false };
  893.     Sanshiro.Game_AnalogMove.Game_Player_updateDashing.call(this);
  894.     this.isMoving = isMoving;
  895. };

  896. // プレイヤークラスのアナログムーブ時の接触イベント起動処理
  897. Game_Player.prototype.checkEventTriggerTouchAnalog = function() {
  898.     if (!this.isThrough() && !$gameMap.isEventRunning()) {
  899.         var event = this._analogMove.collideEvents()[0];
  900.         if (!!event && event.isTriggerIn([1, 2])) {
  901.             event.start();
  902.         }
  903.     }
  904. };

  905. // プレイヤークラスのアナログムーブ時の決定ボタンイベント起動処理
  906. Game_Player.prototype.checkEventTriggerActionAnalog = function() {
  907.     this.triggerAction();
  908. };

  909. // プレイヤークラスの移動更新
  910. Sanshiro.Game_AnalogMove.Game_Player_updateMove = Game_Player.prototype.updateMove;
  911. Game_Player.prototype.updateMove = function() {
  912.     if (this.isAnalogMoveValid()) {
  913.         this.updateEncounterCountAnalog();
  914.     }
  915.     Sanshiro.Game_AnalogMove.Game_Player_updateMove.call(this);
  916. };

  917. // プレイヤークラスのアナログ移動エンカウント歩数カウントダウン
  918. Game_Player.prototype.updateEncounterCountAnalog = function() {
  919.     if (this.canEncounter()) {
  920.         this._encounterCount -= this.encounterProgressValue() * this._analogMove.encounterCount();
  921.     }
  922. };

  923. // プレイヤークラスの乗り物搭乗中のフレーム更新
  924. Sanshiro.Game_AnalogMove.Game_Player_updateVehicleGetOn = Game_Player.prototype.updateVehicleGetOn;
  925. Game_Player.prototype.updateVehicleGetOn = function() {
  926.     Sanshiro.Game_AnalogMove.Game_Player_updateVehicleGetOn.call(this);
  927.     if (!this._vehicleGettingOn) {
  928.         Game_CollideMap.setup();
  929.     }
  930. };

  931. // プレイヤークラスの乗り物下乗中のフレーム更新
  932. Sanshiro.Game_AnalogMove.Game_Player_updateVehicleGetOff = Game_Player.prototype.updateVehicleGetOff;
  933. Game_Player.prototype.updateVehicleGetOff = function() {
  934.     Sanshiro.Game_AnalogMove.Game_Player_updateVehicleGetOff.call(this);
  935.     if (!this._vehicleGettingOff) {
  936.         Game_CollideMap.setup();
  937.     }
  938. };

  939. // プレイヤークラスの個別のアナログムーブ有効判定
  940. Game_Player.prototype.isAnalogMoveValid = function() {
  941.     return Game_Character.prototype.isAnalogMoveValid.call(this) &&
  942.         !this._followers.areGathering();
  943. };

  944. //-----------------------------------------------------------------------------
  945. // Game_Follower
  946. //
  947. // フォロワークラス

  948. // フォロワークラスの目標キャラクター追尾
  949. Game_Follower.prototype.chaseCharacterAnalog = function(character) {
  950.     this._analogMove.followCharacter(this, character);
  951. };

  952. // フォロワークラスのアナログムーブ有効判定
  953. Game_Follower.prototype.isAnalogMoveValid = function() {
  954.     return $gamePlayer.isAnalogMoveValid();
  955. };

  956. // フォロワークラスの移動更新
  957. Sanshiro.Game_AnalogMove.Game_Follower_updateMove = Game_Follower.prototype.updateMove;
  958. Game_Follower.prototype.updateMove = function() {
  959.     Sanshiro.Game_AnalogMove.Game_Follower_updateMove.call(this);
  960. };

  961. //-----------------------------------------------------------------------------
  962. // Game_Followers
  963. //
  964. // フォロワーズクラス

  965. // フォロワーズクラスのフレーム更新
  966. Sanshiro.Game_AnalogMove.Game_Followers_update = Game_Followers.prototype.update;
  967. Game_Followers.prototype.update = function() {
  968.     if ($gamePlayer.isAnalogMoveValid()) {
  969.         this.updateMoveAnalog();
  970.         this.forEach(function(follower) {
  971.             follower.update();
  972.         }, this);
  973.         return;
  974.     }
  975.     Sanshiro.Game_AnalogMove.Game_Followers_update.call(this);
  976. };

  977. // フォロワーズクラスのアナログ移動の更新
  978. Game_Followers.prototype.updateMoveAnalog = function() {
  979.     for (var i = this._data.length - 1; i >= 0; i--) {
  980.         var precedingCharacter = (i > 0 ? this._data[i - 1] : $gamePlayer);
  981.         this._data[i].chaseCharacterAnalog(precedingCharacter);
  982.     }
  983. };

  984. //-----------------------------------------------------------------------------
  985. // Game_Interpreter
  986. //
  987. // インタープリタークラス

  988. // プラグインコマンド
  989. Sanshiro.Game_AnalogMove.Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
  990. Game_Interpreter.prototype.pluginCommand = function(command, args) {
  991.     Sanshiro.Game_AnalogMove.Game_Interpreter_pluginCommand.call(this, command, args);
  992.     if (command === 'AnalogMove') {
  993.         switch (args[0]) {
  994.         case 'ON':
  995.             $gameSystem.setAnalogMoveValid(true);
  996.             break;
  997.         case 'OFF':
  998.             $gameSystem.setAnalogMoveValid(false);
  999.             break;
  1000.         case 'Player':
  1001.             switch (args[1]) {
  1002.             case 'ON':
  1003.                 $gamePlayer.setAnalogMoveValid(true);
  1004.                 break;
  1005.             case 'OFF':
  1006.                 $gamePlayer.setAnalogMoveValid(false);
  1007.                 break;
  1008.             }
  1009.         break;
  1010.         }
  1011.     $gamePlayer.refresh();
  1012.     }
  1013. };
复制代码

也不錯

点评

呃,谢谢  发表于 2016-6-9 09:06
回复

使用道具 举报

梦石
0
星屑
50
在线时间
46 小时
注册时间
2014-3-14
回帖
32
 楼主| 发表于 2016-6-9 08:49:48 | 显示全部楼层
本帖最后由 moe2333 于 2016-6-9 08:51 编辑
taroxd 发表于 2016-6-9 07:42
Quasi Movement 这个插件我觉得挺不错的,楼主可以参考一下


quasi movement如果想要更精确的collision mask需要给每张地图制作一张额外的collision map...然而我不希望这样

如果我找得到合适的也就不会自己写了...我的游戏里不需要交通工具和鼠标操作,于是就变成现在这个样子了
回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部