irpg Community
เชื่อมต่อแผนที่ (ไว้ทำแผนที่โลก) - Printable Version

+- irpg Community (https://irpg.in.th)
+-- Forum: irpg Fabella RPG Maker Academia (https://irpg.in.th/forum-4.html)
+--- Forum: RGSS and JS Showcase (https://irpg.in.th/forum-26.html)
+--- Thread: เชื่อมต่อแผนที่ (ไว้ทำแผนที่โลก) (/thread-1995.html)



เชื่อมต่อแผนที่ (ไว้ทำแผนที่โลก) - Nazuth - 07-04-2014

วิธีใช้
ให้ก็อปสคริปท์นี้ไปวางไว้ใต้ main สำหรับแม็พที่อยากให้เชื่อมต่อกันให้ใส่คำว่า _wrap ไว้หลังชื่อแม็พเช่น Town_wrap

Code:
#==============================================================================
# ? Wrap_Map V1.1
#------------------------------------------------------------------------------
# ?By Dirtie.
# Allows chosen map(s) to "wrap-around", ie. go continuously.
# Just add "_wrap" to the end of the map name for the map you want to be wrapped.
# Many thanks to Dubealex for helping me out, Deke for the map checker script, and to everyone else that contributed.
#============================================================================== #--------------------------------------------------------------------------
#  CLASS Game_Temp
# Script to check for "_wrap" in the map name
# This is taken and modified from Deke's Day/Night and Time System script
# (and therefore may not be compatible with it)
#--------------------------------------------------------------------------
class Game_Temp
attr_reader :map_infos
attr_reader :outside_array
alias wrap_check_original_initialize initialize
def initialize
wrap_check_original_initialize
@map_infos = load_data("Data/MapInfos.rxdata")
@outside_array=Array.new
for key in @map_infos.keys
@outside_array[key]=@map_infos[key].name.include?("_wrap")
end
for key in @map_infos.keys
@map_infos[key] = @map_infos[key].name
@map_infos[key].delete!("_wrap")
end
end
end
#--------------------------------------------------------------------------
#  CLASS Game_Map
# Makes sure screen keeps scrolling near edges of map
# Checks to see if "_wrap" is in the map name
# If not, uses default scrolling options for respective edge of map
# If it is, tells viewport to keep scrolling in the respective direction when actor is near an edge of map
#--------------------------------------------------------------------------
class Game_Map
# Left
def scroll_left(distance)
unless $game_temp.outside_array[$game_map.map_id]
@display_x = [@display_x - distance, 0].max
else
@display_x = [@display_x - distance].max
end
end
# Right
def scroll_right(distance)
unless $game_temp.outside_array[$game_map.map_id]
@display_x = [@display_x + distance, (self.width - 20) * 128].min
else
@display_x = [@display_x + distance].min
end
end
# Top
def scroll_up(distance)
unless $game_temp.outside_array[$game_map.map_id]
@display_y = [@display_y - distance, 0].max
else
@display_y = [@display_y - distance].max
end
end
# Bottom
def scroll_down(distance)
unless $game_temp.outside_array[$game_map.map_id]
@display_y = [@display_y + distance, (self.height - 15) * 128].min
else
@display_y = [@display_y + distance].min
end
end
end
#--------------------------------------------------------------------------
#  CLASS Game_Player
# Makes sure viewport stays centered on player, particularly when teleporting near edges
#--------------------------------------------------------------------------
class Game_Player
def center(x, y)
unless $game_temp.outside_array[$game_map.map_id]
max_x = ($game_map.width - 20) * 128
max_y = ($game_map.height - 15) * 128
$game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
$game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
else
max_x = ($game_map.width + 20) * 128
max_y = ($game_map.height + 15) * 128
$game_map.display_x = [-20 * 128, [x * 128 - CENTER_X, max_x].min].max
$game_map.display_y = [-15 * 128, [y * 128 - CENTER_Y, max_y].min].max
end
end
end
#--------------------------------------------------------------------------
#  CLASS Check_Coordinates
# Checks for coordinates and keyboard input, then teleports if conditions are met
#--------------------------------------------------------------------------
class Check_Coordinates
#------------------------------------------------------------------------
# ? Handles left edge
#------------------------------------------------------------------------
def refresh_left
unless $game_temp.outside_array[$game_map.map_id]
else
if $game_player.real_x == 0
if Input.press?(Input::LEFT)
def $game_player.passable?(x, y, d)
return true
end
@left_trigger = true
end
end
end
end
#------------------------------------------------------------------------
# ? Handles right edge
#------------------------------------------------------------------------
def refresh_right
unless $game_temp.outside_array[$game_map.map_id]
else
@map_width_max = ($game_map.width - 1) * 128
if $game_player.real_x == @map_width_max
if Input.press?(Input::RIGHT)
def $game_player.passable?(x, y, d)
return true
end
@right_trigger = true
end
end
end
end
#------------------------------------------------------------------------
# ? Handles top edge
#------------------------------------------------------------------------
def refresh_top
unless $game_temp.outside_array[$game_map.map_id]
else
if $game_player.real_y == 0
if Input.press?(Input::UP)
def $game_player.passable?(x, y, d)
return true
end
@top_trigger = true
end
end
end
end
#------------------------------------------------------------------------
# ? Handles bottom edge
#------------------------------------------------------------------------
def refresh_bottom
unless $game_temp.outside_array[$game_map.map_id]
else
@map_height_max = ($game_map.height - 1) * 128
if $game_player.real_y == @map_height_max
if Input.press?(Input::DOWN)
def $game_player.passable?(x, y, d)
return true
end
@bottom_trigger = true
end
end
end
end
#------------------------------------------------------------------------
# ? Left teleport
#------------------------------------------------------------------------
def left_trigger
if @left_trigger == true
if $game_player.real_x == -128
$game_player.moveto(($game_map.width - 1), $game_player.y)
def $game_player.passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
unless $game_map.valid?(new_x, new_y)
return false
end
if $DEBUG and Input.press?(Input::CTRL)
return true
end
super
end
@left_trigger = false
end
end
end
#------------------------------------------------------------------------
# ? Right teleport
#------------------------------------------------------------------------
def right_trigger
if @right_trigger == true
if $game_player.real_x == ($game_map.width * 128)
$game_player.moveto(0, $game_player.y)
def $game_player.passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
unless $game_map.valid?(new_x, new_y)
return false
end
if $DEBUG and Input.press?(Input::CTRL)
return true
end
super
end
@right_trigger = false
end
end
end
#------------------------------------------------------------------------
# ? Top teleport
#------------------------------------------------------------------------
def top_trigger
if @top_trigger == true
if $game_player.real_y == -128
$game_player.moveto($game_player.x, ($game_map.height - 1))
def $game_player.passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
unless $game_map.valid?(new_x, new_y)
return false
end
if $DEBUG and Input.press?(Input::CTRL)
return true
end
super
end
@top_trigger = false
end
end
end
#------------------------------------------------------------------------
# ? Bottom teleport
#------------------------------------------------------------------------
def bottom_trigger
if @bottom_trigger == true
if $game_player.real_y == ($game_map.height * 128)
$game_player.moveto($game_player.x, 0)
def $game_player.passable?(x, y, d)
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
unless $game_map.valid?(new_x, new_y)
return false
end
if $DEBUG and Input.press?(Input::CTRL)
return true
end
super
end
@bottom_trigger = false
end
end
end
end
#--------------------------------------------------------------------------
#  CLASS Scene Map
# Initiates a loop for the methods of the Check_Coordinates class
#--------------------------------------------------------------------------
class Scene_Map
$coord_check = Check_Coordinates.new
alias wrap_map_original_update update
def update
wrap_map_original_update
$coord_check.refresh_left
$coord_check.refresh_right
$coord_check.refresh_top
$coord_check.refresh_bottom
$coord_check.left_trigger
$coord_check.right_trigger
$coord_check.top_trigger
$coord_check.bottom_trigger
end
end