Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Name: Dark's Advanced Footstep Effect
- # Author: Nhat Nguyen (Dark Sky)
- # Released on: May 24th 2016
- #-------------------------------------------------------------------------------
- # Version 1.0: Released!
- #-------------------------------------------------------------------------------
- # How to use:
- # Line 21: TERRAIN_TAGS[x] = "se"
- # x : terrain tag bạn set cho tile trong tileset.
- # se: tên file SE khi nhân vật di chuyển.
- #===============================================================================
- module DarkSky
- module DarkStepEffect
- FOOTSTEP_DELAY = 15 #Find it out yourself!
- DISABLE_FOOTPRINT_SWITCH = 15
- DISABLE_FOOTSOUND_SWITCH = 16
- DEFAULT_FOOT_SE = "footstep" #Replace SE when Terrain tag's SE is not found.
- #---------------------------------------------------------------------------
- # Footstep SE // Editable
- #---------------------------------------------------------------------------
- TERRAIN_TAGS = {}
- TERRAIN_TAGS[2] = "footstep"
- TERRAIN_TAGS[3] = "Movea"
- end
- end
- include DarkSky::DarkStepEffect
- class Spriteset_Map
- # <Aliasing Method>
- alias_methods = ["initialize","update","dispose"]
- alias_methods.each do |method|
- eval("alias dark_footstep_effect_#{method} #{method}")
- end
- # </Aliasing Method>
- #-----------------------------------------------------------------------------
- # * Initialize
- #-----------------------------------------------------------------------------
- def initialize
- @footprints_sprites = []
- @footdelay = FOOTSTEP_DELAY
- dark_footstep_effect_initialize
- end
- #-----------------------------------------------------------------------------
- # * Update
- #-----------------------------------------------------------------------------
- def update
- dark_footstep_effect_update
- $game_map.events.values.each do |event|
- break if $game_switches[DISABLE_FOOTPRINT_SWITCH] && $game_switches[DISABLE_FOOTSOUND_SWITCH]
- if event.footprint == true
- if event.moving?
- if event.footdelay == 0
- distance = event.distance_x_from($game_player.x) + event.distance_y_from($game_player.y)
- distance = 20 - distance.abs.to_f
- distance /= 20
- if !$game_switches[DISABLE_FOOTSOUND_SWITCH]
- begin
- RPG::SE.new("#{TERRAIN_TAGS[event.footterrain]}",100*distance.abs).play
- rescue
- RPG::SE.new(DEFAULT_FOOT_SE,100*distance.abs).play
- end
- end
- if !$game_switches[DISABLE_FOOTPRINT_SWITCH]
- @footprints_sprites.push(Sprite_Footprints.new(event.real_x*32,event.real_y*32,@viewport1,event))
- end
- event.footdelay = FOOTSTEP_DELAY
- else
- event.footdelay -= 1
- end
- else
- event.footdelay = 0
- end
- end
- end
- if TERRAIN_TAGS.has_key?($game_map.terrain_tag($game_player.real_x,$game_player.real_y))
- if $game_player.moving?
- if @footdelay == 0
- if !$game_switches[DISABLE_FOOTSOUND_SWITCH]
- begin
- RPG::SE.new("#{TERRAIN_TAGS[$game_map.terrain_tag($game_player.real_x,$game_player.real_y)]}",100).play
- rescue
- RPG::SE.new(DEFAULT_FOOT_SE,100).play
- end
- end
- if !$game_switches[DISABLE_FOOTPRINT_SWITCH]
- @footprints_sprites.push(Sprite_Footprints.new($game_player.real_x*32,$game_player.real_y*32,@viewport1,$game_player))
- end
- @footdelay = FOOTSTEP_DELAY
- else
- @footdelay -= 1
- end
- else
- @footdelay = 0
- end
- end
- @footprints_sprites.each do |sprite|
- sprite.update
- end
- end
- #-----------------------------------------------------------------------------
- # * Dispose
- #-----------------------------------------------------------------------------
- def dispose
- dark_footstep_effect_dispose
- end
- end
- #==============================================================================
- # ** Game_Event
- #------------------------------------------------------------------------------
- # This class handles events. Functions include event page switching via
- # condition determinants and running parallel process events. Used within the
- # Game_Map class.
- #==============================================================================
- include DarkSky::DarkStepEffect
- class Game_Event < Game_Character
- # <Aliasing Method>
- alias dark_foot_effect_event_init initialize
- alias dark_foot_effect_event_update update
- # </Aliasing Method>
- attr_reader :footprint
- attr_accessor :footdelay
- attr_reader :footterrain
- #--------------------------------------------------------------------------
- # * Object Initialization
- # event: RPG::Event
- #--------------------------------------------------------------------------
- def initialize(map_id, event)
- dark_foot_effect_event_init(map_id, event)
- @footprint = false
- @footterrain = nil
- @footdelay = FOOTSTEP_DELAY
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- dark_foot_effect_event_update
- if TERRAIN_TAGS.has_key?($game_map.terrain_tag(self.real_x,self.real_y))
- @footprint = true
- @footterrain = $game_map.terrain_tag(self.real_x,self.real_y)
- else
- @footprint = false
- @footterrain = nil
- end
- end
- end
- class Sprite_Footprints < Sprite
- def initialize(x,y,viewport,character)
- super(viewport)
- @character = character
- self.bitmap = Cache.character("$Footprints")
- self.x = x
- self.y = y
- self.z = 999
- @ch = @cw = 32
- update_src_rect
- end
- def update
- super
- if self.opacity > 0
- self.opacity -= 3
- end
- update_fixed
- end
- def update_fixed
- self.ox = $game_map.display_x*32
- self.oy = $game_map.display_y*32
- end
- def dispose
- super
- end
- def update_src_rect
- index = @character.character_index
- pattern = @character.pattern < 3 ? @character.pattern : 1
- sx = (index % 4 * 3 + pattern) * @cw
- sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
- self.src_rect.set(sx, sy, @cw, @ch)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment