#encoding:utf-8
#==============================================================================
# ■ 多帧4_8方图,4_8向行走
#
# 支持4方图:兼容rmVA原格式图片,4向8向行走
# 支持8方图:从上到下方向为:正、左、右、背、左下、右下、左上、右上
# 对应小键盘:24681379
# 支持开火车,有一定范围的拥挤处理。支持4、8方混合开
# 按住方向键时,碰到障碍物会踏步(可选)
# 可选4、8向行走,在代码开头设置,默认为8向行走
#------------------------------------------------------------------------------
#使用说明:对原rmVA不支持的格式,需要对文件名实行命名规则
# 1.png图片,须仅包含一个人物的全套行走
# 2.图片内容,从左到右,小于99帧;
# 从上到下8个方向:正、左、右、背、左下、右下、左上、右上
# 3.文件命名
# 文件名:角色名+格式串+.png
# name@D#DD%DD.png 其中%DD可选
# @D表示png文件中, 每一列有多少个图。以一位数表示,如8,即8个方向
# #DD表示png文件中,每一行有多少个图。以两位数表示,如06或6,即6帧
# %DD,可选,调整角色在游戏画面中的高度,单位像素。如20,即调低20像素
# 说明:因为如果是精美8方图的话,一般有带阴影,而阴影会比脚低
# 这时可通过%DD来调整人物在画面中的高低
# 有些图片空白过多,也可用此来调整,不用弄PS。
#
#小技巧:★可新建一个工程,以RMVA默认的角色领队开火车,可看出是否对齐
# ★若人物在开火车中挤紧在一起,把其每帧的图片加宽,如>=68像素即可。
#注意: ☆rmVA原格式行走图,停下来会停在第2帧(这是rmVA的默认方法)
# ☆自定义格式行走图,停下来会停在第1帧
# ☆格式串前的name必须在characters文件夹下的png文件中唯一
#------------------------------------------------------------------------------
# by rmav (有任何问题请毫无顾忌滴提出)
#
# v1.0
#==============================================================================
$imported ||= {}
$imported[:rmav_walk] = true
module Rmav
#---------行走选项设置---------#
Opt_walk={
dir8_on: true, #false则4向行走,本插件系列其他功能仍可以用
step_ext_on: true #按着方向键碰到障碍物踏步,若为false则静止(rmVA默认是静止的)
}
INPUT_HV=[[0,0],[4,2],[0,2],[6,2],[4,0],[0,0],[6,0],[4,8],[0,8],[6,8]]
#--------------------------------------------------------------------------
# ● 缓存文件夹中所有png文件名
#--------------------------------------------------------------------------
def self.loadFolder(folderName)
@cache_folder||={}
folderName.gsub!(/\\/,'/')
folderName+='/' if folderName[-1]!='/'
folderName.downcase!
unless @cache_folder.include?(folderName)
@cache_folder[folderName]=[]
Dir.glob(folderName+"*.png"){|f|
@cache_folder[folderName]<<f.split('/')[-1].chomp!('.png').downcase
}
end
@cache_folder[folderName]
end
end
class Sprite_Character
#--------------------------------------------------------------------------
# ● 设置角色的位图(n方向,n帧)
#--------------------------------------------------------------------------
alias_method :set_character_bitmap_org_rmav, :set_character_bitmap
def set_character_bitmap
self.bitmap = Cache.character(@character_name)
@fmt_sign = @character_name[/\@(\d{1,2})\#(\d{1,2})(\%(\d{1,2}))?/]
if @fmt_sign
@fmt_sign=[$1.to_i,$2.to_i,$4.to_i]
@cw = bitmap.width / @fmt_sign[1]
@ch = bitmap.height / @fmt_sign[0]
self.ox = @cw / 2
self.oy = @ch-@fmt_sign[2]
else
set_character_bitmap_org_rmav
end
if @character
@character.cw=@cw
@character.ch=@ch
@character.fmt_sign=@fmt_sign
@character.original_pattern=0 if @fmt_sign
end
end
#--------------------------------------------------------------------------
# ● 更新源矩形
#--------------------------------------------------------------------------
def update_src_rect
if @tile_id == 0
index = @character.character_index
pattern = @character.pattern < (@fmt_sign?@fmt_sign[1]:3) \
? @character.pattern : 1
sx = (index % 4 * 3 + pattern) * @cw
sy = (index / 4 * 4 + (@character.direction - 2) / 2) * @ch
case @character.direction
when 1; sy=@fmt_sign?(@fmt_sign[0]==4?0:4)*@ch:(index / 4 * 4 ) * @ch
when 3; sy=@fmt_sign?(@fmt_sign[0]==4?0:5)*@ch:(index / 4 * 4 ) * @ch
when 7; sy=@fmt_sign?(@fmt_sign[0]==4?3:6)*@ch:(index / 4 * 4+3 ) * @ch
when 9; sy=@fmt_sign?(@fmt_sign[0]==4?3:7)*@ch:(index / 4 * 4+3 ) * @ch
end
self.src_rect.set(sx, sy, @cw, @ch)
end
end
end
class Game_Player
if Rmav::Opt_walk[:dir8_on]
#--------------------------------------------------------------------------
# ● 由方向键移动,8方向
#--------------------------------------------------------------------------
def move_by_input
return if !movable? || $game_map.interpreter.running?
input=Input.dir8
move_diagonal(*Rmav::INPUT_HV[input]) if input > 0
end
end
#--------------------------------------------------------------------------
# ● 更新步行/踏步动画
#--------------------------------------------------------------------------
alias_method :update_animation_org_rmav,:update_animation
def update_animation
if stopping? && @stop_count<1
@step_ext_anime=true
else
@step_ext_anime=false
end
super
end
end
class Game_CharacterBase
attr_accessor :cw,:ch,:fmt_sign,:original_pattern,:step_ext_anime
alias_method :characterBase_init_org_rmav, :initialize
def initialize
characterBase_init_org_rmav
@cw=@ch=0
@fmt_sign=nil
@step_ext_anime=false
end
#--------------------------------------------------------------------------
# ● 斜向移动
# horz : 横向(4 or 6)
# vert : 纵向(2 or 8)
#--------------------------------------------------------------------------
alias_method :charBase_move_diagonal_org_rmav, :move_diagonal
def move_diagonal(horz, vert, turn_ok = true)
unless turn_ok
charBase_move_diagonal_org_rmav(horz, vert)
return
end
@move_succeed = diagonal_passable?(x, y, horz, vert)
if @move_succeed
set_direction(Rmav::INPUT_HV.index([horz, vert]))
@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
elsif turn_ok
set_direction(Rmav::INPUT_HV.index([horz, vert]))
check_event_trigger_touch_front
end
end
#--------------------------------------------------------------------------
# ● 更新动画图案
#--------------------------------------------------------------------------
def update_anime_pattern
if !@step_anime && @stop_count > 0
@pattern = @original_pattern
else
@pattern = (@pattern + 1) % (@fmt_sign?@fmt_sign[1]:4)
end
end
#--------------------------------------------------------------------------
# ● 更新动画计数
#--------------------------------------------------------------------------
alias_method :update_anime_count_org_rmav,:update_anime_count
def update_anime_count
if Rmav::Opt_walk[:step_ext_on] && !(moving? && @walk_anime) && @step_ext_anime
@anime_count += 1
else
update_anime_count_org_rmav
end
end
end
class Game_Follower
attr_accessor :gathering
alias_method :follower_initialize_org_rmav, :initialize
def initialize(member_index, preceding_character)
follower_initialize_org_rmav(member_index, preceding_character)
@gathering=false
end
#--------------------------------------------------------------------------
# ● 追随带队角色
#--------------------------------------------------------------------------
def chase_preceding_character
unless moving?
sx = distance_x_from(@preceding_character.x)
sy = distance_y_from(@preceding_character.y)
dx_pix=[(@preceding_character.cw+@cw)/2, 79].min
if !@gathering && dx_pix > sx.abs*32+16
if sy>0
return if (@ch>32+16&&sy<2)
elsif sy<0
return if (@preceding_character.ch>32+16&&sy.abs<2)
else
return
end
end
if sx != 0 && sy != 0
move_diagonal(sx > 0 ? 4 : 6, sy > 0 ? 8 : 2)
elsif sx != 0
move_straight(sx > 0 ? 4 : 6)
elsif sy != 0
move_straight(sy > 0 ? 8 : 2)
end
end
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
alias_method :update_org_rmav,:update
def update
@step_ext_anime = $game_player.step_ext_anime
@stop_count=0 if @step_ext_anime
update_org_rmav
end
end
class Game_Followers
#--------------------------------------------------------------------------
# ● 集合
#--------------------------------------------------------------------------
alias_method :gather_org_rmav,:gather
def gather
gather_org_rmav
visible_folloers.each {|follower| follower.gathering=true }
end
#--------------------------------------------------------------------------
# ● 判定是否集合完毕
#--------------------------------------------------------------------------
alias_method :gather_org_rmav?,:gather?
def gather?
ok = gather_org_rmav?
if ok
visible_folloers.each {|follower| follower.gathering=false }
end
ok
end
end