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

Project1

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

斜四方脚本问题

 关闭 [复制链接]
头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-8-26
帖子
103
跳转到指定楼层
1
发表于 2007-8-28 22:15:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
头像被屏蔽

Lv1.梦旅人 (禁止发言)

梦石
0
星屑
50
在线时间
0 小时
注册时间
2007-8-26
帖子
103
2
 楼主| 发表于 2007-8-28 22:15:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽

Lv2.观梦者

龙骑

梦石
0
星屑
590
在线时间
10 小时
注册时间
2007-12-31
帖子
2030
3
发表于 2008-1-3 21:21:43 | 只看该作者
给你个老关的斜四好了...
  1. #==============================================================================
  2. # 本脚本来自www.66RPG.com,使用和转载请保留此信息
  3. #$game_map.events[1].name = ""
  4. #==============================================================================
  5. ###########################################################################################################################
  6. ###########################################################################################################################
  7. # 脚本功能:八方向走与多帧移动之图片修正__ver1.1。

  8. # 更新日期:2005年8月6日

  9. # 更新内容:增加斜方向触发,增加斜方向面向角色(1步之内)

  10. # 使用方法:将本脚本插入到main之前。如果你使用了雅土版的八方向走脚本,请确保这个脚本的顺序位置,在雅土八方向走脚本的后面。

  11. # 预先处理:请输入每一步的帧数和总共可用的方向数

  12. $c3_每一步的帧数 = 4
  13. $c3_总共可用的方向数 = 4 #——建议不要修改这个。如果要伪8方向的,就用伪的好了。

  14. # 图片处理与功能说明:

  15. # 1、每一步的帧数:
  16. #    众所周知,RMXP的移动行走图是一个方向共有4帧,很多人都觉得这个帧数有点少。
  17. # 使用这个脚本之后,只要将 $c3_每一步的帧数 这个变量设置一个需要的帧数即可修改
  18. # 单方向移动帧数为相应输入值。修改后,需要用photoshop将所有用到的素材的横排
  19. # 调整为相应帧数,比如输入了8则要将每一行设置8个图像(即每一个行走图有8列)。

  20. # 2、可用方向调整(可用数量:4、8):
  21. #    当为4方向时没有任何变化,还是一个图4行,上左右下4个方向。
  22. #    如果想使用8方向走,将需要八方向行走的行走图在延伸扩大的画布中按照左下、右下、左上、右上继续排布图像。
  23. # 即,行走图图片从上到下的面向排列顺序为:下,左,右,上,左下,右下,左上,右上。
  24. #    至于不需要8方向走的普通的NPC(character),使用photoshop将画布向下扩大一倍即可使用。
  25. #    需要注意的是,如果需要斜方向飞鸟,请不要忘记自制素材。

  26. # 特别提示:   
  27. #     使用本脚本前请先考虑清楚是否要做这种效果。因为使用本脚本后需要用photoshop处理character行走图素材
  28. # 虽然这种处理用photoshop定义动作只需要5分钟即可全部完成,但在制作阶段会感觉不是很爽(具体的用了才知道)
  29. # 作者的建议是,如果你没有足够的制作经验,使用这个脚本得不偿失。请确保自己的能力属于“高手”级别!

  30. # 附赠功能:
  31. #     可以让NPC角色随机8方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c8即可
  32. #     可以让NPC角色随机4斜角方向走,方法是:NPC角色移动路线为“自定义”,然后自定义里面使用脚本,输入c4即可
  33. #     可以使用真·斜4方向行走,参考脚本53行开始
  34. # 作者:carol3
  35. ###########################################################################################################################
  36. ###########################################################################################################################





  37. class Game_Player < Game_Character
  38.   def update
  39.     last_moving = moving?
  40.     unless moving? or $game_system.map_interpreter.running? or
  41.            @move_route_forcing or $game_temp.message_window_showing
  42.            
  43.            if $pic_1_show == true
  44.              $game_screen.pictures[1].erase
  45.              $pic_1_show = false
  46.            end
  47.            
  48.            
  49.       # 用井号后面的东西替代前面的,就可以实现斜4方向走
  50.       case Input.dir8
  51.       when 2
  52.         if $game_switches[8]
  53.           move_down
  54.         else
  55.            move_lower_right#move_lower_left
  56.         end            
  57.       when 4
  58.         if $game_switches[8]
  59.           move_left
  60.         else
  61.         move_lower_left#  move_upper_left
  62.         end
  63.       when 6
  64.         if $game_switches[8]
  65.           move_right
  66.         else
  67.           move_upper_right# move_lower_right
  68.         end
  69.       when 8
  70.         if $game_switches[8]
  71.           move_up
  72.         else
  73.          move_upper_left# move_upper_right        
  74.         end
  75.       when 1
  76.         move_lower_left
  77.       when 3
  78.         move_lower_right
  79.       when 7
  80.         move_upper_left
  81.       when 9
  82.         move_upper_right
  83.       end
  84.     end
  85.     # 本地变量记忆坐标
  86.     last_real_x = @real_x
  87.     last_real_y = @real_y
  88.     super
  89.     # 角色向下移动、画面上的位置在中央下方的情况下
  90.     if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
  91.       # 画面向下卷动
  92.       $game_map.scroll_down(@real_y - last_real_y)
  93.     end
  94.     # 角色向左移动、画面上的位置在中央左方的情况下
  95.     if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
  96.       # 画面向左卷动
  97.       $game_map.scroll_left(last_real_x - @real_x)
  98.     end
  99.     # 角色向右移动、画面上的位置在中央右方的情况下
  100.     if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
  101.       # 画面向右卷动
  102.       $game_map.scroll_right(@real_x - last_real_x)
  103.     end
  104.     # 角色向上移动、画面上的位置在中央上方的情况下
  105.     if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
  106.       # 画面向上卷动
  107.       $game_map.scroll_up(last_real_y - @real_y)
  108.     end
  109.     # 不在移动中的情况下
  110.     unless moving?
  111.       # 上次主角移动中的情况
  112.       if last_moving
  113.         # 与同位置的事件接触就判定为事件启动
  114.         result = check_event_trigger_here([1,2])
  115.         # 没有可以启动的事件的情况下
  116.         if result == false
  117.           # 调试模式为 ON 并且按下 CTRL 键的情况下除外
  118.           unless $DEBUG and Input.press?(Input::CTRL)
  119.             # 遇敌计数下降
  120.             if @encounter_count > 0
  121.               @encounter_count -= 1
  122.             end
  123.           end
  124.         end
  125.       end
  126.       # 按下 C 键的情况下
  127.       if Input.trigger?(Input::C)
  128.         # 判定为同位置以及正面的事件启动
  129.         check_event_trigger_here([0])
  130.         check_event_trigger_there([0,1,2])
  131.       end
  132.     end
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● 正面事件的启动判定
  136.   #--------------------------------------------------------------------------
  137.   def check_event_trigger_there(triggers)
  138.     result = false
  139.     # 事件执行中的情况下
  140.     if $game_system.map_interpreter.running?
  141.       return result
  142.     end
  143.     # 计算正面坐标
  144.     new_x = @x
  145.     new_y = @y
  146.     case @direction
  147.    when 1
  148.       new_x -= 1
  149.       new_y += 1
  150.     when 2
  151.      new_y += 1
  152.     when 3
  153.       new_x += 1
  154.       new_y += 1
  155.     when 4
  156.       new_x -= 1
  157.     when 6
  158.       new_x += 1
  159.     when 7
  160.       new_x -= 1
  161.       new_y -= 1
  162.     when 8
  163.      new_y -= 1
  164.     when 9
  165.       new_x += 1
  166.       new_y -= 1
  167.     end
  168.     # 全部事件的循环
  169.     for event in $game_map.events.values
  170.       # 事件坐标与目标一致的情况下
  171.       if event.x == new_x and event.y == new_y and
  172.          triggers.include?(event.trigger)
  173.         # 跳跃中以外的情况下、启动判定是正面的事件
  174.         if not event.jumping? and not event.over_trigger?
  175.           event.start
  176.           result = true
  177.         end
  178.       end
  179.     end
  180.     # 找不到符合条件的事件的情况下
  181.     if result == false
  182.       # 正面的元件是计数器的情况下
  183.       if $game_map.counter?(new_x, new_y)
  184.         # 计算 1 元件里侧的坐标
  185.         new_x += (@direction == 6 ? 1 : @direction == 4 ? -1 : 0)
  186.         new_y += (@direction == 2 ? 1 : @direction == 8 ? -1 : 0)
  187.         # 全事件的循环
  188.         for event in $game_map.events.values
  189.           # 事件坐标与目标一致的情况下
  190.           if event.x == new_x and event.y == new_y and
  191.              triggers.include?(event.trigger)
  192.             # 跳跃中以外的情况下、启动判定是正面的事件
  193.             if not event.jumping? and not event.over_trigger?
  194.               event.start
  195.               result = true
  196.             end
  197.           end
  198.         end
  199.       end
  200.     end
  201.     return result
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # ● 向左下移动
  205.   #--------------------------------------------------------------------------
  206.   def move_lower_left
  207.     # 没有固定面向的场合
  208.     unless @direction_fix
  209.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  210.       @direction = 3#(@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  211.     end
  212.     # 下→左、左→下 的通道可以通行的情况下
  213.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 4)) or
  214.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 2))
  215.       # 更新坐标
  216.       @x -= 1
  217.       @y += 1
  218.       # 增加步数
  219.       increase_steps
  220.     else
  221.       check_event_trigger_touch(@x-1, @y+1)
  222.     end
  223.   end
  224.   #--------------------------------------------------------------------------
  225.   # ● 向右下移动
  226.   #--------------------------------------------------------------------------
  227.   def move_lower_right
  228.     # 没有固定面向的场合
  229.     unless @direction_fix
  230.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  231.       @direction = 9#(@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  232.     end
  233.     # 下→右、右→下 的通道可以通行的情况下
  234.     if (passable?(@x, @y, 2) and passable?(@x, @y + 1, 6)) or
  235.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 2))
  236.       # 更新坐标
  237.       @x += 1
  238.       @y += 1
  239.       # 增加步数
  240.       increase_steps
  241.     else
  242.       check_event_trigger_touch(@x+1, @y+1)
  243.     end
  244.   end
  245.   #--------------------------------------------------------------------------
  246.   # ● 向左上移动
  247.   #--------------------------------------------------------------------------
  248.   def move_upper_left
  249.     # 没有固定面向的场合
  250.     unless @direction_fix
  251.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  252.       @direction = 7#(@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  253.     end
  254.     # 上→左、左→上 的通道可以通行的情况下
  255.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 4)) or
  256.        (passable?(@x, @y, 4) and passable?(@x - 1, @y, 8))
  257.       # 更新坐标
  258.       @x -= 1
  259.       @y -= 1
  260.       # 增加步数
  261.       increase_steps
  262.     else
  263.       check_event_trigger_touch(@x-1, @y-1)
  264.     end
  265.   end
  266.   #--------------------------------------------------------------------------
  267.   # ● 向右上移动
  268.   #--------------------------------------------------------------------------
  269.   def move_upper_right
  270.     # 没有固定面向的场合
  271.     unless @direction_fix
  272.       # 朝向是右的情况下适合的面是左面、朝向是上的情况下适合的面是下面
  273.       @direction = 1#(@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  274.     end
  275.     # 上→右、右→上 的通道可以通行的情况下
  276.     if (passable?(@x, @y, 8) and passable?(@x, @y - 1, 6)) or
  277.        (passable?(@x, @y, 6) and passable?(@x + 1, @y, 8))
  278.       # 更新坐标
  279.       @x += 1
  280.       @y -= 1
  281.       # 增加步数
  282.       increase_steps
  283.     else
  284.       check_event_trigger_touch(@x+1, @y-1)
  285.     end
  286.   end
  287. end


  288. class Sprite_Character < RPG::Sprite
  289.   
  290.   def update
  291.     super
  292.     # 元件 ID、文件名、色相与现在的情况存在差异的情况下
  293.     if @tile_id != @character.tile_id or
  294.        @character_name != @character.character_name or
  295.        @character_hue != @character.character_hue
  296.       # 记忆元件 ID 与文件名、色相
  297.       @tile_id = @character.tile_id
  298.       @character_name = @character.character_name
  299.       @character_hue = @character.character_hue
  300.       # 元件 ID 为有效值的情况下
  301.       if @tile_id >= 384
  302.         self.bitmap = RPG::Cache.tile($game_map.tileset_name,
  303.           @tile_id, @character.character_hue)
  304.         self.src_rect.set(0, 0, 32, 32)
  305.         self.ox = 16
  306.         self.oy = 32
  307.       # 元件 ID 为无效值的情况下
  308.       else
  309.         self.bitmap = RPG::Cache.character(@character.character_name,
  310.           @character.character_hue)
  311.         @cw = bitmap.width / $c3_每一步的帧数
  312.           @ch = bitmap.height / 4
  313.         self.ox = @cw / 2
  314.         self.oy = @ch
  315.       end
  316.     end
  317.   
  318.    
  319.     # 设置可视状态
  320.     self.visible = (not @character.transparent)
  321.     # 图形是角色的情况下
  322.     if @tile_id == 0
  323.       # 设置传送目标的矩形
  324.       sx = @character.pattern * @cw
  325.         case @character.direction
  326.         when 2
  327.           sy = 0 * @ch
  328.         when 4
  329.           sy = 1 * @ch
  330.         when 6
  331.           sy = 2 * @ch
  332.         when 8
  333.           sy = 3 * @ch
  334.         when 1
  335.           sy = 2 * @ch
  336.         when 3
  337.           sy = 1 * @ch
  338.         when 7
  339.           sy = 3 * @ch
  340.         when 9
  341.           sy = 0 * @ch
  342.         end
  343.       self.src_rect.set(sx, sy, @cw, @ch)
  344.     end
  345.     # 设置脚本的坐标
  346.     self.x = @character.screen_x
  347.     self.y = @character.screen_y
  348.     self.z = @character.screen_z(@ch)
  349.     # 设置不透明度、合成方式、茂密
  350.     self.opacity = @character.opacity
  351.     self.blend_type = @character.blend_type
  352.     self.bush_depth = @character.bush_depth
  353.     # 动画
  354.     if @character.animation_id != 0
  355.       animation = $data_animations[@character.animation_id]
  356.       animation(animation, true)
  357.       @character.animation_id = 0
  358.     end
  359.   end
  360. end
  361. class Game_Character
  362.   attr_accessor :time
  363.   #--------------------------------------------------------------------------
  364.   # ● 初始化对像
  365.   #--------------------------------------------------------------------------
  366.   alias old_ini initialize
  367.   def initialize
  368.     old_ini
  369.     @time = 0
  370.   end
  371.   def c8
  372.     # 随机 0~5 的分支
  373.     case rand(10)
  374.     when 0..3  # 随机
  375.       move_random
  376.     when 4  # 前进一步
  377.       move_forward
  378.     when 5  # 暂时停止
  379.       @stop_count = 0
  380.     when 6..9  #另外4方向随机
  381.       c4
  382.     end
  383.   end
  384.   def c4
  385.     case rand(5)
  386.     when 0
  387.       move_upper_left
  388.     when 1
  389.       move_upper_right
  390.     when 2
  391.       move_lower_left
  392.     when 3
  393.       move_lower_right
  394.     when 4
  395.       @stop_count = 0
  396.     end
  397.   end
  398.       
  399.   def update
  400.     # 跳跃中、移动中、停止中的分支
  401.     if jumping?
  402.       update_jump
  403.     elsif moving?
  404.       update_move
  405.     else
  406.       update_stop
  407.     end
  408.     # 动画计数超过最大值的情况下
  409.     # ※最大值等于基本值减去移动速度 * 1 的值
  410.     if @anime_count > 16*4/$c3_每一步的帧数 - @move_speed * 2  
  411.       # 停止动画为 OFF 并且在停止中的情况下
  412.       if not @step_anime and @stop_count > 0
  413.         # 还原为原来的图形
  414.         @pattern = @original_pattern
  415.       # 停止动画为 ON 并且在移动中的情况下
  416.       else
  417.         # 更新图形
  418.         @pattern = (@pattern + 1) % $c3_每一步的帧数
  419.       end
  420.       # 清除动画计数
  421.       @anime_count = 0
  422.     end
  423.     # 等待中的情况下
  424.     if @wait_count > 0
  425.       # 减少等待计数
  426.       @wait_count -= 0
  427.       return
  428.     end
  429.     # 强制移动路线的场合
  430.     if @move_route_forcing
  431.       # 自定义移动
  432.       move_type_custom
  433.       return
  434.     end
  435.     # 事件执行待机中并且为锁定状态的情况下
  436.     if @starting or lock?
  437.       # 不做规则移动
  438.       return
  439.     end
  440.     # 如果停止计数超过了一定的值(由移动频度算出)
  441.     if @stop_count > (40 - @move_frequency * 2) * (6 - @move_frequency)
  442.       # 移动类型分支
  443.       case @move_type
  444.       when 1  # 随机
  445.         move_type_random
  446.       when 2  # 接近
  447.         move_type_toward_player
  448.       when 3  # 自定义
  449.         move_type_custom
  450.       end
  451.     end
  452.   end
  453. end

  454. class Window_Base < Window
  455.   def draw_actor_graphic(actor, x, y)
  456.     bitmap = RPG::Cache.character(actor.character_name, actor.character_hue)
  457.     cw = bitmap.width / $c3_每一步的帧数
  458.     ch = bitmap.height / $c3_总共可用的方向数
  459.     src_rect = Rect.new(0, 0, cw, ch)
  460.     self.contents.blt(x - cw / 2, y - ch, bitmap, src_rect)
  461.   end
  462. end

  463. class Game_Character
  464.   #--------------------------------------------------------------------------
  465.   # ● 面向主角的方向
  466.   #--------------------------------------------------------------------------
  467.   def turn_toward_player
  468.     # 求得与主角的坐标差
  469.     sx = @x - $game_player.x
  470.     sy = @y - $game_player.y
  471.     # 坐标相等的场合下
  472.     if sx == 0 and sy == 0
  473.       return
  474.     end
  475.     # 横侧距离长的情况下
  476.     if sx.abs > sy.abs
  477.       # 将左右方向变更为朝向主角的方向
  478.       sx > 0 ? turn_left : turn_right
  479.     # 竖侧距离长的情况下
  480.     else
  481.       # 将上下方向变更为朝向主角的方向
  482.       sy > 0 ? turn_up : turn_down
  483.     end
  484.     if sx == -1 and sy == -1
  485.       @direction = 9
  486.       @stop_count = 0
  487.     elsif sx == -1 and sy == 1
  488.       @direction = 1
  489.       @stop_count = 0
  490.     elsif sx == 1 and sy == -1
  491.       @direction = 3
  492.       @stop_count = 0
  493.     elsif sx == 1 and sy == 1
  494.       @direction = 7
  495.       @stop_count = 0
  496.     end
  497.   end
  498. end
复制代码
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-6-19 07:33

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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