查看: 5586|回复: 2

[RMVA发布] 仿DQ马车队列行走

[复制链接]
梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
回帖
2257

贵宾

发表于 2013-1-24 12:56:52 | 显示全部楼层 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有账号?注册会员

×
本帖最后由 Sion 于 2013-1-25 16:50 编辑

DQ4代开始,获得马车以后在大地图上的队形,大概就是这个样子。
QQ截图20130124124512.png
最近复刻这款游戏,顺便就写了这个脚本。
集中队列成员的时候有点卡帧,在下暂时想不出解决办法,希望大家能指点一下:)
已经不卡了,欢迎反馈bug
[pre lang="ruby" line="1"]#==============================================================================
# 仿DQ系列的马车行走
#
# 使用说明:新建2个角色,行走图分别设置为马和车厢。
# 开启对应的开关后,在地图备注中写有<马车Style>的地图上,就能以马车队列行进。
# 在<马车Style>的地图上开启开关时,如果需要要刷新队列,请在事件中执行脚本:
# $game_player.refresh
#==============================================================================
module CarriageStyle
  HORSE    = 10  #设置行走图为马的角色ID
  CARRIAGE = 11  #设置行走图为马车的角色ID
  SWITCH   = 120   #控制马车行走的公共开关
end

#==============================================================================
# ■ Game_Follower
#==============================================================================
class Game_Follower
attr_accessor :need_refresh
  #--------------------------------------------------------------------------
  # ● 获取对应的角色(override method)
  #--------------------------------------------------------------------------
  def actor
    if @need_refresh
      $carriage_array = $game_party.battle_members
      if $game_map.carriage_style? && $game_switches[CarriageStyle::SWITCH]
        $carriage_array.insert(1, $game_actors[CarriageStyle::HORSE],
        $game_actors[CarriageStyle::CARRIAGE])
      end
      @need_refresh = false
    end
    $carriage_array[@member_index]
  end
  #--------------------------------------------------------------------------
  # ● 追随带队角色(override method)
  #--------------------------------------------------------------------------
  def chase_preceding_character
    unless moving?
      case @member_index
      when 1..3; chase(@preceding_character.x, @preceding_character.y)
      when 4;    left_side_chase(@preceding_character)
      when 5;    right_side_chase(@preceding_character); end
    end
  end
  #--------------------------------------------------------------------------
  # ● 追随(new method)
  #--------------------------------------------------------------------------
  def chase(x, y)
    sx = distance_x_from(x)
    sy = distance_y_from(y)
    if sx != 0 && sy != 0
      move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
    elsif sx != 0
      move_straight(sx > 0 ? 4 : 6)
    elsif sy != 0
      move_straight(sy > 0 ? 8 : 2)
    end
  end
  #--------------------------------------------------------------------------
  # ● 左侧人物的移动(new method)
  #--------------------------------------------------------------------------
  def left_side_chase(character)
    if left_side_passable?(character) && !$game_player.followers.gathering?
      sx = distance_x_from(character.left_side_x)
      sy = distance_y_from(character.left_side_y)
      if (sx.abs + sy.abs) >= 3
        moveto(character.back_side_x, character.back_side_y)
      end
      chase(character.left_side_x, character.left_side_y)
    else
      chase(character.x, character.y)
    end
    @direction = character.direction
  end
  #--------------------------------------------------------------------------
  # ● 右侧人物的移动(new method)
  #--------------------------------------------------------------------------
  def right_side_chase(character)
    if right_side_passable?(character) && !$game_player.followers.gathering?
      sx = distance_x_from(character.right_side_x)
      sy = distance_y_from(character.right_side_y)
      if (sx.abs + sy.abs) >= 3
        moveto(character.back_side_x, character.back_side_y)
      end
      chase(character.right_side_x, character.right_side_y)
    else
      chase(character.x, character.y)
    end
    @direction = character.direction
  end
  #--------------------------------------------------------------------------
  # ● 得到目标背后的坐标(new method)
  #--------------------------------------------------------------------------
  def back_side_x
    case self.direction
    when 2; x = 0
    when 4; x = 1
    when 6; x = -1
    when 8; x = 0; end
    $game_map.round_x(x += self.x)
  end
  def back_side_y
    case self.direction
    when 2; y = -1
    when 4; y = 0
    when 6; y = 0
    when 8; y = 1; end
    $game_map.round_y(y += self.y)
  end
  #--------------------------------------------------------------------------
  # ● 得到目标左侧的坐标(new methord)
  #--------------------------------------------------------------------------
  def left_side_x
    case self.direction
    when 2; x = 1
    when 4; x = 0
    when 6; x = 0
    when 8; x = -1; end
    $game_map.round_x(x += self.x)
  end
  def left_side_y
    case self.direction
    when 2; y = 0
    when 4; y = 1
    when 6; y = -1
    when 8; y = 0; end
    $game_map.round_x(y += self.y)
  end
  #--------------------------------------------------------------------------
  # ● 得到目标右侧的坐标(new method)
  #--------------------------------------------------------------------------
  def right_side_x
    case self.direction
    when 2; x = -1
    when 4; x = 0
    when 6; x = 0
    when 8; x = 1; end
    $game_map.round_x(x += self.x)
  end
  def right_side_y
    case self.direction
    when 2; y = 0
    when 4; y = -1
    when 6; y = 1
    when 8; y = 0; end
    $game_map.round_y(y += self.y)
  end
  #--------------------------------------------------------------------------
  # ● 判定HORSE左侧通行度(new method)
  #--------------------------------------------------------------------------
  def left_side_passable?(character)
    $game_map.passable?(character.left_side_x,character.left_side_y,
    character.direction) &&
    !collide_with_events?(character.left_side_x, character.left_side_y)
  end
  #--------------------------------------------------------------------------
  # ● 判定HORSE右侧通行度(new method)
  #--------------------------------------------------------------------------
  def right_side_passable?(character)
    $game_map.passable?(character.right_side_x,character.right_side_y,
    character.direction) &&
    !collide_with_events?(character.right_side_x, character.right_side_y)
  end
