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

Project1

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

[已经解决] 【脚本】八方向行走实现

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
48 小时
注册时间
2012-2-29
帖子
44
跳转到指定楼层
1
发表于 2012-7-21 11:29:34 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 迷糊的安安 于 2012-8-14 19:28 编辑

ACE八方向,求思路,有脚本更好
搜不到诶,之前的那个帖回复是0诶

Lv3.寻梦者

梦石
0
星屑
1344
在线时间
962 小时
注册时间
2012-4-30
帖子
1475

开拓者

2
发表于 2012-7-21 20:10:33 | 只看该作者
伪八方(对角线行走)?or 真八方?
这里有个10+的伪·8D

  1. class Game_Player < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   # ● 方向键移动处理
  4.   #--------------------------------------------------------------------------
  5.   def move_by_input
  6.      case Input.dir8
  7.       when 1;move_diagonal(4,2)
  8.       when 2;move_straight(2)
  9.       when 3;move_diagonal(6,2)
  10.       when 4;move_straight(4)
  11.       when 6;move_straight(6)
  12.       when 7;move_diagonal(4,8)
  13.       
  14.       when 8;move_straight(8)
  15.       when 9;move_diagonal(6,8)
  16.      end  
  17.   end
  18. end   
复制代码
.va写脚本的效率比vx快了不是一星半点啊。。。。咱去试写一下真8D

点评

啊,铅笔君,要真八方啊 额,行走图有什么特别要注意的么?  发表于 2012-7-21 20:24
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
95
在线时间
231 小时
注册时间
2011-5-14
帖子
13
3
发表于 2012-7-22 09:47:06 | 只看该作者
看看这个吧!

八方向行走.rar

695 Bytes, 下载次数: 192

回复 支持 反对

使用道具 举报

Lv3.寻梦者

死亡颂唱者

梦石
0
星屑
1154
在线时间
1794 小时
注册时间
2011-10-21
帖子
2245

开拓者

4
发表于 2012-7-22 10:45:30 | 只看该作者
本帖最后由 acn00269 于 2012-7-22 10:50 编辑

