//=============================================================================
// RegionPassage.js
//=============================================================================
/*:
* @target MZ
* @plugindesc Provide advanced options for tile passage.
* @author taroxd
*
* @param Passable Regions
* @desc Tiles are always passable in these regions.
* @type number[]
* @max 255
* @min 0
* @default []
*
* @param Impassable Regions
* @desc Tiles are always not passable in these regions.
* @type number[]
* @max 255
* @min 0
* @default []
*
* @help This plugin does not provide plugin commands.
*/
void function() {
var parameters = PluginManager.parameters('RegionPassage');
var PASSABLE_REGIONS = JSON.parse(parameters['Passable Regions'])
var IMPASSABLE_REGIONS = JSON.parse(parameters['Impassable Regions'])
var REGIONS = {};
PASSABLE_REGIONS.forEach(function(r) {
REGIONS[r] = true;
});
IMPASSABLE_REGIONS.forEach(function(r) {
REGIONS[r] = false;
});
/* Advanced options:
*
* REGIONS[r] = function(regionId)
*
* The function determines whether it is possible
* to go to region `regionId' from region `r'.
* If the return value is true,
* then it is always possible regardless of the tile.
* If the return value is false,
* then it is always not possible regardless of the tile.
* Any other return value will leave the passage settings unchanged.
*
* For example,
* Region 3 can be entered from and only from region 4.
* And Tiles are always passable in region 3.
* REGIONS[3] = function(r) { return r === 3 || r === 4; };
*
* You cannot walk between region 5 and region 6.
* REGIONS[5] = function(r) { return r !== 6 && null };
*/
var enable = Object.keys(REGIONS).length > 0;
if (!enable) return;
var ip = Game_Map.prototype.isPassable;
Game_Map.prototype.isPassable = function(x, y, d) {
var settings = REGIONS[$gameMap.regionId(x, y)];
if (typeof(settings) === 'function') {
var x2 = $gameMap.roundXWithDirection(x, d);
var y2 = $gameMap.roundYWithDirection(y, d);
settings = settings($gameMap.regionId(x2, y2));
}
if (typeof(settings) === 'boolean') {
return settings;
}
return ip.call(this, x, y, d);
};
}();
Regionpassage
Inputextra
//=============================================================================
// InputExtra.js
//=============================================================================
/*:
* @target MZ
* @plugindesc Extend Input with the full keyboard.
* @author taroxd
*
* @help
*
* API:
* InputExtra.isPressed(keyCode)
* InputExtra.isTriggered(keyCode)
* InputExtra.isRepeated(keyCode)
* InputExtra.isLongPressed(keyCode)
*
* `InputExtra' is basically the same as `Input'
* except that it accepts the keyCode as a parameter.
*/
window.InputExtra = function() {
var states = {};
function appendToInput(name, func) {
var old = Input[name];
Input[name] = function() {
old.apply(Input, arguments);
func.apply(null, arguments);
}
}
function onKeyDown(event) {
var keyCode = event.keyCode;
if(!states[keyCode]) {
states[keyCode] = 0;
}
}
function onKeyUp(event) {
var keyCode = event.keyCode;
if (keyCode) {
delete states[keyCode];
}
}
function clear() {
states = {};
}
function update() {
for (var code in states) {
++states[code];
}
}
appendToInput('_onKeyDown', onKeyDown);
appendToInput('_onKeyUp', onKeyUp);
appendToInput('_onLostFocus', clear);
appendToInput('update', update);
appendToInput('clear', clear);
return {
isPressed: function(keyCode) {
return states[keyCode] != null;
},
isTriggered: function(keyCode) {
return states[keyCode] === 1;
},
isRepeated: function(keyCode) {
var state = states[keyCode];
return (state === 1 ||
(state >= Input.keyRepeatWait &&
state % Input.keyRepeatInterval === 0));
},
isLongPressed: function(keyCode) {
return states[keyCode] >= Input.keyRepeatWait;
}
};
}();
Displaypassage
//=============================================================================
// PassageExtra.js
//=============================================================================
/*:
* @target MZ
* @plugindesc Display passage information in playtest.
* @author taroxd
*
* @param Opacity
* @desc No description.
* @type number
* @max 255
* @min 0
* @default 150
*
* @param NG Color
* @desc The color displayed above inpassable tiles.
* @default #ff0000
*
* @param OK Color
* @desc The color displayed above passable tiles.
* @default #0000ff
*
* @param NG Width
* @desc No description.
* @type number
* @max 24
* @min 0
* @default 4
*
* @param Only Test
* @desc Enable only in playtest.
* @type boolean
* @default true
*
* @help This plugin does not provide plugin commands.
*
* Press Ctrl Key to display passage information.
*/
void function() {
var parameters = PluginManager.parameters('DisplayPassage');
var TEST_ONLY = parameters['Test Only'] !== 'false';
var enable = !TEST_ONLY || Utils.isOptionValid("test");
if (!enable) return;
var OPACITY = parseInt(parameters['Opacity']);
var NG_COLOR = parameters['NG Color'];
var OK_COLOR = parameters['OK Color'];
var NG_WIDTH = parseInt(parameters['NG Width']);
// Advanced options:
// Never change it unless you know what you are doing.
var Z = 20;
function shouldChangeVisibility() {
return Input.isTriggered('control');
}
function PassageSprite() {
TilingSprite.call(this);
this.visible = false;
this.move(0, 0, Graphics.width, Graphics.height);
this.z = Z;
this.opacity = OPACITY;
this.refresh();
}
PassageSprite.prototype = Object.create(TilingSprite.prototype);
PassageSprite.prototype.constructor = PassageSprite;
PassageSprite.prototype.update = function() {
if (shouldChangeVisibility()) {
this.visible = !this.visible;
}
this.origin.x = $gameMap.displayX() * $gameMap.tileWidth();
this.origin.y = $gameMap.displayY() * $gameMap.tileHeight();
};
PassageSprite.prototype.refresh = function() {
var w = $gameMap.width();
var h = $gameMap.height();
this.bitmap = new Bitmap(
w * $gameMap.tileWidth(),
h * $gameMap.tileHeight());
for (var x = 0; x < w; ++x) {
for (var y = 0; y < h; ++y) {
this.drawPoint(x, y);
}
}
};
PassageSprite.prototype.drawPoint = function(x, y) {
var ngDirs = [2, 4, 6, 8].filter(function(d) {
return !$gameMap.isPassable(x, y, d);
});
var bitmap = this.bitmap;
var tw = $gameMap.tileWidth();
var th = $gameMap.tileHeight();
if (ngDirs.length === 4) {
bitmap.fillRect(x * tw, y * th, tw, th, NG_COLOR);
return;
}
bitmap.fillRect(x * tw, y * th, tw, th, OK_COLOR);
ngDirs.forEach(function(d) {
var dx = d === 6 ? tw - NG_WIDTH : 0;
var dy = d === 2 ? th - NG_WIDTH : 0;
var w, h;
if (d === 2 || d === 8) {
w = tw;
h = NG_WIDTH;
} else {
w = NG_WIDTH;
h = tw;
}
bitmap.fillRect(x * tw + dx, y * th + dy, w, h, NG_COLOR);
});
};
var ct = Spriteset_Map.prototype.createTilemap;
Spriteset_Map.prototype.createTilemap = function() {
ct.call(this);
this._tilemap.addChild(new PassageSprite);
};
}();