查看: 3154|回复: 2

[已经解决] 关于八方向行走的问题

[复制链接]
梦石
0
星屑
4825
在线时间
766 小时
注册时间
2006-9-25
回帖
47
发表于 2019-10-25 09:33:36 | 显示全部楼层 |阅读模式

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

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

×
最近想把老游戏的行走图换成八方向的,找了个八方向的脚本,可是和我的图片方向顺序不一样,一个个改图片太麻烦了,想改下脚本可是找不到方法。。。。我图片是,下,左,右,上,左下,右下,左上,右上。这个脚本是左下,右下,左上,右上,下,左,上,右。应该怎么改?求教,谢谢。
  1. ###########################################################################################################################
  2. # 脚本功能:八方向走与多帧移动之图片修正 + 人物跟随。

  3. # 附赠功能:
  4. #     可以让NPC角色随机8方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c8即可
  5. #     可以让NPC角色随机4斜角方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c4即可
  6. #     可以让NPC角色随机4方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入z4即可
  7. #     可以使用真·斜4方向行走,参考脚本53行开始

  8. #改:个快快
  9. #修正内容:修正方向错位,改变站位,切换人物图片错乱
  10. #新增功能:可以让NPC任意规格 8X4 8X5 7X8 1X5都可以

  11. #2 下 4左 6右 8 上 1左下 3右下 7左上 9右上
  12. #修正数据库:{列,行,X坐标,Y坐标}
  13. $人物 = {

  14. "_本事和尚" => [7,4],
  15. }


  16. $c3_每一步的帧数 = 8
  17. $c3_总共可用的方向数 = 8
  18. class Game_Character
  19.   def event_is_in?(x, y)
  20.     for event in $game_map.events.values
  21.       # 事件坐标与目标一致的情况下
  22.       if event.x == x and event.y == y
  23.         # 跳跃中以外的情况下、启动判定是同位置的事件
  24.         return true
  25.       end
  26.     end
  27.     return false
  28.   end
  29.   def player_is_in?(x, y)
  30.     if $game_player.x == x and $game_player.y == y
  31.       return true
  32.     end
  33.     return false
  34.   end
  35.   def can_go?(x, y)
  36.     if player_is_in?(x, y) or event_is_in?(x, y)
  37.       return false
  38.     else
  39.       return true
  40.     end
  41.   end
  42.   #--------------------------------------------------------------------------
  43.   # ● 向下移动
  44.   #     turn_enabled : 本场地位置更改许可标志
  45.   #--------------------------------------------------------------------------
  46.   def move_down(turn_enabled = true)
  47.     # 面向下
  48.     if turn_enabled
  49.       turn_down
  50.     end
  51.     # 可以通行的场合
  52.     if passable?(@x, @y, 2)
  53.       # 面向下
  54.       turn_down
  55.       # 更新坐标
  56.       @y += 1
  57.       # 增加步数
  58.       increase_steps
  59.     #..........................................................................
  60.     elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN) and
  61.           can_go?(@x, @y + 1)
  62.       unless @direction_fix
  63.         @direction = 1
  64.       end
  65.       @x -= 1
  66.       @y += 1
  67.       increase_steps
  68.     elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN) and
  69.           can_go?(@x, @y + 1)
  70.       unless @direction_fix
  71.         @direction = 3
  72.       end
  73.       @x += 1
  74.       @y += 1
  75.       increase_steps
  76.     #..........................................................................
  77.     # 不能通行的情况下
  78.     else
  79.       # 接触事件的启动判定
  80.       check_event_trigger_touch(@x, @y+1)
  81.     end
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ● 向左移动
  85.   #     turn_enabled : 本场地位置更改许可标志
  86.   #--------------------------------------------------------------------------
  87.   def move_left(turn_enabled = true)
  88.     # 面向左
  89.     if turn_enabled
  90.       turn_left
  91.     end
  92.     # 可以通行的情况下
  93.     if passable?(@x, @y, 4)
  94.       # 面向左
  95.       turn_left
  96.       # 更新坐标
  97.       @x -= 1
  98.       # 增加步数
  99.       increase_steps
  100.     #..........................................................................
  101.     elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT) and
  102.           can_go?(@x - 1, @y)
  103.       unless @direction_fix
  104.         @direction = 7
  105.       end
  106.       @x -= 1
  107.       @y -= 1
  108.       increase_steps
  109.     elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT) and
  110.           can_go?(@x - 1, @y)
  111.       unless @direction_fix
  112.         @direction = 1
  113.       end
  114.       @x -= 1
  115.       @y += 1
  116.       increase_steps
  117.     #..........................................................................
  118.     # 不能通行的情况下
  119.     else
  120.       # 接触事件的启动判定
  121.       check_event_trigger_touch(@x-1, @y)
  122.     end
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 向右移动
  126.   #     turn_enabled : 本场地位置更改许可标志
  127.   #--------------------------------------------------------------------------
  128.   def move_right(turn_enabled = true)
  129.     # 面向右
  130.     if turn_enabled
  131.       turn_right
  132.     end
  133.     # 可以通行的场合
  134.     if passable?(@x, @y, 6)
  135.       # 面向右
  136.       turn_right
  137.       # 更新坐标
  138.       @x += 1
  139.       # 增加部数
  140.       increase_steps
  141.     #..........................................................................
  142.     elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT) and
  143.           can_go?(@x + 1, @y)
  144.       unless @direction_fix
  145.         @direction = 9
  146.       end
  147.       @x += 1
  148.       @y -= 1
  149.       increase_steps
  150.     elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT) and
  151.           can_go?(@x + 1, @y)
  152.       unless @direction_fix
  153.         @direction = 3
  154.       end
  155.       @x += 1
  156.       @y += 1
  157.       increase_steps
  158.     #..........................................................................
  159.     # 不能通行的情况下
  160.     else
  161.       # 接触事件的启动判定
  162.       check_event_trigger_touch(@x+1, @y)
  163.     end
  164.   end
  165.   #--------------------------------------------------------------------------
  166.   # ● 向上移动
  167.   #     turn_enabled : 本场地位置更改许可标志
  168.   #--------------------------------------------------------------------------
  169.   def move_up(turn_enabled = true)
  170.     # 面向上
  171.     if turn_enabled
  172.       turn_up
  173.     end
  174.     # 可以通行的情况下
  175.     if passable?(@x, @y, 8)
  176.       # 面向上
  177.       turn_up
  178.       # 更新坐标
  179.       @y -= 1
  180.       # 歩数増加
  181.       increase_steps
  182.     #..........................................................................
  183.     elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP) and
  184.           can_go?(@x, @y - 1)
  185.       unless @direction_fix
  186.         @direction = 7
  187.       end
  188.       @x -= 1
  189.       @y -= 1
  190.       increase_steps
  191.     elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP) and
  192.           can_go?(@x, @y - 1)
  193.       unless @direction_fix
  194.         @direction = 9
  195.       end
  196.       @x += 1
  197.       @y -= 1
  198.       increase_steps
  199.     #..........................................................................
  200.     # 不能通行的情况下
  201.     else
  202.       # 接触事件的启动判定
  203.       check_event_trigger_touch(@x, @y-1)
  204.     end
  205.   end
  206.   #--------------------------------------------------------------------------
  207.   # ● 向左下移动
  208.   #--------------------------------------------------------------------------
  209.   def move_lower_left
  210.     # 没有固定面向的场合
  211.     unless @direction_fix
  212.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  213.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  214.     end
  215.     # 下→左、左→下 的通道可以通行的情况下
  216.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  217.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  218.       # 更新坐标
  219.       @x -= 1
  220.       @y += 1
  221.       # 增加步数
  222.       increase_steps
  223.     #..........................................................................
  224.     elsif passable?(@x, @y, Input::DOWN) and can_go?(@x - 1, @y + 1)
  225.       unless @direction_fix
  226.         @direction = 2
  227.       end
  228.       @y += 1
  229.       increase_steps
  230.     elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y + 1)
  231.       unless @direction_fix
  232.         @direction = 4
  233.       end
  234.       @x -= 1
  235.       increase_steps
  236.     #..........................................................................
  237.     end
  238.   end
  239.   #--------------------------------------------------------------------------
  240.   # ● 向右下移动
  241.   #--------------------------------------------------------------------------
  242.   def move_lower_right
  243.     # 没有固定面向的场合
  244.     unless @direction_fix
  245.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  246.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  247.     end
  248.     # 下→右、右→下 的通道可以通行的情况下
  249.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  250.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  251.       # 更新坐标
  252.       @x += 1
  253.       @y += 1
  254.       # 增加步数
  255.       increase_steps
  256.     elsif passable?(@x, @y, Input::DOWN) and can_go?(@x + 1, @y + 1)
  257.       unless @direction_fix
  258.         @direction = 2
  259.       end
  260.       @y += 1
  261.       increase_steps
  262.     elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y + 1)
  263.       unless @direction_fix
  264.         @direction = 6
  265.       end
  266.       @x += 1
  267.       increase_steps
  268.     end
  269.   end
  270.   #--------------------------------------------------------------------------
  271.   # ● 向左上移动
  272.   #--------------------------------------------------------------------------
  273.   def move_upper_left
  274.     # 没有固定面向的场合
  275.     unless @direction_fix
  276.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  277.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  278.     end
  279.     # 上→左、左→上 的通道可以通行的情况下
  280.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  281.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  282.       # 更新坐标
  283.       @x -= 1
  284.       @y -= 1
  285.       # 增加步数
  286.       increase_steps
  287.     #..........................................................................
  288.     elsif passable?(@x, @y, Input::UP) and can_go?(@x - 1, @y - 1)
  289.       unless @direction_fix
  290.         @direction = 8
  291.       end
  292.       @y -= 1
  293.       increase_steps
  294.     elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y - 1)
  295.       unless @direction_fix
  296.         @direction = 4
  297.       end
  298.       @x -= 1
  299.       increase_steps
  300.     #..........................................................................
  301.     end
  302.   end
  303.   #--------------------------------------------------------------------------
  304.   # ● 向右上移动
  305.   #--------------------------------------------------------------------------
  306.   def move_upper_right
  307.     # 没有固定面向的场合
  308.     unless @direction_fix
  309.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  310.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  311.     end
  312.     # 上→右、右→上 的通道可以通行的情况下
  313.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  314.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  315.       # 更新坐标
  316.       @x += 1
  317.       @y -= 1
  318.       # 增加步数
  319.       increase_steps
  320.     #..........................................................................
  321.     elsif passable?(@x, @y, Input::UP) and can_go?(@x + 1, @y - 1)
  322.       unless @direction_fix
  323.         @direction = 8
  324.       end
  325.       @y -= 1
  326.       increase_steps
  327.     elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y - 1)
  328.       unless @direction_fix
  329.         @direction = 6
  330.       end
  331.       @x += 1
  332.       increase_steps
  333.     #..........................................................................
  334.     end
  335.   end
  336. end
  337. #-------------------------------------------------------------------------------
  338. class Game_Event < Game_Character
  339. def name
  340.   return @event.name
  341. end  
  342. def name=(newname)
  343.   @event.name = newname
  344. end
  345. end
  346. class Game_Player < Game_Character
  347. def name
  348.      return ""
  349. end
  350. end

  351. class Sprite_Character < RPG::Sprite
  352. #--------------------------------------------------------------------------
  353. # ● 定义实例变量
  354. #--------------------------------------------------------------------------
  355. attr_accessor :character                # 角色
  356.   #--------------------------------------------------------------------------
  357. # ● 初始化对像
  358. #     viewport  : 查看端口
  359. #     character : 角色 (Game_Character)
  360. #--------------------------------------------------------------------------
  361. def initialize(viewport, character = nil)
  362.   name = character.name
  363.   super(viewport)
  364.   @character = character
  365.   
  366.   @namesprite = Sprite.new(viewport)
  367.       @namesprite.x = self.x - 50   
  368.    
  369.     if $人物[@character.character_name]  and  $人物[@character.character_name][3]      
  370.        @namesprite.y = self.y - $人物[@character.character_name][3]  
  371.     else
  372.         @namesprite.y = self.y        
  373.     end

  374.   
  375.   #影子
  376.   @shadow = Sprite.new(viewport)
  377.   
  378.      @shadow.bitmap = RPG::Cache.character("shadow.png",1)
  379.   
  380.   @namesprite.bitmap = Bitmap.new(100, 32)
  381.   @namesprite.bitmap.font.name = "宋体"
  382.   @namesprite.bitmap.font.size = 16
  383.   @namesprite.bitmap.font.color.set(255, 255, 0)
  384.   @evname = name
  385.   @evname_split = name.split(/,/)[0]
  386.   if name[0, 2]=="EV"
  387.     @evname_split = ""
  388.   end
  389.   if name.split(/,/)[1] != nil
  390.     case name.split(/,/)[1]
  391.     when "0"
  392.       @namesprite.bitmap.font.color.set(255, 255, 255)
  393.     when "1"
  394.       @namesprite.bitmap.font.color.set(128, 128, 255)
  395.     when "2"
  396.       @namesprite.bitmap.font.color.set(255, 128, 128)
  397.     when "3"
  398.       @namesprite.bitmap.font.color.set(128, 255, 128)
  399.     when "4"
  400.       @namesprite.bitmap.font.color.set(128, 255, 255)
  401.     when "5"
  402.       @namesprite.bitmap.font.color.set(255, 128, 255)
  403.     when "6"
  404.       @namesprite.bitmap.font.color.set(255, 255, 128)
  405.     when "7"
  406.       @namesprite.bitmap.font.color.set(192, 192, 192)
  407.     else
  408.       @namesprite.bitmap.font.color.set(255, 255, 255)
  409.     end
  410.   end

  411.   update
  412. end
  413. end
  414. #----------------------------------------------------------------------------
  415. class Game_Player < Game_Character
  416. if $c3_总共可用的方向数 == 8
  417.    def update
  418.      last_moving = moving?
  419.      unless moving? or $game_system.map_interpreter.running? or
  420.             @move_route_forcing or $game_temp.message_window_showing
  421.        # 用井号后面的东西替代前面的,就可以实现斜4方向走
  422.        case Input.dir8
  423.        when 2
  424.          move_down #move_lower_left
  425.          
  426.        when 4
  427.          move_left #move_upper_left
  428.          
  429.        when 6
  430.          move_right #move_lower_right
  431.          
  432.        when 8
  433.          move_up #move_upper_right
  434.          
  435.        when 1
  436.          move_lower_left
  437.          
  438.        when 3
  439.          move_lower_right
  440.      
  441.        when 7
  442.          move_upper_left
  443.       
  444.        when 9
  445.          move_upper_right
  446.         
  447.        else
  448.          
  449.        end
  450.      end
  451.      # 本地变量记忆坐标
  452.      last_real_x = @real_x
  453.      last_real_y = @real_y
  454.      super
  455.   


  456.      # 角色向下移动、画面上的位置在中央下方的情况下
  457.      if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  458.        # 画面向下卷动
  459.        $game_map.scroll_down(@real_y - last_real_y)
  460.      end
  461.      # 角色向左移动、画面上的位置在中央左方的情况下
  462.      if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  463.        # 画面向左卷动
  464.        $game_map.scroll_left(last_real_x - @real_x)
  465.      end
  466.      # 角色向右移动、画面上的位置在中央右方的情况下
  467.      if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  468.        # 画面向右卷动
  469.        $game_map.scroll_right(@real_x - last_real_x)
  470.      end
  471.      # 角色向上移动、画面上的位置在中央上方的情况下
  472.      if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  473.        # 画面向上卷动
  474.        $game_map.scroll_up(last_real_y - @real_y)
  475.      end

  476.      # 不在移动中的情况下
  477.      unless moving?
  478.        # 上次主角移动中的情况
  479.        if last_moving
  480.          # 与同位置的事件接触就判定为事件启动
  481.          result = check_event_trigger_here([1,2])
  482.          # 没有可以启动的事件的情况下
  483.          if result == false
  484.            # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  485.            unless $DEBUG and Input.press?(Input::CTRL)
  486.              # 遇敌计数下降
  487.              if @encounter_count > 0
  488.                @encounter_count -= 1
  489.              end
  490.            end
  491.          end
  492.        end
  493.        # 按下 C 键的情况下
  494.        if Input.trigger?(Input::C)
  495.          # 判定为同位置以及正面的事件启动
  496.          check_event_trigger_here([0])
  497.          check_event_trigger_there([0,1,2])
  498.        end
  499.      else
  500.        if @move_route_forcing and  $game_map.encounter_list != []
  501.          if @encounter_count > 0
  502.            @encounter_count -= 1 if Graphics.frame_count % 20 == 0
  503.          #elsif $game_map.encounter_list != []
  504.          #  @encounter_coun = 0
  505.          #  @move_route_forcing = false
  506.          else
  507.            @encounter_coun = 0
  508.            @move_route_forcing = false
  509.          end
  510.          #耶..一样好不。。不信试试
  511.        end
  512.      end
  513.    end
  514.    #--------------------------------------------------------------------------
  515.    # ● 正面事件的启动判定
  516.    #--------------------------------------------------------------------------
  517.    def check_event_trigger_there(triggers)
  518.      result = false
  519.      # 事件执行中的情况下
  520.      if $game_system.map_interpreter.running?
  521.        return result
  522.      end
  523.      # 计算正面坐标
  524.      new_x = @x
  525.      new_y = @y
  526.      case @direction
  527.      when 1
  528.        new_x -= 1
  529.        new_y += 1
  530.      when 2
  531.        new_y += 1
  532.      when 3
  533.        new_x += 1
  534.        new_y += 1
  535.      when 4
  536.        new_x -= 1
  537.      when 6
  538.        new_x += 1
  539.      when 7
  540.        new_x -= 1
  541.        new_y -= 1
  542.      when 8
  543.        new_y -= 1
  544.      when 9
  545.        new_x += 1
  546.        new_y -= 1
  547.      end
  548.      # 全部事件的循环
  549.      for event in $game_map.events.values
  550.        # 事件坐标与目标一致的情况下
  551.        if event.x == new_x and event.y == new_y and
  552.           triggers.include?(event.trigger)
  553.          # 跳跃中以外的情况下、启动判定是正面的事件
  554.          if not event.jumping? and not event.over_trigger? and $scene == nil
  555.            event.start
  556.            result = true
  557.          end
  558.        end
  559.      end
  560.      # 找不到符合条件的事件的情况下
  561.      if result == false
  562.        # 正面的元件是计数器的情况下
  563.        if $game_map.counter?(new_x, new_y)
  564.          # 计算 1 元件里侧的坐标
  565.          new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  566.          new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  567.          # 全事件的循环
  568.          for event in $game_map.events.values
  569.            # 事件坐标与目标一致的情况下
  570.            if event.x == new_x and event.y == new_y
  571.               triggers.include?(event.trigger)
  572.              # 跳跃中以外的情况下、启动判定是正面的事件
  573.              if not event.jumping? and not event.over_trigger? and $scene == nil
  574.                event.start
  575.                result = true
  576.              end
  577.            end
  578.          end
  579.        end
  580.      end
  581.      return result
  582.    end
  583. end
  584. end


  585. class Sprite_Character < RPG::Sprite
  586.   def dispose
  587.     super
  588.     if @namesprite.bitmap != nil
  589.       @namesprite.bitmap.dispose
  590.     end
  591.     @namesprite.dispose
  592.     if @shadow.bitmap != nil
  593.       @shadow.bitmap.dispose
  594.     end
  595.     @shadow.dispose
  596.   end
  597.   #----------------------------------------------------------------------------
  598.   # 更新
  599.   #----------------------------------------------------------------------------
  600.   def update
  601.     if @character.x < $game_player.x - 20 or @character.x > $game_player.x + 20 or
  602.      @character.y < $game_player.y - 15 or @character.y > $game_player.y + 15
  603.         return
  604.       end
  605.     super
  606.     #判断影子有无
  607.     if @character_name == nil or @character.character_name == "_W1" or @character_name =="传送" or @character_name == ""
  608.       unless @shadow.bitmap.disposed?
  609.         @shadow.bitmap.dispose
  610.       end
  611.     else
  612.       if @shadow.bitmap.disposed?
  613.         @shadow.bitmap = RPG::Cache.character("shadow", 1)
  614.       end
  615.     end
  616.     if @evname != @character.name
  617.       @namesprite.bitmap.clear
  618.       @evname = @character.name
  619.       @evname_split = @character.name.split(/,/)[0]
  620.       if @evname[0, 2]=="EV"
  621.         @evname_split = ""
  622.       end
  623.       if @character.name.split(/,/)[1] != nil
  624.         case @character.name.split(/,/)[1]
  625.         when "0"
  626.           @namesprite.bitmap.font.color.set(255, 255, 255)
  627.         when "1"
  628.           @namesprite.bitmap.font.color.set(128, 128, 255)
  629.         when "2"
  630.           @namesprite.bitmap.font.color.set(255, 128, 128)
  631.         when "3"
  632.           @namesprite.bitmap.font.color.set(128, 255, 128)
  633.         when "4"
  634.           @namesprite.bitmap.font.color.set(128, 255, 255)
  635.         when "5"
  636.           @namesprite.bitmap.font.color.set(255, 128, 255)
  637.         when "6"
  638.           @namesprite.bitmap.font.color.set(255, 255, 128)
  639.         when "7"
  640.           @namesprite.bitmap.font.color.set(192, 192, 192)
  641.         else
  642.           @namesprite.bitmap.font.color.set(255, 255, 255)
  643.         end
  644.       end
  645.       
  646.             
  647.      @namesprite.x = self.x - 50   
  648.    
  649.      
  650.      if $人物[@character.character_name]  and  $人物[@character.character_name][3]      
  651.         @namesprite.y = self.y - $人物[@character.character_name][3]  
  652.      else
  653.          @namesprite.y = self.y        
  654.      end
  655.       


  656.     end

  657. #------------------------------------------------------------------------------
  658.    # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  659.    if @tile_id != @character.tile_id or
  660.       @character_name != @character.character_name or
  661.       @character_hue != @character.character_hue
  662.      # 记忆元件 ID 与文件名、色相
  663.      @tile_id = @character.tile_id
  664.      @character_name = @character.character_name
  665.      if @character_name != nil and @character_name != ""
  666.        @namesprite.bitmap.clear
  667.       @evname = @character.name
  668.       @evname_split = @character.name.split(/,/)[0]
  669.       if @evname[0, 2]=="EV"
  670.         @evname_split = ""
  671.       end
  672.       if @character.name.split(/,/)[1] != nil
  673.         case @character.name.split(/,/)[1]
  674.         when "0"
  675.           @namesprite.bitmap.font.color.set(255, 255, 255)
  676.         when "1"
  677.           @namesprite.bitmap.font.color.set(128, 128, 255)
  678.         when "2"
  679.           @namesprite.bitmap.font.color.set(255, 128, 128)
  680.         when "3"
  681.           @namesprite.bitmap.font.color.set(128, 255, 128)
  682.         when "4"
  683.           @namesprite.bitmap.font.color.set(128, 255, 255)
  684.         when "5"
  685.           @namesprite.bitmap.font.color.set(255, 128, 255)
  686.         when "6"
  687.           @namesprite.bitmap.font.color.set(255, 255, 128)
  688.         when "7"
  689.           @namesprite.bitmap.font.color.set(192, 192, 192)
  690.         else
  691.           @namesprite.bitmap.font.color.set(255, 255, 255)
  692.         end
  693.       end

  694.      elsif @character_name != nil and @character_name == ""
  695.       @namesprite.bitmap.clear
  696.      end
  697.      @character_hue = @character.character_hue
  698.      # 元件 ID 为有效值的情况下
  699.      if @tile_id >= 384
  700.        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  701.          @tile_id, @character.character_hue)
  702.          

  703.         
  704.        self.src_rect.set(0, 0, 32, 32)
  705.        self.ox = 16
  706.        self.oy = 32
  707.      # 元件 ID 为无效值的情况下
  708.      else
  709.       self.bitmap = RPG::Cache.character(@character.character_name,
  710.          @character.character_hue)

  711.          
  712.          if $人物[@character.character_name]
  713.             @cw = bitmap.width / $人物[@character.character_name][0]

  714.             else
  715.            
  716.               @cw = bitmap.width / $c3_每一步的帧数
  717.               
  718.             end
  719.             
  720.        if $c3_总共可用的方向数==4
  721.          @ch = bitmap.height / 4
  722.        else
  723.          if $人物[@character.character_name]
  724.             @ch = bitmap.height / $人物[@character.character_name][1]

  725.             else
  726.          @ch = bitmap.height / 8
  727.          end
  728.        end
  729.       #判断文件名中附加oy
  730.       name = "Graphics/Characters/"+@character.character_name+".txt"
  731.       default_name = "Graphics/Characters/default.txt"
  732.       @ox_move = 0
  733.       @oy_move = 0
  734.       if @character.character_name != ""
  735.         body = File.open(name,"r") rescue body = File.open(default_name,"r")
  736.         line=body.readlines
  737.         if line[0].split("\n")[0].to_i != 0
  738.           @ox_move = line[0].split("\n")[0].to_i
  739.           @oy_move = line[1].split("\n")[0].to_i
  740.         end
  741.         body.close
  742.       end
  743.       if @oy_move != 0 or @ox_move != 0
  744.         self.ox = @ox_move
  745.         self.oy = @oy_move + 10
  746.       else
  747.         self.ox = @cw / 2
  748.         self.oy = @ch
  749.       end
  750.      end
  751.    end
  752.    # 设置可视状态
  753.    self.visible = (not @character.transparent)
  754.    # 图形是角色的情况下
  755.    if @tile_id == 0
  756.      # 设置传送目标的矩形
  757.      sx = @character.pattern * @cw
  758.       #2 下 4左 6右 8 上 1左下 3右下 7左上 9右上
  759.      if $c3_总共可用的方向数==8
  760.          if $人物[@character.character_name] and $人物[@character.character_name][1]==4
  761.        if  @character == $game_player
  762.        case @character.direction
  763.         when 2
  764.          sy = 0 * @ch
  765.        when 4
  766.          sy = 1 * @ch
  767.        when 6
  768.          sy = 3 * @ch
  769.        when 8
  770.          sy = 2 * @ch
  771.        when 1
  772.          sy = 1 * @ch
  773.        when 3
  774.          sy = 0 * @ch
  775.        when 7
  776.          sy = 2 * @ch
  777.        when 9
  778.          sy = 3 * @ch
  779.        end
  780.      else
  781.            case @character.direction
  782.           when 2
  783.          sy = 0 * @ch
  784.        when 4
  785.          sy = 1 * @ch
  786.        when 6
  787.          sy = 2 * @ch
  788.        when 8
  789.          sy = 3 * @ch
  790.        when 1
  791.          sy = 4 * @ch
  792.        when 3
  793.          sy = 5 * @ch
  794.        when 7
  795.          sy = 6 * @ch
  796.        when 9
  797.          sy = 7 * @ch
  798.          end
  799.       
  800.      end
  801.      
  802.        else
  803.        case @character.direction
  804.          when 2
  805.          sy = 4 * @ch

  806.        when 4
  807.          sy = 5 * @ch

  808.        when 6
  809.          sy = 7 * @ch

  810.        when 8
  811.          sy = 6 * @ch

  812.        when 1
  813.          sy = 1 * @ch

  814.        when 3
  815.          sy = 0 * @ch

  816.        when 7
  817.          sy = 2 * @ch

  818.        when 9
  819.          sy = 3 * @ch

  820.        end
  821.        end
  822.      else
  823.        sy = (@character.direction - 2) / 2 * @ch
  824.      end
  825.      unless sy
  826.        sy = 0
  827.      end
  828.      
  829.          
  830.      self.src_rect.set(sx, sy, @cw, @ch)
  831.      
  832.    end
  833.    
  834.    
  835.    self.x = @character.screen_x
  836.    self.y = @character.screen_y
  837.    
  838.       #刷新影子位置
  839.    unless @shadow.bitmap.disposed?
  840.      if @oy_move != nil or @ox_move != nil
  841.        @shadow.x = self.x - @shadow.bitmap.width / 2
  842.        @shadow.y = self.y - @shadow.bitmap.height / 2 - 10
  843.      else
  844.        @shadow.x = self.x - @shadow.bitmap.width / 2
  845.        @shadow.y = self.y - @shadow.bitmap.height / 2 - 10
  846.      end
  847.    end
  848.    # 设置脚本的坐标
  849.    if $人物[@character.character_name] and $人物[@character.character_name][2]
  850.        self.x = @character.screen_x + $人物[@character.character_name][2]
  851.        self.y = @character.screen_y + $人物[@character.character_name][3]
  852.    end
  853.      
  854.    self.z = 1#@character.screen_z(@ch)
  855.    
  856.    # 设置不透明度、合成方式、茂密
  857.    self.opacity = @character.opacity
  858.    self.blend_type = @character.blend_type
  859.    self.bush_depth = @character.bush_depth
  860.    # 动画
  861.    if @character.animation_id != 0
  862.      animation = $data_animations[@character.animation_id]
  863.      animation(animation, true)
  864.      @character.animation_id = 0
  865.    end
  866. end
  867. end

  868. class Game_Character
  869. def c8
  870.    # 随机 0~5 的分支
  871.    case rand(10)
  872.    when 0..3  # 随机
  873.      move_random
  874.    when 4  # 前进一步
  875.      move_forward
  876.    when 5  # 暂时停止
  877.      @stop_count = 0
  878.    when 6..9  #另外4方向随机
  879.      c4
  880.    end
  881. end
  882. def c4
  883.    case rand(5)
  884.    when 0
  885.      move_upper_left
  886.      @direction = 7
  887.    when 1
  888.      move_upper_right
  889.      @direction = 9
  890.    when 2
  891.      move_lower_left
  892.      @direction = 1
  893.    when 3
  894.      move_lower_right
  895.      @direction = 3
  896.    when 4
  897.      @stop_count = 0
  898.    end
  899. end
  900. def z4
  901.    case rand(5)
  902.    when 0
  903.      move_left
  904.      @direction = 4
  905.    when 1
  906.      move_right
  907.      @direction = 6
  908.    when 2
  909.      move_up
  910.      @direction = 8
  911.    when 3
  912.      move_down
  913.      @direction = 2
  914.    when 4
  915.      @stop_count = 0
  916.    end
  917. end
  918.      
  919. def update
  920.    # 跳跃中、移动中、停止中的分支
  921.    if jumping?
  922.      update_jump
  923.    elsif moving?
  924.      update_move
  925.    else
  926.      update_stop
  927.    end
  928.    # 动画计数超过最大值的情况下
  929.    # ※最大值等于基本值减去移动速度 * 1 的值
  930.    if $人物[@character.character_name]
  931.      
  932.           if @anime_count > 16 * 4/$人物[@character.character_name][0] - @move_speed  * 2 #这是4真的素材,如果用8真的素材,要在  * 2 前加#
  933.      # 停止动画为 OFF 并且在停止中的情况下
  934.        if not @step_anime and @stop_count > 0
  935.        # 还原为原来的图形
  936.        @pattern = @original_pattern
  937.      # 停止动画为 ON 并且在移动中的情况下
  938.       else
  939.        # 更新图形
  940.        @pattern = (@pattern + 1) % $人物[@character.character_name][0]
  941.        end
  942.      # 清除动画计数
  943.      @anime_count = 0
  944.      end
  945.    else
  946.      
  947.    if @anime_count > 16 * 4/$c3_每一步的帧数 - @move_speed * 2 #这是4真的素材,如果用8真的素材,要在  * 2 前加#
  948.      # 停止动画为 OFF 并且在停止中的情况下
  949.      if not @step_anime and @stop_count > 0
  950.        # 还原为原来的图形
  951.        @pattern = @original_pattern
  952.      # 停止动画为 ON 并且在移动中的情况下
  953.      else
  954.        # 更新图形
  955.        @pattern = (@pattern + 1) % $c3_每一步的帧数
  956.      end
  957.      # 清除动画计数
  958.      @anime_count = 0
  959.    end
  960.    end
  961.    
  962.    
  963.    # 等待中的情况下
  964.    if @wait_count > 0
  965.      # 减少等待计数
  966.      @wait_count -= 1
  967.      return
  968.    end
  969.    # 强制移动路线的场合
  970.    if @move_route_forcing
  971.      # 自定义移动
  972.      move_type_custom
  973.      return
  974.    end
  975.    # 事件执行待机中并且为锁定状态的情况下
  976.    if @starting or lock?
  977.      # 不做规则移动
  978.      return
  979.    end
  980.    # 如果停止计数超过了一定的值(由移动频度算出)
  981.    if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  982.      # 移动类型分支
  983.      case @move_type
  984.      when 1  # 随机
  985.        move_type_random
  986.      when 2  # 接近
  987.        move_type_toward_player
  988.      when 3  # 自定义
  989.        move_type_custom
  990.      end
  991.    end
  992. end
  993. end

  994. class Game_Character
  995. #--------------------------------------------------------------------------
  996. # ● 面向主角的方向
  997. #--------------------------------------------------------------------------
  998. def turn_toward_player
  999.    # 求得与主角的坐标差
  1000.    sx = @x - $game_player.x
  1001.    sy = @y - $game_player.y
  1002.    # 坐标相等的场合下
  1003.    if sx == 0 and sy == 0
  1004.      return
  1005.    end
  1006.    # 横侧距离长的情况下
  1007.    if sx.abs > sy.abs
  1008.      # 将左右方向变更为朝向主角的方向
  1009.      sx > 0 ? turn_left : turn_right
  1010.    # 竖侧距离长的情况下
  1011.    else
  1012.      # 将上下方向变更为朝向主角的方向
  1013.      sy > 0 ? turn_up : turn_down
  1014.    end
  1015.    if sx == -1 and sy == -1
  1016.      unless @direction_fix
  1017.        @direction = 3
  1018.      end
  1019.      @stop_count = 0
  1020.    elsif sx == -1 and sy == 1
  1021.      unless @direction_fix
  1022.        @direction = 9
  1023.      end
  1024.      @stop_count = 0
  1025.    elsif sx == 1 and sy == -1
  1026.      unless @direction_fix
  1027.        @direction = 1
  1028.      end
  1029.      @stop_count = 0
  1030.    elsif sx == 1 and sy == 1
  1031.      unless @direction_fix
  1032.        @direction = 7
  1033.      end
  1034.      @stop_count = 0
  1035.    end
  1036. end
  1037. end
  1038. #==============================================================================
  1039. #==============================================================================
复制代码
dsdddsds
梦石
0
星屑
42345
在线时间
6022 小时
注册时间
2006-11-10
回帖
6975
发表于 2019-10-25 11:51:20 | 显示全部楼层
785到848行 , 这里把 when 后面的数字改成你的朝向就可以了, 数字代表的方向就是小键盘除了5以外8个数字按键对应的方向

点评

非常感谢,已经尝试修改好了。三段代码改了第一和第三段。  发表于 2019-10-25 22:09

评分

参与人数 2星屑 +50 赞 +2 收起 理由
RyanBern + 50 + 1 认可答案
thyzqwy + 1 认可答案

查看全部评分

回复 1 0

使用道具 举报

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

本版积分规则

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

在本版发帖返回顶部