マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。 このクラスのインスタンスは $game_map で参照されます。

Methods
A
B
C
D
E
H
L
M
N
O
P
R
S
T
U
V
W
X
Y
Attributes
[R] battleback1_name
[R] battleback2_name
[R] display_x
[R] display_y
[R] events
[R] interpreter
[RW] name_display
[RW] need_refresh
[R] parallax_name
[R] screen

公開インスタンス変数

[R] vehicles
Class Public methods
new()

オブジェクト初期化

# File Game_Map.rb, line 26
def initialize
  @screen = Game_Screen.new
  @interpreter = Game_Interpreter.new
  @map_id = 0
  @events = {}
  @display_x = 0
  @display_y = 0
  create_vehicles
  @name_display = true
end
Instance Public methods
adjust_x(x)

表示座標を差し引いた X 座標の計算

# File Game_Map.rb, line 297
def adjust_x(x)
  if loop_horizontal? && x < @display_x - (width - screen_tile_x) / 2
    x - @display_x + @map.width
  else
    x - @display_x
  end
end
adjust_y(y)

表示座標を差し引いた Y 座標の計算

# File Game_Map.rb, line 308
def adjust_y(y)
  if loop_vertical? && y < @display_y - (height - screen_tile_y) / 2
    y - @display_y + @map.height
  else
    y - @display_y
  end
end
airship()

飛行船の取得

# File Game_Map.rb, line 98
def airship
  @vehicles[2]
end
airship_land_ok?(x, y)

飛行船の着陸可能判定

# File Game_Map.rb, line 547
def airship_land_ok?(x, y)
  check_passage(x, y, 0x0800) && check_passage(x, y, 0x0f)
end
all_tiles(x, y)

指定座標にある全てのタイル(イベント含む)を配列で取得

# File Game_Map.rb, line 510
def all_tiles(x, y)
  tile_events_xy(x, y).collect {|ev| ev.tile_id } + layered_tiles(x, y)
end
any_event_starting?()

起動中マップイベントの存在判定

# File Game_Map.rb, line 757
def any_event_starting?
  @events.values.any? {|event| event.starting }
end
autoplay()

BGM / BGS 自動切り替え

# File Game_Map.rb, line 361
def autoplay
  @map.bgm.play if @map.autoplay_bgm
  @map.bgs.play if @map.autoplay_bgs
end
autotile_type(x, y, z)

指定座標にあるオートタイルの種類を取得

# File Game_Map.rb, line 517
def autotile_type(x, y, z)
  tile_id(x, y, z) >= 2048 ? (tile_id(x, y, z) - 2048) / 48 : -1
end
boat()

小型船の取得

# File Game_Map.rb, line 84
def boat
  @vehicles[0]
end
boat_passable?(x, y)

小型船の通行可能判定

# File Game_Map.rb, line 533
def boat_passable?(x, y)
  check_passage(x, y, 0x0200)
end
bush?(x, y)

茂み判定

# File Game_Map.rb, line 568
def bush?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x40)
end
change_battleback(battleback1_name, battleback2_name)

戦闘背景の変更

# File Game_Map.rb, line 703
def change_battleback(battleback1_name, battleback2_name)
  @battleback1_name = battleback1_name
  @battleback2_name = battleback2_name
end
change_parallax(name, loop_x, loop_y, sx, sy)

遠景の変更

# File Game_Map.rb, line 711
def change_parallax(name, loop_x, loop_y, sx, sy)
  @parallax_name = name
  @parallax_x = 0 if @parallax_loop_x && !loop_x
  @parallax_y = 0 if @parallax_loop_y && !loop_y
  @parallax_loop_x = loop_x
  @parallax_loop_y = loop_y
  @parallax_sx = sx
  @parallax_sy = sy
end
change_tileset(tileset_id)

タイルセットの変更

# File Game_Map.rb, line 695
def change_tileset(tileset_id)
  @tileset_id = tileset_id
  refresh
end
check_passage(x, y, bit)

通行チェック

bit : 調べる通行禁止ビット

