module Tongban
@visible = true #显示?
@renshu = 3 #跟随人数
def self.setup(x,y)
$game_party.move = []
if @visible == false
for i in 1..@renshu
$game_map.events.delete(-i)
end
else
for i in 1..@renshu
actors = $game_party.actors[i]
if actors.is_a?(Game_Actor)
ev = RPG::Event.new(x, y)
ev.id = - i
ev.pages[0].move_speed = $game_player.move_speed
ev.pages[0].graphic.character_name = actors.character_name # 角色 文件名
ev.pages[0].graphic.character_hue = actors.character_hue
$game_map.events[-i] = Game_Event.new(@map_id, ev)
else
$game_map.events.delete(-i)
end
end
end
if $scene.is_a?(Scene_Map)
$scene.refresh_spriteset
end
end
def self.play_move(lx=0,x=0,y =0 )
$game_party.move.unshift([lx , x, y])
for i in 1..@renshu
if $game_party.move[i] != nil
elx = $game_party.move[i][0]
ex = $game_party.move[i][1]
ey= $game_party.move[i][2]
tongban_move(-i,elx,ex,ey)
end
end
$game_party.move.delete_at(10)
end
def self.tongban_move(id,elx,ex,ey)
ev = $game_map.events[id]
if ev.is_a?(Game_Event)
case elx
when 2 # 下
ev.move_down(ex)
when 4 # 左
ev.move_left(ex)
when 6 # 右
ev.move_right(ex)
when 8 # 上
ev.move_up(ex)
when 1
ev.move_lower_left
when 3
ev.move_lower_right
when 7
ev.move_upper_left
when 9
ev.move_upper_right
when 11
ev.jump(ex,ey)
when 12
ev.moveto(ex,ey)
end
end
end
def self.passable?(x,y)
if @visible == true
actors_x = $game_player.x
actors_y = $game_player.y
return true if actors_x == x and actors_y == y
actors_number = 0
for i in 1..@renshu
if $game_map.events[-i].is_a?(Game_Event)
actors_x = $game_map.events[-i].x
actors_y = $game_map.events[-i].y
return true if actors_x == x and actors_y == y
end
actors_number += 1
end
end
return false
end
def self.visible(i)
i = true if i != false
if @visible != i
@visible = i
setup($game_player.x,$game_player.y)
end
end
def self.transfer_player
return @transfer_player
end
def self.transfer_player=( i=false )
return @transfer_player = i
end
end
class Game_Character
attr_accessor :move_speed
# 判断通行
def passable?(x, y, d)
# 求得新的坐标
new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
# 坐标在地图以外的情况
unless $game_map.valid?(new_x, new_y)
# 不能通行
return false
end
return true if (self == $game_player or self.id < 0 and Tongban.passable?(new_x,new_y))
# 穿透是 ON 的情况下
if @through
# 可以通行
return true
end
# 移动者的元件无法来到指定方向的情况下
unless $game_map.passable?(x, y, d, self)
# 通行不可
return false
end
# 从指定方向不能进入到移动处的元件的情况下
unless $game_map.passable?(new_x, new_y, 10 - d)
# 不能通行
return false
end
# 循环全部事件
for event in $game_map.events.values
# 事件坐标于移动目标坐标一致的情况下
if event.x == new_x and event.y == new_y
# 穿透为 ON
unless event.through
# 自己就是事件的情况下
if self != $game_player
# 不能通行
return false
end
# 自己是主角、对方的图形是角色的情况下
if event.character_name != ""
# 不能通行
return false
end
end
end
end
# 主角的坐标与移动目标坐标一致的情况下
if $game_player.x == new_x and $game_player.y == new_y
# 穿透为 ON
unless $game_player.through
# 自己的图形是角色的情况下
if @character_name != ""
# 不能通行
return false
end
end
end
# 可以通行
return true
end
def moveto(x, y)
if self.is_a?(Game_Player)
if Tongban.transfer_player == true
Tongban.setup(x,y)
Tongban.transfer_player = false
else
Tongban.play_move(12,x,y)
end
end
@x = x % $game_map.width
@y = y % $game_map.height
@real_x = @x * 128
@real_y = @y * 128
@prelock_direction = 0
end
#--------------------------------------------------------------------------
# ● 向下移动
# turn_enabled : 本场地位置更改许可标志
#--------------------------------------------------------------------------
def move_down(turn_enabled = true)
# 面向下
if turn_enabled
turn_down
end
# 可以通行的场合
if passable?(@x, @y, 2)
Tongban.play_move(2,turn_enabled) if self == $game_player
# 面向下
turn_down
# 更新坐标
@y += 1
# 增加步数
increase_steps
# 不能通行的情况下
else
# 接触事件的启动判定
check_event_trigger_touch(@x, @y+1)
end
end
#--------------------------------------------------------------------------
# ● 向左移动
# turn_enabled : 本场地位置更改许可标志
#--------------------------------------------------------------------------
def move_left(turn_enabled = true)
# 面向左
if turn_enabled
turn_left
end
# 可以通行的情况下
if passable?(@x, @y, 4)
Tongban.play_move(4,turn_enabled) if self == $game_player
# 面向左
turn_left
# 更新坐标
@x -= 1
# 增加步数
increase_steps
# 不能通行的情况下
else
# 接触事件的启动判定
check_event_trigger_touch(@x-1, @y)
end
end
#--------------------------------------------------------------------------
# ● 向右移动
# turn_enabled : 本场地位置更改许可标志
#--------------------------------------------------------------------------
def move_right(turn_enabled = true)
# 面向右
if turn_enabled
turn_right
end
# 可以通行的场合
if passable?(@x, @y, 6)
Tongban.play_move(6,turn_enabled) if self == $game_player
# 面向右
turn_right
# 更新坐标
@x += 1
# 增加步数
increase_steps
# 不能通行的情况下
else
# 接触事件的启动判定
check_event_trigger_touch(@x+1, @y)
end
end
#--------------------------------------------------------------------------
# ● 向上移动
# turn_enabled : 本场地位置更改许可标志
#--------------------------------------------------------------------------
def move_up(turn_enabled = true)
# 面向上
if turn_enabled
turn_up
end
# 可以通行的情况下
if passable?(@x, @y, 8)
Tongban.play_move(8,turn_enabled) if self == $game_player
# 面向上
turn_up
# 更新坐标
@y -= 1
# 歩数増加
increase_steps
# 不能通行的情况下
else
# 接触事件的启动判定
check_event_trigger_touch(@x, @y-1)
end
end
#--------------------------------------------------------------------------
# ● 向左下移动
#--------------------------------------------------------------------------
def move_lower_left
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
end
# 下→左、左→下 的通道可以通行的情况下
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
Tongban.play_move(1) if self == $game_player
# 更新坐标
@x -= 1
@y += 1
# 增加步数
increase_steps
end
end
#--------------------------------------------------------------------------
# ● 向右下移动
#--------------------------------------------------------------------------
def move_lower_right
# 没有固定面向的场合
unless @direction_fix
# 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
@direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
end
# 下→右、右→下 的通道可以通行的情况下
if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
Tongban.play_move(3) if self == $game_player
# 更新坐标
@x += 1
@y += 1
# 增加步数
increase_steps
end
end
#--------------------------------------------------------------------------
# ● 向左上移动
#--------------------------------------------------------------------------
def move_upper_left
unless @direction_fix
@direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
end
# 上→左、左→上 的通道可以通行的情况下
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
(passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
Tongban.play_move(7) if self == $game_player
# 更新坐标
@x -= 1
@y -= 1
# 增加步数
increase_steps
end
end
#--------------------------------------------------------------------------
# ● 向右上移动
#--------------------------------------------------------------------------
def move_upper_right
unless @direction_fix
@direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
end
if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
(passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
Tongban.play_move(9) if self == $game_player
@x += 1
@y -= 1
increase_steps
end
end
end
class Game_Map
attr_accessor :events
def setup(map_id)
# 地图 ID 记录到 @map_id
@map_id = map_id
# 地图文件装载后、设置到 @map
@map = load_data(sprintf("Data/Map%03d.rxdata", @map_id))
# 定义实例变量设置地图元件信息
tileset = $data_tilesets[@map.tileset_id]
@tileset_name = tileset.tileset_name
@autotile_names = tileset.autotile_names
@panorama_name = tileset.panorama_name
@panorama_hue = tileset.panorama_hue
@fog_name = tileset.fog_name
@fog_hue = tileset.fog_hue
@fog_opacity = tileset.fog_opacity
@fog_blend_type = tileset.fog_blend_type
@fog_zoom = tileset.fog_zoom
@fog_sx = tileset.fog_sx
@fog_sy = tileset.fog_sy
@battleback_name = tileset.battleback_name
@passages = tileset.passages
@priorities = tileset.priorities
@terrain_tags = tileset.terrain_tags
# 初始化显示坐标
@display_x = 0
@display_y = 0
# 清除刷新要求标志
@need_refresh = false
# 设置地图事件数据
@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
# 初始化雾的各种信息
@fog_ox = 0
@fog_oy = 0
@fog_tone = Tone.new(0, 0, 0, 0)
@fog_tone_target = Tone.new(0, 0, 0, 0)
@fog_tone_duration = 0
@fog_opacity_duration = 0
@fog_opacity_target = 0
# 初始化滚动信息
@scroll_direction = 2
@scroll_rest = 0
@scroll_speed = 4
Tongban.transfer_player = true
end
end
class Scene_Map
#--------------------------------------------------------------------------
# ● 重新描绘地图
#--------------------------------------------------------------------------
def refresh_spriteset
@spriteset.dispose
@spriteset = Spriteset_Map.new
end
end
class Game_Party
attr_accessor :move
def refresh
# 游戏数据载入后角色对像直接从 $game_actors
# 分离。
# 回避由于载入造成的角色再设置的问题。
new_actors = []
for i in [email]0...@actors.size[/email]
if $data_actors[@actors[i].id] != nil
new_actors.push($game_actors[@actors[i].id])
end
end
@actors = new_actors
setup($game_player.x,$game_player.y)
end
end