@星雨空也 这个可以不?
  1. #==============================================================================
  2. #  ■8方向移动 for RGSS3 Ver1.01 by 星潟
  3. #
  4. #     功能: 1.可以设置角色往8方向移动.
  5. #           2.可以设置关于移动的一部分功能.
  6. #==============================================================================
  7. # 使用说明:
  8. #   ★通过开关操作切换8方向移动的ON/OFF和能够设置一切移动的禁止.
  9. #   ★根据开关操作调转奔跑判定键.
  10. #   ★根据变量操作实行奔跑速度的强化.
  11. #   ★根据开关切换追加奔跑禁止功能.
  12. #
  13. #==============================================================================

  14. module MOVE_CONTROL
  15.   #--------------------------------------------------------------------------
  16.   # ● 基本设置(新增定义)
  17.   #--------------------------------------------------------------------------
  18.   # 这个开关ON的时候禁止8方向移动,只能4方向移动
  19.   FOUR_MOVE_SWITCH = 100
  20.   
  21.   # 这个开关ON的时候禁止操作角色
  22.   MOVE_SEAL_SWITCH = 101
  23.   
  24.   # 这个开关ON的时候调转奔跑判定键
  25.   # 平时奔跑时按下奔跑键的状态变成通常行走
  26.   DASH_REV = 102
  27.   
  28.   # 这个开关ON的时候奔跑不能使用
  29.   # 开关切换使同一地图能够奔跑的场所和不能奔跑的场所区别开来
  30.   DASH_SEAL = 103
  31.   
  32.   # 这个变量比0大的时候奔跑速度会再次增加
  33.   DASH_PLUS = 100
  34.   
  35. end

  36. class Game_CharacterBase
  37.   #--------------------------------------------------------------------------
  38.   # ● 取得移动速度(考虑奔跑状态)(重定义)
  39.   #--------------------------------------------------------------------------
  40.   alias real_move_speed_8direction real_move_speed
  41.   def real_move_speed
  42.     if $game_variables[MOVE_CONTROL::DASH_PLUS] > 0
  43.       dash_plus = 1 + ($game_variables[MOVE_CONTROL::DASH_PLUS] * 0.1)
  44.       @move_speed + (dash? ? dash_plus : 0)
  45.     else
  46.       real_move_speed_8direction
  47.     end
  48.   end
  49. end

  50. class Game_Player < Game_Character
  51.   #--------------------------------------------------------------------------
  52.   # ● 判定奔跑状态(重定义)
  53.   #--------------------------------------------------------------------------
  54.   alias dash_rev? dash?
  55.   def dash?
  56.     return false if $game_switches[MOVE_CONTROL::DASH_SEAL] == true
  57.     if $game_switches[MOVE_CONTROL::DASH_REV] == true
  58.       return false if @move_route_forcing
  59.       return false if $game_map.disable_dash?
  60.       return false if vehicle
  61.       return false if Input.press?(:A)
  62.       return true
  63.     else
  64.       dash_rev?
  65.     end
  66.   end
  67.   #--------------------------------------------------------------------------
  68.   # ● 处理方向键输入作出的移动(重定义)
  69.   #--------------------------------------------------------------------------
  70.   alias move_by_input_8direction move_by_input
  71.   def move_by_input
  72.     return if $game_switches[MOVE_CONTROL::MOVE_SEAL_SWITCH] == true
  73.     if $game_switches[MOVE_CONTROL::FOUR_MOVE_SWITCH] == true
  74.       move_by_input_8direction
  75.       return
  76.     end
  77.     return if !movable? || $game_map.interpreter.running?
  78.     if Input.press?(:LEFT) && Input.press?(:DOWN)
  79.       if passable?(@x, @y, 4) && passable?(@x, @y, 2) &&
  80.         passable?(@x - 1, @y, 2) && passable?(@x, @y + 1, 4) &&
  81.         passable?(@x - 1, @y + 1, 6) && passable?(@x - 1, @y + 1, 8)
  82.         move_diagonal(4, 2)
  83.       elsif @direction == 4
  84.         if passable?(@x, @y, 2) && passable?(@x, @y + 1, 8)
  85.           move_straight(2)
  86.         elsif passable?(@x, @y, 4) && passable?(@x - 1, @y, 6)
  87.           move_straight(4)
  88.         end
  89.       elsif @direction == 2
  90.         if passable?(@x, @y, 4) && passable?(@x - 1, @y, 6)
  91.           move_straight(4)
  92.         elsif passable?(@x, @y, 2) && passable?(@x, @y + 1, 8)
  93.           move_straight(2)
  94.         else
  95.           move_straight(Input.dir4) if Input.dir4 > 0
  96.         end
  97.       else
  98.         move_straight(Input.dir4) if Input.dir4 > 0
  99.       end
  100.     elsif Input.press?(:RIGHT) && Input.press?(:DOWN)
  101.       if passable?(@x, @y, 6) && passable?(@x, @y, 2) &&
  102.         passable?(@x + 1, @y, 2) && passable?(@x, @y + 1, 6) &&
  103.         passable?(@x + 1, @y + 1, 4) && passable?(@x + 1, @y + 1, 8)
  104.         move_diagonal(6, 2)
  105.       elsif @direction == 6
  106.         if passable?(@x, @y, 2) && passable?(@x, @y + 1, 8)
  107.           move_straight(2)
  108.         elsif passable?(@x, @y, 6) && passable?(@x + 1, @y, 4)
  109.           move_straight(6)
  110.         end
  111.       elsif @direction == 2
  112.         if passable?(@x, @y, 6) && passable?(@x + 1, @y, 4)
  113.           move_straight(6)
  114.         elsif passable?(@x, @y, 2) && passable?(@x, @y + 1, 8)
  115.           move_straight(2)
  116.         else
  117.           move_straight(Input.dir4) if Input.dir4 > 0
  118.         end
  119.       else
  120.         move_straight(Input.dir4) if Input.dir4 > 0
  121.       end
  122.     elsif Input.press?(:LEFT) && Input.press?(:UP)
  123.       if passable?(@x, @y, 4) && passable?(@x, @y, 8) &&
  124.         passable?(@x - 1, @y, 8) && passable?(@x, @y - 1, 4) &&
  125.         passable?(@x - 1, @y - 1, 2) && passable?(@x - 1, @y - 1, 6)
  126.         move_diagonal(4, 8)
  127.       elsif @direction == 4
  128.         if passable?(@x, @y, 8) && passable?(@x, @y - 1, 2)
  129.           move_straight(8)
  130.         elsif passable?(@x, @y, 4) && passable?(@x - 1, @y, 6)
  131.           move_straight(4)
  132.         else
  133.           move_straight(Input.dir4) if Input.dir4 > 0
  134.         end
  135.       elsif @direction == 8
  136.         if passable?(@x, @y, 4) && passable?(@x - 1, @y, 6)
  137.           move_straight(4)
  138.         elsif passable?(@x, @y, 8) && passable?(@x, @y - 1, 2)
  139.           move_straight(8)
  140.         else
  141.           move_straight(Input.dir4) if Input.dir4 > 0
  142.         end
  143.       else
  144.         move_straight(Input.dir4) if Input.dir4 > 0
  145.       end
  146.     elsif Input.press?(:RIGHT) && Input.press?(:UP)
  147.       if passable?(@x, @y, 6) && passable?(@x, @y, 8) &&
  148.         passable?(@x + 1, @y, 8) && passable?(@x, @y - 1, 6) &&
  149.         passable?(@x + 1, @y - 1, 2) && passable?(@x + 1, @y - 1, 4)
  150.         move_diagonal(6, 8)
  151.       elsif @direction == 6
  152.         if passable?(@x, @y, 8) && passable?(@x, @y - 1, 2)
  153.           move_straight(8)
  154.         elsif passable?(@x, @y, 6) && passable?(@x + 1, @y, 4)
  155.           move_straight(6)
  156.         else
  157.           move_straight(Input.dir4) if Input.dir4 > 0
  158.         end
  159.       elsif @direction == 8
  160.         if passable?(@x, @y, 6) && passable?(@x + 1, @y, 4)
  161.           move_straight(6)
  162.         elsif passable?(@x, @y, 8) && passable?(@x, @y - 1, 2)
  163.           move_straight(8)
  164.         else
  165.           move_straight(Input.dir4) if Input.dir4 > 0
  166.         end
  167.       else
  168.         move_straight(Input.dir4) if Input.dir4 > 0
  169.       end
  170.     else
  171.       move_straight(Input.dir4) if Input.dir4 > 0
  172.     end
  173.     unless moving?
  174.       @direction = Input.dir4 unless Input.dir4 == 0
  175.     end
  176.   end
  177. end
