Project1

标题: 仿DQ马车队列行走 [打印本页]

作者: Sion    时间: 2013-1-24 12:56
标题: 仿DQ马车队列行走
本帖最后由 Sion 于 2013-1-25 16:50 编辑

DQ4代开始,获得马车以后在大地图上的队形,大概就是这个样子。

最近复刻这款游戏,顺便就写了这个脚本。
集中队列成员的时候有点卡帧,在下暂时想不出解决办法,希望大家能指点一下:)
已经不卡了,欢迎反馈bug
RUBY 代码复制
  1. #==============================================================================
  2. # 仿DQ系列的马车行走
  3. #
  4. # 使用说明:新建2个角色,行走图分别设置为马和车厢。
  5. # 开启对应的开关后,在地图备注中写有<马车Style>的地图上,就能以马车队列行进。
  6. # 在<马车Style>的地图上开启开关时,如果需要要刷新队列,请在事件中执行脚本:
  7. # $game_player.refresh
  8. #==============================================================================
  9. module CarriageStyle
  10.   HORSE    = 10  #设置行走图为马的角色ID
  11.   CARRIAGE = 11  #设置行走图为马车的角色ID
  12.   SWITCH   = 120   #控制马车行走的公共开关
  13. end
  14.  
  15. #==============================================================================
  16. # ■ Game_Follower
  17. #==============================================================================
  18. class Game_Follower
  19. attr_accessor :need_refresh
  20.   #--------------------------------------------------------------------------
  21.   # ● 获取对应的角色(override method)
  22.   #--------------------------------------------------------------------------
  23.   def actor
  24.     if @need_refresh
  25.       $carriage_array = $game_party.battle_members
  26.       if $game_map.carriage_style? && $game_switches[CarriageStyle::SWITCH]
  27.         $carriage_array.insert(1, $game_actors[CarriageStyle::HORSE],
  28.         $game_actors[CarriageStyle::CARRIAGE])
  29.       end
  30.       @need_refresh = false
  31.     end
  32.     $carriage_array[@member_index]
  33.   end
  34.   #--------------------------------------------------------------------------
  35.   # ● 追随带队角色(override method)
  36.   #--------------------------------------------------------------------------
  37.   def chase_preceding_character
  38.     unless moving?
  39.       case @member_index
  40.       when 1..3; chase(@preceding_character.x, @preceding_character.y)
  41.       when 4;    left_side_chase(@preceding_character)
  42.       when 5;    right_side_chase(@preceding_character); end
  43.     end
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● 追随(new method)
  47.   #--------------------------------------------------------------------------
  48.   def chase(x, y)
  49.     sx = distance_x_from(x)
  50.     sy = distance_y_from(y)
  51.     if sx != 0 && sy != 0
  52.       move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
  53.     elsif sx != 0
  54.       move_straight(sx > 0 ? 4 : 6)
  55.     elsif sy != 0
  56.       move_straight(sy > 0 ? 8 : 2)
  57.     end
  58.   end
  59.   #--------------------------------------------------------------------------
  60.   # ● 左侧人物的移动(new method)
  61.   #--------------------------------------------------------------------------
  62.   def left_side_chase(character)
  63.     if left_side_passable?(character) && !$game_player.followers.gathering?
  64.       sx = distance_x_from(character.left_side_x)
  65.       sy = distance_y_from(character.left_side_y)
  66.       if (sx.abs + sy.abs) >= 3
  67.         moveto(character.back_side_x, character.back_side_y)
  68.       end
  69.       chase(character.left_side_x, character.left_side_y)
  70.     else
  71.       chase(character.x, character.y)
  72.     end
  73.     @direction = character.direction
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 右侧人物的移动(new method)
  77.   #--------------------------------------------------------------------------
  78.   def right_side_chase(character)
  79.     if right_side_passable?(character) && !$game_player.followers.gathering?
  80.       sx = distance_x_from(character.right_side_x)
  81.       sy = distance_y_from(character.right_side_y)
  82.       if (sx.abs + sy.abs) >= 3
  83.         moveto(character.back_side_x, character.back_side_y)
  84.       end
  85.       chase(character.right_side_x, character.right_side_y)
  86.     else
  87.       chase(character.x, character.y)
  88.     end
  89.     @direction = character.direction
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 得到目标背后的坐标(new method)
  93.   #--------------------------------------------------------------------------
  94.   def back_side_x
  95.     case self.direction
  96.     when 2; x = 0
  97.     when 4; x = 1
  98.     when 6; x = -1
  99.     when 8; x = 0; end
  100.     $game_map.round_x(x += self.x)
  101.   end
  102.   def back_side_y
  103.     case self.direction
  104.     when 2; y = -1
  105.     when 4; y = 0
  106.     when 6; y = 0
  107.     when 8; y = 1; end
  108.     $game_map.round_y(y += self.y)
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # ● 得到目标左侧的坐标(new methord)
  112.   #--------------------------------------------------------------------------
  113.   def left_side_x
  114.     case self.direction
  115.     when 2; x = 1
  116.     when 4; x = 0
  117.     when 6; x = 0
  118.     when 8; x = -1; end
  119.     $game_map.round_x(x += self.x)
  120.   end
  121.   def left_side_y
  122.     case self.direction
  123.     when 2; y = 0
  124.     when 4; y = 1
  125.     when 6; y = -1
  126.     when 8; y = 0; end
  127.     $game_map.round_x(y += self.y)
  128.   end
  129.   #--------------------------------------------------------------------------
  130.   # ● 得到目标右侧的坐标(new method)
  131.   #--------------------------------------------------------------------------
  132.   def right_side_x
  133.     case self.direction
  134.     when 2; x = -1
  135.     when 4; x = 0
  136.     when 6; x = 0
  137.     when 8; x = 1; end
  138.     $game_map.round_x(x += self.x)
  139.   end
  140.   def right_side_y
  141.     case self.direction
  142.     when 2; y = 0
  143.     when 4; y = -1
  144.     when 6; y = 1
  145.     when 8; y = 0; end
  146.     $game_map.round_y(y += self.y)
  147.   end
  148.   #--------------------------------------------------------------------------
  149.   # ● 判定HORSE左侧通行度(new method)
  150.   #--------------------------------------------------------------------------
  151.   def left_side_passable?(character)
  152.     $game_map.passable?(character.left_side_x,character.left_side_y,
  153.     character.direction) &&
  154.     !collide_with_events?(character.left_side_x, character.left_side_y)
  155.   end
  156.   #--------------------------------------------------------------------------
  157.   # ● 判定HORSE右侧通行度(new method)
  158.   #--------------------------------------------------------------------------
  159.   def right_side_passable?(character)
  160.     $game_map.passable?(character.right_side_x,character.right_side_y,
  161.     character.direction) &&
  162.     !collide_with_events?(character.right_side_x, character.right_side_y)
  163.   end
  164. end
  165.  
  166. #==============================================================================
  167. # ■ Scene_Map(new method)
  168. #==============================================================================
  169. class Game_Map
  170.   def carriage_style?
  171.     return if map_id == 0
  172.     object = load_data(sprintf("Data/Map%03d.rvdata2", map_id))
  173.     object.note.each_line do |line|
  174.       return true if line.include?("<马车Style>")
  175.     end
  176.     return false
  177.   end
  178. end
  179.  
  180. #==============================================================================
  181. # ■ Scene_Map(override method)
  182. #==============================================================================
  183. class Scene_Map
  184.   def perform_transfer
  185.     pre_transfer
  186.     $game_player.perform_transfer
  187.     $game_player.refresh
  188.     post_transfer
  189.   end
  190. end
  191.  
  192. #==============================================================================
  193. # ■ Game_Followers(alias method)
  194. #==============================================================================
  195. class Game_Followers
  196.   #--------------------------------------------------------------------------
  197.   # ● 初始化(alias method)
  198.   #--------------------------------------------------------------------------
  199.   alias old_initialize initialize
  200.   def initialize(leader)
  201.     old_initialize(leader)
  202.     @data.push(Game_Follower.new(4, @data[0]))
  203.     @data.push(Game_Follower.new(5, @data[0]))
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 刷新(alias method)
  207.   #--------------------------------------------------------------------------
  208.   alias old_refresh refresh
  209.   def refresh
  210.     @data[0].need_refresh = true
  211.     old_refresh
  212.   end
  213. end

作者: eve592370698    时间: 2013-1-24 16:41
大地图随机遇敌咋办?
作者: 小小西    时间: 2016-3-26 16:01
我游戏很多并行事件,玩起来有点卡,但用了这个脚本卡爆了!!
这脚本还能再优化吗、?




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1