# =========================================================================== # ◆ A1 Scripts ◆ # 範囲フラッシュ表示スクリプト(RGSS2) # # バージョン : 1.10 (2011/11/9) # 作者 : A1 # URL     : http://a1-nayuta.seesaa.net/ # --------------------------------------------------------------------------- # 機能: # ・シミュレーションゲームなどによくある、移動範囲のフラッシュを表示させます # --------------------------------------------------------------------------- # 更新履歴   :2011/11/9 Ver1.00 新規作成 #        :2011/11/9 Ver1.01 KGC様「タイルセット拡張」競合対応 #        :2011/11/9 Ver1.10 軽量化 # --------------------------------------------------------------------------- # 設置場所 #  VX_SP1 以下 # KGC様の「タイルセット拡張」使用時は # 「タイルセット拡張」以下に設置 # # 必要スクリプト #  なし # # 使い方 #  中心にしたいイベントのイベントID、フラッシュ距離を変数に代入し #  その後で範囲フラッシュ表示開始スイッチをONにします # #  範囲フラッシュを消去する場合は #  中心にしたイベントのイベントIDを変数に代入し #  範囲フラッシュ消去スイッチをONにします # #  プレイヤーを中心にする場合は #  イベントIDの変数に 0 を代入します # #  それぞれの変数・スイッチのNoは設定項目で設定します # # 慣れている方向け # # [範囲フラッシュ作成時] #  範囲フラッシュの距離(移動力)を引数にして #  Game_Characterクラスの create_area(distance) メソッドで #  範囲フラッシュ用通行設定を作成し # #  範囲フラッシュ用通行設定を引数にして #  Spriteset_Mapクラスの create_area_flash(area_passages) メソッドで #  範囲フラッシュを作成・表示させています # # [範囲フラッシュ消去時] #  Game_Characterクラスの erase_area_flash メソッドで #  範囲フラッシュ用通行設定を初期化し # #  Spriteset_Mapクラスの dispose_area_flash メソッドで #  範囲フラッシュを解放しています # # [消費移動力] #  Game_Mapクラスの move_cost(x, y) メソッドで定義しています #  指定座標に対応する消費移動力をreturnしてください # # --------------------------------------------------------------------------- # 注意事項: # ▽ あまり移動距離を長くすると範囲作成に時間がかかり # もしくは表示されずに止まる可能性があります #============================================================================== # ■ 設定項目 #============================================================================== module A1_System module Setting # 表示トリガー&範囲設定にスイッチ・変数を使う? (使う=true) USE_SWITCH_VARIABLE = true # 範囲フラッシュ距離変数No DISTANCE_VARIABLE = 3 # 範囲フラッシュ対象ID変数No TARGET_VARIABLE = 4 # 範囲フラッシュ表示開始スイッチNo START_SWITCH = 1 # 範囲フラッシュ消去スイッチNo ERASE_SWITCH = 2 #-------------------------------------------------------------------------- # イベントグループ (プレイヤーのIDは 0) # # 同グループ :すり抜け可 # MAP指定なし:通行可能判定準拠 # nil    :全てのイベントがすり抜け可 #-------------------------------------------------------------------------- EVENT_GROUP = { 1 => [ # MAP_ID [0, 2, 3], # グループ1 [4, 5], # グループ2 [6, 7], # グループ3 ], 3 => [ # MAP_ID [0, 1], # グループ1 ], 25 => nil, } end end $imported = {} if $imported == nil $imported["A1_Area_Flash"] = true #============================================================================== # ■ Game_Character #------------------------------------------------------------------------------ #  キャラクターを扱うクラスです。このクラスは Game_Player クラスと Game_Event # クラスのスーパークラスとして使用されます。 #============================================================================== class Game_Character #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :area_passages # 範囲フラッシュの通行設定 attr_reader :area_info # 範囲フラッシュの内容 #-------------------------------------------------------------------------- # ☆ オブジェクト初期化 #-------------------------------------------------------------------------- alias a1_area_flash_game_character_initialize initialize unless $@ def initialize @area_passages = nil @area_info = nil a1_area_flash_game_character_initialize end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ作成 # distance : 範囲フラッシュの距離 #-------------------------------------------------------------------------- def create_area(distance) @area_info = [self.x, self.y, distance] @area_passages = create_area_passages(self.x, self.y, distance) return @area_passages end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ消去 #-------------------------------------------------------------------------- def erase_area_flash @area_passages = nil @area_info = nil end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ再作成 #-------------------------------------------------------------------------- def recreate_area @area_passages = create_area_passages(@area_info[0], @area_info[1], @area_info[2]) return @area_passages end if $imported["TilesetExtension"] #-------------------------------------------------------------------------- # ☆ 通行可能判定(KGC様 タイルセット拡張 対応) #-------------------------------------------------------------------------- alias a1_area_flash_game_character_passable? passable? unless $@ def passable?(x, y, d = 10) # フラッシュ範囲通行設定がない if @area_passages == nil return a1_area_flash_game_character_passable?(x, y, d) # フラッシュ範囲通行設定を使用 else return area_passable?(x, y) end end else #-------------------------------------------------------------------------- # ☆ 通行可能判定 #-------------------------------------------------------------------------- alias a1_area_flash_game_character_passable? passable? unless $@ def passable?(x, y) # フラッシュ範囲通行設定がない if @area_passages == nil return a1_area_flash_game_character_passable?(x, y) # フラッシュ範囲通行設定を使用 else return area_passable?(x, y) end end end #-------------------------------------------------------------------------- # ○ フラッシュ範囲通行判定 #-------------------------------------------------------------------------- def area_passable?(x, y) # フラッシュ範囲通行設定にx座標がない return false if @area_passages[x] == nil # フラッシュ範囲通行設定にy座標がない return false if @area_passages[x][y] == nil # フラッシュ範囲通行設定が0未満 return false if @area_passages[x][y] < 0 # 通行可能判定 return true end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ通行判定の作成 #-------------------------------------------------------------------------- def create_area_passages(x, y, distance) return if self.area_info == nil # 初期化 area_passages = {} area_passages[x] = {} # 初期位置のセット area_passages[x][y] = distance # 4方向検索 search4(x, y, distance, area_passages) return area_passages end #-------------------------------------------------------------------------- # ○ 4方向検索 #-------------------------------------------------------------------------- def search4(x, y, distance, area_passages) search(x, y - 1, distance, area_passages) search(x - 1, y, distance, area_passages) search(x, y + 1, distance, area_passages) search(x + 1, y, distance, area_passages) end #-------------------------------------------------------------------------- # ○ 検索 #-------------------------------------------------------------------------- def search(x, y, distance, area_passages) # nilの場合初期化 area_passages[x] = {} if area_passages[x] == nil area_passages[x][y] = -1 if area_passages[x][y] == nil # 通行不可 return if area_passages[x][y] == nil return if distance == nil # 検索済 return if distance - 1 < area_passages[x][y] # 消費移動力取得 move_cost = $game_map.move_cost(x, y) # 検索済 return if area_passages[x][y] == distance - move_cost # 通行判定 if flash_area_passable?(x, y) distance -= move_cost else distance = nil end # 残り歩数をセット area_passages[x][y] = distance #end # 再帰 search4(x, y, distance, area_passages) end if $imported["TilesetExtension"] #-------------------------------------------------------------------------- # ○ 通行可能判定(KGC様 タイルセット拡張 対応) #-------------------------------------------------------------------------- def flash_area_passable?(x, y) return passable?(x, y, self.direction) unless A1_System::Setting::EVENT_GROUP.include?($game_map.map_id) group = A1_System::Setting::EVENT_GROUP[$game_map.map_id] # 元々通行可能 if passable?(x, y, self.direction) # ALLフリー return true if group == nil # イベントグループを参照 target_group = search_group(group) for i in 0...group.size next if group[i] == target_group return false if event_passable?(x, y, group[i]) end return true # 元々通行不可 else # マップが通行不可 return false unless map_passable?(x, y, self.direction) # ALLフリー return true if group == nil # イベントグループを参照 target_group = search_group(group) for i in 0...group.size next if group[i] != target_group return event_passable?(x, y, group[i]) end end return false end else #-------------------------------------------------------------------------- # ○ 通行可能判定 #-------------------------------------------------------------------------- def flash_area_passable?(x, y) return passable?(x, y) unless A1_System::Setting::EVENT_GROUP.include?($game_map.map_id) group = A1_System::Setting::EVENT_GROUP[$game_map.map_id] # 元々通行可能 if passable?(x, y) # ALLフリー return true if group == nil # イベントグループを参照 target_group = search_group(group) for i in 0...group.size next if group[i] == target_group return false if event_passable?(x, y, group[i]) end return true # 元々通行不可 else # マップが通行不可 return false unless map_passable?(x, y) # ALLフリー return true if group == nil # イベントグループを参照 target_group = search_group(group) for i in 0...group.size next if group[i] != target_group return event_passable?(x, y, group[i]) end end return false end end #-------------------------------------------------------------------------- # ○ イベントを通過可能か? #-------------------------------------------------------------------------- def event_passable?(x, y, target_group) for id in target_group if id == 0 ev = $game_player else ev = $game_map.events[id] end next if ev == nil return true if ev.x == x and ev.y == y end return false end #-------------------------------------------------------------------------- # ○ グループ検索 #-------------------------------------------------------------------------- def search_group(group) for i in 0...group.size for id in group[i] return group[i] if id == self.id end end return nil end end #============================================================================== # ■ Scene_Map #------------------------------------------------------------------------------ #  マップ画面の処理を行うクラスです。 #============================================================================== class Scene_Map < Scene_Base #-------------------------------------------------------------------------- # ☆ 開始処理 #-------------------------------------------------------------------------- alias a1_area_flash_scene_map_start start unless $@ def start a1_area_flash_scene_map_start create_area_flash end #-------------------------------------------------------------------------- # ☆ フレーム更新 #-------------------------------------------------------------------------- alias a1_area_flash_scene_map_update update unless $@ def update a1_area_flash_scene_map_update update_area_flash end #-------------------------------------------------------------------------- # ○ 範囲フラッシュの作成 #-------------------------------------------------------------------------- def create_area_flash # マップ復帰時の再作成 if $game_player.area_info != nil @spriteset.create_area_flash($game_player.recreate_area) else for event in $game_map.events.values if event.area_info != nil @spriteset.create_area_flash(event.recreate_area(@spriteset)) break end end end end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ開始・終了スイッチの監視 #-------------------------------------------------------------------------- def update_area_flash # スイッチ&変数使用 if A1_System::Setting::USE_SWITCH_VARIABLE # 範囲フラッシュ表示開始 if $game_switches[A1_System::Setting::START_SWITCH] # スイッチ初期化 $game_switches[A1_System::Setting::START_SWITCH] = false # 中心位置・距離設定 distance = $game_variables[A1_System::Setting::DISTANCE_VARIABLE] # 範囲フラッシュ対象イベント event = target_event($game_variables[A1_System::Setting::TARGET_VARIABLE]) # 範囲フラッシュ表示 @spriteset.create_area_flash(event.create_area(distance)) # 変数初期化 $game_variables[A1_System::Setting::DISTANCE_VARIABLE] = 0 $game_variables[A1_System::Setting::TARGET_VARIABLE] = 0 end # 範囲フラッシュ消去 if $game_switches[A1_System::Setting::ERASE_SWITCH] # スイッチ初期化 $game_switches[A1_System::Setting::ERASE_SWITCH] = false # 範囲フラッシュ対象イベント event = target_event($game_variables[A1_System::Setting::TARGET_VARIABLE]) # 変数初期化 $game_variables[A1_System::Setting::TARGET_VARIABLE] = 0 # 範囲フラッシュの解放 event.erase_area_flash @spriteset.dispose_area_flash end end end #-------------------------------------------------------------------------- # ○ 範囲フラッシュ対象イベント #-------------------------------------------------------------------------- def target_event(id) return $game_player if id == 0 return $game_map.events[id] end end #============================================================================== # ■ Game_Player #------------------------------------------------------------------------------ #  プレイヤーを扱うクラスです。イベントの起動判定や、マップのスクロールなどの # 機能を持っています。このクラスのインスタンスは $game_player で参照されます。 #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ● 場所移動の予約 # map_id : マップ ID # x : X 座標 # y : Y 座標 # direction : 移動後の向き #-------------------------------------------------------------------------- alias a1_area_flash_reserve_transfer reserve_transfer unless $@ def reserve_transfer(map_id, x, y, direction) a1_area_flash_reserve_transfer(map_id, x, y, direction) @area_passages = nil @area_info = nil end end #============================================================================== # ■ Spriteset_Map #------------------------------------------------------------------------------ #  マップ画面のスプライトやタイルマップなどをまとめたクラスです。このクラスは # Scene_Map クラスの内部で使用されます。 #============================================================================== class Spriteset_Map #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reader :flash_area # フラッシュ範囲 #-------------------------------------------------------------------------- # ☆ オブジェクト初期化 #-------------------------------------------------------------------------- alias a1_area_flash_initialize initialize unless $@ def initialize @flash_area = [] @flash_bitmap = Bitmap.new("Graphics/Pictures/黒セル.png") @flash_tone = Tone.new(252,252,252) @flash_tone_num = -4 a1_area_flash_initialize end #-------------------------------------------------------------------------- # ☆ フレーム更新 #-------------------------------------------------------------------------- alias a1_area_flash_update update unless $@ def update a1_area_flash_update update_area_flash end #-------------------------------------------------------------------------- # ☆ 解放 #-------------------------------------------------------------------------- alias a1_area_flash_dispose dispose unless $@ def dispose a1_area_flash_dispose dispose_area_flash end #-------------------------------------------------------------------------- # ○ 範囲フラッシュの解放 #-------------------------------------------------------------------------- def dispose_area_flash return if @flash_sprite == nil @flash_area = [] for sprite in @flash_sprite sprite.visible = false sprite.dispose end @flash_sprite = nil end #-------------------------------------------------------------------------- # ○ 範囲フラッシュの作成 #-------------------------------------------------------------------------- def create_area_flash(area_passages) @flash_sprite = [] @flash_area = [] # フラッシュ範囲配列をセット for x in area_passages.keys for y in area_passages[x].keys # 通行不可 next if area_passages[x][y] == nil # 通行可 if area_passages[x][y] >= 0 @flash_sprite.push(set_sprite(x,y)) @flash_area.push([x, y]) end end end end #-------------------------------------------------------------------------- # ○ スプライトの作成 #-------------------------------------------------------------------------- def set_sprite(x, y) x = screen_x(x * 256) y = screen_y(y * 256) flash_sprite = Sprite.new flash_sprite.visible = false flash_sprite.bitmap = @flash_bitmap flash_sprite.x = x flash_sprite.y = y flash_sprite.z = 1 flash_sprite.opacity = 80 flash_sprite.visible = true return flash_sprite end #-------------------------------------------------------------------------- # ○ 範囲フラッシュの更新 #-------------------------------------------------------------------------- def update_area_flash return if @flash_sprite == nil # 範囲フラッシュの更新 for i in 0...@flash_sprite.size next if @flash_sprite[i] == nil @flash_sprite[i].update @flash_sprite[i].tone = @flash_tone pos = @flash_area[i] @flash_sprite[i].x = screen_x(pos[0]*256) @flash_sprite[i].y = screen_y(pos[1]*256) end @flash_tone.red += @flash_tone_num @flash_tone.green += @flash_tone_num @flash_tone.blue += @flash_tone_num @flash_tone_num = 4 if @flash_tone.red == 0 @flash_tone_num = -4 if @flash_tone.red == 252 end #-------------------------------------------------------------------------- # ○ 画面 X 座標の取得 #-------------------------------------------------------------------------- def screen_x(real_x) return ($game_map.adjust_x(real_x) + 8007) / 8 - 1000 end #-------------------------------------------------------------------------- # ○ 画面 Y 座標の取得 #-------------------------------------------------------------------------- def screen_y(real_y) y = ($game_map.adjust_y(real_y) + 8007) / 8 - 1000 end end #============================================================================== # ■ Game_Map #------------------------------------------------------------------------------ #  マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。 # このクラスのインスタンスは $game_map で参照されます。 #============================================================================== class Game_Map #-------------------------------------------------------------------------- # ○ 消費移動力(オーバーライドして使用) #-------------------------------------------------------------------------- def move_cost(x, y) return 1 end end