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

Project1

 找回密码
 注册会员
搜索
查看: 3026|回复: 1
打印 上一主题 下一主题

[原创发布] 八方向行走图(不影响4方)

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
157 小时
注册时间
2011-7-17
帖子
128
跳转到指定楼层
1
发表于 2011-12-5 19:54:16 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
其实不是什么特别好的东西,只是见到RM大师天干宝典中的八方行走图,连4方行走图都要拉长,很不方便,于是......
素材在XAS里弄得,找不到XAS的八方脚本,只好自己改......

脚本■ Game_Character3
  1. #==============================================================================
  2. # ■ Game_Character (分割定义 3)
  3. #------------------------------------------------------------------------------
  4. #  处理角色的类。本类作为 Game_Player 类与 Game_Event
  5. # 类的超级类使用。
  6. #==============================================================================

  7. class Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 向下移动
  10.   #     turn_enabled : 本场地位置更改许可标志
  11.   #--------------------------------------------------------------------------
  12.   def move_down(turn_enabled = true)
  13.     # 面向下
  14.     if turn_enabled
  15.       turn_down
  16.     end
  17.     unless @direction_fix
  18.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  19.   ###########################################################################
  20.       @direction = 2
  21.   ###########################################################################
  22.     end
  23.     # 可以通行的场合
  24.     if passable?(@x, @y, 2)
  25.       # 面向下
  26.       turn_down
  27.       # 更新坐标
  28.       @y += 1
  29.       # 增加步数
  30.       increase_steps
  31.     # 不能通行的情况下
  32.     else
  33.       # 接触事件的启动判定
  34.       check_event_trigger_touch(@x, @y+1)
  35.     end
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # ● 向左移动
  39.   #     turn_enabled : 本场地位置更改许可标志
  40.   #--------------------------------------------------------------------------
  41.   def move_left(turn_enabled = true)
  42.     # 面向左
  43.     if turn_enabled
  44.       turn_left
  45.     end
  46.     unless @direction_fix
  47.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  48.   ###########################################################################
  49.       @direction = 4
  50.   ###########################################################################
  51.     end
  52.     # 可以通行的情况下
  53.     if passable?(@x, @y, 4)
  54.       # 面向左
  55.       turn_left
  56.       # 更新坐标
  57.       @x -= 1
  58.       # 增加步数
  59.       increase_steps
  60.     # 不能通行的情况下
  61.     else
  62.       # 接触事件的启动判定
  63.       check_event_trigger_touch(@x-1, @y)
  64.     end
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● 向右移动
  68.   #     turn_enabled : 本场地位置更改许可标志
  69.   #--------------------------------------------------------------------------
  70.   def move_right(turn_enabled = true)
  71.     # 面向右
  72.     if turn_enabled
  73.       turn_right
  74.     end
  75.     unless @direction_fix
  76.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  77.   ###########################################################################
  78.       @direction = 6
  79.   ###########################################################################
  80.     end
  81.     # 可以通行的场合
  82.     if passable?(@x, @y, 6)
  83.       # 面向右
  84.       turn_right
  85.       # 更新坐标
  86.       @x += 1
  87.       # 增加部数
  88.       increase_steps
  89.     # 不能通行的情况下
  90.     else
  91.       # 接触事件的启动判定
  92.       check_event_trigger_touch(@x+1, @y)
  93.     end
  94.   end
  95.   #--------------------------------------------------------------------------
  96.   # ● 向上移动
  97.   #     turn_enabled : 本场地位置更改许可标志
  98.   #--------------------------------------------------------------------------
  99.   def move_up(turn_enabled = true)
  100.     # 面向上
  101.     if turn_enabled
  102.       turn_up
  103.     end
  104.     unless @direction_fix
  105.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  106.   ###########################################################################
  107.       @direction = 8
  108.   ###########################################################################
  109.     end
  110.     # 可以通行的情况下
  111.     if passable?(@x, @y, 8)
  112.       # 面向上
  113.       turn_up
  114.       # 更新坐标
  115.       @y -= 1
  116.       # 歩数増加
  117.       increase_steps
  118.     # 不能通行的情况下
  119.     else
  120.       # 接触事件的启动判定
  121.       check_event_trigger_touch(@x, @y-1)
  122.     end
  123.   end
  124.   #--------------------------------------------------------------------------
  125.   # ● 向左下移动
  126.   #--------------------------------------------------------------------------
  127.   def move_lower_left
  128.     # 没有固定面向的场合
  129.     unless @direction_fix
  130.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  131.   ###########################################################################
  132.       @direction = 1
  133.   ###########################################################################
  134.     end
  135.     # 下→左、左→下 的通道可以通行的情况下
  136.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  137.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  138.       # 更新坐标
  139.       @x -= 1
  140.       @y += 1
  141.       # 增加步数
  142.       increase_steps
  143.     end
  144.   end
  145.   #--------------------------------------------------------------------------
  146.   # ● 向右下移动
  147.   #--------------------------------------------------------------------------
  148.   def move_lower_right
  149.     # 没有固定面向的场合
  150.     unless @direction_fix
  151.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  152.   ###########################################################################
  153.       @direction = 3
  154.   ###########################################################################
  155.     end
  156.     # 下→右、右→下 的通道可以通行的情况下
  157.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  158.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  159.       # 更新坐标
  160.       @x += 1
  161.       @y += 1
  162.       # 增加步数
  163.       increase_steps
  164.     end
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # ● 向左上移动
  168.   #--------------------------------------------------------------------------
  169.   def move_upper_left
  170.     # 没有固定面向的场合
  171.     unless @direction_fix
  172.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  173.   ###########################################################################
  174.       @direction = 7
  175.   ###########################################################################
  176.     end
  177.     # 上→左、左→上 的通道可以通行的情况下
  178.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  179.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  180.       # 更新坐标
  181.       @x -= 1
  182.       @y -= 1
  183.       # 增加步数
  184.       increase_steps
  185.     end
  186.   end
  187.   #--------------------------------------------------------------------------
  188.   # ● 向右上移动
  189.   #--------------------------------------------------------------------------
  190.   def move_upper_right
  191.     # 没有固定面向的场合
  192.     unless @direction_fix
  193.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  194.   ###########################################################################
  195.       @direction = 9
  196.   ###########################################################################
  197.     end
  198.     # 上→右、右→上 的通道可以通行的情况下
  199.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  200.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  201.       # 更新坐标
  202.       @x += 1
  203.       @y -= 1
  204.       # 增加步数
  205.       increase_steps
  206.     end
  207.   end
  208.   #--------------------------------------------------------------------------
  209.   # ● 随机移动
  210.   #--------------------------------------------------------------------------
  211.   def move_random
  212.     case rand(4)
  213.     when 0  # 向下移动
  214.       move_down(false)
  215.     when 1  # 向左移动
  216.       move_left(false)
  217.     when 2  # 向右移动
  218.       move_right(false)
  219.     when 3  # 向上移动
  220.       move_up(false)
  221.     end
  222.   end
  223.   #--------------------------------------------------------------------------
  224.   # ● 接近主角
  225.   #--------------------------------------------------------------------------
  226.   def move_toward_player
  227.     # 求得与主角的坐标差
  228.     sx = @x - $game_player.x
  229.     sy = @y - $game_player.y
  230.     # 坐标相等情况下
  231.     if sx == 0 and sy == 0
  232.       return
  233.     end
  234.     # 求得差的绝对值
  235.     abs_sx = sx.abs
  236.     abs_sy = sy.abs
  237.     # 横距离与纵距离相等的情况下
  238.     if abs_sx == abs_sy
  239.       # 随机将边数增加 1
  240.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  241.     end
  242.     # 横侧距离长的情况下
  243.     if abs_sx > abs_sy
  244.       # 左右方向优先。向主角移动
  245.       sx > 0 ? move_left : move_right
  246.       if not moving? and sy != 0
  247.         sy > 0 ? move_up : move_down
  248.       end
  249.     # 竖侧距离长的情况下
  250.     else
  251.       # 上下方向优先。向主角移动
  252.       sy > 0 ? move_up : move_down
  253.       if not moving? and sx != 0
  254.         sx > 0 ? move_left : move_right
  255.       end
  256.     end
  257.   end
  258.   #--------------------------------------------------------------------------
  259.   # ● 远离主角
  260.   #--------------------------------------------------------------------------
  261.   def move_away_from_player
  262.     # 求得与主角的坐标差
  263.     sx = @x - $game_player.x
  264.     sy = @y - $game_player.y
  265.     # 坐标相等情况下
  266.     if sx == 0 and sy == 0
  267.       return
  268.     end
  269.     # 求得差的绝对值
  270.     abs_sx = sx.abs
  271.     abs_sy = sy.abs
  272.     # 横距离与纵距离相等的情况下
  273.     if abs_sx == abs_sy
  274.       # 随机将边数增加 1
  275.       rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
  276.     end
  277.     # 横侧距离长的情况下
  278.     if abs_sx > abs_sy
  279.       # 左右方向优先。远离主角移动
  280.       sx > 0 ? move_right : move_left
  281.       if not moving? and sy != 0
  282.         sy > 0 ? move_down : move_up
  283.       end
  284.     # 竖侧距离长的情况下
  285.     else
  286.       # 上下方向优先。远离主角移动
  287.       sy > 0 ? move_down : move_up
  288.       if not moving? and sx != 0
  289.         sx > 0 ? move_right : move_left
  290.       end
  291.     end
  292.   end
  293.   #--------------------------------------------------------------------------
  294.   # ● 前进一步
  295.   #--------------------------------------------------------------------------
  296.   def move_forward
  297.     case @direction
  298.     when 2
  299.       move_down(false)
  300.     when 4
  301.       move_left(false)
  302.     when 6
  303.       move_right(false)
  304.     when 8
  305.       move_up(false)
  306.     end
  307.   end
  308.   #--------------------------------------------------------------------------
  309.   # ● 后退一步
  310.   #--------------------------------------------------------------------------
  311.   def move_backward
  312.     # 记忆朝向固定信息
  313.     last_direction_fix = @direction_fix
  314.     # 强制固定朝向
  315.     @direction_fix = true
  316.     # 朝向分支
  317.     case @direction
  318.     when 2  # 下
  319.       move_up(false)
  320.     when 4  # 左
  321.       move_right(false)
  322.     when 6  # 右
  323.       move_left(false)
  324.     when 8  # 上
  325.       move_down(false)
  326.     end
  327.     # 还原朝向固定信息
  328.     @direction_fix = last_direction_fix
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # ● 跳跃
  332.   #     x_plus : X 坐标增加值
  333.   #     y_plus : Y 坐标增加值
  334.   #--------------------------------------------------------------------------
  335.   def jump(x_plus, y_plus)
  336.     # 增加值不是 (0,0) 的情况下
  337.     if x_plus != 0 or y_plus != 0
  338.       # 横侧距离长的情况下
  339.       if x_plus.abs > y_plus.abs
  340.         # 变更左右方向
  341.         x_plus < 0 ? turn_left : turn_right
  342.       # 竖侧距离长的情况下
  343.       else
  344.         # 变更上下方向
  345.         y_plus < 0 ? turn_up : turn_down
  346.       end
  347.     end
  348.     # 计算新的坐标
  349.     new_x = @x + x_plus
  350.     new_y = @y + y_plus
  351.     # 增加值为 (0,0) 的情况下、跳跃目标可以通行的场合
  352.     if (x_plus == 0 and y_plus == 0) or passable?(new_x, new_y, 0)
  353.       # 矫正姿势
  354.       straighten
  355.       # 更新坐标
  356.       @x = new_x
  357.       @y = new_y
  358.       # 距计算距离
  359.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  360.       # 设置跳跃记数
  361.       @jump_peak = 10 + distance - @move_speed
  362.       @jump_count = @jump_peak * 2
  363.       # 清除停止记数信息
  364.       @stop_count = 0
  365.     end
  366.   end
  367.   #--------------------------------------------------------------------------
  368.   # ● 面向向下
  369.   #--------------------------------------------------------------------------
  370.   def turn_down
  371.     unless @direction_fix
  372.       @direction = 2
  373.       @stop_count = 0
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # ● 面向向左
  378.   #--------------------------------------------------------------------------
  379.   def turn_left
  380.     unless @direction_fix
  381.       @direction = 4
  382.       @stop_count = 0
  383.     end
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # ● 面向向右
  387.   #--------------------------------------------------------------------------
  388.   def turn_right
  389.     unless @direction_fix
  390.       @direction = 6
  391.       @stop_count = 0
  392.     end
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # ● 面向向上
  396.   #--------------------------------------------------------------------------
  397.   def turn_up
  398.     unless @direction_fix
  399.       @direction = 8
  400.       @stop_count = 0
  401.     end
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # ● 向右旋转 90 度
  405.   #--------------------------------------------------------------------------
  406.   def turn_right_90
  407.     case @direction
  408.     when 2
  409.       turn_left
  410.     when 4
  411.       turn_up
  412.     when 6
  413.       turn_down
  414.     when 8
  415.       turn_right
  416.     end
  417.   end
  418.   #--------------------------------------------------------------------------
  419.   # ● 向左旋转 90 度
  420.   #--------------------------------------------------------------------------
  421.   def turn_left_90
  422.     case @direction
  423.     when 2
  424.       turn_right
  425.     when 4
  426.       turn_down
  427.     when 6
  428.       turn_up
  429.     when 8
  430.       turn_left
  431.     end
  432.   end
  433.   #--------------------------------------------------------------------------
  434.   # ● 旋转 180 度
  435.   #--------------------------------------------------------------------------
  436.   def turn_180
  437.     case @direction
  438.     when 2
  439.       turn_up
  440.     when 4
  441.       turn_right
  442.     when 6
  443.       turn_left
  444.     when 8
  445.       turn_down
  446.     end
  447.   end
  448.   #--------------------------------------------------------------------------
  449.   # ● 从右向左旋转 90 度
  450.   #--------------------------------------------------------------------------
  451.   def turn_right_or_left_90
  452.     if rand(2) == 0
  453.       turn_right_90
  454.     else
  455.       turn_left_90
  456.     end
  457.   end
  458.   #--------------------------------------------------------------------------
  459.   # ● 随机变换方向
  460.   #--------------------------------------------------------------------------
  461.   def turn_random
  462.     case rand(4)
  463.     when 0
  464.       turn_up
  465.     when 1
  466.       turn_right
  467.     when 2
  468.       turn_left
  469.     when 3
  470.       turn_down
  471.     end
  472.   end
  473.   #--------------------------------------------------------------------------
  474.   # ● 接近主角的方向
  475.   #--------------------------------------------------------------------------
  476.   def turn_toward_player
  477.     # 求得与主角的坐标差
  478.     sx = @x - $game_player.x
  479.     sy = @y - $game_player.y
  480.     # 坐标相等的场合下
  481.     if sx == 0 and sy == 0
  482.       return
  483.     end
  484.     # 横侧距离长的情况下
  485.     if sx.abs > sy.abs
  486.       # 将左右方向变更为朝向主角的方向
  487.       sx > 0 ? turn_left : turn_right
  488.     # 竖侧距离长的情况下
  489.     else
  490.       # 将上下方向变更为朝向主角的方向
  491.       sy > 0 ? turn_up : turn_down
  492.     end
  493.   end
  494.   #--------------------------------------------------------------------------
  495.   # ● 背向主角的方向
  496.   #--------------------------------------------------------------------------
  497.   def turn_away_from_player
  498.     # 求得与主角的坐标差
  499.     sx = @x - $game_player.x
  500.     sy = @y - $game_player.y
  501.     # 坐标相等的场合下
  502.     if sx == 0 and sy == 0
  503.       return
  504.     end
  505.     # 横侧距离长的情况下
  506.     if sx.abs > sy.abs
  507.       # 将左右方向变更为背离主角的方向
  508.       sx > 0 ? turn_right : turn_left
  509.     # 竖侧距离长的情况下
  510.     else
  511.       # 将上下方向变更为背离主角的方向
  512.       sy > 0 ? turn_down : turn_up
  513.     end
  514.   end
  515. end
