Advertisement
GuilhermeSantos_4T

Jump System

Jan 5th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // Jump System
  3. // By GuilhermeSantos
  4. // GS_JumpSystem.js
  5. // Version: 2.0.1
  6. // Date: 05/01/2017
  7. // Update: 06/01/2017
  8. // ===========================================================================
  9. //  Terms of use
  10. // ===========================================================================
  11. // Put the GS in the credits of your project.
  12. // Free for commercial and non commercial use.
  13. // ===========================================================================
  14. //  Termos de uso
  15. // ===========================================================================
  16. // Coloque o GS nos créditos do seu projeto.
  17. // Livre para uso comercial e não comercial.
  18. //============================================================================
  19. /*:
  20. * @author GuilhermeSantos
  21. * @plugindesc Jump system (GS)
  22. *
  23. * @param ---Regions---
  24. * @default
  25. *
  26. * @param Region ID
  27. * @desc Choose jump region verification id
  28. * Pattern: 1, 2
  29. * @default 1, 2
  30. *
  31. * @param Region Position
  32. * @desc Choose the jump positions of the regions
  33. * Following the order of the list of id of the regions.
  34. * @default up-down, up-down
  35. *
  36. * @param ---Jumps---
  37. * @default
  38. *
  39. * @param Jump Down
  40. * @desc Set the jump down (x, y)
  41. * Following the order of the list of id of the regions.
  42. * @default 0 - 1, 0 - 3
  43. *
  44. * @param Jump Up
  45. * @desc Set the jump up (x, y)
  46. * Following the order of the list of id of the regions.
  47. * @default 0 - 1, 0 - 3
  48. *
  49. * @param Jump Left
  50. * @desc Set the jump left (x, y)
  51. * Following the order of the list of id of the regions.
  52. * @default 0 - 0, 6 - 2
  53. *
  54. * @param Jump Right
  55. * @desc Set the jump right (x, y)
  56. * Following the order of the list of id of the regions.
  57. * @default 0 - 2, 0 - 5
  58. *
  59. * @param ---Values---
  60. * @default
  61. *
  62. * @param Value Down
  63. * @desc Set the value type.
  64. * Following the order of the Jumps id list.
  65. * @default positive-positive, positive-positive
  66. *
  67. * @param Value Up
  68. * @desc Set the value type.
  69. * Following the order of the Jumps id list.
  70. * @default negative-negative, negative-negative
  71. *
  72. * @param Value Left
  73. * @desc Set the value type.
  74. * Following the order of the Jumps id list.
  75. * @default positive-positive, negative-negative
  76. *
  77. * @param Value Right
  78. * @desc Set the value type.
  79. * Following the order of the Jumps id list.
  80. * @default positive-positive, negative-negative
  81. *
  82. * @param ---Frames---
  83. * @default
  84. *
  85. * @param Frames Down
  86. * @desc Set the verification time down.
  87. * YES: Value | NO: False.
  88. * @default false
  89. *
  90. * @param Frames Up
  91. * @desc Set the verification time up.
  92. * YES: Value | NO: False.
  93. * @default false
  94. *
  95. * @param Frames Left
  96. * @desc Set the verification time left.
  97. * YES: Value | NO: False.
  98. * @default false
  99. *
  100. * @param Frames Right
  101. * @desc Set the verification time right.
  102. * YES: Value | NO: False.
  103. * @default false
  104. *
  105. * @help
  106. * ===========================================================================
  107. * Introduction:
  108. * Use this plugin to perform the jumps in your game, For a while using only
  109. * the game regions for the system.
  110. * ===========================================================================
  111. * Contact:
  112. *     website http://lzogames.esy.es/
  113. * ===========================================================================
  114. * Regions ID: 1, 2, 3... Always placing the (,) When to change lines
  115. * Regions Position: 1 - 2, 3 - 6, 6 - 8... Always placing the (-) to change
  116. * axis (x, y), Always placing the (,) When to change lines
  117. * Jump Position: up, down, left e right
  118. * Jump Values: positive e negative
  119. * Frames: Use a value to leave active or false to leave disabled
  120. * ===========================================================================
  121. * Script:
  122. * * $gamePlayer.verific_Region(); - Leap region verification.
  123. * * $gamePlayer.verific_position(paramId); - Leap position check.
  124. *
  125. * Script Details:
  126. * * paramId: Region list ID, The count starts at 0
  127. * ===========================================================================
  128. * Update:
  129. * * Thanks for liking and using this plugin. I hope you have a lot of help
  130. * using this plugin ;)
  131. *
  132. * ===========================================================================
  133. */
  134. /*:pt
  135. * @author GuilhermeSantos
  136. * @plugindesc Sistema de salto (GS)
  137. *
  138. * @param ---Regions---
  139. * @default
  140. *
  141. * @param Region ID
  142. * @desc Escolha o id da região de verificação do salto
  143. * Padrão: 1, 2
  144. * @default 1, 2
  145. *
  146. * @param Region Position
  147. * @desc Escolha as posições de pulo das regiões
  148. * Seguindo a ordem da lista de id das regiões.
  149. * @default up-down, up-down
  150. *
  151. * @param ---Jumps---
  152. * @default
  153. *
  154. * @param Jump Down
  155. * @desc Defina o pulo para baixo (x, y)
  156. * Seguindo a ordem da lista de id das regiões.
  157. * @default 0 - 1, 0 - 3
  158. *
  159. * @param Jump Up
  160. * @desc Defina o pulo para cima (x, y)
  161. * Seguindo a ordem da lista de id das regiões.
  162. * @default 0 - 1, 0 - 3
  163. *
  164. * @param Jump Left
  165. * @desc Defina o pulo para esquerda (x, y)
  166. * Seguindo a ordem da lista de id das regiões.
  167. * @default 0 - 0, 6 - 2
  168. *
  169. * @param Jump Right
  170. * @desc Defina o pulo para direita (x, y)
  171. * Seguindo a ordem da lista de id das regiões.
  172. * @default 0 - 2, 0 - 5
  173. *
  174. * @param ---Values---
  175. * @default
  176. *
  177. * @param Value Down
  178. * @desc Defina o tipo de valor.
  179. * Seguindo a ordem da lista de id dos Jumps.
  180. * @default positive-positive, positive-positive
  181. *
  182. * @param Value Up
  183. * @desc Defina o tipo de valor.
  184. * Seguindo a ordem da lista de id dos Jumps.
  185. * @default negative-negative, negative-negative
  186. *
  187. * @param Value Left
  188. * @desc Defina o tipo de valor.
  189. * Seguindo a ordem da lista de id dos Jumps.
  190. * @default positive-positive, negative-negative
  191. *
  192. * @param Value Right
  193. * @desc Defina o tipo de valor.
  194. * Seguindo a ordem da lista de id dos Jumps.
  195. * @default positive-positive, negative-negative
  196. *
  197. * @param ---Frames---
  198. * @default
  199. *
  200. * @param Frames Down
  201. * @desc Defina o tempo de verificação para baixo.
  202. * SIM: Value | NÂO: False.
  203. * @default false
  204. *
  205. * @param Frames Up
  206. * @desc Defina o tempo de verificação para baixo.
  207. * SIM: Value | NÂO: False.
  208. * @default false
  209. *
  210. * @param Frames Left
  211. * @desc Defina o tempo de verificação para baixo.
  212. * SIM: Value | NÂO: False.
  213. * @default false
  214. *
  215. * @param Frames Right
  216. * @desc Defina o tempo de verificação para baixo.
  217. * SIM: Value | NÂO: False.
  218. * @default false
  219. *
  220. * @help
  221. * ===========================================================================
  222. * Introduction:
  223. * Utilize esse plugin para executar os saltos em seu jogo, por enquanto estou
  224. * utilizando apenas as regiões como gatilho para o sitema.
  225. * ===========================================================================
  226. * Contact:
  227. *     website http://lzogames.esy.es/
  228. * ===========================================================================
  229. * Regions ID: 1, 2, 3... sempre colocando a (,) quando for trocar de linha
  230. * Regions Position: 1 - 2, 3 - 6, 6 - 8... sempre colocando o (-) para trocar
  231. * de eixo (x, y) e a (,) quando for trocar de linha
  232. * Jump Position: up, down, left e right
  233. * Jump Values: positive e negative
  234. * Frames: Utilize um valor para deixar ativo ou false para deixar desativado
  235. * ===========================================================================
  236. * Script:
  237. * * $gamePlayer.verific_Region(); - Verificação de região de pulo.
  238. * * $gamePlayer.verific_position(paramId); - Verificação de posição de pulo.
  239. *
  240. * Script Details:
  241. * * paramId: ID da lista de regiões, a contagem inicia em 0
  242. * ===========================================================================
  243. * Update:
  244. * * Obrigado por gostar e usar esse plugin. Espero que tenha uma enorme ajuda
  245. * utilizando esse sistema de pulo ;)
  246. *
  247. * ===========================================================================
  248. */
  249. (function() {
  250.     "use strict";
  251. var GS = GS || {};  
  252. GS.Core = GS.Core || {};
  253. //=============================================================================
  254. // CORE UTILS
  255. //=============================================================================
  256. GS.Core.metods = {
  257.     replaceParamsPattern: function (param, type) {
  258.         for (var item = 0, string = param, value = 0; item < string.length; item++) {
  259.             if(typeof param === 'string')param = [];
  260.             if(string[item] === ",")value++;
  261.             if(string[item] != " " && string[item] != ",")
  262.             {
  263.                 if(type == 0){
  264.                     param[value] = parseInt(string[item]);
  265.                 }
  266.                 else if(type == 1){
  267.                     param[value] = String(string[item]);
  268.                 }
  269.                 else{
  270.                     param[value] = string[item];
  271.                 };
  272.             };
  273.         };return param;
  274.     },
  275.     replaceParamsToArray: function (param, type) {
  276.         for (var item = 0, string = param, value = 0, str = [""], strValue = 0, maxValue = string.length - 1;
  277.         item < string.length; item++) {
  278.             if(string[item] === "-")strValue++;
  279.             if(string[item] != " " && string[item] != "," && string[item] != "-")
  280.             {
  281.                 if(str[strValue] === undefined)str[strValue] = "";
  282.                 str[strValue] += string[item];
  283.             };
  284.             if(string[item] === "," || maxValue === item){
  285.                 if(typeof param === "string")param = [];
  286.                 param[value] = [];
  287.                 for (var sts in str) {
  288.                     if(type == 0){
  289.                         param[value].push(parseInt(str[sts]));
  290.                     }
  291.                     else if(type == 1){
  292.                         param[value].push(String(str[sts]));
  293.                     }
  294.                     else {
  295.                         param[value].push(str[sts]);
  296.                     };
  297.                 };
  298.                 str = [""];
  299.                 strValue = 0;
  300.                 value++;
  301.             };            
  302.         };return param;
  303.     },
  304.     replaceParamsToNumber: function (param){
  305.         if(!isNaN(parseFloat(param)) && isFinite(param)){
  306.             return parseInt(param);
  307.         }else{return param};
  308.     }
  309. };
  310. //=============================================================================
  311. // Parameter Variables
  312. //=============================================================================
  313. GS.Parameters = PluginManager.parameters('GS_JumpSystem');
  314. GS.Parameters.regionId = String(GS.Parameters['Region ID']);
  315. GS.Parameters.regionPosition = String(GS.Parameters['Region Position']);
  316. GS.Parameters.jumpDown = String(GS.Parameters['Jump Down']);
  317. GS.Parameters.jumpUp = String(GS.Parameters['Jump Up']);
  318. GS.Parameters.jumpLeft = String(GS.Parameters['Jump Left']);
  319. GS.Parameters.jumpRight = String(GS.Parameters['Jump Right']);
  320. GS.Parameters.valueDown = String(GS.Parameters['Value Down']);
  321. GS.Parameters.valueUp = String(GS.Parameters['Value Up']);
  322. GS.Parameters.valueLeft = String(GS.Parameters['Value Left']);
  323. GS.Parameters.valueRight = String(GS.Parameters['Value Right']);
  324. GS.Parameters.framesDown = eval(String(GS.Parameters['Frames Down']));
  325. GS.Parameters.framesUp = eval(String(GS.Parameters['Frames Up']));
  326. GS.Parameters.framesLeft = eval(String(GS.Parameters['Frames Left']));
  327. GS.Parameters.framesRight = eval(String(GS.Parameters['Frames Right']));
  328. GS.Parameters.regionId = GS.Core.metods.replaceParamsPattern(GS.Parameters.regionId, 0);
  329. GS.Parameters.regionPosition = GS.Core.metods.replaceParamsToArray(GS.Parameters.regionPosition, 1);
  330. GS.Parameters.jumpDown = GS.Core.metods.replaceParamsToArray(GS.Parameters.jumpDown, 0);
  331. GS.Parameters.jumpUp = GS.Core.metods.replaceParamsToArray(GS.Parameters.jumpUp, 0);
  332. GS.Parameters.jumpLeft = GS.Core.metods.replaceParamsToArray(GS.Parameters.jumpLeft, 0);
  333. GS.Parameters.jumpRight = GS.Core.metods.replaceParamsToArray(GS.Parameters.jumpRight, 0);
  334. GS.Parameters.valueDown = GS.Core.metods.replaceParamsToArray(GS.Parameters.valueDown, 1);
  335. GS.Parameters.valueUp = GS.Core.metods.replaceParamsToArray(GS.Parameters.valueUp, 1);
  336. GS.Parameters.valueLeft = GS.Core.metods.replaceParamsToArray(GS.Parameters.valueLeft, 1);
  337. GS.Parameters.valueRight = GS.Core.metods.replaceParamsToArray(GS.Parameters.valueRight, 1);
  338. GS.Parameters.framesDown = GS.Core.metods.replaceParamsToNumber(GS.Parameters.framesDown);
  339. GS.Parameters.framesUp = GS.Core.metods.replaceParamsToNumber(GS.Parameters.framesUp);
  340. GS.Parameters.framesLeft = GS.Core.metods.replaceParamsToNumber(GS.Parameters.framesLeft);
  341. GS.Parameters.framesRight = GS.Core.metods.replaceParamsToNumber(GS.Parameters.framesRight);
  342. //=============================================================================
  343. // Game_Player
  344. //=============================================================================
  345. var Game_Player_initialize = Game_Player.prototype.initialize;
  346. Game_Player.prototype.initialize = function() {
  347.     Game_Player_initialize.call(this);
  348.     this.clearJumpFrames();
  349. };
  350.  
  351. Game_Player.prototype.clearJumpFrames = function() {
  352.     this._framesJumpDown = 0;
  353.     this._framesJumpUp = 0;
  354.     this._framesJumpLeft = 0;
  355.     this._framesJumpRight = 0;    
  356. };
  357.  
  358. Game_Player.prototype.updateNonmoving = function(wasMoving) {
  359.     if (!$gameMap.isEventRunning()) {
  360.         if (wasMoving) {
  361.             $gameParty.onPlayerWalk();
  362.             this.checkEventTriggerHere([1,2]);
  363.             if ($gameMap.setupStartingEvent()) {
  364.                 return;
  365.             }
  366.         }
  367.         if (this.triggerAction()) {
  368.             return;
  369.         }
  370.         if (wasMoving) {
  371.             this.updateEncounterCount();
  372.         } else {
  373.             $gameTemp.clearDestination();
  374.         }
  375.         if(!wasMoving){ // if Not is moving
  376.             switch($gamePlayer._direction){
  377.                 case 2:
  378.                     if(typeof GS.Parameters.framesDown != 'number')break;
  379.                     this._framesJumpDown++;
  380.                     if(this._framesJumpDown > GS.Parameters.framesDown){
  381.                         this._framesJumpDown = 0;
  382.                         this.verific_Region();
  383.                     };
  384.                     break;
  385.                 case 8:
  386.                 if(typeof GS.Parameters.framesUp != 'number')break;
  387.                     this._framesJumpUp++;
  388.                     if(this._framesJumpUp > GS.Parameters.framesUp){
  389.                         this._framesJumpUp = 0;
  390.                         this.verific_Region();
  391.                     };
  392.                     break;
  393.                 case 4:
  394.                 if(typeof GS.Parameters.framesLeft != 'number')break;
  395.                     this._framesJumpLeft++;
  396.                     if(this._framesJumpLeft > GS.Parameters.framesLeft){
  397.                         this._framesJumpLeft = 0;
  398.                         this.verific_Region();
  399.                     };
  400.                     break;
  401.                 case 6:
  402.                 if(typeof GS.Parameters.framesRight != 'number')break;
  403.                     this._framesJumpRight++;
  404.                     if(this._framesJumpRight > GS.Parameters.framesRight){
  405.                         this._framesJumpRight = 0;
  406.                         this.verific_Region();
  407.                     };
  408.                     break;                                                
  409.             };
  410.         }else{this.clearJumpFrames()};        
  411.     }
  412. };
  413.  
  414. var Game_Player_updateMove = Game_Player.prototype.updateMove;
  415. Game_Player.prototype.updateMove = function() {
  416.     Game_Player_updateMove.call(this);
  417.     this.verific_Region();
  418. };
  419.  
  420. Game_Player.prototype.verific_Region = function() {
  421.     for (var item = 0, array = GS.Parameters.regionId; item < array.length; item++) {
  422.             if($gameMap.regionId($gamePlayer._x, $gamePlayer._y) === array[item]){
  423.                 this.verific_position(item);break;
  424.             };
  425.     };
  426. };
  427.  
  428. Game_Player.prototype.verific_position = function(paramId) {
  429.     switch ($gamePlayer._direction) {
  430.         case 2:
  431.             for (var item = 0, string = GS.Parameters.regionPosition[paramId]; item < string.length; item++) {
  432.                 if(string[item].toUpperCase() === "DOWN"){
  433.                     this.exe_jump(GS.Parameters.jumpDown, paramId, GS.Parameters.valueDown);break;
  434.                 };
  435.             };
  436.             break;
  437.         case 8:
  438.             for (var item = 0, string = GS.Parameters.regionPosition[paramId]; item < string.length; item++) {
  439.                 if(string[item].toUpperCase() === "UP"){
  440.                     this.exe_jump(GS.Parameters.jumpUp, paramId, GS.Parameters.valueUp);break;
  441.                 };
  442.             };
  443.             break;
  444.         case 4:
  445.             for (var item = 0, string = GS.Parameters.regionPosition[paramId]; item < string.length; item++) {
  446.                 if(string[item].toUpperCase() === "LEFT"){
  447.                     this.exe_jump(GS.Parameters.jumpLeft, paramId, GS.Parameters.valueLeft);break;
  448.                 };
  449.             };
  450.             break;
  451.         case 6:
  452.             for (var item = 0, string = GS.Parameters.regionPosition[paramId]; item < string.length; item++) {
  453.                 if(string[item].toUpperCase() === "RIGHT"){
  454.                     this.exe_jump(GS.Parameters.jumpRight, paramId, GS.Parameters.valueRight);break;
  455.                 };
  456.             };
  457.             break;                        
  458.     };
  459. };
  460.  
  461. Game_Player.prototype.exe_jump = function(param, paramId, paramValue) {
  462.     var x = $gamePlayer._x, y = $gamePlayer._y;
  463.     x += param[paramId][0], y += param[paramId][1];
  464.     var p = [2, 8, 4, 6] // Directions (MV)
  465.     for (var item in p) {
  466.         if($gameMap.isPassable(x, y, p[item])){
  467.             x = param[paramId][0], y = param[paramId][1];
  468.             var value1 = paramValue[paramId][0].toUpperCase(),
  469.             value2 = paramValue[paramId][1].toUpperCase();
  470.             if(value1 === "POSITIVE" && value2 === "POSITIVE"){
  471.                 $gamePlayer.jump(x, y);break;
  472.             }else if(value1 === "NEGATIVE" && value2 === "NEGATIVE"){
  473.                 $gamePlayer.jump(-x, -y);break;
  474.             }else if(value1 === "POSITIVE" && value2 === "NEGATIVE"){
  475.                 $gamePlayer.jump(x, -y);break;
  476.             }else if(value1 === "NEGATIVE" && value2 === "POSITIVE"){
  477.                 $gamePlayer.jump(-x, y);break;
  478.             }else{break;};
  479.         };
  480.     };
  481. };
  482. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement