设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2121|回复: 0
打印 上一主题 下一主题

[RMVX发布] 微主角移动速度增减

[复制链接]

Lv1.梦旅人

小黑

梦石
0
星屑
50
在线时间
140 小时
注册时间
2011-8-23
帖子
536
跳转到指定楼层
1
发表于 2011-11-14 03:07:54 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

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

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

x
本帖最后由 咚小黑 于 2011-11-14 03:24 编辑

个人感觉更加适合赛车游戏


Q减速   W加速



Game_Character【可以直接代替】
  1. #==============================================================================
  2. #=《微主角速度增减》
  3. #==============================================================================
  4. #=
  5. #=   by:黑之翅膀    =    =    转载请保留此信息
  6. #=
  7. #==============================================================================
  8. # ■ Game_Character
  9. #------------------------------------------------------------------------------
  10. #  处理角色的类。本类作为 Game_Player 类与 Game_Event 类的超级类使用。
  11. #==============================================================================

  12. class Game_Character
  13.   #--------------------------------------------------------------------------
  14.   # ● 定义实例变量
  15.   #--------------------------------------------------------------------------
  16.   attr_reader   :id                       # ID
  17.   attr_reader   :x                        # 地图逻辑 X 座标
  18.   attr_reader   :y                        # 地图逻辑 Y 座标
  19.   attr_reader   :real_x                   # 地图 X 座标(逻辑 X 座标 * 256)
  20.   attr_reader   :real_y                   # 地图 Y 座标(逻辑 Y 座标 * 256)
  21.   attr_reader   :tile_id                  # 图块ID(0则无效化)
  22.   attr_reader   :character_name           # 角色图档名称
  23.   attr_reader   :character_index          # 角色图档索引
  24.   attr_reader   :opacity                  # 不透明度
  25.   attr_reader   :blend_type               # 合成方式
  26.   attr_reader   :direction                # 面向
  27.   attr_reader   :pattern                  # 图案
  28.   attr_reader   :move_route_forcing       # 移动路线强制标志
  29.   attr_reader   :priority_type            # 优先度类型
  30.   attr_reader   :through                  # 穿透
  31.   attr_reader   :bush_depth               # 草木深度
  32.   attr_accessor :animation_id             # 动画 ID
  33.   attr_accessor :balloon_id               # 心情图标ID
  34.   attr_accessor :transparent              # 透明标志
  35.   attr_accessor :move_speed               # 新加入!!
  36.   #--------------------------------------------------------------------------
  37.   # ● 初始化对像
  38.   #--------------------------------------------------------------------------
  39.   def initialize
  40.     @id = 0
  41.     @x = 0
  42.     @y = 0
  43.     @real_x = 0
  44.     @real_y = 0
  45.     @tile_id = 0
  46.     @character_name = ""
  47.     @character_index = 0
  48.     @opacity = 255
  49.     @blend_type = 0
  50.     @direction = 2
  51.     @pattern = 1
  52.     @move_route_forcing = false
  53.     @priority_type = 1
  54.     @through = false
  55.     @bush_depth = 0
  56.     @animation_id = 0
  57.     @balloon_id = 0
  58.     @transparent = false
  59.     @original_direction = 2               # 原朝向
  60.     @original_pattern = 1                 # 原图案
  61.     @move_type = 0                        # 移动类型
  62.     @move_speed = 4                       # 移动速度
  63.     @move_frequency = 6                   # 移动频度
  64.     @move_route = nil                     # 移动路线
  65.     @move_route_index = 0                 # 移动路线索引
  66.     @original_move_route = nil            # 原移动路线
  67.     @original_move_route_index = 0        # 原移动路线索引
  68.     @walk_anime = true                    # 步行动化
  69.     @step_anime = false                   # 踏步动画
  70.     @direction_fix = false                # 固定朝向
  71.     @anime_count = 0                      # 动画计数
  72.     @stop_count = 0                       # 停止计数
  73.     @jump_count = 0                       # 跳跃计数
  74.     @jump_peak = 0                        # 跳跃高度记数
  75.     @wait_count = 0                       # 等待计数
  76.     @locked = false                       # 锁定标志
  77.     @prelock_direction = 0                # 锁定前朝向
  78.     @move_failed = false                  # 移动失败标志
  79.   end
  80.   #--------------------------------------------------------------------------
  81.   # ● 判断是否移动
  82.   #    如果在移动中理论坐标与实际坐标不同
  83.   #--------------------------------------------------------------------------
  84.   def moving?
  85.     return (@real_x != @x * 256 or @real_y != @y * 256)
  86.   end
  87.   #--------------------------------------------------------------------------
  88.   # ● 判断是否跳跃
  89.   #--------------------------------------------------------------------------
  90.   def jumping?
  91.     return @jump_count > 0
  92.   end
  93.   #--------------------------------------------------------------------------
  94.   # ● 判断是否停止
  95.   #--------------------------------------------------------------------------
  96.   def stopping?
  97.     return (not (moving? or jumping?))
  98.   end
  99.   #--------------------------------------------------------------------------
  100.   # ● 判断是否奔跑中
  101.   #--------------------------------------------------------------------------
  102.   def dash?
  103.     return false
  104.   end
  105.   #--------------------------------------------------------------------------
  106.   # ● 判断是否是游戏测试通行状态
  107.   #--------------------------------------------------------------------------
  108.   def debug_through?
  109.     return false
  110.   end
  111.   #--------------------------------------------------------------------------
  112.   # ● 矫正姿势
  113.   #--------------------------------------------------------------------------
  114.   def straighten
  115.     @pattern = 1 if @walk_anime or @step_anime
  116.     @anime_count = 0
  117.   end
  118.   #--------------------------------------------------------------------------
  119.   # ● 强制行动路线
  120.   #     move_route : 新移动路线
  121.   #--------------------------------------------------------------------------
  122.   def force_move_route(move_route)
  123.     if @original_move_route == nil
  124.       @original_move_route = @move_route
  125.       @original_move_route_index = @move_route_index
  126.     end
  127.     @move_route = move_route
  128.     @move_route_index = 0
  129.     @move_route_forcing = true
  130.     @prelock_direction = 0
  131.     @wait_count = 0
  132.     move_type_custom
  133.   end
  134.   #--------------------------------------------------------------------------
  135.   # ● 判断所在座标是否指定位置
  136.   #     x : X 座标
  137.   #     y : Y 座标
  138.   #--------------------------------------------------------------------------
  139.   def pos?(x, y)
  140.     return (@x == x and @y == y)
  141.   end
  142.   #--------------------------------------------------------------------------
  143.   # ● 指定位置座标和不可穿透判断(nt = 不可穿透)
  144.   #     x : X 座标
  145.   #     y : Y 座标
  146.   #--------------------------------------------------------------------------
  147.   def pos_nt?(x, y)
  148.     return (pos?(x, y) and not @through)
  149.   end
  150.   #--------------------------------------------------------------------------
  151.   # ● 通行判定
  152.   #     x : X 座标
  153.   #     y : Y 座标
  154.   #--------------------------------------------------------------------------
  155.   def passable?(x, y)
  156.     x = $game_map.round_x(x)                        # 横向循环校正
  157.     y = $game_map.round_y(y)                        # 纵向循环校正
  158.     return false unless $game_map.valid?(x, y)      # 判断是否在地图之外
  159.     return true if @through or debug_through?       # 判断是否允许穿透
  160.     return false unless map_passable?(x, y)         # 判断地图是否不可通行
  161.     return false if collide_with_characters?(x, y)  # 判断是否与其他角色碰撞
  162.     return true                                     # 可以通行
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # ● 地图通行判定
  166.   #     x : X 座标
  167.   #     y : Y 座标
  168.   #    判断目标图块是否能通行。
  169.   #--------------------------------------------------------------------------
  170.   def map_passable?(x, y)
  171.     return $game_map.passable?(x, y)
  172.   end
  173.   #--------------------------------------------------------------------------
  174.   # ● 判断角色碰撞
  175.   #     x : X 座标
  176.   #     y : Y 座标
  177.   #    侦察与普通角色碰撞,包括角色与交通工具
  178.   #--------------------------------------------------------------------------
  179.   def collide_with_characters?(x, y)
  180.     for event in $game_map.events_xy(x, y)          # 判断事件位置
  181.       unless event.through                          # 事件是否允许通行
  182.         return true if self.is_a?(Game_Event)       # 本身是否事件
  183.         return true if event.priority_type == 1     # 目标事件是普通角色
  184.       end
  185.     end
  186.     if @priority_type == 1                          # 本身是普通角色的场合
  187.       return true if $game_player.pos_nt?(x, y)     # 判断主角位置
  188.       return true if $game_map.boat.pos_nt?(x, y)   # 判断小型船位置
  189.       return true if $game_map.ship.pos_nt?(x, y)   # 判断大型船位置
  190.     end
  191.     return false
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # ● 锁定(事件进行中中断的处理)
  195.   #--------------------------------------------------------------------------
  196.   def lock
  197.     unless @locked
  198.       @prelock_direction = @direction
  199.       turn_toward_player
  200.       @locked = true
  201.     end
  202.   end
  203.   #--------------------------------------------------------------------------
  204.   # ● 解除锁定
  205.   #--------------------------------------------------------------------------
  206.   def unlock
  207.     if @locked
  208.       @locked = false
  209.       set_direction(@prelock_direction)
  210.     end
  211.   end
  212.   #--------------------------------------------------------------------------
  213.   # ● 移动制指定目标
  214.   #     x : X 座标
  215.   #     y : Y 座标
  216.   #--------------------------------------------------------------------------
  217.   def moveto(x, y)
  218.     @x = x % $game_map.width
  219.     @y = y % $game_map.height
  220.     @real_x = @x * 256
  221.     @real_y = @y * 256
  222.     @prelock_direction = 0
  223.     straighten
  224.     update_bush_depth
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # ● 改变为指定方向
  228.   #     direction : 新方向
  229.   #--------------------------------------------------------------------------
  230.   def set_direction(direction)
  231.     if not @direction_fix and direction != 0
  232.       @direction = direction
  233.       @stop_count = 0
  234.     end
  235.   end
  236.   #--------------------------------------------------------------------------
  237.   # ● 判断物件类型
  238.   #--------------------------------------------------------------------------
  239.   def object?
  240.     return (@tile_id > 0 or @character_name[0, 1] == '!')
  241.   end
  242.   #--------------------------------------------------------------------------
  243.   # ● 获取画面 X 座标
  244.   #--------------------------------------------------------------------------
  245.   def screen_x
  246.     return ($game_map.adjust_x(@real_x) + 8007) / 8 - 1000 + 16
  247.   end
  248.   #--------------------------------------------------------------------------
  249.   # ● 获取画面 Y 座标
  250.   #--------------------------------------------------------------------------
  251.   def screen_y
  252.     y = ($game_map.adjust_y(@real_y) + 8007) / 8 - 1000 + 32
  253.     y -= 4 unless object?
  254.     if @jump_count >= @jump_peak
  255.       n = @jump_count - @jump_peak
  256.     else
  257.       n = @jump_peak - @jump_count
  258.     end
  259.     return y - (@jump_peak * @jump_peak - n * n) / 2
  260.   end
  261.   #--------------------------------------------------------------------------
  262.   # ● 获取画面 Z 座标
  263.   #--------------------------------------------------------------------------
  264.   def screen_z
  265.     if @priority_type == 2
  266.       return 200
  267.     elsif @priority_type == 0
  268.       return 60
  269.     elsif @tile_id > 0
  270.       pass = $game_map.passages[@tile_id]
  271.       if pass & 0x10 == 0x10    # [☆]
  272.         return 160
  273.       else
  274.         return 40
  275.       end
  276.     else
  277.       return 100
  278.     end
  279.   end
  280.   #--------------------------------------------------------------------------
  281.   # ● 更新画面
  282.   #--------------------------------------------------------------------------
  283.   def update
  284.     if jumping?                 # 跳跃
  285.       update_jump
  286.     elsif moving?               # 移动
  287.       update_move
  288.     else                        # 停止
  289.       update_stop
  290.     end
  291.     if @wait_count > 0          # 等待
  292.       @wait_count -= 1
  293.     elsif @move_route_forcing   # 强制移动
  294.       move_type_custom
  295.     elsif not @locked           # 非锁定状态
  296.       update_self_movement
  297.     end
  298.     update_animation
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ● 更新画面 (跳跃)
  302.   #--------------------------------------------------------------------------
  303.   def update_jump
  304.     @jump_count -= 1
  305.     @real_x = (@real_x * @jump_count + @x * 256) / (@jump_count + 1)
  306.     @real_y = (@real_y * @jump_count + @y * 256) / (@jump_count + 1)
  307.     update_bush_depth
  308.   end
  309.   #--------------------------------------------------------------------------
  310.   # ● 更新画面 (移动)
  311.   #--------------------------------------------------------------------------
  312.   
  313.   
  314. #=============================================================================
  315.   def update_move
  316.    
  317.     a = -50                                       #最小速度
  318.     b = 50                                        #最大速度

  319.   if Input.trigger?(Input::L)
  320.     if @move_speed >= a
  321.       $game_player.move_speed = @move_speed - 0.1
  322.     else
  323.       end
  324.   else
  325.       
  326.       
  327.       
  328.   if Input.trigger?(Input::R)
  329.     if @move_speed <= b
  330.       $game_player.move_speed = @move_speed + 0.1
  331.     else
  332.       end
  333.   else
  334.       
  335. #=============================================================================      


  336.     distance = 2 ** @move_speed   # 转换成移动距离
  337.    
  338.     distance *= 2 if dash?        # 跑步中加倍
  339.    
  340.     @real_x = [@real_x - distance, @x * 256].max if @x * 256 < @real_x
  341.     @real_x = [@real_x + distance, @x * 256].min if @x * 256 > @real_x
  342.     @real_y = [@real_y - distance, @y * 256].max if @y * 256 < @real_y
  343.     @real_y = [@real_y + distance, @y * 256].min if @y * 256 > @real_y
  344.     update_bush_depth unless moving?
  345.     if @walk_anime
  346.       @anime_count += 1.5
  347.     elsif @step_anime
  348.       @anime_count += 1
  349.     end
  350.   end
  351. end
  352. end
  353.   #--------------------------------------------------------------------------
  354.   # ● 更新画面 (停止)
  355.   #--------------------------------------------------------------------------
  356.   def update_stop
  357.     if @step_anime
  358.       @anime_count += 1
  359.     elsif @pattern != @original_pattern
  360.       @anime_count += 1.5
  361.     end
  362.     @stop_count += 1 unless @locked
  363.   end
  364.   #--------------------------------------------------------------------------
  365.   # ● 更新画面 (本身行动)
  366.   #--------------------------------------------------------------------------
  367.   def update_self_movement
  368.     if @stop_count > 30 * (5 - @move_frequency)
  369.       case @move_type
  370.       when 1;  move_type_random
  371.       when 2;  move_type_toward_player
  372.       when 3;  move_type_custom
  373.       end
  374.     end
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # ● 更新画面 (动画)
  378.   #--------------------------------------------------------------------------
  379.   def update_animation
  380.     speed = @move_speed + (dash? ? 1 : 0)
  381.     if @anime_count > 18 - speed * 2
  382.       if not @step_anime and @stop_count > 0
  383.         @pattern = @original_pattern
  384.       else
  385.         @pattern = (@pattern + 1) % 4
  386.       end
  387.       @anime_count = 0
  388.     end
  389.   end
  390.   #--------------------------------------------------------------------------
  391.   # ● 更新画面 (草木繁茂)
  392.   #--------------------------------------------------------------------------
  393.   def update_bush_depth
  394.     if object? or @priority_type != 1 or @jump_count > 0
  395.       @bush_depth = 0
  396.     else
  397.       bush = $game_map.bush?(@x, @y)
  398.       if bush and not moving?
  399.         @bush_depth = 8
  400.       elsif not bush
  401.         @bush_depth = 0
  402.       end
  403.     end
  404.   end
  405.   #--------------------------------------------------------------------------
  406.   # ● 移动类型:随机
  407.   #--------------------------------------------------------------------------
  408.   def move_type_random
  409.     case rand(6)
  410.     when 0..1;  move_random
  411.     when 2..4;  move_forward
  412.     when 5;     @stop_count = 0
  413.     end
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # ● 移动类型:接近
  417.   #--------------------------------------------------------------------------
  418.   def move_type_toward_player
  419.     sx = @x - $game_player.x
  420.     sy = @y - $game_player.y
  421.     if sx.abs + sy.abs >= 20
  422.       move_random
  423.     else
  424.       case rand(6)
  425.       when 0..3;  move_toward_player
  426.       when 4;     move_random
  427.       when 5;     move_forward
  428.       end
  429.     end
  430.   end
  431.   #--------------------------------------------------------------------------
  432.   # ● 移动类型:自订
  433.   #--------------------------------------------------------------------------
  434.   def move_type_custom
  435.     if stopping?
  436.       command = @move_route.list[@move_route_index]   # Get movement command
  437.       @move_failed = false
  438.       if command.code == 0                            # End of list
  439.         if @move_route.repeat                         # [Repeat Action]
  440.           @move_route_index = 0
  441.         elsif @move_route_forcing                     # Forced move route
  442.           @move_route_forcing = false                 # Cancel forcing
  443.           @move_route = @original_move_route          # Restore original
  444.           @move_route_index = @original_move_route_index
  445.           @original_move_route = nil
  446.         end
  447.       else
  448.         case command.code
  449.         when 1    # 往下移动
  450.           move_down
  451.         when 2    # 往左移动
  452.           move_left
  453.         when 3    # 往右移动
  454.           move_right
  455.         when 4    # 往上移动
  456.           move_up
  457.         when 5    # 往左下移动
  458.           move_lower_left
  459.         when 6    # 往右下移动
  460.           move_lower_right
  461.         when 7    # 往左上移动
  462.           move_upper_left
  463.         when 8    # 往右上移动
  464.           move_upper_right
  465.         when 9    # 随机移动
  466.           move_random
  467.         when 10   # 接近主角
  468.           move_toward_player
  469.         when 11   # 远离主角
  470.           move_away_from_player
  471.         when 12   # 前进一步
  472.           move_forward
  473.         when 13   # 後退一步
  474.           move_backward
  475.         when 14   # 跳跃
  476.           jump(command.parameters[0], command.parameters[1])
  477.         when 15   # 等待
  478.           @wait_count = command.parameters[0] - 1
  479.         when 16   # 面向下
  480.           turn_down
  481.         when 17   # 面向左
  482.           turn_left
  483.         when 18   # 面向右
  484.           turn_right
  485.         when 19   # 面向上
  486.           turn_up
  487.         when 20   # 向右转 90 度
  488.           turn_right_90
  489.         when 21   # 向左转 90 度
  490.           turn_left_90
  491.         when 22   # 旋转 180 度
  492.           turn_180
  493.         when 23   # 随机转 90 度
  494.           turn_right_or_left_90
  495.         when 24   # 随机转换方向
  496.           turn_random
  497.         when 25   # 面向主角
  498.           turn_toward_player
  499.         when 26   # 背向主角
  500.           turn_away_from_player
  501.         when 27   # 开启开关
  502.           $game_switches[command.parameters[0]] = true
  503.           $game_map.need_refresh = true
  504.         when 28   # 关闭开关
  505.           $game_switches[command.parameters[0]] = false
  506.           $game_map.need_refresh = true
  507.         when 29   # 更改移动速度
  508.           @move_speed = command.parameters[0]
  509.         when 30   # 更改移动频度
  510.           @move_frequency = command.parameters[0]
  511.         when 31   # 开启步行动画
  512.           @walk_anime = true
  513.         when 32   # 关闭步行动画
  514.           @walk_anime = false
  515.         when 33   # 开启踏步动画
  516.           @step_anime = true
  517.         when 34   # 关闭踏步动画
  518.           @step_anime = false
  519.         when 35   # 开启面向固定
  520.           @direction_fix = true
  521.         when 36   # 关闭面向固定
  522.           @direction_fix = false
  523.         when 37   # 允许穿透
  524.           @through = true
  525.         when 38   # 不允许穿透
  526.           @through = false
  527.         when 39   # 开启透明状态
  528.           @transparent = true
  529.         when 40   # 关闭透明状态
  530.           @transparent = false
  531.         when 41   # 更改角色图像
  532.           set_graphic(command.parameters[0], command.parameters[1])
  533.         when 42   # 更改透明度
  534.           @opacity = command.parameters[0]
  535.         when 43   # 更改合成方式
  536.           @blend_type = command.parameters[0]
  537.         when 44   # 播放音效
  538.           command.parameters[0].play
  539.         when 45   # 脚本
  540.           eval(command.parameters[0])
  541.         end
  542.         if not @move_route.skippable and @move_failed
  543.           return  # 非[跳过不能移动的场合] 并且移动失败
  544.         end
  545.         @move_route_index += 1
  546.       end
  547.     end
  548.   end
  549.   #--------------------------------------------------------------------------
  550.   # ● 增加步数
  551.   #--------------------------------------------------------------------------
  552.   def increase_steps
  553.     @stop_count = 0
  554.     update_bush_depth
  555.   end
  556.   #--------------------------------------------------------------------------
  557.   # ● 计算距离主角的横向距离
  558.   #--------------------------------------------------------------------------
  559.   def distance_x_from_player
  560.     sx = @x - $game_player.x
  561.     if $game_map.loop_horizontal?         # 横向循环的场合
  562.       if sx == 1 - $game_map.width
  563.         sx += $game_map.width  
  564.       elsif sx.abs > $game_map.width / 2  # 是否大于地图宽度
  565.         sx -= $game_map.width             # 减除地图宽度
  566.       end
  567.     end
  568.     return sx
  569.   end
  570.   #--------------------------------------------------------------------------
  571.   # ● 计算距离主角的纵向距离
  572.   #--------------------------------------------------------------------------
  573.   def distance_y_from_player
  574.     sy = @y - $game_player.y
  575.     if $game_map.loop_vertical?           # 纵像循环的场合
  576.       if sy == 1 - $game_map.height
  577.         sy += $game_map.height     
  578.       elsif sy.abs > $game_map.height / 2 # 是否大于地图高度
  579.         sy -= $game_map.height            # 减除地图高度
  580.       end
  581.     end
  582.     return sy
  583.   end
  584.   #--------------------------------------------------------------------------
  585.   # ● 向下移动
  586.   #     turn_ok : 允许当场转向
  587.   #--------------------------------------------------------------------------
  588.   def move_down(turn_ok = true)
  589.     if passable?(@x, @y+1)                  # 可通行的场合
  590.       turn_down
  591.       @y = $game_map.round_y(@y+1)
  592.       @real_y = (@y-1)*256
  593.       increase_steps
  594.       @move_failed = false
  595.     else                                    # 不可通行的场合
  596.       turn_down if turn_ok
  597.       check_event_trigger_touch(@x, @y+1)   # 是否触发接触事件
  598.       @move_failed = true
  599.     end
  600.   end
  601.   #--------------------------------------------------------------------------
  602.   # ● 向左移动
  603.   #     turn_ok : 允许当场转向
  604.   #--------------------------------------------------------------------------
  605.   def move_left(turn_ok = true)
  606.     if passable?(@x-1, @y)                  # 可通行的场合
  607.       turn_left
  608.       @x = $game_map.round_x(@x-1)
  609.       @real_x = (@x+1)*256
  610.       increase_steps
  611.       @move_failed = false
  612.     else                                    # 不可通行的场合
  613.       turn_left if turn_ok
  614.       check_event_trigger_touch(@x-1, @y)   # 是否触发接触事件
  615.       @move_failed = true
  616.     end
  617.   end
  618.   #--------------------------------------------------------------------------
  619.   # ● 向右移动
  620.   #     turn_ok : 允许当场转向
  621.   #--------------------------------------------------------------------------
  622.   def move_right(turn_ok = true)
  623.     if passable?(@x+1, @y)                  # 可通行的场合
  624.       turn_right
  625.       @x = $game_map.round_x(@x+1)
  626.       @real_x = (@x-1)*256
  627.       increase_steps
  628.       @move_failed = false
  629.     else                                    # 不可通行的场合
  630.       turn_right if turn_ok
  631.       check_event_trigger_touch(@x+1, @y)   # 是否触发接触事件
  632.       @move_failed = true
  633.     end
  634.   end
  635.   #--------------------------------------------------------------------------
  636.   # ● 向上移动
  637.   #     turn_ok : 允许当场转向
  638.   #--------------------------------------------------------------------------
  639.   def move_up(turn_ok = true)
  640.     if passable?(@x, @y-1)                  # 可通行的场合
  641.       turn_up
  642.       @y = $game_map.round_y(@y-1)
  643.       @real_y = (@y+1)*256
  644.       increase_steps
  645.       @move_failed = false
  646.     else                                    # 不可通行的场合
  647.       turn_up if turn_ok
  648.       check_event_trigger_touch(@x, @y-1)   # 是否触发接触事件
  649.       @move_failed = true
  650.     end
  651.   end
  652.   #--------------------------------------------------------------------------
  653.   # ● 向左下移动
  654.   #--------------------------------------------------------------------------
  655.   def move_lower_left
  656.     unless @direction_fix
  657.       @direction = (@direction == 6 ? 4 : @direction == 8 ? 2 : @direction)
  658.     end
  659.     if (passable?(@x, @y+1) and passable?(@x-1, @y+1)) or
  660.        (passable?(@x-1, @y) and passable?(@x-1, @y+1))
  661.       @x -= 1
  662.       @y += 1
  663.       increase_steps
  664.       @move_failed = false
  665.     else
  666.       @move_failed = true
  667.     end
  668.   end
  669.   #--------------------------------------------------------------------------
  670.   # ● 向右下移动
  671.   #--------------------------------------------------------------------------
  672.   def move_lower_right
  673.     unless @direction_fix
  674.       @direction = (@direction == 4 ? 6 : @direction == 8 ? 2 : @direction)
  675.     end
  676.     if (passable?(@x, @y+1) and passable?(@x+1, @y+1)) or
  677.        (passable?(@x+1, @y) and passable?(@x+1, @y+1))
  678.       @x += 1
  679.       @y += 1
  680.       increase_steps
  681.       @move_failed = false
  682.     else
  683.       @move_failed = true
  684.     end
  685.   end
  686.   #--------------------------------------------------------------------------
  687.   # ● 向左上移动
  688.   #--------------------------------------------------------------------------
  689.   def move_upper_left
  690.     unless @direction_fix
  691.       @direction = (@direction == 6 ? 4 : @direction == 2 ? 8 : @direction)
  692.     end
  693.     if (passable?(@x, @y-1) and passable?(@x-1, @y-1)) or
  694.        (passable?(@x-1, @y) and passable?(@x-1, @y-1))
  695.       @x -= 1
  696.       @y -= 1
  697.       increase_steps
  698.       @move_failed = false
  699.     else
  700.       @move_failed = true
  701.     end
  702.   end
  703.   #--------------------------------------------------------------------------
  704.   # ● 向右上移动
  705.   #--------------------------------------------------------------------------
  706.   def move_upper_right
  707.     unless @direction_fix
  708.       @direction = (@direction == 4 ? 6 : @direction == 2 ? 8 : @direction)
  709.     end
  710.     if (passable?(@x, @y-1) and passable?(@x+1, @y-1)) or
  711.        (passable?(@x+1, @y) and passable?(@x+1, @y-1))
  712.       @x += 1
  713.       @y -= 1
  714.       increase_steps
  715.       @move_failed = false
  716.     else
  717.       @move_failed = true
  718.     end
  719.   end
  720.   #--------------------------------------------------------------------------
  721.   # ● 随机移动
  722.   #--------------------------------------------------------------------------
  723.   def move_random
  724.     case rand(4)
  725.     when 0;  move_down(false)
  726.     when 1;  move_left(false)
  727.     when 2;  move_right(false)
  728.     when 3;  move_up(false)
  729.     end
  730.   end
  731.   #--------------------------------------------------------------------------
  732.   # ● 接近主角
  733.   #--------------------------------------------------------------------------
  734.   def move_toward_player
  735.     sx = distance_x_from_player
  736.     sy = distance_y_from_player
  737.     sx += $game_map.width * 2 if $game_map.loop_horizontal? and sx < - $game_map.width  and sx > - $game_map.width * 2
  738.     sy += $game_map.height * 2 if $game_map.loop_vertical? and sy < - $game_map.height  and sy > - $game_map.height * 2
  739.     if sx != 0 or sy != 0
  740.       if sx.abs > sy.abs                  # 横向距离较大
  741.         sx > 0 ? move_left : move_right   # 优先往左右走
  742.         if @move_failed and sy != 0
  743.           sy > 0 ? move_up : move_down
  744.         end
  745.       else                                # 纵向距离较大
  746.         sy > 0 ? move_up : move_down      # 优先往上下走
  747.         if @move_failed and sx != 0
  748.           sx > 0 ? move_left : move_right
  749.         end
  750.       end
  751.     end
  752.   end
  753.   #--------------------------------------------------------------------------
  754.   # ● 远离主角
  755.   #--------------------------------------------------------------------------
  756.   def move_away_from_player
  757.     sx = distance_x_from_player
  758.     sy = distance_y_from_player
  759.     sx += $game_map.width * 2 if $game_map.loop_horizontal? and sx < - $game_map.width  and sx > - $game_map.width * 2
  760.     sy += $game_map.height * 2 if $game_map.loop_vertical? and sy < - $game_map.height  and sy > - $game_map.height * 2     
  761.     if sx != 0 or sy != 0
  762.       if sx.abs > sy.abs                  # 横向距离较大
  763.         sx > 0 ? move_right : move_left   # 优先往左右走
  764.         if @move_failed and sy != 0
  765.           sy > 0 ? move_down : move_up
  766.         end
  767.       else                                # 纵向距离较大
  768.         sy > 0 ? move_down : move_up      # 优先往上下走
  769.         if @move_failed and sx != 0
  770.           sx > 0 ? move_right : move_left
  771.         end
  772.       end
  773.     end
  774.   end
  775.   #--------------------------------------------------------------------------
  776.   # ● 向前一步
  777.   #--------------------------------------------------------------------------
  778.   def move_forward
  779.     case @direction
  780.     when 2;  move_down(false)
  781.     when 4;  move_left(false)
  782.     when 6;  move_right(false)
  783.     when 8;  move_up(false)
  784.     end
  785.   end
  786.   #--------------------------------------------------------------------------
  787.   # ● 向後一步
  788.   #--------------------------------------------------------------------------
  789.   def move_backward
  790.     last_direction_fix = @direction_fix
  791.     @direction_fix = true
  792.     case @direction
  793.     when 2;  move_up(false)
  794.     when 4;  move_right(false)
  795.     when 6;  move_left(false)
  796.     when 8;  move_down(false)
  797.     end
  798.     @direction_fix = last_direction_fix
  799.   end
  800.   #--------------------------------------------------------------------------
  801.   # ● 跳跃
  802.   #     x_plus : X 座标增值
  803.   #     y_plus : Y 座标增值
  804.   #--------------------------------------------------------------------------
  805.   def jump(x_plus, y_plus)
  806.     if x_plus.abs > y_plus.abs            # 横向距离较大
  807.       x_plus < 0 ? turn_left : turn_right
  808.     elsif x_plus.abs > y_plus.abs         # 纵向距离较大
  809.       y_plus < 0 ? turn_up : turn_down
  810.     end
  811.     @x += x_plus
  812.     @y += y_plus
  813.     distance = Math.sqrt(x_plus * x_plus + y_plus * y_plus).round
  814.     @jump_peak = 10 + distance - @move_speed
  815.     @jump_count = @jump_peak * 2
  816.     @stop_count = 0
  817.     straighten
  818.   end
  819.   #--------------------------------------------------------------------------
  820.   # ● 面向下
  821.   #--------------------------------------------------------------------------
  822.   def turn_down
  823.     set_direction(2)
  824.   end
  825.   #--------------------------------------------------------------------------
  826.   # ● 面向左
  827.   #--------------------------------------------------------------------------
  828.   def turn_left
  829.     set_direction(4)
  830.   end
  831.   #--------------------------------------------------------------------------
  832.   # ● 面向右
  833.   #--------------------------------------------------------------------------
  834.   def turn_right
  835.     set_direction(6)
  836.   end
  837.   #--------------------------------------------------------------------------
  838.   # ● 面向上
  839.   #--------------------------------------------------------------------------
  840.   def turn_up
  841.     set_direction(8)
  842.   end
  843.   #--------------------------------------------------------------------------
  844.   # ● 向右转90度
  845.   #--------------------------------------------------------------------------
  846.   def turn_right_90
  847.     case @direction
  848.     when 2;  turn_left
  849.     when 4;  turn_up
  850.     when 6;  turn_down
  851.     when 8;  turn_right
  852.     end
  853.   end
  854.   #--------------------------------------------------------------------------
  855.   # ● 向左转90度
  856.   #--------------------------------------------------------------------------
  857.   def turn_left_90
  858.     case @direction
  859.     when 2;  turn_right
  860.     when 4;  turn_down
  861.     when 6;  turn_up
  862.     when 8;  turn_left
  863.     end
  864.   end
  865.   #--------------------------------------------------------------------------
  866.   # ● 旋转180度
  867.   #--------------------------------------------------------------------------
  868.   def turn_180
  869.     case @direction
  870.     when 2;  turn_up
  871.     when 4;  turn_right
  872.     when 6;  turn_left
  873.     when 8;  turn_down
  874.     end
  875.   end
  876.   #--------------------------------------------------------------------------
  877.   # ● 随机左右转90度
  878.   #--------------------------------------------------------------------------
  879.   def turn_right_or_left_90
  880.     case rand(2)
  881.     when 0;  turn_right_90
  882.     when 1;  turn_left_90
  883.     end
  884.   end
  885.   #--------------------------------------------------------------------------
  886.   # ● 随机转向
  887.   #--------------------------------------------------------------------------
  888.   def turn_random
  889.     case rand(4)
  890.     when 0;  turn_up
  891.     when 1;  turn_right
  892.     when 2;  turn_left
  893.     when 3;  turn_down
  894.     end
  895.   end
  896.   #--------------------------------------------------------------------------
  897.   # ● 面向主角
  898.   #--------------------------------------------------------------------------
  899.   def turn_toward_player
  900.     sx = distance_x_from_player
  901.     sy = distance_y_from_player
  902.     if sx.abs > sy.abs                    # 横向距离较大
  903.       sx > 0 ? turn_left : turn_right
  904.     elsif sx.abs < sy.abs                 # 纵向距离较大
  905.       sy > 0 ? turn_up : turn_down
  906.     end
  907.   end
  908.   #--------------------------------------------------------------------------
  909.   # ● 背向主角
  910.   #--------------------------------------------------------------------------
  911.   def turn_away_from_player
  912.     sx = distance_x_from_player
  913.     sy = distance_y_from_player
  914.     if sx.abs > sy.abs                    # 横向距离较大
  915.       sx > 0 ? turn_right : turn_left
  916.     elsif sx.abs < sy.abs                 # 纵向距离较大
  917.       sy > 0 ? turn_down : turn_up
  918.     end
  919.   end
  920.   #--------------------------------------------------------------------------
  921.   # ● 变更角色图像
  922.   #     character_name  : 新角色图像文件名称
  923.   #     character_index : 新角色图像文件索引
  924.   #--------------------------------------------------------------------------
  925.   def set_graphic(character_name, character_index)
  926.     @tile_id = 0
  927.     @character_name = character_name
  928.     @character_index = character_index
  929.   end
  930. end
复制代码
范本下载:
微增移动速度.zip (251.56 KB, 下载次数: 823)

评分

参与人数 1星屑 +2 收起 理由
竹轩轩 + 2 看起来挺好

查看全部评分

起码对得起自己。
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-28 19:40

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表