查看: 3154|回复: 4

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

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

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

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

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

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

class Game_CharacterBase
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :through                  # pass-through
  attr_accessor :accessible               # able to be boarded
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias movingPlatformsChar_initializer initialize
  def initialize
    movingPlatformsChar_initializer
    @accessible = false
  end
  
  #--------------------------------------------------------------------------
  # ● 通行可能判定
  #     d : 方向(2,4,6,8)
  #--------------------------------------------------------------------------
  def passableEx?(x, y, d)
    x2 = $game_map.round_x_with_direction(x, d)
    y2 = $game_map.round_y_with_direction(y, d)
    return false unless $game_map.valid?(x2, y2)
    return true if @through || debug_through?
    #PATCH
    if !$game_map.events_xy(x2, y2).empty?
      for event in $game_map.events_xy(x2, y2)
        return true if event.accessible
      end
    end
    if !$game_map.events_xy(x, y).empty?
      #no need to check current location
    else
      return false unless map_passable?(x, y, d)
    end
    #return false unless map_passable?(x, y, d)
    #PATCH
    return false unless map_passable?(x2, y2, reverse_dir(d))
    return false if collide_with_characters?(x2, y2)
    return true
  end
  #--------------------------------------------------------------------------
  # ● まっすぐに移動
  #     d       : 方向(2,4,6,8)
  #     turn_ok : その場での向き変更を許可
  #--------------------------------------------------------------------------
  def move_straight(d, turn_ok = true)
    @move_succeed = passableEx?(@x, @y, d)
    if @move_succeed
      set_direction(d)
      @x = $game_map.round_x_with_direction(@x, d)
      @y = $game_map.round_y_with_direction(@y, d)
      @real_x = $game_map.x_with_direction(@x, reverse_dir(d))
      @real_y = $game_map.y_with_direction(@y, reverse_dir(d))
      increase_steps
    elsif turn_ok
      set_direction(d)
      check_event_trigger_touch_front
    end
  end
end

#==============================================================================
# ** Game_Player
#------------------------------------------------------------------------------
#  This class handles maps. It includes event starting determinants and map
# scrolling functions. The instance of this class is referenced by $game_map.
#==============================================================================
class Game_Player < Game_Character
  #--------------------------------------------------------------------------
  # * Get Character
  #     param : if -1, player. If 0, this event. Otherwise, event ID.
  #--------------------------------------------------------------------------
  def get_character(param)
    case param
    when -1   # Player
      return $game_player #self?
    when 0    # This event
      events = $game_map.events
      return events == nil ? nil : events[@event_id]
    else      # Particular event
      events = $game_map.events
      return events == nil ? nil : events[param]
    end
  end
  
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :platformID               # if greater than 0, an event ID
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  alias movingPlatformsPlyr_initializer initialize
  def initialize
    movingPlatformsPlyr_initializer
    @platformID = 0
    @exitingPlatform = false
    @fixingPosition = false
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  alias movingPlatforms_updater update
  def update
    if @platformID > 0
      last_real_x = @real_x
      last_real_y = @real_y
      @x = get_character(@platformID).x
      @y = get_character(@platformID).y
      
      #Get realMoveSpeed & distancePerFrame
      realMoveSpeed = get_character(@platformID).move_speed + 1#(dash? ? 1 : 0)
      distancePerFrame = 2 ** realMoveSpeed / 256.0
      
      temp = @real_x != get_character(@platformID).real_x ||
             @real_y != get_character(@platformID).real_y ? true : false
      if temp && !@fixingPosition
        # Fixing position check
        @fixingPosition=false
        if @real_x != get_character(@platformID).real_x
          if @real_x < get_character(@platformID).real_x
            if get_character(@platformID).real_x <= @real_x + distancePerFrame
              @fixingPosition=true
            end
          end
          if @real_x > get_character(@platformID).real_x
            if get_character(@platformID).real_x >= @real_x - distancePerFrame
              @fixingPosition=true
            end
          end
        end
        if @real_y != get_character(@platformID).real_y
          if @real_y < get_character(@platformID).real_y
            if get_character(@platformID).real_y <= @real_y + distancePerFrame
              @fixingPosition=true
            end
          end
          if @real_y > get_character(@platformID).real_y
            if get_character(@platformID).real_y >= @real_y - distancePerFrame
              @fixingPosition=true
            end
          end
        end
        # Convert to movement
        @real_x = [@real_x - distancePerFrame, @x].max if @x < @real_x
        @real_x = [@real_x + distancePerFrame, @x].min if @x > @real_x
        @real_y = [@real_y - distancePerFrame, @y].max if @y < @real_y
        @real_y = [@real_y + distancePerFrame, @y].min if @y > @real_y
        update_bush_depth unless moving?
        update_animation
      else
        @real_x = get_character(@platformID).real_x
        @real_y = get_character(@platformID).real_y
      end
      
      move_by_input_onPlatform
      if @exitingPlatform
        movingPlatforms_updater
        @platformID = 0
        @exitingPlatform = false
        @fixingPosition = false
      end
      update_scroll(last_real_x, last_real_y)
    else
      movingPlatforms_updater
    end
  end
  #--------------------------------------------------------------------------
  # * Processing of Movement via input from the Directional Buttons
  #--------------------------------------------------------------------------
  def move_by_input_onPlatform
    return unless get_character(@platformID).accessible
    return if !movable? || $game_map.interpreter.running?
    case Input.dir4
    when 2
      move_straight(Input.dir4) if Input.dir4 > 0
      @exitingPlatform = @move_succeed ? true : false
    when 4
      move_straight(Input.dir4) if Input.dir4 > 0
      @exitingPlatform = @move_succeed ? true : false
    when 6
      move_straight(Input.dir4) if Input.dir4 > 0
      @exitingPlatform = @move_succeed ? true : false
    when 8
      move_straight(Input.dir4) if Input.dir4 > 0
      @exitingPlatform = @move_succeed ? true : false
    end
  end
end[/pre]
梦石
0
星屑
29901
在线时间
5734 小时
注册时间
2016-3-8
回帖
1653
 楼主| 发表于 2020-8-6 19:57:07 | 显示全部楼层
本帖最后由 alexncf125 于 2020-8-6 19:58 编辑

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

使用道具 举报

梦石
0
星屑
29901
在线时间
5734 小时
注册时间
2016-3-8
回帖
1653
 楼主| 发表于 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
星屑
29901
在线时间
5734 小时
注册时间
2016-3-8
回帖
1653
 楼主| 发表于 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.

在本版发帖返回顶部