bad-end-collector/Scripts/_.24.rb
2024-05-18 13:05:37 -05:00

103 lines
No EOL
3.6 KiB
Ruby
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#==============================================================================
#
# ■
#
# 【内容】
#   自然で滑らかな斜め移動ができるようになります。
#
# 【導入方法】
# スクリプトエディタの「▼ 素材」セクションと「▼ メイン」セクションの間に
#  全文をコピー&ペーストしてください。
#
#==============================================================================
class Game_CharacterBase
#--------------------------------------------------------------------------
# ● まっすぐに移動(再定義)
# d : 方向2,4,6,8
# turn_ok : その場での向き変更を許可
#--------------------------------------------------------------------------
def move_straight(d, turn_ok = true)
@move_succeed = passable?(@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))
@pre_move_x = @pre_move_y = 0
@pre_move_x = d if d == 4 || d == 6
@pre_move_y = d if d == 2 || d == 8
increase_steps
elsif turn_ok
set_direction(d)
check_event_trigger_touch_front
end
end
#--------------------------------------------------------------------------
# ● 斜めに移動(再定義)
# horz : 横方向4 or 6
# vert : 縦方向2 or 8
#--------------------------------------------------------------------------
def move_diagonal(horz, vert)
@move_succeed = diagonal_passable?(x, y, horz, vert)
if @move_succeed
@x = $game_map.round_x_with_direction(@x, horz)
@y = $game_map.round_y_with_direction(@y, vert)
@real_x = $game_map.x_with_direction(@x, reverse_dir(horz))
@real_y = $game_map.y_with_direction(@y, reverse_dir(vert))
@pre_move_x = horz
@pre_move_y = vert
increase_steps
end
set_direction(horz) if @direction == reverse_dir(horz)
set_direction(vert) if @direction == reverse_dir(vert)
end
end
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 方向ボタン入力による移動処理
#--------------------------------------------------------------------------
alias uma005_move_by_input move_by_input
def move_by_input
case Input.dir8
when 1 ; smooth_move_diagonal(4, 2)
when 3 ; smooth_move_diagonal(6, 2)
when 7 ; smooth_move_diagonal(4, 8)
when 9 ; smooth_move_diagonal(6, 8)
else
uma005_move_by_input
end
end
#--------------------------------------------------------------------------
# ● 滑らかな斜め移動処理
#--------------------------------------------------------------------------
def smooth_move_diagonal(horz, vert)
return if !movable? || $game_map.interpreter.running?
if passable?(@x, @y, vert)
if passable?(@x, @y, horz)
if diagonal_passable?(x, y, horz, vert)
move_diagonal(horz, vert)
else
@pre_move_x = 0 if @pre_move_x.nil?
@pre_move_y = 0 if @pre_move_y.nil?
d = Input.dir4 if d.nil?
if diagonal_passable?(x, y, reverse_dir(horz), vert)
d = horz
elsif diagonal_passable?(x, y, horz, reverse_dir(vert))
d = vert
else
d = vert if @pre_move_x > 0
d = horz if @pre_move_y > 0
end
move_straight(d)
end
else
move_straight(vert)
end
else
move_straight(horz)
end
end
end