Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // AvilkaJump.js v1.1
- //=============================================================================
- /*:
- * @plugindesc Allows the character to jump.
- * <id:Avilka Jump>
- * @author Drykul
- *
- * @param Disable Jumping
- * @desc If this switch is set to true, jumping will not be enabled.
- * @default 20
- *
- * @param Jump Key
- * @desc The button to press for jumping. alt, control, up, shift, etc
- * @default alt
- *
- * @param Jump Height
- * @desc The maximum height of jump in pixels Default: 240
- * @default 240
- *
- * @param Regular Movement Speed
- * @desc Normal movement speed for the player. Default: 4.5
- * @default 4.5
- *
- * @param Jump Speed
- * @desc How fast movement is while jumping. Default: 6.0
- * @default 6.0
- *
- * @param Fall Speed
- * @desc How fast movement is while falling. Default: 6.0
- * @default 6.0
- *
- * @help
- * ======== INSTALLING ========
- * Enable plugin in the plugin manager. On the first map where player controls
- * are active, have an event run the following code in a script command:
- *
- * $dryPhysics.gravityEnabled = true
- * $dryPhysics.controlsEnabled = true
- *
- * If at any time you want to temporarily suspend jumping ability, just toggle
- * the switch set in the plugin manager settings for this plugin. If you want
- * to disable controls, just run a script command as follows:
- *
- * $dryPhysics.controlsEnabled = false
- *
- * !!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- *
- * Setting jump speed or fall speed anything higher than 6.0 causes problems
- * with collision detection.
- *
- *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- *
- * If you have any bugs to report, requests, or questions you can contact me
- * at drykul(at)cloud9studios.net. I'm also on www.rpgmakerweb.com and
- * www.rpgmakervxace.net as shaynec1981 as well as www.rpgmakermv.co as drykul.
- *
- * No credit is necessary for use of this script in either free
- * or commercial projects. Just shoot me a line and let me know if it was
- * worth your time! :)
- *
- * // CHANGELOG //
- * 2-8-17 - Version 1.0 complete
- * 2-8-17 - Version 1.1
- * ## Changed
- * - Fixed bug with jump height causing player to skyrocket.
- * - Fixed bug where the player could still jump if a game message was being
- * displayed.
- * - Disabled sprite frame from changing while jumping.
- */
- // Set up plugin parameters
- var scriptParameters = $plugins.filter(function (p) {
- return p.description.contains("<id:Avilka Jump>")
- })[0].parameters
- // Set up global namespace
- var $dryPhysics = {
- controlsEnabled: false
- , gravityEnabled: false
- , isFalling: false
- , isJumping: false
- , jumpEnd: 0
- , disableSwitch: scriptParameters['Disable Jumping']
- , jumpKey: scriptParameters['Jump Key']
- , jumpHeight: parseFloat(scriptParameters['Jump Height'])
- , moveSpeed: parseFloat(scriptParameters['Regular Movement Speed'])
- , jumpSpeed: parseFloat(scriptParameters['Jump Speed'])
- , fallSpeed: parseFloat(scriptParameters['Fall Speed'])
- };
- var aliasSceneMapUpdate = Scene_Map.prototype.update;
- Scene_Map.prototype.update = function () {
- aliasSceneMapUpdate.call(this);
- if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
- $gamePlayer._moveSpeed = $dryPhysics.moveSpeed;
- }
- if ($dryPhysics.isJumping) {
- if ($gamePlayer.canPass($gamePlayer._realX, $gamePlayer._realY, 8) == false) {
- $dryPhysics.isJumping = false;
- $dryPhysics.isFalling = true;
- }
- else {
- $gamePlayer._moveSpeed = $dryPhysics.jumpSpeed;
- $gamePlayer._py -= ($dryPhysics.jumpSpeed + 2);
- jumpEndCheck();
- }
- }
- if ($dryPhysics.gravityEnabled == true) {
- gravityCheck();
- }
- if ($dryPhysics.controlsEnabled == true) {
- keyCheck();
- }
- };
- function jumpEndCheck() {
- if ($gamePlayer._py <= $dryPhysics.jumpEnd) {
- $dryPhysics.isJumping = false;
- $dryPhysics.isFalling = true;
- }
- };
- function gravityCheck() {
- if ($dryPhysics.isJumping == false && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 2)) {
- $dryPhysics.isFalling = true;
- $gamePlayer._moveSpeed = $dryPhysics.fallSpeed;
- $gamePlayer._py += ($dryPhysics.fallSpeed + 2);
- }
- else {
- $dryPhysics.isFalling = false;
- }
- };
- function keyCheck() {
- if ($gameSwitches.value($dryPhysics.disableSwitch) === false && $gameMessage.isBusy() === false) {
- if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
- $gamePlayer._directionFix = false;
- if ($gamePlayer._direction == 2) {
- $gamePlayer._direction = 6;
- }
- if ($gamePlayer._direction == 8) {
- $gamePlayer._direction = 4;
- }
- if (Input.isTriggered($dryPhysics.jumpKey)) {
- if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 8)) {
- $dryPhysics.isJumping = true;
- $dryPhysics.jumpEnd = clone($gamePlayer._py);
- $dryPhysics.jumpEnd -= $dryPhysics.jumpHeight;
- $gamePlayer._directionFix = true;
- // if ($gamePlayer._direction == 6) { //
- // $gamePlayer._direction = 2; //
- // } // USED FOR CUSTOM JUMP FRAMES
- // else if ($gamePlayer._direction == 4) { //
- // $gamePlayer._direction = 8; //
- // } //
- }
- }
- }
- }
- if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('left') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 4)) {
- // $gamePlayer._direction = 8; // USED FOR CUSTOM JUMP FRAMES
- $gamePlayer._px -= 4;
- }
- if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('right') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 6)) {
- // $gamePlayer._direction = 2; // USED FOR CUSTOM JUMP FRAMES
- $gamePlayer._px += 4;
- }
- }
- function clone(obj) {
- // Handle the 3 simple types, and null or undefined
- if (null == obj || "object" != typeof obj) return obj;
- // Handle Date
- if (obj instanceof Date) {
- var copy = new Date();
- copy.setTime(obj.getTime());
- return copy;
- }
- // Handle Array
- if (obj instanceof Array) {
- var copy = [];
- for (var i = 0, len = obj.length; i < len; i++) {
- copy[i] = clone(obj[i]);
- }
- return copy;
- }
- // Handle Object
- if (obj instanceof Object) {
- var copy = {};
- for (var attr in obj) {
- if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
- }
- return copy;
- }
- throw new Error("Unable to copy obj! Its type isn't supported.");
- };
- Input.keyMapper = {
- 9: 'tab', // tab
- 13: 'ok', // enter
- 16: 'shift', // shift
- 17: 'control', // control
- 18: 'alt', // alt
- 27: 'escape', // escape
- 32: 'ok', // space
- 33: 'pageup', // pageup
- 34: 'pagedown', // pagedown
- 37: 'left', // left arrow
- 38: 'up', // up arrow
- 39: 'right', // right arrow
- 40: 'down', // down arrow
- 45: 'escape', // insert
- 81: 'pageup', // Q
- 87: 'pagedown', // W
- 88: 'escape', // X
- 90: 'ok', // Z
- 96: 'escape', // numpad 0
- 98: 'down', // numpad 2
- 100: 'left', // numpad 4
- 102: 'right', // numpad 6
- 104: 'up', // numpad 8
- 120: 'debug', // F9
- 121: 'f10' // F10
- };
- /**
- * @static
- * @method _signX
- * @private
- */
- Input._signX = function () {
- var x = 0;
- if (this.isPressed('left') && $dryPhysics.controlsEnabled) {
- x--;
- }
- if (this.isPressed('right') && $dryPhysics.controlsEnabled) {
- x++;
- }
- return x;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement