查看: 3216|回复: 4

[已经解决] 使用「粘性移动平台」时,调高并剪裁行走图

[复制链接]
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
发表于 2020-8-6 09:45:28 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 alexncf125 于 2024-1-25 01:47 编辑

站在平台上时,
能把角色的行走图的位置向上昇高一些么?(当平台的行走图是矿车/飞毯时
能把角色的行走图的下半身裁去一部分么?(当平台的行走图只是矿车时
  1. #==============================================================================
  2. # 粘性移动平台
  3. # by ???nOBodY???
  4. #==============================================================================
  5. # 设置一个粘性平台,首先你需要一个事件
  6. # 在事件的移动路线里使用脚本:
  7. # self.accessible = true 或 self.accessible = false
  8. # 来开启或关闭事件的粘性状态.
  9. #
  10. # 粘性事件移动时会带着玩家一起移动,直至玩家离开事件
  11. # 平台事件的事件页里,并行处理以下内容:
  12. #
  13. # 如果: 脚本: get_character(0).accessible
  14. #   脚本: get_character(0).through = false
  15. #   如果: 脚本: get_character(0).x == $game_player.x &&
  16. #                               get_character(0).y == $game_player.y
  17. #     脚本: $game_player.platformID = @event_id
  18. #   结束
  19. # 否则
  20. #   Script: get_character(0).through = true
  21. # 结束
  22. #==============================================================================

  23. class Game_CharacterBase
  24.   #--------------------------------------------------------------------------
  25.   # * Public Instance Variables
  26.   #--------------------------------------------------------------------------
  27.   attr_accessor :through                  # pass-through
  28.   attr_accessor :accessible               # able to be boarded
  29.   #--------------------------------------------------------------------------
  30.   # * Object Initialization
  31.   #--------------------------------------------------------------------------
  32.   alias movingPlatformsChar_initializer initialize
  33.   def initialize
  34.     movingPlatformsChar_initializer
  35.     @accessible = false
  36.   end
  37.   
  38.   #--------------------------------------------------------------------------
  39.   # ● 通行可能判定
  40.   #     d : 方向(2,4,6,8)
  41.   #--------------------------------------------------------------------------
  42.   def passableEx?(x, y, d)
  43.     x2 = $game_map.round_x_with_direction(x, d)
  44.     y2 = $game_map.round_y_with_direction(y, d)
  45.     return false unless $game_map.valid?(x2, y2)
  46.     return true if @through || debug_through?
  47.     #PATCH
  48.     if !$game_map.events_xy(x2, y2).empty?
  49.       for event in $game_map.events_xy(x2, y2)
  50.         return true if event.accessible
  51.       end
  52.     end
  53.     if !$game_map.events_xy(x, y).empty?
  54.       #no need to check current location
  55.     else
  56.       return false unless map_passable?(x, y, d)
  57.     end
  58.     #return false unless map_passable?(x, y, d)
  59.     #PATCH
  60.     return false unless map_passable?(x2, y2, reverse_dir(d))
  61.     return false if collide_with_characters?(x2, y2)
  62.     return true
  63.   end
  64.   #--------------------------------------------------------------------------
  65.   # ● まっすぐに移動
  66.   #     d       : 方向(2,4,6,8)
  67.   #     turn_ok : その場での向き変更を許可
  68.   #--------------------------------------------------------------------------
  69.   def move_straight(d, turn_ok = true)
  70.     @move_succeed = passableEx?(@x, @y, d)
  71.     if @move_succeed
  72.       set_direction(d)
  73.       @x = $game_map.round_x_with_direction(@x, d)
  74.       @y = $game_map.round_y_with_direction(@y, d)
  75.       @real_x = $game_map.x_with_direction(@x, reverse_dir(d))
  76.       @real_y = $game_map.y_with_direction(@y, reverse_dir(d))
  77.       increase_steps
  78.     elsif turn_ok
  79.       set_direction(d)
  80.       check_event_trigger_touch_front
  81.     end
  82.   end
  83. end

  84. #==============================================================================
  85. # ** Game_Player
  86. #------------------------------------------------------------------------------
  87. #  This class handles maps. It includes event starting determinants and map
  88. # scrolling functions. The instance of this class is referenced by $game_map.
  89. #==============================================================================
  90. class Game_Player < Game_Character
  91.   #--------------------------------------------------------------------------
  92.   # * Get Character
  93.   #     param : if -1, player. If 0, this event. Otherwise, event ID.
  94.   #--------------------------------------------------------------------------
  95.   def get_character(param)
  96.     case param
  97.     when -1   # Player
  98.       return $game_player #self?
  99.     when 0    # This event
  100.       events = $game_map.events
  101.       return events == nil ? nil : events[@event_id]
  102.     else      # Particular event
  103.       events = $game_map.events
  104.       return events == nil ? nil : events[param]
  105.     end
  106.   end
  107.   
  108.   #--------------------------------------------------------------------------
  109.   # * Public Instance Variables
  110.   #--------------------------------------------------------------------------
  111.   attr_accessor :platformID               # if greater than 0, an event ID
  112.   #--------------------------------------------------------------------------
  113.   # * Object Initialization
  114.   #--------------------------------------------------------------------------
  115.   alias movingPlatformsPlyr_initializer initialize
  116.   def initialize
  117.     movingPlatformsPlyr_initializer
  118.     @platformID = 0
  119.     @exitingPlatform = false
  120.     @fixingPosition = false
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # * Frame Update
  124.   #--------------------------------------------------------------------------
  125.   alias movingPlatforms_updater update
  126.   def update
  127.     if @platformID > 0
  128.       last_real_x = @real_x
  129.       last_real_y = @real_y
  130.       @x = get_character(@platformID).x
  131.       @y = get_character(@platformID).y
  132.       
  133.       #Get realMoveSpeed & distancePerFrame
  134.       realMoveSpeed = get_character(@platformID).move_speed + 1#(dash? ? 1 : 0)
  135.       distancePerFrame = 2 ** realMoveSpeed / 256.0
  136.       
  137.       temp = @real_x != get_character(@platformID).real_x ||
  138.              @real_y != get_character(@platformID).real_y ? true : false
  139.       if temp && !@fixingPosition
  140.         # Fixing position check
  141.         @fixingPosition=false
  142.         if @real_x != get_character(@platformID).real_x
  143.           if @real_x < get_character(@platformID).real_x
  144.             if get_character(@platformID).real_x <= @real_x + distancePerFrame
  145.               @fixingPosition=true
  146.             end
  147.           end
  148.           if @real_x > get_character(@platformID).real_x
  149.             if get_character(@platformID).real_x >= @real_x - distancePerFrame
  150.               @fixingPosition=true
  151.             end
  152.           end
  153.         end
  154.         if @real_y != get_character(@platformID).real_y
  155.           if @real_y < get_character(@platformID).real_y
  156.             if get_character(@platformID).real_y <= @real_y + distancePerFrame
  157.               @fixingPosition=true
  158.             end
  159.           end
  160.           if @real_y > get_character(@platformID).real_y
  161.             if get_character(@platformID).real_y >= @real_y - distancePerFrame
  162.               @fixingPosition=true
  163.             end
  164.           end
  165.         end
  166.         # Convert to movement
  167.         @real_x = [@real_x - distancePerFrame, @x].max if @x < @real_x
  168.         @real_x = [@real_x + distancePerFrame, @x].min if @x > @real_x
  169.         @real_y = [@real_y - distancePerFrame, @y].max if @y < @real_y
  170.         @real_y = [@real_y + distancePerFrame, @y].min if @y > @real_y
  171.         update_bush_depth unless moving?
  172.         update_animation
  173.       else
  174.         @real_x = get_character(@platformID).real_x
  175.         @real_y = get_character(@platformID).real_y
  176.       end
  177.       
  178.       move_by_input_onPlatform
  179.       if @exitingPlatform
  180.         movingPlatforms_updater
  181.         @platformID = 0
  182.         @exitingPlatform = false
  183.         @fixingPosition = false
  184.       end
  185.       update_scroll(last_real_x, last_real_y)
  186.     else
  187.       movingPlatforms_updater
  188.     end
  189.   end
  190.   #--------------------------------------------------------------------------
  191.   # * Processing of Movement via input from the Directional Buttons
  192.   #--------------------------------------------------------------------------
  193.   def move_by_input_onPlatform
  194.     return unless get_character(@platformID).accessible
  195.     return if !movable? || $game_map.interpreter.running?
  196.     case Input.dir4
  197.     when 2
  198.       move_straight(Input.dir4) if Input.dir4 > 0
  199.       @exitingPlatform = @move_succeed ? true : false
  200.     when 4
  201.       move_straight(Input.dir4) if Input.dir4 > 0
  202.       @exitingPlatform = @move_succeed ? true : false
  203.     when 6
  204.       move_straight(Input.dir4) if Input.dir4 > 0
  205.       @exitingPlatform = @move_succeed ? true : false
  206.     when 8
  207.       move_straight(Input.dir4) if Input.dir4 > 0
  208.       @exitingPlatform = @move_succeed ? true : false
  209.     end
  210.   end
  211. end
复制代码
梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-6 19:57:07 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-6 19:58 编辑

试了一下
这脚本好像会把平台的行走图与人物的行走图合二为一了
害我把人物的行走图昇高时一併也会把平台的行走图昇高
有大神知道怎样破么...把人物的行走图裁去下半身一部分的方法仍然毫无头绪
回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-7 11:10:47 | 显示全部楼层
贴一下第一个的解法,顺道顶一顶
把人物的行走图裁去下半身一部分的方法仍然毫无头绪
  1. class Sprite_Character < Sprite_Base
  2.   alias old_update_position_old update_position
  3.   def update_position
  4.     old_update_position_old
  5.     self.y = @character.screen_y - 8 if @character.is_a?(Game_Player) && $game_player.platformID > 0
  6.   end
  7. end
复制代码

点评

self.oy除2看看?  发表于 2020-8-7 21:16
回复

使用道具 举报

梦石
0
星屑
30103
在线时间
5741 小时
注册时间
2016-3-8
回帖
1662
 楼主| 发表于 2020-8-7 21:57:16 | 显示全部楼层
贴一下第二个的解法,顺道结帖
  1. class Sprite_Character < Sprite_Base
  2.   def update_src_rect
  3.     if @tile_id == 0
  4.       index = @character.character_index
  5.       pattern = @character.pattern < 3 ? @character.pattern : 1
  6.       sx = (index % 4 * 3 + pattern) * @cw
  7.       sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
  8.       if @character.is_a?(Game_Player) && $game_player.platformID > 0
  9.         self.src_rect.set(sx, sy, @cw, @ch - 6)
  10.       else
  11.         self.src_rect.set(sx, sy, @cw, @ch)
  12.       end
  13.     end
  14.   end
  15. end
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

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

在本版发帖返回顶部