幻想森林

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1329|回复: 0

[RMXP] 帮忙改下行走图脚本

[复制链接]

38

主题

129

帖子

1151

积分

⑥精研

无既空,空既色

积分
1151
发表于 2010-1-13 16:59:21 | 显示全部楼层 |阅读模式
这个是真八方向的行走图,不过是被人修改过的,那个原来的脚本没找到在别人的游戏里提的,他把改成斜四方向了我原来把
case linput.dir8 下面的改成8方向行走,可出来的只是伪八方向的只能显示主角上下左右的行走,斜方向的显示不出来,后来我发现这里只有上下左右的是不是要在这加上斜四方向就能显示出斜四方向的行走了!
# 角色向下移动、画面上的位置在中央下方的情况下
    if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
      # 画面向下卷动
      $game_map.scroll_down(@real_y - last_real_y)
    end
    # 角色向左移动、画面上的位置在中央左方的情况下
    if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
      # 画面向左卷动
      $game_map.scroll_left(last_real_x - @real_x)
    end
    # 角色向右移动、画面上的位置在中央右方的情况下
    if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
      # 画面向右卷动
      $game_map.scroll_right(@real_x - last_real_x)
    end
    # 角色向上移动、画面上的位置在中央上方的情况下
    if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
      # 画面向上卷动
      $game_map.scroll_up(last_real_y - @real_y)
    end




*******************************************************************************************************************************************
请注意发脚本的格式,谢谢
  1. class Game_Player < Game_Character
  2.   TIME_LIMIT = 20
  3.   def update
  4.     last_moving = moving?
  5.     unless moving? or $game_system.map_interpreter.running? or
  6.            @move_route_forcing or $game_temp.message_window_showing
  7.       # 用井号后面的东西替代前面的,就可以实现斜4方向走
  8.       case Input.dir8
  9.        when 2
  10.         if $game_switches[2]
  11.           move_down
  12.         else
  13.           move_lower_left
  14.         end            
  15.       when 4
  16.         if $game_switches[2]
  17.           move_left
  18.         else
  19.           move_upper_left
  20.         end
  21.       when 6
  22.         if $game_switches[2]
  23.           move_right
  24.         else
  25.           move_lower_right
  26.         end
  27.       when 8
  28.         if $game_switches[2]
  29.           move_up
  30.         else
  31.           move_upper_right        
  32.         end
  33.       end
  34.     end
  35.     # 本地变量记忆坐标
  36.     last_real_x = @real_x
  37.     last_real_y = @real_y
  38.     super
  39.     # 角色向下移动、画面上的位置在中央下方的情况下
  40.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  41.       # 画面向下卷动
  42.       $game_map.scroll_down(@real_y - last_real_y)
  43.     end
  44.     # 角色向左移动、画面上的位置在中央左方的情况下
  45.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  46.       # 画面向左卷动
  47.       $game_map.scroll_left(last_real_x - @real_x)
  48.     end
  49.     # 角色向右移动、画面上的位置在中央右方的情况下
  50.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  51.       # 画面向右卷动
  52.       $game_map.scroll_right(@real_x - last_real_x)
  53.     end
  54.     # 角色向上移动、画面上的位置在中央上方的情况下
  55.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  56.       # 画面向上卷动
  57.       $game_map.scroll_up(last_real_y - @real_y)
  58.     end
  59.     # 不在移动中的情况下
  60.     unless moving?
  61.       # 上次主角移动中的情况
  62.       if last_moving
  63.         # 与同位置的事件接触就判定为事件启动
  64.         result = check_event_trigger_here([1,2])
  65.         # 没有可以启动的事件的情况下
  66.         if result == false
  67.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  68.           unless $DEBUG and Input.press?(Input::CTRL)
  69.             # 遇敌计数下降
  70.             if @encounter_count > 0
  71.               @encounter_count -= 1
  72.             end
  73.           end
  74.         end
  75.       end
  76.       # 按下 C 键的情况下
  77.       if Input.trigger?(Input::C)
  78.         # 判定为同位置以及正面的事件启动
  79.         check_event_trigger_here([0])
  80.         check_event_trigger_there([0,1,2])
  81.       end
  82.     end
  83.   end
  84.   #--------------------------------------------------------------------------
  85.   # ● 正面事件的启动判定
  86.   #--------------------------------------------------------------------------
  87.   def check_event_trigger_there(triggers)
  88.     result = false
  89.     # 事件执行中的情况下
  90.     if $game_system.map_interpreter.running?
  91.       return result
  92.     end
  93.     # 计算正面坐标
  94.     new_x = @x
  95.     new_y = @y
  96.     case @direction
  97.     when 1
  98.       new_x -= 1
  99.       new_y += 1
  100.     when 2
  101.       new_y += 1
  102.     when 3
  103.       new_x += 1
  104.       new_y += 1
  105.     when 4
  106.       new_x -= 1
  107.     when 6
  108.       new_x += 1
  109.     when 7
  110.       new_x -= 1
  111.       new_y -= 1
  112.     when 8
  113.       new_y -= 1
  114.     when 9
  115.       new_x += 1
  116.       new_y -= 1
  117.     end
  118.     # 全部事件的循环
  119.     for event in $game_map.events.values
  120.       # 事件坐标与目标一致的情况下
  121.       if event.x == new_x and event.y == new_y and
  122.          triggers.include?(event.trigger)
  123.         # 跳跃中以外的情况下、启动判定是正面的事件
  124.         if not event.jumping? and not event.over_trigger?
  125.           event.start
  126.           result = true
  127.         end
  128.       end
  129.     end
  130.     # 找不到符合条件的事件的情况下
  131.     if result == false
  132.       # 正面的元件是计数器的情况下
  133.       if $game_map.counter?(new_x, new_y)
  134.         # 计算 1 元件里侧的坐标
  135.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  136.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  137.         # 全事件的循环
  138.         for event in $game_map.events.values
  139.           # 事件坐标与目标一致的情况下
  140.           if event.x == new_x and event.y == new_y and
  141.              triggers.include?(event.trigger)
  142.             # 跳跃中以外的情况下、启动判定是正面的事件
  143.             if not event.jumping? and not event.over_trigger?
  144.               event.start
  145.               result = true
  146.             end
  147.           end
  148.         end
  149.       end
  150.     end
  151.     return result
  152.   end
  153.   #--------------------------------------------------------------------------
  154.   # ● 向左下移动
  155.   #--------------------------------------------------------------------------
  156.   def move_lower_left
  157.     # 没有固定面向的场合
  158.     unless @direction_fix
  159.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  160.       @direction = 1#(@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  161.     end
  162.     # 下→左、左→下 的通道可以通行的情况下
  163.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  164.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  165.       # 更新坐标
  166.       @x -= 1
  167.       @y += 1
  168.       # 增加步数
  169.       increase_steps
  170.     else
  171.       check_event_trigger_touch(@x-1, @y+1)
  172.     end
  173.   end
  174.   #--------------------------------------------------------------------------
  175.   # ● 向右下移动
  176.   #--------------------------------------------------------------------------
  177.   def move_lower_right
  178.     # 没有固定面向的场合
  179.     unless @direction_fix
  180.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  181.       @direction = 3#(@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  182.     end
  183.     # 下→右、右→下 的通道可以通行的情况下
  184.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  185.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  186.       # 更新坐标
  187.       @x += 1
  188.       @y += 1
  189.       # 增加步数
  190.       increase_steps
  191.     else
  192.       check_event_trigger_touch(@x+1, @y+1)
  193.     end
  194.   end
  195.   #--------------------------------------------------------------------------
  196.   # ● 向左上移动
  197.   #--------------------------------------------------------------------------
  198.   def move_upper_left
  199.     # 没有固定面向的场合
  200.     unless @direction_fix
  201.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  202.       @direction = 7#(@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  203.     end
  204.     # 上→左、左→上 的通道可以通行的情况下
  205.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  206.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  207.       # 更新坐标
  208.       @x -= 1
  209.       @y -= 1
  210.       # 增加步数
  211.       increase_steps
  212.     else
  213.       check_event_trigger_touch(@x-1, @y-1)
  214.     end
  215.   end
  216.   #--------------------------------------------------------------------------
  217.   # ● 向右上移动
  218.   #--------------------------------------------------------------------------
  219.   def move_upper_right
  220.     # 没有固定面向的场合
  221.     unless @direction_fix
  222.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  223.       @direction = 9#(@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  224.     end
  225.     # 上→右、右→上 的通道可以通行的情况下
  226.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  227.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  228.       # 更新坐标
  229.       @x += 1
  230.       @y -= 1
  231.       # 增加步数
  232.       increase_steps
  233.     else
  234.       check_event_trigger_touch(@x+1, @y-1)
  235.     end
  236.   end
  237. end
  238. class Sprite_Character < RPG::Sprite
  239.   def update
  240.     super
  241.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  242.     if @tile_id != @character.tile_id or
  243.        @character_name != @character.character_name or
  244.        @character_hue != @character.character_hue
  245.       # 记忆元件 ID 与文件名、色相
  246.       @tile_id = @character.tile_id
  247.       @character_name = @character.character_name
  248.       @character_hue = @character.character_hue
  249.       # 元件 ID 为有效值的情况下
  250.       if @tile_id >= 384
  251.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  252.           @tile_id, @character.character_hue)
  253.         self.src_rect.set(0, 0, 32, 32)
  254.         self.ox = 16
  255.         self.oy = 32
  256.       # 元件 ID 为无效值的情况下
  257.       else
  258.         self.bitmap = RPG::Cache.character(@character.character_name,
  259.           @character.character_hue)
  260.         @cw = bitmap.width / $c3_每一步的帧数
  261.           @ch = bitmap.height / 4
  262.         self.ox = @cw / 2
  263.         self.oy = @ch
  264.       end
  265.     end
  266.     # 设置可视状态
  267.     self.visible = (not @character.transparent)
  268.     # 图形是角色的情况下
  269.     if @tile_id == 0
  270.       # 设置传送目标的矩形
  271.       sx = @character.pattern * @cw
  272.         case @character.direction
  273.         when 2
  274.           sy = 0 * @ch
  275.         when 4
  276.           sy = 1 * @ch
  277.         when 6
  278.           sy = 2 * @ch
  279.         when 8
  280.           sy = 3 * @ch
  281.         when 1
  282.           sy = 2 * @ch
  283.         when 3
  284.           sy = 1 * @ch
  285.         when 7
  286.           sy = 3 * @ch
  287.         when 9
  288.           sy = 0 * @ch
  289.         end
  290.       self.src_rect.set(sx, sy, @cw, @ch)
  291.     end
  292.     # 设置脚本的坐标
  293.     self.x = @character.screen_x
  294.     self.y = @character.screen_y
  295.     self.z = @character.screen_z(@ch)
  296.     # 设置不透明度、合成方式、茂密
  297.     self.opacity = @character.opacity
  298.     self.blend_type = @character.blend_type
  299.     self.bush_depth = @character.bush_depth
  300.     # 动画
  301.     if @character.animation_id != 0
  302.       animation = $data_animations[@character.animation_id]
  303.       animation(animation, true)
  304.       @character.animation_id = 0
  305.     end
  306.   end
  307. end
  308. class Game_Character
  309.   attr_accessor :time
  310.   #--------------------------------------------------------------------------
  311.   # ● 初始化对像
  312.   #--------------------------------------------------------------------------
  313.   alias old_ini initialize
  314.   def initialize
  315.     old_ini
  316.     @time = 0
  317.   end
  318.   def c8
  319.     # 随机 0~5 的分支
  320.     case rand(10)
  321.     when 0..3  # 随机
  322.       move_random
  323.     when 4  # 前进一步
  324.       move_forward
  325.     when 5  # 暂时停止
  326.       @stop_count = 0
  327.     when 6..9  #另外4方向随机
  328.       c4
  329.     end
  330.   end
  331.   def c4
  332.     case rand(5)
  333. when 0
  334.       move_upper_left
  335.     when 1
  336.       move_upper_right
  337.     when 2
  338.       move_lower_left
  339.     when 3
  340.       move_lower_right
  341.     when 4
  342.       @stop_count = 0
  343.     end
  344.   end
  345.       
  346.   def update
  347.     # 跳跃中、移动中、停止中的分支
  348.     if jumping?
  349.       update_jump
  350.     elsif moving?
  351.       update_move
  352.     else
  353.       update_stop
  354.     end
  355.     # 动画计数超过最大值的情况下
  356.     # ※最大值等于基本值减去移动速度 * 1 的值
  357.     if @anime_count > 16*4/$c3_每一步的帧数 - @move_speed * 2
  358.       # 停止动画为 OFF 并且在停止中的情况下
  359.       if not @step_anime and @stop_count > 0
  360.         # 还原为原来的图形
  361.         @pattern = @original_pattern
  362.       # 停止动画为 ON 并且在移动中的情况下
  363.       else
  364.         # 更新图形
  365.         @pattern = (@pattern + 1) % $c3_每一步的帧数
  366.       end
  367.       # 清除动画计数
  368.       @anime_count = 0
  369.     end
  370.     # 等待中的情况下
  371.     if @wait_count > 0
  372.       # 减少等待计数
  373.       @wait_count -= 1
  374.       return
  375.     end
  376.     # 强制移动路线的场合
  377.     if @move_route_forcing
  378.       # 自定义移动
  379.       move_type_custom
  380.       return
  381.     end
  382.     # 事件执行待机中并且为锁定状态的情况下
  383.     if @starting or lock?
  384.       # 不做规则移动
  385.       return
  386.     end
  387.     # 如果停止计数超过了一定的值(由移动频度算出)
  388.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  389.       # 移动类型分支
  390.       case @move_type
  391.       when 1  # 随机
  392.         move_type_random
  393.       when 2  # 接近
  394.         move_type_toward_player
  395.       when 3  # 自定义
  396.         move_type_custom
  397.       end
  398.     end
  399.   end
  400. end
  401. class Window_Base < Window
  402.   def draw_actor_graphic(actor, x, y)
  403.     bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
  404.     cw = bitmap.width / $c3_每一步的帧数
  405.     ch = bitmap.height / $c3_总共可用的方向数
  406.     src_rect = Rect.new(0, 0, cw, ch)
  407.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  408.   end
  409. end
  410. class Game_Character
  411.   #--------------------------------------------------------------------------
  412.   # ● 面向主角的方向
  413.   #--------------------------------------------------------------------------
  414.   def turn_toward_player
  415.     # 求得与主角的坐标差
  416.     sx = @x - $game_player.x
  417.     sy = @y - $game_player.y
  418.     # 坐标相等的场合下
  419.     if sx == 0 and sy == 0
  420.       return
  421.     end
  422.     # 横侧距离长的情况下
  423.     if sx.abs > sy.abs
  424.       # 将左右方向变更为朝向主角的方向
  425.       sx > 0 ? turn_left : turn_right
  426.     # 竖侧距离长的情况下
  427.     else
  428.       # 将上下方向变更为朝向主角的方向
  429.       sy > 0 ? turn_up : turn_down
  430.     end
  431.     if sx == -1 and sy == -1
  432.       @direction = 3
  433.       @stop_count = 0
  434.     elsif sx == -1 and sy == 1
  435.       @direction = 9
  436.       @stop_count = 0
  437.     elsif sx == 1 and sy == -1
  438.       @direction = 1
  439.       @stop_count = 0
  440.     elsif sx == 1 and sy == 1
  441.       @direction = 7
  442.       @stop_count = 0
  443.     end
  444.   end
  445. end
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|幻想森林

GMT+8, 2025-6-18 09:28 , Processed in 0.010396 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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