# File Game_Map.rb, line 483
def check_passage(x, y, bit)
  all_tiles(x, y).each do |tile_id|
    flag = tileset.flags[tile_id]
    next if flag & 0x10 != 0            # [☆] : 通行に影響しない
    return true  if flag & bit == 0     # [○] : 通行可
    return false if flag & bit == bit   # [×] : 通行不可
  end
  return false                          # 通行不可
end
counter?(x, y)

カウンター判定

# File Game_Map.rb, line 575
def counter?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x80)
end
create_vehicles()

乗り物の作成

# File Game_Map.rb, line 57
def create_vehicles
  @vehicles = []
  @vehicles[0] = Game_Vehicle.new(:boat)
  @vehicles[1] = Game_Vehicle.new(:ship)
  @vehicles[2] = Game_Vehicle.new(:airship)
end
damage_floor?(x, y)

ダメージ床判定

# File Game_Map.rb, line 582
def damage_floor?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x100)
end
data()

マップデータの取得

# File Game_Map.rb, line 269
def data
  @map.data
end
disable_dash?()

ダッシュ禁止か否かの取得

# File Game_Map.rb, line 248
def disable_dash?
  @map.disable_dashing
end
display_name()

表示名の取得

# File Game_Map.rb, line 213
def display_name
  @map.display_name
end
do_scroll(direction, distance)

スクロールの実行

# File Game_Map.rb, line 660
def do_scroll(direction, distance)
  case direction
  when 2;  scroll_down (distance)
  when 4;  scroll_left (distance)
  when 6;  scroll_right(distance)
  when 8;  scroll_up   (distance)
  end
end
encounter_list()

エンカウントリストの取得

# File Game_Map.rb, line 255
def encounter_list
  @map.encounter_list
end
encounter_step()

エンカウント歩数の取得

# File Game_Map.rb, line 262
def encounter_step
  @map.encounter_step
end
event_id_xy(x, y)

指定座標に存在するイベントの ID 取得(一つのみ)

# File Game_Map.rb, line 407
def event_id_xy(x, y)
  list = events_xy(x, y)
  list.empty? ? 0 : list[0].id
end
events_xy(x, y)

指定座標に存在するイベントの配列取得

# File Game_Map.rb, line 386
def events_xy(x, y)
  @events.values.select {|event| event.pos?(x, y) }
end
events_xy_nt(x, y)

指定座標に存在するイベント(すり抜け以外)の配列取得

# File Game_Map.rb, line 393
def events_xy_nt(x, y)
  @events.values.select {|event| event.pos_nt?(x, y) }
end
height()

高さの取得

# File Game_Map.rb, line 227
def height
  @map.height
end
ladder?(x, y)

梯子判定

# File Game_Map.rb, line 561
def ladder?(x, y)
  valid?(x, y) && layered_tiles_flag?(x, y, 0x20)
end
layered_tiles(x, y)

指定座標にある全レイヤーのタイル(上から順)を配列で取得

# File Game_Map.rb, line 503
def layered_tiles(x, y)
  [2, 1, 0].collect {|z| tile_id(x, y, z) }
end
layered_tiles_flag?(x, y, bit)

指定座標の全レイヤーのフラグ判定

# File Game_Map.rb, line 554
def layered_tiles_flag?(x, y, bit)
  layered_tiles(x, y).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }
end
loop_horizontal?()

横方向にループするか?

# File Game_Map.rb, line 234
def loop_horizontal?
  @map.scroll_type == 2 || @map.scroll_type == 3
end
loop_vertical?()

縦方向にループするか?

# File Game_Map.rb, line 241
def loop_vertical?
  @map.scroll_type == 1 || @map.scroll_type == 3
end
map_id()

マップ ID の取得

# File Game_Map.rb, line 199
def map_id
  @map_id
end
overworld?()

フィールドタイプか否か

# File Game_Map.rb, line 276
def overworld?
  tileset.mode == 0
end
parallax_ox(bitmap)

遠景表示の原点 X 座標の計算

