赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
- #==============================================================================
- # ■ Game_Map
- #------------------------------------------------------------------------------
- # 处理地图的类。包含卷动以及可以通行的判断功能。本类的实例请参考 $game_map 。
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :screen # 地图画面状态
- attr_reader :interpreter # 地图事件解释器
- attr_reader :display_x # 画面 X 座标 * 256
- attr_reader :display_y # 画面 Y 座标 * 256
- attr_reader :parallax_name # 远景图文件名
- attr_reader :passages # 通行列表
- attr_reader :events # 事件
- attr_reader :vehicles # 交通工具
- attr_accessor :need_refresh # 需要刷新标志
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- @screen = Game_Screen.new
- @interpreter = Game_Interpreter.new(0, true)
- @map_id = 0
- @display_x = 0
- @display_y = 0
- create_vehicles
- end
- #--------------------------------------------------------------------------
- # ● 设置
- # map_id : 地图 ID
- #--------------------------------------------------------------------------
- def setup(map_id)
- @map_id = map_id
- @map = load_data(sprintf("Data/Map%03d.rvdata", @map_id))
- @display_x = 0
- @display_y = 0
- @passages = $data_system.passages
- referesh_vehicles
- setup_events
- setup_scroll
- setup_parallax
- @need_refresh = false
- end
- #--------------------------------------------------------------------------
- # ● 生成交通工具
- #--------------------------------------------------------------------------
- def create_vehicles
- @vehicles = []
- @vehicles[0] = Game_Vehicle.new(0) # 小型船
- @vehicles[1] = Game_Vehicle.new(1) # 大型船
- @vehicles[2] = Game_Vehicle.new(2) # 飞船
- end
- #--------------------------------------------------------------------------
- # ● 刷新交通工具
- #--------------------------------------------------------------------------
- def referesh_vehicles
- for vehicle in @vehicles
- vehicle.refresh
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取小型船
- #--------------------------------------------------------------------------
- def boat
- return @vehicles[0]
- end
- #--------------------------------------------------------------------------
- # ● 获取大型船
- #--------------------------------------------------------------------------
- def ship
- return @vehicles[1]
- end
- #--------------------------------------------------------------------------
- # ● 获取飞船
- #--------------------------------------------------------------------------
- def airship
- return @vehicles[2]
- end
- #--------------------------------------------------------------------------
- # ● 设置事件
- #--------------------------------------------------------------------------
- def setup_events
- @events = {} # 地图事件
- for i in @map.events.keys
- @events[i] = Game_Event.new(@map_id, @map.events[i])
- end
- @common_events = {} # 公共事件
- for i in 1...$data_common_events.size
- @common_events[i] = Game_CommonEvent.new(i)
- end
- end
- #--------------------------------------------------------------------------
- # ● 设置滚动
- #--------------------------------------------------------------------------
- def setup_scroll
- @scroll_direction = 2
- @scroll_rest = 0
- @scroll_speed = 4
- @margin_x = (width - $原宽度/32) * 256 / 2 # 画面未显示宽度 / 2
- @margin_y = (height - $原高度/32) * 256 / 2 # 画面未显示高度 / 2
- end
- #--------------------------------------------------------------------------
- # ● 设置远景
- #--------------------------------------------------------------------------
- def setup_parallax
- @parallax_name = @map.parallax_name
- @parallax_loop_x = @map.parallax_loop_x
- @parallax_loop_y = @map.parallax_loop_y
- @parallax_sx = @map.parallax_sx
- @parallax_sy = @map.parallax_sy
- @parallax_x = 0
- @parallax_y = 0
- end
- #--------------------------------------------------------------------------
- # ● 设置显示位置
- # x : 新显示 X 座标 * 256
- # y : 新显示 Y 座标 * 256
- #--------------------------------------------------------------------------
- def set_display_pos(x, y)
- @display_x = (x + @map.width * 256) % (@map.width * 256)
- @display_y = (y + @map.height * 256) % (@map.height * 256)
- @parallax_x = x
- @parallax_y = y
- end
- #--------------------------------------------------------------------------
- # ● 计算远景 X 座标
- # bitmap : 远景图
- #--------------------------------------------------------------------------
- def calc_parallax_x(bitmap)
- if bitmap == nil
- return 0
- elsif @parallax_loop_x
- return @parallax_x / 16
- elsif loop_horizontal?
- return 0
- else
- w1 = bitmap.width - $原宽度
- w2 = @map.width * 32 - $原宽度
- if w1 <= 0 or w2 <= 0
- return 0
- else
- return @parallax_x * w1 / w2 / 8
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算远景 Y 座标
- # bitmap : 远景图
- #--------------------------------------------------------------------------
- def calc_parallax_y(bitmap)
- if bitmap == nil
- return 0
- elsif @parallax_loop_y
- return @parallax_y / 16
- elsif loop_vertical?
- return 0
- else
- h1 = bitmap.height - $原高度
- h2 = @map.height * 32 - $原高度
- if h1 <= 0 or h2 <= 0
- return 0
- else
- return @parallax_y * h1 / h2 / 8
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取地图 ID
- #--------------------------------------------------------------------------
- def map_id
- return @map_id
- end
- #--------------------------------------------------------------------------
- # ● 获取宽度
- #--------------------------------------------------------------------------
- def width
- return @map.width
- end
- #--------------------------------------------------------------------------
- # ● 获取高度
- #--------------------------------------------------------------------------
- def height
- return @map.height
- end
- #--------------------------------------------------------------------------
- # ● 横向回圈判断
- #--------------------------------------------------------------------------
- def loop_horizontal?
- return (@map.scroll_type == 2 or @map.scroll_type == 3)
- end
- #--------------------------------------------------------------------------
- # ● 纵向回圈判断
- #--------------------------------------------------------------------------
- def loop_vertical?
- return (@map.scroll_type == 1 or @map.scroll_type == 3)
- end
- #--------------------------------------------------------------------------
- # ● 判断是否禁止奔跑
- #--------------------------------------------------------------------------
- def disable_dash?
- return @map.disable_dashing
- end
- #--------------------------------------------------------------------------
- # ● 获取遇敌列表
- #--------------------------------------------------------------------------
- def encounter_list
- return @map.encounter_list
- end
- #--------------------------------------------------------------------------
- # ● 获取遇敌步数
- #--------------------------------------------------------------------------
- def encounter_step
- return @map.encounter_step
- end
- #--------------------------------------------------------------------------
- # ● 获取地图对象
- #--------------------------------------------------------------------------
- def map
- return @map
- end
- #--------------------------------------------------------------------------
- # ● 获取地图数据
- #--------------------------------------------------------------------------
- def data
- return @map.data
- end
- #--------------------------------------------------------------------------
- # ● 计算 X 座标减去显示座标
- # x : X 座标
- #--------------------------------------------------------------------------
- def adjust_x(x)
- if loop_horizontal? and x < @display_x - @margin_x
- return x - @display_x + @map.width * 256
- else
- return x - @display_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算 Y 座标减去显示座标
- # y : Y 座标
- #--------------------------------------------------------------------------
- def adjust_y(y)
- if loop_vertical? and y < @display_y - @margin_y
- return y - @display_y + @map.height * 256
- else
- return y - @display_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算回圈调整後的 X 座标
- # x : X 座标
- #--------------------------------------------------------------------------
- def round_x(x)
- if loop_horizontal?
- return (x + width) % width
- else
- return x
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算回圈调整後的 Y 座标
- # y : Y 座标
- #--------------------------------------------------------------------------
- def round_y(y)
- if loop_vertical?
- return (y + height) % height
- else
- return y
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算一格指定方向的 X 座标
- # x : X 座标
- # direction : 方向(2, 4, 6, 8)
- #--------------------------------------------------------------------------
- def x_with_direction(x, direction)
- return round_x(x + (direction == 6 ? 1 : direction == 4 ? -1 : 0))
- end
- #--------------------------------------------------------------------------
- # ● 计算一格指定方向的 Y 座标
- # y : Y 座标
- # direction : 方向(2, 4, 6, 8)
- #--------------------------------------------------------------------------
- def y_with_direction(y, direction)
- return round_y(y + (direction == 2 ? 1 : direction == 8 ? -1 : 0))
- end
- #--------------------------------------------------------------------------
- # ● 获取指定位置的事件数组
- # x : X 座标
- # y : Y 座标
- #--------------------------------------------------------------------------
- def events_xy(x, y)
- result = []
- for event in $game_map.events.values
- result.push(event) if event.pos?(x, y)
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● BGM / BGS 自动切换
- #--------------------------------------------------------------------------
- def autoplay
- @map.bgm.play if @map.autoplay_bgm unless $game_player.in_vehicle?
- @map.bgs.play if @map.autoplay_bgs
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- if @map_id > 0
- for event in @events.values
- event.refresh
- end
- for common_event in @common_events.values
- common_event.refresh
- end
- end
- @need_refresh = false
- end
- #--------------------------------------------------------------------------
- # ● 向下滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_down(distance)
- if loop_vertical?
- @display_y += distance
- @display_y %= @map.height * 256
- @parallax_y += distance
- else
- last_y = @display_y
- @display_y = [@display_y + distance, (height - $原高度/32) * 256].min
- @parallax_y += @display_y - last_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 向左滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_left(distance)
- if loop_horizontal?
- @display_x += @map.width * 256 - distance
- @display_x %= @map.width * 256
- @parallax_x -= distance
- else
- last_x = @display_x
- @display_x = [@display_x - distance, 0].max
- @parallax_x += @display_x - last_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 向右滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_right(distance)
- if loop_horizontal?
- @display_x += distance
- @display_x %= @map.width * 256
- @parallax_x += distance
- else
- last_x = @display_x
- @display_x = [@display_x + distance, (width - $原宽度/32) * 256].min
- @parallax_x += @display_x - last_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 向上滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_up(distance)
- if loop_vertical?
- @display_y += @map.height * 256 - distance
- @display_y %= @map.height * 256
- @parallax_y -= distance
- else
- last_y = @display_y
- @display_y = [@display_y - distance, 0].max
- @parallax_y += @display_y - last_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 有效坐标判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def valid?(x, y)
- return (x >= 0 and x < width and y >= 0 and y < height)
- end
- #--------------------------------------------------------------------------
- # ● 可以通行判定
- # x : X 坐标
- # y : Y 坐标
- # flag : 通行度标志(非交通工具时,一般为 0x01)
- #--------------------------------------------------------------------------
- def passable?(x, y, flag = 0x01)
- for event in events_xy(x, y) # 循环指定位置的事件数组
- next if event.tile_id == 0 # 事件图片非图块的情况下
- next if event.priority_type > 0 # 非「一般角色之下」
- next if event.through # 允许穿透
- pass = @passages[event.tile_id] # 获取通行属性
- next if pass & 0x10 == 0x10 # ☆: 不影响通行判定
- return true if pass & flag == 0x00 # ○: 可以通行
- return false if pass & flag == flag # x: 不可通行
- end
- for i in [2, 1, 0] # 由上层而下
- tile_id = @map.data[x, y, i] # 获取图块 ID
- return false if tile_id == nil # 无法获取图块:不可通行
- pass = @passages[tile_id] # 获取通行属性
- next if pass & 0x10 == 0x10 # ☆: 不影响通行判定
- return true if pass & flag == 0x00 # o: 可以通行
- return false if pass & flag == flag # x: 不可通行
- end
- return false # 不可通行
- end
- #--------------------------------------------------------------------------
- # ● 判断小型船通行度
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def boat_passable?(x, y)
- return passable?(x, y, 0x02)
- end
- #--------------------------------------------------------------------------
- # ● 判断大型船通行度
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def ship_passable?(x, y)
- return passable?(x, y, 0x04)
- end
- #--------------------------------------------------------------------------
- # ● 判断飞船降落通行度
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def airship_land_ok?(x, y)
- return passable?(x, y, 0x08)
- end
- #--------------------------------------------------------------------------
- # ● 判断草木繁茂处
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def bush?(x, y)
- return false unless valid?(x, y)
- return @passages[@map.data[x, y, 1]] & 0x40 == 0x40
- end
- #--------------------------------------------------------------------------
- # ● 判断柜台属性
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def counter?(x, y)
- return false unless valid?(x, y)
- return @passages[@map.data[x, y, 0]] & 0x80 == 0x80
- end
- #--------------------------------------------------------------------------
- # ● 开始滚动
- # direction : 滚动方向
- # distance : 滚动距离
- # speed : 滚动速度
- #--------------------------------------------------------------------------
- def start_scroll(direction, distance, speed)
- @scroll_direction = direction
- @scroll_rest = distance * 256
- @scroll_speed = speed
- end
- #--------------------------------------------------------------------------
- # ● 滚动判断
- #--------------------------------------------------------------------------
- def scrolling?
- return @scroll_rest > 0
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- refresh if $game_map.need_refresh
- update_scroll
- update_events
- update_vehicles
- update_parallax
- @screen.update
- end
- #--------------------------------------------------------------------------
- # ● 更新滚动
- #--------------------------------------------------------------------------
- def update_scroll
- if @scroll_rest > 0 # 滚动中
- distance = 2 ** @scroll_speed # 转换成距离
- case @scroll_direction
- when 2 # 下
- scroll_down(distance)
- when 4 # 左
- scroll_left(distance)
- when 6 # 右
- scroll_right(distance)
- when 8 # 上
- scroll_up(distance)
- end
- @scroll_rest -= distance # 减短距离
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新事件
- #--------------------------------------------------------------------------
- def update_events
- for event in @events.values
- event.update
- end
- for common_event in @common_events.values
- common_event.update
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新交通工具
- #--------------------------------------------------------------------------
- def update_vehicles
- for vehicle in @vehicles
- vehicle.update
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新远景
- #--------------------------------------------------------------------------
- def update_parallax
- @parallax_x += @parallax_sx * 4 if @parallax_loop_x
- @parallax_y += @parallax_sy * 4 if @parallax_loop_y
- end
- end
复制代码- #==============================================================================
- # ■ Game_Player
- #------------------------------------------------------------------------------
- # 处理主角的类。事件启动的判定、以及地图的滚动等功能。
- # 本类的实例请参考 $game_player。
- #==============================================================================
- class Game_Player < Game_Character
- #--------------------------------------------------------------------------
- # ● 常量
- #--------------------------------------------------------------------------
- CENTER_X = ($原宽度 / 2 - 16) * 8 # 画面中央 X 座标 * 8
- CENTER_Y = ($原高度 / 2 - 16) * 8 # 画面中央 Y 座标 * 8
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :vehicle_type # 目前乘坐交通工具类型
- #--------------------------------------------------------------------------
- # ● 初始化对像
- #--------------------------------------------------------------------------
- def initialize
- super
- @vehicle_type = -1
- @vehicle_getting_on = false # 乘坐交通工具标志
- @vehicle_getting_off = false # 离开交通工具标志
- @transferring = false # 场所移动标志
- @new_map_id = 0 # 目标地图 ID
- @new_x = 0 # 目标 X 座标
- @new_y = 0 # 目标 Y 座标
- @new_direction = 0 # 移动後方向
- @walking_bgm = nil # 记忆用行走时 BGM
- end
- #--------------------------------------------------------------------------
- # ● 判断是否停止
- #--------------------------------------------------------------------------
- def stopping?
- return false if @vehicle_getting_on
- return false if @vehicle_getting_off
- return super
- end
- #--------------------------------------------------------------------------
- # ● 场所移动准备
- # map_id : 地图 ID
- # x : X 座标
- # y : Y 座标
- # direction : 移动後面向
- #--------------------------------------------------------------------------
- def reserve_transfer(map_id, x, y, direction)
- @transferring = true
- @new_map_id = map_id
- @new_x = x
- @new_y = y
- @new_direction = direction
- end
- #--------------------------------------------------------------------------
- # ● 判断是否准备场所移动
- #--------------------------------------------------------------------------
- def transfer?
- return @transferring
- end
- #--------------------------------------------------------------------------
- # ● 执行场所移动
- #--------------------------------------------------------------------------
- def perform_transfer
- return unless @transferring
- @transferring = false
- set_direction(@new_direction)
- if $game_map.map_id != @new_map_id
- $game_map.setup(@new_map_id) # 移动到另一地图
- end
- moveto(@new_x, @new_y)
- @walking_bgm = $game_map.map.bgm
- end
- #--------------------------------------------------------------------------
- # ● 判断地图是否可以通行
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def map_passable?(x, y)
- case @vehicle_type
- when 0 # 小型船
- return $game_map.boat_passable?(x, y)
- when 1 # 大型船
- return $game_map.ship_passable?(x, y)
- when 2 # 飞船
- return true
- else # 行走
- return $game_map.passable?(x, y)
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断行走通行度
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def can_walk?(x, y)
- last_vehicle_type = @vehicle_type # 移除交通工具类型
- @vehicle_type = -1 # 暂时设置为行走
- result = passable?(x, y) # 判断是否可以通行
- @vehicle_type = last_vehicle_type # 回复交通工具类型
- return result
- end
- #--------------------------------------------------------------------------
- # ● 判断飞船降落通行度
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def airship_land_ok?(x, y)
- unless $game_map.airship_land_ok?(x, y)
- return false # 指定地图图块无法降落
- end
- unless $game_map.events_xy(x, y).empty?
- return false # 不可降落于事件之上
- end
- return true # 可以降落
- end
- #--------------------------------------------------------------------------
- # ● 判断是否在交通工具上
- #--------------------------------------------------------------------------
- def in_vehicle?
- return @vehicle_type >= 0
- end
- #--------------------------------------------------------------------------
- # ● 判断是否在飞船之上
- #--------------------------------------------------------------------------
- def in_airship?
- return @vehicle_type == 2
- end
- #--------------------------------------------------------------------------
- # ● 判断是否奔跑中
- #--------------------------------------------------------------------------
- def dash?
- return false if @move_route_forcing
- return false if $game_map.disable_dash?
- return false if in_vehicle?
- return Input.press?(Input::A)
- end
- #--------------------------------------------------------------------------
- # ● 判断是否是游戏测试通行状态
- #--------------------------------------------------------------------------
- def debug_through?
- return false unless $TEST
- return Input.press?(Input::CTRL)
- end
- #--------------------------------------------------------------------------
- # ● 设置地图画面座标为画面中央
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def center(x, y)
- display_x = x * 256 - CENTER_X # 计算座标
- unless $game_map.loop_horizontal? # 非横向回圈的场合
- max_x = ($game_map.width - $原宽度/32) * 256 # 计算最大值
- display_x = [0, [display_x, max_x].min].max # 校正座标
- end
- display_y = y * 256 - CENTER_Y # 计算座标
- unless $game_map.loop_vertical? # 非横向回圈的场合
- max_y = ($game_map.height - $原高度/32) * 256 # 计算最大值
- display_y = [0, [display_y, max_y].min].max # 校正座标
- end
-
- $game_map.set_display_pos(display_x, display_y) # 改变地图位置
- end
- #--------------------------------------------------------------------------
- # ● 移动至指定位置
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def moveto(x, y)
- super
- center(x, y) # 居中对齐
- make_encounter_count # 初始化遇敌
- if in_vehicle? # 在交通工具中的场合
- vehicle = $game_map.vehicles[@vehicle_type] # 获取交通工具
- vehicle.refresh # 刷新交通工具
- end
- end
- #--------------------------------------------------------------------------
- # ● 增加步数
- #--------------------------------------------------------------------------
- def increase_steps
- super
- return if @move_route_forcing
- return if in_vehicle?
- $game_party.increase_steps
- $game_party.on_player_walk
- end
- #--------------------------------------------------------------------------
- # ● 设置遇敌计数
- #--------------------------------------------------------------------------
- def encounter_count
- return @encounter_count
- end
- #--------------------------------------------------------------------------
- # ● 初始化遇敌计数
- #--------------------------------------------------------------------------
- def make_encounter_count
- if $game_map.map_id != 0
- n = $game_map.encounter_step
- @encounter_count = rand(n) + rand(n) + 1 # 好比掷两个骰子
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断是否在地图区域中
- # area : 区域数据(RPG::Area)
- #--------------------------------------------------------------------------
- def in_area?(area)
- return false if area == nil
- return false if $game_map.map_id != area.map_id
- return false if @x < area.rect.x
- return false if @y < area.rect.y
- return false if @x >= area.rect.x + area.rect.width
- return false if @y >= area.rect.y + area.rect.height
- return true
- end
- #--------------------------------------------------------------------------
- # ● 生成遇敌队伍
- #--------------------------------------------------------------------------
- def make_encounter_troop_id
- encounter_list = $game_map.encounter_list.clone
- for area in $data_areas.values
- encounter_list += area.encounter_list if in_area?(area)
- end
- if encounter_list.empty?
- make_encounter_count
- return 0
- end
- return encounter_list[rand(encounter_list.size)]
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- if $game_party.members.size == 0
- @character_name = ""
- @character_index = 0
- else
- actor = $game_party.members[0] # 获取队伍第一人
- @character_name = actor.character_name
- @character_index = actor.character_index
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断同位置事件是否被触发
- # triggers : 触发数组
- #--------------------------------------------------------------------------
- def check_event_trigger_here(triggers)
- return false if $game_map.interpreter.running?
- result = false
- for event in $game_map.events_xy(@x, @y)
- if triggers.include?(event.trigger) and event.priority_type != 1
- event.start
- result = true if event.starting
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 确认前方事件是否被触发
- # triggers : 触发数组
- #--------------------------------------------------------------------------
- def check_event_trigger_there(triggers)
- return false if $game_map.interpreter.running?
- result = false
- front_x = $game_map.x_with_direction(@x, @direction)
- front_y = $game_map.y_with_direction(@y, @direction)
- for event in $game_map.events_xy(front_x, front_y)
- if triggers.include?(event.trigger) and event.priority_type == 1
- event.start
- result = true
- end
- end
- if result == false and $game_map.counter?(front_x, front_y)
- front_x = $game_map.x_with_direction(front_x, @direction)
- front_y = $game_map.y_with_direction(front_y, @direction)
- for event in $game_map.events_xy(front_x, front_y)
- if triggers.include?(event.trigger) and event.priority_type == 1
- event.start
- result = true
- end
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 判断接触事件是否被触发
- # x:X 座标
- # y:Y 座标
- #--------------------------------------------------------------------------
- def check_event_trigger_touch(x, y)
- x -= $game_map.width if $game_map.loop_horizontal? and x == $game_map.width
- y -= $game_map.height if $game_map.loop_vertical? and y == $game_map.height
- return false if $game_map.interpreter.running?
- result = false
- for event in $game_map.events_xy(x, y)
- if [1,2].include?(event.trigger) and event.priority_type == 1
- event.start
- result = true
- end
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● 方向键移动处理
- #--------------------------------------------------------------------------
- def move_by_input
- return unless movable?
- return if $game_map.interpreter.running?
- case Input.dir4
- when 2; move_down
- when 4; move_left
- when 6; move_right
- when 8; move_up
- end
- end
- #--------------------------------------------------------------------------
- # ● 可以行动判定
- #--------------------------------------------------------------------------
- def movable?
- return false if moving? # 正在移动
- return false if @move_route_forcing # 强制移动路线
- return false if @vehicle_getting_on # 正在乘上交通工具
- return false if @vehicle_getting_off # 正在乘上交通工具
- return false if $game_message.visible # 正在显示讯息
- return false if in_airship? and not $game_map.airship.movable?
- return true
- end
- #--------------------------------------------------------------------------
- # ● 更新画面
- #--------------------------------------------------------------------------
- def update
- last_real_x = @real_x
- last_real_y = @real_y
- last_moving = moving?
- move_by_input
- super
- update_scroll(last_real_x, last_real_y)
- update_vehicle
- update_nonmoving(last_moving)
- end
- #--------------------------------------------------------------------------
- # ● 更新滚动
- #--------------------------------------------------------------------------
- def update_scroll(last_real_x, last_real_y)
- ax1 = $game_map.adjust_x(last_real_x)
- ay1 = $game_map.adjust_y(last_real_y)
- ax2 = $game_map.adjust_x(@real_x)
- ay2 = $game_map.adjust_y(@real_y)
- if ay2 > ay1 and ay2 > CENTER_Y
- $game_map.scroll_down(ay2 - ay1)
- end
- if ax2 < ax1 and ax2 < CENTER_X
- $game_map.scroll_left(ax1 - ax2)
- end
- if ax2 > ax1 and ax2 > CENTER_X
- $game_map.scroll_right(ax2 - ax1)
- end
- if ay2 < ay1 and ay2 < CENTER_Y
- $game_map.scroll_up(ay1 - ay2)
- end
- end
- #--------------------------------------------------------------------------
- # ● 更新交通工具
- #--------------------------------------------------------------------------
- def update_vehicle
- return unless in_vehicle?
- vehicle = $game_map.vehicles[@vehicle_type]
- if @vehicle_getting_on # 正在乘上?
- if not moving?
- @direction = vehicle.direction # 更改方向
- @move_speed = vehicle.speed # 更改移动速度
- @vehicle_getting_on = false # 结束乘上操作
- @transparent = true # 透明状态
- end
- elsif @vehicle_getting_off # 正在离开?
- if not moving? and vehicle.altitude == 0
- @vehicle_getting_off = false # 结束乘上操作
- @vehicle_type = -1 # 清除交通工具类型
- @transparent = false # 移除透明状态
- end
- else # 正在交通工具之上
- vehicle.sync_with_player # 与角色同步移动
- end
- end
- #--------------------------------------------------------------------------
- # ● 非移动中更新
- # last_moving : 之前是否正在移动
- #--------------------------------------------------------------------------
- def update_nonmoving(last_moving)
- return if $game_map.interpreter.running?
- return if moving?
- return if check_touch_event if last_moving
- if not $game_message.visible and Input.trigger?(Input::C)
- return if get_on_off_vehicle
- return if check_action_event
- end
- update_encounter if last_moving
- end
- #--------------------------------------------------------------------------
- # ● 更新遇敌
- #--------------------------------------------------------------------------
- def update_encounter
- return if $TEST and Input.press?(Input::CTRL) # 测试游戏中
- return if in_vehicle? # 乘坐交通工具中
- if $game_map.bush?(@x, @y) # 在草木繁茂处
- @encounter_count -= 2 # 将遇敌计数减2
- else # 否则
- @encounter_count -= 1 # 将遇敌计数减1
- end
- end
- #--------------------------------------------------------------------------
- # ● 判断事件是否由接触触发(重叠)
- #--------------------------------------------------------------------------
- def check_touch_event
- return false if in_airship?
- return check_event_trigger_here([1,2])
- end
- #--------------------------------------------------------------------------
- # ● 判断事件是否由确认键触发
- #--------------------------------------------------------------------------
- def check_action_event
- return false if in_airship?
- return true if check_event_trigger_here([0])
- return check_event_trigger_there([0,1,2])
- end
- #--------------------------------------------------------------------------
- # ● 上下交通工具
- #--------------------------------------------------------------------------
- def get_on_off_vehicle
- return false unless movable?
- if in_vehicle?
- return get_off_vehicle
- else
- return get_on_vehicle
- end
- end
- #--------------------------------------------------------------------------
- # ● 乘上交通工具
- # 以角色非在交通工具之上为前提
- #--------------------------------------------------------------------------
- def get_on_vehicle
- front_x = $game_map.x_with_direction(@x, @direction)
- front_y = $game_map.y_with_direction(@y, @direction)
- if $game_map.airship.pos?(@x, @y) # 判断角色是否与飞船重叠
- get_on_airship
- return true
- elsif $game_map.ship.pos?(front_x, front_y) # 判断前方是否有大型船
- get_on_ship
- return true
- elsif $game_map.boat.pos?(front_x, front_y) # 判断前方是否有小型船
- get_on_boat
- return true
- end
- return false
- end
- #--------------------------------------------------------------------------
- # ● 乘上小型船
- #--------------------------------------------------------------------------
- def get_on_boat
- @vehicle_getting_on = true # 乘上交通工具标志
- @vehicle_type = 0 # 设置交通工具类型
- force_move_forward # 向前一步
- @walking_bgm = RPG::BGM::last # 记忆行走 BGM
- $game_map.boat.get_on # 上船处理
- end
- #--------------------------------------------------------------------------
- # ● 乘上大型船
- #--------------------------------------------------------------------------
- def get_on_ship
- @vehicle_getting_on = true # 乘上交通工具标志
- @vehicle_type = 1 # 设置交通工具类型
- force_move_forward # 向前一步
- @walking_bgm = RPG::BGM::last # 记忆行走 BGM
- $game_map.ship.get_on # 上船处理
- end
- #--------------------------------------------------------------------------
- # ● 乘上飞船
- #--------------------------------------------------------------------------
- def get_on_airship
- @vehicle_getting_on = true # 乘上交通工具标志
- @vehicle_type = 2 # 设置交通工具类型
- @through = true # 允许穿透
- @walking_bgm = RPG::BGM::last # 记忆行走 BGM
- $game_map.airship.get_on # 上船处理
- end
- #--------------------------------------------------------------------------
- # ● 离开交通工具
- # 以角色在交通工具之上为前提
- #--------------------------------------------------------------------------
- def get_off_vehicle
- if in_airship? # 在飞船之上
- return unless airship_land_ok?(@x, @y) # 判断是否能降落
- else # 在大/小型船上
- front_x = $game_map.x_with_direction(@x, @direction)
- front_y = $game_map.y_with_direction(@y, @direction)
- return unless can_walk?(front_x, front_y) # 判断是否能下船
- end
- $game_map.vehicles[@vehicle_type].get_off # 下船处理
- if in_airship? # 飞船
- @direction = 2 # 面向下
- else # 大/小型船
- force_move_forward # 向前一步
- @transparent = false # 移除透明状态
- end
- @vehicle_getting_off = true # 开始下船处理
- @move_speed = 4 # 回复移动速度
- @through = false # 不允许穿透
- @walking_bgm.play # 回复行走 BGM
- make_encounter_count # 初始化遇敌
- end
- #--------------------------------------------------------------------------
- # ● 强迫向前一步
- #--------------------------------------------------------------------------
- def force_move_forward
- @through = true # 允许穿透
- move_forward # 向前一步
- @through = false # 不允许穿透
- end
- end
复制代码 关于其他的自己改去吧,
什么,不能运行?你没见过常量吗? |
|