Project1
标题:
如何自定义战斗动画
[打印本页]
作者:
cc623925
时间:
2015-7-27 19:57
标题:
如何自定义战斗动画
这是VX幻与梦的边缘使用的脚本,上面对Sprite_Battler做了更改,使用文件夹下的图片作为战斗图片。
#==============================================================================
# ■ Sprite_Battler
#------------------------------------------------------------------------------
# 战斗显示用活动块。Game_Battler 类的实例监视、
# 活动块的状态的监视。
#==============================================================================
class Sprite_Battler < Sprite_Base
#--------------------------------------------------------------------------
# ● 定量
#--------------------------------------------------------------------------
WHITEN = 1 # 白色闪光 (行动开始)
BLINK = 2 # 闪烁 (伤害)
APPEAR = 3 # 出现 (出现、复活)
DISAPPEAR = 4 # 消失 (逃走)
COLLAPSE = 5 # 崩坏 (战斗不能)
#--------------------------------------------------------------------------
# ● 定义实例变量
#--------------------------------------------------------------------------
attr_accessor :battler
#--------------------------------------------------------------------------
# ● 初始化对像
# viewport : 视口
# battler : 战斗者 (Game_Battler)
#--------------------------------------------------------------------------
def initialize(viewport, battler = nil)
super(viewport)
@battler = battler
@battler_visible = false
@effect_type = 0 # 效果种类
@effect_duration = 0 # 效果剩余时间
@nx = 0 # 当前的帧数
@xbit = 0 # 当前的图像
@collapse_duration = 0
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
end
super
end
#--------------------------------------------------------------------------
# ● 刷新画面
#--------------------------------------------------------------------------
def update
super
if @battler == nil
self.bitmap = nil
else
@use_sprite = @battler.use_sprite?
if @use_sprite
self.x = @battler.screen_x
self.y = @battler.screen_y
self.z = @battler.screen_z
update_battler_bitmap
end
setup_new_effect
update_effect
if @battler.damage_pop
damage(@battler.hp_damage, @battler.critical , true)
@battler.critical = false
@battler.damage_pop = false
end
if @battler.state?(2)
self.tone.set(0,128,0,64)
else
self.tone.set(0,0,0,0)
end
if @flash_shake_switch == true
self.x = @battler.screen_x
self.y = @battler.screen_y
self.z = @battler.screen_z
@flash_shake_switch = false
end
if @flash_shake != 0 and @battler.hp_damage != nil
case @flash_shake % 4
when 3
self.x = @battler.screen_x - 4
when 2
self.x = @battler.screen_x + 8
when 1
self.x = @battler.screen_x
end
@flash_shake -= 1
elsif @flash_shake == 0
self.x = @battler.screen_x
end
end
end
#--------------------------------------------------------------------------
# ● 刷新传送的位图数据
#--------------------------------------------------------------------------
def update_battler_bitmap
if @battler.battler_name != @battler_name or
@battler.battler_hue != @battler_hue
return if @collapse_duration > 0
@battler_name = @battler.battler_name
@battler_hue = @battler.battler_hue
self.bitmap = Cache.battler(@battler_name, @battler_hue)
@width = bitmap.width
@height = bitmap.height
# self.ox = @width / 2
case @battler.show_type
when 0
@nx = @xbit = 0
when 1 #挨打
@nx = 11
when 2 #防御
@nx = 11
when 3 #胜利
@nx = 11
when 4 #施法
@nx = 11
when 5 #攻击
@nx = @xbit = 0
end
self.oy = @height
if @battler.hidden # or @battler.dead?
self.opacity = 0
end
end
if @battler.show_type == 1 and @nx == @battler.frame * 10 - 1
@battler.stand_act
else
@nx += 1 unless @collapse_duration > 0
end
case @battler.show_type
when 0
@nx %= @battler.frame * 8
@xbit = @nx / 8 * self.bitmap.width / @battler.frame
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
when 1
a = @battler.id == 1 ? 1 : 0
@battler.stand_act if @nx == @battler.frame * 8 - a
@xbit = @nx / 10 * self.bitmap.width / @battler.frame
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
when 2
@xbit = self.bitmap.width / @battler.frame
if @nx % 10 == 4
@battler.screen_x += 2
elsif @nx % 10 == 9
@battler.screen_x -= 2
end
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
@battler.stand_act if @nx == 40
when 3
@xbit = @nx / 10 * self.bitmap.width / @battler.frame unless @nx >( @battler.frame * 10 - 1)
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
when 4
if @nx < ((@battler.frame - 2) * 10 - 1)
@xbit = @nx / 10 * self.bitmap.width / @battler.frame
else
@xbit = ((@nx / 5 )% 2 + (@battler.frame - 2)) * self.bitmap.width / @battler.frame
end
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
when 5
if @nx == @battler.frame * 8 - 1
if @battler.battler_name.split(/_/)[1] != "b2"
@battler.stand_act
else
@battler.frame = 1 ; @nx = @xbit = 0
end
end
@xbit = @nx / 8 * self.bitmap.width / @battler.frame
self.src_rect.set(@xbit, 0, self.bitmap.width / @battler.frame, self.bitmap.height)
end
end
#--------------------------------------------------------------------------
# ● 设置新效果
#--------------------------------------------------------------------------
def setup_new_effect
if @battler.white_flash
@effect_type = WHITEN
@effect_duration = 16
@battler.white_flash = false
end
if @battler.blink
@effect_type = BLINK
@effect_duration = 20
@battler.blink = false
end
if not @battler_visible and @battler.exist?
@effect_type = APPEAR
@effect_duration = 16
@battler_visible = true
end
if @battler_visible and @battler.hidden
@effect_type = DISAPPEAR
@effect_duration = 32
@battler_visible = false
end
if @battler.collapse
@effect_type = COLLAPSE
@effect_duration = 48
@collapse_duration = 48
@battler.collapse = false
@battler_visible = false
#~ 死法之1:升天
#~ @coll.dispose if @coll != nil
#~ @coll = Sprite.new
#~ @coll.bitmap = Bitmap.new("Graphics/Battlers/#{@battler_name}")
#~ @coll.src_rect.set(0, 0, self.bitmap.width / DB::Enemies[@battler.original_name]["待机帧数"], self.bitmap.height)
#~ @coll.ox = self.ox
#~ @coll.oy = self.oy
#~ @coll.opacity = 100
#~ @coll.z = 0
#~ @coll.blend_type = 1
#~ @coll.x = self.x
#~ @coll.y = self.y
#~ 死法之2:两半
#~ self.visible = false
#~ @coll.dispose if @coll != nil
#~ @coll = Sprite.new
#~ @coll.bitmap = Bitmap.new("Graphics/Battlers/#{@battler_name}")
#~ @coll.src_rect.set(0, 0, self.bitmap.width / DB::Enemies[@battler.original_name]["待机帧数"], self.bitmap.height)
#~ @coll.ox = self.ox
#~ @coll.oy = self.oy
#~ @coll.opacity = 100
#~ @coll.z = 0
#~ w = @coll.bitmap.width / DB::Enemies[@battler.original_name]["待机帧数"]
#~ h = @coll.bitmap.height
#~ @coll.x = self.x
#~ @coll.y = self.y + h/2
#~ @coll.src_rect = Rect.new(0,h/2,w,h)
#~ @collq.dispose if @collq != nil
#~ @collq = Sprite.new
#~ @collq.bitmap = Bitmap.new("Graphics/Battlers/#{@battler_name}")
#~ @collq.src_rect.set(0, 0, self.bitmap.width / DB::Enemies[@battler.original_name]["待机帧数"], self.bitmap.height)
#~ @collq.ox = self.ox
#~ @collq.oy = self.oy
#~ @collq.opacity = 255
#~ @collq.z = 0
#~ @collq.x = self.x
#~ @collq.y = self.y
#~ @collq.src_rect = Rect.new(0,0,w,h/2)
#~ 死法之3:波形
self.wave_amp = 6
self.wave_length = 120
self.wave_speed = 960
end
if @battler.animation_id != 0
animation = $data_animations[@battler.animation_id]
mirror = @battler.animation_mirror
start_animation(animation, mirror ,$scene.active_battler )
@battler.animation_id = 0
end
end
#--------------------------------------------------------------------------
# ● 刷新效果
#--------------------------------------------------------------------------
def update_effect
@collapse_duration -= 1 if @collapse_duration > 0
if @effect_duration > 0
@effect_duration -= 1
case @effect_type
when WHITEN
update_whiten
when BLINK
update_blink
when APPEAR
update_appear
when DISAPPEAR
update_disappear
when COLLAPSE
update_collapse
end
end
end
#--------------------------------------------------------------------------
# ● 刷新白色闪光效果
#--------------------------------------------------------------------------
def update_whiten
self.blend_type = 0
self.color.set(255, 255, 255, 128)
self.opacity = 255
self.color.alpha = 128 - (16 - @effect_duration) * 10
end
#--------------------------------------------------------------------------
# ● 刷新闪烁效果
#--------------------------------------------------------------------------
def update_blink
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = 255
self.visible = (@effect_duration % 10 < 5)
end
#--------------------------------------------------------------------------
# ● 刷新出现效果
#--------------------------------------------------------------------------
def update_appear
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = (16 - @effect_duration) * 16
end
#--------------------------------------------------------------------------
# ● 刷新消失效果
#--------------------------------------------------------------------------
def update_disappear
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = 256 - (32 - @effect_duration) * 10
end
#--------------------------------------------------------------------------
# ● 刷新崩坏效果
#--------------------------------------------------------------------------
def update_collapse
#~ self.blend_type = 1
self.color.set(255, 128, 128, 128)
self.opacity = 256 - (48 - @effect_duration) * 6
#~ @coll.y = self.y - (48 - @collapse_duration) * 6
#~ self.opacity = 256 - (48 - @collapse_duration) * 6
#~ @coll.dispose if @collapse_duration == 0
#~ @coll.x = self.x + (48 - @collapse_duration) * 16
#~ @collq.x = self.x - (48 - @collapse_duration) * 16
#~ @coll.opacity = 256 - (48 - @collapse_duration) * 16
#~ @collq.opacity = 256 - (48 - @collapse_duration) * 16
#~ @coll.dispose if @collapse_duration == 0
end
#--------------------------------------------------------------------------
# ● 刷新动画
#--------------------------------------------------------------------------
def update_animation
if @animation_duration > 0
frame_index = @animation.frame_max - (@animation_duration + 3) / 4
if @animation.id == 90 and frame_index == 7
$scene.active_battler.screen_x -= 70
$scene.active_battler.screen_y += 16
end
animation_set_sprites(@animation.frames[frame_index])
for timing in @animation.timings
if timing.flash_scope == 1 and timing.frame == frame_index
t = 1.000 * quanzhong(timing) / @all_quanzhong
t *= 2 if $scene.active_battler.heavy_attack unless $scene.active_battler.nil?
f = false
for i in @animation.timings
next if i.flash_scope != 1
f = true if timing == i
break
end
case @active_battler.action.kind
when 0
@battler.attack_effect(@active_battler,f,t)
when 1
@battler.skill_effect(@active_battler, @active_battler.action.skill ,f,t)
when 2
@battler.item_effect(@active_battler, @active_battler.action.item ,f,t)
end
@damage_string = @battler.hp_damage
@damage_string2 = @battler.mp_damage
if @battler.missed
@damage_string = "未中"
@battler.guard_act
@battler.missed = false
end
if @battler.evaded
@damage_string = "闪避"
@battler.guard_act
@battler.evaded = false
end
if
[email protected]
and
[email protected]
and @battler.hp_damage > 0
if @battler.guarding?
@battler.guard_act
else
if @damage_string.is_a?(Numeric) and @battler.hp_damage > 0
@flash_shake_switch = true
@flash_shake = 12
end
@battler.hurt_act
end
end
damage(@damage_string,@battler.critical,timing == @animation.timings[0])
if @battler.mp_damage != 0
damage(@damage_string2,@battler.critical,timing == @animation.timings[0],1)
end
end
if timing.frame == frame_index
animation_process_timing(timing)
end
end
else
dispose_animation
end
end
#--------------------------------------------------------------------------
# ● 权重计算
# timing : Timing数据 (RPG::Animation::Timing)
#--------------------------------------------------------------------------
def quanzhong(timing)
return timing.flash_scope == 1 ? timing.flash_color.alpha * timing.flash_duration : 0
end
#--------------------------------------------------------------------------
# ● 开始动画
#--------------------------------------------------------------------------
def start_animation(animation, mirror = false, active_battler = nil )
@active_battler = active_battler
dispose_animation
@animation = animation
return if @animation == nil
@animation_mirror = mirror
@animation_duration = @animation.frame_max * 4 + 1
@all_quanzhong = 1
for timing in @animation.timings
@all_quanzhong += quanzhong(timing)
end
load_animation_bitmap
@animation_sprites = []
if @animation.position != 3 or not @@animations.include?(animation)
if @use_sprite
for i in 0..15
sprite = ::Sprite.new(viewport)
sprite.visible = false
@animation_sprites.push(sprite)
end
unless @@animations.include?(animation)
@@animations.push(animation)
end
end
end
if @animation.position == 3
if viewport == nil
@animation_ox = 544 / 2
@animation_oy = 416 / 2
else
@animation_ox = viewport.rect.width / 2
@animation_oy = viewport.rect.height / 2
end
else
@animation_ox = x - ox + width / 2
@animation_oy = y - oy + height / 2
if @animation.position == 0
@animation_oy -= height / 2
elsif @animation.position == 2
@animation_oy += height / 2
end
end
end
#--------------------------------------------------------------------------
# ● damage 伤害弹出
#--------------------------------------------------------------------------
def damage(value, critical,first_timing,type = 0)
dispose_damage if first_timing
if !$scene.active_battler.nil?
return if $scene.active_battler.action.kind == 2 and value == 0
end
if value.is_a?(Numeric)
damage_string = value.abs.to_s
else
damage_string = value.to_s
end
bitmap = Bitmap.new(65, 42)
bitmap.font.name = "黑体"
bitmap.font.size = 20
if value.is_a?(Numeric)
damage_array = damage_string.scan(/./)
damage_x = 32.5 - damage_string.size * 6.5
if value < 0
rect_y = 21
else
rect_y = 0
end
for char in damage_array
number = char.to_i
case type
when 0
bitmap.blt(damage_x, 21, Cache.picture("Damage"),
Rect.new(number * 13, rect_y, 13, 21))
when 1
bitmap.blt(damage_x, 21, Cache.picture("Damage1"),
Rect.new(number * 13, rect_y, 13, 21))
end
damage_x += 13
end
if critical
bitmap.blt(11, 0, Cache.picture("Damage"), Rect.new(87, 42, 43, 21))
end
else
case value
when "未中"
bitmap.blt(11, 21, Cache.picture("Damage"), Rect.new(0, 42, 43, 21))
Audio.se_play("Audio/SE/Evasion.ogg") unless @battler.actor?
when "闪避"
bitmap.blt(11, 21, Cache.picture("Damage"), Rect.new(43, 42, 43, 21))
Audio.se_play("Audio/SE/Evasion.ogg") unless @battler.actor?
else
bitmap.font.color.set(255, 255, 255)
bitmap.draw_text(0, 28, 162, 36, damage_string, 1)
end
end
@_damage_sprite = ::Sprite.new(self.viewport)
@_damage_sprite.bitmap = bitmap
@_damage_sprite.ox = 32
@_damage_sprite.oy = 21
if self.battler.actor?
@_damage_sprite.x = self.x + DB::Actors[self.battler.original_name]["伤距修正"]
else
@_damage_sprite.x = self.x + DB::Enemies[self.battler.original_name]["伤距修正"]
end
@_damage_sprite.y = self.y - self.oy / 2
@_damage_sprite.z = 3000
@_damage_duration = 40
#=======================================
# 修改:推入新的伤害
#=======================================
@_damage.push([@_damage_sprite,@_damage_duration-10,0, rand(30) - 15, rand(3)])
end
#--------------------------------------------------------------------------
# ● SE 与闪烁的时机处理
# timing : Timing数据 (RPG::Animation::Timing)
#--------------------------------------------------------------------------
def animation_process_timing(timing)
timing.se.play if timing.flash_scope != 1 or @damage_string.is_a?(Numeric)
case timing.flash_scope
when 1
if
[email protected]
and
[email protected]
and @battler.hp_damage > 0
self.flash(timing.flash_color, timing.flash_duration * 4)
end
when 2
if viewport != nil
viewport.flash(timing.flash_color, timing.flash_duration * 4)
end
when 3
self.flash(nil, timing.flash_duration * 4)
end
end
end
复制代码
还有这个数据库用来定义每个动画的帧数
module DB
#待机帧数,待机图片宽度,攻击帧数,前进帧数,施法帧数,道具帧数,胜利帧数,
#升级帧数,挨打帧数,虚弱帧数,重攻击帧数,攻击等待,重攻击等待
#伤距修正 = 待机宽度 / 待机帧数 / 2
#攻距修正 约 攻击宽度 / 攻击帧数 / 3
Enemies = {
"麦尔斯" => {"待机帧数"=> 18, "攻击帧数"=> 7, "施法帧数"=> 7,
"攻击等待"=> 24, "施法类型"=> 4, "伤距修正"=> 68,
"攻距修正"=> 95, "攻击动画"=> 81},
"黏怪" => {"待机帧数"=> 4, "攻击帧数"=> 8, "施法帧数"=> 8,
"攻击等待"=> 24, "施法类型"=> 4, "伤距修正"=> 57,
"攻距修正"=> 33, "攻击动画"=>151},
"隐翅虫"=> {"待机帧数"=> 8, "攻击帧数"=> 8, "施法帧数"=> 8,
"攻击等待"=> 28, "施法类型"=> 3, "伤距修正"=> 49,
"攻距修正"=> 10, "攻击动画"=>154},
"毒蜘蛛"=> {"待机帧数"=> 8, "攻击帧数"=> 7, "施法帧数"=> 0,
"攻击等待"=> 24, "施法类型"=> 0, "伤距修正"=> 80,
"攻距修正"=> 0, "攻击动画"=>155},
"熊"=> {"待机帧数"=> 5, "攻击帧数"=> 5, "施法帧数"=> 7,
"攻击等待"=> 36, "施法类型"=> 4, "伤距修正"=> 80,
"攻距修正"=> 70, "攻击动画"=>156},
"蝙蝠"=> {"待机帧数"=> 4, "攻击帧数"=> 8, "施法帧数"=> 8,
"攻击等待"=> 48, "施法类型"=> 4, "伤距修正"=> 80,
"攻距修正"=> 33, "攻击动画"=>152},
"僵尸"=> {"待机帧数"=> 4, "攻击帧数"=> 8, "施法帧数"=> 0,
"攻击等待"=> 24, "施法类型"=> 0, "伤距修正"=> 72,
"攻距修正"=> 50, "攻击动画"=>157},
"侏儒"=> {"待机帧数"=> 4, "攻击帧数"=> 6, "施法帧数"=> 0,
"攻击等待"=> 24, "施法类型"=> 0, "伤距修正"=> 66,
"攻距修正"=> 20, "攻击动画"=>152},
"水鬼"=> {"待机帧数"=> 6, "攻击帧数"=> 6, "施法帧数"=> 0,
"攻击等待"=> 24, "施法类型"=> 0, "伤距修正"=> 50,
"攻距修正"=> 20, "攻击动画"=>158},
"野猴"=> {"待机帧数"=> 6, "攻击帧数"=> 10, "施法帧数"=> 8,
"攻击等待"=> 32, "施法类型"=> 4, "伤距修正"=> 72,
"攻距修正"=> 80, "攻击动画"=>153},
"巨蛾"=> {"待机帧数"=> 6, "攻击帧数"=> 6, "施法帧数"=> 0,
"攻击等待"=> 24, "施法类型"=> 0, "伤距修正"=> 72,
"攻距修正"=> 20, "攻击动画"=>159},
"恐惧之王"=>{"待机帧数"=> 10, "攻击帧数"=> 6, "施法帧数"=> 8,
"攻击等待"=> 24, "施法类型"=> 4, "伤距修正"=> 88,
"攻距修正"=> 0, "攻击动画"=>160},
"蝎子"=> {"待机帧数"=> 6, "攻击帧数"=> 8, "施法帧数"=> 5,
"攻击等待"=> 16, "施法类型"=> 3, "伤距修正"=> 50,
"攻距修正"=> 33, "攻击动画"=>161},
"蜈蚣"=> {"待机帧数"=> 8, "攻击帧数"=> 7, "施法帧数"=> 8,
"攻击等待"=> 24, "施法类型"=> 1, "伤距修正"=> 72,
"攻距修正"=> 20, "攻击动画"=>162},
"剧毒蝎子"=>{"待机帧数"=> 6, "攻击帧数"=> 8, "施法帧数"=> 5,
"攻击等待"=> 16, "施法类型"=> 3, "伤距修正"=> 50,
"攻距修正"=> 33, "攻击动画"=>161}
}
Actors = {
"赛特" => {"待机帧数"=> 10, "攻击帧数"=> 6, "施法帧数"=> 9,
"前进帧数"=> 6, "道具帧数"=> 6, "胜利帧数"=> 7,
"升级帧数"=> 8, "挨打帧数"=> 5, "虚弱帧数"=> 8,
"重攻帧数"=> 12, "攻击等待"=> 16, "重攻等待"=> 18,
"施法类型"=> 4, "伤距修正"=> 80,},
"妮可" => {"待机帧数"=> 10, "攻击帧数"=> 6, "施法帧数"=> 16,
"前进帧数"=> 2, "道具帧数"=> 6, "胜利帧数"=> 11,
"升级帧数"=> 11, "挨打帧数"=> 5, "虚弱帧数"=> 10,
"重攻帧数"=> 12, "攻击等待"=> 24, "重攻等待"=> 80,
"施法类型"=> 3, "伤距修正"=> 76,}
}
#属性设置
Elements = {"赛特" => "火" , "妮可" => "暗"}
#绝技设置 [帧数,x偏移,y偏移]
USkill = {"赛特" => [nil,[30,-44,11]] , "妮可" => [nil,[20,45,-10]]}
#战斗背景设置
BattleBack = {"树林" => [5,6,7,8,9] , "下水道" => [3] , "山洞" => [12]}
end
复制代码
如何在VA中也有这样的设定呢?要怎样更改。请教
作者:
冷峻逸
时间:
2015-7-28 13:32
提示:
作者被禁止或删除 内容自动屏蔽
作者:
cc623925
时间:
2015-7-28 14:33
冷峻逸 发表于 2015-7-28 13:32
修改素材文件
脚本不能直接在VA中使用,要怎么弄。。。
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1