复制代码

点评

总是出错耶,什么未定义方法?????额···找不出原因,好吧,我承认我的脚本水平很烂  发表于 2012-7-23 11:46
这家伙很懒,什么也没有留下
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1344
在线时间
962 小时
注册时间
2012-4-30
帖子
1475

开拓者

5
发表于 2012-7-22 15:47:20 | 只看该作者
本帖最后由 铅笔描绘的思念 于 2012-7-22 15:48 编辑

人家写好了(´Д`)。。居然和LS撞了么。。。
RUBY 代码复制
  1. #===============================================================================
  2. #  八方向行走
  3. #    by:铅笔描绘的思念
  4. #    在Characters里添加八方向行走图(命名规范:在四方向上的基础上+_8D)
  5. #    行走动画就为8方向的。否则就会原4方向的代替8方向的。
  6. #
  7. #    八方向:数字键盘方向对应的数字
  8. #     7   8   9
  9. #      ↖ ↑ ↗
  10. #     4← 0 →6
  11. #      ↙ ↓ ↘
  12. #     1   2   3
  13. #===============================================================================
  14. #==============================================================================
  15. # ■ Game_Player
  16. #==============================================================================
  17. class Game_Player < Game_Character
  18.   #--------------------------------------------------------------------------
  19.   # ● 八方向
  20.   #--------------------------------------------------------------------------
  21.   def direction_8dir
  22.     @direction_8dir = @direction if @direction_8dir == nil
  23.     return @direction_8dir
  24.   end
  25.   #--------------------------------------------------------------------------
  26.   # ● 八方向移动
  27.   #    d    :1、3、7、9 对应小键盘的四个方向
  28.   #--------------------------------------------------------------------------
  29.   def move_eight_dir(d)
  30.     move_diagonal(d + 3,2) if d == 1 || d == 3
  31.     move_diagonal(d - 3,8) if d == 7 || d == 9
  32.   end
  33.   #--------------------------------------------------------------------------
  34.   # ● 八方向按键
  35.   #--------------------------------------------------------------------------
  36.   def move_by_input
  37.     return if !movable? || $game_map.interpreter.running?
  38.     case Input.dir8
  39.      when 1,3,7,9;  move_eight_dir(Input.dir8)
  40.      when 2,4,6,8;  move_straight(Input.dir4)
  41.     else;    return
  42.     end
  43.     @direction_8dir = Input.dir8
  44.   end
  45.   #--------------------------------------------------------------------------
  46.   # ● 斜向移动
  47.   #     horz : 横向(4 or 6)
  48.   #     vert : 纵向(2 or 8)
  49.   #--------------------------------------------------------------------------
  50.   def move_diagonal(horz, vert)
  51.     @move_succeed = diagonal_passable?(x, y, horz, vert)
  52.     last_steps = $game_party.steps
  53.     if @move_succeed
  54.       @x = $game_map.round_x_with_direction(@x, horz)
  55.       @y = $game_map.round_y_with_direction(@y, vert)
  56.       @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
  57.       @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
  58.       increase_steps
  59.       # 八方向移动正确步数计算
  60.       if $game_party.steps - last_steps == 2
  61.         $game_party.decrease_steps
  62.       end
  63.     end
  64.     set_direction(2) if horz == 4 && vert == 2
  65.     set_direction(4) if horz == 4 && vert == 8
  66.     set_direction(6) if horz == 6 && vert == 2
  67.     set_direction(8) if horz == 6 && vert == 8
  68.   end
  69. end
  70. #==============================================================================
  71. # ■ Game_Party
  72. #==============================================================================
  73. class Game_Party < Game_Unit
  74.   def decrease_steps
  75.     @steps -= 1
  76.   end
  77. end
  78. #==============================================================================
  79. # ■ Sprite_Character
  80. #==============================================================================
  81. class Sprite_Character < Sprite_Base
  82.   #--------------------------------------------------------------------------
  83.   # ● 更新源位图(Source Bitmap)
  84.   #--------------------------------------------------------------------------
  85.   alias update_bitmap_8dir update_bitmap
  86.   def update_bitmap
  87.     update_bitmap_8dir
  88.     if @tile_id > 0            
  89.       @enable_slant = false
  90.       return
  91.     end
  92.     unless graphic_changed?
  93.      @enable_slant = true
  94.     end
  95.    begin
  96.       @character_name_slant = "#{@character_name}_8D"
  97.       Cache.character(@character_name_slant)
  98.     rescue
  99.       @enable_slant = false
  100.     end
  101.   end
  102.   #--------------------------------------------------------------------------
  103.   # ● 更新源矩形
  104.   #--------------------------------------------------------------------------
  105.   alias update_src_rect_8dir update_src_rect  
  106.   def update_src_rect
  107.     return if @tile_id > 0      
  108.     if @enable_slant
  109.       update_src_rect_for_slant
  110.     else
  111.       update_src_rect_8dir
  112.     end
  113.   end
  114.   #--------------------------------------------------------------------------
  115.   # ● 更新斜方向传送矩形
  116.   #--------------------------------------------------------------------------
  117.   def update_src_rect_for_slant
  118.     index = @character.character_index
  119.     pattern = @character.pattern < 3 ? @character.pattern : 1
  120.     sx = (index % 4 * 3 + pattern) * @cw
  121.     dir = @character.direction_8dir
  122.     case dir % 2
  123.     when 0  # 上下左右
  124.       if @last_slant
  125.         self.bitmap = Cache.character(@character_name)
  126.         @last_slant = false
  127.       end
  128.     else   
  129.       unless @last_slant
  130.         self.bitmap = Cache.character(@character_name_slant)
  131.         @last_slant = true
  132.       end
  133.     end
  134.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  135.     self.src_rect.set(sx, sy, @cw, @ch)
  136.   end
  137. end

点评

谢谢铅笔君,搬走啦  发表于 2012-7-23 11:45
咱去发布。。  发表于 2012-7-22 15:49

评分

参与人数 1星屑 +400 梦石 +4 收起 理由
迷糊的安安 + 400 + 4 推荐问答 附赠66RPG提供的精美好人卡2张^^.

查看全部评分

回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-5-15 00:10

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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