Project1
标题:
关于沉影大大发的显示敌人血条的问题
[打印本页]
作者:
005020671
时间:
2010-11-26 14:01
标题:
关于沉影大大发的显示敌人血条的问题
本帖最后由 005020671 于 2010-11-28 18:19 编辑
下面是脚本,请问这个怎么用到Sideview横版系统里呢,沉影大大说"Sprite_Battler这部分,把我的内容搬到sideview脚本Sprite_Battler同名方法里...",哪位老大能说的具体一点呢???谢谢拉...
这是原帖地址
http://rpg.blue/forum.php?mod=viewthread&tid=134556&highlight=%E8%A1%80%E6%9D%A1
#==============================================================================
# ■ 显示敌人血条 by 沉影不器
#------------------------------------------------------------------------------
# 功能描述:
# ① 战斗时让敌人显示血条,宽度可定制
# ② 可选功能: 显示具体生命值 显示敌人名称
# 使用说明:
# ① 脚本插入到Main之前
# ② 脚本第19行设定血条的默认宽度
# 为个别敌人指定血条宽度是"数据库-敌角色-备注栏"填写"hp_width=数值"
# ③ 脚本第20行选择是否显示具体生命值
# ④ 脚本第21行选择是否显示敌人名称
# ⑤ 其它参数设定详见脚本
# ⑥ 此脚本需要基础脚本[读取rmvx备注栏指定字段]
#==============================================================================
# ■ 参数设定
#==============================================================================
module Enemy_HP
HP_WIDTH = 64 # 血条的默认宽度
SHOW_VALUE = false # 是否显示敌人生命值
SHOW_NAME = true # 是否显示敌人名称
NAME_SIZE = 16 # 敌人名称字体大小
NAME_COLOR = 0 # 敌人名称字体颜色
end
#==============================================================================
# ■ RPG
#==============================================================================
module RPG
class Enemy
def hp_width
return self.read_note('hp_width')
end
end
end
#==============================================================================
# ■ Game_Enemy
#==============================================================================
class Game_Enemy < Game_Battler
#--------------------------------------------------------------------------
# ○ 血条宽度
#--------------------------------------------------------------------------
def hp_width
return $data_enemies[@enemy_id].hp_width
end
end
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
#--------------------------------------------------------------------------
# ◎ 初始化对象
# viewport : 视区
# battler : 战斗者 (Game_Battler)
#--------------------------------------------------------------------------
def initialize(viewport, battler = nil)
super(viewport)
@battler = battler
@battler_visible = false
@effect_type = 0 # 效果种类
@effect_duration = 0 # 效果剩余时间
if @battler.is_a?(Game_Enemy)
width = hp_width + 32
height = 24 + 32
x = @battler.screen_x - width/2
y = @battler.screen_y - height/2
# 调节名称位置
if Enemy_HP::SHOW_NAME
height += Enemy_HP::NAME_SIZE + 2
y -= Enemy_HP::NAME_SIZE + 2
end
# 生成血条窗体
@enemy_hp_window = Window_Base.new(x, y, width, height)
@enemy_hp_window.opacity = 0
@enemy_hp_window.contents_opacity = 0
@enemy_hp_window.contents = Bitmap.new(width - 32, height - 32)
@enemy_hp_window.draw_enemy_info(@battler, 0, 0, width - 32)
# 保存旧血量(控制刷新)
@old_hp = -1
end
end
#--------------------------------------------------------------------------
# ◎ 释放
#--------------------------------------------------------------------------
def dispose
if self.bitmap != nil
self.bitmap.dispose
@enemy_hp_window.dispose
end
super
end
#--------------------------------------------------------------------------
# ◎ 释放敌人活动块
#--------------------------------------------------------------------------
def dispose_enemies
for sprite in @enemy_sprites
sprite.dispose
@enemy_hp_window.dispose
end
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 @enemy_hp_window != nil and @old_hp != @battler.hp
@enemy_hp_window.contents.clear
@enemy_hp_window.draw_enemy_info(@battler, 0, 0, hp_width)
@old_hp = @battler.hp
end
end
end
#--------------------------------------------------------------------------
# ◎ 更新出现效果
#--------------------------------------------------------------------------
def update_appear
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = (16 - @effect_duration) * 16
# 对象非敌人时返回
return unless @battler.is_a?(Game_Enemy)
@enemy_hp_window.contents_opacity = self.opacity
end
#--------------------------------------------------------------------------
# ◎ 更新消失效果
#--------------------------------------------------------------------------
def update_disappear
self.blend_type = 0
self.color.set(0, 0, 0, 0)
self.opacity = 256 - (32 - @effect_duration) * 10
# 对象非敌人时返回
return unless @battler.is_a?(Game_Enemy)
@enemy_hp_window.contents_opacity = self.opacity
end
#--------------------------------------------------------------------------
# ◎ 更新崩溃效果
#--------------------------------------------------------------------------
def update_collapse
self.blend_type = 1
self.color.set(255, 128, 128, 128)
self.opacity = 256 - (48 - @effect_duration) * 6
# 对象非敌人时返回
return unless @battler.is_a?(Game_Enemy)
@enemy_hp_window.contents_opacity = self.opacity
end
#--------------------------------------------------------------------------
# ○ 血条宽度
#--------------------------------------------------------------------------
def hp_width
result = Enemy_HP::HP_WIDTH
if @battler.is_a?(Game_Enemy)
if @battler.hp_width.to_i == 0
result = Enemy_HP::HP_WIDTH
else
result = @battler.hp_width.to_i
end
end
return result
end
end
#==============================================================================
# ■ Window_Base
#==============================================================================
class Window_Base < Window
#--------------------------------------------------------------------------
# ○ 描绘敌人信息
# enemy : 角色
# x : 描绘目标 X 坐标
# y : 描绘目标 Y 坐标
# width : 宽
#--------------------------------------------------------------------------
def draw_enemy_info(enemy, x, y, width = 64)
# 为字体阴影内缩1像素
width -= 1
# 显示名称
if Enemy_HP::SHOW_NAME
self.contents.font.color = text_color(Enemy_HP::NAME_COLOR)
self.contents.font.size = Enemy_HP::NAME_SIZE
self.contents.draw_text(x, y, width, WLH, enemy.name, 1)
self.contents.font.size = Font.default_size
y += Enemy_HP::NAME_SIZE + 2
end
# 描绘血槽
draw_actor_hp_gauge(enemy, x, y, width)
# 描绘生命符号
self.contents.font.color = system_color
self.contents.draw_text(x, y, 30, WLH, Vocab::hp_a)
# 描绘具体生命值
return unless Enemy_HP::SHOW_VALUE
self.contents.font.color = hp_color(enemy)
xr = x + width
self.contents.draw_text(xr - 40, y, 40, WLH, enemy.hp, 2)
end
end
复制代码
作者:
005020671
时间:
2010-11-26 18:29
一箭烂YiJL 兄,你给的那个是没有冲突,可是我想要的效果是战斗时敌人脚下直接能显示血条,而不是只有当指向它时才显示,不过还是谢谢你啦。。。
还有不知道有什么办法能让Sideview横版系统战斗时下方不显示我方血条蓝条,而在我方脚下现实呢,xp就有相关脚本。。。
作者:
一箭烂YiJL
时间:
2010-11-26 22:32
回复
005020671
的帖子
我猜应该是指把上面的编码放进“Sprite_Battler”的代码页中,详见:
横版有三个编码页,把上面的脚本按照每一个函数(def XXX项)
插入叫“Sprite_Battler”的横版的编码页的对照函数里。(重复多余的删掉)
就像这个脚本里的def initialize插进横版“Sprite_Battler”的def initialize,对照下去
(这只是估计而已,最好请到沉大来解答)
作者:
Rion幻音
时间:
2010-11-27 10:31
那就试试这脚本……
#==============================================================================
# ★RGSS2
# STR15_Enemy HP Gauge v1.1a
# By star:http://strcatyou.u-abel.net/
# Translated by Mr. Bubble
#
# ・Show HP gauge of enemies when hit.
# ・You can hide a specified enemy's HP gauge by adding "HIDEHP" to
# the enemy's Notes field in the Database.
# ・Updated with a back attack fix by Moonlight. Use this version ONLY with the
# ATB+SBS scripts.
#------------------------------------------------------------------------------
#==============================================================================
# ★このスクリプトの機能を有効にする
if true
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
# Word used in enemy Notes field to hide HP gauge
GAUGE_M = "HIDEHP"
# Gauge back color [Border color, Inside color]
GAUGE_BC = [Color.new(0,0,0), Color.new(32,48,64)]
# Color gradient [Left, Right]
GAUGE_GC = [Color.new(64,128,96), Color.new(96,192,160)]
#
GAUGE_W = 96 # Gauge width
GAUGE_H = 6 # Gauge height
GAUGE_S = 8 # Gauge speed (more than 2)
GAUGE_T = 640 # Gauge display length (more 510)
GAUGE_O = 16 # Gauge opacity
#
GAUGE_V = false # STR cursor appears when damaged. Requires STRxx Cursor. # ※XP風バトルを導入してない場合は有効にしないでください
#--------------------------------------------------------------------------
# ● ゲージスプライト作成(追加)
#--------------------------------------------------------------------------
def create_enhpgauge
g_width = GAUGE_W # 幅
g_height = GAUGE_H # 高さ
f_color = GAUGE_BC # ゲージバックカラー
g_color = GAUGE_GC # ゲージカラー
# ビットマップ作成
bitmap = Bitmap.new(g_width, g_height * 2)
# 上半分:ゲージバック
bitmap.fill_rect(0, 0, g_width, g_height, f_color[0]) # 枠外
bitmap.fill_rect(1, 1, g_width - 2, g_height - 2, f_color[1]) # 枠内
# 下半分:グラデゲージ
bitmap.gradient_fill_rect(1, g_height + 1, g_width - 2, g_height - 2,
g_color[0], g_color[1]) # グラデ
# スプライト作成 # [0] = ゲージバック; [1] = ゲージ
@hp_gauge = [Sprite.new, Sprite.new]
for i in 0..1
sprite = @hp_gauge[i]
sprite.viewport = self.viewport
sprite.bitmap = bitmap
sprite.src_rect.set(0, 0, g_width, g_height)
sprite.src_rect.y = g_height if i == 1
if $back_attack && N01::BACK_ATTACK && N01::BACK_ATTACK_NON_BACK_MIRROR
sprite.x = Graphics.width - @battler.screen_x
else
sprite.x = @battler.screen_x
end
sprite.y = @battler.screen_y - 8
sprite.ox = g_width / 2
sprite.oy = g_height / 2
sprite.z = 200
sprite.z += 20 if i == 1
sprite.opacity = 0
end
# いろいろ
@enid = @battler.enemy_id
@hp = @battler.hp
@gauge_width = GAUGE_W + 1
@gauge_opacity = 0
end
#--------------------------------------------------------------------------
# ● ゲージ更新(追加)
#--------------------------------------------------------------------------
def enhpgauge_update
# エネミーIDが変動していたらメモの内容を再取得・可視状態も更新
if @enid != @battler.enemy_id
@enid = @battler.enemy_id
@gauge_visible = true
@gauge_visible = false if $data_enemies[@enid].note.include?(GAUGE_M)
for i in @hp_gauge do i.visible = @gauge_visible end
end
return unless @gauge_visible
# ゲージ更新
if @hp != @battler.hp
g_width = (@battler.hp / (@battler.maxhp * 1.0))
@gauge_width = ((GAUGE_W * g_width) + 1).truncate
@gauge_opacity = GAUGE_T
@hp = @battler.hp
end
# 幅
g_width = @hp_gauge[1].src_rect.width
speed = GAUGE_S
rect = @hp_gauge[1].src_rect
rect.width = (@gauge_width + (g_width * (speed - 1))) / speed
if rect.width != @gauge_width
if rect.width > @gauge_width
rect.width -= 1
else
rect.width += 1
end
end
rect.width = 2 if rect.width <= 1 and @hp > 0
# 透明度
if GAUGE_V and @battler.cursor_flash
@gauge_opacity += GAUGE_O * 2 if @gauge_opacity <= GAUGE_T / 2
else
@gauge_opacity -= GAUGE_O if @gauge_opacity > 0
end
# 透明度適用
for i in @hp_gauge do i.opacity = @gauge_opacity end
end
#--------------------------------------------------------------------------
# ● オブジェクト初期化(エイリアス)
#--------------------------------------------------------------------------
alias initialize_str15 initialize
def initialize(viewport, battler = nil)
initialize_str15(viewport, battler)
if @battler.is_a?(Game_Enemy)
create_enhpgauge
@gauge_visible = true
@gauge_visible = false if $data_enemies[@enid].note.include?(GAUGE_M)
for i in @hp_gauge do i.visible = @gauge_visible end
end
end
#--------------------------------------------------------------------------
# ● 解放(エイリアス)
#--------------------------------------------------------------------------
alias dispose_str15 dispose
def dispose
dispose_str15
if @battler.is_a?(Game_Enemy)
@hp_gauge[0].bitmap.dispose
@hp_gauge[0].dispose
@hp_gauge[1].dispose
end
end
#--------------------------------------------------------------------------
# ● フレーム更新(エイリアス)
#--------------------------------------------------------------------------
alias update_str15 update
def update
update_str15
enhpgauge_update if @battler.is_a?(Game_Enemy)
end
end
#
end
复制代码
作者:
一箭烂YiJL
时间:
2010-11-27 10:51
回复
Rion幻音
的帖子
试过后什么都没有。。。。。。楼主要的是和横版不会冲突的。
若是最普通的战斗系统,还要等到斩下去的一刻才有一条青绿色的带子。。。。。。
是我的问题吗?。。。。。。。
作者:
一箭烂YiJL
时间:
2010-11-27 11:41
首先,多谢幻音前辈的脚本
我把它翻译了,还调教了一些有关颜色(让它更好看)了
#==============================================================================
# ★要启用这个脚本
if true
#==============================================================================
# ■ Sprite_Battler
#==============================================================================
class Sprite_Battler < Sprite_Base
# Word used in enemy Notes field to hide HP gauge
GAUGE_M = "HIDEHP"
# 背景色 [边框颜色, 内部颜色]
GAUGE_BC = [Color.new(0,0,0), Color.new(155,205,155)]
# 面层色(渐变效果) [左端, 右端]
GAUGE_GC = [Color.new(255,10,0), Color.new(255,154,0)]
#
GAUGE_W = 96 # 宽度
GAUGE_H = 6 # 高度
GAUGE_S = 8 # 扣减速度(超过2)
GAUGE_T = 650 # 显示帧数 (多于 510)(最多999999999)
GAUGE_O = 16 # 不透明度
#
GAUGE_V = false # 当光标出现可疑损坏。需要STRxx光标。
#--------------------------------------------------------------------------
# ● 绘画血条
#--------------------------------------------------------------------------
def create_enhpgauge
g_width = GAUGE_W # 长
g_height = GAUGE_H # 高
f_color = GAUGE_BC # 背景色
g_color = GAUGE_GC # 面层色
# 图画绘制
bitmap = Bitmap.new(g_width, g_height * 2)
# 上半部分:图画定义,背景色
bitmap.fill_rect(0, 0, g_width, g_height, f_color[0]) # 外框
bitmap.fill_rect(1, 1, g_width - 2, g_height - 2, f_color[1]) # 内部
# 上半部分:图画定义,面层色
bitmap.gradient_fill_rect(1, g_height + 1, g_width - 2, g_height - 2,
g_color[0], g_color[1]) # 层次
# 血条建立 # [0] = 背景色 ; [1] = 面层色
@hp_gauge = [Sprite.new, Sprite.new]
for i in 0..1
sprite = @hp_gauge[i]
sprite.viewport = self.viewport
sprite.bitmap = bitmap
sprite.src_rect.set(0, 0, g_width, g_height)
sprite.src_rect.y = g_height if i == 1
if $back_attack && N01::BACK_ATTACK && N01::BACK_ATTACK_NON_BACK_MIRROR
sprite.x = Graphics.width - @battler.screen_x
else
sprite.x = @battler.screen_x
end
sprite.y = @battler.screen_y - 8
sprite.ox = g_width / 2
sprite.oy = g_height / 2
sprite.z = 200
sprite.z += 20 if i == 1
sprite.opacity = 0
end
# 各种
@enid = @battler.enemy_id
@hp = @battler.hp
@gauge_width = GAUGE_W + 1
@gauge_opacity = 0
end
#--------------------------------------------------------------------------
# ● 血条更新
#--------------------------------------------------------------------------
def enhpgauge_update
# 如果对应ID敌人被伤害的时候需要显示
if @enid != @battler.enemy_id
@enid = @battler.enemy_id
@gauge_visible = true
@gauge_visible = false if $data_enemies[@enid].note.include?(GAUGE_M)
for i in @hp_gauge do i.visible = @gauge_visible end
end
return unless @gauge_visible
# 计算更新
if @hp != @battler.hp
g_width = (@battler.hp / (@battler.maxhp * 1.0))
@gauge_width = ((GAUGE_W * g_width) + 1).truncate
@gauge_opacity = GAUGE_T
@hp = @battler.hp
end
# 长
g_width = @hp_gauge[1].src_rect.width
speed = GAUGE_S
rect = @hp_gauge[1].src_rect
rect.width = (@gauge_width + (g_width * (speed - 1))) / speed
if rect.width != @gauge_width
if rect.width > @gauge_width
rect.width -= 1
else
rect.width += 1
end
end
rect.width = 2 if rect.width <= 1 and @hp > 0
# 透明度
if GAUGE_V and @battler.cursor_flash
@gauge_opacity += GAUGE_O * 2 if @gauge_opacity <= GAUGE_T / 2
else
@gauge_opacity -= GAUGE_O if @gauge_opacity > 0
end
# 透明度適用
for i in @hp_gauge do i.opacity = @gauge_opacity end
end
#--------------------------------------------------------------------------
# ● 对象初始化
#--------------------------------------------------------------------------
alias initialize_str15 initialize
def initialize(viewport, battler = nil)
initialize_str15(viewport, battler)
if @battler.is_a?(Game_Enemy)
create_enhpgauge
@gauge_visible = true
@gauge_visible = false if $data_enemies[@enid].note.include?(GAUGE_M)
for i in @hp_gauge do i.visible = @gauge_visible end
end
end
#--------------------------------------------------------------------------
# ● 解放(dispose)
#--------------------------------------------------------------------------
alias dispose_str15 dispose
def dispose
dispose_str15
if @battler.is_a?(Game_Enemy)
@hp_gauge[0].bitmap.dispose
@hp_gauge[0].dispose
@hp_gauge[1].dispose
end
end
#--------------------------------------------------------------------------
# ● 帧更新
#--------------------------------------------------------------------------
alias update_str15 update
def update
update_str15
enhpgauge_update if @battler.is_a?(Game_Enemy)
end
end
#
end
复制代码
作者:
005020671
时间:
2010-11-28 18:18
回复
Rion幻音
的帖子
谢谢啦。。。
作者:
storm74
时间:
2011-8-22 19:11
首先,多谢幻音前辈的脚本
我把它翻译了,还调教了一些有关颜色(让它更好看)了
小白 用了前辈的翻译的 脚本 想知道怎么才能不用挨打就从战斗一开始就显示敌人的血条呢?
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1