#[url=home.php?mod=space&uid=104764]@nova[/url]
class Game_Interpreter
def trigger_radar #事件中插入此脚本触发探测器
Sprite_DetectSign::init
dEvs = $game_map.events.values.select {|e| e.detectable}
@nova = Sprite_RadarNova.new(dEvs)
update_animations until @nova.anime_end?
@nova.dispose
@nova = nil
update_detect until Sprite_DetectSign::not_busy?
end
def update_animations
@nova.update
update_detect
end
def update_detect
Sprite_DetectSign::update
Fiber.yield
end
def terminate_rada
@nova.dispose if @nova
Sprite_DetectSign::dispose
end
end
#-
class Game_Event
attr_reader :detectable
alias_method :detected_setup_page_20131018, :setup_page
def setup_page(p)
detected_setup_page_20131018(p)
detected_object_judge
end
def detected_object_judge
@detectable = nil ;
@list.each {|cmd| break if detected_scan_list(cmd)} unless empty?
end
def detected_scan_list(cmd)
return false unless cmd.code == 108 || cmd.code == 408
return @detectable = cmd.parameters[0].include?("可探测")
end
end
#-
class Sprite_RadarNova < Sprite
def radar_radius; 200 end #雷达探测半径
def anime_end?
zoom_x * width >= radar_radius * 2
end
def initialize(dEvs, vp=nil)
super(vp)
self.z = 300
self.bitmap = Cache.system('RadarNova')
self.ox = width / 2
self.oy = height / 2
self.zoom_x = 0
self.zoom_y = 0
setup_detectable_events(dEvs)
@map_x = $game_player.real_x
@map_y = $game_player.real_y
update
end
#
def setup_detectable_events(dEvs)
@dEvs_R = {}
dEvs.each {|e|
er = radius_from_player(e)
@dEvs_R[e] = er if er <= radar_radius
}
end
def radius_from_player(e)
(($game_player.real_x-e.real_x)**2+($game_player.real_y-e.real_y)**2)**0.5
end
def update
self.x = $game_map.adjust_x(@map_x) * 32 + 16
self.y = $game_map.adjust_y(@map_y) * 32 + 16
update_detect
end
def update_detect
r = zoom_x + 0.025 #修改放大公式
self.zoom_x = r
self.zoom_y = r
r *= width / 64.0
trgEvs = []
@dEvs_R.each {|e, er|
next if r <= er
trgEvs.push(e)
Sprite_DetectSign.new(e.real_x, e.real_y)
Audio.se_play('Audio/SE/ice1') #修改探测音效
}
trgEvs.each {|e| @dEvs_R.delete(e)} unless trgEvs.empty?
end
end
#-
class Sprite_DetectSign < Sprite
#探测到事件动画参考 Graphics\System 内 DetectSign
def anime_rate; 9 end #设置帧切换间隔
def anime_frames; 4 end #动画帧数
def anime_width; 32 end #单帧宽度
def anime_height; 32 end #单帧高度
def initialize(x, y, vp=nil)
super(vp)
@map_x = x
@map_y = y
self.z = 300
self.bitmap = Cache.system('DetectSign')
self.ox = anime_width / 2
self.oy = anime_height / 2
@count = 0
src_rect.set(0, 0, anime_width, anime_height)
@@animations.push(self)
update
end
def update
self.x = $game_map.adjust_x(@map_x) * 32 + 16
self.y = $game_map.adjust_y(@map_y) * 32 + 16
@count += 1
return if @count % anime_rate != 0
src_rect.x += anime_width
anime_end if src_rect.x == anime_frames * anime_width
end
def anime_end
dispose
@@ended_animations.push(self)
end
end
#
class << Sprite_DetectSign
def init
@@animations = []
@@ended_animations = []
end
#
def update
@@animations.each {|anime| anime.update}
return if @@ended_animations.empty?
@@animations -= @@ended_animations
@@ended_animations.clear
end
def dispose
@@animations.each {|anime| anime.dispose}
@@animations.clear
@@ended_animations.clear
end
def not_busy?
@@animations.empty?
end
end
class Game_CommonEvent
def refresh
if active?
@interpreter ||= Game_Interpreter.new
elsif @interpreter
@interpreter.terminate_rada
@interpreter = nil
end
end
end