查看: 7212|回复: 4

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

[复制链接]
梦石
0
星屑
50
在线时间
48 小时
注册时间
2012-2-29
回帖
35
发表于 2012-7-21 11:29:34 | 显示全部楼层 |阅读模式

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

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

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

ACE八方向,求思路,有脚本更好
搜不到诶,之前的那个帖回复是0诶
梦石
0
星屑
2306
在线时间
1010 小时
注册时间
2012-4-30
回帖
1455

开拓者

发表于 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
回复

使用道具 举报

梦石
0
星屑
95
在线时间
231 小时
注册时间
2011-5-14
回帖
12
发表于 2012-7-22 09:47:06 | 显示全部楼层
看看这个吧!

八方向行走.rar

695 Bytes, 下载次数: 193

回复

使用道具 举报

死亡颂唱者

梦石
0
星屑
1159
在线时间
1795 小时
注册时间
2011-10-21
回帖
2205

开拓者

发表于 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
这家伙很懒,什么也没有留下
回复

使用道具 举报

梦石
0
星屑
2306
在线时间
1010 小时
注册时间
2012-4-30
回帖
1455

开拓者

发表于 2012-7-22 15:47:20 | 显示全部楼层
本帖最后由 铅笔描绘的思念 于 2012-7-22 15:48 编辑

人家写好了(´Д`)。。居然和LS撞了么。。。[pre lang="ruby" line="1"]#===============================================================================
#  八方向行走
#    by:铅笔描绘的思念
#    在Characters里添加八方向行走图(命名规范:在四方向上的基础上+_8D)
#    行走动画就为8方向的。否则就会原4方向的代替8方向的。
#
#    八方向:数字键盘方向对应的数字
#     7   8   9
#      ↖ ↑ ↗
#     4← 0 →6
#      ↙ ↓ ↘
#     1   2   3
#===============================================================================
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 八方向
  #--------------------------------------------------------------------------
  def direction_8dir
    @direction_8dir = @direction if @direction_8dir == nil
    return @direction_8dir
  end
  #--------------------------------------------------------------------------
  # ● 八方向移动
  #    d    :1、3、7、9 对应小键盘的四个方向
  #--------------------------------------------------------------------------
  def move_eight_dir(d)
    move_diagonal(d + 3,2) if d == 1 || d == 3
    move_diagonal(d - 3,8) if d == 7 || d == 9
  end
  #--------------------------------------------------------------------------
  # ● 八方向按键
  #--------------------------------------------------------------------------
  def move_by_input
    return if !movable? || $game_map.interpreter.running?
    case Input.dir8
     when 1,3,7,9;  move_eight_dir(Input.dir8)
     when 2,4,6,8;  move_straight(Input.dir4)
    else;    return
    end
    @direction_8dir = Input.dir8
  end
  #--------------------------------------------------------------------------
  # ● 斜向移动
  #     horz : 横向(4 or 6)
  #     vert : 纵向(2 or 8)
  #--------------------------------------------------------------------------
  def move_diagonal(horz, vert)
    @move_succeed = diagonal_passable?(x, y, horz, vert)
    last_steps = $game_party.steps
    if @move_succeed
      @x = $game_map.round_x_with_direction(@x, horz)
      @y = $game_map.round_y_with_direction(@y, vert)
      @real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
      @real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
      increase_steps
      # 八方向移动正确步数计算
      if $game_party.steps - last_steps == 2
        $game_party.decrease_steps
      end
    end
    set_direction(2) if horz == 4 && vert == 2
    set_direction(4) if horz == 4 && vert == 8
    set_direction(6) if horz == 6 && vert == 2
    set_direction(8) if horz == 6 && vert == 8
  end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party < Game_Unit
  def decrease_steps
    @steps -= 1
  end
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
  #--------------------------------------------------------------------------
  # ● 更新源位图(Source Bitmap)
  #--------------------------------------------------------------------------
  alias update_bitmap_8dir update_bitmap
  def update_bitmap
    update_bitmap_8dir
    if @tile_id > 0            
      @enable_slant = false
      return
    end
    unless graphic_changed?
     @enable_slant = true
    end
   begin
      @character_name_slant = "#{@character_name}_8D"
      Cache.character(@character_name_slant)
    rescue
      @enable_slant = false
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新源矩形
  #--------------------------------------------------------------------------
  alias update_src_rect_8dir update_src_rect  
  def update_src_rect
    return if @tile_id > 0      
    if @enable_slant
      update_src_rect_for_slant
    else
      update_src_rect_8dir
    end
  end
  #--------------------------------------------------------------------------
  # ● 更新斜方向传送矩形
  #--------------------------------------------------------------------------
  def update_src_rect_for_slant
    index = @character.character_index
    pattern = @character.pattern < 3 ? @character.pattern : 1
    sx = (index % 4 * 3 + pattern) * @cw
    dir = @character.direction_8dir
    case dir % 2
    when 0  # 上下左右
      if @last_slant
        self.bitmap = Cache.character(@character_name)
        @last_slant = false
      end
    else   
      unless @last_slant
        self.bitmap = Cache.character(@character_name_slant)
        @last_slant = true
      end
    end
      sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
    self.src_rect.set(sx, sy, @cw, @ch)
  end
end
[/pre]

点评

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

评分

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

查看全部评分

回复

使用道具 举报

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

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部