Advertisement
Drykul

Avilka Jump 1.1

Feb 8th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // AvilkaJump.js v1.1
  3. //=============================================================================
  4. /*:
  5.  * @plugindesc Allows the character to jump.
  6.  * <id:Avilka Jump>
  7.  * @author Drykul
  8.  *
  9.  * @param Disable Jumping
  10.  * @desc If this switch is set to true, jumping will not be enabled.
  11.  * @default 20
  12.  *
  13.  * @param Jump Key
  14.  * @desc The button to press for jumping.                            alt, control, up, shift, etc
  15.  * @default alt
  16.  *
  17.  * @param Jump Height                                                
  18.  * @desc The maximum height of jump in pixels                        Default: 240
  19.  * @default 240
  20.  *
  21.  * @param Regular Movement Speed
  22.  * @desc Normal movement speed for the player.                       Default: 4.5
  23.  * @default 4.5
  24.  *
  25.  * @param Jump Speed
  26.  * @desc How fast movement is while jumping.                         Default: 6.0
  27.  * @default 6.0
  28.  *
  29.  * @param Fall Speed
  30.  * @desc How fast movement is while falling.                         Default: 6.0
  31.  * @default 6.0
  32.  *
  33.  * @help
  34.  * ======== INSTALLING ========
  35.  * Enable plugin in the plugin manager. On the first map where player controls
  36.  * are active, have an event run the following code in a script command:
  37.  *
  38.  *    $dryPhysics.gravityEnabled = true
  39.  *    $dryPhysics.controlsEnabled = true
  40.  *
  41.  * If at any time you want to temporarily suspend jumping ability, just toggle
  42.  * the switch set in the plugin manager settings for this plugin. If you want
  43.  * to disable controls, just run a script command as follows:
  44.  *
  45.  *    $dryPhysics.controlsEnabled = false
  46.  *
  47.  * !!!!!!!!!!!!!!!!!!!!!!!!!!!!! IMPORTANT !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  48.  *
  49.  * Setting jump speed or fall speed anything higher than 6.0 causes problems
  50.  * with collision detection.
  51.  *
  52.  *!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  53.  *
  54.  * If you have any bugs to report, requests, or questions you can contact me
  55.  * at drykul(at)cloud9studios.net. I'm also on www.rpgmakerweb.com and
  56.  * www.rpgmakervxace.net as shaynec1981 as well as www.rpgmakermv.co as drykul.
  57.  *
  58.  * No credit is necessary for use of this script in either free
  59.  * or commercial projects. Just shoot me a line and let me know if it was
  60.  * worth your time! :)
  61.  *
  62.  * // CHANGELOG //
  63.  * 2-8-17 - Version 1.0 complete
  64.  * 2-8-17 - Version 1.1
  65.  *  ## Changed
  66.  *  - Fixed bug with jump height causing player to skyrocket.
  67.  *  - Fixed bug where the player could still jump if a game message was being
  68.  *      displayed.
  69.  *  - Disabled sprite frame from changing while jumping.
  70.  */
  71. // Set up plugin parameters
  72. var scriptParameters = $plugins.filter(function (p) {
  73.         return p.description.contains("<id:Avilka Jump>")
  74.     })[0].parameters
  75.     // Set up global namespace
  76. var $dryPhysics = {
  77.     controlsEnabled: false
  78.     , gravityEnabled: false
  79.     , isFalling: false
  80.     , isJumping: false
  81.     , jumpEnd: 0
  82.     , disableSwitch: scriptParameters['Disable Jumping']
  83.     , jumpKey: scriptParameters['Jump Key']
  84.     , jumpHeight: parseFloat(scriptParameters['Jump Height'])
  85.     , moveSpeed: parseFloat(scriptParameters['Regular Movement Speed'])
  86.     , jumpSpeed: parseFloat(scriptParameters['Jump Speed'])
  87.     , fallSpeed: parseFloat(scriptParameters['Fall Speed'])
  88. };
  89. var aliasSceneMapUpdate = Scene_Map.prototype.update;
  90. Scene_Map.prototype.update = function () {
  91.     aliasSceneMapUpdate.call(this);
  92.     if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
  93.         $gamePlayer._moveSpeed = $dryPhysics.moveSpeed;
  94.     }
  95.     if ($dryPhysics.isJumping) {
  96.         if ($gamePlayer.canPass($gamePlayer._realX, $gamePlayer._realY, 8) == false) {
  97.             $dryPhysics.isJumping = false;
  98.             $dryPhysics.isFalling = true;
  99.         }
  100.         else {
  101.             $gamePlayer._moveSpeed = $dryPhysics.jumpSpeed;
  102.             $gamePlayer._py -= ($dryPhysics.jumpSpeed + 2);
  103.             jumpEndCheck();
  104.         }
  105.     }
  106.     if ($dryPhysics.gravityEnabled == true) {
  107.         gravityCheck();
  108.     }
  109.     if ($dryPhysics.controlsEnabled == true) {
  110.         keyCheck();
  111.     }
  112. };
  113.  
  114. function jumpEndCheck() {
  115.     if ($gamePlayer._py <= $dryPhysics.jumpEnd) {
  116.         $dryPhysics.isJumping = false;
  117.         $dryPhysics.isFalling = true;
  118.     }
  119. };
  120.  
  121. function gravityCheck() {
  122.     if ($dryPhysics.isJumping == false && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 2)) {
  123.         $dryPhysics.isFalling = true;
  124.         $gamePlayer._moveSpeed = $dryPhysics.fallSpeed;
  125.         $gamePlayer._py += ($dryPhysics.fallSpeed + 2);
  126.     }
  127.     else {
  128.         $dryPhysics.isFalling = false;
  129.     }
  130. };
  131.  
  132. function keyCheck() {
  133.     if ($gameSwitches.value($dryPhysics.disableSwitch) === false && $gameMessage.isBusy() === false) {
  134.         if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
  135.             $gamePlayer._directionFix = false;
  136.             if ($gamePlayer._direction == 2) {
  137.                 $gamePlayer._direction = 6;
  138.             }
  139.             if ($gamePlayer._direction == 8) {
  140.                 $gamePlayer._direction = 4;
  141.             }
  142.             if (Input.isTriggered($dryPhysics.jumpKey)) {
  143.                 if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 8)) {
  144.                     $dryPhysics.isJumping = true;
  145.                     $dryPhysics.jumpEnd = clone($gamePlayer._py);
  146.                     $dryPhysics.jumpEnd -= $dryPhysics.jumpHeight;
  147.                     $gamePlayer._directionFix = true;
  148.                     //                    if ($gamePlayer._direction == 6) {        //
  149.                     //                        $gamePlayer._direction = 2;           //      
  150.                     //                    }                                         // USED FOR CUSTOM JUMP FRAMES
  151.                     //                    else if ($gamePlayer._direction == 4) {   //
  152.                     //                        $gamePlayer._direction = 8;           //
  153.                     //                    }                                         //
  154.                 }
  155.             }
  156.         }
  157.     }
  158.     if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('left') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 4)) {
  159.         //        $gamePlayer._direction = 8;                           // USED FOR CUSTOM JUMP FRAMES
  160.         $gamePlayer._px -= 4;
  161.     }
  162.     if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('right') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 6)) {
  163.         //        $gamePlayer._direction = 2;                           // USED FOR CUSTOM JUMP FRAMES
  164.         $gamePlayer._px += 4;
  165.     }
  166. }
  167.  
  168. function clone(obj) {
  169.     // Handle the 3 simple types, and null or undefined
  170.     if (null == obj || "object" != typeof obj) return obj;
  171.     // Handle Date
  172.     if (obj instanceof Date) {
  173.         var copy = new Date();
  174.         copy.setTime(obj.getTime());
  175.         return copy;
  176.     }
  177.     // Handle Array
  178.     if (obj instanceof Array) {
  179.         var copy = [];
  180.         for (var i = 0, len = obj.length; i < len; i++) {
  181.             copy[i] = clone(obj[i]);
  182.         }
  183.         return copy;
  184.     }
  185.     // Handle Object
  186.     if (obj instanceof Object) {
  187.         var copy = {};
  188.         for (var attr in obj) {
  189.             if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
  190.         }
  191.         return copy;
  192.     }
  193.     throw new Error("Unable to copy obj! Its type isn't supported.");
  194. };
  195. Input.keyMapper = {
  196.     9: 'tab', // tab
  197.     13: 'ok', // enter
  198.     16: 'shift', // shift
  199.     17: 'control', // control
  200.     18: 'alt', // alt
  201.     27: 'escape', // escape
  202.     32: 'ok', // space
  203.     33: 'pageup', // pageup
  204.     34: 'pagedown', // pagedown
  205.     37: 'left', // left arrow
  206.     38: 'up', // up arrow
  207.     39: 'right', // right arrow
  208.     40: 'down', // down arrow
  209.     45: 'escape', // insert
  210.     81: 'pageup', // Q
  211.     87: 'pagedown', // W
  212.     88: 'escape', // X
  213.     90: 'ok', // Z
  214.     96: 'escape', // numpad 0
  215.     98: 'down', // numpad 2
  216.     100: 'left', // numpad 4
  217.     102: 'right', // numpad 6
  218.     104: 'up', // numpad 8
  219.     120: 'debug', // F9
  220.     121: 'f10' // F10
  221. };
  222. /**
  223.  * @static
  224.  * @method _signX
  225.  * @private
  226.  */
  227. Input._signX = function () {
  228.     var x = 0;
  229.     if (this.isPressed('left') && $dryPhysics.controlsEnabled) {
  230.         x--;
  231.     }
  232.     if (this.isPressed('right') && $dryPhysics.controlsEnabled) {
  233.         x++;
  234.     }
  235.     return x;
  236. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement