设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2234|回复: 2

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

[复制链接]

Lv3.寻梦者

梦石
0
星屑
4639
在线时间
735 小时
注册时间
2006-9-25
帖子
63
发表于 2019-10-25 09:33:36 | 显示全部楼层 |阅读模式

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

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

x
最近想把老游戏的行走图换成八方向的,找了个八方向的脚本,可是和我的图片方向顺序不一样,一个个改图片太麻烦了,想改下脚本可是找不到方法。。。。我图片是,下,左,右,上,左下,右下,左上,右上。这个脚本是左下,右下,左上,右上,下,左,上,右。应该怎么改?求教,谢谢。
RUBY 代码复制
  1. ###########################################################################################################################
  2. # 脚本功能:八方向走与多帧移动之图片修正 + 人物跟随。
  3.  
  4. # 附赠功能:
  5. #     可以让NPC角色随机8方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c8即可
  6. #     可以让NPC角色随机4斜角方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c4即可
  7. #     可以让NPC角色随机4方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入z4即可
  8. #     可以使用真·斜4方向行走,参考脚本53行开始
  9.  
  10. #改:个快快
  11. #修正内容:修正方向错位,改变站位,切换人物图片错乱
  12. #新增功能:可以让NPC任意规格 8X4 8X5 7X8 1X5都可以
  13.  
  14. #2 下 4左 6右 8 上 1左下 3右下 7左上 9右上
  15. #修正数据库:{列,行,X坐标,Y坐标}
  16. $人物 = {
  17.  
  18. "_本事和尚" => [7,4],
  19. }
  20.  
  21.  
  22. $c3_每一步的帧数 = 8
  23. $c3_总共可用的方向数 = 8
  24. class Game_Character
  25.   def event_is_in?(x, y)
  26.     for event in $game_map.events.values
  27.       # 事件坐标与目标一致的情况下
  28.       if event.x == x and event.y == y
  29.         # 跳跃中以外的情况下、启动判定是同位置的事件
  30.         return true
  31.       end
  32.     end
  33.     return false
  34.   end
  35.   def player_is_in?(x, y)
  36.     if $game_player.x == x and $game_player.y == y
  37.       return true
  38.     end
  39.     return false
  40.   end
  41.   def can_go?(x, y)
  42.     if player_is_in?(x, y) or event_is_in?(x, y)
  43.       return false
  44.     else
  45.       return true
  46.     end
  47.   end
  48.   #--------------------------------------------------------------------------
  49.   # ● 向下移动
  50.   #     turn_enabled : 本场地位置更改许可标志
  51.   #--------------------------------------------------------------------------
  52.   def move_down(turn_enabled = true)
  53.     # 面向下
  54.     if turn_enabled
  55.       turn_down
  56.     end
  57.     # 可以通行的场合
  58.     if passable?(@x, @y, 2)
  59.       # 面向下
  60.       turn_down
  61.       # 更新坐标
  62.       @y += 1
  63.       # 增加步数
  64.       increase_steps
  65.     #..........................................................................
  66.     elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::DOWN) and
  67.           can_go?(@x, @y + 1)
  68.       unless @direction_fix
  69.         @direction = 1
  70.       end
  71.       @x -= 1
  72.       @y += 1
  73.       increase_steps
  74.     elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::DOWN) and
  75.           can_go?(@x, @y + 1)
  76.       unless @direction_fix
  77.         @direction = 3
  78.       end
  79.       @x += 1
  80.       @y += 1
  81.       increase_steps
  82.     #..........................................................................
  83.     # 不能通行的情况下
  84.     else
  85.       # 接触事件的启动判定
  86.       check_event_trigger_touch(@x, @y+1)
  87.     end
  88.   end
  89.   #--------------------------------------------------------------------------
  90.   # ● 向左移动
  91.   #     turn_enabled : 本场地位置更改许可标志
  92.   #--------------------------------------------------------------------------
  93.   def move_left(turn_enabled = true)
  94.     # 面向左
  95.     if turn_enabled
  96.       turn_left
  97.     end
  98.     # 可以通行的情况下
  99.     if passable?(@x, @y, 4)
  100.       # 面向左
  101.       turn_left
  102.       # 更新坐标
  103.       @x -= 1
  104.       # 增加步数
  105.       increase_steps
  106.     #..........................................................................
  107.     elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::LEFT) and
  108.           can_go?(@x - 1, @y)
  109.       unless @direction_fix
  110.         @direction = 7
  111.       end
  112.       @x -= 1
  113.       @y -= 1
  114.       increase_steps
  115.     elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::LEFT) and
  116.           can_go?(@x - 1, @y)
  117.       unless @direction_fix
  118.         @direction = 1
  119.       end
  120.       @x -= 1
  121.       @y += 1
  122.       increase_steps
  123.     #..........................................................................
  124.     # 不能通行的情况下
  125.     else
  126.       # 接触事件的启动判定
  127.       check_event_trigger_touch(@x-1, @y)
  128.     end
  129.   end
  130.   #--------------------------------------------------------------------------
  131.   # ● 向右移动
  132.   #     turn_enabled : 本场地位置更改许可标志
  133.   #--------------------------------------------------------------------------
  134.   def move_right(turn_enabled = true)
  135.     # 面向右
  136.     if turn_enabled
  137.       turn_right
  138.     end
  139.     # 可以通行的场合
  140.     if passable?(@x, @y, 6)
  141.       # 面向右
  142.       turn_right
  143.       # 更新坐标
  144.       @x += 1
  145.       # 增加部数
  146.       increase_steps
  147.     #..........................................................................
  148.     elsif passable?(@x, @y, Input::UP) and passable?(@x, @y - 1, Input::RIGHT) and
  149.           can_go?(@x + 1, @y)
  150.       unless @direction_fix
  151.         @direction = 9
  152.       end
  153.       @x += 1
  154.       @y -= 1
  155.       increase_steps
  156.     elsif passable?(@x, @y, Input::DOWN) and passable?(@x, @y + 1, Input::RIGHT) and
  157.           can_go?(@x + 1, @y)
  158.       unless @direction_fix
  159.         @direction = 3
  160.       end
  161.       @x += 1
  162.       @y += 1
  163.       increase_steps
  164.     #..........................................................................
  165.     # 不能通行的情况下
  166.     else
  167.       # 接触事件的启动判定
  168.       check_event_trigger_touch(@x+1, @y)
  169.     end
  170.   end
  171.   #--------------------------------------------------------------------------
  172.   # ● 向上移动
  173.   #     turn_enabled : 本场地位置更改许可标志
  174.   #--------------------------------------------------------------------------
  175.   def move_up(turn_enabled = true)
  176.     # 面向上
  177.     if turn_enabled
  178.       turn_up
  179.     end
  180.     # 可以通行的情况下
  181.     if passable?(@x, @y, 8)
  182.       # 面向上
  183.       turn_up
  184.       # 更新坐标
  185.       @y -= 1
  186.       # 歩数増加
  187.       increase_steps
  188.     #..........................................................................
  189.     elsif passable?(@x, @y, Input::LEFT) and passable?(@x - 1, @y, Input::UP) and
  190.           can_go?(@x, @y - 1)
  191.       unless @direction_fix
  192.         @direction = 7
  193.       end
  194.       @x -= 1
  195.       @y -= 1
  196.       increase_steps
  197.     elsif passable?(@x, @y, Input::RIGHT) and passable?(@x + 1, @y, Input::UP) and
  198.           can_go?(@x, @y - 1)
  199.       unless @direction_fix
  200.         @direction = 9
  201.       end
  202.       @x += 1
  203.       @y -= 1
  204.       increase_steps
  205.     #..........................................................................
  206.     # 不能通行的情况下
  207.     else
  208.       # 接触事件的启动判定
  209.       check_event_trigger_touch(@x, @y-1)
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● 向左下移动
  214.   #--------------------------------------------------------------------------
  215.   def move_lower_left
  216.     # 没有固定面向的场合
  217.     unless @direction_fix
  218.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  219.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  220.     end
  221.     # 下→左、左→下 的通道可以通行的情况下
  222.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  223.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  224.       # 更新坐标
  225.       @x -= 1
  226.       @y += 1
  227.       # 增加步数
  228.       increase_steps
  229.     #..........................................................................
  230.     elsif passable?(@x, @y, Input::DOWN) and can_go?(@x - 1, @y + 1)
  231.       unless @direction_fix
  232.         @direction = 2
  233.       end
  234.       @y += 1
  235.       increase_steps
  236.     elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y + 1)
  237.       unless @direction_fix
  238.         @direction = 4
  239.       end
  240.       @x -= 1
  241.       increase_steps
  242.     #..........................................................................
  243.     end
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # ● 向右下移动
  247.   #--------------------------------------------------------------------------
  248.   def move_lower_right
  249.     # 没有固定面向的场合
  250.     unless @direction_fix
  251.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  252.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  253.     end
  254.     # 下→右、右→下 的通道可以通行的情况下
  255.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  256.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  257.       # 更新坐标
  258.       @x += 1
  259.       @y += 1
  260.       # 增加步数
  261.       increase_steps
  262.     elsif passable?(@x, @y, Input::DOWN) and can_go?(@x + 1, @y + 1)
  263.       unless @direction_fix
  264.         @direction = 2
  265.       end
  266.       @y += 1
  267.       increase_steps
  268.     elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y + 1)
  269.       unless @direction_fix
  270.         @direction = 6
  271.       end
  272.       @x += 1
  273.       increase_steps
  274.     end
  275.   end
  276.   #--------------------------------------------------------------------------
  277.   # ● 向左上移动
  278.   #--------------------------------------------------------------------------
  279.   def move_upper_left
  280.     # 没有固定面向的场合
  281.     unless @direction_fix
  282.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  283.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  284.     end
  285.     # 上→左、左→上 的通道可以通行的情况下
  286.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  287.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  288.       # 更新坐标
  289.       @x -= 1
  290.       @y -= 1
  291.       # 增加步数
  292.       increase_steps
  293.     #..........................................................................
  294.     elsif passable?(@x, @y, Input::UP) and can_go?(@x - 1, @y - 1)
  295.       unless @direction_fix
  296.         @direction = 8
  297.       end
  298.       @y -= 1
  299.       increase_steps
  300.     elsif passable?(@x, @y, Input::LEFT) and can_go?(@x - 1, @y - 1)
  301.       unless @direction_fix
  302.         @direction = 4
  303.       end
  304.       @x -= 1
  305.       increase_steps
  306.     #..........................................................................
  307.     end
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● 向右上移动
  311.   #--------------------------------------------------------------------------
  312.   def move_upper_right
  313.     # 没有固定面向的场合
  314.     unless @direction_fix
  315.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  316.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  317.     end
  318.     # 上→右、右→上 的通道可以通行的情况下
  319.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  320.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  321.       # 更新坐标
  322.       @x += 1
  323.       @y -= 1
  324.       # 增加步数
  325.       increase_steps
  326.     #..........................................................................
  327.     elsif passable?(@x, @y, Input::UP) and can_go?(@x + 1, @y - 1)
  328.       unless @direction_fix
  329.         @direction = 8
  330.       end
  331.       @y -= 1
  332.       increase_steps
  333.     elsif passable?(@x, @y, Input::RIGHT) and can_go?(@x + 1, @y - 1)
  334.       unless @direction_fix
  335.         @direction = 6
  336.       end
  337.       @x += 1
  338.       increase_steps
  339.     #..........................................................................
  340.     end
  341.   end
  342. end
  343. #-------------------------------------------------------------------------------
  344. class Game_Event < Game_Character
  345. def name
  346.   return @event.name
  347. end  
  348. def name=(newname)
  349.   @event.name = newname
  350. end
  351. end
  352. class Game_Player < Game_Character
  353. def name
  354.      return ""
  355. end
  356. end
  357.  
  358. class Sprite_Character < RPG::Sprite
  359. #--------------------------------------------------------------------------
  360. # ● 定义实例变量
  361. #--------------------------------------------------------------------------
  362. attr_accessor :character                # 角色
  363.   #--------------------------------------------------------------------------
  364. # ● 初始化对像
  365. #     viewport  : 查看端口
  366. #     character : 角色 (Game_Character)
  367. #--------------------------------------------------------------------------
  368. def initialize(viewport, character = nil)
  369.   name = character.name
  370.   super(viewport)
  371.   @character = character
  372.  
  373.   @namesprite = Sprite.new(viewport)
  374.       @namesprite.x = self.x - 50   
  375.  
  376.     if $人物[@character.character_name]  and  $人物[@character.character_name][3]      
  377.        @namesprite.y = self.y - $人物[@character.character_name][3]  
  378.     else
  379.         @namesprite.y = self.y        
  380.     end
  381.  
  382.  
  383.   #影子
  384.   @shadow = Sprite.new(viewport)
  385.  
  386.      @shadow.bitmap = RPG::Cache.character("shadow.png",1)
  387.  
  388.   @namesprite.bitmap = Bitmap.new(100, 32)
  389.   @namesprite.bitmap.font.name = "宋体"
  390.   @namesprite.bitmap.font.size = 16
  391.   @namesprite.bitmap.font.color.set(255, 255, 0)
  392.   @evname = name
  393.   @evname_split = name.split(/,/)[0]
  394.   if name[0, 2]=="EV"
  395.     @evname_split = ""
  396.   end
  397.   if name.split(/,/)[1] != nil
  398.     case name.split(/,/)[1]
  399.     when "0"
  400.       @namesprite.bitmap.font.color.set(255, 255, 255)
  401.     when "1"
  402.       @namesprite.bitmap.font.color.set(128, 128, 255)
  403.     when "2"
  404.       @namesprite.bitmap.font.color.set(255, 128, 128)
  405.     when "3"
  406.       @namesprite.bitmap.font.color.set(128, 255, 128)
  407.     when "4"
  408.       @namesprite.bitmap.font.color.set(128, 255, 255)
  409.     when "5"
  410.       @namesprite.bitmap.font.color.set(255, 128, 255)
  411.     when "6"
  412.       @namesprite.bitmap.font.color.set(255, 255, 128)
  413.     when "7"
  414.       @namesprite.bitmap.font.color.set(192, 192, 192)
  415.     else
  416.       @namesprite.bitmap.font.color.set(255, 255, 255)
  417.     end
  418.   end
  419.  
  420.   update
  421. end
  422. end
  423. #----------------------------------------------------------------------------
  424. class Game_Player < Game_Character
  425. if $c3_总共可用的方向数 == 8
  426.    def update
  427.      last_moving = moving?
  428.      unless moving? or $game_system.map_interpreter.running? or
  429.             @move_route_forcing or $game_temp.message_window_showing
  430.        # 用井号后面的东西替代前面的,就可以实现斜4方向走
  431.        case Input.dir8
  432.        when 2
  433.          move_down #move_lower_left
  434.  
  435.        when 4
  436.          move_left #move_upper_left
  437.  
  438.        when 6
  439.          move_right #move_lower_right
  440.  
  441.        when 8
  442.          move_up #move_upper_right
  443.  
  444.        when 1
  445.          move_lower_left
  446.  
  447.        when 3
  448.          move_lower_right
  449.  
  450.        when 7
  451.          move_upper_left
  452.  
  453.        when 9
  454.          move_upper_right
  455.  
  456.        else
  457.  
  458.        end
  459.      end
  460.      # 本地变量记忆坐标
  461.      last_real_x = @real_x
  462.      last_real_y = @real_y
  463.      super
  464.  
  465.  
  466.  
  467.      # 角色向下移动、画面上的位置在中央下方的情况下
  468.      if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  469.        # 画面向下卷动
  470.        $game_map.scroll_down(@real_y - last_real_y)
  471.      end
  472.      # 角色向左移动、画面上的位置在中央左方的情况下
  473.      if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  474.        # 画面向左卷动
  475.        $game_map.scroll_left(last_real_x - @real_x)
  476.      end
  477.      # 角色向右移动、画面上的位置在中央右方的情况下
  478.      if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  479.        # 画面向右卷动
  480.        $game_map.scroll_right(@real_x - last_real_x)
  481.      end
  482.      # 角色向上移动、画面上的位置在中央上方的情况下
  483.      if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  484.        # 画面向上卷动
  485.        $game_map.scroll_up(last_real_y - @real_y)
  486.      end
  487.  
  488.      # 不在移动中的情况下
  489.      unless moving?
  490.        # 上次主角移动中的情况
  491.        if last_moving
  492.          # 与同位置的事件接触就判定为事件启动
  493.          result = check_event_trigger_here([1,2])
  494.          # 没有可以启动的事件的情况下
  495.          if result == false
  496.            # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  497.            unless $DEBUG and Input.press?(Input::CTRL)
  498.              # 遇敌计数下降
  499.              if @encounter_count > 0
  500.                @encounter_count -= 1
  501.              end
  502.            end
  503.          end
  504.        end
  505.        # 按下 C 键的情况下
  506.        if Input.trigger?(Input::C)
  507.          # 判定为同位置以及正面的事件启动
  508.          check_event_trigger_here([0])
  509.          check_event_trigger_there([0,1,2])
  510.        end
  511.      else
  512.        if @move_route_forcing and  $game_map.encounter_list != []
  513.          if @encounter_count > 0
  514.            @encounter_count -= 1 if Graphics.frame_count % 20 == 0
  515.          #elsif $game_map.encounter_list != []
  516.          #  @encounter_coun = 0
  517.          #  @move_route_forcing = false
  518.          else
  519.            @encounter_coun = 0
  520.            @move_route_forcing = false
  521.          end
  522.          #耶..一样好不。。不信试试
  523.        end
  524.      end
  525.    end
  526.    #--------------------------------------------------------------------------
  527.    # ● 正面事件的启动判定
  528.    #--------------------------------------------------------------------------
  529.    def check_event_trigger_there(triggers)
  530.      result = false
  531.      # 事件执行中的情况下
  532.      if $game_system.map_interpreter.running?
  533.        return result
  534.      end
  535.      # 计算正面坐标
  536.      new_x = @x
  537.      new_y = @y
  538.      case @direction
  539.      when 1
  540.        new_x -= 1
  541.        new_y += 1
  542.      when 2
  543.        new_y += 1
  544.      when 3
  545.        new_x += 1
  546.        new_y += 1
  547.      when 4
  548.        new_x -= 1
  549.      when 6
  550.        new_x += 1
  551.      when 7
  552.        new_x -= 1
  553.        new_y -= 1
  554.      when 8
  555.        new_y -= 1
  556.      when 9
  557.        new_x += 1
  558.        new_y -= 1
  559.      end
  560.      # 全部事件的循环
  561.      for event in $game_map.events.values
  562.        # 事件坐标与目标一致的情况下
  563.        if event.x == new_x and event.y == new_y and
  564.           triggers.include?(event.trigger)
  565.          # 跳跃中以外的情况下、启动判定是正面的事件
  566.          if not event.jumping? and not event.over_trigger? and $scene == nil
  567.            event.start
  568.            result = true
  569.          end
  570.        end
  571.      end
  572.      # 找不到符合条件的事件的情况下
  573.      if result == false
  574.        # 正面的元件是计数器的情况下
  575.        if $game_map.counter?(new_x, new_y)
  576.          # 计算 1 元件里侧的坐标
  577.          new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  578.          new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  579.          # 全事件的循环
  580.          for event in $game_map.events.values
  581.            # 事件坐标与目标一致的情况下
  582.            if event.x == new_x and event.y == new_y
  583.               triggers.include?(event.trigger)
  584.              # 跳跃中以外的情况下、启动判定是正面的事件
  585.              if not event.jumping? and not event.over_trigger? and $scene == nil
  586.                event.start
  587.                result = true
  588.              end
  589.            end
  590.          end
  591.        end
  592.      end
  593.      return result
  594.    end
  595. end
  596. end
  597.  
  598.  
  599. class Sprite_Character < RPG::Sprite
  600.   def dispose
  601.     super
  602.     if @namesprite.bitmap != nil
  603.       @namesprite.bitmap.dispose
  604.     end
  605.     @namesprite.dispose
  606.     if @shadow.bitmap != nil
  607.       @shadow.bitmap.dispose
  608.     end
  609.     @shadow.dispose
  610.   end
  611.   #----------------------------------------------------------------------------
  612.   # 更新
  613.   #----------------------------------------------------------------------------
  614.   def update
  615.     if @character.x < $game_player.x - 20 or @character.x > $game_player.x + 20 or
  616.      @character.y < $game_player.y - 15 or @character.y > $game_player.y + 15
  617.         return
  618.       end
  619.     super
  620.     #判断影子有无
  621.     if @character_name == nil or @character.character_name == "_W1" or @character_name =="传送" or @character_name == ""
  622.       unless @shadow.bitmap.disposed?
  623.         @shadow.bitmap.dispose
  624.       end
  625.     else
  626.       if @shadow.bitmap.disposed?
  627.         @shadow.bitmap = RPG::Cache.character("shadow", 1)
  628.       end
  629.     end
  630.     if @evname != @character.name
  631.       @namesprite.bitmap.clear
  632.       @evname = @character.name
  633.       @evname_split = @character.name.split(/,/)[0]
  634.       if @evname[0, 2]=="EV"
  635.         @evname_split = ""
  636.       end
  637.       if @character.name.split(/,/)[1] != nil
  638.         case @character.name.split(/,/)[1]
  639.         when "0"
  640.           @namesprite.bitmap.font.color.set(255, 255, 255)
  641.         when "1"
  642.           @namesprite.bitmap.font.color.set(128, 128, 255)
  643.         when "2"
  644.           @namesprite.bitmap.font.color.set(255, 128, 128)
  645.         when "3"
  646.           @namesprite.bitmap.font.color.set(128, 255, 128)
  647.         when "4"
  648.           @namesprite.bitmap.font.color.set(128, 255, 255)
  649.         when "5"
  650.           @namesprite.bitmap.font.color.set(255, 128, 255)
  651.         when "6"
  652.           @namesprite.bitmap.font.color.set(255, 255, 128)
  653.         when "7"
  654.           @namesprite.bitmap.font.color.set(192, 192, 192)
  655.         else
  656.           @namesprite.bitmap.font.color.set(255, 255, 255)
  657.         end
  658.       end
  659.  
  660.  
  661.      @namesprite.x = self.x - 50   
  662.  
  663.  
  664.      if $人物[@character.character_name]  and  $人物[@character.character_name][3]      
  665.         @namesprite.y = self.y - $人物[@character.character_name][3]  
  666.      else
  667.          @namesprite.y = self.y        
  668.      end
  669.  
  670.  
  671.  
  672.     end
  673.  
  674. #------------------------------------------------------------------------------
  675.    # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  676.    if @tile_id != @character.tile_id or
  677.       @character_name != @character.character_name or
  678.       @character_hue != @character.character_hue
  679.      # 记忆元件 ID 与文件名、色相
  680.      @tile_id = @character.tile_id
  681.      @character_name = @character.character_name
  682.      if @character_name != nil and @character_name != ""
  683.        @namesprite.bitmap.clear
  684.       @evname = @character.name
  685.       @evname_split = @character.name.split(/,/)[0]
  686.       if @evname[0, 2]=="EV"
  687.         @evname_split = ""
  688.       end
  689.       if @character.name.split(/,/)[1] != nil
  690.         case @character.name.split(/,/)[1]
  691.         when "0"
  692.           @namesprite.bitmap.font.color.set(255, 255, 255)
  693.         when "1"
  694.           @namesprite.bitmap.font.color.set(128, 128, 255)
  695.         when "2"
  696.           @namesprite.bitmap.font.color.set(255, 128, 128)
  697.         when "3"
  698.           @namesprite.bitmap.font.color.set(128, 255, 128)
  699.         when "4"
  700.           @namesprite.bitmap.font.color.set(128, 255, 255)
  701.         when "5"
  702.           @namesprite.bitmap.font.color.set(255, 128, 255)
  703.         when "6"
  704.           @namesprite.bitmap.font.color.set(255, 255, 128)
  705.         when "7"
  706.           @namesprite.bitmap.font.color.set(192, 192, 192)
  707.         else
  708.           @namesprite.bitmap.font.color.set(255, 255, 255)
  709.         end
  710.       end
  711.  
  712.      elsif @character_name != nil and @character_name == ""
  713.       @namesprite.bitmap.clear
  714.      end
  715.      @character_hue = @character.character_hue
  716.      # 元件 ID 为有效值的情况下
  717.      if @tile_id >= 384
  718.        self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  719.          @tile_id, @character.character_hue)
  720.  
  721.  
  722.  
  723.        self.src_rect.set(0, 0, 32, 32)
  724.        self.ox = 16
  725.        self.oy = 32
  726.      # 元件 ID 为无效值的情况下
  727.      else
  728.       self.bitmap = RPG::Cache.character(@character.character_name,
  729.          @character.character_hue)
  730.  
  731.  
  732.          if $人物[@character.character_name]
  733.             @cw = bitmap.width / $人物[@character.character_name][0]
  734.  
  735.             else
  736.  
  737.               @cw = bitmap.width / $c3_每一步的帧数
  738.  
  739.             end
  740.  
  741.        if $c3_总共可用的方向数==4
  742.          @ch = bitmap.height / 4
  743.        else
  744.          if $人物[@character.character_name]
  745.             @ch = bitmap.height / $人物[@character.character_name][1]
  746.  
  747.             else
  748.          @ch = bitmap.height / 8
  749.          end
  750.        end
  751.       #判断文件名中附加oy
  752.       name = "Graphics/Characters/"+@character.character_name+".txt"
  753.       default_name = "Graphics/Characters/default.txt"
  754.       @ox_move = 0
  755.       @oy_move = 0
  756.       if @character.character_name != ""
  757.         body = File.open(name,"r") rescue body = File.open(default_name,"r")
  758.         line=body.readlines
  759.         if line[0].split("\n")[0].to_i != 0
  760.           @ox_move = line[0].split("\n")[0].to_i
  761.           @oy_move = line[1].split("\n")[0].to_i
  762.         end
  763.         body.close
  764.       end
  765.       if @oy_move != 0 or @ox_move != 0
  766.         self.ox = @ox_move
  767.         self.oy = @oy_move + 10
  768.       else
  769.         self.ox = @cw / 2
  770.         self.oy = @ch
  771.       end
  772.      end
  773.    end
  774.    # 设置可视状态
  775.    self.visible = (not @character.transparent)
  776.    # 图形是角色的情况下
  777.    if @tile_id == 0
  778.      # 设置传送目标的矩形
  779.      sx = @character.pattern * @cw
  780.       #2 下 4左 6右 8 上 1左下 3右下 7左上 9右上
  781.      if $c3_总共可用的方向数==8
  782.          if $人物[@character.character_name] and $人物[@character.character_name][1]==4
  783.        if  @character == $game_player
  784.        case @character.direction
  785.         when 2
  786.          sy = 0 * @ch
  787.        when 4
  788.          sy = 1 * @ch
  789.        when 6
  790.          sy = 3 * @ch
  791.        when 8
  792.          sy = 2 * @ch
  793.        when 1
  794.          sy = 1 * @ch
  795.        when 3
  796.          sy = 0 * @ch
  797.        when 7
  798.          sy = 2 * @ch
  799.        when 9
  800.          sy = 3 * @ch
  801.        end
  802.      else
  803.            case @character.direction
  804.           when 2
  805.          sy = 0 * @ch
  806.        when 4
  807.          sy = 1 * @ch
  808.        when 6
  809.          sy = 2 * @ch
  810.        when 8
  811.          sy = 3 * @ch
  812.        when 1
  813.          sy = 4 * @ch
  814.        when 3
  815.          sy = 5 * @ch
  816.        when 7
  817.          sy = 6 * @ch
  818.        when 9
  819.          sy = 7 * @ch
  820.          end
  821.  
  822.      end
  823.  
  824.        else
  825.        case @character.direction
  826.          when 2
  827.          sy = 4 * @ch
  828.  
  829.        when 4
  830.          sy = 5 * @ch
  831.  
  832.        when 6
  833.          sy = 7 * @ch
  834.  
  835.        when 8
  836.          sy = 6 * @ch
  837.  
  838.        when 1
  839.          sy = 1 * @ch
  840.  
  841.        when 3
  842.          sy = 0 * @ch
  843.  
  844.        when 7
  845.          sy = 2 * @ch
  846.  
  847.        when 9
  848.          sy = 3 * @ch
  849.  
  850.        end
  851.        end
  852.      else
  853.        sy = (@character.direction - 2) / 2 * @ch
  854.      end
  855.      unless sy
  856.        sy = 0
  857.      end
  858.  
  859.  
  860.      self.src_rect.set(sx, sy, @cw, @ch)
  861.  
  862.    end
  863.  
  864.  
  865.    self.x = @character.screen_x
  866.    self.y = @character.screen_y
  867.  
  868.       #刷新影子位置
  869.    unless @shadow.bitmap.disposed?
  870.      if @oy_move != nil or @ox_move != nil
  871.        @shadow.x = self.x - @shadow.bitmap.width / 2
  872.        @shadow.y = self.y - @shadow.bitmap.height / 2 - 10
  873.      else
  874.        @shadow.x = self.x - @shadow.bitmap.width / 2
  875.        @shadow.y = self.y - @shadow.bitmap.height / 2 - 10
  876.      end
  877.    end
  878.    # 设置脚本的坐标
  879.    if $人物[@character.character_name] and $人物[@character.character_name][2]
  880.        self.x = @character.screen_x + $人物[@character.character_name][2]
  881.        self.y = @character.screen_y + $人物[@character.character_name][3]
  882.    end
  883.  
  884.    self.z = 1#@character.screen_z(@ch)
  885.  
  886.    # 设置不透明度、合成方式、茂密
  887.    self.opacity = @character.opacity
  888.    self.blend_type = @character.blend_type
  889.    self.bush_depth = @character.bush_depth
  890.    # 动画
  891.    if @character.animation_id != 0
  892.      animation = $data_animations[@character.animation_id]
  893.      animation(animation, true)
  894.      @character.animation_id = 0
  895.    end
  896. end
  897. end
  898.  
  899. class Game_Character
  900. def c8
  901.    # 随机 0~5 的分支
  902.    case rand(10)
  903.    when 0..3  # 随机
  904.      move_random
  905.    when 4  # 前进一步
  906.      move_forward
  907.    when 5  # 暂时停止
  908.      @stop_count = 0
  909.    when 6..9  #另外4方向随机
  910.      c4
  911.    end
  912. end
  913. def c4
  914.    case rand(5)
  915.    when 0
  916.      move_upper_left
  917.      @direction = 7
  918.    when 1
  919.      move_upper_right
  920.      @direction = 9
  921.    when 2
  922.      move_lower_left
  923.      @direction = 1
  924.    when 3
  925.      move_lower_right
  926.      @direction = 3
  927.    when 4
  928.      @stop_count = 0
  929.    end
  930. end
  931. def z4
  932.    case rand(5)
  933.    when 0
  934.      move_left
  935.      @direction = 4
  936.    when 1
  937.      move_right
  938.      @direction = 6
  939.    when 2
  940.      move_up
  941.      @direction = 8
  942.    when 3
  943.      move_down
  944.      @direction = 2
  945.    when 4
  946.      @stop_count = 0
  947.    end
  948. end
  949.  
  950. def update
  951.    # 跳跃中、移动中、停止中的分支
  952.    if jumping?
  953.      update_jump
  954.    elsif moving?
  955.      update_move
  956.    else
  957.      update_stop
  958.    end
  959.    # 动画计数超过最大值的情况下
  960.    # ※最大值等于基本值减去移动速度 * 1 的值
  961.    if $人物[@character.character_name]
  962.  
  963.           if @anime_count > 16 * 4/$人物[@character.character_name][0] - @move_speed  * 2 #这是4真的素材,如果用8真的素材,要在  * 2 前加#
  964.      # 停止动画为 OFF 并且在停止中的情况下
  965.        if not @step_anime and @stop_count > 0
  966.        # 还原为原来的图形
  967.        @pattern = @original_pattern
  968.      # 停止动画为 ON 并且在移动中的情况下
  969.       else
  970.        # 更新图形
  971.        @pattern = (@pattern + 1) % $人物[@character.character_name][0]
  972.        end
  973.      # 清除动画计数
  974.      @anime_count = 0
  975.      end
  976.    else
  977.  
  978.    if @anime_count > 16 * 4/$c3_每一步的帧数 - @move_speed * 2 #这是4真的素材,如果用8真的素材,要在  * 2 前加#
  979.      # 停止动画为 OFF 并且在停止中的情况下
  980.      if not @step_anime and @stop_count > 0
  981.        # 还原为原来的图形
  982.        @pattern = @original_pattern
  983.      # 停止动画为 ON 并且在移动中的情况下
  984.      else
  985.        # 更新图形
  986.        @pattern = (@pattern + 1) % $c3_每一步的帧数
  987.      end
  988.      # 清除动画计数
  989.      @anime_count = 0
  990.    end
  991.    end
  992.  
  993.  
  994.    # 等待中的情况下
  995.    if @wait_count > 0
  996.      # 减少等待计数
  997.      @wait_count -= 1
  998.      return
  999.    end
  1000.    # 强制移动路线的场合
  1001.    if @move_route_forcing
  1002.      # 自定义移动
  1003.      move_type_custom
  1004.      return
  1005.    end
  1006.    # 事件执行待机中并且为锁定状态的情况下
  1007.    if @starting or lock?
  1008.      # 不做规则移动
  1009.      return
  1010.    end
  1011.    # 如果停止计数超过了一定的值(由移动频度算出)
  1012.    if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  1013.      # 移动类型分支
  1014.      case @move_type
  1015.      when 1  # 随机
  1016.        move_type_random
  1017.      when 2  # 接近
  1018.        move_type_toward_player
  1019.      when 3  # 自定义
  1020.        move_type_custom
  1021.      end
  1022.    end
  1023. end
  1024. end
  1025.  
  1026. class Game_Character
  1027. #--------------------------------------------------------------------------
  1028. # ● 面向主角的方向
  1029. #--------------------------------------------------------------------------
  1030. def turn_toward_player
  1031.    # 求得与主角的坐标差
  1032.    sx = @x - $game_player.x
  1033.    sy = @y - $game_player.y
  1034.    # 坐标相等的场合下
  1035.    if sx == 0 and sy == 0
  1036.      return
  1037.    end
  1038.    # 横侧距离长的情况下
  1039.    if sx.abs > sy.abs
  1040.      # 将左右方向变更为朝向主角的方向
  1041.      sx > 0 ? turn_left : turn_right
  1042.    # 竖侧距离长的情况下
  1043.    else
  1044.      # 将上下方向变更为朝向主角的方向
  1045.      sy > 0 ? turn_up : turn_down
  1046.    end
  1047.    if sx == -1 and sy == -1
  1048.      unless @direction_fix
  1049.        @direction = 3
  1050.      end
  1051.      @stop_count = 0
  1052.    elsif sx == -1 and sy == 1
  1053.      unless @direction_fix
  1054.        @direction = 9
  1055.      end
  1056.      @stop_count = 0
  1057.    elsif sx == 1 and sy == -1
  1058.      unless @direction_fix
  1059.        @direction = 1
  1060.      end
  1061.      @stop_count = 0
  1062.    elsif sx == 1 and sy == 1
  1063.      unless @direction_fix
  1064.        @direction = 7
  1065.      end
  1066.      @stop_count = 0
  1067.    end
  1068. end
  1069. end
  1070. #==============================================================================
  1071. #==============================================================================
dsdddsds

Lv5.捕梦者

梦石
0
星屑
37789
在线时间
5399 小时
注册时间
2006-11-10
帖子
6546
发表于 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

使用道具 举报

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

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 13:37

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表