/Field/Force_Move_Tiles.rb

https://gitlab.com/GethN7/YEARepo · Ruby · 244 lines · 98 code · 33 blank · 113 comment · 20 complexity · 6ff3960f265eb311ccc68b5971735772 MD5 · raw file

  1. #==============================================================================
  2. #
  3. # Yanfly Engine Ace - Force Move Tiles v1.00
  4. # -- Last Updated: 2011.12.06
  5. # -- Level: Normal
  6. # -- Requires: n/a
  7. #
  8. #==============================================================================
  9. $imported = {} if $imported.nil?
  10. $imported["YEA-ForceMoveTiles"] = true
  11. #==============================================================================
  12. # Updates
  13. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  14. # 2011.12.06 - Started Script and Finished.
  15. #
  16. #==============================================================================
  17. # Introduction
  18. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  19. # This script allows certain tiles to force the player to move in one direction
  20. # and continuing moving in that direction until the player is off of those
  21. # specific tiles. Similar to conveyor belts or gravity tiles (from games like
  22. # Chip's Challenge), these tiles only move the player in one direction.
  23. #
  24. #==============================================================================
  25. # Instructions
  26. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  27. # To install this script, open up your script editor and copy/paste this script
  28. # to an open slot below Materials/素材 but above Main. Remember to save.
  29. #
  30. # -----------------------------------------------------------------------------
  31. # Tileset Notetags - These notetags go in the tileset notebox in the database.
  32. # -----------------------------------------------------------------------------
  33. # <force up: x>
  34. # <force up: x, x>
  35. # <force down: x>
  36. # <force down: x, x>
  37. # <force left: x>
  38. # <force left: x, x>
  39. # <force right: x>
  40. # <force right: x, x>
  41. # By marking specific terrain tags with x and using these notetags, you can
  42. # have a tile specifically move the player in that direction until the player
  43. # is off of a force move tile or until the player hits an object.
  44. #
  45. #==============================================================================
  46. # Compatibility
  47. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  48. # This script is made strictly for RPG Maker VX Ace. It is highly unlikely that
  49. # it will run with RPG Maker VX without adjusting.
  50. #
  51. #==============================================================================
  52. # Editting anything past this point may potentially result in causing
  53. # computer damage, incontinence, explosion of user's head, coma, death, and/or
  54. # halitosis so edit at your own risk.
  55. #==============================================================================
  56. module YEA
  57. module REGEXP
  58. module TILESET
  59. FORCE_UP = /<(?:FORCE_UP|force up):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  60. FORCE_DOWN = /<(?:FORCE_DOWN|force down):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  61. FORCE_LEFT = /<(?:FORCE_LEFT|force left):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  62. FORCE_RIGHT = /<(?:FORCE_RIGHT|force right):[ ]*(\d+(?:\s*,\s*\d+)*)>/i
  63. end # TILESET
  64. end # REGEXP
  65. end # YEA
  66. #==============================================================================
  67. # DataManager
  68. #==============================================================================
  69. module DataManager
  70. #--------------------------------------------------------------------------
  71. # alias method: load_database
  72. #--------------------------------------------------------------------------
  73. class <<self; alias load_database_fmt load_database; end
  74. def self.load_database
  75. load_database_fmt
  76. load_notetags_fmt
  77. end
  78. #--------------------------------------------------------------------------
  79. # new method: load_notetags_fmt
  80. #--------------------------------------------------------------------------
  81. def self.load_notetags_fmt
  82. groups = [$data_tilesets]
  83. for group in groups
  84. for obj in group
  85. next if obj.nil?
  86. obj.load_notetags_fmt
  87. end
  88. end
  89. end
  90. end # DataManager
  91. #==============================================================================
  92. # RPG::Tileset
  93. #==============================================================================
  94. class RPG::Tileset
  95. #--------------------------------------------------------------------------
  96. # public instance variables
  97. #--------------------------------------------------------------------------
  98. attr_accessor :force_up
  99. attr_accessor :force_down
  100. attr_accessor :force_left
  101. attr_accessor :force_right
  102. #--------------------------------------------------------------------------
  103. # common cache: load_notetags_fmt
  104. #--------------------------------------------------------------------------
  105. def load_notetags_fmt
  106. @force_up = []
  107. @force_down = []
  108. @force_left = []
  109. @force_right = []
  110. #---
  111. self.note.split(/[\r\n]+/).each { |line|
  112. case line
  113. #---
  114. when YEA::REGEXP::TILESET::FORCE_UP
  115. $1.scan(/\d+/).each { |num|
  116. @force_up.push(num.to_i) if num.to_i > 0 }
  117. when YEA::REGEXP::TILESET::FORCE_DOWN
  118. $1.scan(/\d+/).each { |num|
  119. @force_down.push(num.to_i) if num.to_i > 0 }
  120. when YEA::REGEXP::TILESET::FORCE_LEFT
  121. $1.scan(/\d+/).each { |num|
  122. @force_left.push(num.to_i) if num.to_i > 0 }
  123. when YEA::REGEXP::TILESET::FORCE_RIGHT
  124. $1.scan(/\d+/).each { |num|
  125. @force_right.push(num.to_i) if num.to_i > 0 }
  126. #---
  127. end
  128. } # self.note.split
  129. #---
  130. end
  131. end # RPG::Tileset
  132. #==============================================================================
  133. # Game_Map
  134. #==============================================================================
  135. class Game_Map
  136. #--------------------------------------------------------------------------
  137. # new method: force_move_tile?
  138. #--------------------------------------------------------------------------
  139. def force_move_tile?(dx, dy)
  140. return (valid?(dx, dy) && force_move_tag?(dx, dy))
  141. end
  142. #--------------------------------------------------------------------------
  143. # new method: force_move_tag?
  144. #--------------------------------------------------------------------------
  145. def force_move_tag?(dx, dy)
  146. return true if tileset.force_up.include?(terrain_tag(dx, dy))
  147. return true if tileset.force_down.include?(terrain_tag(dx, dy))
  148. return true if tileset.force_left.include?(terrain_tag(dx, dy))
  149. return true if tileset.force_right.include?(terrain_tag(dx, dy))
  150. return false
  151. end
  152. #--------------------------------------------------------------------------
  153. # new method: force_move_direction
  154. #--------------------------------------------------------------------------
  155. def force_move_direction(dx, dy)
  156. return 8 if tileset.force_up.include?(terrain_tag(dx, dy))
  157. return 2 if tileset.force_down.include?(terrain_tag(dx, dy))
  158. return 4 if tileset.force_left.include?(terrain_tag(dx, dy))
  159. return 6 if tileset.force_right.include?(terrain_tag(dx, dy))
  160. end
  161. end # Game_Map
  162. #==============================================================================
  163. # Game_CharacterBase
  164. #==============================================================================
  165. class Game_CharacterBase
  166. #--------------------------------------------------------------------------
  167. # new method: on_force_move_tile?
  168. #--------------------------------------------------------------------------
  169. def on_force_move_tile?; $game_map.force_move_tile?(@x, @y); end
  170. end # Game_CharacterBase
  171. #==============================================================================
  172. # Game_Player
  173. #==============================================================================
  174. class Game_Player < Game_Character
  175. #--------------------------------------------------------------------------
  176. # alias method: dash?
  177. #--------------------------------------------------------------------------
  178. alias game_player_dash_fmt dash?
  179. def dash?
  180. return false if on_force_move_tile?
  181. return game_player_dash_fmt
  182. end
  183. #--------------------------------------------------------------------------
  184. # alias method: update
  185. #--------------------------------------------------------------------------
  186. alias game_player_update_fmt update
  187. def update
  188. game_player_update_fmt
  189. update_force_move_tile
  190. end
  191. #--------------------------------------------------------------------------
  192. # new method: update_force_move_tile
  193. #--------------------------------------------------------------------------
  194. def update_force_move_tile
  195. return if $game_map.interpreter.running?
  196. return unless on_force_move_tile?
  197. return if moving?
  198. move_forced_direction
  199. end
  200. #--------------------------------------------------------------------------
  201. # new method: move_forced_direction
  202. #--------------------------------------------------------------------------
  203. def move_forced_direction
  204. move_straight($game_map.force_move_direction(@x, @y))
  205. end
  206. end # Game_Player
  207. #==============================================================================
  208. #
  209. # End of File
  210. #
  211. #==============================================================================