复制代码
■ Game_Player
  1. #==============================================================================
  2. # ■ Game_Player
  3. #------------------------------------------------------------------------------
  4. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  5. # 本类的实例请参考 $game_player。
  6. #==============================================================================

  7. class Game_Player < Game_Character
  8.   #--------------------------------------------------------------------------
  9.   # ● 恒量
  10.   #--------------------------------------------------------------------------
  11.   CENTER_X = (320 - 16) * 4   # 画面中央的 X 坐标 * 4
  12.   CENTER_Y = (240 - 16) * 4   # 画面中央的 Y 坐标 * 4
  13.   #--------------------------------------------------------------------------
  14.   # ● 可以通行判定
  15.   #     x : X 坐标
  16.   #     y : Y 坐标
  17.   #     d : 方向 (0,2,4,6,8)  ※ 0 = 全方向不能通行的情况判定 (跳跃用)
  18.   #--------------------------------------------------------------------------
  19.   def passable?(x, y, d)
  20.     # 求得新的坐标
  21.     new_x = x + (d == 6 ? 1 : d == 4 ? -1 : 0)
  22.     new_y = y + (d == 2 ? 1 : d == 8 ? -1 : 0)
  23.     # 坐标在地图外的情况下
  24.     unless $game_map.valid?(new_x, new_y)
  25.       # 不能通行
  26.       return false
  27.     end
  28.     # 调试模式为 ON 并且 按下 CTRL 键的情况下
  29.     if $DEBUG and Input.press?(Input::CTRL)
  30.       # 可以通行
  31.       return true
  32.     end
  33.     super
  34.   end
  35.   #--------------------------------------------------------------------------
  36.   # ● 像通到画面中央一样的设置地图的显示位置
  37.   #--------------------------------------------------------------------------
  38.   def center(x, y)
  39.     max_x = ($game_map.width - 20) * 128
  40.     max_y = ($game_map.height - 15) * 128
  41.     $game_map.display_x = [0, [x * 128 - CENTER_X, max_x].min].max
  42.     $game_map.display_y = [0, [y * 128 - CENTER_Y, max_y].min].max
  43.   end
  44.   #--------------------------------------------------------------------------
  45.   # ● 向指定的位置移动
  46.   #     x : X 座標
  47.   #     y : Y 座標
  48.   #--------------------------------------------------------------------------
  49.   def moveto(x, y)
  50.     super
  51.     # 自连接
  52.     center(x, y)
  53.     # 生成遇敌计数
  54.     make_encounter_count
  55.   end
  56.   #--------------------------------------------------------------------------
  57.   # ● 增加步数
  58.   #--------------------------------------------------------------------------
  59.   def increase_steps
  60.     super
  61.     # 不是强制移动路线的场合
  62.     unless @move_route_forcing
  63.       # 增加步数
  64.       $game_party.increase_steps
  65.       # 步数是偶数的情况下
  66.       if $game_party.steps % 2 == 0
  67.         # 检查连续伤害
  68.         $game_party.check_map_slip_damage
  69.       end
  70.     end
  71.   end
  72.   #--------------------------------------------------------------------------
  73.   # ● 获取遇敌计数
  74.   #--------------------------------------------------------------------------
  75.   def encounter_count
  76.     return @encounter_count
  77.   end
  78.   #--------------------------------------------------------------------------
  79.   # ● 生成遇敌计数
  80.   #--------------------------------------------------------------------------
  81.   def make_encounter_count
  82.     # 两种颜色震动的图像
  83.     if $game_map.map_id != 0
  84.       n = $game_map.encounter_step
  85.       @encounter_count = rand(n) + rand(n) + 1
  86.     end
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # ● 刷新
  90.   #--------------------------------------------------------------------------
  91.   def refresh
  92.     # 同伴人数为 0 的情况下
  93.     if $game_party.actors.size == 0
  94.       # 清除角色的文件名及对像
  95.       @character_name = ""
  96.       @character_hue = 0
  97.       # 分支结束
  98.       return
  99.     end
  100.     # 获取带头的角色
  101.     actor = $game_party.actors[0]
  102.     # 设置角色的文件名及对像
  103.     @character_name = actor.character_name
  104.     @character_hue = actor.character_hue
  105.     # 初始化不透明度和合成方式子
  106.     @opacity = 255
  107.     @blend_type = 0
  108.   end
  109.   #--------------------------------------------------------------------------
  110.   # ● 同位置的事件启动判定
  111.   #--------------------------------------------------------------------------
  112.   def check_event_trigger_here(triggers)
  113.     result = false
  114.     # 事件执行中的情况下
  115.     if $game_system.map_interpreter.running?
  116.       return result
  117.     end
  118.     # 全部事件的循环
  119.     for event in $game_map.events.values
  120.       # 事件坐标与目标一致的情况下
  121.       if event.x == @x and event.y == @y and triggers.include?(event.trigger)
  122.         # 跳跃中以外的情况下、启动判定是同位置的事件
  123.         if not event.jumping? and event.over_trigger?
  124.           event.start
  125.           result = true
  126.         end
  127.       end
  128.     end
  129.     return result
  130.   end
  131.   #--------------------------------------------------------------------------
  132.   # ● 正面事件的启动判定
  133.   #--------------------------------------------------------------------------
  134.   def check_event_trigger_there(triggers)
  135.     result = false
  136.     # 事件执行中的情况下
  137.     if $game_system.map_interpreter.running?
  138.       return result
  139.     end
  140.     # 计算正面坐标
  141.     new_x = @x + (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  142.     new_y = @y + (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  143.     # 全部事件的循环
  144.     for event in $game_map.events.values
  145.       # 事件坐标与目标一致的情况下
  146.       if event.x == new_x and event.y == new_y and
  147.          triggers.include?(event.trigger)
  148.         # 跳跃中以外的情况下、启动判定是正面的事件
  149.         if not event.jumping? and not event.over_trigger?
  150.           event.start
  151.           result = true
  152.         end
  153.       end
  154.     end
  155.     # 找不到符合条件的事件的情况下
  156.     if result == false
  157.       # 正面的元件是计数器的情况下
  158.       if $game_map.counter?(new_x, new_y)
  159.         # 计算 1 元件里侧的坐标
  160.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  161.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  162.         # 全事件的循环
  163.         for event in $game_map.events.values
  164.           # 事件坐标与目标一致的情况下
  165.           if event.x == new_x and event.y == new_y and
  166.              triggers.include?(event.trigger)
  167.             # 跳跃中以外的情况下、启动判定是正面的事件
  168.             if not event.jumping? and not event.over_trigger?
  169.               event.start
  170.               result = true
  171.             end
  172.           end
  173.         end
  174.       end
  175.     end
  176.     return result
  177.   end
  178.   #--------------------------------------------------------------------------
  179.   # ● 接触事件启动判定
  180.   #--------------------------------------------------------------------------
  181.   def check_event_trigger_touch(x, y)
  182.     result = false
  183.     # 事件执行中的情况下
  184.     if $game_system.map_interpreter.running?
  185.       return result
  186.     end
  187.     # 全事件的循环
  188.     for event in $game_map.events.values
  189.       # 事件坐标与目标一致的情况下
  190.       if event.x == x and event.y == y and [1,2].include?(event.trigger)
  191.         # 跳跃中以外的情况下、启动判定是正面的事件
  192.         if not event.jumping? and not event.over_trigger?
  193.           event.start
  194.           result = true
  195.         end
  196.       end
  197.     end
  198.     return result
  199.   end
  200.   #--------------------------------------------------------------------------
  201.   # ● 画面更新
  202.   #--------------------------------------------------------------------------
  203.   def update
  204.     # 本地变量记录移动信息
  205.     last_moving = moving?
  206.     # 移动中、事件执行中、强制移动路线中、
  207.     # 信息窗口一个也不显示的时候
  208.     unless moving? or $game_system.map_interpreter.running? or
  209.            @move_route_forcing or $game_temp.message_window_showing
  210.       # 如果方向键被按下、主角就朝那个方向移动
  211.   ###########################################################################
  212.       case Input.dir8
  213.       when 2
  214.         move_down
  215.       when 4
  216.         move_left
  217.       when 6
  218.         move_right
  219.       when 8
  220.         move_up
  221.       when 1
  222.         move_lower_left
  223.       when 3
  224.         move_lower_right
  225.       when 7
  226.         move_upper_left
  227.       when 9
  228.         move_upper_right
  229.       end
  230.   ###########################################################################
  231.     end
  232.     # 本地变量记忆坐标
  233.     last_real_x = @real_x
  234.     last_real_y = @real_y
  235.     super
  236.     # 角色向下移动、画面上的位置在中央下方的情况下
  237.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  238.       # 画面向下卷动
  239.       $game_map.scroll_down(@real_y - last_real_y)
  240.     end
  241.     # 角色向左移动、画面上的位置在中央左方的情况下
  242.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  243.       # 画面向左卷动
  244.       $game_map.scroll_left(last_real_x - @real_x)
  245.     end
  246.     # 角色向右移动、画面上的位置在中央右方的情况下
  247.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  248.       # 画面向右卷动
  249.       $game_map.scroll_right(@real_x - last_real_x)
  250.     end
  251.     # 角色向上移动、画面上的位置在中央上方的情况下
  252.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  253.       # 画面向上卷动
  254.       $game_map.scroll_up(last_real_y - @real_y)
  255.     end
  256.     # 不在移动中的情况下
  257.     unless moving?
  258.       # 上次主角移动中的情况
  259.       if last_moving
  260.         # 与同位置的事件接触就判定为事件启动
  261.         result = check_event_trigger_here([1,2])
  262.         # 没有可以启动的事件的情况下
  263.         if result == false
  264.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  265.           unless $DEBUG and Input.press?(Input::CTRL)
  266.             # 遇敌计数下降
  267.             if @encounter_count > 0
  268.               @encounter_count -= 1
  269.             end
  270.           end
  271.         end
  272.       end
  273.       # 按下 C 键的情况下
  274.       if Input.trigger?(Input::C)
  275.         # 判定为同位置以及正面的事件启动
  276.         check_event_trigger_here([0])
  277.         check_event_trigger_there([0,1,2])
  278.       end
  279.     end
  280.   end
  281. end
复制代码
■ Sprite_Character
  1. #==============================================================================
  2. # ■ Sprite_Character
  3. #------------------------------------------------------------------------------
  4. #  角色显示用脚本。监视 Game_Character 类的实例、
  5. # 自动变化脚本状态。
  6. #==============================================================================

  7. class Sprite_Character < RPG::Sprite
  8.   #--------------------------------------------------------------------------
  9.   # ● 定义实例变量
  10.   #--------------------------------------------------------------------------
  11.   attr_accessor :character                # 角色
  12.   #--------------------------------------------------------------------------
  13.   # ● 初始化对像
  14.   #     viewport  : 查看端口
  15.   #     character : 角色 (Game_Character)
  16.   #--------------------------------------------------------------------------
  17.   def initialize(viewport, character = nil)
  18.     super(viewport)
  19.     @character = character
  20.     update
  21.   end
  22.   #--------------------------------------------------------------------------
  23.   # ● 更新画面
  24.   #--------------------------------------------------------------------------
  25.   def update
  26.     super
  27.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  28.     if @tile_id != @character.tile_id or
  29.        @character_name != @character.character_name or
  30.        @character_hue != @character.character_hue
  31.       # 记忆元件 ID 与文件名、色相
  32.       @tile_id = @character.tile_id
  33.       @character_name = @character.character_name
  34.       @character_hue = @character.character_hue
  35.       # 元件 ID 为有效值的情况下
  36.       if @tile_id >= 384
  37.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  38.           @tile_id, @character.character_hue)
  39.         self.src_rect.set(0, 0, 32, 32)
  40.         self.ox = 16
  41.         self.oy = 32
  42.       # 元件 ID 为无效值的情况下
  43.       else
  44.         self.bitmap = RPG::Cache.character(@character.character_name,
  45.           @character.character_hue)
  46.         @cw = bitmap.width / 4
  47.   ###########################################################################
  48.         @ch = bitmap.height / 4
  49.   ###########################################################################
  50.         self.ox = @cw / 2
  51.         self.oy = @ch
  52.       end
  53.     end
  54.     # 设置可视状态
  55.     self.visible = (not @character.transparent)
  56.     # 图形是角色的情况下
  57.     if @tile_id == 0
  58.       # 设置传送目标的矩形
  59.       sx = @character.pattern * @cw
  60.   ###########################################################################
  61.       case @character.direction
  62.       when 2
  63.         self.bitmap = RPG::Cache.character(@character.character_name,
  64.           @character.character_hue)
  65.           @cw = bitmap.width / 4
  66.         @ch = bitmap.height / 4
  67.         sy = 0 * @ch
  68.       when 4
  69.         self.bitmap = RPG::Cache.character(@character.character_name,
  70.           @character.character_hue)
  71.           @cw = bitmap.width / 4
  72.         @ch = bitmap.height / 4
  73.         sy = 1 * @ch
  74.       when 6
  75.         self.bitmap = RPG::Cache.character(@character.character_name,
  76.           @character.character_hue)
  77.           @cw = bitmap.width / 4
  78.         @ch = bitmap.height / 4
  79.         sy = 2 * @ch
  80.       when 8
  81.         self.bitmap = RPG::Cache.character(@character.character_name,
  82.           @character.character_hue)
  83.           @cw = bitmap.width / 4
  84.         @ch = bitmap.height / 4
  85.         sy = 3 * @ch
  86.       when 1
  87.         self.bitmap = RPG::Cache.character(@character.character_name + "_quarter.png",
  88.           @character.character_hue)
  89.           @cw = bitmap.width / 4
  90.         @ch = bitmap.height / 4
  91.         sy = 0 * @ch
  92.       when 3
  93.         self.bitmap = RPG::Cache.character(@character.character_name + "_quarter.png",
  94.           @character.character_hue)
  95.           @cw = bitmap.width / 4
  96.         @ch = bitmap.height / 4
  97.         sy = 2 * @ch
  98.         
  99.       when 7
  100.         self.bitmap = RPG::Cache.character(@character.character_name + "_quarter.png",
  101.           @character.character_hue)
  102.           @cw = bitmap.width / 4
  103.         @ch = bitmap.height / 4
  104.         sy = 1 * @ch
  105.       when 9
  106.         self.bitmap = RPG::Cache.character(@character.character_name + "_quarter.png",
  107.           @character.character_hue)
  108.           @cw = bitmap.width / 4
  109.         @ch = bitmap.height / 4
  110.         sy = 3 * @ch
  111.       end
  112.       self.src_rect.set(sx, sy, @cw, @ch)
  113.   ###########################################################################
  114.     end
  115.     # 设置脚本的坐标
  116.     self.x = @character.screen_x
  117.     self.y = @character.screen_y
  118.     self.z = @character.screen_z(@ch)
  119.     # 设置不透明度、合成方式、茂密
  120.     self.opacity = @character.opacity
  121.     self.blend_type = @character.blend_type
  122.     self.bush_depth = @character.bush_depth
  123.     # 动画
  124.     if @character.animation_id != 0
  125.       animation = $data_animations[@character.animation_id]
  126.       animation(animation, true)
  127.       @character.animation_id = 0
  128.     end
  129.   end
  130. end
复制代码
工程 125.rar (236.66 KB, 下载次数: 1202)
新手弄的,不知道有没有问题
在那遥远的地方——有一只小猫
这里没有字→
相信我吧。

Lv2.观梦者

(?????)

梦石
0
星屑
700
在线时间
1327 小时
注册时间
2011-7-18
帖子
3184

贵宾

2
发表于 2011-12-5 21:31:54 | 只看该作者
BUG
1:Hero.png应整体向左向下各移动1像素。
2:斜四方向时设置移动路线的前进一步无效。
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-20 09:49

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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