end

#==============================================================================
# ■ Scene_Map(new method)
#==============================================================================
class Game_Map
  def carriage_style?
    return if map_id == 0
    object = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
    object.note.each_line do |line|
      return true if line.include?("<马车Style>")
    end
    return false
  end
end

#==============================================================================
# ■ Scene_Map(override method)
#==============================================================================
class Scene_Map
  def perform_transfer
    pre_transfer
    $game_player.perform_transfer
    $game_player.refresh
    post_transfer
  end
end

#==============================================================================
# ■ Game_Followers(alias method)
#==============================================================================
class Game_Followers
  #--------------------------------------------------------------------------
  # ● 初始化(alias method)
  #--------------------------------------------------------------------------
  alias old_initialize initialize
  def initialize(leader)
    old_initialize(leader)
    @data.push(Game_Follower.new(4, @data[0]))
    @data.push(Game_Follower.new(5, @data[0]))
  end
  #--------------------------------------------------------------------------
  # ● 刷新(alias method)
  #--------------------------------------------------------------------------
  alias old_refresh refresh
  def refresh
    @data[0].need_refresh = true
    old_refresh
  end
end[/pre]

梦石
0
星屑
432
在线时间
4175 小时
注册时间
2010-6-26
回帖
6276
发表于 2013-1-24 16:41:31 | 显示全部楼层
大地图随机遇敌咋办?

点评

设置成不遇敌不就完了  发表于 2014-2-1 20:53
潜水,专心忙活三次元工作了……
回复

使用道具 举报

梦石
0
星屑
1461
在线时间
815 小时
注册时间
2013-8-3
回帖
355
发表于 2016-3-26 16:01:09 | 显示全部楼层
我游戏很多并行事件,玩起来有点卡,但用了这个脚本卡爆了!!
这脚本还能再优化吗、?

【同人游戏】勇者斗恶龙TG
欢迎加入游戏测试群333599798
如有需私聊请加QQ:516425000
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部