# File Game_Map.rb, line 173
def parallax_ox(bitmap)
  if @parallax_loop_x
    @parallax_x * 16
  else
    w1 = [bitmap.width - Graphics.width, 0].max
    w2 = [width * 32 - Graphics.width, 1].max
    @parallax_x * 16 * w1 / w2
  end
end
parallax_oy(bitmap)

遠景表示の原点 Y 座標の計算

# File Game_Map.rb, line 186
def parallax_oy(bitmap)
  if @parallax_loop_y
    @parallax_y * 16
  else
    h1 = [bitmap.height - Graphics.height, 0].max
    h2 = [height * 32 - Graphics.height, 1].max
    @parallax_y * 16 * h1 / h2
  end
end
parallel_common_events()

並列処理コモンイベントの配列を取得

# File Game_Map.rb, line 119
def parallel_common_events
  $data_common_events.select {|event| event && event.parallel? }
end
passable?(x, y, d)

通常キャラの通行可能判定

d : 方向(2,4,6,8) 指定された座標のタイルが指定方向に通行可能かを判定する。

# File Game_Map.rb, line 526
def passable?(x, y, d)
  check_passage(x, y, (1 << (d / 2 - 1)) & 0x0f)
end
referesh_vehicles()

乗り物のリフレッシュ

# File Game_Map.rb, line 67
def referesh_vehicles
  @vehicles.each {|vehicle| vehicle.refresh }
end
refresh()

リフレッシュ

# File Game_Map.rb, line 369
def refresh
  @events.each_value {|event| event.refresh }
  @common_events.each {|event| event.refresh }
  refresh_tile_events
  @need_refresh = false
end
refresh_tile_events()

タイル扱いイベントの配列をリフレッシュ

# File Game_Map.rb, line 379
def refresh_tile_events
  @tile_events = @events.values.select {|event| event.tile? }
end
region_id(x, y)

リージョン ID の取得

# File Game_Map.rb, line 601
def region_id(x, y)
  valid?(x, y) ? @map.data[x, y, 3] >> 8 : 0
end
round_x(x)

ループ補正後の X 座標計算

# File Game_Map.rb, line 319
def round_x(x)
  loop_horizontal? ? (x + width) % width : x
end
round_x_with_direction(x, d)

特定の方向に 1 マスずらした X 座標の計算(ループ補正あり)

# File Game_Map.rb, line 347
def round_x_with_direction(x, d)
  round_x(x + (d == 6 ? 1 : d == 4 ? -1 : 0))
end
round_y(y)

ループ補正後の Y 座標計算

# File Game_Map.rb, line 326
def round_y(y)
  loop_vertical? ? (y + height) % height : y
end
round_y_with_direction(y, d)

特定の方向に 1 マスずらした Y 座標の計算(ループ補正あり)

# File Game_Map.rb, line 354
def round_y_with_direction(y, d)
  round_y(y + (d == 2 ? 1 : d == 8 ? -1 : 0))
end
screen_tile_x()

画面の横タイル数

# File Game_Map.rb, line 283
def screen_tile_x
  Graphics.width / 32
end
screen_tile_y()

画面の縦タイル数

# File Game_Map.rb, line 290
def screen_tile_y
  Graphics.height / 32
end
scroll_distance()

スクロール距離の計算

# File Game_Map.rb, line 653
def scroll_distance
  2 ** @scroll_speed / 256.0
end
scroll_down(distance)

下にスクロール

# File Game_Map.rb, line 415
def scroll_down(distance)
  if loop_vertical?
    @display_y += distance
    @display_y = @map.height
    @parallax_y += distance if @parallax_loop_y
  else
    last_y = @display_y
    @display_y = [@display_y + distance, height - screen_tile_y].min
    @parallax_y += @display_y - last_y
  end
end
scroll_left(distance)

左にスクロール

# File Game_Map.rb, line 430
def scroll_left(distance)
  if loop_horizontal?
    @display_x += @map.width - distance
    @display_x = @map.width 
    @parallax_x -= distance if @parallax_loop_x
  else
    last_x = @display_x
    @display_x = [@display_x - distance, 0].max
    @parallax_x += @display_x - last_x
  end
