| 
本帖最后由 jiaboxuan 于 2013-12-21 23:15 编辑
x
加入我们,或者,欢迎回来。您需要 登录 才可以下载或查看,没有帐号?注册会员  
 因为是刚刚开始接触RGSS,所以不知道我这样实现有什么弊端,期望有经验的朋友们来帮忙指正。
 
 #==============================================================================# ■ Game_Character_Box (自定义)#------------------------------------------------------------------------------# □ 扩展Game_Character#============================================================================== class Game_Character   #--------------------------------------------------------------------------  # ● 定义实例变量  #--------------------------------------------------------------------------  attr_accessor   :destination            # 目的地  attr_accessor   :is_arrive              # 是否到达  #--------------------------------------------------------------------------  # ● 初始化对像  #--------------------------------------------------------------------------  def initialize_box    @destination = false    @is_arrive = false        $pass_num = 0  endend
#============================================================================== 
# ■ Game_Character_Box (自定义) 
#------------------------------------------------------------------------------ 
# □ 扩展Game_Character 
#============================================================================== 
  
class Game_Character  
  #-------------------------------------------------------------------------- 
  # ● 定义实例变量 
  #-------------------------------------------------------------------------- 
  attr_accessor   :destination            # 目的地 
  attr_accessor   :is_arrive              # 是否到达 
  #-------------------------------------------------------------------------- 
  # ● 初始化对像 
  #-------------------------------------------------------------------------- 
  def initialize_box 
    @destination = false 
    @is_arrive = false     
    $pass_num = 0 
  end 
end 
 #==============================================================================# ■ Interpreter_Box (自定义)#------------------------------------------------------------------------------# □ 扩展Interpreter#==============================================================================class Interpreter  #--------------------------------------------------------------------------  # ● 自定义脚本_设定目的地  #--------------------------------------------------------------------------  def command_set_destination        unless get_character(0).destination      get_character(0).destination = true      $pass_num += 1    end    end    #--------------------------------------------------------------------------  # ● 自定义脚本_推箱子  #--------------------------------------------------------------------------  def command_pushbox      row = 0    col = 0     # 判断人物朝向    case $game_player.direction    when 2      row += 1    when 4      col -= 1    when 6      col += 1    when 8      row -= 1    end         # 箱子    box = get_character(0)     # 地图上的这个位置不能通行的情况下    unless $game_map.passable?(box.x+col, box.y+row, 0)      return    end         # 遍历所有事件    for event in $game_map.events.values        # 首先排除自己      if event.id != box.id        # 1.判断箱子后方是否存在将要触发的事件        if event.x == box.x+col && event.y == box.y+row          # 2.判断是否可以通过          if event.through             break          else                        return          end        end              else          next      end     end     # 如果方法可以执行到这里,说明触发了移动事件        box.moveto(box.x+col, box.y+row)        # 移动之后暂时不清楚是否到达目的,所以将标志位统一设置成false    box.is_arrive = false     # 更新人物位置    case $game_player.direction    when 2      $game_player.move_down    when 4      $game_player.move_left    when 6      $game_player.move_right          when 8      $game_player.move_up          end        # 遍历所有事件,判断移动后的箱子是否到达目的地    for event in $game_map.events.values         # 首先排除自己      if event.id != box.id        # 1.判断箱子所在位置是否存在事件        if event.x == box.x && event.y == box.y            # 2.判断该事件的目的地信息            if event.destination              box.is_arrive = true              break            else              return            end                    end      end      end     # 如果方法可以执行到这里,说明这次移动触发了到达目的地事件        num = 0     # 遍历所有事件,统计到达目的地的箱子数量    for event in $game_map.events.values       if event.is_arrive        num +=1      end    end     # 判断到达目的地的箱子数量和通关所需的数量是否一致        if num != 0 && num == $pass_num       print "通关(打印信息会暂停动画效果,并非BUG.)"    end   end  end
#============================================================================== 
# ■ Interpreter_Box (自定义) 
#------------------------------------------------------------------------------ 
# □ 扩展Interpreter 
#============================================================================== 
class Interpreter 
  #-------------------------------------------------------------------------- 
  # ● 自定义脚本_设定目的地 
  #-------------------------------------------------------------------------- 
  def command_set_destination     
    unless get_character(0).destination 
      get_character(0).destination = true 
      $pass_num += 1 
    end   
  end   
  #-------------------------------------------------------------------------- 
  # ● 自定义脚本_推箱子 
  #-------------------------------------------------------------------------- 
  def command_pushbox  
  
    row = 0 
    col = 0 
  
    # 判断人物朝向 
    case $game_player.direction 
    when 2 
      row += 1 
    when 4 
      col -= 1 
    when 6 
      col += 1 
    when 8 
      row -= 1 
    end     
  
    # 箱子 
    box = get_character(0) 
  
    # 地图上的这个位置不能通行的情况下 
    unless $game_map.passable?(box.x+col, box.y+row, 0) 
      return 
    end     
  
    # 遍历所有事件 
    for event in $game_map.events.values   
      # 首先排除自己 
      if event.id != box.id 
        # 1.判断箱子后方是否存在将要触发的事件 
        if event.x == box.x+col && event.y == box.y+row 
          # 2.判断是否可以通过 
          if event.through  
            break 
          else             
            return 
          end 
        end         
      else 
          next 
      end  
    end 
  
    # 如果方法可以执行到这里,说明触发了移动事件     
    box.moveto(box.x+col, box.y+row)     
    # 移动之后暂时不清楚是否到达目的,所以将标志位统一设置成false 
    box.is_arrive = false 
  
    # 更新人物位置 
    case $game_player.direction 
    when 2 
      $game_player.move_down 
    when 4 
      $game_player.move_left 
    when 6 
      $game_player.move_right       
    when 8 
      $game_player.move_up       
    end    
  
    # 遍历所有事件,判断移动后的箱子是否到达目的地 
    for event in $game_map.events.values    
      # 首先排除自己 
      if event.id != box.id 
        # 1.判断箱子所在位置是否存在事件 
        if event.x == box.x && event.y == box.y 
            # 2.判断该事件的目的地信息 
            if event.destination 
              box.is_arrive = true 
              break 
            else 
              return 
            end             
        end 
      end   
    end 
  
    # 如果方法可以执行到这里,说明这次移动触发了到达目的地事件     
    num = 0  
    # 遍历所有事件,统计到达目的地的箱子数量 
    for event in $game_map.events.values  
      if event.is_arrive 
        num +=1 
      end 
    end 
  
    # 判断到达目的地的箱子数量和通关所需的数量是否一致     
    if num != 0 && num == $pass_num  
      print "通关(打印信息会暂停动画效果,并非BUG.)" 
    end 
  
  end   
end 
 
 最后在 Game_Character 1 中 initialize 方法中调用 initialize_box 方法
 
 在地图编辑时
 1.如果需要设置箱子,
 编辑事件-->选项-->固定朝向
 -->事件开始条件-->与主角接触
 -->执行内如-->插入-->脚本-->command_pushbox
 2.如果需要设置目的地,
 编辑事件-->选项-->允许穿透
 -->事件开始条件-->自动执行
 -->执行内容-->插入-->脚本-->command_set_destination
 -->执行内容-->插入-->操作独立开关-->A:ON
 -->新建事件页-->事件出现条件-->独立开关-->A 为 ON
 
 |