-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathDirectionLock.js
86 lines (76 loc) · 2.85 KB
/
DirectionLock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//==============================================================================
// DirectionLock.js
//==============================================================================
var Imported = Imported || {};
Imported.DirectionLock = true;
/*:
* @plugindesc Only allows player to face left or right, while still letting player interact with events up/down
* @author mjshi
*
* @param Lock Player Only
* @type boolean
* @desc Lock the direction of only the player or all sprites?
* @on Player Only
* @off All Sprites
* @default true
*
* @param Lock Horizontal
* @type boolean
* @desc Lock the horizontal direction? (if set to false locks the vertical)
* @on Horizontal
* @off Vertical
* @default true
*
* @help
* ------------------------------------------------------------------------------
* Direction Lock v1.0 by mjshi
* Free for both commercial and non-commercial use, with credit.
* ------------------------------------------------------------------------------
* In this plugin, your character still "turns" but you just can't see it.
* That way, you can still interact with events all around you despite being
* fixed in a direction.
* ------------------------------------------------------------------------------
*
* > Is something broken? Go to http://mjshi.weebly.com/contact.html and I'll
* try my best to help you!
*/
(function () {
/* BEGIN */
var validDirOne = !!eval(PluginManager.parameters('DirectionLock')["Lock Horizontal"]) ? 4 : 2;
var validDirTwo = !!eval(PluginManager.parameters('DirectionLock')["Lock Horizontal"]) ? 6 : 8;
if (!!eval(PluginManager.parameters('DirectionLock')["Lock Player Only"])) {
var alias_mjshi_dirfix_sprite_char_init = Sprite_Character.prototype.initialize;
Sprite_Character.prototype.initialize = function(character) {
alias_mjshi_dirfix_sprite_char_init.call(this, character);
if (character === $gamePlayer) {
this._isPlayer = true;
this._cachedDir = validDirOne;
}
};
var alias_mjshi_dirfix_sprite_characterPatternY = Sprite_Character.prototype.characterPatternY;
Sprite_Character.prototype.characterPatternY = function() {
if (this._isPlayer) {
var d = this._character.direction();
if (d === validDirOne || d === validDirTwo) {
this._cachedDir = d;
}
return (this._cachedDir - 2) / 2;
}
return alias_mjshi_dirfix_sprite_characterPatternY.call(this);
};
} else {
var alias_mjshi_dirfix_sprite_char_init = Sprite_Character.prototype.initialize;
Sprite_Character.prototype.initialize = function(character) {
alias_mjshi_dirfix_sprite_char_init.call(this, character);
this._cachedDir = validDirOne;
};
Sprite_Character.prototype.characterPatternY = function() {
var d = this._character.direction();
if (d === validDirOne || d === validDirTwo) {
this._cachedDir = d;
}
return (this._cachedDir - 2) / 2;
};
}
/* END */
})();