end
scroll_right(distance)

右にスクロール

# File Game_Map.rb, line 445
def scroll_right(distance)
  if loop_horizontal?
    @display_x += distance
    @display_x = @map.width
    @parallax_x += distance if @parallax_loop_x
  else
    last_x = @display_x
    @display_x = [@display_x + distance, (width - screen_tile_x)].min
    @parallax_x += @display_x - last_x
  end
end
scroll_up(distance)

上にスクロール

# File Game_Map.rb, line 460
def scroll_up(distance)
  if loop_vertical?
    @display_y += @map.height - distance
    @display_y = @map.height
    @parallax_y -= distance if @parallax_loop_y
  else
    last_y = @display_y
    @display_y = [@display_y - distance, 0].max
    @parallax_y += @display_y - last_y
  end
end
scrolling?()

スクロール中判定

# File Game_Map.rb, line 617
def scrolling?
  @scroll_rest > 0
end
set_display_pos(x, y)

表示位置の設定

# File Game_Map.rb, line 161
def set_display_pos(x, y)
  x = [0, [x, width - screen_tile_x].min].max unless loop_horizontal?
  y = [0, [y, height - screen_tile_y].min].max unless loop_vertical?
  @display_x = (x + width) % width
  @display_y = (y + height) % height
  @parallax_x = x
  @parallax_y = y
end
setup(map_id)

セットアップ

# File Game_Map.rb, line 40
def setup(map_id)
  @map_id = map_id
  @map = load_data(sprintf("Data/Map%03d.rvdata2", @map_id))
  @tileset_id = @map.tileset_id
  @display_x = 0
  @display_y = 0
  referesh_vehicles
  setup_events
  setup_scroll
  setup_parallax
  setup_battleback
  @need_refresh = false
end
setup_autorun_common_event()

自動実行のコモンイベントを検出/セットアップ

# File Game_Map.rb, line 774
def setup_autorun_common_event
  event = $data_common_events.find do |event|
    event && event.autorun? && $game_switches[event.switch_id]
  end
  @interpreter.setup(event.list) if event
  event
end
setup_battleback()

戦闘背景のセットアップ

# File Game_Map.rb, line 148
def setup_battleback
  if @map.specify_battleback
    @battleback1_name = @map.battleback1_name
    @battleback2_name = @map.battleback2_name
  else
    @battleback1_name = nil
    @battleback2_name = nil
  end
end
setup_events()

イベントのセットアップ

# File Game_Map.rb, line 105
def setup_events
  @events = {}
  @map.events.each do |i, event|
    @events[i] = Game_Event.new(@map_id, event)
  end
  @common_events = parallel_common_events.collect do |common_event|
    Game_CommonEvent.new(common_event.id)
  end
  refresh_tile_events
end
setup_parallax()

遠景のセットアップ

# File Game_Map.rb, line 135
def setup_parallax
  @parallax_name = @map.parallax_name
  @parallax_loop_x = @map.parallax_loop_x
  @parallax_loop_y = @map.parallax_loop_y
  @parallax_sx = @map.parallax_sx
  @parallax_sy = @map.parallax_sy
  @parallax_x = 0
  @parallax_y = 0
end
setup_scroll()

スクロールのセットアップ

# File Game_Map.rb, line 126
def setup_scroll
  @scroll_direction = 2
  @scroll_rest = 0
  @scroll_speed = 4
end
setup_starting_event()

起動中イベントのセットアップ

# File Game_Map.rb, line 746
def setup_starting_event
  refresh if @need_refresh
  return true if @interpreter.setup_reserved_common_event
  return true if setup_starting_map_event
  return true if setup_autorun_common_event
  return false
end
setup_starting_map_event()

起動中のマップイベントを検出/セットアップ

# File Game_Map.rb, line 764
def setup_starting_map_event
  event = @events.values.find {|event| event.starting }
  event.clear_starting_flag if event
  @interpreter.setup(event.list, event.id) if event
  event
end
ship()

大型船の取得

# File Game_Map.rb, line 91
def ship
  @vehicles[1]
