查看: 3522|回复: 5

[RMVA发布] 像素单位的移动[2015/10/22 更新1.01]

[复制链接]

Mr.Gandum

梦石
0
星屑
226
在线时间
2070 小时
注册时间
2007-1-31
回帖
2982

贵宾

发表于 2014-6-11 22:21:22 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 feizhaodan 于 2015-10-22 20:43 编辑

让角色移动更加细腻!
这个脚本让VA默认的格子单位移动改为像素单位移动,顺便让通行度可以用区域来控制。
脚本内容
  1. #encoding:utf-8
  2. #==============================================================================
  3. # ☆ 像素移动系统
  4. #      作者:feizhaodan
  5. #      版本:1.1.0
  6. #==============================================================================
  7. # ☆ 使用说明
  8. #     将脚本插入到插件脚本下方Main上方。
  9. #     然后在GraphData模块内根据行走图需要来设置行走图的实际判定大小。
  10. #     在地图的备注栏内输入来令特定区域ID的图块有特别的碰撞大小。
  11. #     id是区域ID,n1,n2,n3,n4分别是图块的左侧,右侧,上侧,下侧的碰撞位置。
  12. #   在事件的第一个指令使用添加注释,然后在里面输入`offx=n'`offy=n'`offz=n'
  13. #     来调整事件的初始XY坐标和Z坐标
  14. #==============================================================================
  15. # ☆ 行走图判定设置方法
  16. #      在行走图文件名后面添加字符来设置各行走图的判定大小
  17. #    例:Actor1-1[W28][H28]
  18. #      [WXX]为行走图判定宽度,用数字替换XX
  19. #      [HXX]为行走图判定高度,用数字替换XX
  20. #      实际碰撞矩形为以角色行走图底部的中心为基准,向左右移动宽度/2,
  21. #                                                向上移动高度分的矩形
  22. #      这些若没有设置的情况下使用RM默认值(即行走图的宽度和高度)
  23. #==============================================================================
  24. # ☆ 注意事项
  25. #     使用地图循环将会使滚动暴走,不要使用循环。
  26. #==============================================================================
  27. # ☆ 更新内容
  28. #    1.1.0: ·大幅度修改判定方法,从像素判定改为矩形判定。预期可以大幅度改善运行速度
  29. #           ·取消脚本内设置判定的方法,改为利用文件名进行设置,方便制作
  30. #    1.0.1: ·添加移动指令功能,在移动指令内的脚本输入`@rountine_count=n'来让之后的
  31. #             移动类指令自动重复n次(如@routine_count=10之后,一个向下移动会自动让
  32. #             事件移动10个单位。使用@routine_count指定的次数不会受到移动频率影响。
  33. #           ·一大堆BUG修正(多到我忘了有哪些)
  34. #==============================================================================
  35. # ■ Kien::PixelMove
  36. #------------------------------------------------------------------------------
  37. #  提供脚本的一些可更改内容
  38. #==============================================================================
  39. module Kien
  40.   module PixelMove
  41.    
  42.     # 滚动锁定控制开关ID
  43.     # 打开时锁定移动时的滚动
  44.     SCROLL_LOCK_SWITCH_ID = 101
  45.    
  46.     # 玩家初始位置调整量
  47.     #                 x坐标 Y坐标
  48.     PLAYER_OFFSETS = [ 16,   16]
  49.    
  50.     # 对地形标记使用精密判定
  51.     # 对梯子等地形判断使用精密判定
  52.     # 即角色所在的所有格子必须都是指定的地形才算为在该判定内
  53.     # 使用长宽大于32的行走图时请关闭来获得更好的游戏体验
  54.     USE_PRECISE_TILETAG = true
  55.   end
  56. end

  57. #==============================================================================
  58. #   设定内容结束
  59. #==============================================================================
  60. $imported ||= {}
  61. $imported[:kien_pixel_move] = true
  62. #==============================================================================
  63. # ■ Rect
  64. #------------------------------------------------------------------------------
  65. #  表达矩形的类
  66. #     添加一些泛用函数。
  67. #==============================================================================
  68. class Rect
  69.   #--------------------------------------------------------------------------
  70.   # ● 是否包含某个点
  71.   #--------------------------------------------------------------------------
  72.   def inside?(tx,ty)
  73.     return tx.between?(x,x+width) && ty.between?(y,y+height)
  74.   end
  75.   #--------------------------------------------------------------------------
  76.   # ● 是否与其他矩形重叠
  77.   #      允许两种参数:
  78.   # 1. collide?(rect)
  79.   #      判断是否与rect相重叠
  80.   # 2. collide?(x,y,width,height,center=false)
  81.   #      判断是否与由x,y,width,height组成的矩形想重叠
  82.   #      当center为true时,表示x,y表达的是矩形的中心坐标
  83.   #--------------------------------------------------------------------------
  84.   def collide?(tx,ty=nil,twidth=nil,theight=nil,convertc=nil)
  85.     if (ty == nil)
  86.       ty = tx.cy
  87.       twidth = tx.width
  88.       theight = tx.height
  89.       tx = tx.cx
  90.     elsif convertc != true
  91.       tx = tx+(twidth/2)
  92.       ty = ty+(theight/2)
  93.     end
  94.     return (cx-tx).abs < (twidth+width)/2 && (cy-ty).abs < (theight+height)/2
  95.   end
  96.   #--------------------------------------------------------------------------
  97.   # ● 矩形的中心x坐标
  98.   #--------------------------------------------------------------------------
  99.   def cx
  100.     return x+(width/2)
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # ● 矩形的中心y坐标
  104.   #--------------------------------------------------------------------------
  105.   def cy
  106.     return y+(height/2)
  107.   end
  108.   #--------------------------------------------------------------------------
  109.   # ● 矩形的左上和右下坐标
  110.   #--------------------------------------------------------------------------
  111.   def getpoints
  112.     return [x,y,x+width,y+height]
  113.   end
  114.   alias collide collide?
  115.   #--------------------------------------------------------------------------
  116.   # ● 矩形的矩形
  117.   #--------------------------------------------------------------------------
  118.   def boundbox
  119.     return self
  120.   end
  121. end
  122. #==============================================================================
  123. # ■ RPG::Map
  124. #------------------------------------------------------------------------------
  125. #  保存地图数据的数据结构。
  126. #==============================================================================
  127. class RPG::Map
  128.   def region_data(id)
  129.     @note.each_line do |line|
  130.       case line
  131.       when /\<R[ ]*(\d+)\|((\d+)\,(\d+)\,(\d+)\,(\d+))\>/
  132.         if $1.to_i == id
  133.           return [$3.to_i,$4.to_i,$5.to_i,$6.to_i]
  134.         end
  135.       end
  136.     end
  137.     return []
  138.   end
  139.   def region_data_rect(id)
  140.     arr = region_data(id)
  141.     unless arr.empty?
  142.       return Rect.new(arr[0],arr[1],arr[2]-arr[0],arr[3]-arr[1])
  143.     end
  144.     return Rect.new(0,0,0,0)
  145.   end
  146.   def region_data_f(id)
  147.     @note.each_line do |line|
  148.       case line
  149.       when /\<Rs[ ]*(\d+)\|(\w+)\>/
  150.         if $1.to_i == id
  151.           return $2
  152.         end
  153.       end
  154.     end
  155.     return nil
  156.   end
  157. end
  158. #==============================================================================
  159. # ■ Game_CharacterBase
  160. #------------------------------------------------------------------------------
  161. #  キャラクターを扱う基本のクラスです。全てのキャラクターに共通する、座標やグ
  162. # ラフィックなどの基本的な情報を保持します。
  163. #==============================================================================

  164. class Game_CharacterBase
  165.   #--------------------------------------------------------------------------
  166.   # ● 非公開メンバ変数の初期化
  167.   #--------------------------------------------------------------------------
  168.   alias pixel_move_init_private_members init_private_members
  169.   def init_private_members
  170.     @move_count = 0
  171.     @target_move_count = 0
  172.     @last_move = []
  173.     # @character_data = [宽,高]
  174.     # 笔记: 角色坐标与显示部分
  175.     #       角色坐标表示角色的脚的中心
  176.     #       角色的碰撞矩形X坐标则为X坐标-宽/2
  177.     #                    Y坐标则为Y坐标-高
  178.     @character_data = [0,0]
  179.     pixel_move_init_private_members
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ● 碰撞矩形
  183.   #      所有判定都使用这个矩形来进行判定
  184.   #--------------------------------------------------------------------------
  185.   def boundbox
  186.     return Rect.new(@x-@character_data[0]/2,# x
  187.                     @y-@character_data[1],# y
  188.                     @character_data[0],# width
  189.                     @character_data[1])# height
  190.   end
  191.   #--------------------------------------------------------------------------
  192.   # ● 移动矩形
  193.   #--------------------------------------------------------------------------
  194.   def move_box(tx,ty,rect=boundbox)
  195.     rect.x = tx - rect.width/2
  196.     rect.y = ty - rect.height
  197.     return rect
  198.   end
  199.   #--------------------------------------------------------------------------
  200.   # ● 从矩形提取坐标
  201.   #--------------------------------------------------------------------------
  202.   def extract_pos_from_box(rect)
  203.     return [rect.x+rect.width/2,rect.y+rect.height]
  204.   end
  205.   #--------------------------------------------------------------------------
  206.   # ● 梯子判定
  207.   #--------------------------------------------------------------------------
  208.   def ladder?
  209.       return $game_map.ladder_rect?(boundbox)
  210.   end
  211.   #--------------------------------------------------------------------------
  212.   # ● 移動速度の取得(ダッシュを考慮)
  213.   #--------------------------------------------------------------------------
  214.   def real_move_speed
  215.     @move_speed + (dash? ? @move_speed/2 : 0)
  216.   end
  217.   #--------------------------------------------------------------------------
  218.   # ● 座標一致判定
  219.   #--------------------------------------------------------------------------
  220.   def pos?(x, y)
  221.     return boundbox.inside?(x,y)
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● 与矩形重叠判定
  225.   #--------------------------------------------------------------------------
  226.   def collide_with?(rect)
  227.     return boundbox.collide?(rect)
  228.   end
  229.   #--------------------------------------------------------------------------
  230.   # ● 更新跳跃
  231.   #--------------------------------------------------------------------------
  232.   def update_jump
  233.     @jump_count -= 1
  234.     @real_x = (@real_x * @jump_count + @x) / (@jump_count + 1.0)
  235.     @real_y = (@real_y * @jump_count + @y) / (@jump_count + 1.0)
  236.     update_bush_depth
  237.     if @jump_count == 0
  238.       @x = @real_x = $game_map.round_x(@x)
  239.       @y = @real_y = $game_map.round_y(@y)
  240.     end
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● イベントIDを獲得
  244.   #--------------------------------------------------------------------------
  245.   def event_id
  246.     return 0
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # ● 获取区域 ID
  250.   #--------------------------------------------------------------------------
  251.   def region_id
  252.     $game_map.region_id(@real_x/32,@real_y/32)
  253.   end
  254.   #--------------------------------------------------------------------------
  255.   # ● 获取区域 ID
  256.   #--------------------------------------------------------------------------
  257.   def region_id_rect
  258.     $game_map.region_id_rect(boundbox)
  259.   end
  260.   #--------------------------------------------------------------------------
  261.   # ● 画面 X 座標の取得
  262.   #--------------------------------------------------------------------------
  263.   def screen_x
  264.     $game_map.adjust_x(@real_x)
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # ● 获取偏移的坐标量
  268.   #--------------------------------------------------------------------------
  269.   def shift_y
  270.     object_character? ? -1 : 0
  271.   end
  272.   #--------------------------------------------------------------------------
  273.   # ● 画面 Y 座標の取得
  274.   #--------------------------------------------------------------------------
  275.   def screen_y
  276.     $game_map.adjust_y(@real_y) - shift_y - jump_height
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # ● 计算跳跃的高度
  280.   #--------------------------------------------------------------------------
  281.   def jump_height
  282.     (@jump_peak * @jump_peak - (@jump_count - @jump_peak).abs ** 2) / 4
  283.   end
  284.   #--------------------------------------------------------------------------
  285.   # ● まっすぐに移動
  286.   #     d       : 方向(2,4,6,8)
  287.   #     turn_ok : その場での向き変更を許可
  288.   #--------------------------------------------------------------------------
  289.   alias pixelmove_move_straight move_straight
  290.   def move_straight(d, turn_ok = true)
  291.     max = distance_per_frame
  292.     cx,cy = @x,@y
  293.     (1..max).to_a.reverse.each do |dis|
  294.       @move_succeed = passable?(@x, @y, d, dis)
  295.       if @move_succeed
  296.         set_direction(d)
  297.         @x = round_x(x_with_direction(@x, d, dis))
  298.         @y = round_y(y_with_direction(@y, d, dis))
  299.         @real_x = x_with_direction(@x,reverse_dir(d), dis)
  300.         @real_y = y_with_direction(@y,reverse_dir(d), dis)
  301.         increase_steps
  302.         break
  303.       else
  304.         @x,@y = cx,cy
  305.       end
  306.     end
  307.     if !@move_succeed && turn_ok
  308.       set_direction(d)
  309.       check_event_trigger_touch_front
  310.     end
  311.   end
  312.   #--------------------------------------------------------------------------
  313.   # ● 斜めに移動
  314.   #     horz : 横方向(4 or 6)
  315.   #     vert : 縦方向(2 or 8)
  316.   #--------------------------------------------------------------------------
  317.   def move_diagonal(horz, vert)
  318.     dir = @direction
  319.     cx,cy = @x,@y
  320.     # first try
  321.     move_straight(horz)
  322.     if @move_succeed
  323.       move_straight(vert)
  324.       if @move_succeed
  325.         return
  326.       end
  327.     end
  328.     @x,@y = cx,cy
  329.     move_straight(vert)
  330.     if @move_succeed
  331.       move_straight(horz)
  332.       if @move_succeed
  333.         return
  334.       end
  335.     end
  336.     @x,@y = cx,cy
  337.     @direction = dir
  338.   end
  339.   #--------------------------------------------------------------------------
  340.   # ● X座標のループ補正
  341.   #--------------------------------------------------------------------------
  342.   def round_x(x)
  343.     $game_map.loop_horizontal? ? (x+$game_map.width*32) % ($game_map.width*32) : x
  344.   end
  345.   #--------------------------------------------------------------------------
  346.   # ● Y座標のループ補正
  347.   #--------------------------------------------------------------------------
  348.   def round_y(y)
  349.     $game_map.loop_vertical? ? (y+$game_map.height*32) % ($game_map.height*32) : y
  350.   end
  351.   #--------------------------------------------------------------------------
  352.   # ● X座標に移動量を追加
  353.   #--------------------------------------------------------------------------
  354.   def x_with_direction(x,d,dis = distance_per_frame)
  355.     return x + (d==4 ? -dis : d==6 ? dis : 0)
  356.   end
  357.   #--------------------------------------------------------------------------
  358.   # ● Y座標に移動量を追加
  359.   #--------------------------------------------------------------------------
  360.   def y_with_direction(y,d,dis = distance_per_frame)
  361.     return y +(d==2 ? dis : d==8 ? -dis : 0)
  362.   end
  363.   #--------------------------------------------------------------------------
  364.   # ● 通行判定の方向
  365.   #--------------------------------------------------------------------------
  366.   def dir_for_pass(d)
  367.     return (5 - @direction - d).abs
  368.   end
  369.   #--------------------------------------------------------------------------
  370.   # ● 判定是否地图人物的实例
  371.   #--------------------------------------------------------------------------
  372.   def object_character?
  373.     @tile_id > 0 || @character_name[0, 1] == '!' || @character_name.empty?
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ● 通行可能判定
  377.   #     d : 方向(2,4,6,8)
  378.   #--------------------------------------------------------------------------
  379.   def passable?(x, y, d, dis = distance_per_frame)
  380.     # 笔记:判定方法
  381.     # 获取当前的判定矩形和移动后的判定矩形
  382.     # 比较两个矩形所占有的格子,获取移动后离开的格子和进入的格子
  383.     # 对离开的格子判断是否可以离开,进入的格子是否可以进入
  384.     # 都被允许的情况下返回true,否则false
  385.    
  386.     # 获取移动后矩形
  387.     rect_after = move_box(x_with_direction(x,d,dis),
  388.                           y_with_direction(y,d,dis))
  389.     # 矩形是否在地图有小范围内
  390.     return false unless $game_map.valid_rect?(rect_after)
  391.     # 是否允许穿透
  392.     return true if @through || debug_through?
  393.     tiles_before = $game_map.tiles_in(boundbox)
  394.     tiles_after = $game_map.tiles_in(rect_after)
  395.     tiles_in = tiles_after - tiles_before
  396.     # 判定所有要进入的格子是否可以进入
  397.     return false unless tiles_in.all? {|xy| map_passable?(*xy,reverse_dir(d)) }
  398.     tiles_out = tiles_before - tiles_after
  399.     # 判定所有要离开的格子是否可以离开
  400.     return false unless tiles_out.all? {|xy| map_passable?(*xy,d) }
  401.     # 判断是否与其他角色相接触
  402.     return false if collide_with_characters?(rect_after)
  403.     return true
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # ● 判定是否可以斜向通行
  407.   #     horz : 横向(4 or 6)
  408.   #     vert : 纵向(2 or 8)
  409.   #--------------------------------------------------------------------------
  410.   def diagonal_passable?(x, y, horz, vert)
  411.     x2 = round_x(x_with_direction(x, horz))
  412.     y2 = round_y(y_with_direction(y, vert))
  413.     (passable?(x, y, vert) && passable?(x, y2, horz)) ||
  414.     (passable?(x, y, horz) && passable?(x2, y, vert))
  415.   end
  416.   #--------------------------------------------------------------------------
  417.   # ● 正面の接触イベントの起動判定
  418.   #--------------------------------------------------------------------------
  419.   def check_event_trigger_touch_front
  420.     x3,y3 = x_with_direction(@real_x,@direction),y_with_direction(@real_y,@direction)
  421.     check_event_trigger_touch(x3,y3)
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # ● 判定是否与玩家人物碰撞
  425.   #--------------------------------------------------------------------------
  426.   def collide_with_characters?(boundbox)
  427.     collide_with_events?(boundbox) || collide_with_vehicles?(boundbox)
  428.   end
  429.   #--------------------------------------------------------------------------
  430.   # ● イベントとの衝突判定
  431.   #--------------------------------------------------------------------------
  432.   def collide_with_events?(boundbox)
  433.     $game_map.events_collide_nt(boundbox).any? do |event|
  434.       event.normal_priority? || self.is_a?(Game_Event)
  435.     end
  436.   end
  437.   #--------------------------------------------------------------------------
  438.   # ● 判定是否与载具碰撞
  439.   #--------------------------------------------------------------------------
  440.   def collide_with_vehicles?(boundbox)
  441.     $game_map.boat.collide_with?(boundbox) || $game_map.ship.collide_with?(boundbox)
  442.   end
  443.   #--------------------------------------------------------------------------
  444.   # ● 1 フレームあたりの移動距離を計算
  445.   #--------------------------------------------------------------------------
  446.   def distance_per_frame
  447.     real_move_speed
  448.   end
  449.   #--------------------------------------------------------------------------
  450.   # ● 指定位置に移動
  451.   #--------------------------------------------------------------------------
  452.   def moveto(x, y)
  453.     @x = x*32+16
  454.     @y = y*32
  455.     @y += 31
  456.     @real_x = @x
  457.     @real_y = @y
  458.     @prelock_direction = 0
  459.     straighten
  460.     update_bush_depth
  461.   end
  462.   #--------------------------------------------------------------------------
  463.   # ● 指定位置に移動
  464.   #--------------------------------------------------------------------------
  465.   def moveto32(x, y)
  466.     @x = x
  467.     @y = y
  468.     @real_x = @x
  469.     @real_y = @y
  470.     @prelock_direction = 0
  471.     straighten
  472.     update_bush_depth
  473.   end
  474.   #--------------------------------------------------------------------------
  475.   # ● 更新动画图案
  476.   #--------------------------------------------------------------------------
  477.   def update_anime_pattern
  478.     if !@step_anime && @stop_count > 0
  479.       @pattern = @original_pattern
  480.     else
  481.       @pattern = (@pattern + 1) % 4
  482.     end
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # ● 更改图像
  486.   #     character_name  : 新的行走图文件名
  487.   #     character_index : 新的行走图索引
  488.   #--------------------------------------------------------------------------
  489.   alias pixel_move_set_graphic set_graphic
  490.   def set_graphic(character_name, character_index)
  491.     pixel_move_set_graphic(character_name,character_index)
  492.     if @character_name =~ /\[W(\d+)\]/
  493.       @character_data[0] = $1.to_i
  494.     else
  495.       @character_data[0] = 32
  496.     end
  497.     if @character_name =~ /\[H(\d+)\]/
  498.       @character_data[1] = $1.to_i
  499.     else
  500.       @character_data[1] = 32
  501.     end
  502.   end
  503. end
  504. #==============================================================================
  505. # ■ Game_Character
  506. #------------------------------------------------------------------------------
  507. #  主に移動ルートなどの処理を追加したキャラクターのクラスです。Game_Player、
  508. # Game_Follower、GameVehicle、Game_Event のスーパークラスとして使用されます。
  509. #==============================================================================

  510. class Game_Character < Game_CharacterBase
  511.   #--------------------------------------------------------------------------
  512.   # ● 非公開メンバ変数の初期化
  513.   #--------------------------------------------------------------------------
  514.   alias pixel_move_init_private_members2 init_private_members
  515.   def init_private_members
  516.     pixel_move_init_private_members2
  517.     @routine_move = nil
  518.     @routine_count = 1
  519.     @old_routine_count = 1
  520.     @by_user = true
  521.   end
  522.   #--------------------------------------------------------------------------
  523.   # ● X 方向の距離計算
  524.   #--------------------------------------------------------------------------
  525.   def distance_x_from(x)
  526.     result = @x - x
  527.     if $game_map.loop_horizontal? && result.abs > $game_map.width*32 / 2
  528.       if result < 0
  529.         result += $game_map.width*32
  530.       else
  531.         result -= $game_map.width*32
  532.       end
  533.     end
  534.     result
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # ● Y 方向の距離計算
  538.   #--------------------------------------------------------------------------
  539.   def distance_y_from(y)
  540.     result = @y - y
  541.     if $game_map.loop_vertical? && result.abs > $game_map.height*32 / 2
  542.       if result < 0
  543.         result += $game_map.height*32
  544.       else
  545.         result -= $game_map.height*32
  546.       end
  547.     end
  548.     result
  549.   end
  550.   #--------------------------------------------------------------------------
  551.   # ● 距離計算
  552.   #--------------------------------------------------------------------------
  553.   def distance_from(character)
  554.     dx = distance_x_from(character.x)
  555.     dy = distance_y_from(character.y)
  556.     return Math.hypot(dx,dy)
  557.   end
  558.   #--------------------------------------------------------------------------
  559.   # ● ジャンプ
  560.   #     x_plus : X 座標加算値
  561.   #     y_plus : Y 座標加算値
  562.   #--------------------------------------------------------------------------
  563.   def jump(x_plus, y_plus)
  564.     x_plus,y_plus = x_plus,y_plus
  565.     if x_plus.abs > y_plus.abs
  566.       set_direction(x_plus < 0 ? 4 : 6) if x_plus != 0
  567.     else
  568.       set_direction(y_plus < 0 ? 8 : 2) if y_plus != 0
  569.     end
  570.     @x += x_plus
  571.     @y += y_plus
  572.     distance = Math.sqrt((x_plus/2 + y_plus/2).abs).round
  573.     @jump_peak = 10 + distance - @move_speed
  574.     @jump_count = @jump_peak * 2
  575.     @stop_count = 0
  576.     straighten
  577.   end
  578.   #--------------------------------------------------------------------------
  579.   # ● ルートに沿った移動の更新
  580.   #--------------------------------------------------------------------------
  581.   alias pixel_move_update_routine_move update_routine_move
  582.   def update_routine_move
  583.     if @routine_move == nil
  584.       pixel_move_update_routine_move
  585.     end
  586.     unless @wait_count > 0
  587.       if @routine_move != nil
  588.         if @routine_move[0].size == 1
  589.           if @routine_move[0][0] == 0
  590.             move_toward_character($game_player)
  591.           elsif @routine_move[0][0] == -1
  592.             move_away_from_character($game_player)
  593.           else
  594.             move_straight(*@routine_move[0])
  595.           end
  596.         elsif @routine_move[0].size == 2
  597.           move_diagonal(*@routine_move[0])
  598.         end
  599.         if @move_succeed || @move_route.skippable
  600.           @routine_move[1] -= 1
  601.           if @routine_move[1] == 0
  602.             if @routine_move[2].is_a?(Proc)
  603.               Proc.call
  604.             end
  605.             @routine_move = nil
  606.           else
  607.             return
  608.           end
  609.         else
  610.           return
  611.         end
  612.       end
  613.     end
  614.   end
  615.   #--------------------------------------------------------------------------
  616.   # ● 移動コマンドの処理
  617.   #--------------------------------------------------------------------------
  618.   def process_move_command(command)
  619.     params = command.parameters
  620.     case command.code
  621.     when ROUTE_END;               process_route_end
  622.     when ROUTE_MOVE_DOWN;         @routine_move = [[2],@routine_count]
  623.     when ROUTE_MOVE_LEFT;         @routine_move = [[4],@routine_count]
  624.     when ROUTE_MOVE_RIGHT;        @routine_move = [[6],@routine_count]
  625.     when ROUTE_MOVE_UP;           @routine_move = [[8],@routine_count]
  626.     when ROUTE_MOVE_LOWER_L;      @routine_move = [[4,2],@routine_count]
  627.     when ROUTE_MOVE_LOWER_R;      @routine_move = [[6,2],@routine_count]
  628.     when ROUTE_MOVE_UPPER_L;      @routine_move = [[4,8],@routine_count]
  629.     when ROUTE_MOVE_UPPER_R;      @routine_move = [[6,8],@routine_count]
  630.     when ROUTE_MOVE_RANDOM;       @routine_move = [[2 + rand(4) * 2],@routine_count]
  631.     when ROUTE_MOVE_TOWARD;       @routine_move = [[0],@routine_count]
  632.     when ROUTE_MOVE_AWAY;         @routine_move = [[-1],@routine_count]
  633.     when ROUTE_MOVE_FORWARD;      @routine_move = [[@direction],@routine_count]
  634.     when ROUTE_MOVE_BACKWARD;     @routine_move = [[reverse_dir(@direction)],@routine_count,Proc.new{@direction_fix=@direction_fix}] ; @direction_fix = true
  635.     when ROUTE_JUMP;              jump(params[0], params[1])
  636.     when ROUTE_WAIT;              @wait_count = params[0] - 1
  637.     when ROUTE_TURN_DOWN;         set_direction(2)
  638.     when ROUTE_TURN_LEFT;         set_direction(4)
  639.     when ROUTE_TURN_RIGHT;        set_direction(6)
  640.     when ROUTE_TURN_UP;           set_direction(8)
  641.     when ROUTE_TURN_90D_R;        turn_right_90
  642.     when ROUTE_TURN_90D_L;        turn_left_90
  643.     when ROUTE_TURN_180D;         turn_180
  644.     when ROUTE_TURN_90D_R_L;      turn_right_or_left_90
  645.     when ROUTE_TURN_RANDOM;       turn_random
  646.     when ROUTE_TURN_TOWARD;       turn_toward_player
  647.     when ROUTE_TURN_AWAY;         turn_away_from_player
  648.     when ROUTE_SWITCH_ON;         $game_switches[params[0]] = true
  649.     when ROUTE_SWITCH_OFF;        $game_switches[params[0]] = false
  650.     when ROUTE_CHANGE_SPEED;      @move_speed = params[0]
  651.     when ROUTE_CHANGE_FREQ;       @move_frequency = params[0]
  652.     when ROUTE_WALK_ANIME_ON;     @walk_anime = true
  653.     when ROUTE_WALK_ANIME_OFF;    @walk_anime = false
  654.     when ROUTE_STEP_ANIME_ON;     @step_anime = true
  655.     when ROUTE_STEP_ANIME_OFF;    @step_anime = false
  656.     when ROUTE_DIR_FIX_ON;        @direction_fix = true
  657.     when ROUTE_DIR_FIX_OFF;       @direction_fix = false
  658.     when ROUTE_THROUGH_ON;        @through = true
  659.     when ROUTE_THROUGH_OFF;       @through = false
  660.     when ROUTE_TRANSPARENT_ON;    @transparent = true
  661.     when ROUTE_TRANSPARENT_OFF;   @transparent = false
  662.     when ROUTE_CHANGE_GRAPHIC;    set_graphic(params[0], params[1])
  663.     when ROUTE_CHANGE_OPACITY;    @opacity = params[0]
  664.     when ROUTE_CHANGE_BLENDING;   @blend_type = params[0]
  665.     when ROUTE_PLAY_SE;           params[0].play
  666.     when ROUTE_SCRIPT;            eval(params[0])
  667.     end
  668.   end
  669. end
  670. #==============================================================================
  671. # ■ Game_Player
  672. #------------------------------------------------------------------------------
  673. #  プレイヤーを扱うクラスです。イベントの起動判定や、マップのスクロールなどの
  674. # 機能を持っています。このクラスのインスタンスは $game_player で参照されます。
  675. #==============================================================================

  676. class Game_Player < Game_Character
  677.   #--------------------------------------------------------------------------
  678.   # ● 移動時の更新
  679.   #--------------------------------------------------------------------------
  680.   alias pixel_move_update_move update_move
  681.   def update_move
  682.     @move_count += 0.5
  683.     pixel_move_update_move
  684.   end
  685.   #--------------------------------------------------------------------------
  686.   # ● まっすぐに移動
  687.   #--------------------------------------------------------------------------
  688.   def move_straight(d, turn_ok = true)
  689.     super
  690.     @followers.move if @move_succeed
  691.   end
  692.   #--------------------------------------------------------------------------
  693.   # ● フレーム更新
  694.   #--------------------------------------------------------------------------
  695.   def update
  696.     last_real_x = @real_x
  697.     last_real_y = @real_y
  698.     last_moving = moving?
  699.     last_succeed = @move_succeed
  700.     @move_succeed = false
  701.     move_by_input
  702.     super
  703.     update_scroll(last_real_x, last_real_y)  unless $game_switches[Kien::PixelMove::SCROLL_LOCK_SWITCH_ID]
  704.     update_vehicle
  705.     update_encounter if $game_switches[100] && last_succeed && @move_count%10==0
  706.     update_encounter if !$game_switches[100] && last_moving && !moving?
  707.     update_nonmoving(last_succeed) unless @move_succeed
  708.     @followers.update
  709.   end
  710.   #--------------------------------------------------------------------------
  711.   # ● 处理卷动
  712.   #--------------------------------------------------------------------------
  713.   def update_scroll(last_real_x, last_real_y)
  714.     ax1 = $game_map.adjust_x(last_real_x)
  715.     ay1 = $game_map.adjust_y(last_real_y)
  716.     ax2 = $game_map.adjust_x(@real_x)
  717.     ay2 = $game_map.adjust_y(@real_y)
  718.     $game_map.scroll_down (ay2 - ay1) if ay2 > ay1 && ay2 > center_y
  719.     $game_map.scroll_left (ax1 - ax2) if ax2 < ax1 && ax2 < center_x
  720.     $game_map.scroll_right(ax2 - ax1) if ax2 > ax1 && ax2 > center_x
  721.     $game_map.scroll_up   (ay1 - ay2) if ay2 < ay1 && ay2 < center_y
  722.   end
  723.   #--------------------------------------------------------------------------
  724.   # ● ルートに沿った移動の更新
  725.   #--------------------------------------------------------------------------
  726.   def update_routine_move
  727.     if @routine_move == nil
  728.       pixel_move_update_routine_move
  729.     end
  730.     unless @wait_count > 0
  731.       @move_count = real_move_speed
  732.       if @routine_move != nil
  733.         if @routine_move[0].size == 1
  734.           if @routine_move[0][0] == 0
  735.             move_toward_character($game_player)
  736.           elsif @routine_move[0][0] == -1
  737.             move_away_from_character($game_player)
  738.           else
  739.             move_straight(*@routine_move[0])
  740.           end
  741.         elsif @routine_move[0].size == 2
  742.           move_diagonal(*@routine_move[0])
  743.         end
  744.         if @move_succeed || @move_route.skippable
  745.           @routine_move[1] -= 1
  746.           if @routine_move[1] == 0
  747.             @routine_move = nil
  748.           else
  749.             return
  750.           end
  751.         else
  752.           return
  753.         end
  754.       end
  755.     end
  756.   end
  757.   #--------------------------------------------------------------------------
  758.   # ● 1 フレームあたりの移動距離を計算
  759.   #--------------------------------------------------------------------------
  760.   def distance_per_frame
  761.     dash? ? (real_move_speed*1.2).round : [real_move_speed + [@move_count - real_move_speed,0].min, 1].max
  762.   end
  763.   #--------------------------------------------------------------------------
  764.   # ● 移動中でない場合の処理
  765.   #     last_moving : 直前に移動中だったか
  766.   #--------------------------------------------------------------------------
  767.   alias pixel_move_update_nonmoving update_nonmoving
  768.   def update_nonmoving(last_moving)
  769.     @move_count = 0 unless last_moving
  770.     return pixel_move_update_nonmoving(last_moving)
  771.   end
  772.   #--------------------------------------------------------------------------
  773.   # ● 由方向键移动
  774.   #--------------------------------------------------------------------------
  775.   def move_by_input
  776.     return if !movable? || $game_map.interpreter.running?
  777.     if Input.dir8 > 0
  778.       if Input.dir8%2 == 0
  779.         move_straight(Input.dir8)
  780.       else
  781.         vert = Input.dir8 > 5 ? 8 : 2
  782.         horz = Input.dir8%3 == 0 ? 6 : 4
  783.         @move_diag = true
  784.         move_diagonal(horz,vert)
  785.         @move_diag = false
  786.         unless @move_succeed
  787.           @move_diag = true
  788.           move_straight(horz)
  789.             @move_diag = false
  790.           unless @move_succeed
  791.             @move_diag = true
  792.             move_straight(vert)
  793.             @move_diag = false
  794.           end
  795.         end
  796.       end
  797.     end
  798.   end
  799.   #--------------------------------------------------------------------------
  800.   # ● 正面のイベント起動判定
  801.   #--------------------------------------------------------------------------
  802.   def check_event_trigger_there(triggers)
  803.     dir = @direction
  804.     x2,y2 = x_with_direction(@real_x,dir),y_with_direction(@real_y,dir)
  805.     rect_front = move_box(x2,y2)
  806.     start_map_event(rect_front, triggers, true)
  807.     return if $game_map.any_event_starting?
  808.     return unless $game_map.counter_rect?(rect_front)
  809.     x2,y2 = x_with_direction(x2,dir,32),y_with_direction(y2,dir,32)
  810.     rect_front = move_box(x2,y2)
  811.     start_map_event(rect_front, triggers, true)
  812.   end
  813.   #--------------------------------------------------------------------------
  814.   # ● 同位置のイベント起動判定
  815.   #--------------------------------------------------------------------------
  816.   def check_event_trigger_here(triggers)
  817.     start_map_event(boundbox, triggers, false)
  818.   end
  819.   #--------------------------------------------------------------------------
  820.   # ● 接触事件的启动判定
  821.   #--------------------------------------------------------------------------
  822.   def check_event_trigger_touch(x, y)
  823.     triggers = [1,2]
  824.     dir = @direction
  825.     x2,y2 = x_with_direction(x,dir),y_with_direction(y,dir)
  826.     rect_front = move_box(x2,y2)
  827.     start_map_event(rect_front, triggers, true)
  828.   end
  829.   #--------------------------------------------------------------------------
  830.   # ● 画面中央の X 座標
  831.   #--------------------------------------------------------------------------
  832.   def center_x
  833.     (Graphics.width - 1) / 2.0
  834.   end
  835.   #--------------------------------------------------------------------------
  836.   # ● 画面中央の Y 座標
  837.   #--------------------------------------------------------------------------
  838.   def center_y
  839.     (Graphics.height - 1) / 2.0
  840.   end
  841.   #--------------------------------------------------------------------------
  842.   # ● 指定位置に移動
  843.   #--------------------------------------------------------------------------
  844.   def moveto(x, y)
  845.     super
  846.     center(x*32, y*32)
  847.     make_encounter_count
  848.     vehicle.refresh if vehicle
  849.     @followers.synchronize(x, y, direction)
  850.   end
  851.   #--------------------------------------------------------------------------
  852.   # ● 指定位置に移動
  853.   #--------------------------------------------------------------------------
  854.   def moveto32(x, y)
  855.     super
  856.     center(x, y)
  857.     make_encounter_count
  858.     vehicle.refresh if vehicle
  859.     @followers.synchronize(x, y, direction)
  860.   end
  861.   #--------------------------------------------------------------------------
  862.   # ● 启动地图事件
  863.   #     triggers : 启动方式的数组
  864.   #     normal   : 优先级“与人物一样”还是其他
  865.   #--------------------------------------------------------------------------
  866.   def start_map_event(boundbox, triggers, normal)
  867.     $game_map.events_collide(boundbox).each do |event|
  868.       if event.trigger_in?(triggers) && event.normal_priority? == normal
  869.         event.start
  870.       end
  871.     end
  872.   end
  873.   #--------------------------------------------------------------------------
  874.   # ● 判定是否伤害地形
  875.   #--------------------------------------------------------------------------
  876.   def on_damage_floor?
  877.     $game_map.damage_floor_rect?(boundbox) && !in_airship?
  878.   end
  879.   #--------------------------------------------------------------------------
  880.   # ● 刷新
  881.   #--------------------------------------------------------------------------
  882.   alias pixel_move_refresh refresh
  883.   def refresh
  884.     pixel_move_refresh
  885.     if @character_name =~ /\[W(\d+)\]/
  886.       @character_data[0] = $1.to_i
  887.     else
  888.       @character_data[0] = 32
  889.     end
  890.     if @character_name =~ /\[H(\d+)\]/
  891.       @character_data[1] = $1.to_i
  892.     else
  893.       @character_data[1] = 32
  894.     end
  895.   end
  896.   #--------------------------------------------------------------------------
  897.   # ● 判定是否碰撞(包含跟随角色)
  898.   #--------------------------------------------------------------------------
  899.   def collide?(boundbox)
  900.     !@through && (collide_with?(boundbox) || followers.collide?(boundbox))
  901.   end
  902. end
  903. #==============================================================================
  904. # ■ Game_Event
  905. #------------------------------------------------------------------------------
  906. #  イベントを扱うクラスです。条件判定によるイベントページ切り替えや、並列処理
  907. # イベント実行などの機能を持っており、Game_Map クラスの内部で使用されます。
  908. #==============================================================================

  909. class Game_Event < Game_Character
  910.   #--------------------------------------------------------------------------
  911.   # ● オブジェクト初期化
  912.   #     event : RPG::Event
  913.   #--------------------------------------------------------------------------
  914.   def initialize(map_id, event)
  915.     super()
  916.     @map_id = map_id
  917.     @event = event
  918.     @id = @event.id
  919.     @offx = 0
  920.     @offy = 0
  921.     @offz = 0
  922.     refresh
  923.     obtain_initial_offset
  924.     moveto(@event.x, @event.y)
  925.   end
  926.   #--------------------------------------------------------------------------
  927.   # ● 设置事件页的设置
  928.   #--------------------------------------------------------------------------
  929.   alias pixel_move_setup_page_settings setup_page_settings
  930.   def setup_page_settings
  931.     pixel_move_setup_page_settings
  932.     if @character_name =~ /\[W(\d+)\]/
  933.       @character_data[0] = $1.to_i
  934.     else
  935.       @character_data[0] = 32
  936.     end
  937.     if @character_name =~ /\[H(\d+)\]/
  938.       @character_data[1] = $1.to_i
  939.     else
  940.       @character_data[1] = 32
  941.     end
  942.   end
  943.   #--------------------------------------------------------------------------
  944.   # ● 初期位置補正を獲得
  945.   #--------------------------------------------------------------------------
  946.   def obtain_initial_offset
  947.     return unless @list
  948.     @list.each do |command|
  949.       break if ![108,408].include?(command.code)
  950.       if command.parameters[0] =~ /offx=([+-]*\d+)/i
  951.         @offx += $1.to_i
  952.       elsif command.parameters[0] =~ /offy=([+-]*\d+)/i
  953.         @offy += $1.to_i
  954.       elsif command.parameters[0] =~ /offz=([+-]*\d+)/i
  955.         @offz += $1.to_i
  956.       end
  957.     end
  958.   end
  959.   #--------------------------------------------------------------------------
  960.   # ● 获取画面 Z 坐标
  961.   #--------------------------------------------------------------------------
  962.   def screen_z
  963.     super + @offz
  964.   end
  965.   #--------------------------------------------------------------------------
  966.   # ● 指定位置に移動
  967.   #--------------------------------------------------------------------------
  968.   def moveto(x, y)
  969.     super
  970.     @x = @real_x = @x+@offx
  971.     @y = @real_y = @y+@offy
  972.     @offx = 0
  973.     @offy = 0
  974.   end
  975.   #--------------------------------------------------------------------------
  976.   # ● 画面の可視領域付近にいるか判定
  977.   #     dx : 画面中央から左右何マス以内を判定するか
  978.   #     dy : 画面中央から上下何マス以内を判定するか
  979.   #--------------------------------------------------------------------------
  980.   def near_the_screen?(dx = 12, dy = 8)
  981.     dx,dy = dx*32,dy*32
  982.     ax = $game_map.adjust_x(@real_x) - Graphics.width / 2
  983.     ay = $game_map.adjust_y(@real_y) - Graphics.height / 2
  984.     ax >= -dx && ax <= dx && ay >= -dy && ay <= dy
  985.   end
  986.   #--------------------------------------------------------------------------
  987.   # ● プレイヤーの近くにいるか判定
  988.   #--------------------------------------------------------------------------
  989.   def near_the_player?
  990.     sx = distance_x_from($game_player.x).abs
  991.     sy = distance_y_from($game_player.y).abs
  992.     sx + sy < (20*32)
  993.   end
  994.   #--------------------------------------------------------------------------
  995.   # ● イベントIDを獲得
  996.   #--------------------------------------------------------------------------
  997.   def event_id
  998.     return @id
  999.   end
  1000.   #--------------------------------------------------------------------------
  1001.   # ● 接触事件的启动判定
  1002.   #--------------------------------------------------------------------------
  1003.   def check_event_trigger_touch(x, y)
  1004.     return if $game_map.interpreter.running?
  1005.     rect = boundbox
  1006.     rect.x = x
  1007.     rect.y = y
  1008.     if @trigger == 2 && !jumping? && normal_priority? && !empty?
  1009.       return start if $game_player.collide_with?(rect)
  1010.     end
  1011.   end
  1012.   #--------------------------------------------------------------------------
  1013.   # ● イベントとの衝突判定
  1014.   #--------------------------------------------------------------------------
  1015.   def collide_with_events?(boundbox)
  1016.     $game_map.events_collide_nt(boundbox).any? do |event|
  1017.       event.priority_type == self.priority_type && event.event_id != self.event_id
  1018.     end
  1019.   end
  1020.   #--------------------------------------------------------------------------
  1021.   # ● 判定是否与人物碰撞
  1022.   #--------------------------------------------------------------------------
  1023.   def collide_with_characters?(bondbox)
  1024.     super || collide_with_player_characters?(boundbox)
  1025.   end
  1026.   #--------------------------------------------------------------------------
  1027.   # ● 判定是否与玩家碰撞(包括跟随角色)
  1028.   #--------------------------------------------------------------------------
  1029.   def collide_with_player_characters?(boundbox)
  1030.     normal_priority? && $game_player.collide?(boundbox)
  1031.   end
  1032.   #--------------------------------------------------------------------------
  1033.   # ● 自动移动的更新
  1034.   #--------------------------------------------------------------------------
  1035.   def update_self_movement
  1036.     if near_the_screen? && (@stop_count > stop_count_threshold || @routine_move != nil)
  1037.       case @move_type
  1038.       when 1;  move_type_random
  1039.       when 2;  move_type_toward_player
  1040.       when 3;  move_type_custom
  1041.       end
  1042.     end
  1043.   end
  1044. end
  1045. #==============================================================================
  1046. # ■ Game_Follower
  1047. #------------------------------------------------------------------------------
  1048. #  フォロワーを扱うクラスです。フォロワーとは、隊列歩行で表示する、先頭以外の
  1049. # 仲間キャラクターのことです。Game_Followers クラスの内部で参照されます。
  1050. #==============================================================================

  1051. class Game_Follower < Game_Character
  1052.   #--------------------------------------------------------------------------
  1053.   # ● 先導キャラクターを追う
  1054.   #--------------------------------------------------------------------------
  1055.   def chase_preceding_character
  1056.     unless moving?
  1057.       sx = distance_x_from(@preceding_character.x)
  1058.       sy = distance_y_from(@preceding_character.y)
  1059.       sd = distance_from(@preceding_character)
  1060.       if sd > 32
  1061.         move_toward_character(@preceding_character)
  1062.       end
  1063.     end
  1064.   end
  1065. end
  1066. #==============================================================================
  1067. # ■ Game_Followers
  1068. #------------------------------------------------------------------------------
  1069. #  包装跟随角色的数组的外壳。本类在 Game_Player 类的内部使用。
  1070. #==============================================================================

  1071. class Game_Followers
  1072.   #--------------------------------------------------------------------------
  1073.   # ● 碰撞的判定
  1074.   #--------------------------------------------------------------------------
  1075.   def collide?(boundbox)
  1076.     visible_folloers.any? {|follower| follower.collide_with?(boundbox) }
  1077.   end
  1078. end
  1079. #==============================================================================
  1080. # ■ Game_Map
  1081. #------------------------------------------------------------------------------
  1082. #  マップを扱うクラスです。スクロールや通行可能判定などの機能を持っています。
  1083. # このクラスのインスタンスは $game_map で参照されます。
  1084. #==============================================================================

  1085. class Game_Map
  1086.   #--------------------------------------------------------------------------
  1087.   # ● 计算显示坐标的剩余 X 坐标
  1088.   #--------------------------------------------------------------------------
  1089.   def adjust_x(x)
  1090.     if loop_horizontal? && x < @display_x - (width - screen_tile_x) / 2
  1091.       x - @display_x + @map.width*32
  1092.     else
  1093.       x - @display_x
  1094.     end
  1095.   end
  1096.   #--------------------------------------------------------------------------
  1097.   # ● 计算显示坐标的剩余 Y 坐标
  1098.   #--------------------------------------------------------------------------
  1099.   def adjust_y(y)
  1100.     if loop_vertical? && y < @display_y - (height - screen_tile_y) / 2
  1101.       y - @display_y + @map.height*32
  1102.     else
  1103.       y - @display_y
  1104.     end
  1105.   end
  1106.   #--------------------------------------------------------------------------
  1107.   # ● 计算循环修正后的 X 坐标
  1108.   #--------------------------------------------------------------------------
  1109.   def round_x(x)
  1110.     loop_horizontal? ? (x + width*32) % (width*32) : x
  1111.   end
  1112.   #--------------------------------------------------------------------------
  1113.   # ● 计算循环修正后的 Y 坐标
  1114.   #--------------------------------------------------------------------------
  1115.   def round_y(y)
  1116.     loop_vertical? ? (y + height*32) % (height*32) : y
  1117.   end
  1118.   #--------------------------------------------------------------------------
  1119.   # ● 下にスクロール
  1120.   #--------------------------------------------------------------------------
  1121.   def scroll_down(distance)
  1122.     if loop_vertical?
  1123.       @display_y += distance
  1124.       @display_y %= @map.height*32
  1125.       @parallax_y += distance if @parallax_loop_y
  1126.     else
  1127.       last_y = @display_y
  1128.       @display_y = [@display_y + distance, (height - screen_tile_y)*32].min
  1129.       @parallax_y += @display_y - last_y
  1130.     end
  1131.   end
  1132.   #--------------------------------------------------------------------------
  1133.   # ● 左にスクロール
  1134.   #--------------------------------------------------------------------------
  1135.   def scroll_left(distance)
  1136.     if loop_horizontal?
  1137.       @display_x += @map.width*32 - distance
  1138.       @display_x %= @map.width*32
  1139.       @parallax_x -= distance if @parallax_loop_x
  1140.     else
  1141.       last_x = @display_x
  1142.       @display_x = [@display_x - distance, 0].max
  1143.       @parallax_x += @display_x - last_x
  1144.     end
  1145.   end
  1146.   #--------------------------------------------------------------------------
  1147.   # ● 右にスクロール
  1148.   #--------------------------------------------------------------------------
  1149.   def scroll_right(distance)
  1150.     if loop_horizontal?
  1151.       @display_x += distance
  1152.       @display_x %= @map.width*32
  1153.       @parallax_x += distance if @parallax_loop_x
  1154.     else
  1155.       last_x = @display_x
  1156.       @display_x = [@display_x + distance, (width - screen_tile_x)*32].min
  1157.       @parallax_x += @display_x - last_x
  1158.     end
  1159.   end
  1160.   #--------------------------------------------------------------------------
  1161.   # ● 上にスクロール
  1162.   #--------------------------------------------------------------------------
  1163.   def scroll_up(distance)
  1164.     if loop_vertical?
  1165.       @display_y += @map.height*32 - distance
  1166.       @display_y %= @map.height*32
  1167.       @parallax_y -= distance if @parallax_loop_y
  1168.     else
  1169.       last_y = @display_y
  1170.       @display_y = [@display_y - distance, 0].max
  1171.       @parallax_y += @display_y - last_y
  1172.     end
  1173.   end
  1174.   #--------------------------------------------------------------------------
  1175.   # ● 遠景表示の原点 X 座標の計算
  1176.   #--------------------------------------------------------------------------
  1177.   def parallax_ox(bitmap)
  1178.     if @parallax_loop_x
  1179.       @parallax_x
  1180.     else
  1181.       w1 = [bitmap.width - Graphics.width, 0].max
  1182.       w2 = [width * 32 - Graphics.width, 1].max
  1183.       @parallax_x * w1 / w2
  1184.     end
  1185.   end
  1186.   #--------------------------------------------------------------------------
  1187.   # ● 遠景表示の原点 Y 座標の計算
  1188.   #--------------------------------------------------------------------------
  1189.   def parallax_oy(bitmap)
  1190.     if @parallax_loop_y
  1191.       @parallax_y
  1192.     else
  1193.       h1 = [bitmap.height - Graphics.height, 0].max
  1194.       h2 = [height * 32 - Graphics.height, 1].max
  1195.       @parallax_y * h1 / h2
  1196.     end
  1197.   end
  1198.   #--------------------------------------------------------------------------
  1199.   # ● 表示位置の設定
  1200.   #--------------------------------------------------------------------------
  1201.   def set_display_pos(x, y)
  1202.     x = [0, [x, width*32 - screen_tile_x*32].min].max unless loop_horizontal?
  1203.     y = [0, [y, height*32 - screen_tile_y*32].min].max unless loop_vertical?
  1204.     @display_x = (x + width*32) % (width*32)
  1205.     @display_y = (y + height*32) % (height*32)
  1206.     @parallax_x = x
  1207.     @parallax_y = y
  1208.   end
  1209.   #--------------------------------------------------------------------------
  1210.   # ● 通行检查
  1211.   #     bit : 判断通行禁止与否的字节(请参照二进制运算)
  1212.   #--------------------------------------------------------------------------
  1213.   def check_passage(x, y, bit)
  1214.     x32,y32 = x/32,y/32
  1215.     lx,ly = x%32,y%32
  1216.     rid = region_id(x,y)
  1217.     data = @map.region_data(rid)
  1218.     if !data.empty?
  1219.       return true if lx >= data[0] && lx <= data[1] && ly >= data[2] && ly <= data[3]
  1220.     end
  1221.     all_tiles(x, y).each do |tile_id|
  1222.       flag = tileset.flags[tile_id]
  1223.       next if flag & 0x10 != 0            # [☆] : 不影响通行
  1224.       return true  if flag & bit == 0     # [○] : 可以通行
  1225.       return false if flag & bit == bit   # [×] : 不能通行
  1226.     end
  1227.     return false                          # 不能通行
  1228.   end
  1229.   #--------------------------------------------------------------------------
  1230.   # ● 有效坐标判定
  1231.   #--------------------------------------------------------------------------
  1232.   def valid_rect?(rect)
  1233.     rect.x >= 0 && rect.x+rect.width < width*32 &&
  1234.     rect.y >= 0 && rect.y+rect.height < height*32
  1235.   end
  1236.   #--------------------------------------------------------------------------
  1237.   # ● 获取矩形所包括的地图坐标数组
  1238.   #--------------------------------------------------------------------------
  1239.   def tiles_in(rect)
  1240.     xs = (rect.x/32)
  1241.     xe = (rect.x+rect.width)/32
  1242.     ys = (rect.y/32)
  1243.     ye = (rect.y+rect.height)/32
  1244.     arr = []
  1245.     (xs..xe).each do |x|
  1246.       (ys..ye).each do |y|
  1247.         arr.push([x,y])
  1248.       end
  1249.     end
  1250.     return arr
  1251.   end
  1252.   #--------------------------------------------------------------------------
  1253.   # ● 判定指定坐标处所有层次的标志
  1254.   #--------------------------------------------------------------------------
  1255.   def layered_tiles_rect_flag?(rect, bit)
  1256.     arr = tiles_in(rect)
  1257.     emu = nil
  1258.     if Kien::PixelMove::USE_PRECISE_TILETAG
  1259.       return arr.all? {|xy| layered_tiles(*xy).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }}
  1260.     else
  1261.       return arr.any?  {|xy| layered_tiles(*xy).any? {|tile_id| tileset.flags[tile_id] & bit != 0 }}
  1262.     end
  1263.   end
  1264.   #--------------------------------------------------------------------------
  1265.   # ● 判定是否梯子
  1266.   #--------------------------------------------------------------------------
  1267.   def ladder_rect?(boundbox)
  1268.     valid_rect?(boundbox) && layered_tiles_rect_flag?(boundbox, 0x20)
  1269.   end
  1270.   #--------------------------------------------------------------------------
  1271.   # ● 判定是否柜台属性
  1272.   #--------------------------------------------------------------------------
  1273.   def counter_rect?(boundbox)
  1274.     valid_rect?(boundbox) && layered_tiles_rect_flag?(boundbox, 0x80)
  1275.   end
  1276.   #--------------------------------------------------------------------------
  1277.   # ● 判定是否有害地形
  1278.   #--------------------------------------------------------------------------
  1279.   def damage_floor_rect?(boundbox)
  1280.     valid_rect?(boundbox) && layered_tiles_rect_flag?(boundbox, 0x100)
  1281.   end
  1282.   #--------------------------------------------------------------------------
  1283.   # ● 获取地形标志
  1284.   #--------------------------------------------------------------------------
  1285.   def terrain_tag(x, y)
  1286.     return 0 unless valid_rect?(x, y)
  1287.     layered_tiles(x, y).each do |tile_id|
  1288.       tag = tileset.flags[tile_id] >> 12
  1289.       return tag if tag > 0
  1290.     end
  1291.     return 0
  1292.   end
  1293.   #--------------------------------------------------------------------------
  1294.   # ● 获取区域 ID 数组
  1295.   #--------------------------------------------------------------------------
  1296.   def region_id_rect(boundbox)
  1297.     if valid_rect?(boundbox)
  1298.       arr = tiles_in(boundbox)
  1299.       hash = {}
  1300.       arr.each do |xy|
  1301.         hash[xy] = @map.data[*xy, 3] >> 8
  1302.       end
  1303.       return hash
  1304.     end
  1305.     return {}
  1306.   end
  1307.   #--------------------------------------------------------------------------
  1308.   # ● 获取与指定矩形重叠的事件的数组
  1309.   #--------------------------------------------------------------------------
  1310.   def events_collide(boundbox)
  1311.     @events.values.select {|event| event.collide_with?(boundbox) }
  1312.   end
  1313.   #--------------------------------------------------------------------------
  1314.   # ● 获取指定坐标处存在的事件(穿透以外)的数组
  1315.   #--------------------------------------------------------------------------
  1316.   def events_collide_nt(boundbox)
  1317.     @events.values.select {|event| event.collide_with?(boundbox) && !event.through }
  1318.   end
  1319.   #--------------------------------------------------------------------------
  1320.   # ● 获取指定坐标处存在的图块事件(穿透以外)的数组
  1321.   #--------------------------------------------------------------------------
  1322.   def tile_events_collide(boundbox)
  1323.     @tile_events.select {|event| event.collide_with?(boundbox) && !event.through }
  1324.   end
  1325.   #--------------------------------------------------------------------------
  1326.   # ● 获取指定坐标处存在的事件的 ID (仅一个)
  1327.   #--------------------------------------------------------------------------
  1328.   def event_id_collide(boundbox)
  1329.     list = events_xy(boundbox)
  1330.     list.empty? ? 0 : list[0].id
  1331.   end
  1332. end
  1333. #==============================================================================
  1334. # ■ Spriteset_Map
  1335. #------------------------------------------------------------------------------
  1336. #  マップ画面のスプライトやタイルマップなどをまとめたクラスです。このクラスは
  1337. # Scene_Map クラスの内部で使用されます。
  1338. #==============================================================================

  1339. class Spriteset_Map
  1340.   #--------------------------------------------------------------------------
  1341.   # ● タイルマップの更新
  1342.   #--------------------------------------------------------------------------
  1343.   def update_tilemap
  1344.     @tilemap.map_data = $game_map.data
  1345.     @tilemap.ox = $game_map.display_x
  1346.     @tilemap.oy = $game_map.display_y
  1347.     @tilemap.update
  1348.   end
  1349. end
  1350. #==============================================================================
  1351. # ■ Sprite_Character
  1352. #------------------------------------------------------------------------------
  1353. #  地图人物的精灵。根据 Game_Character 类的实例自动变化。
  1354. #==============================================================================

  1355. class Sprite_Character < Sprite_Base
  1356.   #--------------------------------------------------------------------------
  1357.   # ● 设置图块的位图
  1358.   #--------------------------------------------------------------------------
  1359.   def set_tile_bitmap
  1360.     sx = (@tile_id / 128 % 2 * 8 + @tile_id % 8) * 32;
  1361.     sy = @tile_id % 256 / 8 % 16 * 32;
  1362.     self.bitmap = tileset_bitmap(@tile_id)
  1363.     self.src_rect.set(sx, sy, 32, 32)
  1364.     self.ox = 16
  1365.     self.oy = 32
  1366.   end
  1367.   #--------------------------------------------------------------------------
  1368.   # ● 设置角色的位图
  1369.   #--------------------------------------------------------------------------
  1370.   def set_character_bitmap
  1371.     self.bitmap = Cache.character(@character_name)
  1372.     sign = @character_name[/^[\!\$]./]
  1373.     if sign && sign.include?('$')
  1374.       @cw = bitmap.width / 3
  1375.       @ch = bitmap.height / 4
  1376.     else
  1377.       @cw = bitmap.width / 12
  1378.       @ch = bitmap.height / 8
  1379.     end
  1380.     self.ox = @cw/2
  1381.     self.oy = @ch
  1382.   end
  1383. end
