| 
 
| 赞 | 0 |  
| VIP | 0 |  
| 好人卡 | 0 |  
| 积分 | 1 |  
| 经验 | 1851 |  
| 最后登录 | 2014-6-28 |  
| 在线时间 | 75 小时 |  
 Lv1.梦旅人 
	梦石0 星屑50 在线时间75 小时注册时间2013-8-1帖子26 | 
5楼
 
 
 楼主|
发表于 2013-8-8 13:41:32
|
只看该作者 
| gaogs123456 发表于 2013-8-7 18:12 ![]() 跳跃脚本对我来说觉得很好用,能让玩家不用按照地图上画出的‘路’固定式的行走。但也有一些BUG和好笑的问 ...
我改了一些东西,这样大多数BUG都没了 ,可以在房顶上跳。。。也保证了不可以在山上跳下来或者跳上去  还有事件的跳跃改成了判断落地点是否有可跳跃的事件。。。总之感觉真实一点,你试试?顺便问一下如何操作BCDE型的图块ID?nojunp=(113..117).to_b这样写为啥不行。。。新手,见笑了
 复制代码class Game_Map
  #--------------------------------------------------------------------------
  # ● 计算地图元件ID
  #--------------------------------------------------------------------------
  def get_tile_id(x, y)
    a = data[x, y, 0]
    return 0 unless a
    a-=2000
    map_tile_id_0 = (a >= 0) ? a/48 : (a+593)
    map_tile_id_1 = (data[x, y, 1]-2000) / 48
    map_tile_id_2 = (data[x, y, 2])
         
    map_tile_id_0 = 0 if map_tile_id_0 == -42 # A
    map_tile_id_1 = 0 if map_tile_id_1 == -42 # I
    map_tile_id_2 = 0 if map_tile_id_2 == -42 # B~E
    
    # 图块 ID 矫正
    map_tile_id_0 = map_tile_id_1 if map_tile_id_1 > 0
    unless @events.nil?
      for event in @events.values
        if event.pos?(x, y) and event.tile_id > 0
          # 若是事件使用地图元件,使用该地图元件的ID
          map_tile_id_2 = event.tile_id
        end
      end
    end
    # 返回 [底层ID, 上层ID]
    return [map_tile_id_0, map_tile_id_2]
  end
end
class Game_Character < Game_CharacterBase
  #--------------------------------------------------------------------------
  # ● 获取地图元件ID
  #--------------------------------------------------------------------------
  def get_map_tile_id(x, y)
    return $game_map.get_tile_id(x, y)
  end
  #--------------------------------------------------------------------------
  # ● 判断是否能跳跃
  #--------------------------------------------------------------------------
  def can_jump?
    # 面向与方向键不同时不跳跃
    return false if Input.dir4 != @direction 
    return false if debug_through? # 测试行走(按下Ctrl)时不跳跃
    x_f1 = x_f2 = @x
    y_f1 = y_f2 = @y
    
    # 计算前两格座标
    case @direction
    when 2
      y_f2 += 2
      y_f1 += 1
    when 4
      x_f2 -= 2
      x_f1 -= 1
    when 6
      x_f2 += 2
      x_f1 += 1
    when 8
      y_f2 -= 2
      y_f1 -= 1
    end
    #落地判断
    return false if !(map_passable?(x_f2, y_f2, 2)|map_passable?(x_f2, y_f2, 4)|map_passable?(x_f2, y_f2, 6)|map_passable?(x_f2, y_f2, 8))
    
    tile_id_0 = get_map_tile_id(@x, @y)       # 获取当前格元件ID
    tile_id_1 = get_map_tile_id(x_f1, y_f1)   # 获取前一格元件ID
    tile_id_2 = get_map_tile_id(x_f2, y_f2)   # 获取前两格元件ID
    event_1 = $game_map.events_xy(x_f1, y_f1) # 获取前一格事件
    event_2 = $game_map.events_xy(x_f2, y_f2) # 获取前两格事件
    
    return false if $game_map.counter?(x_f1, y_f1) # 前一格为柜台时无法跳跃
    return false if !event_2.empty? # 前两格也有事件则不能跳跃
    # 判断面前一格是否墙壁元件
    # 获取墙壁元件ID
    wall_tile = (57..64).to_a + (73..80).to_a + (89..96).to_a + (105..112).to_a + (121..128).to_a + (241..243).to_a + (246..251).to_a + (254..256).to_a
    # 获取墙顶元件ID
    w_top_tile = (49..56).to_a + (65..72).to_a + (81..88).to_a + (97..104).to_a + (113..120).to_a + (217..240).to_a + (244..245).to_a + (252..253).to_a
    
    return false if wall_tile.include?(tile_id_2[0]) # 前两格为墙壁时无法跳跃
    
    if w_top_tile.include?(tile_id_0[0])
      if w_top_tile.include?(tile_id_2[0])
        return true if !event_1.empty?&&check_event_jumpable?(event_1)
        return true if !map_passable?(@x, @y, @direction)
        return true if !map_passable?(x_f1, y_f1, @direction)
        return true if !map_passable?(x_f1, y_f1, 8)&&@direction==2
      end
      return false
    end
  
    
    return false if w_top_tile.include?(tile_id_1[0])
    return false if wall_tile.include?(tile_id_1[0])
    return false if w_top_tile.include?(tile_id_2[0]) #前两格是墙顶不能跳
    
    if !event_1.empty? # 若前一格有事件
      return false if w_top_tile.include?(tile_id_1[0]) #事件在墙顶不能跳
      return false if !map_passable?(x_f1, y_f1, @direction)
      return check_event_jumpable?(event_1) # 判断是否指定可以跳跃
    end
    
