=begin ▼ 簡易マップ表示 マッピング ver. 1.3 RPGツクールVXAce用スクリプト 制作 : 木星ペンギン URL : http://woodpenguin.blog.fc2.com/ ------------------------------------------------------------------------------ 概要 □ 近くを通ったことのある範囲のみ、マップに標示します。 ------------------------------------------------------------------------------ イベントコマンド □ イベントコマンドのスクリプトで、以下の機能が使えます。 $game_map.mapping(X, Y, R) => 現在のマップの座標(X, Y)を中心に、半径 R マスのマッピングを行います。 $game_map.map_open(マップID) $game_map.map_close(マップID) => 指定したマップの簡易マップをマッピング中の画像にするかどうか。 map_open で通常のマップ画像になります。 map_close でマッピング中の画像になります。(デフォルト) ※ 画像が切り替わるだけで、内部ではマッピングを行っています。 $game_map.event_open(マップID) $game_map.event_close(マップID) => 指定したマップでマッピングした範囲のみマーカーを標示するかどうか。 event_open で全てのマーカーが標示されます。 event_close でマッピング範囲内のマーカーのみ標示します。(デフォルト) ※ 上記のマップ画像の切り替えでは標示範囲は変わりません。 $game_map.clear_mapping(マップID) => 指定したマップのマッピング情報を初期化します。 =end module WdTk::SimpMap::OP1 #-------------------------------------------------------------------------- # ● マッピング半径を設定する変数 ID # 変数に 0 を代入すると、マッピングを行いません。 #-------------------------------------------------------------------------- RadiusID = 2 #-------------------------------------------------------------------------- # ● マッピングしていない範囲の色 #-------------------------------------------------------------------------- UndvColor = Color.new(0, 0, 0, 96) end #////////////////////////////////////////////////////////////////////////////// # # 以降、変更する必要なし # #////////////////////////////////////////////////////////////////////////////// module WdTk @material << :SimpMap_OP1 end #============================================================================== # ■ Game_Map #============================================================================== class Game_Map #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :mapping_data attr_reader :draw_pos #-------------------------------------------------------------------------- # ○ セットアップ #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_setup setup def setup(map_id) _wdtk_simpmap_op1_setup(map_id) @mapping_tables ||= {} @map_open_flags ||= {} @event_open_flags ||= {} @draw_pos = [] @mapping_data = nil return if WdTk::SimpMap::NonMap.include?(map_id) return if WdTk::SimpMap::NonMap.empty? && !WdTk::SimpMap::MapName.include?(map_id) data = @mapping_tables[map_id] if !data || data.xsize != width || data.ysize != height @mapping_tables[map_id] = Table.new(width, height) end @mapping_data = @mapping_tables[map_id] end #-------------------------------------------------------------------------- # ○ リフレッシュ #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_refresh refresh def refresh _wdtk_simpmap_op1_refresh $game_player.on_mapping end #-------------------------------------------------------------------------- # ● 指定した座標を中心にマッピングを行う #-------------------------------------------------------------------------- def mapping(x, y, radius) return unless @mapping_data x_min = x - radius - 1 x_max = x + radius + 1 unless loop_horizontal? x_min = 0 if x_min < 0 x_max = width - 1 if x_max >= width end y_min = y - radius - 1 y_max = y + radius + 1 unless loop_vertical? y_min = 0 if y_min < 0 y_max = height - 1 if y_max >= height end x_min.upto(x_max) do |dx| x2 = dx % width y_min.upto(y_max) do |dy| n = (128 * (radius - 1 - Math.hypot(x - dx, y - dy))).to_i n = 255 if n > 255 y2 = dy % height if @mapping_data[x2, y2] < n @mapping_data[x2, y2] = n @draw_pos << x2 * width + y2 # 軽量化のため配列を使わない end end end end #-------------------------------------------------------------------------- # ● マップの公開 #-------------------------------------------------------------------------- def map_open(map_id) @map_open_flags[map_id] = true end #-------------------------------------------------------------------------- # ● マップの非公開 #-------------------------------------------------------------------------- def map_close(map_id) @map_open_flags[map_id] = false end #-------------------------------------------------------------------------- # ● 公開するマップかどうか #-------------------------------------------------------------------------- def open_map? @map_open_flags[@map_id] == true end #-------------------------------------------------------------------------- # ● イベントの公開 #-------------------------------------------------------------------------- def event_open(map_id) @event_open_flags[map_id] = true end #-------------------------------------------------------------------------- # ● イベントの非公開 #-------------------------------------------------------------------------- def event_close(map_id) @event_open_flags[map_id] = false end #-------------------------------------------------------------------------- # ● 公開するイベントかどうか #-------------------------------------------------------------------------- def open_event? @event_open_flags[@map_id] == true end #-------------------------------------------------------------------------- # ● マッピングのクリア #-------------------------------------------------------------------------- def clear_mapping(map_id) @mapping_tables.delete(map_id) @mapping_tables[map_id] = Table.new(width, height) if @map_id == map_id end end #============================================================================== # ■ Game_Player #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ○ 指定位置に移動 #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_moveto moveto def moveto(x, y) _wdtk_simpmap_op1_moveto(x, y) on_mapping end #-------------------------------------------------------------------------- # ○ 歩数増加 #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_increase_steps increase_steps def increase_steps _wdtk_simpmap_op1_increase_steps on_mapping end #-------------------------------------------------------------------------- # ● 現在地のマッピング #-------------------------------------------------------------------------- def on_mapping r = $game_variables[WdTk::SimpMap::OP1::RadiusID] $game_map.mapping(@x, @y, r) if r > 0 end end #============================================================================== # ■ Spriteset_SimpleMap #============================================================================== class Spriteset_SimpleMap #-------------------------------------------------------------------------- # ● モジュール #-------------------------------------------------------------------------- include WdTk::SimpMap::OP1 #-------------------------------------------------------------------------- # ● マップ画像の作成 #-------------------------------------------------------------------------- def create_map_bitmap @loop_bitmap.dispose if @loop_bitmap @base_bitmap.dispose if @base_bitmap @loop_bitmap = nil @base_bitmap = nil return if NonMap.include?($game_map.map_id) map_name = MapName[$game_map.map_id] if map_name unless map_name.empty? @base_bitmap = Cache.load_bitmap(DirName, map_name) else @base_bitmap = WdTk.load_simplemap($game_map.map_id) end elsif !NonMap.empty? @base_bitmap = WdTk.load_simplemap($game_map.map_id) else return end @map_width = @base_bitmap.width @map_height = @base_bitmap.height width = $game_map.loop_horizontal? ? @map_width * 2 : @map_width height = $game_map.loop_vertical? ? @map_height * 2 : @map_height @loop_bitmap = Bitmap.new(width, height) if $game_map.open_map? @loop_bitmap.blt(0, 0, @base_bitmap, @base_bitmap.rect) @open_flag = true else redraw_all_mapping @open_flag = false end rect = Rect.new(0, 0, @map_width, @map_height) @loop_bitmap.blt(@map_width, 0, @loop_bitmap, rect) @loop_bitmap.blt(0, @map_height, @loop_bitmap, @loop_bitmap.rect) end #-------------------------------------------------------------------------- # ○ フレーム更新 #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_update update def update _wdtk_simpmap_op1_update return unless @loop_bitmap if $game_map.open_map? return if @open_flag @loop_bitmap.blt(0, 0, @base_bitmap, @base_bitmap.rect) @open_flag = true elsif @open_flag redraw_all_mapping @open_flag = false else return if $game_map.draw_pos.empty? rect = Rect.new rect.width = (@map_width + $game_map.width - 1) / $game_map.width rect.height = (@map_height + $game_map.height - 1) / $game_map.height $game_map.draw_pos.each do |n| draw_mapping(n / $game_map.width, n % $game_map.width, rect) end $game_map.draw_pos.clear end rect = Rect.new(0, 0, @map_width, @map_height) @loop_bitmap.clear_rect(@map_width, 0, @map_width, @map_height) @loop_bitmap.clear_rect(0, @map_height, @map_width * 2, @map_height) @loop_bitmap.blt(@map_width, 0, @loop_bitmap, rect) @loop_bitmap.blt(0, @map_height, @loop_bitmap, @loop_bitmap.rect) end #-------------------------------------------------------------------------- # ○ 全てのイベントを取得 #-------------------------------------------------------------------------- alias _wdtk_simpmap_op1_all_events all_events def all_events if $game_map.open_event? _wdtk_simpmap_op1_all_events else _wdtk_simpmap_op1_all_events.select do |event| $game_map.mapping_data[event.x, event.y] > 200 end end end #-------------------------------------------------------------------------- # ● マップの再描写 #-------------------------------------------------------------------------- def redraw_all_mapping @loop_bitmap.clear rect = Rect.new rect.width = (@map_width + $game_map.width - 1) / $game_map.width rect.height = (@map_height + $game_map.height - 1) / $game_map.height $game_map.width.times do |x| $game_map.height.times {|y| draw_mapping(x, y, rect) } end $game_map.draw_pos.clear end #-------------------------------------------------------------------------- # ● マップの描写 #-------------------------------------------------------------------------- def draw_mapping(x, y, rect) n = $game_map.mapping_data[x, y] rect.x = @map_width * x / $game_map.width rect.y = @map_height * y / $game_map.height @loop_bitmap.clear_rect(rect) if n < 255 color = WdTk::SimpMap::OP1::UndvColor alpha = color.alpha color.alpha = alpha * (255 - n) / 255 @loop_bitmap.fill_rect(rect, color) color.alpha = alpha end @loop_bitmap.blt(rect.x, rect.y, @base_bitmap, rect, n) if n > 0 end end