Heirukichi

Heirukichi_MogLMBS_gravityAddon-VXACE

Oct 12th, 2018
559
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 11.39 KB | None | 0 0
  1. #==============================================================================
  2. # HEIRUKICHI MOG'S LINEAR MOVEMENT BATTLE SYSTEM GRAVITY ADDON
  3. #==============================================================================
  4. # Version 1.0
  5. # - Last updated: 10-12-2018 [MM-DD-YYYY]
  6. # - Author: Heirukichi
  7. # - Required: Mog's Linear Movement Battle System (LMBS)
  8. #   You can download the required script here:
  9. #   https://atelierrgss.wordpress.com/rgss3-lmbs-linear-motion-battle-system/
  10. #==============================================================================
  11. # TERMS OF USE
  12. #------------------------------------------------------------------------------
  13. # This script was commissioned by JosephSeraph from RPGMaker community.
  14. #
  15. # You can use this script for both commercial and non commercial games as long
  16. # as proper credit is given to me (Heirukichi).
  17. # Keep in mind that this script is an addon to Mog's Linear Movement Battle
  18. # System. If you are using this you need that one and so you have to give
  19. # proper credits to the autor of the original script as well.
  20. #
  21. # Credits for the original script (required to run this one) go to Moghunter.
  22. # Here is a link to his website: https://atelierrgss.wordpress.com
  23. #
  24. # You can edit this script as much as you like as long as you do not pretend to
  25. # have written the whole script and you distribute it under the same license.
  26. #
  27. # Attribution-ShareAlike 4.0 International: https://creativecommons.org/licenses/by-sa/4.0/
  28. #
  29. # In addition to this I would like to be notified when this script is used in a
  30. # commercial game. I do not require you to give me a percentage of your income
  31. # when using this script but I would like to keep track of games where this
  32. # script is being used.
  33. # You can send me a private message on RPG Maker Forums @Heirukichi. While
  34. # doing this is not mandatory please do not forget about it. It helps a lot.
  35. # Of course feel free to notify me when you use it for non-commercial games as
  36. # well. It is highly appreciated.
  37. #==============================================================================
  38. # DESCRIPTION
  39. #------------------------------------------------------------------------------
  40. # This scirpt adds physics to Mog's Linear Movement Battle System. This means
  41. # your jumps, double jumps and falls will be affected by gravity.
  42. #==============================================================================
  43. # INSTRUCTIONS
  44. #------------------------------------------------------------------------------
  45. # This script is a plug and play script. There is only one parameter you can
  46. # configure and that is if physics is enabled or not. More details below.
  47. # Everything else must be configured in the original LMBS script.
  48. #
  49. # This script supports air friction for each character. You can configure
  50. # notetags as in the original script. Keep in mind that Jump Speed is your jump
  51. # initial speed and Jump Height tells you how high that character goes.
  52. # If two characters have the same Jump Height but different Jump Speed that
  53. # means the one with the lowest Jump Speed stays mid-air longer. In the same
  54. # way if two characters have the same Jump Speed but different Jump Height the
  55. # one with the highest Jump Height will stay mid-air longer.
  56. #==============================================================================
  57. # METHODS LIST
  58. #------------------------------------------------------------------------------
  59. # In this script I aliased few methods and also created new ones. The following
  60. # list shows which ones are aliased, new or overwritten.
  61. # + = New method.
  62. # * = Aliased method.
  63. # ! = Overwritten method.
  64. # The script works as long as you put it BELOW every other script containing
  65. # one or more of the aliased methods. In case it overwrites a method you have
  66. # to place it BELOW the script where that method is defined and ABOVE scripts
  67. # where that method is aliased. Also be sure to place it ABOVE any other script
  68. # that aliases or overwrites any of the new methods.
  69. #------------------------------------------------------------------------------
  70. # Game_Battler
  71. #   * initialize
  72. #   * set_f_basic_parameters
  73. #   * set_fmbs_initial_parameters
  74. #   * f_mov_jump
  75. #   * f_grv_speed
  76. #   * f_update_jump
  77. #   * f_update_gravity
  78. #   * f_update_double_jump
  79. #   * f_mov_double_jump
  80. #   * f_move_screen_y
  81. #   * f_mov_air_dash
  82. #   + initialize_gravity_variables
  83. #   + setup_gravity
  84. #   + hrk_f_grv_speed
  85. #   + double_jump_speed
  86. #   + increase_jump_frames
  87. #==============================================================================
  88.  
  89. module HLMBSF
  90.    
  91.     module Config
  92.    
  93.         #======================================================================
  94.         # Set the following to true if you want to use physics in your jumps,
  95.         # set it to false if you want linear jumps. Default is true.
  96.         #======================================================================
  97.    
  98.         PHYSICS = true
  99.    
  100.     end
  101.    
  102.     #==========================================================================
  103.     # !! WARNING !!
  104.     #--------------------------------------------------------------------------
  105.     # Configuration module ends here. Any change after this point might prevent
  106.     # the script from working properly. Please do not touch anything after this
  107.     # point unless you know exactly what you are doing.
  108.     #==========================================================================
  109.    
  110.     def self.physics_enabled?
  111.         return Config::PHYSICS
  112.     end
  113.    
  114. end
  115.  
  116. #==============================================================================
  117. # * Game Battler Class
  118. #==============================================================================
  119.  
  120. class Game_Battler < Game_BattlerBase
  121.  
  122.     attr_reader :jump_frames
  123.     attr_reader :gravity
  124.    
  125.     #--------------------------------------------------------------------------
  126.     # * Aliased Initialize
  127.     #--------------------------------------------------------------------------
  128.  
  129.     alias hrk_initialize_old  initialize
  130.     def initialize
  131.         hrk_initialize_old
  132.         initialize_gravity_variables
  133.     end
  134.    
  135.     #--------------------------------------------------------------------------
  136.     # * Aliased Set Basic Parameters
  137.     #--------------------------------------------------------------------------
  138.    
  139.     alias hrk_set_f_basic_parameters_old    set_f_basic_parameters
  140.     def set_f_basic_parameters
  141.         hrk_set_f_basic_parameters_old
  142.         return unless HLMBSF.physics_enabled?
  143.         setup_gravity
  144.     end
  145.    
  146.     #--------------------------------------------------------------------------
  147.     # * Aliased Set Initial Parameters
  148.     #--------------------------------------------------------------------------
  149.    
  150.     alias hrk_set_fmbs_initial_parameters_old set_fmbs_initial_parameters
  151.     def set_fmbs_initial_parameters(f_battler)
  152.         hrk_set_fmbs_initial_parameters_old(f_battler)
  153.         return unless HLMBSF.physics_enabled?
  154.         setup_gravity
  155.     end
  156.    
  157.     #--------------------------------------------------------------------------
  158.     # * Aliased Jump
  159.     #--------------------------------------------------------------------------    
  160.  
  161.     alias hrk_f_mov_jump_old    f_mov_jump
  162.     def f_mov_jump
  163.         hrk_f_mov_jump_old
  164.         return if !f_jump_conditions_met?
  165.         @jump_frames = 0
  166.     end
  167.    
  168.     #--------------------------------------------------------------------------
  169.     # * Aliased Grv Speed
  170.     #--------------------------------------------------------------------------
  171.    
  172.     alias hrk_f_grv_speed_old   f_grv_speed
  173.     def f_grv_speed
  174.         return hrk_f_grv_speed.abs if HLMBSF.physics_enabled?
  175.         return hrk_f_grv_speed_old
  176.     end
  177.  
  178.     #--------------------------------------------------------------------------
  179.     # * Aliased Update Jump
  180.     #--------------------------------------------------------------------------    
  181.    
  182.     alias hrk_f_update_jump_old f_update_jump
  183.     def f_update_jump
  184.         @sprite_data[6][2] = 1 if ((hrk_f_grv_speed >= 0) && (!f_mov_air_dash?))
  185.         hrk_f_update_jump_old
  186.         f_ground? ? (@jump_frames = 0) : (@jump_frames += 1)
  187.     end
  188.    
  189.     #--------------------------------------------------------------------------
  190.     # * Aliased Update Gravity
  191.     #--------------------------------------------------------------------------
  192.    
  193.     alias hrk_f_update_gravity_old  f_update_gravity
  194.     def f_update_gravity
  195.         hrk_f_update_gravity_old
  196.         return if f_update_flying?
  197.         return if !f_gravity_conditions_met?  
  198.         increase_jump_frames
  199.         @double_jump_speed = 0 if f_ground?
  200.     end
  201.    
  202.     #--------------------------------------------------------------------------
  203.     # * Aliased Update Double Jump
  204.     #--------------------------------------------------------------------------
  205.    
  206.     alias hrk_f_update_double_jump_old  f_update_double_jump
  207.     def f_update_double_jump
  208.         hrk_f_update_double_jump_old
  209.         increase_jump_frames
  210.     end
  211.    
  212.     #--------------------------------------------------------------------------
  213.     # * Aliased Mov Double Jump
  214.     #--------------------------------------------------------------------------
  215.    
  216.     alias hrk_f_mov_double_jump_old f_mov_double_jump
  217.     def f_mov_double_jump
  218.         return if !f_double_jump_conditions_met?
  219.         @jump_frames = 0
  220.         @double_jump_speed = double_jump_speed
  221.         hrk_f_mov_double_jump_old
  222.     end
  223.    
  224.     #--------------------------------------------------------------------------
  225.     # * Aliased Move Screen Y
  226.     #--------------------------------------------------------------------------
  227.    
  228.     alias hrk_f_move_screen_y_old f_move_screen_y
  229.     def f_move_screen_y(val)
  230.         hrk_f_move_screen_y_old(val)
  231.         return if !f_move_usable?
  232.         @screen_y = f_ground if @screen_y > f_ground
  233.     end
  234.  
  235.     #--------------------------------------------------------------------------
  236.     # * Aliased Mov Air Dash
  237.     #--------------------------------------------------------------------------
  238.    
  239.     alias hrk_f_mov_air_dash_old    f_mov_air_dash
  240.     def f_mov_air_dash
  241.         hrk_f_mov_air_dash_old
  242.         return if !f_air_dash_conditions_met?
  243.         @jump_frames = ((@double_jump_speed == 0 ? @jump_speed : double_jump_speed) / @gravity).to_i
  244.     end
  245.    
  246.    
  247.    
  248.    
  249.     #==========================================================================
  250.     # ** NEW METHODS
  251.     #==========================================================================
  252.    
  253.    
  254.    
  255.     #--------------------------------------------------------------------------
  256.     # + Initialize Gravity-related variables
  257.     #--------------------------------------------------------------------------
  258.  
  259.     def initialize_gravity_variables
  260.         @jump_frames = 0
  261.         @double_jump_speed = 0
  262.         @gravity = 0
  263.     end
  264.    
  265.     #--------------------------------------------------------------------------
  266.     # + Setup Gravity
  267.     #--------------------------------------------------------------------------
  268.    
  269.     def setup_gravity
  270.         @gravity = (@jump_speed * @jump_speed / (2 * @jump_height).to_f)
  271.     end
  272.  
  273.     #--------------------------------------------------------------------------
  274.     # + Gravity Speed (Physics Based)
  275.     #--------------------------------------------------------------------------
  276.    
  277.     def hrk_f_grv_speed
  278.         vd = (@gravity * @jump_frames)
  279.         vd += 1 if vd > vd.to_i
  280.         s = (@double_jump_speed == 0 ? @jump_speed : @double_jump_speed) - vd.to_i
  281.         return -s
  282.     end
  283.    
  284.     #--------------------------------------------------------------------------
  285.     # + Double Jump Speed
  286.     #--------------------------------------------------------------------------
  287.    
  288.     def double_jump_speed
  289.         return (@jump_speed - [(@jump_speed / 4), 1].max)
  290.     end
  291.    
  292.     #--------------------------------------------------------------------------
  293.     # + Increase Jump Frames
  294.     #--------------------------------------------------------------------------
  295.    
  296.     def increase_jump_frames
  297.         return if f_ground?
  298.         @jump_frames += 1
  299.     end
  300.    
  301. end
Advertisement
Add Comment
Please, Sign In to add comment