橙光脚本1

发布时间:2014-07-12 17:18:51

#_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ #_/ ◆ 图块扩张 - KGC_TilesetExtension ◆ VX ◆ #_/ ◇ Last update : 2008/01/20 ◇ #_/---------------------------------------------------------------------------- #_/ 变更图块图像、增加4方向通行、地形标记功能。 #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ #============================================================================== # ★ 自定义項目 - Customize ★ #============================================================================== module KGC module TilesetExtension # ◆ 图块图像的字首 # 图块图像名称前方的文字(如 TileA1 中的 Tile) TILE_IMAGE_PREFIX = "Tile" # ◆ 预设的图块图像 # 使用[SET <预设组名称>]设定。 TILE_PRESET = {} # ← 这行不可删除 # 预设在下方。 # ↓范例 TILE_PRESET["魔王之城"] = { "A1"=>"A1-Maou", "A2"=>"A2-Maou", "B"=>"B-Maou", "D"=>"D-Maou", } # 使用时,在地图名插入[SET 魔王之城] # ◆ 4方向通行、地形标记确认的按钮 (DEBUG用) # 按下此键之时,就会以对话框的方式显现 # 当前玩家所在图块的可通行方向和地形标记。 # 当设定为nil时则关闭此功能 # ※ 此功能只有在游戏测试时有效 DEBUG_INFO_BUTTON = Input::F7 end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ $imported = {} if $imported == nil $imported["TilesetExtension"] = true if $data_mapinfos == nil $data_mapinfos = load_data("Data/MapInfos.rvdata") end # 方向通行度 (4方向通行对应) module DirectionFlag DOWN = 0x01 LEFT = 0x02 RIGHT = 0x04 UP = 0x08 end module KGC::TilesetExtension # 扩张时储存的档案名称 EX_RVDATA = "TilesetEx.rvdata" # 正規表現 module Regexp # 継承 INHERIT = /\[INHERIT\]/i # プリセット PRESET = /\[SET ([\w\-]+)\]/i end # デフォルトタイルセットファイル名 DEFAULT_FILENAME = { "A1"=>"TileA1", "A2"=>"TileA2", "A3"=>"TileA3", "A4"=>"TileA4", "A5"=>"TileA5", "B"=>"TileB", "C"=>"TileC", "D"=>"TileD", "E"=>"TileE" } @@__filename = DEFAULT_FILENAME.dup module_function #-------------------------------------------------------------------------- # ○ 指定マップのタイル画像ファイル名初期化 # map_id : マップ ID #-------------------------------------------------------------------------- def init_tileset_filename(map_id) @@__filename = get_converted_tileset_filename(map_id) end #-------------------------------------------------------------------------- # ○ 変換後のタイル画像ファイル名を取得 # map_id : マップ ID #--- events.values.find { |e| e.id == event_id } if event == nil # 該当するイベントが無ければ 0 tag = 0 else tag = $game_map.terrain_tag(event.x, event.y) end # 指定された変数に代入 if variable_id > 0 $game_variables[variable_id] = tag end return tag end #-------------------------------------------------------------------------- # ○ プレイヤーの位置の地形タグ取得 # variable_id : 取得した地形タグを代入する変数の ID #-------------------------------------------------------------------------- def get_player_terrain_tag(variable_id = 0) tag = $game_map.terrain_tag($game_player.x, $game_player.y) # 指定された変数に代入 if variable_id > 0 $game_variables[variable_id] = tag end return tag end end class Game_Interpreter include KGC::Commands end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # ■ RPG::MapInfo #============================================================================== class RPG::MapInfo #-------------------------------------------------------------------------- # ● マップ名取得 #-------------------------------------------------------------------------- def name return @name.gsub(/\[.*\]/) { "" } end #-------------------------------------------------------------------------- # ○ オリジナルマップ名取得 #-------------------------------------------------------------------------- def original_name return @name end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # □ RPG::Tileset #------------------------------------------------------------------------------ # タイルセットの付加的情報を扱うクラスです。 #============================================================================== class RPG::Tileset #-------------------------------------------------------------------------- # ○ 定数 #-------------------------------------------------------------------------- TABLE_SIZE = 8192 # 通行・地形タグテーブルのサイズ #-------------------------------------------------------------------------- # ○ 公開インスタンス変数 #-------------------------------------------------------------------------- attr_accessor :version # 内部バージョン attr_accessor :passages # 4 方向通行フラグ attr_accessor :terrain_tags # 地形タグ #-------------------------------------------------------------------------- # ○ オブジェ クト初期化 #-------------------------------------------------------------------------- def initialize @version = 1 @passages = Table.new(TABLE_SIZE) @terrain_tags = Table.new(TABLE_SIZE) end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # ■ Game_Map #============================================================================== class Game_Map LAYERS = [2, 1, 0] #-------------------------------------------------------------------------- # ● セットアップ # map_id : マップ ID #-------------------------------------------------------------------------- alias setup_KGC_TilesetExtension setup def setup(map_id) # タイルセット画像ファイル名を初期化 KGC::TilesetExtension.init_tileset_filename(map_id) setup_KGC_TilesetExtension(map_id) end #-------------------------------------------------------------------------- # ○ 指定座標の通行フラグ取得 # x : X 座標 # y : Y 座標 #-------------------------------------------------------------------------- def passage(x, y) LAYERS.each { |i| tile_id = @map.data[x, y, i] return 0 if tile_id == nil return $data_tileset.passages[tile_id] } return 0 end #-------------------------------------------------------------------------- # ○ 指定座標の地形タグ取得 # x : X 座標 # y : Y 座標 #-------------------------------------------------------------------------- def terrain_tag(x, y) LAYERS.each { |i| tile_id = @map.data[x, y, i] # タイル ID を取得 return 0 if tile_id == nil # タイル ID 取得失敗 : タグなし tag = $data_tileset.terrain_tags[tile_id] # 地形タグを取得 return tag if tag > 0 # タグが設定してあれば返す } return 0 end #-------------------------------------------------------------------------- # ○ 指定方向通行可能判定 # x : X 座標 # y : Y 座標 # d : 移動方向 #-------------------------------------------------------------------------- def passable_dir?(x, y, d) # 方向 (0,2,4,6,8,10) から 通行フラグ (0,1,2,4,8,0) に変換 flag = (1 << (d / 2 - 1)) & 0x0F LAYERS.each { |i| # レイヤーの上から順に調べる tile_id = @map.data[x, y, i] # タイル ID を取得 return false if tile_id == nil # タイル ID 取得失敗 : 通行不可 pass = $data_tileset.passages[tile_id] # タイルセットの通行属性を取得 return false if pass & flag != 0x00 # フラグが立っていたら通行不可 } return true end end #★☆★ ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # ■ Game_Character #============================================================================== class Game_Character #-------------------------------------------------------------------------- # ○ 通行可能判定 # x : X 座標 # y : Y 座標 # d : 移動方向 (省略時: 10) #-------------------------------------------------------------------------- def passable?(x, y, d = 10) nx = moved_x(x, d) ny = moved_y(y, d) nx = $game_map.round_x(nx) # 横方向ループ補正 ny = $game_map.round_y(ny) # 縦方向ループ補正 return false unless $game_map.valid?(nx, ny) # マップ外? return true if @through or debug_through? # すり抜け ON? return false unless map_passable?(x, y, d) # 指定方向に移動不能? return false unless map_passable?(nx, ny, 10 - d) # 移動先が進入不能? return false if collide_with_characters?(nx, ny) # キャラクターに衝突? return true # 通行可 end #-------------------------------------------------------------------------- # ○ 移動後の X 座標算出 # x : X 座標 # d : 移動方向 # 移動後の X 座標を計算する。 #-------------------------------------------------------------------------- def moved_x(x, d) return x + (d == 6 ? 1 : d == 4 ? -1 : 0) end #-------------------------------------------------------------------------- # ○ 移動後の Y 座標算出 # y : Y 座標 # d : 移動方向 # 移動後の Y 座標を計算する。 #-------------------------------------------------------------------------- def moved_y(y, d) return y + (d == 2 ? 1 : d == 8 ? -1 : 0) end #-------------------------------------------------------------------------- # ○ マップ通行可能判定 # x : X 座標 # y : Y 座標 # d : 移動方向 # 指定座標の指定した方向が通行可能かを取得する。 #-------------------------------------------------------------------------- def map_passable?(x, y, d) return $game_map.passable?(x, y) && $game_map.passable_dir?(x, y, d) end #-------------------------------------------------------------------------- # ● 下に移動 # turn_ok : その場での向き変更を許可 #-------------------------------------------------------------------------- def move_down(turn_ok = true) if passable?(@x, @y, 2) # 通行可能 turn_down @y = $game_map.round_y(@y+1) @real_y = (@y-1)*256 increase_steps @move_failed = false else # 通行不可能 turn_down if turn_ok check_event_trigger_touch(@x, @y+1) # 接触イベントの起動判定 @move_failed = true end end #-------------------------------------------------------------------------- # ● 左に移動 # turn_ok : その場での向き変更を許可 #-------------------------------------------------------------------------- def move_left(turn_ok = true) if passable?(@x, @y, 4) # 通行可能 turn_left @x = $game_map.round_x(@x-1) @real_x = (@x+1)*256 increase_steps @move_failed = false else # 通行不可能 turn_left if turn_ok check_event_trigger_touch(@x-1, @y) # 接触イベントの起動判定 @move_failed = true end end #-------------------------------------------------------------------------- # ● 右に移動 # turn_ok : その場での向き変更を許可 #-------------------------------------------------------------------------- def move_right(turn_ok = true) if passable?(@x, @y, 6) # 通行可能 turn_right @x = $game_map.round_x(@x+1) @real_x = (@x-1)*256 increase_steps @move_failed = false else # 通行不可能 turn_right if turn_ok check_event_trigger_touch(@x+1, @y) # 接触イベントの起動判定 @move_failed = true end end #-------------------------------------------------------------------------- # ● 上に移動 # turn_ok : その場での向き変更を許可 #-------------------------------------------------------------------------- def move_up(turn_ok = true) if passable?(@x, @y, 8) # 通行可能 turn_up @y = $game_map.round_y(@y-1) @real_y = (@y+1)*256 increase_steps @move_failed = false else # 通行不可能 turn_up if turn_ok check_event_trigger_touch(@x, @y-1) # 接触イベントの起動判定 @move_failed = true end end #-------------------------------------------------------------------------- # ● 左下に移動 #-------------------------------------------------------------------------- def move_lower_left unless @direction_fix @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction) end if (passable?(@x, @y, 2) && passable?(@x, @y+1, 4)) || (passable?(@x, @y, 4) && passable?(@x-1, @y, 2)) @x -= 1 @y += 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # ● 右下に移動 #-------------------------------------------------------------------------- def move_lower_right unless @dire ction_fix @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction) end if (passable?(@x, @y, 2) && passable?(@x, @y+1, 6)) || (passable?(@x, @y, 6) && passable?(@x+1, @y, 2)) @x += 1 @y += 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # ● 左上に移動 #-------------------------------------------------------------------------- def move_upper_left unless @direction_fix @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction) end if (passable?(@x, @y, 8) && passable?(@x, @y-1, 4)) || (passable?(@x, @y, 4) && passable?(@x-1, @y, 8)) @x -= 1 @y -= 1 increase_steps @move_failed = false else @move_failed = true end end #-------------------------------------------------------------------------- # ● 右上に移動 #-------------------------------------------------------------------------- def move_upper_right unless @direction_fix @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction) end if (passable?(@x, @y, 8) && passable?(@x, @y-1, 6)) || (passable?(@x, @y, 6) && passable?(@x+1, @y, 8)) @x += 1 @y -= 1 increase_steps @move_failed = false else @move_failed = true end end end #★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★ #============================================================================== # ■ Game_Player #============================================================================== class Game_Player < Game_Character #-------------------------------------------------------------------------- # ○ マップ通行可能判定 # x : X 座標 # y : Y 座標 # d : 移動方向 # 指定座標の指定した方向が通行可能かを取得する。 #-------------------------------------------------------------------------- alias map_passable_KGC_TilesetExtension? map_passable? def map_passable?(x, y, d) return false unless map_passable_KGC_TilesetExtension?(x, y) return $game_map.passable_dir?(x, y, d) end if $TEST && KGC::TilesetExtension::DEBUG_INFO_BUTTON != nil #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- alias update_KGC_TilesetExtension update def update update_KGC_TilesetExtension if Input.trigger?(KGC::TilesetExtension::DEBUG_INFO_BUTTON) show_passage_and_terrain_tag end end #-------------------------------------------------------------------------- # ○ プレイヤー位置の通行フラグ・地形タグを表示 === # ■ Scene_Title #============================================================================== class Scene_Title < Scene_Base #-------------------------------------------------------------------------- # ● データベースのロード #-------------------------------------------------------------------------- alias load_database_KGC_TilesetExtension load_database def load_database load_database_KGC_TilesetExtension load_tileset end #-------------------------------------------------------------------------- # ○ タイルセット付加情報のロード #-------------------------------------------------------------------------- def load_tileset begin $data_tileset = load_data("Data/#{KGC::TilesetExtension::EX_RVDATA}") rescue $data_tileset = RPG::Tileset.new end end end

橙光脚本1

相关推荐