#=============================================================================== # Name: Dark's Dowsing Machine (Pokemon) # Author: Nhat Nguyen (Dark Sky) # Released on: May 31st 2016 #------------------------------------------------------------------------------- # Version 1.0: Released! #------------------------------------------------------------------------------- # Plug and play! #------------------------------------------------------------------------------- # Event's Comment Tag: #=============================================================================== module DarkCreation module HiddenObjects ACTIVE_RANGE = 5 #Find it out yourself! ACTIVE_SWITCH = 15 #Set this switch to true to activate the machine WIN_X = 32*6 WIN_Y = 32*7 TOKEN = //i #Just leave it alone! end end include DarkCreation::HiddenObjects class Spriteset_Map #-------------------------------------------------------------------------- # * Aliasing Methods #-------------------------------------------------------------------------- alias d1init initialize alias d1upd update alias d1dis dispose #-------------------------------------------------------------------------- # * Initialize #-------------------------------------------------------------------------- def initialize init_hidden_objects @dowsing_machine = Window_DowsingMachine.new(WIN_X,WIN_Y) @dowsing_machine.targets = @_hidden_objects d1init end #-------------------------------------------------------------------------- # * Initialize Hidden Objects #-------------------------------------------------------------------------- def init_hidden_objects @_hidden_objects ||= [] @_hidden_objects.clear $game_map.events.values.each do |event| next if event.list.nil? event.list.each do |command| next if command.code != 108 if command.parameters[0] =~ TOKEN @_hidden_objects.push(event) end end end end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update d1upd if $game_switches[ACTIVE_SWITCH] @dowsing_machine.update else @dowsing_machine.visible = false if @dowsing_machine.visible == true end end #-------------------------------------------------------------------------- # * Dispose #-------------------------------------------------------------------------- def dispose d1dis @dowsing_machine.dispose end end class Window_DowsingMachine < Window_Base attr_accessor :targets DELAY_TIME = 20 #-------------------------------------------------------------------------- # * Initialize #-------------------------------------------------------------------------- def initialize(x,y) super(x,y,5*32,3*32) self.opacity = 0 @current_tar = nil @viewport = Viewport.new(0,0,Graphics.width,Graphics.height) @viewport.z = 100 self.viewport = @viewport self.back_opacity = 0 self.z = 100 @contents = Sprite.new @contents.bitmap = Bitmap.new(5*32,3*32) @contents.bitmap.fill_rect(0,0,5*32,3*32,Color.new(0,0,0,120)) @contents.viewport = @viewport @contents.z = 50 @contents.x = self.x @contents.y = self.y @bg = Sprite.new @bg.bitmap = Cache.picture("Downsing_BG") @outline = Cache.picture("Downsing_BG2") @bg.bitmap.blt(0,0,@outline,@outline.rect) @bg.viewport = @viewport @bg.z = 60 @bg.x = self.x @bg.y = self.y @sprite_dir = Sprite.new @sprite_dir.bitmap = Cache.picture("D_director") @sprite_dir.viewport = @viewport @sprite_dir.z = 110 @sprite_dir.ox = @sprite_dir.bitmap.width @sprite_dir.oy = @sprite_dir.bitmap.height / 2 @sprite_dir.x = self.x + @contents.bitmap.width / 2 - @sprite_dir.bitmap.width / 2 @sprite_dir.y = self.y + @sprite_dir.bitmap.width @sprite_dir.opacity = 150 @sprite_dir2 = Sprite.new @sprite_dir2.bitmap = Cache.picture("D_director") @sprite_dir2.viewport = @viewport @sprite_dir2.z = 110 @sprite_dir2.ox = @sprite_dir2.bitmap.width @sprite_dir2.oy = @sprite_dir2.bitmap.height / 2 @sprite_dir2.x = self.x + @contents.bitmap.width / 2 + @sprite_dir2.bitmap.width / 2 + 3 @sprite_dir2.y = self.y + @sprite_dir.bitmap.width @sprite_dir2.opacity = 150 @update_delay = DELAY_TIME @target_sound_delay = DELAY_TIME @found_sound_delay = DELAY_TIME normal_pose end #-------------------------------------------------------------------------- # * Set Visibility #-------------------------------------------------------------------------- def visible=(*arg) super(*arg) @sprite_dir.visible = arg[0] @sprite_dir2.visible = arg[0] @contents.visible = arg[0] @bg.visible = arg[0] end #-------------------------------------------------------------------------- # * Arrow Poses #-------------------------------------------------------------------------- def normal_pose @sprite_dir.angle = -45 @sprite_dir2.angle = -135 end def found_pose @sprite_dir.angle = -135 @sprite_dir2.angle = -45 end def up_pose @sprite_dir.angle = -90 @sprite_dir2.angle = -90 end def upl_pose @sprite_dir.angle = -45 @sprite_dir2.angle = -45 end def upr_pose @sprite_dir.angle = -135 @sprite_dir2.angle = -135 end def down_pose @sprite_dir.angle = 90 @sprite_dir2.angle = 90 end def downr_pose @sprite_dir.angle = 135 @sprite_dir2.angle = 135 end def downl_pose @sprite_dir.angle = 45 @sprite_dir2.angle = 45 end def l_pose @sprite_dir.angle = 0 @sprite_dir2.angle = 0 end def r_pose @sprite_dir.angle = 180 @sprite_dir2.angle = 180 end #-------------------------------------------------------------------------- # * Update #-------------------------------------------------------------------------- def update super if @update_delay > 0 @update_delay -= 1 end if @target_sound_delay > 0 @target_sound_delay -= 1 end if @found_sound_delay > 0 @found_sound_delay -= 1 end if @targets && @update_delay == 0 distance_a = [] @targets.each do |tar| next if tar.erased dis = tar.distance_x_from($game_player.x).abs + tar.distance_y_from($game_player.y).abs if dis > ACTIVE_RANGE next else distance_a.push([dis,tar]) end end if distance_a.size > 0 distance_a.sort! {|a,b| a[0] <=> b[0]} @last_tar = @current_target @current_target = distance_a[0][1] if @last_tar != @current_target RPG::SE.new("Decision2",100,120).play @non_target_sound = false end @update_delay = DELAY_TIME else @current_target = nil end end if @current_target if @current_target.distance_x_from($game_player.x) < 0 && @current_target.distance_y_from($game_player.y) == 0 l_pose end if @current_target.distance_x_from($game_player.x) > 0 && @current_target.distance_y_from($game_player.y) == 0 r_pose end if @current_target.distance_y_from($game_player.y) < 0 && @current_target.distance_x_from($game_player.x) == 0 up_pose end if @current_target.distance_y_from($game_player.y) > 0 && @current_target.distance_x_from($game_player.x) == 0 down_pose end if @current_target.distance_y_from($game_player.y) < 0 if @current_target.distance_x_from($game_player.x) > 0 upr_pose elsif @current_target.distance_x_from($game_player.x) < 0 upl_pose end elsif @current_target.distance_y_from($game_player.y) > 0 if @current_target.distance_x_from($game_player.x) > 0 downr_pose elsif @current_target.distance_x_from($game_player.x) < 0 downl_pose end end if @current_target.distance_y_from($game_player.y) == 0 if @current_target.distance_x_from($game_player.x) == 0 if @found_sound_delay == 0 RPG::SE.new("Chime2",70,120).play found_pose @found_sound_delay = DELAY_TIME end end end elsif @current_target == nil normal_pose if @target_sound_delay == 0 && !@non_target_sound RPG::SE.new("Ice1").play @target_sound_delay = DELAY_TIME @non_target_sound = true end end end #End def #-------------------------------------------------------------------------- # * Standard Padding #-------------------------------------------------------------------------- def standard_padding return 2 end #-------------------------------------------------------------------------- # * Dispose #-------------------------------------------------------------------------- def dispose super @contents.bitmap.dispose @contents.dispose @sprite_dir.bitmap.dispose @sprite_dir2.dispose @sprite_dir.dispose @bg.bitmap.dispose @bg.dispose @outline.dispose end end class Game_Event attr_reader :erased end #=============================================================================== # END OF SCRIPT! #===============================================================================