#==============================================================================
# Veiw Range Script
#------------------------------------------------------------------------------
# By: Near Fantastica
# Date: 14.06.05
#==============================================================================
class View_Range
#--------------------------------------------------------------------------
# â— Range system works by sereching the area of a circle for the Player's xy
# The Veiw is set in each event and is the radius of the circle
# The Eaquation used is (Px-EX)^2 + (Py-Ey)^2 = radius^2
# If the Radius is less than or equal to the View the Player is inside the circle
#--------------------------------------------------------------------------
def initialize
@playing_bgs = []
@bgs = BGS.new
@bgs.pitch = 100
end
#--------------------------------------------------------------------------
def in_range?(element, object, range)
x = (element.x - object.x) * (element.x - object.x)
y = (element.y - object.y) * (element.y - object.y)
r = x + y
if r <= (range * range)
return true
else
return false
end
end
#--------------------------------------------------------------------------
# Max Sound Effect Range is 8 units DO NOT OVER LAP
# or it will go into super lag mode you have been warned
# This is because you are trying to play 2 different sound
# effects and will cycles between them
#
# Note : This overrides the maps default sound effect
#--------------------------------------------------------------------------
def event_sound(event_id, bgs_name)
event = $game_map.events[event_id]
@bgs.name = bgs_name
radius = ($game_player.x-event.x)*($game_player.x-event.x) + ($game_player.y-event.y)*($game_player.y-event.y)
if radius > 64
if @playing_bgs[event.id] != nil
@playing_bgs[event.id] = nil
$game_system.bgs_fade(1)
return
end
elsif radius <= 64 and radius > 49
if @playing_bgs[event.id] == nil
@bgs.volume = 30
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
end
@bgs.volume = 30
if @bgs.volume != @playing_bgs[event.id].volume or
@bgs.name != @playing_bgs[event.id].name
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
end
elsif radius <= 49 and radius > 36
@bgs.volume = 40
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius <= 36 and radius > 25
@bgs.volume = 50
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius <= 25 and radius > 16
@bgs.volume = 60
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius <= 16 and radius > 9
@bgs.volume = 70
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius <= 9 and radius > 4
@bgs.volume = 80
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius <= 4 and radius > 1
@bgs.volume = 90
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
elsif radius = 1
@bgs.volume = 100
@playing_bgs[event.id] = @bgs
$game_system.bgs_play(@bgs)
return
end
end
#--------------------------------------------------------------------------
def event_view(event_id, view_range, switch_id)
event = $game_map.events[event_id]
if in_range?(event, $game_player, view_range)
$game_switches[switch_id] = true
end
end
#--------------------------------------------------------------------------
def enemies_view(event_id, view_range, switch_id)
event = $game_map.events[event_id]
if event.direction == 2
if $game_player.y >= event.y
if in_range?(event, $game_player, view_range)
$game_switches[switch_id] = true
end
end
end
if event.direction == 4
if $game_player.x <= event.x
if in_range?(event, $game_player, view_range)
$game_switches[switch_id] = true
end
end
end
if event.direction == 6
if $game_player.x >= event.x
if in_range?(event, $game_player, view_range)
$game_switches[switch_id] = true
end
end
end
if event.direction == 8
if $game_player.y <= event.y
if in_range?(event, $game_player, view_range)
$game_switches[switch_id] = true
end
end
end
end
end
#======================================
# â– Scene Title
#======================================
class Scene_Title
#--------------------------------------------------------------------------
alias vr_scene_title_update update
#--------------------------------------------------------------------------
def update
$view_range = View_Range.new
vr_scene_title_update
end
end
#======================================
# â– Scene Load
#======================================
class Scene_Load < Scene_File
#--------------------------------------------------------------------------
alias vr_scene_load_read_save_data read_save_data
#--------------------------------------------------------------------------
def read_save_data(file)
vr_scene_load_read_save_data(file)
$view_range = View_Range.new
end
end
#======================================
# â– Game System
#======================================
class Game_System
attr_accessor :playing_bgs
end
#======================================
# â– Back Ground Sounds
#======================================
class BGS
#--------------------------------------------------------------------------
attr_accessor :name
attr_accessor :volume
attr_accessor :pitch
#--------------------------------------------------------------------------
def initialize
@name
@volume
@pitch
end
end