Preserved forum archive. This topic stores the original first post and locally mirrored RPG Maker Web attachments when available. It is posted by the BMMPlay archive account, not by the original creator.
Original Source
- Original title: Etude87's KMS MiniMap Add-on - Fixing / Editing it's function - VX ACE.
- Original author: Devildimos
- Original date: April 24, 2021
- Source thread: https://forums.rpgmakerweb.com/threads/etude87s-kms-minimap-add-on-fixing-editing-its-function-vx-ace.135813/
- Source forum path: Game Development Engines > Ruby Game System (RGSS) Scripts > RGSS3 Scripts (RMVX Ace) > RGSS3 Script Requests
Summary
=> [:lozenge, 5], # ID 2번맵 정사각형 시야범 # ID 2 map square view 2 => [:square, 4],
Archived First Post
Good day you all!
I have been messing around with 3 scripts trying to put a simple variable but realize that there is so much more missing that is way out of my scripting knowledge. I will paste all three scripts below in a spoiler.
First off let me explain what these scripts do, this add-on script is for "TheoAllen - Fog of War" and "KMS_MiniMap" to work together and adjusting the way the fog of war works. Creating a... well here it explains in much more details > https://etude87.itch.io/etude87s-kms-minimap-add-on
What I want to add and change.
1. TheoAllen - Fog of War "script calls" are not working. Such as : $game_map.reveal_tiles(x, y), $game_map.reveal_tiles(x, y, distance), $game_map.events[event_id].reveal_tiles, and $game_map.events[event_id].reveal_tiles(distance). I'd love to have these script calls to function.
2. I would like a script call where I can reset the Fog of War to reappear in a specific map ID. For example $game_map.reset_map_id(x).
3. I would like to add a Variable for the player's view distance that I can change at anytime. This way I can change the sight range of the player for any reason.
The add-on's "Handle exceptions by map" like "lozenge, square, circle" is very nicely done. Even though I will use the square mostly, but it would be nice to add those exceptions into a variable as well. If it is possible.
4. In the add-on there is a way to give an event a tag to block the line of sight of the player. Is it possible to have a "comment" in the top of the event progress instead of having the "[FOV]" in the event's name. This way I can self switch A to remove the FOV like a door.
In the spoiler here are all 3 scripts however, the link above already directs to the scripts.
If there is anything else you need please ask.
Thank you and stay safe.
I have been messing around with 3 scripts trying to put a simple variable but realize that there is so much more missing that is way out of my scripting knowledge. I will paste all three scripts below in a spoiler.
First off let me explain what these scripts do, this add-on script is for "TheoAllen - Fog of War" and "KMS_MiniMap" to work together and adjusting the way the fog of war works. Creating a... well here it explains in much more details > https://etude87.itch.io/etude87s-kms-minimap-add-on
What I want to add and change.
1. TheoAllen - Fog of War "script calls" are not working. Such as : $game_map.reveal_tiles(x, y), $game_map.reveal_tiles(x, y, distance), $game_map.events[event_id].reveal_tiles, and $game_map.events[event_id].reveal_tiles(distance). I'd love to have these script calls to function.
2. I would like a script call where I can reset the Fog of War to reappear in a specific map ID. For example $game_map.reset_map_id(x).
3. I would like to add a Variable for the player's view distance that I can change at anytime. This way I can change the sight range of the player for any reason.
The add-on's "Handle exceptions by map" like "lozenge, square, circle" is very nicely done. Even though I will use the square mostly, but it would be nice to add those exceptions into a variable as well. If it is possible.
4. In the add-on there is a way to give an event a tag to block the line of sight of the player. Is it possible to have a "comment" in the top of the event progress instead of having the "[FOV]" in the event's name. This way I can self switch A to remove the FOV like a door.
In the spoiler here are all 3 scripts however, the link above already directs to the scripts.
If there is anything else you need please ask.
Thank you and stay safe.
Ruby:
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#_/ ◆ ミニマップ - KMS_MiniMap ◆ VX Ace ◆
#_/ ◇ Last update : 2012/02/12 (TOMY@Kamesoft) ◇
#_/----------------------------------------------------------------------------
#_/ ミニマップ表示機能を追加します。
#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
#==============================================================================
# ★ 設定項目 - BEGIN Setting ★
#==============================================================================
module KMS_MiniMap
# ◆ ミニマップ表示切替ボタン
# nil にするとボタン切り替え無効。
SWITCH_BUTTON = nil
# ◆ ミニマップ表示位置・サイズ (X, Y, 幅, 高さ)
MAP_RECT = Rect.new(5, 5, 130, 130)
# ◆ ミニマップの Z 座標
# 大きくしすぎると色々なものに被ります。
MAP_Z = 0
# ◆ 1マスのサイズ
# 3 以上を推奨。
GRID_SIZE = 3
# ◆ ミニマップカラー
FOREGROUND_COLOR = Color.new(192, 192, 224, 160) # 前景色 (通行可)
BACKGROUND_COLOR = Color.new( 0, 0, 160, 160) # 背景色 (通行不可)
POSITION_COLOR = Color.new(255, 0, 0, 192) # 現在位置
MOVE_EVENT_COLOR = Color.new(255, 160, 0, 192) # マップ移動イベント
VEHICLE_COLOR = Color.new( 96, 128, 0, 192) # 乗り物
# ◆ オブジェクトの色
# 要素の先頭から順に OBJ1, OBJ2, ... に対応。
OBJECT_COLOR = [
Color.new( 0, 200, 0, 192), # OBJ 1
Color.new( 0, 255, 255, 192), # OBJ 2
Color.new(255, 170, 0, 192), # OBJ 3
Color.new(200, 0, 0, 192), # OBJ 4
Color.new(200, 0, 200, 192), # OBJ 5
] # ← この ] は消さないこと!
# ◆ アイコンの点滅の強さ
# 5 ~ 8 あたりを推奨。
BLINK_LEVEL = 7
# ◆ マップのキャッシュ数
# この数を超えると、長期間参照していないものから削除。
CACHE_NUM = 1
end
#==============================================================================
# ☆ 設定ここまで - END Setting ☆
#==============================================================================
$kms_imported = {} if $kms_imported == nil
$kms_imported["MiniMap"] = true
module KMS_MiniMap
# ミニマップ非表示
REGEX_NO_MINIMAP_NOTE = /<(?:ミニマップ|MINIMAP)\s*(?:非表示|HIDE)>/i
REGEX_NO_MINIMAP_NAME = /\[NOMAP\]/i
# 障害物
REGEX_WALL_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:壁|障害物|WALL)>/i
# 移動イベント
REGEX_MOVE_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:移動|MOVE)>/i
# オブジェクト
REGEX_OBJECT = /<(?:ミニマップ|MINIMAP)\s+OBJ(?:ECT)?\s*(\d+)>/i
end
# *****************************************************************************
#==============================================================================
# □ KMS_Commands
#==============================================================================
module KMS_Commands
module_function
#--------------------------------------------------------------------------
# ○ ミニマップを表示
#--------------------------------------------------------------------------
def show_minimap
$game_temp.minimap_manual_visible = true
$game_system.minimap_show = true
end
#--------------------------------------------------------------------------
# ○ ミニマップを隠す
#--------------------------------------------------------------------------
def hide_minimap
$game_system.minimap_show = false
end
#--------------------------------------------------------------------------
# ○ ミニマップ表示状態の取得
#--------------------------------------------------------------------------
def minimap_showing?
return $game_system.minimap_show
end
#--------------------------------------------------------------------------
# ○ ミニマップをリフレッシュ
#--------------------------------------------------------------------------
def refresh_minimap
return unless SceneManager.scene_is?(Scene_Map)
$game_map.refresh if $game_map.need_refresh
SceneManager.scene.refresh_minimap
end
#--------------------------------------------------------------------------
# ○ ミニマップのオブジェクトを更新
#--------------------------------------------------------------------------
def update_minimap_object
return unless SceneManager.scene_is?(Scene_Map)
$game_map.refresh if $game_map.need_refresh
SceneManager.scene.update_minimap_object
end
end
#==============================================================================
# ■ Game_Interpreter
#==============================================================================
class Game_Interpreter
# イベントコマンドから直接コマンドを叩けるようにする
include KMS_Commands
end
#==============================================================================
# ■ RPG::Map
#==============================================================================
class RPG::Map
#--------------------------------------------------------------------------
# ○ ミニマップのキャッシュ生成
#--------------------------------------------------------------------------
def create_minimap_cache
@__minimap_show = true
note.each_line { |line|
if line =~ KMS_MiniMap::REGEX_NO_MINIMAP_NOTE # マップ非表示
@__minimap_show = false
end
}
end
#--------------------------------------------------------------------------
# ○ ミニマップ表示
#--------------------------------------------------------------------------
def minimap_show?
create_minimap_cache if @__minimap_show.nil?
return @__minimap_show
end
end
#==============================================================================
# ■ RPG::MapInfo
#==============================================================================
class RPG::MapInfo
#--------------------------------------------------------------------------
# ● マップ名取得
#--------------------------------------------------------------------------
def name
return @name.gsub(/\[.*\]/) { "" }
end
#--------------------------------------------------------------------------
# ○ オリジナルマップ名取得
#--------------------------------------------------------------------------
def original_name
return @name
end
#--------------------------------------------------------------------------
# ○ ミニマップのキャッシュ生成
#--------------------------------------------------------------------------
def create_minimap_cache
@__minimap_show = !(@name =~ KMS_MiniMap::REGEX_NO_MINIMAP_NAME)
end
#--------------------------------------------------------------------------
# ○ ミニマップ表示
#--------------------------------------------------------------------------
def minimap_show?
create_minimap_cache if @__minimap_show == nil
return @__minimap_show
end
end
#==============================================================================
# ■ Game_Temp
#==============================================================================
class Game_Temp
#--------------------------------------------------------------------------
# ○ 公開インスタンス変数
#--------------------------------------------------------------------------
attr_accessor :minimap_manual_visible # ミニマップ手動表示切り替えフラグ
#--------------------------------------------------------------------------
# ○ オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KMS_MiniMap initialize
def initialize
initialize_KMS_MiniMap
@minimap_manual_visible = true
end
end
#==============================================================================
# ■ Game_System
#==============================================================================
class Game_System
#--------------------------------------------------------------------------
# ○ 公開インスタンス変数
#--------------------------------------------------------------------------
attr_accessor :minimap_show # ミニマップ表示フラグ
#--------------------------------------------------------------------------
# ○ オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KMS_MiniMap initialize
def initialize
initialize_KMS_MiniMap
@minimap_show = true
end
end
#==============================================================================
# ■ Game_Map
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
# ○ 定数
#--------------------------------------------------------------------------
MINIMAP_FADE_NONE = 0 # ミニマップ フェードなし
MINIMAP_FADE_IN = 1 # ミニマップ フェードイン
MINIMAP_FADE_OUT = 2 # ミニマップ フェードアウト
#--------------------------------------------------------------------------
# ○ 公開インスタンス変数
#--------------------------------------------------------------------------
attr_accessor :minimap_fade
#--------------------------------------------------------------------------
# ○ ミニマップを表示するか
#--------------------------------------------------------------------------
def minimap_show?
return $data_mapinfos[map_id].minimap_show? && @map.minimap_show?
end
#--------------------------------------------------------------------------
# ○ ミニマップをフェードイン
#--------------------------------------------------------------------------
def fadein_minimap
@minimap_fade = MINIMAP_FADE_IN
end
#--------------------------------------------------------------------------
# ○ ミニマップをフェードアウト
#--------------------------------------------------------------------------
def fadeout_minimap
@minimap_fade = MINIMAP_FADE_OUT
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
alias refresh_KMS_MiniMap refresh
def refresh
refresh_KMS_MiniMap
SceneManager.scene.refresh_minimap if SceneManager.scene_is?(Scene_Map)
end
end
#==============================================================================
# ■ Game_Event
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
# ○ ミニマップ用のキャッシュを作成
#--------------------------------------------------------------------------
def __create_minimap_cache
@__last_page = @page
@__minimap_wall_event = false
@__minimap_move_event = false
@__minimap_object_type = -1
return if @page.nil?
@page.list.each { |cmd|
# 注釈以外に到達したら離脱
break unless [108, 408].include?(cmd.code)
# 正規表現判定
case cmd.parameters[0]
when KMS_MiniMap::REGEX_WALL_EVENT
@__minimap_wall_event = true
when KMS_MiniMap::REGEX_MOVE_EVENT
@__minimap_move_event = true
when KMS_MiniMap::REGEX_OBJECT
@__minimap_object_type = $1.to_i
end
}
end
private :__create_minimap_cache
#--------------------------------------------------------------------------
# ○ グラフィックがあるか
#--------------------------------------------------------------------------
def graphic_exist?
return (character_name != "" || tile_id > 0)
end
#--------------------------------------------------------------------------
# ○ 障害物か
#--------------------------------------------------------------------------
def is_minimap_wall_event?
if @__minimap_wall_event.nil? || @__last_page != @page
__create_minimap_cache
end
return @__minimap_wall_event
end
#--------------------------------------------------------------------------
# ○ 移動イベントか
#--------------------------------------------------------------------------
def is_minimap_move_event?
if @__minimap_move_event.nil? || @__last_page != @page
__create_minimap_cache
end
return @__minimap_move_event
end
#--------------------------------------------------------------------------
# ○ ミニマップオブジェクトか
#--------------------------------------------------------------------------
def is_minimap_object?
if @__minimap_object_type.nil? || @__last_page != @page
__create_minimap_cache
end
return @__minimap_object_type > 0
end
#--------------------------------------------------------------------------
# ○ ミニマップオブジェクトタイプ
#--------------------------------------------------------------------------
def minimap_object_type
if @__minimap_object_type.nil? || @__last_page != @page
__create_minimap_cache
end
return @__minimap_object_type
end
end
#==============================================================================
# □ Game_MiniMap
#------------------------------------------------------------------------------
# ミニマップを扱うクラスです。
#==============================================================================
class Game_MiniMap
#--------------------------------------------------------------------------
# ○ 構造体
#--------------------------------------------------------------------------
Point = Struct.new(:x, :y)
Size = Struct.new(:width, :height)
PassageCache = Struct.new(:map_id, :table, :scan_table)
#--------------------------------------------------------------------------
# ○ クラス変数
#--------------------------------------------------------------------------
@@passage_cache = [] # 通行フラグテーブルキャッシュ
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize(tilemap)
@map_rect = KMS_MiniMap::MAP_RECT
@grid_size = [KMS_MiniMap::GRID_SIZE, 1].max
@x = 0
@y = 0
@grid_num = Point.new(
(@map_rect.width + @grid_size - 1) / @grid_size,
(@map_rect.height + @grid_size - 1) / @grid_size
)
@draw_grid_num = Point.new(@grid_num.x + 2, @grid_num.y + 2)
@draw_range_begin = Point.new(0, 0)
@draw_range_end = Point.new(0, 0)
@tilemap = tilemap
@last_x = $game_player.x
@last_y = $game_player.y
@showing = false
@hiding = false
create_sprites
refresh
unless $game_temp.minimap_manual_visible
self.opacity = 0
end
end
#--------------------------------------------------------------------------
# ○ スプライト作成
#--------------------------------------------------------------------------
def create_sprites
@viewport = Viewport.new(@map_rect)
@viewport.z = KMS_MiniMap::MAP_Z
# ビットマップサイズ計算
@bmp_size = Size.new(
(@grid_num.x + 2) * @grid_size,
(@grid_num.y + 2) * @grid_size
)
@buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
# マップ用スプライト作成
@map_sprite = Sprite.new(@viewport)
@map_sprite.x = -@grid_size
@map_sprite.y = -@grid_size
@map_sprite.z = 0
@map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
# オブジェクト用スプライト作成
@object_sprite = Sprite_MiniMapIcon.new(@viewport)
@object_sprite.x = -@grid_size
@object_sprite.y = -@grid_size
@object_sprite.z = 1
@object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
# 現在位置スプライト作成
@position_sprite = Sprite_MiniMapIcon.new
@position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
@position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
@position_sprite.z = @viewport.z + 2
bitmap = Bitmap.new(@grid_size, @grid_size)
bitmap.fill_rect(bitmap.rect, KMS_MiniMap::POSITION_COLOR)
@position_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
# ● 解放
#--------------------------------------------------------------------------
def dispose
@buf_bitmap.dispose
@map_sprite.bitmap.dispose
@map_sprite.dispose
@object_sprite.bitmap.dispose
@object_sprite.dispose
@position_sprite.bitmap.dispose
@position_sprite.dispose
@viewport.dispose
end
#--------------------------------------------------------------------------
# ○ 可視状態取得
#--------------------------------------------------------------------------
def visible
return @map_sprite.visible
end
#--------------------------------------------------------------------------
# ○ 可視状態設定
#--------------------------------------------------------------------------
def visible=(value)
@viewport.visible = value
@map_sprite.visible = value
@object_sprite.visible = value
@position_sprite.visible = value
end
#--------------------------------------------------------------------------
# ○ 不透明度取得
#--------------------------------------------------------------------------
def opacity
return @map_sprite.opacity
end
#--------------------------------------------------------------------------
# ○ 不透明度設定
#--------------------------------------------------------------------------
def opacity=(value)
@map_sprite.opacity = value
@object_sprite.opacity = value
@position_sprite.opacity = value
end
#--------------------------------------------------------------------------
# ○ リフレッシュ
#--------------------------------------------------------------------------
def refresh
update_draw_range
update_passage_table
update_object_list
update_position
draw_map
draw_object
Graphics.frame_reset
end
#--------------------------------------------------------------------------
# ○ フェードイン
#--------------------------------------------------------------------------
def fadein
@showing = true
@hiding = false
end
#--------------------------------------------------------------------------
# ○ フェードアウト
#--------------------------------------------------------------------------
def fadeout
@showing = false
@hiding = true
end
#--------------------------------------------------------------------------
# ○ キー入力更新
#--------------------------------------------------------------------------
def update_input
return if KMS_MiniMap::SWITCH_BUTTON.nil?
if Input.trigger?(KMS_MiniMap::SWITCH_BUTTON)
if opacity < 255 && !@showing
$game_temp.minimap_manual_visible = true
fadein
elsif opacity > 0 && !@hiding
$game_temp.minimap_manual_visible = false
fadeout
end
end
end
#--------------------------------------------------------------------------
# ○ 描画範囲更新
#--------------------------------------------------------------------------
def update_draw_range
range = []
(2).times { |i| range[i] = @draw_grid_num[i] / 2 }
@draw_range_begin.x = $game_player.x - range[0]
@draw_range_begin.y = $game_player.y - range[1]
@draw_range_end.x = $game_player.x + range[0]
@draw_range_end.y = $game_player.y + range[1]
end
#--------------------------------------------------------------------------
# ○ 通行可否テーブル更新
#--------------------------------------------------------------------------
def update_passage_table
cache = get_passage_table_cache
@passage_table = cache.table
@passage_scan_table = cache.scan_table
update_around_passage_table
end
#--------------------------------------------------------------------------
# ○ 通行可否テーブルのキャッシュを取得
#--------------------------------------------------------------------------
def get_passage_table_cache
map_id = $game_map.map_id
cache = @@passage_cache.find { |c| c.map_id == map_id }
# キャッシュミスしたら新規作成
if cache == nil
cache = PassageCache.new(map_id)
cache.table = Table.new($game_map.width, $game_map.height)
cache.scan_table = Table.new(
($game_map.width + @draw_grid_num.x - 1) / @draw_grid_num.x,
($game_map.height + @draw_grid_num.y - 1) / @draw_grid_num.y
)
end
# 直近のキャッシュは先頭に移動し、古いキャッシュは削除
@@passage_cache.unshift(cache)
@@passage_cache.delete_at(KMS_MiniMap::CACHE_NUM)
return cache
end
#--------------------------------------------------------------------------
# ○ 通行可否テーブルのキャッシュをクリア
#--------------------------------------------------------------------------
def clear_passage_table_cache
return if @passage_scan_table == nil
table = @passage_scan_table
@passage_scan_table = Table.new(table.xsize, table.ysize)
end
#--------------------------------------------------------------------------
# ○ 通行可否テーブルの探索
# x, y : 探索位置
#--------------------------------------------------------------------------
def scan_passage(x, y)
dx = x / @draw_grid_num.x
dy = y / @draw_grid_num.y
# 探索済み
return if @passage_scan_table[dx, dy] == 1
# マップ範囲外
return unless dx.between?(0, @passage_scan_table.xsize - 1)
return unless dy.between?(0, @passage_scan_table.ysize - 1)
rx = (dx * @draw_grid_num.x)...((dx + 1) * @draw_grid_num.x)
ry = (dy * @draw_grid_num.y)...((dy + 1) * @draw_grid_num.y)
mw = $game_map.width - 1
mh = $game_map.height - 1
# 探索範囲内の通行テーブルを生成
rx.each { |x|
next unless x.between?(0, mw)
ry.each { |y|
next unless y.between?(0, mh)
# 通行方向フラグ作成
# (↓、←、→、↑ の順に 1, 2, 4, 8 が対応)
flag = 0
[2, 4, 6, 8].each{ |d|
flag |= 1 << (d / 2 - 1) if $game_map.passable?(x, y, d)
}
@passage_table[x, y] = flag
}
}
@passage_scan_table[dx, dy] = 1
end
#--------------------------------------------------------------------------
# ○ 周辺の通行可否テーブル更新
#--------------------------------------------------------------------------
def update_around_passage_table
gx = @draw_grid_num.x
gy = @draw_grid_num.y
dx = $game_player.x - gx / 2
dy = $game_player.y - gy / 2
scan_passage(dx, dy)
scan_passage(dx + gx, dy)
scan_passage(dx, dy + gy)
scan_passage(dx + gx, dy + gy)
end
#--------------------------------------------------------------------------
# ○ オブジェクト一覧更新
#--------------------------------------------------------------------------
def update_object_list
events = $game_map.events.values
# WALL
@wall_events = events.find_all { |e| e.is_minimap_wall_event? }
# MOVE
@move_events = events.find_all { |e| e.is_minimap_move_event? }
# OBJ
@object_list = events.find_all { |e| e.is_minimap_object? }
end
#--------------------------------------------------------------------------
# ○ 位置更新
#--------------------------------------------------------------------------
def update_position
# 移動量算出
pt = Point.new($game_player.x, $game_player.y)
ox = ($game_player.real_x - pt.x) * @grid_size
oy = ($game_player.real_y - pt.y) * @grid_size
@viewport.ox = ox
@viewport.oy = oy
# 移動していたらマップ再描画
if pt.x != @last_x || pt.y != @last_y
draw_map
@last_x = pt.x
@last_y = pt.y
end
end
#--------------------------------------------------------------------------
# ○ 描画範囲内判定
#--------------------------------------------------------------------------
def in_draw_range?(x, y)
rb = @draw_range_begin
re = @draw_range_end
return (x.between?(rb.x, re.x) && y.between?(rb.y, re.y))
end
#--------------------------------------------------------------------------
# ○ マップ範囲内判定
#--------------------------------------------------------------------------
def in_map_range?(x, y)
mw = $game_map.width
mh = $game_map.height
return (x.between?(0, mw - 1) && y.between?(0, mh - 1))
end
#--------------------------------------------------------------------------
# ○ マップ描画
#--------------------------------------------------------------------------
def draw_map
update_around_passage_table
bitmap = @map_sprite.bitmap
bitmap.fill_rect(bitmap.rect, KMS_MiniMap::BACKGROUND_COLOR)
draw_map_foreground(bitmap)
draw_map_move_event(bitmap)
end
#--------------------------------------------------------------------------
# ○ 通行可能領域の描画
#--------------------------------------------------------------------------
def draw_map_foreground(bitmap)
range_x = (@draw_range_begin.x)..(@draw_range_end.x)
range_y = (@draw_range_begin.y)..(@draw_range_end.y)
map_w = $game_map.width - 1
map_h = $game_map.height - 1
rect = Rect.new(0, 0, @grid_size, @grid_size)
range_x.each { |x|
next unless x.between?(0, map_w)
range_y.each { |y|
next unless y.between?(0, map_h)
next if @passage_table[x, y] == 0
next if @wall_events.find { |e| e.x == x && e.y == y } # 壁
# グリッド描画サイズ算出
rect.set(0, 0, @grid_size, @grid_size)
rect.x = (x - @draw_range_begin.x) * @grid_size
rect.y = (y - @draw_range_begin.y) * @grid_size
flag = @passage_table[x, y]
if flag & 0x01 == 0 # 下通行不能
rect.height -= 1
end
if flag & 0x02 == 0 # 左通行不能
rect.x += 1
rect.width -= 1
end
if flag & 0x04 == 0 # 右通行不能
rect.width -= 1
end
if flag & 0x08 == 0 # 上通行不能
rect.y += 1
rect.height -= 1
end
bitmap.fill_rect(rect, KMS_MiniMap::FOREGROUND_COLOR)
}
}
end
#--------------------------------------------------------------------------
# ○ 移動イベントの描画
#--------------------------------------------------------------------------
def draw_map_move_event(bitmap)
rect = Rect.new(0, 0, @grid_size, @grid_size)
@move_events.each { |e|
rect.x = (e.x - @draw_range_begin.x) * @grid_size
rect.y = (e.y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR)
}
end
#--------------------------------------------------------------------------
# ○ アニメーション更新
#--------------------------------------------------------------------------
def update_animation
if @showing
# フェードイン
self.opacity += 16
if opacity == 255
@showing = false
end
elsif @hiding
# フェードアウト
self.opacity -= 16
if opacity == 0
@hiding = false
end
end
end
#--------------------------------------------------------------------------
# ○ オブジェクト描画
#--------------------------------------------------------------------------
def draw_object
# 下準備
bitmap = @object_sprite.bitmap
bitmap.clear
rect = Rect.new(0, 0, @grid_size, @grid_size)
# オブジェクト描画
@object_list.each { |obj|
next unless in_draw_range?(obj.x, obj.y)
color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
next if color.nil?
rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, color)
}
# 乗り物描画
$game_map.vehicles.each { |vehicle|
next if vehicle.transparent
rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR)
}
end
#--------------------------------------------------------------------------
# ○ 更新
#--------------------------------------------------------------------------
def update
update_input
return unless need_update?
update_draw_range
update_position
update_animation
draw_object
@map_sprite.update
@object_sprite.update
@position_sprite.update
end
#--------------------------------------------------------------------------
# ○ 更新判定
#--------------------------------------------------------------------------
def need_update?
return (visible && opacity > 0) || @showing || @hiding
end
end
#==============================================================================
# □ Sprite_MiniMapIcon
#------------------------------------------------------------------------------
# ミニマップ用アイコンのクラスです。
#==============================================================================
class Sprite_MiniMapIcon < Sprite
DURATION_MAX = 60
#--------------------------------------------------------------------------
# ● オブジェクト初期化
# viewport : ビューポート
#--------------------------------------------------------------------------
def initialize(viewport = nil)
super(viewport)
@duration = DURATION_MAX / 2
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
def update
super
@duration += 1
if @duration == DURATION_MAX
@duration = 0
end
update_effect
end
#--------------------------------------------------------------------------
# ○ エフェクトの更新
#--------------------------------------------------------------------------
def update_effect
self.color.set(255, 255, 255,
(@duration - DURATION_MAX / 2).abs * KMS_MiniMap::BLINK_LEVEL
)
end
end
#==============================================================================
# ■ Spriteset_Map
#==============================================================================
class Spriteset_Map
attr_reader :minimap
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
alias initialize_KMS_MiniMap initialize
def initialize
initialize_KMS_MiniMap
create_minimap
end
#--------------------------------------------------------------------------
# ○ ミニマップの作成
#--------------------------------------------------------------------------
def create_minimap
@minimap = Game_MiniMap.new(@tilemap)
@minimap.visible = $game_system.minimap_show && $game_map.minimap_show?
end
#--------------------------------------------------------------------------
# ● 解放
#--------------------------------------------------------------------------
alias dispose_KMS_MiniMap dispose
def dispose
dispose_KMS_MiniMap
dispose_minimap
end
#--------------------------------------------------------------------------
# ○ ミニマップの解放
#--------------------------------------------------------------------------
def dispose_minimap
@minimap.dispose
@minimap = nil
end
#--------------------------------------------------------------------------
# ● フレーム更新
#--------------------------------------------------------------------------
alias update_KMS_MiniMap update
def update
update_KMS_MiniMap
update_minimap
end
#--------------------------------------------------------------------------
# ○ ミニマップ更新
#--------------------------------------------------------------------------
def minimap_show?
return $game_map.minimap_show? && $game_system.minimap_show
end
#--------------------------------------------------------------------------
# ○ ミニマップ更新
#--------------------------------------------------------------------------
def update_minimap
return if @minimap.nil?
# 表示切替
if minimap_show?
@minimap.visible = true
else
@minimap.visible = false
return
end
# フェード判定
case $game_map.minimap_fade
when Game_Map::MINIMAP_FADE_IN
@minimap.fadein
$game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
when Game_Map::MINIMAP_FADE_OUT
@minimap.fadeout
$game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
end
@minimap.update
end
#--------------------------------------------------------------------------
# ○ ミニマップ全体をリフレッシュ
#--------------------------------------------------------------------------
def refresh_minimap
return if @minimap.nil?
@minimap.clear_passage_table_cache
@minimap.refresh
end
#--------------------------------------------------------------------------
# ○ ミニマップのオブジェクトを更新
#--------------------------------------------------------------------------
def update_minimap_object
@minimap.update_object_list unless @minimap.nil?
end
end
#==============================================================================
# ■ Scene_Map
#==============================================================================
class Scene_Map
#--------------------------------------------------------------------------
# ● 場所移動後の処理
#--------------------------------------------------------------------------
alias post_transfer_KMS_MiniMap post_transfer
def post_transfer
refresh_minimap
post_transfer_KMS_MiniMap
end
#--------------------------------------------------------------------------
# ○ ミニマップ全体をリフレッシュ
#--------------------------------------------------------------------------
def refresh_minimap
@spriteset.refresh_minimap unless @spriteset.nil?
end
#--------------------------------------------------------------------------
# ○ ミニマップのオブジェクトを更新
#--------------------------------------------------------------------------
def update_minimap_object
@spriteset.update_minimap_object unless @spriteset.nil?
end
end
Ruby:
#===============================================================================
# TheoAllen - Fog of War
# Requested by : Zero0018
# Last edited : 15.01.2015
#-------------------------------------------------------------------------------
# How to use :
# Put the script below materials but above main
# No external resource is required
#
#------------------------------------------------------------------------------
# ** MAP NOTETAG :
#------------------------------------------------------------------------------
# To show fog in map, simply put <fog> in map note
# To hide fog in map, simply put <no fog> in map note
#
# Set the default of showing fog in configuration
#
#------------------------------------------------------------------------------
# ** SCRIPT CALL :
#------------------------------------------------------------------------------
#
# $game_map.reveal_tiles(x, y)
# $game_map.reveal_tiles(x, y, distance)
# Will reveal tiles in x,y within the distance. If distance is ommited, it will
# be same as the VisiRange in script setting
#
# $game_map.events[event_id].reveal_tiles
# $game_map.events[event_id].reveal_tiles(distance)
# Will reveal tiles from the event location within the distance. If distance is
# ommited, it will be same as the VisiRange in script setting
#
#-------------------------------------------------------------------------------
# Configuration
#===============================================================================
module Theo
VisiRange = 4
# Visibility range of the character. Larger value, longer distance
FogOpacity = 255
# Fog opacity. Set 255 for full opacity.
DefaultFog = false
# If set to true, every map will has fog. Unless you put <no fog>
# If set to false, every map will has no fog. Unless you put <fog>
end
#===============================================================================
# End of config
#===============================================================================
#===============================================================================
# ** Bitmap
#===============================================================================
class Bitmap
# Fill entire bitmap with color
def entire_fill(color = Color.new(0,0,0,150))
fill_rect(self.rect,color)
end
end
#===============================================================================
# ** Fog of War
#===============================================================================
class Fog_of_War < Plane
@@bitmap_cache = {}
#----------------------------------------------------------------------------
# * Initialize
#----------------------------------------------------------------------------
def initialize(vport)
super(vport)
@id = -1
end
#----------------------------------------------------------------------------
# * Update
#----------------------------------------------------------------------------
def update
if $game_map
if @id != $game_map.map_id
@id = $game_map.map_id
@width = $game_map.width
@height = $game_map.height
update_bitmap
end
self.ox = $game_map.display_x * 32
self.oy = $game_map.display_y * 32
self.visible = !$game_map.no_fog?
end
end
#----------------------------------------------------------------------------
# * Update bitmap
#----------------------------------------------------------------------------
def update_bitmap
bmp = @@bitmap_cache[@id]
unless bmp && !bmp.disposed?
bmp = Bitmap.new(@width * 32, @height * 32)
@@bitmap_cache[@id] = bmp
end
self.bitmap = bmp
return if $game_map.no_fog?
bitmap.entire_fill(Color.new(0,0,0,Theo::FogOpacity))
reveal_tiles($game_system.revealed_tiles)
reveal_tiles($game_player.reveal_tiles)
end
#----------------------------------------------------------------------------
# * Reveal Tiles
#----------------------------------------------------------------------------
def reveal_tiles(tiles)
tiles.each do |pos|
x = pos.x * 32
y = pos.y * 32
bitmap.clear_rect(x,y,32,32)
end unless disposed?
end
end
#===============================================================================
# ** Game_System
#===============================================================================
class Game_System
#----------------------------------------------------------------------------
# * Revealed tiles
#----------------------------------------------------------------------------
def revealed_tiles
@revealed_map ||= {}
@revealed_map[$game_map.map_id] ||= []
@revealed_map[$game_map.map_id]
end
#----------------------------------------------------------------------------
# * Revealed tiles =
#----------------------------------------------------------------------------
def revealed_tiles=(t)
@revealed_map ||= {}
@revealed_map[$game_map.map_id] = t
end
end
#===============================================================================
# ** Revealed Node
#===============================================================================
class Revealed_Node
#----------------------------------------------------------------------------
# * Public attributes
#----------------------------------------------------------------------------
attr_accessor :parent
attr_accessor :visited
attr_accessor :x
attr_accessor :y
attr_reader :expanded
attr_reader :nodes
#----------------------------------------------------------------------------
# * Initialize
#----------------------------------------------------------------------------
def initialize(x,y)
@x ,@y = x, y
@nodes = {}
@visited = false
@expanded = false
end
#----------------------------------------------------------------------------
# * Expand node
#----------------------------------------------------------------------------
def expand_node(mapnodes, char)
dir = [2,4,6,8]
dir.each do |d|
xpos = $game_map.round_x_with_direction(@x, d)
ypos = $game_map.round_y_with_direction(@y, d)
key = [xpos, ypos]
next_node = mapnodes[key]
if next_node.nil?
next_node = Revealed_Node.new(xpos, ypos)
mapnodes[key] = next_node
elsif next_node.visited
next
end
next_node.parent = self
self.nodes[d] = next_node
end
@expanded = true
end
#----------------------------------------------------------------------------
# * Get Parent Direction
#----------------------------------------------------------------------------
def get_parent_dir
parent.nodes.index(self)
end
end
#===============================================================================
# ** Game_Map
#===============================================================================
class Game_Map
#----------------------------------------------------------------------------
# * No fog?
#----------------------------------------------------------------------------
def no_fog?
return false unless @map
return true if @map.note[/<no[\s_]+fog>/i]
return false if @map.note[/<fog>/i]
return !Theo::DefaultFog
end
#----------------------------------------------------------------------------
# * Reveal tiles
#----------------------------------------------------------------------------
def reveal_tiles(x, y, distance = Theo::VisiRange, reveal = true)
return if no_fog?
# Initialize
@revealed_nodes = {}
@max_distance = distance - 1
@init_x = x
@init_y = y
# Make first node to check
first_node = Revealed_Node.new(x, y)
first_node.expand_node(@revealed_nodes, self)
first_node.visited = true
@revealed_nodes[[x, y]] = first_node
@reveal_queue = []
@reveal_queue.push(first_node)
# spread search using BFS
until @reveal_queue.empty?
spread_search(@reveal_queue.shift)
end
node_to_reveal = @revealed_nodes.values - $game_system.revealed_tiles
sprset = SceneManager.scene.spriteset
sprset.fogofwar.reveal_tiles(node_to_reveal) if sprset
$game_system.revealed_tiles += @revealed_nodes.values
end
#----------------------------------------------------------------------------
# * Spread search
#----------------------------------------------------------------------------
def spread_search(node)
dir = [2,4,6,8]
dir.shuffle.each do |d|
next_node = node.nodes[d]
next unless next_node
next if next_node.visited
next if get_distance(next_node) > @max_distance
next_node.expand_node(@revealed_nodes, self) unless next_node.expanded
next_node.visited = true
@reveal_queue.push(next_node, node)
end
end
#----------------------------------------------------------------------------
# * Get distance
#----------------------------------------------------------------------------
def get_distance(node)
range_x = node.x - @init_x
range_y = node.y - @init_y
result = Math.sqrt((range_x**2) + (range_y**2))
return result
end
end
#===============================================================================
# ** Game_Character
#===============================================================================
class Game_Character
#----------------------------------------------------------------------------
# * Reveal tiles
#----------------------------------------------------------------------------
def reveal_tiles(distance = Theo::VisiRange)
$game_map.reveal_tiles(x, y, distance)
end
end
#===============================================================================
# ** Game_Player
#===============================================================================
class Game_Player
#----------------------------------------------------------------------------
# * Increase step
#----------------------------------------------------------------------------
alias theo_fogofwar_increase_steps increase_steps
def increase_steps
theo_fogofwar_increase_steps
reveal_tiles
end
end
#===============================================================================
# ** Spriteset_Map
#===============================================================================
class Spriteset_Map
#----------------------------------------------------------------------------
# * Attribute Reader
#----------------------------------------------------------------------------
attr_reader :fogofwar
#----------------------------------------------------------------------------
# * Create viewports (alias)
#----------------------------------------------------------------------------
alias theo_fogofwar_create_viewports create_viewports
def create_viewports
theo_fogofwar_create_viewports
create_fogofwar
end
#----------------------------------------------------------------------------
# * Create fog of war
#----------------------------------------------------------------------------
def create_fogofwar
@fogofwar = Fog_of_War.new(@viewport1)
@fogofwar.z = 500#210
end
#----------------------------------------------------------------------------
# * Update (alias)
#----------------------------------------------------------------------------
alias theo_fogofwar_update update
def update
theo_fogofwar_update
@fogofwar.update
end
#----------------------------------------------------------------------------
# * Dispose (alias)
#----------------------------------------------------------------------------
alias theo_fogofwar_dispose dispose
def dispose
theo_fogofwar_dispose
@fogofwar.dispose
end
end
#===============================================================================
# ** Scene_Base
#===============================================================================
class Scene_Base
attr_reader :spriteset
end
Ruby:
#==============================================================================
# □ Etude87's KMS MiniMap Add-on ver.1.3.7
#==============================================================================
# * 한국어
# 작성자 : 습작
# 설 명 : KMS MiniMap에 이동경로 그리기 및 포그 기능 등을 추가해주는 스크립트 입니다.
#==============================================================================
# * ENG
# Author : etude87
# Explanation : It is a script that adds movement path drawing and fog function to KMS MiniMap.
#==============================================================================
#
# 현재 문제점 : 지붕타일 정상 작동 안함, FOV 화면 스크롤과 이격, 타일 id 기반 지붕타일 예외 추가 처리 안됨, inRange 필요 여부
#
#==============================================================================
module Etude87_KMS_MiniMap
#--------------------------------------------------------------------------
# 현재 위치 그리기 설정 모음
# Collection of current location drawing settings
#--------------------------------------------------------------------------
# 세모꼴 위치 표시 사용 여부
# Whether to use the triangle mark
USE_TRIANGLE_POINT = true
# 세모꼴 위치 표시 정렬 방식(0:상단, 1:중단, 2:하단)
# Triangle mark position display alignment method(0:top, 1:middle, 2:bottom)
ALIGN_TRIANGLE_POINT = 1
#--------------------------------------------------------------------------
# 미니맵 이동 경로 그리기 설정 모음
# Mini Map Drawing Path Drawing Set Collection
#--------------------------------------------------------------------------
# 이동 경로 그리기 사용 여부
# Whether to use draw path
USE_MOVE_ROUTE = true
# 이동 경로 색상
# Path color
MOVE_ROUTE_COLOR = Color.new(255, 0, 0, 192)
# 이동 경로 길이( 1보다 작은 경우 무제한 )
# Path length (unlimited if less than 1)
MOVE_ROUTE_LENGTH = 50
# 이동 경로 선 굵기
# Thickness of the moving path
LINE_THICKNESS = 1
# 점점 흐려지기 사용 여부
# Increasingly blurred
USE_TRANSPARENCY = true
#--------------------------------------------------------------------------
# 미니맵 포그 기능 설정 모음
# Mini Map fog feature set
#--------------------------------------------------------------------------
# 미니맵 포그 기능 사용 여부
# Whether mini-map fog function is used
USE_FOG = true
# 시야범위 최 외각 처리여부
# Whether the outline of the field is processed
USE_OUTLINE = true
# 시야범위 최 외각 굵기
# Outline thickness
OUTLINE_THICKNESS = 5
# 맵별 예외처리
# Handle exceptions by map
EXCEPTION = {
# ID 1번맵 마름모 시야범위
# ID 1 map rhombus view
#1 => [:lozenge, 5],
# ID 2번맵 정사각형 시야범
# ID 2 map square view
2 => [:square, 4],
# ID 3번맵 원형 시야범위
# ID 3 map round view
#3 => [:circle, 5],
# ID 4번맵 마름모 시야범위
# ID 4 map rhombus view
#4 => [:lozenge, 5],
# ID 5번맵 포그 미사용
# ID 5 map fog unused
#5 => :none,
}#<= 지우지 말것 / Do not erase
#--------------------------------------------------------------------------
# 미니맵 시야각 기능 설정 모음
# Mini Map field of view feature set
#--------------------------------------------------------------------------
# 미니맵 시야각 기능 사용 여부
# Whether mini-map field of view function is used
USE_FOV = true
# 통행설정 기반 시야각 판별 사용 여부
# Use of traffic setting based viewing angle discrimination
Auto_FOV = true
# 지붕 및 벽 시야각 처리 여부
# Handle roof and wall viewing angles
Roof_Wall = true
# 시야각 처리 예외 지형 태그
# Viewing angle handling exception terrain tag
Exception_Terrain_Tag = 1
# 시야각 처리 추가 지형 태그
# View angle handling added terrain tag
Additional_Terrain_Tag = 2
# 시야각 처리 대상 이벤트 이름 키워드
# Viewing angle processing target event name keyword
FOV_Ev_Name_Keyword = "[FOV]"
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_System
attr_reader :route
attr_reader :drawable
#--------------------------------------------------------------------------
alias etude87_initialize initialize
def initialize
@route = []
@drawable = {}
etude87_initialize
end
#--------------------------------------------------------------------------
def add_route(pos)
@route.shift if (Etude87_KMS_MiniMap::MOVE_ROUTE_LENGTH <= @route.size && Etude87_KMS_MiniMap::MOVE_ROUTE_LENGTH >= 1)
@route.push(pos)
px = $game_player.x
py = $game_player.y
m = Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id]
o = Etude87_KMS_MiniMap::USE_OUTLINE
t = Etude87_KMS_MiniMap::OUTLINE_THICKNESS
tx = $game_map.screen_tile_x.to_i
ty = $game_map.screen_tile_y.to_i
dx = $game_map.display_x.to_i
dy = $game_map.display_y.to_i
mw = $game_map.width.to_i
mh = $game_map.height.to_i
if Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id] && Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id] != :none
min_x = px - m[1]
max_x = px + m[1]
min_y = py - m[1]
max_y = py + m[1]
else
min_x = [[px - (tx - 1)/2, 0].max, mw - tx].min
max_x = min_x + tx - 1
min_y = [[py - (ty - 1)/2, 0].max, mh - ty].min
max_y = min_y + ty - 1
if o
min_x -= t if min_x == 0
max_x += t if max_x == mw - 1
min_y -= t if min_y == 0
max_y += t if max_y == mh - 1
end
end
@drawable[pos[0]] ||= {}
for i in dx..(dx + tx)
for j in dy..(dy + ty)
@drawable[pos[0]][i] ||= {}
if Etude87_KMS_MiniMap::USE_FOV
unless checkFOV(px, py, i, j, false)
if @drawable[pos[0]][i][j]
@drawable[pos[0]][i][j] = 1
end
next
end
end
end
end
for x in min_x..max_x
for y in min_y..max_y
@drawable[pos[0]][x] ||= {}
if Etude87_KMS_MiniMap::USE_FOV
unless checkFOV(px, py, x, y, true)
if @drawable[pos[0]][x][y]
@drawable[pos[0]][x][y] = 1
end
next
end
end
if m
case m[0]
when :circle
next if m[1] < Math.sqrt((px - x)**2 + (py - y)**2).to_i
when :lozenge
next if (px - x).abs + (py - y).abs > m[1]
end
end
r = offset(x, min_x, max_x, y, min_y, max_y, px, py)
if @drawable[pos[0]][x][y]
if @drawable[pos[0]][x][y] < r
@drawable[pos[0]][x][y] = r
end
else
@drawable[pos[0]][x][y] = r
end
end
end
end
#--------------------------------------------------------------------------
def checkFOV(x1, y1, x2, y2, inRange)
return true if x1 == x2 && y1 == y2
x = x1
y = y1
counter = 0
result = true
dx = x2 - x1
dy = y2 - y1
if dx.abs > dy.abs
d = dx > 0 ? 6 : 4
elsif dy != 0
d = dy > 0 ? 2 : 8
end
if dx < 0
addX = -1
dx = -dx
else
addX = 1
end
if dy < 0
addY = -1
dy = -dy
else
addY = 1
end
if dx >= dy
for i in 0...dx
x += addX
counter += dy
if counter >= dx
y += addY
counter -= dx
end
unless $game_map.viewable?(x, y, d)
result = false unless (x == x2 && y == y2)
break
end
end
else
for i in 0...dy
y += addY
counter += dx
if counter >= dy
x += addX
counter -= dy
end
unless $game_map.viewable?(x, y, d)
result = false unless (x == x2 && y == y2)
break
end
end
end
return result
end
#--------------------------------------------------------------------------
def offset(x, min_x, max_x, y, min_y, max_y, px, py)
t = Etude87_KMS_MiniMap::OUTLINE_THICKNESS
return t unless Etude87_KMS_MiniMap::USE_OUTLINE
if Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id]
m = Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id]
case m[0]
when :square
a = (x - min_x).abs if (x - min_x).abs < t
b = (x - max_x).abs if (x - max_x).abs < t
c = (y - min_y).abs if (y - min_y).abs < t
d = (y - max_y).abs if (y - max_y).abs < t
when :circle
i = m[1] - Math.sqrt((px - x)**2 + (py - y)**2).to_i
a = i if i < t
when :lozenge
a = m[1] - ((px - x).abs + (py - y).abs) if m[1] - ((px - x).abs + (py - y).abs) < t
end
else
a = (x - min_x).abs if (x - min_x).abs < t
b = (x - max_x).abs if (x - max_x).abs < t
c = (y - min_y).abs if (y - min_y).abs < t
d = (y - max_y).abs if (y - max_y).abs < t
end
return [a,b,c,d,t].compact.min
end
#--------------------------------------------------------------------------
def clear_route
@route = []
end
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_Event < Game_Character
#--------------------------------------------------------------------------
attr_reader :event
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_Map
#--------------------------------------------------------------------------
def viewable?(x, y, d)
check_view(x, y, (1 << (d / 2 - 1)) & 0x0f)
end
#--------------------------------------------------------------------------
def check_view(x, y, bit)
all_tiles(x, y).each do |tile_id|
unless events_xy(x, y).empty?
ev = events_xy(x, y)[0]
return false if ev.event.name.include?(Etude87_KMS_MiniMap::FOV_Ev_Name_Keyword) && ev.normal_priority?
end
return false if terrain_tag(x, y) == Etude87_KMS_MiniMap::Additional_Terrain_Tag
flag = tileset.flags[tile_id]
if flag & 0x10 != 0
next if flag & bit == 0
else
return true if flag & bit == 0
end
return true if terrain_tag(x, y) == Etude87_KMS_MiniMap::Exception_Terrain_Tag
return false if tile_id >= 4352 && tile_id <= 8191 && Etude87_KMS_MiniMap::Roof_Wall
return false if flag & bit == bit && Etude87_KMS_MiniMap::Auto_FOV
end
return false
end
#--------------------------------------------------------------------------
def reveal_tiles(x, y, distance = Theo::VisiRange, reveal = true)
return if no_fog?
sprset = SceneManager.scene.spriteset
sprset.fogofwar.reveal_fogs if sprset
end
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
alias etude87_moveto moveto
def moveto(x, y)
etude87_moveto(x, y)
@last_pos = [$game_map.map_id, @x, @y, 5]
$game_system.add_route(@last_pos)
end
#--------------------------------------------------------------------------
alias etude87_increase_steps increase_steps
def increase_steps
$game_system.add_route(@last_pos) if @last_pos
@last_pos = [$game_map.map_id, @x, @y, @direction]
etude87_increase_steps
end
#--------------------------------------------------------------------------
alias etude87_reserve_transfer reserve_transfer
def reserve_transfer(map_id, x, y, d = 2)
etude87_reserve_transfer(map_id, x, y, d)
$game_system.clear_route
end
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Game_MiniMap
#--------------------------------------------------------------------------
alias etude87_create_sprites create_sprites
def create_sprites
unless Etude87_KMS_MiniMap::USE_TRIANGLE_POINT
etude87_create_sprites
else
@viewport = Viewport.new(@map_rect)
@viewport.z = KMS_MiniMap::MAP_Z
@bmp_size = Size.new(
(@grid_num.x + 2) * @grid_size,
(@grid_num.y + 2) * @grid_size
)
@buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
@map_sprite = Sprite.new(@viewport)
@map_sprite.x = -@grid_size
@map_sprite.y = -@grid_size
@map_sprite.z = 0
@map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
@object_sprite = Sprite_MiniMapIcon.new(@viewport)
@object_sprite.x = -@grid_size
@object_sprite.y = -@grid_size
@object_sprite.z = 1
@object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
@position_sprite = Sprite_MiniMapIcon.new
@position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
@position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
@position_sprite.z = @viewport.z + 2
bitmap = Bitmap.new(@grid_size, @grid_size)
case Etude87_KMS_MiniMap::ALIGN_TRIANGLE_POINT
when 0
align_tp = 0
when 1
align_tp = @grid_size/4
when 2
align_tp = @grid_size/2
end
@last_dir = $game_player.direction
for i in 0...(@grid_size/2 + @grid_size%2)
case @last_dir
when 2
bitmap.fill_rect(@grid_size/2-i, @grid_size-i-1-align_tp, 2*i+1, 1, KMS_MiniMap::POSITION_COLOR)
when 4
bitmap.fill_rect(i+align_tp, @grid_size/2-i, 1, 2*i+1, KMS_MiniMap::POSITION_COLOR)
when 6
bitmap.fill_rect(@grid_size-i-1-align_tp, @grid_size/2-i, 1, 2*i+1, KMS_MiniMap::POSITION_COLOR)
when 8
bitmap.fill_rect(@grid_size/2-i, i+align_tp, 2*i+1, 1, KMS_MiniMap::POSITION_COLOR)
end
end
@position_sprite.bitmap = bitmap
end
end
#--------------------------------------------------------------------------
alias etude87_update_position update_position
def update_position
etude87_update_position
return unless Etude87_KMS_MiniMap::USE_TRIANGLE_POINT
return unless @last_dir != $game_player.direction
@position_sprite.bitmap.clear
bitmap = Bitmap.new(@grid_size, @grid_size)
case Etude87_KMS_MiniMap::ALIGN_TRIANGLE_POINT
when 0
align_tp = 0
when 1
align_tp = @grid_size/4
when 2
align_tp = @grid_size/2
end
@last_dir = $game_player.direction
for i in 0...(@grid_size/2 + @grid_size%2)
case @last_dir
when 2
bitmap.fill_rect(@grid_size/2-i, @grid_size-i-1-align_tp, 2*i+1, 1, KMS_MiniMap::POSITION_COLOR)
when 4
bitmap.fill_rect(i+align_tp, @grid_size/2-i, 1, 2*i+1, KMS_MiniMap::POSITION_COLOR)
when 6
bitmap.fill_rect(@grid_size-i-1-align_tp, @grid_size/2-i, 1, 2*i+1, KMS_MiniMap::POSITION_COLOR)
when 8
bitmap.fill_rect(@grid_size/2-i, i+align_tp, 2*i+1, 1, KMS_MiniMap::POSITION_COLOR)
end
end
@position_sprite.bitmap = bitmap
end
#--------------------------------------------------------------------------
alias etude87_draw_map_foreground draw_map_foreground
def draw_map_foreground(bitmap)
if Etude87_KMS_MiniMap::USE_FOG && Etude87_KMS_MiniMap::EXCEPTION[$game_map.map_id] != :none
range_x = (@draw_range_begin.x)..(@draw_range_end.x)
range_y = (@draw_range_begin.y)..(@draw_range_end.y)
map_w = $game_map.width - 1
map_h = $game_map.height - 1
rect = Rect.new(0, 0, @grid_size, @grid_size)
range_x.each { |x|
next unless x.between?(0, map_w)
next unless $game_system.drawable[$game_map.map_id][x]
range_y.each { |y|
next unless y.between?(0, map_h)
next unless $game_system.drawable[$game_map.map_id][x][y]
next if @passage_table[x, y] == 0
next if @wall_events.find { |e| e.x == x && e.y == y }
rect.set(0, 0, @grid_size, @grid_size)
rect.x = (x - @draw_range_begin.x) * @grid_size
rect.y = (y - @draw_range_begin.y) * @grid_size
flag = @passage_table[x, y]
if flag & 0x01 == 0
rect.height -= 1
end
if flag & 0x02 == 0
rect.x += 1
rect.width -= 1
end
if flag & 0x04 == 0
rect.width -= 1
end
if flag & 0x08 == 0
rect.y += 1
rect.height -= 1
end
color = outline_color($game_system.drawable[$game_map.map_id][x][y])
bitmap.fill_rect(rect, color)
}
}
else
etude87_draw_map_foreground(bitmap)
end
if Etude87_KMS_MiniMap::USE_MOVE_ROUTE
if $game_system.route.size > 0
for i in 0...$game_system.route.size
draw_route(bitmap, i)
end
end
end
end
#--------------------------------------------------------------------------
alias etude87_draw_map_move_event draw_map_move_event
def draw_map_move_event(bitmap)
if Etude87_KMS_MiniMap::USE_FOG
rect = Rect.new(0, 0, @grid_size, @grid_size)
@move_events.each { |e|
rect.x = (e.x - @draw_range_begin.x) * @grid_size
rect.y = (e.y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR) if map_visible?(e.x, e.y)
}
else
etude87_draw_map_move_event(bitmap)
end
end
#--------------------------------------------------------------------------
alias etude87_draw_object draw_object
def draw_object
if Etude87_KMS_MiniMap::USE_FOG
bitmap = @object_sprite.bitmap
bitmap.clear
rect = Rect.new(0, 0, @grid_size, @grid_size)
@object_list.each { |obj|
next unless in_draw_range?(obj.x, obj.y)
color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
next if color.nil?
rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, color) if map_visible?(obj.real_x, obj.real_y)
}
$game_map.vehicles.each { |vehicle|
next if vehicle.transparent
rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR) if map_visible?(vehicle.real_x, vehicle.real_y)
}
else
etude87_draw_object
end
end
#--------------------------------------------------------------------------
def outline_color(i)
t = Etude87_KMS_MiniMap::OUTLINE_THICKNESS
c1 = KMS_MiniMap::BACKGROUND_COLOR
c2 = KMS_MiniMap::FOREGROUND_COLOR
red = c2.red + (c1.red - c2.red) /(t + 1) * (t - i)
green = c2.green + (c1.green - c2.green)/(t + 1) * (t - i)
blue = c2.blue + (c1.blue - c2.blue) /(t + 1) * (t - i)
alpha = c2.alpha + (c1.alpha - c2.alpha)/(t + 1) * (t - i)
return Color.new(red, green, blue, alpha)
end
#--------------------------------------------------------------------------
def map_visible?(x, y)
return false unless $game_system.drawable[$game_map.map_id]
return false unless $game_system.drawable[$game_map.map_id][x]
return false unless $game_system.drawable[$game_map.map_id][x][y]
return true
end
#--------------------------------------------------------------------------
def draw_route(bitmap, i)
a = i+1 < $game_system.route.size ? $game_system.route[i+1][3] : $game_player.direction
r = $game_system.route[i]
x = (r[1] - @draw_range_begin.x) * @grid_size
y = (r[2] - @draw_range_begin.y) * @grid_size
draw_line(bitmap, x, y, a, i)
draw_line(bitmap, x, y, 10-r[3], i)
end
#--------------------------------------------------------------------------
def draw_line(bitmap, x, y, dir, i)
t = Etude87_KMS_MiniMap::LINE_THICKNESS
l = ((@grid_size - t) - (@grid_size - t)%2)/2 + t
case dir
when 2
rect = Rect.new(0, 0, t, l)
rect.x = x + l - t
rect.y = y + l - t
when 4
rect = Rect.new(0, 0, l, t)
rect.x = x
rect.y = y + l - t
when 6
rect = Rect.new(0, 0, l, t)
rect.x = x + l - t
rect.y = y + l - t
when 8
rect = Rect.new(0, 0, t, l)
rect.x = x + l - t
rect.y = y
end
bitmap.fill_rect(rect, line_color(KMS_MiniMap::FOREGROUND_COLOR, Etude87_KMS_MiniMap::MOVE_ROUTE_COLOR, i)) if rect
end
#--------------------------------------------------------------------------
def line_color(c1, c2, i)
return c2 unless Etude87_KMS_MiniMap::USE_TRANSPARENCY
red = c2.red + (c1.red - c2.red)/$game_system.route.size * ($game_system.route.size - i)
green = c2.green + (c1.green - c2.green)/$game_system.route.size * ($game_system.route.size - i)
blue = c2.blue + (c1.blue - c2.blue)/$game_system.route.size * ($game_system.route.size - i)
alpha = c2.alpha + (c1.alpha - c2.alpha)/$game_system.route.size * ($game_system.route.size - i)
return Color.new(red, green, blue, alpha)
end
#--------------------------------------------------------------------------
end
#==============================================================================
#==============================================================================
class Fog_of_War < Plane
#----------------------------------------------------------------------------
def update_bitmap
bmp = @@bitmap_cache[@id]
unless bmp && !bmp.disposed?
bmp = Bitmap.new(@width * 32, @height * 32)
@@bitmap_cache[@id] = bmp
end
self.bitmap = bmp
return if $game_map.no_fog?
bitmap.entire_fill(Color.new(0,0,0,Theo::FogOpacity))
reveal_fogs
end
#----------------------------------------------------------------------------
def reveal_fogs
for x in 0..@width
for y in 0..@height
next unless ($game_system.drawable[$game_map.map_id][x] && $game_system.drawable[$game_map.map_id][x][y])
width = 32
height = 32
fog_x = x * width
fog_y = y * height
bitmap.clear_rect(fog_x,fog_y,width,height)
if $game_system.drawable[$game_map.map_id][x] && $game_system.drawable[$game_map.map_id][x][y]
t = Etude87_KMS_MiniMap::OUTLINE_THICKNESS
i = $game_system.drawable[$game_map.map_id][x][y]
alpha = 255 / (t + 1) * (t - i)
bitmap.fill_rect(fog_x,fog_y,width,height,Color.new(0,0,0,alpha)) if alpha > 0
end
end
end unless disposed?
end
#----------------------------------------------------------------------------
end
Downloads / Referenced Files
Log in to download
Log in, then follow the RPG Maker Developers Group to see these download links.
Log in to downloadCreator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
0
replies
1
view
Topic Summary
Loading summary...