复制代码


注意,这个脚本基本把所有Game_Map和Game_CharacterBase与其继承类改的面目全非,与其他地图类脚本基本无法共存(因该),如果有冲突问题请放弃这个脚本,毕竟对实际游戏内容基本没有改变。另外脚本的说明请看脚本内容的开头的注释,除了那些就没有啥可以动的了。

例子.PNG
事件里的移动路线里的各种移动指令将只会令事件移动一定像素(不是一整格),移动像素量是在事件设置里面的移动速度。另外为了移动频率需要设置成最大来保证事件移动的流畅。
这脚本其实是去年完成的囧   

点评

见过类似的  发表于 2014-6-12 20:05

评分

参与人数 3星屑 +191 收起 理由
kakarot + 180 塞糖~
3106345123 + 1 塞糖
jspython + 10 好牛逼的样子...地址在哪?

查看全部评分

梦石
0
星屑
15290
在线时间
1593 小时
注册时间
2012-7-24
回帖
1246
发表于 2014-6-12 12:40:03 | 显示全部楼层
还是想看游戏截图效果如何感觉很强大的脚本

点评

截图真的不知到该怎么截。截个图在两个格子正中央?  发表于 2014-6-12 18:08

欢迎大家加我
回复

使用道具 举报

梦石
0
星屑
8026
在线时间
1051 小时
注册时间
2012-4-3
回帖
1270

