Project1
标题:
求一个显示掉血的脚本
[打印本页]
作者:
zxc123a4s5d6
时间:
2015-8-21 16:43
标题:
求一个显示掉血的脚本
就是当造成伤害时,敌人战斗图上跳出红色的数字,然后消失的脚本,刚刚搜索了一下也没看到,就求大神发一个。。
作者:
zdqhzs
时间:
2015-8-21 17:09
是不是要这个?
#==============================================================================
# ■ Sprite_Damage (新增类)
#==============================================================================
class Sprite_Damage < Sprite
#--------------------------------------------------------------------------
# ● 获取/生成伤害值源图
#--------------------------------------------------------------------------
@@obmp = nil
def self.obmp
if @@obmp.nil? or @@obmp.disposed?
@@obmp = Bitmap.new(180, 256)
#@@obmp.font.bold = true #粗黑体
#@@obmp.font.shadow = false #阴影
#@@obmp.font.outline = true #数字外围边框
@@obmp.font.out_color = Color.new(255, 255, 255, 255)
@@obmp.font.size = 32
colors = []
colors.push(Color.new(255, 0, 0, 255))#HP伤害颜色(红)
colors.push(Color.new( 0, 224, 96, 255))#HP回复颜色(亮绿)
colors.push(Color.new( 0, 0, 255, 255))#MP伤害颜色(蓝)
colors.push(Color.new(255, 255, 64, 255))#MP回复颜色(亮黄)
colors.push(Color.new( 0, 0, 0, 255))#TP伤害颜色(深黑)
colors.push(Color.new(255, 255, 255, 255))#TP回复颜色(白)
#Graphics/System/damage.png伤害图8行10列180×256
#第 1 行 HP 伤害数字0~9
#第 2 行 HP 回复数字0~9
#第 3 行 MP 伤害数字0~9
#第 4 行 MP 回复数字0~9
#第 5 行 TP 伤害数字0~9
#第 6 行 TP 回复数字0~9
#第 7 行 左边暴击(Critical)右边 攻击落空(Miss)
#第 8 行 左边闪避(Evasion) 右边 留空
colors.each_with_index do |color, hi| #每个数字占18×32
@@obmp.font.color = color
for wi in 0..9
@@obmp.draw_text(wi * 18, hi * 32, 18, 32, "#{wi}", 1)
end
end
@@obmp.font.size = 24 #字体大小
#@@obmp.font.italic = true #斜体
@@obmp.font.out_color = Color.new(0, 0, 0, 255)
@@obmp.font.color = Color.new(255, 0, 255, 255)#暴击等文字的颜色(亮粉红)
@@obmp.draw_text( 0, 192, 90, 32, "暴击", 1)
@@obmp.draw_text(90, 192, 90, 32, "Miss", 1)
@@obmp.draw_text( 0, 224, 90, 32, "闪避", 1)
#@@obmp.hue_change(0)# 设置伤害值图形的色相 取值范围 0~360
end
return @@obmp
end
#--------------------------------------------------------------------------
# ● 初始化
#--------------------------------------------------------------------------
def initialize(viewport, args)
super(viewport)
@type = args[0] #伤害类型hp、mp、tp
@value = args[1] #伤害值
@critical = args[2] #是否暴击
self.x = args[4]
self.y = args[5]
self.z = args[6] + Graphics.height * 5
make_move(args[3])
refresh
end
#--------------------------------------------------------------------------
# ● 生成移动数据
#--------------------------------------------------------------------------
def make_move(battler_obj_class)
@move = []
case battler_obj_class
when :actor
make_move_actor
when :enemy
make_move_enemy
else
make_move_default
end
end
#--------------------------------------------------------------------------
# ● 生成移动数据 默认
#--------------------------------------------------------------------------
def make_move_default
45.times do |n|
if n % 3 == 0
ady = n < 21 ? -6 : -1
opa = n < 21 ? 255 : 255-(n-21)*6
@move.push([0, ady, opa])
else
@move.push([0, 0, -1])
end
end
end
#--------------------------------------------------------------------------
# ● 生成移动数据 角色
#--------------------------------------------------------------------------
def make_move_actor
make_move_default
end
#--------------------------------------------------------------------------
# ● 生成移动数据 敌人
#--------------------------------------------------------------------------
def make_move_enemy
make_move_default
end
#--------------------------------------------------------------------------
# ● 描绘
#--------------------------------------------------------------------------
def refresh
if not self.bitmap.nil?
self.bitmap.dispose
self.bitmap = nil
end
begin
@obmp = Cache.system("damage")
rescue Errno::ENOENT
@obmp = Sprite_Damage.obmp #找不到伤害值显示图则使用自建的代替图
end
@numw = @obmp.width / 10
@numh = @obmp.height / 8
@strw = @obmp.width / 2
case @value
when Numeric #伤害值是数字
blt_obmp_numeric
when Symbol #伤害值是文字
blt_obmp_text
end
end
#--------------------------------------------------------------------------
# ● 通过源图描绘数字
#--------------------------------------------------------------------------
def blt_obmp_numeric
nums = @value.to_i.abs.to_s.split("")
nbmpw = nums.size * @numw
bmph = @numh
cbmpw = 0
crect = nil
dy = 0
if @critical
cbmpw = @strw
bmph *= 2
crect = Rect.new(0, @numh * 6, @strw, @numh)
dy = @numh
end
self.bitmap = Bitmap.new([nbmpw, cbmpw, 32].max, [bmph, 32].max)
self.ox = bitmap.width / 2
self.oy = bmph /2
bitmap.blt((bitmap.width - cbmpw) / 2, 0, @obmp, crect) if crect
dx = (bitmap.width - nbmpw) / 2
ry = 0
case @type
when :hp
ry = @value >= 0 ? 0 : @numh
when :mp
ry = @value >= 0 ? @numh * 2 : @numh * 3
when :tp
ry = @value >= 0 ? @numh * 4 : @numh * 5
else
return
end
rect = Rect.new(0, ry, @numw, @numh)
nums.each_with_index do |str, i|
rect.x = str.to_i * @numw
bitmap.blt(dx, dy, @obmp, rect)
dx += @numw
end
end
#--------------------------------------------------------------------------
# ● 通过源图描绘文字
#--------------------------------------------------------------------------
def blt_obmp_text
self.bitmap = Bitmap.new([@strw, 32].max, [@numh, 32].max)
self.ox = @strw / 2
self.oy = @numh / 2
rx = ry = 0
case @type
when :miss
rx = @strw
ry = @numh * 6
when :eva
ry = @numh * 7
else
return
end
rect = Rect.new(rx, ry, @strw, @numh)
bitmap.blt(0, 0, @obmp, rect)
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
bitmap.dispose if bitmap
super
end
#--------------------------------------------------------------------------
# ● 移动中判定
#--------------------------------------------------------------------------
def moving?
return (not @move.empty?)
end
#--------------------------------------------------------------------------
# ● 刷新
#--------------------------------------------------------------------------
def update
super
if moving?
ary = @move.shift
self.x += ary[0]
self.y += ary[1]
self.opacity = ary[2] if ary[2] >= 0
end
end
end
#==============================================================================
# ■ Window_BattleLog
#==============================================================================
class Window_BattleLog < Window_Selectable
#--------------------------------------------------------------------------
# ● 显示 MISS (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_miss_for_display_damage_wnd_btlog display_miss
def display_miss(target, item)
target.damage_for_show = [:miss, :miss, false]
hzhj_old_display_miss_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示回避 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_evasion_for_display_damage_wnd_btlog display_evasion
def display_evasion(target, item)
target.damage_for_show = [:eva, :evasion, false]
hzhj_old_display_evasion_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 HP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_hp_damage_for_display_damage_wnd_btlog display_hp_damage
def display_hp_damage(target, item)
return if target.result.hp_damage == 0 && item && !item.damage.to_hp?
value = target.result.hp_damage
critical = target.result.critical
target.damage_for_show = [:hp, value, critical]
hzhj_old_display_hp_damage_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 MP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_mp_damage_for_display_damage_wnd_btlog display_mp_damage
def display_mp_damage(target, item)
return if target.dead? || target.result.mp_damage == 0
value = target.result.mp_damage
critical = target.result.critical
target.damage_for_show = [:mp, value, critical]
hzhj_old_display_mp_damage_for_display_damage_wnd_btlog(target, item)
end
#--------------------------------------------------------------------------
# ● 显示 TP 伤害 (追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_display_tp_damage_for_display_damage_wnd_btlog display_tp_damage
def display_tp_damage(target, item)
return if target.dead? || target.result.tp_damage == 0
value = target.result.tp_damage
critical = target.result.critical
target.damage_for_show = [:tp, value, critical]
hzhj_old_display_tp_damage_for_display_damage_wnd_btlog(target, item)
end
end
#==============================================================================
# ■ Sprite_Base
#==============================================================================
class Sprite_Base < Sprite
#--------------------------------------------------------------------------
# ● 初始化(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_init_for_display_damage_spr_base initialize
def initialize(*args)
hzhj_old_init_for_display_damage_spr_base(*args)
@damage_num_sprites = []
end
#--------------------------------------------------------------------------
# ● 释放(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_dispose_for_display_damage_spr_base dispose
def dispose
hzhj_old_dispose_for_display_damage_spr_base
dispose_damage
end
#--------------------------------------------------------------------------
# ● 判断是否有伤害在显示(新增定义)
#--------------------------------------------------------------------------
def damage?
return (not @damage_num_sprites.empty?)
end
#--------------------------------------------------------------------------
# ● 开始显示伤害(新增定义)
#--------------------------------------------------------------------------
def start_damage(args)
args[4] = x - ox + width / 2
args[5] = y - oy + height / 2
args[6] = z
@damage_num_sprites.push(Sprite_Damage.new(viewport, args))
end
#--------------------------------------------------------------------------
# ● 释放所有伤害显示(新增定义)
#--------------------------------------------------------------------------
def dispose_damage
return unless damage?
@damage_num_sprites.each{|sprite|sprite.dispose}
@damage_num_sprites.clear
end
#--------------------------------------------------------------------------
# ● 刷新(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_update_for_display_damage_spr_base update
def update
hzhj_old_update_for_display_damage_spr_base
update_damage
end
#--------------------------------------------------------------------------
# ● 刷新显示伤害(新增定义)
#--------------------------------------------------------------------------
def update_damage
return unless damage?
@damage_num_sprites.each_with_index do |sprite, i|
if sprite.moving?
sprite.update
else
sprite.dispose
@damage_num_sprites[i] = nil
end
end
@damage_num_sprites.delete(nil)
end
end
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
#--------------------------------------------------------------------------
# ● 刷新(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_update_for_display_damage_spr_battler update
def update
hzhj_old_update_for_display_damage_spr_battler
if @battler
if not @battler.damage_for_show.empty?
#unless @battler.damage_section_displayed
args = @battler.damage_for_show.clone
args[3] = @battler.actor? ? :actor : (@battler.enemy? ? :enemy : nil)
start_damage(args)
#end
@battler.damage_for_show.clear
end
end
end
end
#==============================================================================
# ■ Game_BattlerBase
#==============================================================================
class Game_BattlerBase
#--------------------------------------------------------------------------
# ● 实例变量(新增定义)
#--------------------------------------------------------------------------
attr_accessor :damage_for_show #hzhj_damage
#--------------------------------------------------------------------------
# ● 初始化(追加定义)
#--------------------------------------------------------------------------
alias hzhj_old_init_for_display_damage_game_battler_base initialize
def initialize
@damage_for_show = []
hzhj_old_init_for_display_damage_game_battler_base
end
end
复制代码
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1