查看: 1900|回复: 0

[已经过期] RM重力系统能不能让事件跳跃

[复制链接]
梦石
0
星屑
841
在线时间
194 小时
注册时间
2014-1-11
回帖
19
发表于 2015-8-3 22:12:49 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 丿梁丶小柒 于 2015-10-4 21:59 编辑
  1. #=============================================================================
  2. #★RMVX重力系统★
  3. #-----------------------------------------------------------------------------
  4. #★作者: Zhong_zw
  5. #★联系方式: 66rpg.com论坛短信 或 [email]zhong8890@126.com[/email] 或 [email]zhong317@126.com[/email]
  6. #★游戏中引用本脚本,请保留以上信息,并作相关说明.
  7. #☆如若转载本脚本请联系本人☆
  8. #==============================================================================
  9. #==============================================================================
  10. # ★ Game_Character
  11. #------------------------------------------------------------------------------
  12. #  涉及角色的类。本类作为 Game_Player 类与 Game_Event 的超级类
  13. # 使用。
  14. #==============================================================================

  15. #==============================================================================
  16. #★参数设置
  17. #==============================================================================
  18. #跳跃初速度
  19. JUMP_SPEED = 150

  20. #重力加速度
  21. GRAVITATIONAL = 9

  22. #连跳次数
  23. JUME_SERIES = 2

  24. #连跳速度衰减
  25. JUMP_SERIES_WEAKEN = 30

  26. #跳跃键
  27. JUMP_KEY = Input::C #默认为键盘A键

  28. #弹跳时的行走图 (格式为:[名称,index])
  29. JUMP_CHARACTER = nil

  30. #弹跳时的声音 (注:声音文件放在SE文件夹下)
  31. JUMP_SE = "Jump1.ogg"

  32. #掉出屏幕时打开的开关(用于调用相关公共事件)
  33. DEAD_SWITCHES_ID = 50

  34. #各地图交通工具的摆放位置
  35. MAP_VEHICLE = {1=>[[2,1],[3,1],[4,1],[5,1],[8,2],[6,2],[7,2,1]]}


  36. #各地图可以飞的事件
  37. MAP_FLY_EVENT = {1=>[10]}

  38. #默认地图模式 0为正常模式 1为重力模式
  39. DEFAULT_MAP_MODE = 0


  40. #==============================================================================

  41. class Game_Character
  42.   #--------------------------------------------------------------------------
  43.   # ● 定义实例变量
  44.   #--------------------------------------------------------------------------
  45.   attr_reader   :id                       # ID
  46.   #===============================================================
  47.   attr_accessor :x                        # 地图 X 坐标 (理论坐标)
  48.   attr_accessor :y                        # 地图 Y 坐标 (理论坐标)
  49.   attr_accessor :real_x                   # 地图 X 坐标 (实际坐标 * 256)
  50.   attr_accessor :real_y                   # 地图 Y 坐标 (实际坐标 * 256)
  51.   attr_accessor :move_speed               #角色移动速度
  52.   attr_accessor :jump_series              #连跳次数
  53.   attr_accessor :gravitational            #重力加速度
  54.   attr_accessor :vertical_speed           #垂直速度
  55.   attr_accessor :can_fly                  #飞行开关  
  56.   attr_accessor :jump_speed               #跳跃初速度
  57.   attr_accessor :on_ladder                #是否在梯子上
  58.   attr_accessor :map_vehicle              #地图交通工具 0 无 1 为梯子 2 为踏板
  59.   attr_accessor :pedal_type               #踏板类型
  60.   attr_accessor :on_pedal                 #是否在踏板
  61.   attr_accessor :jump_character           #弹跳时的行走图
  62.   #=====================================================
  63.   #==========================================================================
  64.   # ★ 初始化对象
  65.   #==========================================================================
  66.   def initialize
  67.     @id = 0
  68.     @x = 0
  69.     @y = 0
  70.     @real_x = 0
  71.     @real_y = 0
  72.     @tile_id = 0
  73.     @character_name = ""
  74.     @character_index = 0
  75.     @opacity = 255
  76.     @blend_type = 0
  77.     @direction = 2
  78.     @pattern = 1
  79.     @move_route_forcing = false
  80.     @priority_type = 1
  81.     @through = false
  82.     @bush_depth = 0
  83.     @animation_id = 0
  84.     @balloon_id = 0
  85.     @transparent = false
  86.     @original_direction = 2               # 原朝向
  87.     @original_pattern = 1                 # 原图案
  88.     @move_type = 0                        # 移动类型
  89.     @move_speed = 4                       # 移动速度
  90.     @move_frequency = 6                   # 移动频度
  91.     @move_route = nil                     # 移动路径
  92.     @move_route_index = 0                 # 移动路径执行位置
  93.     @original_move_route = nil            # 原移动路径
  94.     @original_move_route_index = 0        # 原移动路径执行位置
  95.     @walk_anime = true                    # 步行动画
  96.     @step_anime = false                   # 踏步动画
  97.     @direction_fix = false                # 朝向固定
  98.     @anime_count = 0                      # 动画计数
  99.     @stop_count = 0                       # 停止计数
  100.     @jump_count = 0                       # 跳跃计数
  101.     @jump_peak = 0                        # 跳跃顶点计数
  102.     @wait_count = 0                       # 等待计数
  103.     @locked = false                       # 锁定标志
  104.     @prelock_direction = 0                # 锁定前的朝向
  105.     @move_failed = false                  # 移动失败标志
  106.    
  107.    
  108.    
  109.     #===========================================================
  110.     @jump_speed = JUMP_SPEED  #跳跃速度
  111.    
  112.     #@jump_height = JUMP_HEIGHT
  113.    
  114.     @jump_series = 0                #连跳次数累计
  115.    
  116.     @jump_max_series = JUME_SERIES  #最大连跳次数
  117.    
  118.     @can_fly = false
  119.    
  120.    
  121.    
  122.    
  123.     #计算重力加速度
  124.     [url=home.php?mod=space&uid=282336]@gravitational[/url] = GRAVITATIONAL
  125.    
  126.     #垂直速度为0
  127.     @vertical_speed  = 0
  128.    
  129.     #初始速度
  130.     @init_Vspeed = 0
  131.    
  132.     #着陆
  133.     @is_land = true
  134.    
  135.     #不需要继续下落的开关
  136.     @no_need_fall = false
  137.    
  138.    
  139.     #是否可以坠入悬崖
  140.     @can_falldown_screen = true
  141.    
  142.     #交通工具性质
  143.     @map_vehicle = 0            #地图交通工具 0 无  1为梯子 2 为踏板
  144.    
  145.    
  146.     #是否在梯子上
  147.     @on_ladder = false
  148.    
  149.     #踏板类型
  150.     @pedal_type = 0              # 0 为推进型踏板 1 为即落型踏板
  151.    
  152.     #是否在踏板
  153.     @on_pedal = false
  154.    
  155.     #弹跳时的行走图
  156.     @jump_character = nil
  157.    
  158.     #跳前行走图
  159.     @last_character = nil
  160.    
  161.     #乘客(踏板的情况下)
  162.     @passengers = nil

  163.     #===========================================================
  164.    
  165.   end
  166.   
  167.   #==========================================================================
  168.   #★ 设置跳跃初速度
  169.   #==========================================================================
  170.   def set_jump_speed(speed)
  171.      @jump_speed = speed
  172.   end #def
  173.   
  174.   #==========================================================================
  175.   
  176.   #--------------------------------------------------------------------------
  177.   # ★ 判断是否在跳跃
  178.   #--------------------------------------------------------------------------
  179.   def jumping?
  180.     if $game_map.scene_mode == 0
  181.       return @jump_count > 0
  182.     else
  183.       return false  #废弃跳跃判定.主判定已放进update_falling里
  184.     end #if  
  185.   end

  186.   #==========================================================================
  187.   # ★ 判断角色冲突
  188.   #     x : X 坐标
  189.   #     y : Y 坐标
  190.   #    包含玩家和交通工具、检测普通角色的冲突。
  191.   #==========================================================================
  192.   def collide_with_characters?(x, y)
  193.     for event in $game_map.events_xy(x, y)          # 与事件坐标一致
  194.       if($game_map.scene_mode == 1 && event.map_vehicle == 1)
  195.         return false
  196.       end  
  197.       unless event.through                          # 穿越 OFF?
  198.         return true if self.is_a?(Game_Event)       # 自己是事件
  199.         return true if event.priority_type == 1     # 对方是普通角色
  200.       end
  201.       
  202.     end
  203.     if @priority_type == 1                          # 自己是普通角色
  204.       return true if $game_player.pos_nt?(x, y)     # 与玩家的坐标一致
  205.       return true if $game_map.boat.pos_nt?(x, y)   # 与小型船坐标一致
  206.       return true if $game_map.ship.pos_nt?(x, y)   # 与大型船坐标一致
  207.     end
  208.     return false
  209.   end
  210.   #==========================================================================
  211.   # ★ 获取画面 Y 坐标
  212.   #==========================================================================
  213.   def screen_y
  214.     y = ($game_map.adjust_y(@real_y) + 8007) / 8 - 1000 + 32
  215.     #================================================
  216.     y -= 4 unless object? || $game_map.scene_mode == 1
  217.     #================================================
  218.     if $game_map.scene_mode == 0
  219.      if @jump_count >= @jump_peak
  220.        n = @jump_count - @jump_peak
  221.      else
  222.        n = @jump_peak - @jump_count
  223.      end
  224.      return y - (@jump_peak * @jump_peak - n * n) / 2
  225.    else
  226.      return y
  227.    end #if  
  228.   end
  229.   #==========================================================================
  230.   # ★ 刷新画面
  231.   #==========================================================================
  232.   def update
  233.    
  234.     if $game_map.scene_mode == 1
  235.      if falling?
  236.        update_falling
  237.      else
  238.       
  239.       #如果本身是踏板的话检查上面有没乘客
  240.       check_passenger
  241.       
  242.       if @real_y < @y*256 && !@on_ladder && !@can_fly && !on_pedal
  243.         free_fall
  244.         #update_horizontal_fly
  245.       else
  246.         if !@on_ladder && !@can_fly && !@on_pedal  #不在梯子上
  247.          @real_y = @y*256  #修正
  248.         end
  249.         @vertical_speed = 0
  250.         @init_Vspeed = 0
  251.         @jump_count = 0
  252.         if moving?
  253.           update_move
  254.         else                        # 正在停止
  255.           update_stop
  256.         end
  257.         if @wait_count > 0          # 正在等待
  258.           @wait_count -= 1
  259.         elsif @move_route_forcing   # 强制移动路径
  260.           move_type_custom
  261.         elsif not @locked           # 被锁定以外
  262.           update_self_movement
  263.          end
  264.          update_animation
  265.       
  266.        end
  267.       
  268.      end
  269.       
  270.     else
  271.      if jumping?                 # 正在跳跃
  272.       update_jump
  273.      elsif moving?               # 正在移动
  274.       update_move
  275.      else                        # 正在停止
  276.       update_stop
  277.      end
  278.      if @wait_count > 0          # 正在等待
  279.       @wait_count -= 1
  280.      elsif @move_route_forcing   # 强制移动路径
  281.       move_type_custom
  282.      elsif not @locked           # 被锁定以外
  283.       update_self_movement
  284.      end
  285.      update_animation
  286.     end #if
  287.   end
  288.   #==========================================================================
  289.   #★判断是否会下落
  290.   #==========================================================================
  291.   def falling?
  292.    
  293.     if @jump_series > 0 && !@on_ladder && @jump_character != nil
  294.       if @last_character == nil || @character_name != @jump_character[0]
  295.         @last_character = [@character_name,@character_index]
  296.       end  
  297.       set_graphic(@jump_character[0],@jump_character[1])
  298.     elsif @last_character != nil  && @last_character[0] != @character_name
  299.      set_graphic(@last_character[0],@last_character[1])
  300.     end
  301.    
  302.      if @can_fly  || @no_need_fall || @map_vehicle >= 1
  303.        return false
  304.      end
  305.      
  306.      have_ladder = false
  307.      for event in $game_map.events_xy(@x, @y)          # 与事件坐标一致
  308.        if event.map_vehicle == 1
  309.          have_ladder = true
  310.          @on_ladder = true
  311.          @is_land = true
  312.         end  
  313.      end
  314.      
  315.      if !have_ladder  
  316.        @on_ladder = false if @on_ladder
  317.      else
  318.        return false
  319.      end  
  320.       
  321.      
  322.      
  323.      dir =  @vertical_speed >= 0  ? 1 : -1
  324.      if @jump_count < 0 && @init_Vspeed < 0
  325.        dir = -1
  326.      end  
  327.      
  328.      x = @x
  329.      
  330.      if @x*256-@real_x > 0 #向右
  331.       x = (@real_x*1.0/256).floor
  332.      elsif @x*256-@real_x < 0
  333.       x = (@real_x*1.0/256).ceil
  334.      end
  335.      
  336.      result = passable?(x, @y+dir) && passable?(@x, @y+dir)
  337.      
  338.      if ((@y+dir) >= $game_map.height || @real_y/256 > $game_map.height) && @can_falldown_screen
  339.         @y = ($game_map.height+1)
  340.         @no_need_fall = true
  341.         if self.is_a?(Game_Player)
  342.           $game_switches[DEAD_SWITCHES_ID] = true
  343.         end #
  344.         
  345.      elsif (@y+dir) <= 0
  346.         result = true   
  347.      end  
  348.      

  349.       
  350.      if @on_pedal&&result
  351.        @on_pedal = false
  352.      end
  353.      
  354.      last_state = @is_land
  355.      @is_land = !result && dir == 1
  356.      
  357.       #判断上顶或着陆事件
  358.      if !result  && (self.is_a?(Game_Player) || self.is_a?(Game_Event))
  359.        dir = -1 if @vertical_speed < 0
  360.        check_event_trigger_touch(@x,@y+dir)
  361.      end
  362.      
  363.      
  364.      
  365.      return result
  366.    
  367.   end  
  368.   
  369.   #==========================================================================
  370.   #★ 下落的更新
  371.   #==========================================================================
  372.   def update_falling
  373.      last_y = @real_y
  374.      y = (last_y/256).ceil
  375.      free_fall
  376.      dir =  @vertical_speed >= 0 ? 1 : -1
  377.      d =  (dir*@vertical_speed*1.00/256).ceil.abs
  378.      lst_i = 0
  379.       
  380.    
  381.      for i in 0..d
  382.       
  383.        if !passable?(@x, y+i*dir)
  384.          
  385.          break
  386.       
  387.        end #if
  388.       
  389.        lst_i = i
  390.       
  391.      end #for
  392.      
  393.      if  i > 0
  394.       @y = y+lst_i*dir
  395.       if !passable?(@x, @y+dir) && @y +dir > 0
  396.         @real_y = @y*256
  397.         #@vertical_speed = 0
  398.         @init_Vspeed = 0
  399.         @jump_count = 0
  400.       end
  401.      end

  402.      
  403.      update_horizontal_fly
  404.      

  405.   end
  406.   #==========================================================================
  407.   #★自由落体运动
  408.   #==========================================================================
  409.   def free_fall
  410.     @jump_count += 1
  411.     @vertical_speed = @init_Vspeed + @gravitational*@jump_count
  412.     @real_y = @real_y + @vertical_speed
  413.   end
  414.   
  415.   #=========================================================================
  416.   #★空中横向移动
  417.   #=========================================================================
  418.   def update_horizontal_fly
  419.     distance = 2 ** @move_speed*2   # 变换移动速度与移动距离
  420.     distance += 5 if dash?        # 跑步状态时移动速度加倍
  421.    
  422.     @real_x = [@real_x - distance, @x * 256].max if @x * 256 < @real_x
  423.     @real_x = [@real_x + distance, @x * 256].min if @x * 256 > @real_x
  424.   end
  425.   #=========================================================================
  426.   #★ 检查乘客(踏板专用)
  427.   #=========================================================================
  428.   def check_passenger
  429.       return if @map_vehicle != 2 || $game_map.scene_mode != 1
  430.       if @passengers == nil
  431.         @passengers = []
  432.       end  
  433.       if @passengers.size > 0
  434.         @passengers.clear
  435.       end
  436.       for event in $game_map.events_xy(@x, @y-1)
  437.         if  @pedal_type == 1 #即落型
  438.           @map_vehicle = 0    #设为普通角色(重力下自动掉落)
  439.           return
  440.         else
  441.            @passengers.push(event)
  442.         end  
  443.       end   
  444.       if $game_player.x == @x && $game_player.y == @y-1
  445.         if  @pedal_type == 1 #即落型
  446.           @map_vehicle = 0    #设为普通角色(重力下自动掉落)
  447.           return
  448.         else
  449.            @passengers.push($game_player)
  450.         end  
  451.         
  452.       end  
  453.      
  454.   end
  455.   #==========================================================================
  456.   #--------------------------------------------------------------------------
  457.   # ★ 跳跃时的更新
  458.   #--------------------------------------------------------------------------
  459.   def update_jump
  460.    
  461.     if $game_map.scene_mode == 0
  462.       @jump_count -= 1
  463.       @real_x = (@real_x * @jump_count + @x * 256) / (@jump_count + 1)
  464.       @real_y = (@real_y * @jump_count + @y * 256) / (@jump_count + 1)
  465.       update_bush_depth
  466.      end #if
  467.   end

  468.    
  469.   #--------------------------------------------------------------------------
  470.   # ★ 向下移动
  471.   #     turn_ok : 此地可以更改朝向
  472.   #--------------------------------------------------------------------------
  473.   def move_down(turn_ok = true)
  474.                  
  475.       if $game_map.scene_mode == 1
  476.         @on_ladder =true
  477.       end
  478.       
  479.       if passable?(@x, @y+1)                               # 可以通过
  480.        if $game_map.scene_mode == 0                        #正常模式下
  481.          turn_down
  482.        elsif $game_map.scene_mode == 1                     #重力模式
  483.          turn_up if !@can_fly                              #设置爬梯时的朝向
  484.          #是否踏板,是否有乘客
  485.          if @map_vehicle == 2 && @passengers != nil && @passengers.size > 0        
  486.             for event in @passengers
  487.                event.y = @y
  488.                event.on_pedal = true
  489.             end  
  490.          end  
  491.        end  
  492.         @y = $game_map.round_y(@y+1)
  493.         @real_y = (@y-1)*256
  494.         increase_steps
  495.         @move_failed = false
  496.       
  497.       else                                     # 不可以通过
  498.         turn_down if turn_ok
  499.         check_event_trigger_touch(@x, @y+1)    # 判断接触的事件启动
  500.         @move_failed = true
  501.       end
  502.       
  503.     #end #if
  504.   end
  505.   #--------------------------------------------------------------------------
  506.   # ★ 向左移动
  507.   #     turn_ok : 此地可以更改朝向
  508.   #--------------------------------------------------------------------------
  509.   def move_left(turn_ok = true)
  510.     if passable?(@x-1, @y)                  # 可以通过
  511.       turn_left
  512.       if $game_map.scene_mode == 1
  513.         if @map_vehicle == 2 && @passengers != nil && @passengers.size > 0        
  514.             for event in @passengers
  515.                event.x = $game_map.round_x(@x-1)
  516.                event.on_pedal = true
  517.             end  
  518.         end
  519.       end  
  520.       @x = $game_map.round_x(@x-1)
  521.       @real_x = (@x+1)*256
  522.       increase_steps
  523.       @move_failed = false
  524.     else                                    # 不可以通过
  525.       turn_left if turn_ok
  526.       check_event_trigger_touch(@x-1, @y)   # 判断接触的事件启动
  527.       @move_failed = true
  528.     end
  529.   end
  530.   #--------------------------------------------------------------------------
  531.   # ★ 向右移动
  532.   #     turn_ok : 此地可以更改朝向
  533.   #--------------------------------------------------------------------------
  534.   def move_right(turn_ok = true)
  535.     if passable?(@x+1, @y)                  # 可以通过
  536.       turn_right
  537.       if $game_map.scene_mode == 1
  538.         if @map_vehicle == 2 && @passengers != nil && @passengers.size > 0        
  539.             for event in @passengers
  540.                event.x = $game_map.round_x(@x+1)
  541.                event.on_pedal = true
  542.             end #for

  543.         end
  544.       end  
  545.       @x = $game_map.round_x(@x+1)
  546.       @real_x = (@x-1)*256
  547.       increase_steps
  548.       @move_failed = false
  549.     else                                    # 不可以通过
  550.       turn_right if turn_ok
  551.       check_event_trigger_touch(@x+1, @y)   # 判断接触的事件启动
  552.       @move_failed = true
  553.     end
  554.   end
  555.   #--------------------------------------------------------------------------
  556.   # ★ 向上移动
  557.   #     turn_ok : 此地可以更改朝向
  558.   #--------------------------------------------------------------------------
  559.   def move_up(turn_ok = true)
  560.    if $game_map.scene_mode == 0 || ($game_map.scene_mode == 1 && (@on_ladder || @can_fly || @map_vehicle == 2))
  561.      pedal_passable = false
  562.      if @map_vehicle == 2 && $game_map.scene_mode == 1 && @passengers != nil && @passengers.size > 0
  563.            for event in @passengers
  564.              if (event.passable?(@x,@y-2))
  565.                pedal_passable = true
  566.                event.y = $game_map.round_y(@y-2)
  567.                event.on_pedal = true
  568.              end #if  
  569.            end#for  
  570.      end     
  571.      if passable?(@x, @y-1) || pedal_passable      # 可以通过
  572.        turn_up
  573.        @y = $game_map.round_y(@y-1)
  574.        @real_y = (@y+1)*256
  575.        increase_steps
  576.        @move_failed = false
  577.      else                                    # 不可以通过
  578.        turn_up if turn_ok
  579.        check_event_trigger_touch(@x, @y-1)   # 判断接触的事件启动
  580.        @move_failed = true
  581.      end
  582.       
  583.    end #if
  584.   end
  585.   #--------------------------------------------------------------------------
  586.   # ★ 向左下移动(为了不引起不必要的bug,把重力模式暂时没用到的屏蔽了)
  587.   #--------------------------------------------------------------------------
  588.   def move_lower_left
  589.    if $game_map.scene_mode == 0  
  590.     unless @direction_fix
  591.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  592.     end
  593.     if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
  594.        (passable?(@x-1, @y) and passable?(@x-1, @y+1))
  595.       @x -= 1
  596.       @y += 1
  597.       increase_steps
  598.       @move_failed = false
  599.     else
  600.       @move_failed = true
  601.     end
  602.    end
  603.   end
  604.   #--------------------------------------------------------------------------
  605.   # ★ 向右下移动
  606.   #--------------------------------------------------------------------------
  607.   def move_lower_right
  608.     if $game_map.scene_mode == 0
  609.      unless @direction_fix
  610.        @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  611.      end
  612.      if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
  613.         (passable?(@x+1, @y) and passable?(@x+1, @y+1))
  614.        @x += 1
  615.        @y += 1
  616.        increase_steps
  617.        @move_failed = false
  618.      else
  619.        @move_failed = true
  620.      end
  621.     end #if  
  622.   end
  623.   #--------------------------------------------------------------------------
  624.   # ★ 向左上移动
  625.   #--------------------------------------------------------------------------
  626.   def move_upper_left
  627.     if $game_map.scene_mode == 0
  628.      unless @direction_fix
  629.        @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  630.      end
  631.      if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
  632.         (passable?(@x-1, @y) and passable?(@x-1, @y-1))
  633.        @x -= 1
  634.        @y -= 1
  635.        increase_steps
  636.        @move_failed = false
  637.      else
  638.        @move_failed = true
  639.      end
  640.     end #if  
  641.   end
  642.   #--------------------------------------------------------------------------
  643.   # ★ 向右上移动
  644.   #--------------------------------------------------------------------------
  645.   def move_upper_right
  646.     if $game_map.scene_mode == 0
  647.      unless @direction_fix
  648.        @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  649.      end
  650.      if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
  651.         (passable?(@x+1, @y) and passable?(@x+1, @y-1))
  652.        @x += 1
  653.        @y -= 1
  654.        increase_steps
  655.        @move_failed = false
  656.      else
  657.        @move_failed = true
  658.      end
  659.     end #if
  660.   end
  661.   #==========================================================================
  662.   #★以下这几个是默认的,但是留着方便以后进一步扩展
  663.   #==========================================================================
  664.   #--------------------------------------------------------------------------
  665.   # ★ 随机移动
  666.   #--------------------------------------------------------------------------
  667.   def move_random
  668.     case rand(4)
  669.     when 0;  move_down(false)
  670.     when 1;  move_left(false)
  671.     when 2;  move_right(false)
  672.     when 3;  move_up(false)
  673.     end
  674.   end
  675.   #--------------------------------------------------------------------------
  676.   # ★ 接近玩家
  677.   #--------------------------------------------------------------------------
  678.   def move_toward_player
  679.     sx = distance_x_from_player
  680.     sy = distance_y_from_player
  681.     if sx != 0 or sy != 0
  682.       if sx.abs > sy.abs                  # 如果横向距离长
  683.         sx > 0 ? move_left : move_right   # 左右方向优先
  684.         if @move_failed and sy != 0
  685.           sy > 0 ? move_up : move_down
  686.         end
  687.       else                                # 如果纵向距离等长
  688.         sy > 0 ? move_up : move_down      # 上下方向优先
  689.         if @move_failed and sx != 0
  690.           sx > 0 ? move_left : move_right
  691.         end
  692.       end
  693.     end
  694.   end
  695.   #--------------------------------------------------------------------------
  696.   # ★ 远离玩家
  697.   #--------------------------------------------------------------------------
  698.   def move_away_from_player
  699.     sx = distance_x_from_player
  700.     sy = distance_y_from_player
  701.     if sx != 0 or sy != 0
  702.       if sx.abs > sy.abs                  # 如果横向距离长
  703.         sx > 0 ? move_right : move_left   # 左右方向优先
  704.         if @move_failed and sy != 0
  705.           sy > 0 ? move_down : move_up
  706.         end #if
  707.       else                                # 如果纵向距离等长
  708.         sy > 0 ? move_down : move_up      # 上下方向优先
  709.         if @move_failed and sx != 0
  710.           sx > 0 ? move_right : move_left
  711.         end #if
  712.       end #if
  713.     end #if
  714.   end
  715.   #--------------------------------------------------------------------------
  716.   # ★ 前进一步
  717.   #--------------------------------------------------------------------------
  718.   def move_forward
  719.     case @direction
  720.     when 2;  move_down(false)
  721.     when 4;  move_left(false)
  722.     when 6;  move_right(false)
  723.     when 8;  move_up(false)
  724.     end
  725.   end
  726.   #--------------------------------------------------------------------------
  727.   # ★ 后退一步
  728.   #--------------------------------------------------------------------------
  729.   def move_backward
  730.     last_direction_fix = @direction_fix
  731.     @direction_fix = true
  732.     case @direction
  733.     when 2;  move_up(false)
  734.     when 4;  move_right(false)
  735.     when 6;  move_left(false)
  736.     when 8;  move_down(false)
  737.     end
  738.     @direction_fix = last_direction_fix
  739.   end
  740.   #==========================================================================
  741.   #★以上这几个是默认的,但是留着方便以后进一步扩展
  742.   #==========================================================================
  743.   
  744.   #--------------------------------------------------------------------------
  745.   # ★ 跳跃(重力模式该函数被屏蔽)
  746.   #     x_plus : X 坐标增加值
  747.   #     y_plus : Y 坐标增加值
  748.   #--------------------------------------------------------------------------
  749.   def jump(x_plus, y_plus)
  750.     if $game_map.scene_mode == 0
  751.       if x_plus.abs > y_plus.abs            # 横向距离长
  752.        x_plus < 0 ? turn_left : turn_right
  753.       elsif x_plus.abs > y_plus.abs         # 纵向距离长
  754.        y_plus < 0 ? turn_up : turn_down
  755.       end
  756.       @x += x_plus
  757.       @y += y_plus
  758.       distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  759.       @jump_peak = 10 + distance - @move_speed
  760.       @jump_count = @jump_peak * 2
  761.       @stop_count = 0
  762.       straighten
  763.     end #if
  764.   end
  765.   
  766.   
  767. end # class

  768. #==============================================================================
  769. # ★ Game_Map
  770. #------------------------------------------------------------------------------
  771. #  处理地图的类。包含卷动以及可以通行的判断功能。
  772. # 本类的实例请参考 $game_map 。
  773. #==============================================================================

  774. class Game_Map
  775.   
  776.   attr_accessor :scene_mode  #地图模式
  777.   attr_accessor :events      # 事件
  778.   #--------------------------------------------------------------------------
  779.   # ● 初始化对象
  780.   #--------------------------------------------------------------------------
  781.   def initialize
  782.     @screen = Game_Screen.new
  783.     @interpreter = Game_Interpreter.new(0, true)
  784.     @map_id = 0
  785.     @display_x = 0
  786.     @display_y = 0
  787.     @scene_mode = DEFAULT_MAP_MODE #0为正常模式 1为重力模式
  788.     create_vehicles
  789.   end
  790.   #--------------------------------------------------------------------------
  791.   # ● 设置事件
  792.   #--------------------------------------------------------------------------
  793.   def setup_events
  794.     @events = {}          # 地图事件
  795.     for i in @map.events.keys
  796.       @events[i] = Game_Event.new(@map_id, @map.events[i])
  797.     end
  798.     @common_events = {}   # 公共事件
  799.     for i in 1...$data_common_events.size
  800.       @common_events[i] = Game_CommonEvent.new(i)
  801.     end
  802.     if @scene_mode == 1
  803.      if  MAP_VEHICLE != nil && MAP_VEHICLE.include?(@map_id)
  804.        for v in MAP_VEHICLE[@map_id]
  805.          @events[v[0]].map_vehicle = v[1]
  806.          if  v[1] == 2
  807.           #如果是踏板且有设定其类型的情况下 设置其踏板类型
  808.           @events[v[0]].pedal_type = v[2] if v.size > 2
  809.           #设置踏板移动速度与角色速度相同,解决踏板与角色脱节的bug.但仍有缺陷,鉴于RM本身地图设计的局限性,忍了!
  810.           @events[v[0]].move_speed = $game_player.move_speed
  811.          end#if
  812.         end #for  
  813.     end
  814.     if MAP_FLY_EVENT != nil && MAP_FLY_EVENT.include?(@map_id)
  815.        for v in MAP_FLY_EVENT[@map_id]
  816.          @events[v].can_fly = true
  817.        end #for
  818.      end  
  819.     end #if  
  820.   end
  821.   
  822.   #=========================================================================
  823.   # ★ 判断是否可以通行
  824.   #     x    : X 坐标
  825.   #     y    : Y 坐标
  826.   #     flag : 不能通行的点 (一般情况下为 0x01、可以在交通工具的情况下被更改)
  827.   #=========================================================================
  828.   def passable?(x, y, flag = 0x01)
  829.     for event in events_xy(x, y)            # 调用坐标一致的事件
  830.       next if event.tile_id == 0            # 没有元件图片
  831.       next if event.priority_type > 0       # 不是"在普通角色下"
  832.       next if event.through                 # 直接通过状态
  833.       pass = @passages[event.tile_id]       # 获取通行属性
  834.       next if pass & 0x10 == 0x10           # [☆] : 不受通行影响
  835.       return true if pass & flag == 0x00    # [○] : 可以通行
  836.       #=========================================================================
  837.       if($game_map.scene_mode == 1 && $game_player.on_ladder && event.map_vehicle == 1)
  838.         return true
  839.       end  
  840.       #=========================================================================
  841.       return false if pass & flag == flag   # [×] : 不可以通行
  842.     end
  843.     for i in [2, 1, 0]                      # 调用图层顺序
  844.       tile_id = @map.data[x, y, i]          # 获取元件 ID
  845.       return false if tile_id == nil        # 获取元件 ID 失败 : 不可以通行
  846.       pass = @passages[tile_id]             # 获取通行属性
  847.       next if pass & 0x10 == 0x10           # [☆] : 不受通行影响
  848.       return true if pass & flag == 0x00    # [○] : 可以通行
  849.       return false if pass & flag == flag   # [×] : 不可以通行
  850.     end
  851.     return false                            # 不可以通行
  852.   end
  853.   
  854. end #class

  855. #==============================================================================
  856. # ★ Game_Player
  857. #------------------------------------------------------------------------------
  858. #  处理主角的类。事件启动的判定、以及地图的滚动等功能。
  859. # 本类的实例请参考 $game_player。
  860. #==============================================================================

  861. class Game_Player < Game_Character

  862.   #--------------------------------------------------------------------------
  863.   # ★ 初始化对象
  864.   #--------------------------------------------------------------------------
  865.   def initialize
  866.     super
  867.     @vehicle_type = -1
  868.     @vehicle_getting_on = false     # 乘座动作中标志
  869.     @vehicle_getting_off = false    # 降下动作中标志
  870.     @transferring = false           # 场所移动标志
  871.     @new_map_id = 0                 # 移动目标地图 ID
  872.     @new_x = 0                      # 移动目标 X 坐标
  873.     @new_y = 0                      # 移动目标 Y 坐标
  874.     @new_direction = 0              # 移动后朝向
  875.     @walking_bgm = nil              # 记忆步行时的 BGM 用
  876.    
  877.     #=====================================================
  878.     @keypress_period = 0
  879.     @jump_character = JUMP_CHARACTER
  880.     #=====================================================
  881.    
  882.   end
  883.   #==========================================================================
  884.   #★ 刷新输入
  885.   #==========================================================================
  886.   def update_input
  887.     return if $game_map.interpreter.running?
  888.     if @is_land
  889.        @jump_series = 0
  890.     end
  891.     #按下跳跃键时
  892.     if Input.press?(JUMP_KEY)
  893.       if @jump_series < @jump_max_series && @keypress_period == 0 && (@is_land || @jump_series > 0) && @y <= $game_map.height
  894.          @init_Vspeed  = - @jump_speed  + JUMP_SERIES_WEAKEN*@jump_series
  895.          @jump_count = -1
  896.          @jump_series += 1
  897.          if  JUMP_SE != nil && JUMP_SE != ""
  898.           Audio.se_play("Audio/SE/"+JUMP_SE,100,100)
  899.          end
  900.       end
  901.       @keypress_period += 1
  902.      
  903.     else
  904.       if @keypress_period > 0
  905.        @keypress_period = 0
  906.        @init_Vspeed = 0
  907.        @jump_count = -1
  908.       end
  909.     end  
  910.    
  911.     case Input.dir4
  912.       #向下
  913.       when 2;
  914.         move_down if movable?
  915.       #向左
  916.       when 4;
  917.         
  918.         move_left if movable? || (!@is_land && flyable?)
  919.    
  920.       #向右  
  921.       when 6;
  922.       
  923.         move_right if  movable? || (!@is_land && flyable?)
  924.         
  925.         
  926.       #向上  
  927.       when 8;
  928.          move_up if  movable?
  929.         
  930.     end #case
  931.    
  932.   end
  933.   #==========================================================================
  934.   #★ 判断是否可以滑翔
  935.   #==========================================================================
  936.   def flyable?
  937.     return !(@real_x != @x * 256)
  938.    
  939.   end  
  940.   #==========================================================================
  941.   #★ 角色调入悬崖后重生(重新初始化相关重力数据)
  942.   #==========================================================================
  943.   def reborn
  944.     @no_need_fall = false
  945.   end  
  946.   #==========================================================================

  947.   #--------------------------------------------------------------------------
  948.   # ★ 刷新画面
  949.   #--------------------------------------------------------------------------
  950.   def update
  951.     last_real_x = @real_x
  952.     last_real_y = @real_y
  953.     last_moving = moving?
  954.     if $game_map.scene_mode == 1 #重力模式
  955.      update_input
  956.     else  
  957.      move_by_input
  958.     end
  959.     super
  960.     update_scroll(last_real_x, last_real_y)
  961.     update_vehicle
  962.     update_nonmoving(last_moving)
  963.   end

  964.   #==========================================================================
  965.   #★以下这几个是默认的,但是留着方便以后进一步扩展
  966.   #==========================================================================

  967.   #--------------------------------------------------------------------------
  968.   # ● 乘降交通工具
  969.   #--------------------------------------------------------------------------
  970.   def get_on_off_vehicle
  971.     return false unless movable?
  972.     if in_vehicle?
  973.       return get_off_vehicle
  974.     else
  975.       return get_on_vehicle
  976.     end
  977.   end
  978.   #--------------------------------------------------------------------------
  979.   # ● 乘座交通工具
  980.   #    前提是当前没有乘座交通工具。
  981.   #--------------------------------------------------------------------------
  982.   def get_on_vehicle
  983.     front_x = $game_map.x_with_direction(@x, @direction)
  984.     front_y = $game_map.y_with_direction(@y, @direction)
  985.     if $game_map.airship.pos?(@x, @y)             # 与飞行船重合了吗?
  986.       get_on_airship
  987.       return true
  988.     elsif $game_map.ship.pos?(front_x, front_y)   # 正面有大型船?
  989.       get_on_ship
  990.       return true
  991.     elsif $game_map.boat.pos?(front_x, front_y)   # 正面有小型船?
  992.       get_on_boat
  993.       return true
  994.     end
  995.     return false
  996.   end
  997.   #--------------------------------------------------------------------------
  998.   # ● 乘座小型船
  999.   #--------------------------------------------------------------------------
  1000.   def get_on_boat
  1001.     @vehicle_getting_on = true        # 乘座中标志
  1002.     @vehicle_type = 0                 # 设置交通工具类型
  1003.     force_move_forward                # 前进一步
  1004.     @walking_bgm = RPG::BGM::last     # 记忆步行时 BGM 用
  1005.     $game_map.boat.get_on             # 乘座处理
  1006.   end
  1007.   #--------------------------------------------------------------------------
  1008.   # ● 乘座大型船
  1009.   #--------------------------------------------------------------------------
  1010.   def get_on_ship
  1011.     @vehicle_getting_on = true        # 乘座
  1012.     @vehicle_type = 1                 # 设置交通工具类型
  1013.     force_move_forward                # 前进一步
  1014.     @walking_bgm = RPG::BGM::last     # 记忆步行时 BGM 用
  1015.     $game_map.ship.get_on             # 乘座处理
  1016.   end
  1017.   #--------------------------------------------------------------------------
  1018.   # ● 乘座飞行船
  1019.   #--------------------------------------------------------------------------
  1020.   def get_on_airship
  1021.     @vehicle_getting_on = true        # 开始乘座动作
  1022.     @vehicle_type = 2                 # 设置交通工具类型
  1023.     @through = true                   # 穿越 ON
  1024.     @walking_bgm = RPG::BGM::last     # 记忆步行时 BGM 用
  1025.     $game_map.airship.get_on          # 乘座处理
  1026.   end
  1027.   #--------------------------------------------------------------------------
  1028.   # ● 降下交通工具
  1029.   #    前提是现在乘座了交通工具。
  1030.   #--------------------------------------------------------------------------
  1031.   def get_off_vehicle
  1032.     if in_airship?                                # 飞行船
  1033.       return unless airship_land_ok?(@x, @y)      # 无法着陆?
  1034.     else                                          # 小型船·大型船
  1035.       front_x = $game_map.x_with_direction(@x, @direction)
  1036.       front_y = $game_map.y_with_direction(@y, @direction)
  1037.       return unless can_walk?(front_x, front_y)   # 无法靠岸?
  1038.     end
  1039.     $game_map.vehicles[@vehicle_type].get_off     # 降下处理
  1040.     if in_airship?                                # 飞行船
  1041.       @direction = 2                              # 面朝下
  1042.     else                                          # 小型船·大型船
  1043.       force_move_forward                          # 前进一步
  1044.       @transparent = false                        # 解除透明
  1045.     end
  1046.     @vehicle_getting_off = true                   # 开始降下动作
  1047.     @move_speed = 4                               # 还原移动速度
  1048.     @through = false                              # 穿越 OFF
  1049.     @walking_bgm.play                             # 还原步行时的 BGM
  1050.     make_encounter_count                          # 初始化遇敌率
  1051.   end
  1052.   
  1053.   #==========================================================================
  1054.   #★以上这几个是默认的,但是留着方便以后进一步扩展
  1055.   #==========================================================================
  1056. end #class

  1057. 就是这个脚本了{:2_279:} 本人脚本盲,求助
复制代码
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部