Advertisement
Drykul

Avilka Jump Plugin

Feb 8th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // AvilkaJump.js v1.0
  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.  */
  65. // Set up plugin parameters
  66. var scriptParameters = $plugins.filter(function (p) {
  67.         return p.description.contains("<id:Avilka Jump>")
  68.     })[0].parameters
  69.     // Set up global namespace
  70. var $dryPhysics = {
  71.     controlsEnabled: false
  72.     , gravityEnabled: false
  73.     , isFalling: false
  74.     , isJumping: false
  75.     , jumpEnd: 0
  76.     , disableSwitch: scriptParameters['Disable Jumping']
  77.     , jumpKey: scriptParameters['Jump Key']
  78.     , jumpHeight: parseFloat(scriptParameters['Jump Height'])
  79.     , moveSpeed: parseFloat(scriptParameters['Regular Movement Speed'])
  80.     , jumpSpeed: parseFloat(scriptParameters['Jump Speed'])
  81.     , fallSpeed: parseFloat(scriptParameters['Fall Speed'])
  82. };
  83. var aliasSceneMapUpdate = Scene_Map.prototype.update;
  84. Scene_Map.prototype.update = function () {
  85.     aliasSceneMapUpdate.call(this);
  86.     if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
  87.         $gamePlayer._moveSpeed = $dryPhysics.moveSpeed;
  88.     }
  89.     if ($dryPhysics.isJumping) {
  90.         if ($gamePlayer.canPass($gamePlayer._realX, $gamePlayer._realY, 8) == false) {
  91.             $dryPhysics.isJumping = false;
  92.             $dryPhysics.isFalling = true;
  93.         }
  94.         else {
  95.             $gamePlayer._moveSpeed = $dryPhysics.jumpSpeed;
  96.             $gamePlayer._py -= ($dryPhysics.jumpSpeed + 2);
  97.             jumpEndCheck();
  98.         }
  99.     }
  100.     if ($dryPhysics.gravityEnabled == true) {
  101.         gravityCheck();
  102.     }
  103.     if ($dryPhysics.controlsEnabled == true) {
  104.         keyCheck();
  105.     }
  106. };
  107.  
  108. function jumpEndCheck() {
  109.     if ($gamePlayer._py == $dryPhysics.jumpEnd) {
  110.         $dryPhysics.isJumping = false;
  111.         $dryPhysics.isFalling = true;
  112.     }
  113. };
  114.  
  115. function gravityCheck() {
  116.     if ($dryPhysics.isJumping == false && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 2)) {
  117.         $dryPhysics.isFalling = true;
  118.         $gamePlayer._moveSpeed = $dryPhysics.fallSpeed;
  119.         $gamePlayer._py += ($dryPhysics.fallSpeed + 2);
  120.     }
  121.     else {
  122.         $dryPhysics.isFalling = false;
  123.     }
  124. };
  125.  
  126. function keyCheck() {
  127.     if ($gameSwitches.value($dryPhysics.disableSwitch) === false) {
  128.         if ($dryPhysics.isJumping == false && $dryPhysics.isFalling == false) {
  129.             $gamePlayer._directionFix = false;
  130.             if ($gamePlayer._direction == 2) {
  131.                 $gamePlayer._direction = 6;
  132.             }
  133.             if ($gamePlayer._direction == 8) {
  134.                 $gamePlayer._direction = 4;
  135.             }
  136.             if (Input.isTriggered($dryPhysics.jumpKey)) {
  137.                 if ($gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 8)) {
  138.                     $dryPhysics.isJumping = true;
  139.                     $dryPhysics.jumpEnd = clone($gamePlayer._py);
  140.                     $dryPhysics.jumpEnd -= $dryPhysics.jumpHeight;
  141.                     $gamePlayer._directionFix = true;
  142.                     if ($gamePlayer._direction == 6) {
  143.                         $gamePlayer._direction = 2;
  144.                     }
  145.                     else if ($gamePlayer._direction == 4) {
  146.                         $gamePlayer._direction = 8;
  147.                     }
  148.                 }
  149.             }
  150.         }
  151.     }
  152.     if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('left') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 4)) {
  153.         $gamePlayer._direction = 8;
  154.         $gamePlayer._px -= 4;
  155.     }
  156.     if (($dryPhysics.isJumping || $dryPhysics.isFalling) && Input.isPressed('right') && $gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, 6)) {
  157.         $gamePlayer._direction = 2;
  158.         $gamePlayer._px += 4;
  159.     }
  160. }
  161.  
  162. function clone(obj) {
  163.     // Handle the 3 simple types, and null or undefined
  164.     if (null == obj || "object" != typeof obj) return obj;
  165.     // Handle Date
  166.     if (obj instanceof Date) {
  167.         var copy = new Date();
  168.         copy.setTime(obj.getTime());
  169.         return copy;
  170.     }
  171.     // Handle Array
  172.     if (obj instanceof Array) {
  173.         var copy = [];
  174.         for (var i = 0, len = obj.length; i < len; i++) {
  175.             copy[i] = clone(obj[i]);
  176.         }
  177.         return copy;
  178.     }
  179.     // Handle Object
  180.     if (obj instanceof Object) {
  181.         var copy = {};
  182.         for (var attr in obj) {
  183.             if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
  184.         }
  185.         return copy;
  186.     }
  187.     throw new Error("Unable to copy obj! Its type isn't supported.");
  188. };
  189. Input.keyMapper = {
  190.     9: 'tab', // tab
  191.     13: 'ok', // enter
  192.     16: 'shift', // shift
  193.     17: 'control', // control
  194.     18: 'alt', // alt
  195.     27: 'escape', // escape
  196.     32: 'ok', // space
  197.     33: 'pageup', // pageup
  198.     34: 'pagedown', // pagedown
  199.     37: 'left', // left arrow
  200.     38: 'up', // up arrow
  201.     39: 'right', // right arrow
  202.     40: 'down', // down arrow
  203.     45: 'escape', // insert
  204.     81: 'pageup', // Q
  205.     87: 'pagedown', // W
  206.     88: 'escape', // X
  207.     90: 'ok', // Z
  208.     96: 'escape', // numpad 0
  209.     98: 'down', // numpad 2
  210.     100: 'left', // numpad 4
  211.     102: 'right', // numpad 6
  212.     104: 'up', // numpad 8
  213.     120: 'debug', // F9
  214.     121: 'f10' // F10
  215. };
  216. /**
  217.  * @static
  218.  * @method _signX
  219.  * @private
  220.  */
  221. Input._signX = function () {
  222.     var x = 0;
  223.     if (this.isPressed('left') && $dryPhysics.controlsEnabled) {
  224.         x--;
  225.     }
  226.     if (this.isPressed('right') && $dryPhysics.controlsEnabled) {
  227.         x++;
  228.     }
  229.     return x;
  230. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement