dsiver144

Dark's Footstep Effect

May 24th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.41 KB | None | 0 0
  1. #===============================================================================
  2. # Name: Dark's Advanced Footstep Effect
  3. # Author: Nhat Nguyen (Dark Sky)
  4. # Released on: May 24th 2016
  5. #-------------------------------------------------------------------------------
  6. # Version 1.0: Released!
  7. #-------------------------------------------------------------------------------
  8. # How to use:
  9. # Line 21: TERRAIN_TAGS[x] = "se"
  10. # x : terrain tag bạn set cho tile trong tileset.
  11. # se: tên file SE khi nhân vật di chuyển.
  12. #===============================================================================
  13. module DarkSky
  14. module DarkStepEffect
  15. FOOTSTEP_DELAY = 15 #Find it out yourself!
  16. DISABLE_FOOTPRINT_SWITCH = 15
  17. DISABLE_FOOTSOUND_SWITCH = 16
  18. DEFAULT_FOOT_SE = "footstep" #Replace SE when Terrain tag's SE is not found.
  19. #---------------------------------------------------------------------------
  20. # Footstep SE // Editable
  21. #---------------------------------------------------------------------------
  22. TERRAIN_TAGS = {}
  23. TERRAIN_TAGS[2] = "footstep"
  24. TERRAIN_TAGS[3] = "Movea"
  25. end
  26. end
  27. include DarkSky::DarkStepEffect
  28. class Spriteset_Map
  29. # <Aliasing Method>
  30. alias_methods = ["initialize","update","dispose"]
  31. alias_methods.each do |method|
  32. eval("alias dark_footstep_effect_#{method} #{method}")
  33. end
  34. # </Aliasing Method>
  35. #-----------------------------------------------------------------------------
  36. # * Initialize
  37. #-----------------------------------------------------------------------------
  38. def initialize
  39. @footprints_sprites = []
  40. @footdelay = FOOTSTEP_DELAY
  41. dark_footstep_effect_initialize
  42. end
  43. #-----------------------------------------------------------------------------
  44. # * Update
  45. #-----------------------------------------------------------------------------
  46. def update
  47. dark_footstep_effect_update
  48. $game_map.events.values.each do |event|
  49. break if $game_switches[DISABLE_FOOTPRINT_SWITCH] && $game_switches[DISABLE_FOOTSOUND_SWITCH]
  50. if event.footprint == true
  51. if event.moving?
  52. if event.footdelay == 0
  53. distance = event.distance_x_from($game_player.x) + event.distance_y_from($game_player.y)
  54. distance = 20 - distance.abs.to_f
  55. distance /= 20
  56. if !$game_switches[DISABLE_FOOTSOUND_SWITCH]
  57. begin
  58. RPG::SE.new("#{TERRAIN_TAGS[event.footterrain]}",100*distance.abs).play
  59. rescue
  60. RPG::SE.new(DEFAULT_FOOT_SE,100*distance.abs).play
  61. end
  62. end
  63. if !$game_switches[DISABLE_FOOTPRINT_SWITCH]
  64. @footprints_sprites.push(Sprite_Footprints.new(event.real_x*32,event.real_y*32,@viewport1,event))
  65. end
  66. event.footdelay = FOOTSTEP_DELAY
  67. else
  68. event.footdelay -= 1
  69. end
  70. else
  71. event.footdelay = 0
  72. end
  73. end
  74. end
  75. if TERRAIN_TAGS.has_key?($game_map.terrain_tag($game_player.real_x,$game_player.real_y))
  76. if $game_player.moving?
  77. if @footdelay == 0
  78. if !$game_switches[DISABLE_FOOTSOUND_SWITCH]
  79. begin
  80. RPG::SE.new("#{TERRAIN_TAGS[$game_map.terrain_tag($game_player.real_x,$game_player.real_y)]}",100).play
  81. rescue
  82. RPG::SE.new(DEFAULT_FOOT_SE,100).play
  83. end
  84. end
  85. if !$game_switches[DISABLE_FOOTPRINT_SWITCH]
  86. @footprints_sprites.push(Sprite_Footprints.new($game_player.real_x*32,$game_player.real_y*32,@viewport1,$game_player))
  87. end
  88. @footdelay = FOOTSTEP_DELAY
  89. else
  90. @footdelay -= 1
  91. end
  92. else
  93. @footdelay = 0
  94. end
  95. end
  96. @footprints_sprites.each do |sprite|
  97. sprite.update
  98. end
  99. end
  100. #-----------------------------------------------------------------------------
  101. # * Dispose
  102. #-----------------------------------------------------------------------------
  103. def dispose
  104. dark_footstep_effect_dispose
  105. end
  106. end
  107.  
  108. #==============================================================================
  109. # ** Game_Event
  110. #------------------------------------------------------------------------------
  111. # This class handles events. Functions include event page switching via
  112. # condition determinants and running parallel process events. Used within the
  113. # Game_Map class.
  114. #==============================================================================
  115. include DarkSky::DarkStepEffect
  116. class Game_Event < Game_Character
  117. # <Aliasing Method>
  118. alias dark_foot_effect_event_init initialize
  119. alias dark_foot_effect_event_update update
  120. # </Aliasing Method>
  121. attr_reader :footprint
  122. attr_accessor :footdelay
  123. attr_reader :footterrain
  124. #--------------------------------------------------------------------------
  125. # * Object Initialization
  126. # event: RPG::Event
  127. #--------------------------------------------------------------------------
  128. def initialize(map_id, event)
  129. dark_foot_effect_event_init(map_id, event)
  130. @footprint = false
  131. @footterrain = nil
  132. @footdelay = FOOTSTEP_DELAY
  133. end
  134. #--------------------------------------------------------------------------
  135. # * Frame Update
  136. #--------------------------------------------------------------------------
  137. def update
  138. dark_foot_effect_event_update
  139. if TERRAIN_TAGS.has_key?($game_map.terrain_tag(self.real_x,self.real_y))
  140. @footprint = true
  141. @footterrain = $game_map.terrain_tag(self.real_x,self.real_y)
  142. else
  143. @footprint = false
  144. @footterrain = nil
  145. end
  146. end
  147. end
  148.  
  149. class Sprite_Footprints < Sprite
  150. def initialize(x,y,viewport,character)
  151. super(viewport)
  152. @character = character
  153. self.bitmap = Cache.character("$Footprints")
  154. self.x = x
  155. self.y = y
  156. self.z = 999
  157. @ch = @cw = 32
  158. update_src_rect
  159. end
  160. def update
  161. super
  162. if self.opacity > 0
  163. self.opacity -= 3
  164. end
  165. update_fixed
  166. end
  167. def update_fixed
  168. self.ox = $game_map.display_x*32
  169. self.oy = $game_map.display_y*32
  170. end
  171. def dispose
  172. super
  173. end
  174. def update_src_rect
  175. index = @character.character_index
  176. pattern = @character.pattern < 3 ? @character.pattern : 1
  177. sx = (index % 4 * 3 + pattern) * @cw
  178. sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  179. self.src_rect.set(sx, sy, @cw, @ch)
  180. end
  181. end
Advertisement
Add Comment
Please, Sign In to add comment