khanhdu

<< Speed Trail >>

Jan 25th, 2018
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 46.02 KB | None | 0 0
  1. %Q(
  2. ╔════╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═════╗
  3. ║ ╔══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╩═══╗ ║
  4. ╠─╣                               Speed Trail                                ╠─╣
  5. ╠─╣                           by RPG Maker Source.                           ╠─╣
  6. ╠─╣                          www.rpgmakersource.com                          ╠─╣
  7. ║ ╚══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╦═══╝ ║
  8. ╠════╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═╤═╩═════╣
  9. ║ ┌────┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴───┴─────┐ ║
  10. ╠─┤ Version 1.0.3                   02/12/14                        DD/MM/YY ├─╣
  11. ║ └────┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬───┬─────┘ ║
  12. ╠══════╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══╧═══════╣
  13. ║                                                                              ║
  14. ║               This work is protected by the following license:               ║
  15. ║     ╔══════════════════════════════════════════════════════════════════╗     ║
  16. ║     │                                                                  │     ║
  17. ║     │ Copyright © 2014 Maker Systems.                                  │     ║
  18. ║     │                                                                  │     ║
  19. ║     │ This software is provided 'as-is', without any kind of           │     ║
  20. ║     │ warranty. Under no circumstances will the author be held         │     ║
  21. ║     │ liable for any damages arising from the use of this software.    │     ║
  22. ║     │                                                                  │     ║
  23. ║     │ Permission is granted to anyone to use this software on their    │     ║
  24. ║     │ free or commercial games made with a legal copy of RPG Maker     │     ║
  25. ║     │ VX Ace, as long as Maker Systems - RPG Maker Source is           │     ║
  26. ║     │ credited within the game.                                        │     ║
  27. ║     │                                                                  │     ║
  28. ║     │ Selling this code or any portions of it 'as-is' or as part of    │     ║
  29. ║     │ another code, is not allowed.                                    │     ║
  30. ║     │                                                                  │     ║
  31. ║     │ The original header, which includes this copyright notice,       │     ║
  32. ║     │ must not be edited or removed from any verbatim copy of the      │     ║
  33. ║     │ sotware nor from any edited version.                             │     ║
  34. ║     │                                                                  │     ║
  35. ║     ╚══════════════════════════════════════════════════════════════════╝     ║
  36. ║                                                                              ║
  37. ║                                                                              ║
  38. ╠══════════════════════════════════════════════════════════════════════════════╣
  39. 1. VERSION HISTORY.                                                        ▼ ║
  40. ╠══════════════════════════════════════════════════════════════════════════════╣
  41. ║                                                                              ║
  42. ║ • Version 1.0.0, 29/11/14 - (DD/MM/YY).                                      ║
  43. ║                                                                              ║
  44. ║ • Version 1.0.1, 29/11/14 - (DD/MM/YY).                                      ║
  45. ║                                                                              ║
  46. ║ • Version 1.0.2, 30/11/14 - (DD/MM/YY).                                      ║
  47. ║                                                                              ║
  48. ║ • Version 1.0.3, 02/12/14 - (DD/MM/YY).                                      ║
  49. ║                                                                              ║
  50. ╠══════════════════════════════════════════════════════════════════════════════╣
  51. ╠══════════════════════════════════════════════════════════════════════════════╣
  52. 2. USER MANUAL.                                                            ▼ ║
  53. ╠══════════════════════════════════════════════════════════════════════════════╣
  54. ║                                                                              ║
  55. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  56. ║ │ ■ Introduction.                                                          │ ║
  57. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  58. ║                                                                              ║
  59. ║  Hello there! This script is "plug and play", you can simply insert it       ║
  60. ║  into your project and it will perform flawlessly.                           ║
  61. ║                                                                              ║
  62. ║  This script can create awesome looking effects for characters in your       ║
  63. ║  game (both for Events and player characters). It can be used for many       ║
  64. ║  situations, to convey the idea of speed, power effects, skills, slow        ║
  65. ║  motion camera, ghosts, and even mitical beings. Your imagination is the     ║
  66. ║  limit.                                                                      ║
  67. ║                                                                              ║
  68. ║  There are a lot of different looking effects that are possible by just      ║
  69. ║  changing some parameter combinations when you call for the effect, so be    ║
  70. ║  sure to check the Feature Documentation section of this manual to           ║
  71. ║  experience the full power of the system.                                    ║
  72. ║                                                                              ║
  73. ║  We hope you enjoy it.                                                       ║
  74. ║                                                                              ║
  75. ║  Thanks for choosing our products.                                           ║
  76. ║                                                                              ║
  77. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  78. ║ │ ■ Configuration.                                                         │ ║
  79. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  80. ║                                                                              ║
  81. ║  The effect can be set to be performed automatically when the player         ║
  82. ║  dashes, and you can choose how it will look by changing the same            ║
  83. ║  parameters that you can use when you call for the effect to be performed    ║
  84. ║  on an event.                                                                ║
  85. ║                                                                              ║
  86. ║  The parameters are explained in the Feature Documentation section, to       ║
  87. ║  change certain parameter for the Player default (when dashing), click       ║
  88. ║  anywhere in the script editor and select "Find" or (CTRL + F), search       ║
  89. ║  for:                                                                        ║
  90. ║                                                                              ║
  91. ║  Player_Dash_ + parameter name. For example:                                 ║
  92. ║                                                                              ║
  93. ║  "PLAYER_DASH_RHYTHM" (without quotation marks)                              ║
  94. ║                                                                              ║
  95. ║  You will see something like "PLAYER_DASH_RHYTHM = 4"                        ║
  96. ║                                                                              ║
  97. ║  Change the number after the equality sign to any possible parameter         ║
  98. ║  value, the possible values are decribed in the next section (Feature        ║
  99. ║  Documentation).                                                             ║
  100. ║                                                                              ║
  101. ║ ┌──────────────────────────────────────────────────────────────────────────┐ ║
  102. ║ │ ■ Feature Documentation.                                                 │ ║
  103. ║ └┬┬┬┬──────────────────────────────────────────────────────────────────┬┬┬┬┘ ║
  104. ║                                                                              ║
  105. ║  There are two script calls documented in the following section, one is      ║
  106. ║  for starting the effect on a certain character and the other one is for     ║
  107. ║  ending the effect on a certain character.                                   ║
  108. ║                                                                              ║
  109. ║  ┌─────────────────────────────────────────────────────────────────────┐     ║
  110. ║  │ ms_start_speed_trail(id, rhythm, delay, blend_type, opacity, [...]) │     ║
  111. ║  ├─────────────────────────────────────────────────────────────────────┴──┐  ║
  112. ║  │ This command tells the system to start performing the effect on        │  ║
  113. ║  │ certain character.                                                     │  ║
  114. ║  │                                                                        │  ║
  115. ║  │ There are many properties that you can combine to make unique, cool    │  ║
  116. ║  │ effects for your scenes.                                               │  ║
  117. ║  │ There are 5 necessary parameters, this are "id", "rhythm", "delay",    │  ║
  118. ║  │ "blend_type" and "opacity". Any parameter after those is optional, but │  ║
  119. ║  │ should you include more, they need to be written in the following      │  ║
  120. ║  │ order:                                                                 │  ║
  121. ║  │                                                                        │  ║
  122. ║  │ ([...], color, wave_amp, wave_length, wave_speed, blur_level, limit)   │  ║
  123. ║  │                                                                        │  ║
  124. ║  │ If you want to include a parameter that comes after one that you       │  ║
  125. ║  │ don't, make 'nil' (without quotation marks) the value for those you    │  ║
  126. ║  │ don't want (to keep the order).                                        │  ║
  127. ║  │                                                                        │  ║
  128. ║  │ • What is "id"?                                                        │  ║
  129. ║  │ id is a number representing the character, 0 is for player, and 1 and  │  ║
  130. ║  │ up for event id.                                                       │  ║
  131. ║  │                                                                        │  ║
  132. ║  │ • What is "rhytm"?                                                     │  ║
  133. ║  │ Interval in frames of each Sprite appearance. Lower numbers result in  │  ║
  134. ║  │ a more continuous effect while bigger number makes each "blueprint"    │  ║
  135. ║  │ Sprite appear more far appart.                                         │  ║
  136. ║  │                                                                        │  ║
  137. ║  │ Use any number equal or greater than 0.                                │  ║
  138. ║  │                                                                        │  ║
  139. ║  │ • What is "delay"?                                                     │  ║
  140. ║  │ Number of frames that each Sprite will remain visible.                 │  ║
  141. ║  │                                                                        │  ║
  142. ║  │ Use any number equal or greater than 1.                                │  ║
  143. ║  │                                                                        │  ║
  144. ║  │ • What is "blendType"?                                                 │  ║
  145. ║  │ Blend mode for the Sprites used in the effect.                         │  ║
  146. ║  │                                                                        │  ║
  147. ║  │ Use 0 for normal, 1 for addition, and 2 for subtraction.               │  ║
  148. ║  │                                                                        │  ║
  149. ║  │ • What is "opacity"?                                                   │  ║
  150. ║  │ This represents the starting opacity for each Sprite.                  │  ║
  151. ║  │                                                                        │  ║
  152. ║  │ Use either a number between 0.0 and 1.0 to represent the percentage    │  ║
  153. ║  │ (0.9 being 90%, and so on), or a number from 0 to 255 (255 being 100%  │  ║
  154. ║  │ and so on).                                                            │  ║
  155. ║  │                                                                        │  ║
  156. ║  │ • What is "color"?                                                     │  ║
  157. ║  │ Color represents the color of the trail, in case you want the effect   │  ║
  158. ║  │ to have a different color than that of the normal character sprite.    │  ║
  159. ║  │                                                                        │  ║
  160. ║  │ Example: '0 255 0'                                                     │  ║
  161. ║  │                                                                        │  ║
  162. ║  │ You might be asking yourself "What is that supposed to mean?" but      │  ║
  163. ║  │ worry not, my friend, because it is actually very simple:              │  ║
  164. ║  │ The single quotes are used to encapsulate the color information. You   │  ║
  165. ║  │ can put either RGBA values in there or HEX values.                     │  ║
  166. ║  │ If you want to use RGBA colors, simple leave a space after each color  │  ║
  167. ║  │ value, like this:                                                      │  ║
  168. ║  │                                                                        │  ║
  169. ║  │ BACK_COLOR = 'RED GREEN BLUE ALPHA'                                    │  ║
  170. ║  │                                                                        │  ║
  171. ║  │ The values for RED, GREEN, BLUE, and ALPHA must be numbers between 0   │  ║
  172. ║  │ and 255.                                                               │  ║
  173. ║  │                                                                        │  ║
  174. ║  │ ALPHA is the opacity of the color.                                     │  ║
  175. ║  │                                                                        │  ║
  176. ║  │ On the other hand, if you want to use HEX codes, simply put a # (hash  │  ║
  177. ║  │ character) before it, like this:                                       │  ║
  178. ║  │                                                                        │  ║
  179. ║  │ BACK_COLOR = '#0000009B'                                               │  ║
  180. ║  │                                                                        │  ║
  181. ║  │ • What is "wave_amp"?                                                  │  ║
  182. ║  │ This represents the amplitude of the wave effect and it is not         │  ║
  183. ║  │ necessary for you to include it. It is deactivated by default. For     │  ║
  184. ║  │ more information, check RPG Maker Ace's help file, Sprite section.     │  ║
  185. ║  │                                                                        │  ║
  186. ║  │ • What is "wave_length"?                                               │  ║
  187. ║  │ This represents the wave frequency, it is not necessary for you to     │  ║
  188. ║  │ include it unless you want the system to perform a wave effect for     │  ║
  189. ║  │ this Speed Trail.                                                      │  ║
  190. ║  │                                                                        │  ║
  191. ║  │ • What is "wave_speed"?                                                │  ║
  192. ║  │ This represents the speed of the wave effect, it is not necessary for  │  ║
  193. ║  │ you to include it and the default is 360.                              │  ║
  194. ║  │                                                                        │  ║
  195. ║  │ • What is "blur_level"?                                                │  ║
  196. ║  │ This represents the strength of the blur effect in each Sprite, it is  │  ║
  197. ║  │ not necessary for you to include it and the default is nil             │  ║
  198. ║  │ (deactivated). Use either nil for no blur, or any number equal or      │  ║
  199. ║  │ greater than 1. Keep in mind that blur effects are CPU intensive, the  │  ║
  200. ║  │ bigger the strength (blur level), the more intensive.                  │  ║
  201. ║  │                                                                        │  ║
  202. ║  │ • What is "size_limit"?                                                │  ║
  203. ║  │ This represents the maximum number of Sprites that the effect can use  │  ║
  204. ║  │ for each character simultaneously.                                     │  ║
  205. ║  │ So for example, if you set the size limit of the Player to 22 and      │  ║
  206. ║  │ either the rhythm is too short or the spawn delay is too long, causing │  ║
  207. ║  │ many Sprites to appear on screen at the same time, the Sprite creation │  ║
  208. ║  │ will be capped at 22.                                                  │  ║
  209. ║  │ This is to ensure the good performance of your game.                   │  ║
  210. ║  │                                                                        │  ║
  211. ║  │ Any numer equal or greater than 1. If you don't include this           │  ║
  212. ║  │ parameter, the default SIZE_LIMIT will be used.                        │  ║
  213. ║  │                                                                        │  ║
  214. ║  └────────────────────────────────────────────────────────────────────────┘  ║
  215. ║  ┌─────────────────────────┐                                                 ║
  216. ║  │ ms_stop_speed_trail(id) │                                                 ║
  217. ║  ├─────────────────────────┴──────────────────────────────────────────────┐  ║
  218. ║  │ This command tells the system to stop performing the effect on certain │  ║
  219. ║  │ character.                                                             │  ║
  220. ║  │                                                                        │  ║
  221. ║  │ • What is "id"?                                                        │  ║
  222. ║  │ id is a number representing the character, 0 is for player, and 1 and  │  ║
  223. ║  │ up for event id.                                                       │  ║
  224. ║  │                                                                        │  ║
  225. ║  └────────────────────────────────────────────────────────────────────────┘  ║
  226. ║                                                                              ║
  227. ║  TL;DR:                                                                      ║
  228. ║  • The effect can be automatic each time the player dashes by pressing       ║
  229. ║    SHIFT. To customize the look of that effect, go to the configuration      ║
  230. ║    part of the script.                                                       ║
  231. ║    To turn the automatic effect off, set PLAYER_DASH_AUTOST to false.        ║
  232. ║  • You can activate the effect, and deactivate it for any character by       ║
  233. ║    using ms_start_speed_trail(the arguments) and ms_stop_speed_trail(id)     ║
  234. ║  • You're awesome.                                                           ║
  235. ║                                                                              ║
  236. ╠══════════════════════════════════════════════════════════════════════════════╣
  237. ╠══════════════════════════════════════════════════════════════════════════════╣
  238. ║ 3. NOTES.                                                                  ▼ ║
  239. ╠══════════════════════════════════════════════════════════════════════════════╣
  240. ║                                                                              ║
  241. ║  Have fun and enjoy!                                                         ║
  242. ║                                                                              ║
  243. ╠══════════════════════════════════════════════════════════════════════════════╣
  244. ╠══════════════════════════════════════════════════════════════════════════════╣
  245. ║ 4. CONTACT.                                                                ▼ ║
  246. ╠══════════════════════════════════════════════════════════════════════════════╣
  247. ║                                                                              ║
  248. ║  Keep in touch with us and be the first to know about new releases:          ║
  249. ║                                                                              ║
  250. ║  www.rpgmakersource.com                                                      ║
  251. ║  www.facebook.com/RPGMakerSource                                             ║
  252. ║  www.twitter.com/RPGMakerSource                                              ║
  253. ║  www.youtube.com/user/RPGMakerSource                                         ║
  254. ║                                                                              ║
  255. ║  Get involved! Have an idea for a system? Let us know.                       ║
  256. ║                                                                              ║
  257. ║  Spread the word and help us reach more people so we can continue creating   ║
  258. ║  awesome resources for you!                                                  ║
  259. ║                                                                              ║
  260. ╚══════════════════════════════════════════════════════════════════════════════╝)
  261.  
  262. #==============================================================================
  263. # ** Maker Systems
  264. #------------------------------------------------------------------------------
  265. #  Module for our scripts.
  266. #==============================================================================
  267.  
  268. module MakerSystems
  269.  
  270.  #============================================================================
  271.  # ** Speed Trail                                                        [NEW]
  272.  #----------------------------------------------------------------------------
  273.  #  Module for some configurable values in Speed Trail.
  274.  #============================================================================
  275.  
  276.  module SpeedTrail
  277.    
  278.    #------------------------------------------------------------------------
  279.    # * Default Speed Trail for Player Dashing.                         [OPT]
  280.    #------------------------------------------------------------------------
  281.    PLAYER_DASH_AUTOST      = true
  282.    #------------------------------------------------------------------------
  283.    # * Rhythm for Player Dashing.                                      [OPT]
  284.    #------------------------------------------------------------------------
  285.    PLAYER_DASH_RHYTHM      = 2
  286.    #------------------------------------------------------------------------
  287.    # * Delay for Player Dashing.                                       [OPT]
  288.    #------------------------------------------------------------------------
  289.    PLAYER_DASH_SPAWNDELAY  = 15
  290.    #------------------------------------------------------------------------
  291.    # * Blend Type for Player Dashing.                                  [OPT]
  292.    #------------------------------------------------------------------------
  293.    PLAYER_DASH_BLENDTYPE   = 0
  294.    #------------------------------------------------------------------------
  295.    # * Opacity for Player Dashing.                                     [OPT]
  296.    #------------------------------------------------------------------------
  297.    PLAYER_DASH_OPACITY     = 0.9
  298.    #------------------------------------------------------------------------
  299.    # * Color for Player Dashing.                                     [OPT]
  300.    #------------------------------------------------------------------------
  301.    PLAYER_DASH_COLOR       = nil
  302.    #------------------------------------------------------------------------
  303.    # * Wave Amp for Player Dashing.                                    [OPT]
  304.    #------------------------------------------------------------------------
  305.    PLAYER_DASH_WAVE_AMP    = nil
  306.    #------------------------------------------------------------------------
  307.    # * Wave Length for Player Dashing.                                 [OPT]
  308.    #------------------------------------------------------------------------
  309.    PLAYER_DASH_WAVE_LENGTH = nil
  310.    #------------------------------------------------------------------------
  311.    # * Wave Speed for Player Dashing.                                  [OPT]
  312.    #------------------------------------------------------------------------
  313.    PLAYER_DASH_WAVE_SPEED  = nil
  314.    #------------------------------------------------------------------------
  315.    # * Blur Level for Player Dashing.                                  [OPT]
  316.    #------------------------------------------------------------------------
  317.    PLAYER_DASH_BLUR_LEVEL  = 1
  318.    #------------------------------------------------------------------------
  319.    # * Trail Size Limit for Player Dashing.                            [OPT]
  320.    #------------------------------------------------------------------------
  321.    PLAYER_DASH_SIZE_LIMIT  = 22
  322.    #------------------------------------------------------------------------
  323.    # * Default Limit of Speed Trails (Sprites) for each Character.     [OPT]
  324.    #------------------------------------------------------------------------
  325.    SIZE_LIMIT              = 10
  326.    
  327.  end
  328.  
  329. end
  330.  
  331. #==============================================================================
  332. # ** Game_CharacterBase                                                   [MOD]
  333. #------------------------------------------------------------------------------
  334. #  Adds some variables to handle the effect.
  335. #==============================================================================
  336.  
  337. class Game_CharacterBase
  338.  
  339.  #--------------------------------------------------------------------------
  340.  # * Public Instance Variables.                                        [NEW]
  341.  #--------------------------------------------------------------------------
  342.  attr_accessor :ms_speed_trail_enable, :ms_speed_trail_rhythm,
  343.                :ms_speed_trail_delay, :ms_speed_trail_blend_type,
  344.                :ms_speed_trail_opacity, :ms_speed_trail_wave_amp,
  345.                :ms_speed_trail_wave_length, :ms_speed_trail_wave_speed,
  346.                :ms_speed_trail_blur_level, :ms_speed_trail_limit,
  347.                :ms_speed_trail_color
  348.    
  349. end
  350.  
  351. #==============================================================================
  352. # ** Game_Player                                                          [MOD]
  353. #------------------------------------------------------------------------------
  354. #  Alias to Update. Adds method that handles the effect while player runs.
  355. #==============================================================================
  356.  
  357. class Game_Player < Game_Character
  358.  
  359.  #--------------------------------------------------------------------------
  360.  # * Public Instance Variables.                                        [NEW]
  361.  #--------------------------------------------------------------------------
  362.  attr_accessor :ms_speed_trail_previous
  363.  #--------------------------------------------------------------------------
  364.  # * Alias Update.                                                     [NEW]
  365.  #--------------------------------------------------------------------------
  366.  alias_method(:ms_speed_trail_original_update, :update)
  367.  #--------------------------------------------------------------------------
  368.  # * Update.                                                           [MOD]
  369.  #--------------------------------------------------------------------------
  370.  def update
  371.    # Original method.
  372.    ms_speed_trail_original_update
  373.    # If the effect is automatically active for player dashing.
  374.    if MakerSystems::SpeedTrail::PLAYER_DASH_AUTOST
  375.      # Player dashing?
  376.      if dash?
  377.        if @ms_speed_trail_enable && !@ms_speed_trail_enable_from_dashing
  378.          @ms_speed_trail_previous ||= [@ms_speed_trail_rhythm,
  379.          @ms_speed_trail_delay, @ms_speed_trail_blend_type,
  380.          @ms_speed_trail_opacity, @ms_speed_trail_color,
  381.          @ms_speed_trail_wave_amp, @ms_speed_trail_wave_length,
  382.          @ms_speed_trail_wave_speed, @ms_speed_trail_blur_level,
  383.          @ms_speed_trail_limit]
  384.        end
  385.        # Shortcut to Speed Trail module.
  386.        ms_speed_trail = MakerSystems::SpeedTrail
  387.        # Set up the effect using Player values.
  388.        @ms_speed_trail_rhythm      = ms_speed_trail::PLAYER_DASH_RHYTHM
  389.        @ms_speed_trail_delay       = ms_speed_trail::PLAYER_DASH_SPAWNDELAY
  390.        @ms_speed_trail_blend_type  = ms_speed_trail::PLAYER_DASH_BLENDTYPE
  391.        @ms_speed_trail_opacity     = ms_speed_trail::PLAYER_DASH_OPACITY
  392.        @ms_speed_trail_color       = ms_speed_trail::PLAYER_DASH_COLOR
  393.        @ms_speed_trail_wave_amp    = ms_speed_trail::PLAYER_DASH_WAVE_AMP
  394.        @ms_speed_trail_wave_length = ms_speed_trail::PLAYER_DASH_WAVE_LENGTH
  395.        @ms_speed_trail_wave_speed  = ms_speed_trail::PLAYER_DASH_WAVE_SPEED
  396.        @ms_speed_trail_blur_level  = ms_speed_trail::PLAYER_DASH_BLUR_LEVEL
  397.        @ms_speed_trail_limit       = ms_speed_trail::PLAYER_DASH_SIZE_LIMIT
  398.        # Effect ready flag.
  399.        @ms_speed_trail_enable = true
  400.        @ms_speed_trail_enable_from_dashing = true
  401.      else
  402.        if @ms_speed_trail_enable_from_dashing
  403.          @ms_speed_trail_enable_from_dashing = nil
  404.          if @ms_speed_trail_previous
  405.            # Restores previous effect.
  406.            @ms_speed_trail_rhythm, @ms_speed_trail_delay,
  407.            @ms_speed_trail_blend_type, @ms_speed_trail_opacity,
  408.            @ms_speed_trail_color, @ms_speed_trail_wave_amp,
  409.            @ms_speed_trail_wave_length, @ms_speed_trail_wave_speed,
  410.            @ms_speed_trail_blur_level, @ms_speed_trail_limit =
  411.            *@ms_speed_trail_previous
  412.            @ms_speed_trail_previous = nil
  413.          else
  414.            # Cancels the effect and clears its information.
  415.            @ms_speed_trail_enable = nil
  416.            @ms_speed_trail_delay = @ms_speed_trail_rhythm =
  417.            @ms_speed_trail_blend_type = @ms_speed_trail_opacity =
  418.            @ms_speed_trail_color = @ms_speed_trail_wave_amp =
  419.            @ms_speed_trail_wave_length = @ms_speed_trail_wave_speed =
  420.            @ms_speed_trail_blur_level = @ms_speed_trail_limit = nil
  421.          end
  422.        end
  423.      end
  424.    end
  425.  end
  426.  
  427. end
  428.  
  429. #==============================================================================
  430. # ** MS_SpeedTrail_Sprite                                                 [NEW]
  431. #------------------------------------------------------------------------------
  432. #  This class is used to display the effect.
  433. #==============================================================================
  434.  
  435. class MS_SpeedTrail_Sprite < Sprite
  436.  
  437.  #--------------------------------------------------------------------------
  438.  # * Initialize.
  439.  #--------------------------------------------------------------------------
  440.  def initialize(parent)
  441.    # Superclass method.
  442.    super(parent.viewport)
  443.    # Get parent character.
  444.    character = parent.character
  445.    # Get parent Sprite rect.
  446.    rect  = parent.src_rect
  447.    # Get parent character shift_y.
  448.    shift = character.shift_y
  449.    # Get parent character jump_height.
  450.    jump  = character.jump_height
  451.    # Set up target X & target Y.
  452.    @target_x = $game_map.display_x * 32 + parent.x
  453.    @target_y = $game_map.display_y * 32 + parent.y
  454.    # Set up Offset X & Offset Y.
  455.    self.ox = parent.ox
  456.    self.oy = parent.oy
  457.    # Opacity value.
  458.    transparency = character.ms_speed_trail_opacity
  459.    # If transparency value represents a percentage.
  460.    if transparency < 1.0
  461.      # Set opacity according to percentage given.
  462.      @target_opacity = parent.opacity * transparency
  463.    else
  464.      # Set opacity according to desired value.
  465.      @target_opacity = transparency
  466.    end
  467.    # Step value.
  468.    @target_step = @target_opacity.to_f / character.ms_speed_trail_delay.to_f
  469.    # Z order.
  470.    self.z = character.direction == 8 ? parent.z + 1 : parent.z - 1
  471.    # Set up X & Y position.
  472.    self.x = -$game_map.display_x * 32 + @target_x
  473.    self.y = -$game_map.display_y * 32 + @target_y
  474.    # Set up desired blend type.
  475.    self.blend_type = parent.character.ms_speed_trail_blend_type
  476.    # Set up opacity.
  477.    self.opacity = @target_opacity
  478.    # Set up bitmap for correct character pose.
  479.    self.bitmap = Bitmap.new(rect.width, rect.height)
  480.    self.bitmap.blt(0, 0, parent.bitmap, rect)
  481.    # Apply blur if needed.
  482.    if character.ms_speed_trail_blur_level
  483.      character.ms_speed_trail_blur_level.times { self.bitmap.blur }
  484.    end
  485.    # Set up wave effect if needed.
  486.    if character.ms_speed_trail_wave_amp
  487.      self.wave_amp    = character.ms_speed_trail_wave_amp
  488.      self.wave_length = character.ms_speed_trail_wave_length
  489.      self.wave_speed  = character.ms_speed_trail_wave_speed
  490.    end
  491.    # Set up Sprite color if needed.
  492.    if parent.character.ms_speed_trail_color
  493.      self.color = character.ms_speed_trail_color
  494.    end
  495.  end
  496.  #--------------------------------------------------------------------------
  497.  # * Update
  498.  #--------------------------------------------------------------------------
  499.  def update
  500.    # Superclass method.
  501.    super
  502.    # Updates X & Y position.
  503.    self.x = -$game_map.display_x * 32 + @target_x
  504.    self.y = -$game_map.display_y * 32 + @target_y
  505.    # Updates opacity and returns vital signs.
  506.    self.opacity -= @target_step
  507.    self.opacity > 0
  508.  end
  509.  
  510. end
  511.  
  512. #==============================================================================
  513. # ** Sprite_Character                                                     [MOD]
  514. #------------------------------------------------------------------------------
  515. #  Alias to Update. Adds method to handle the main effect.
  516. #==============================================================================
  517.  
  518. class Sprite_Character < Sprite_Base
  519.  
  520.  #--------------------------------------------------------------------------
  521.  # * Alias Update.                                                     [NEW]
  522.  #--------------------------------------------------------------------------
  523.  alias_method(:ms_speed_trail_original_update, :update)
  524.  #--------------------------------------------------------------------------
  525.  # * Update.                                                           [MOD]
  526.  #--------------------------------------------------------------------------
  527.  def update
  528.    # Original method.
  529.    ms_speed_trail_original_update
  530.    # If child sprites exists.
  531.    if @ms_speed_trail_sprites
  532.      # Iterate through each Speed Trail Sprite.
  533.      @ms_speed_trail_sprites.each do |sprite|
  534.        # Update and check vitality.
  535.        unless sprite.update
  536.          # Dispose Bitmap and Sprite when dead.
  537.          sprite.bitmap.dispose
  538.          sprite.dispose
  539.          # Remove from array.
  540.          @ms_speed_trail_sprites.delete(sprite)
  541.        end
  542.      end
  543.    end
  544.    # If the effect is enabled.
  545.    if @character.ms_speed_trail_enable
  546.      # Unless there is already a Sprite container.
  547.      unless @ms_speed_trail_sprites
  548.        # Create Speed Trail if moving.
  549.        if @character.moving?
  550.          @ms_speed_trail_sprites = [MS_SpeedTrail_Sprite.new(self)]
  551.        end
  552.        # Save this position for future reference.
  553.        @ms_speed_trail_last_x = @character.real_x
  554.        @ms_speed_trail_last_y = @character.real_y
  555.        # Set up spawn rate.
  556.        @ms_speed_trail_spawn_rate = @character.ms_speed_trail_rhythm
  557.      end
  558.      # Update rate.
  559.      @ms_speed_trail_spawn_rate -= 1
  560.      # Correct rate if needed.
  561.      if @ms_speed_trail_spawn_rate < 0
  562.        @ms_speed_trail_spawn_rate = 0
  563.      end
  564.      # If time is up.
  565.      if @ms_speed_trail_spawn_rate == 0
  566.        # If character moved.
  567.        if @character.real_x != @ms_speed_trail_last_x ||
  568.           @character.real_y != @ms_speed_trail_last_y
  569.          # Custom limit?
  570.          if @character.ms_speed_trail_limit
  571.            limit = @character.ms_speed_trail_limit
  572.          else
  573.            # Default limit.
  574.            limit = MakerSystems::SpeedTrail::SIZE_LIMIT
  575.          end
  576.          # If trail is smaller than limit.
  577.          if @ms_speed_trail_sprites.size < limit
  578.            # Create Speed Trail if visible.
  579.            if self.visible
  580.              @ms_speed_trail_sprites << MS_SpeedTrail_Sprite.new(self)
  581.            end
  582.          end
  583.          # Save this position for future reference.
  584.          @ms_speed_trail_last_x = @character.real_x
  585.          @ms_speed_trail_last_y = @character.real_y
  586.          # Reset spawn rate.
  587.          @ms_speed_trail_spawn_rate = @character.ms_speed_trail_rhythm
  588.        end
  589.      end
  590.    else
  591.      # Speed Trail container?
  592.      if @ms_speed_trail_sprites && @ms_speed_trail_sprites.empty?
  593.        # Clear container.
  594.        @ms_speed_trail_sprites.clear
  595.        # Clear used variables.
  596.        @ms_speed_trail_sprites = @ms_speed_trail_last_x =
  597.        @ms_speed_trail_last_y = @ms_speed_trail_spawn_rate = nil
  598.      end
  599.    end
  600.  end
  601.  #--------------------------------------------------------------------------
  602.  # * Alias Dispose.                                                    [NEW]
  603.  #--------------------------------------------------------------------------
  604.  alias_method(:ms_speed_trail_original_dispose, :dispose)
  605.  #--------------------------------------------------------------------------
  606.  # * Dispose.                                                          [MOD]
  607.  #--------------------------------------------------------------------------
  608.  def dispose
  609.    # Original method.
  610.    ms_speed_trail_original_dispose
  611.    # Dispose existing trail Sprites.
  612.    if @ms_speed_trail_sprites
  613.      @ms_speed_trail_sprites.each do |sprite|
  614.        sprite.bitmap.dispose
  615.        sprite.dispose
  616.      end
  617.    end
  618.  end
  619.  
  620. end
  621.  
  622.  #--------------------------------------------------------------------------
  623.  # * Start Speed Trail.                                                [NEW]
  624.  #--------------------------------------------------------------------------
  625.  def ms_start_speed_trail(id, rhythm, delay, blend_type = 1, opacity = 0.9,
  626.                           color = nil, wave_amp = nil, wave_length = nil,
  627.                           wave_speed = nil, ms_speed_trail_blur_level = nil,
  628.                           limit = nil)
  629.    # Get character based on id.
  630.    character = id == 0 ? $game_player : $game_map.events[id]
  631.    # Color object generation.
  632.    if color
  633.      if color.include?('#')
  634.         color = color.delete!('#').scan(/../).map { |c| c.to_i(16) }
  635.       else
  636.         color = color.split(' ').map { |c| c.to_i }
  637.       end
  638.       color = Color.new(*color)
  639.     end
  640.     # Default value correction.
  641.     blend_type = 1   unless blend_type
  642.     opacity    = 0.9 unless opacity
  643.     # Set up basic effect information.
  644.     character.ms_speed_trail_rhythm      = rhythm
  645.     character.ms_speed_trail_delay       = delay
  646.     character.ms_speed_trail_blend_type  = blend_type
  647.     character.ms_speed_trail_opacity     = opacity
  648.     character.ms_speed_trail_wave_amp    = wave_amp
  649.     character.ms_speed_trail_wave_length = wave_length
  650.     character.ms_speed_trail_wave_speed  = wave_speed
  651.     character.ms_speed_trail_blur_level  = ms_speed_trail_blur_level
  652.     character.ms_speed_trail_limit       = limit
  653.     character.ms_speed_trail_color       = color
  654.     # Effect enabled.
  655.     character.ms_speed_trail_enable = true
  656.   end
  657.   #--------------------------------------------------------------------------
  658.   # * Stop Speed Trail.                                                 [NEW]
  659.   #--------------------------------------------------------------------------
  660.   def ms_stop_speed_trail(id)
  661.     # Get character based on id.
  662.     character = id == 0 ? $game_player : $game_map.events[id]
  663.     # Effect disabled.
  664.     character.ms_speed_trail_enable = false
  665.     # Clears effect information.
  666.     character.ms_speed_trail_rhythm = character.ms_speed_trail_delay =
  667.     character.ms_speed_trail_blend_type = character.ms_speed_trail_opacity =
  668.     character.ms_speed_trail_wave_amp = character.ms_speed_trail_wave_length =
  669.     character.ms_speed_trail_wave_speed = character.ms_speed_trail_blur_level =
  670.     character.ms_speed_trail_limit = character.ms_speed_trail_color = nil
  671.   end
Add Comment
Please, Sign In to add comment