#    njump = (113..117).to_b + (121..125).to_b + (129..132).to_b + (137..140).to_b
    # 前第一格判断
    #if tile_id_1[1]>1 
     # return false # 前一格的B~E层无法通行时也不能跳跃
    # 判断面前两格是否相同
    #return false if tile_id_1 == tile_id_2
    #return false if tile_id_1 == tile_id_0
    #if !map_passable?(x_f1, y_f1, )
    return false if map_passable?(x_f1, y_f1, 4)
      return true
    #end
    
  end
  #--------------------------------------------------------------------------
  # ● 判断某格的事件是否能跳跃
  #--------------------------------------------------------------------------
  def check_event_jumpable?(events)
    events.each{|event|
      return true if event.can_jump?
    }
    return false
  end
  #--------------------------------------------------------------------------
  # ● 执行跳跃
  #--------------------------------------------------------------------------
  def do_jump(d=@direction)
    # 判断跳跃方向
    Audio.se_play("Audio/SE/"+"Jump2",80,100)
    case d
    when 2;  jump(0, 2)  # 向下跳
    when 4;  jump(-2, 0) # 向左跳
    when 6;  jump(2, 0)  # 向右跳
    when 8;  jump(0, -2) # 向上跳
    end
  end
end
class Game_Event < Game_Character
  #--------------------------------------------------------------------------
  # ● 判断事件是否能跳跃
  #--------------------------------------------------------------------------
  def can_jump?
    return false if @list[0].code != 108 # 第一个指令不是“注释”时返回 false
    return @list[0].parameters[0] == "jump"
  end
end
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # ● 输入移动处理
  #--------------------------------------------------------------------------
  alias old_move_by_input move_by_input
  def move_by_input
    # 不能行动时忽略所有动作
    return unless movable?
    # 解释器执行时忽略所有动作
    return if $game_map.interpreter.running?
    d = Input.dir4
    if can_jump?# 能够跳跃时
      if $game_player.followers.visible # 队伍跟随时
        $game_player.followers.gather   # 跟随队伍聚集
        while !$game_player.followers.gather?
          $game_player.followers.update # 跟随队伍刷新
        end
        # 跟随队员跳跃
        $game_player.followers.each{ |follower|
          follower.do_jump(d)
        }
      end
      do_jump(d) # 执行跳跃
    else
      old_move_by_input # 呼叫原有方法
    end
  end
end
 | 
 |