| 
 
| 赞 | 0 |  
| VIP | 7 |  
| 好人卡 | 1 |  
| 积分 | 1 |  
| 经验 | 4577 |  
| 最后登录 | 2023-11-6 |  
| 在线时间 | 169 小时 |  
 Lv1.梦旅人 
	梦石0 星屑100 在线时间169 小时注册时间2007-8-12帖子203 | 
| 本帖最后由 心雪 于 2011-4-21 16:29 编辑 
 制作SLG是个非常麻烦的工程……Good Luck复制代码class Game_Character
  #------------------------------------------------------
  # ● 可以到达的位置
  # ! 返回数组 
  # ! 递归调用
  # x 当前x坐标
  # y 当前y坐标
  # s 当前步数
  # a 当前数组 初始调用设置为nil
  #------------------------------------------------------
  def can_get(x = @x,y = @y,s = 10,a = nil)
    #如果当前位置被用更少的步数走过,返回
    if a == nil
      a = Table.new($game_map.width,$game_map.height)
      for i in 0...a.xsize
        for j in 0...a.ysize
          a[i,j] = -1
        end
      end
    end
    if a[x,y] != nil
      if a[x,y] >= s
        return a
      end
    end
    #如果步数用尽,返回
    if s < 0
      return a
    end
    #添加当前位置
    a[x,y] = s
    #如果右方可以通行
    if x < $game_map.width - 1
      if passable?(x,y,6)
        can_get(x+1,y,s-1,a)
      end
    end
    #如果左方可以通行
    if x > 0
      if passable?(x,y,4) && x > 0
        can_get(x-1,y,s-1,a)
      end
    end
    #如果上方可以通行
    if y < $game_map.height - 1
      if passable?(x,y,2)
        can_get(x,y+1,s-1,a)
      end
    end
    #如果下方可以通行
    if passable?(x,y,8) && y > 0
      can_get(x,y-1,s-1,a)
    end
    return a 
  end
end
class Game_Map
  attr :color_area
  attr :need_refresh_color,true
  alias _snow_heart_setup setup
  def setup(*arg)
    _snow_heart_setup(*arg)
    @color_area = Table.new(width,height)
    @need_refresh_color = false
  end
  def color_area=(v)
    @color_area = v
    @need_refresh_color = true
  end
end
  
class Spriteset_Map
  alias _snow_heart_initialize_ initialize
  def initialize
    _snow_heart_initialize_
    @color_sprite = []
  end
  alias _snow_heart_update_ update
  def update
    update_color
    _snow_heart_update_
  end
  def update_color
    #刷新图片,添加动画可以在这里写
    if $game_map.need_refresh_color
      refresh_color
      $game_map.need_refresh_color = false
    end
  end
  def refresh_color
    for i in @color_sprite
      i.dispose
    end
    for i in 0...$game_map.color_area.xsize
      for j in 0...$game_map.color_area.ysize
        if $game_map.color_area[i,j] > 0 
          sc = Sprite.new(@viewport1)
          sc.z = 0
          sc.bitmap = Bitmap.new(32,32)
          sc.bitmap.fill_rect(0,0,32,32,Color.new(0,0,255,128)) #此处可修改风格
          sc.x = (i*128 - $game_map.display_x + 3) / 4 + 16
          sc.y = (j*128 - $game_map.display_y + 3) / 4 + 32
          sc.ox = 16
          sc.oy = 32
          @color_sprite.push(sc)
        end
      end
    end
  end
end
测试方法:
 $game_map.color_area = $game_player.can_get
 把脚本从VX改到XP好纠结=,=
 ------------------------------------------------------------
 发现一错误……已修改,注释不小心写错了导致转成XP脚本时写错方向……看来注释也是不能马虎呢~
 | 
 评分
查看全部评分
 |