end
ship_passable?(x, y)

大型船の通行可能判定

# File Game_Map.rb, line 540
def ship_passable?(x, y)
  check_passage(x, y, 0x0400)
end
start_scroll(direction, distance, speed)

スクロールの開始

# File Game_Map.rb, line 608
def start_scroll(direction, distance, speed)
  @scroll_direction = direction
  @scroll_rest = distance
  @scroll_speed = speed
end
terrain_tag(x, y)

地形タグの取得

# File Game_Map.rb, line 589
def terrain_tag(x, y)
  return 0 unless valid?(x, y)
  layered_tiles(x, y).each do |tile_id|
    tag = tileset.flags[tile_id] >> 12
    return tag if tag > 0
  end
  return 0
end
tile_events_xy(x, y)

指定座標に存在するタイル扱いイベント(すり抜け以外)の配列取得

# File Game_Map.rb, line 400
def tile_events_xy(x, y)
  @tile_events.select {|event| event.pos_nt?(x, y) }
end
tile_id(x, y, z)

指定座標にあるタイル ID の取得

# File Game_Map.rb, line 496
def tile_id(x, y, z)
  @map.data[x, y, z] || 0
end
tileset()

タイルセットの取得

# File Game_Map.rb, line 206
def tileset
  $data_tilesets[@tileset_id]
end
unlock_event(event_id)

イベントのロック解除

# File Game_Map.rb, line 739
def unlock_event(event_id)
  @events[event_id].unlock if @events[event_id]
end
update(main = false)

フレーム更新

main : インタプリタ更新フラグ

# File Game_Map.rb, line 625
def update(main = false)
  refresh if @need_refresh
  update_interpreter if main
  update_scroll
  update_events
  update_vehicles
  update_parallax
  @screen.update
end
update_events()

イベントの更新

# File Game_Map.rb, line 672
def update_events
  @events.each_value {|event| event.update }
  @common_events.each {|event| event.update }
end
update_interpreter()

インタプリタの更新

# File Game_Map.rb, line 724
def update_interpreter
  loop do
    @interpreter.update
    return if @interpreter.running?
    if @interpreter.event_id > 0
      unlock_event(@interpreter.event_id)
      @interpreter.clear
    end
    return unless setup_starting_event
  end
end
update_parallax()

遠景の更新

# File Game_Map.rb, line 687
def update_parallax
  @parallax_x += @parallax_sx / 64.0 if @parallax_loop_x
  @parallax_y += @parallax_sy / 64.0 if @parallax_loop_y
end
update_scroll()

スクロールの更新

# File Game_Map.rb, line 638
def update_scroll
  return unless scrolling?
  last_x = @display_x
  last_y = @display_y
  do_scroll(@scroll_direction, scroll_distance)
  if @display_x == last_x && @display_y == last_y
    @scroll_rest = 0
  else
    @scroll_rest -= scroll_distance
  end
end
update_vehicles()

乗り物の更新

# File Game_Map.rb, line 680
def update_vehicles
  @vehicles.each {|vehicle| vehicle.update }
end
valid?(x, y)

有効座標判定

# File Game_Map.rb, line 475
def valid?(x, y)
  x >= 0 && x < width && y >= 0 && y < height
end
vehicle(type)

乗り物の取得

# File Game_Map.rb, line 74
def vehicle(type)
  return @vehicles[0] if type == :boat
  return @vehicles[1] if type == :ship
  return @vehicles[2] if type == :airship
  return nil
end
width()

幅の取得

# File Game_Map.rb, line 220
def width
  @map.width
end
x_with_direction(x, d)

特定の方向に 1 マスずらした X 座標の計算(ループ補正なし)

# File Game_Map.rb, line 333
def x_with_direction(x, d)
  x + (d == 6 ? 1 : d == 4 ? -1 : 0)
end
y_with_direction(y, d)

特定の方向に 1 マスずらした Y 座標の計算(ループ補正なし)

# File Game_Map.rb, line 340
def y_with_direction(y, d)
  y + (d == 2 ? 1 : d == 8 ? -1 : 0)
end