开拓者

发表于 2014-6-12 18:03:44 来自手机 | 显示全部楼层
走半步,然后kiss动作就可以很好地刻画了。
回复

使用道具 举报

梦石
0
星屑
49
在线时间
108 小时
注册时间
2013-12-11
回帖
358
发表于 2014-6-12 19:15:37 | 显示全部楼层
好流弊的样子
我是拘束,我为自己代言,并为自己带盐,并喂自己袋盐!
咳...齁死我了...
小学生党。来自SHADE。
活跃在水世界(活跃吗)(在水世界有个毛用啊)
表示对RM橙光神马的完全不熟悉......
虽然我还是在用吧......
完。
回复

使用道具 举报

梦石
0
星屑
803
在线时间
2068 小时
注册时间
2011-10-3
回帖
1620
发表于 2014-6-12 22:16:09 | 显示全部楼层
想知道走到两个事件中间后,按确定调查后显示的是哪个事件的对话(之前找的几个像素移动都有这样的问题)

点评

判定方向是从左到右从上到下,左上-〉左下-〉右上-〉右下的顺序  发表于 2014-6-13 20:23
回复

使用道具 举报

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
回帖
2257

贵宾

发表于 2014-6-14 18:14:02 | 显示全部楼层
发个工程吧,不知道为什么我放进去没效果的样子。

点评

把开关100打开。  发表于 2014-6-15 18:10
回复

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部