#===============================================================================
# 八方向行走
# by:铅笔描绘的思念
# 在Characters里添加八方向行走图(命名规范:在四方向上的基础上+_8D)
# 行走动画就为8方向的。否则就会原4方向的代替8方向的。
#
# 八方向:数字键盘方向对应的数字
# 7 8 9
# ↖ ↑ ↗
# 4← 0 →6
# ↙ ↓ ↘
# 1 2 3
#===============================================================================
#==============================================================================
# ■ Game_Player
#==============================================================================
class Game_Player < Game_Character
#--------------------------------------------------------------------------
# ● 八方向移动
# d :1、3、7、9 对应小键盘的四个方向
#--------------------------------------------------------------------------
def move_eight_dir(d)
move_diagonal(d + 3,2) if d == 1 || d == 3
move_diagonal(d - 3,8) if d == 7 || d == 9
end
#--------------------------------------------------------------------------
# ● 八方向按键
#--------------------------------------------------------------------------
def move_by_input
return if !movable? || $game_map.interpreter.running?
case Input.dir8
when 1,3,7,9; move_eight_dir(Input.dir8)
when 2,4,6,8; move_straight(Input.dir4)
end
end
#--------------------------------------------------------------------------
# ● 斜向移动
# horz : 横向(4 or 6)
# vert : 纵向(2 or 8)
#--------------------------------------------------------------------------
def move_diagonal(horz, vert)
@followers.move if diagonal_passable?(@x, @y, horz, vert)
@move_succeed = diagonal_passable?(x, y, horz, vert)
last_steps = $game_party.steps
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))
increase_steps
# 八方向移动正确步数计算
if $game_party.steps - last_steps == 2
$game_party.decrease_steps
end
end
set_direction(2) if horz == 4 && vert == 2
set_direction(4) if horz == 4 && vert == 8
set_direction(6) if horz == 6 && vert == 2
set_direction(8) if horz == 6 && vert == 8
end
end
#==============================================================================
# ■ Game_Party
#==============================================================================
class Game_Party < Game_Unit
def decrease_steps
@steps -= 1
end
end
#==============================================================================
# ■ Sprite_Character
#==============================================================================
class Sprite_Character < Sprite_Base
#--------------------------------------------------------------------------
# ● 更新源位图(Source Bitmap)
#--------------------------------------------------------------------------
alias update_bitmap_8dir update_bitmap
def update_bitmap
update_bitmap_8dir
if @tile_id > 0
@enable_slant = false
return
end
unless graphic_changed?
@enable_slant = true
end
begin
@character_name_slant = "#{@character_name}_8D"
Cache.character(@character_name_slant)
rescue
@enable_slant = false
end
end
#--------------------------------------------------------------------------
# ● 更新源矩形
#--------------------------------------------------------------------------
alias update_src_rect_8dir update_src_rect
def update_src_rect
return if @tile_id > 0
if @enable_slant && @character != $game_map.events
update_src_rect_for_slant
else
update_src_rect_8dir
end
end
#--------------------------------------------------------------------------
# ● 更新斜方向传送矩形
#--------------------------------------------------------------------------
def update_src_rect_for_slant
index = @character.character_index
pattern = @character.pattern < 3 ? @character.pattern : 1
sx = (index % 4 * 3 + pattern) * @cw
case Input.dir8 % 2
when 0 # 上下左右
if @last_slant
self.bitmap = Cache.character(@character_name)
@last_slant = false
end
else
unless @last_slant
self.bitmap = Cache.character(@character_name_slant)
@last_slant = true
end
end
sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
self.src_rect.set(sx, sy, @cw, @ch)
end
end