赞 | 3 |
VIP | 0 |
好人卡 | 0 |
积分 | 22 |
经验 | 46374 |
最后登录 | 2024-11-12 |
在线时间 | 1011 小时 |
Lv3.寻梦者
- 梦石
- 0
- 星屑
- 2180
- 在线时间
- 1011 小时
- 注册时间
- 2015-10-17
- 帖子
- 1285
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 fjm 于 2020-4-5 15:47 编辑
用了下面这个脚本,战斗时频繁出现游戏停止的提示,问下哪里出了问题,知道的指点下,谢谢
#encoding:utf-8 #============================================================================== # ■ Sprite_Hp #------------------------------------------------------------------------------ # 显示血条的精灵。根据 绑定敌人 的状态自动变化。 #============================================================================== class Sprite_Hp < Sprite #-------------------------------------------------------------------------- # ● 初始化常量 #-------------------------------------------------------------------------- H = 36 #位图 高度 DUR = 0.5 #动画 持续时间 FPS = 60 #每秒 帧数 #-------------------------------------------------------------------------- # ● 初始化对象 #-------------------------------------------------------------------------- def initialize( viewport, enemy) super(viewport) initPara(enemy) create_bitmap update end #-------------------------------------------------------------------------- # ● 初始化参数 #-------------------------------------------------------------------------- def initPara(enemy) @enemy = enemy #绑定敌人 @colorset = [ MyColor.darkGreen, MyColor.green, MyColor.blue, MyColor.purple, MyColor.yellow] #不同管血条的颜色,可以Color.new(r,g,b,a)来设置 @life = getLife.to_i #获取生命数 @tmphp = enemy.hp #用于动画的 临时血量 @tmpname = enemy.name #用于敌人的 名字 @perlife = ( @life == 0 ? enemy.hp : enemy.hp/@life) #每条命的血量 @dvalue = 0 #临时血量差值 @ANIMA = false #动画状态 setPara(@enemy.enemy.note) @nameRect = Rect.new( 0, 0, @length, 18) #名称矩形 @bgRect = Rect.new( 0, 18, @length, 18) #背景矩形 @hlRect = Rect.new( 4, 20, @length - 16, 8) #高光矩形 end #-------------------------------------------------------------------------- # ● 设置参数(通过 注释) #-------------------------------------------------------------------------- def setPara(note) @offsetX = (/<OFFSETX\s*(\d+)>/ =~ note ? $1.to_i : 0) @offsetY = (/<OFFSETY\s*(\d+)>/ =~ note ? $1.to_i : -20) @length = (/<LEN\s*(\d+)>/ =~ note ? $1.to_i : 128) #为了绘制高光,建议设置为 8 的倍数 end #-------------------------------------------------------------------------- # ● 释放 #-------------------------------------------------------------------------- def dispose self.bitmap.dispose super end #-------------------------------------------------------------------------- # ● 生成位图 #-------------------------------------------------------------------------- def create_bitmap self.bitmap = Bitmap.new( @length, H) self.bitmap.fill_rect( @bgRect, color2) #绘制背景矩形 self.bitmap.font.size = 16 self.bitmap.font.bold = true self.bitmap.font.italic = false self.bitmap.font.color.set(255, 255, 255) end #-------------------------------------------------------------------------- # ● 底层颜色(始终填充整个矩形) #-------------------------------------------------------------------------- def color1 if @life == 0 MyColor.darkBlue else @colorset[@life % @colorset.size - 1] end end #-------------------------------------------------------------------------- # ● 血条颜色(变动矩形) #-------------------------------------------------------------------------- def color2 @colorset[@life % @colorset.size ] end #-------------------------------------------------------------------------- # ● 获取生命条数 #-------------------------------------------------------------------------- def getLife /<LIFE\s*(\d+)>/ =~ @enemy.enemy.note ? $1.to_s : 0 end #-------------------------------------------------------------------------- # ● 血条长度 #-------------------------------------------------------------------------- def flexlen if @tmphp % @perlife != 0 return (@tmphp % @perlife) * @length / @perlife end if (@tmphp != 0) && (@tmphp % @perlife == 0) return @length end end #-------------------------------------------------------------------------- # ● 更新画面 #-------------------------------------------------------------------------- def update super update_tmphp update_life update_bitmap update_position update_visibility end #-------------------------------------------------------------------------- # ● 更新临时血量(tmp Hp) #-------------------------------------------------------------------------- def update_tmphp if !@anima && (@tmphp != @enemy.hp) @dvalue = @tmphp - @enemy.hp @anima = true @tmphp = @tmphp - @dvalue/(DUR * FPS) elsif @anima && (@tmphp == @enemy.hp) @anima = false elsif @anima && (@tmphp != @enemy.hp) @tmphp = @tmphp - @dvalue/(DUR * FPS) @tmphp = @enemy.hp if @tmphp < @enemy.hp end end #-------------------------------------------------------------------------- # ● 更新命数(life) #-------------------------------------------------------------------------- def update_life @life = @life - 1 if @tmphp/@perlife < @life end #-------------------------------------------------------------------------- # ● 更新源位图(Source Bitmap) #-------------------------------------------------------------------------- def update_bitmap redraw end #-------------------------------------------------------------------------- # ● 重绘 #-------------------------------------------------------------------------- def redraw self.bitmap.clear self.bitmap.fill_rect( @bgRect, color1) #绘制背景矩形 self.bitmap.fill_rect( @bgRect.x, @bgRect.y, flexlen, @bgRect.height, color2) if @tmphp != 0 #绘制血条矩形 self.bitmap.draw_border( @bgRect, MyColor.darkBlue, 2) #绘制边框 draw_highlight( @hlRect) #绘制高光 self.bitmap.draw_text(self.bitmap.rect, life_text, 2) if @life != 0 #绘制生命数(当生命数不为0) self.bitmap.draw_text(@bgRect, @tmphp.to_i.to_s, 1) #绘制生命值 self.bitmap.draw_text(0, 0, 120, 24, @tmpname) #绘制敌人名字 end #-------------------------------------------------------------------------- # ● 绘制高光 #-------------------------------------------------------------------------- def draw_highlight( dest_rect) leftCorner = Rect.new(0,0,8,8) middle = Rect.new(8,0,8,8) rightCorner = Rect.new(16,0,8,8) pic = Cache.picture("hightLight01") x = dest_rect.x y = dest_rect.y i = 1 self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, leftCorner) while x < (dest_rect.x + dest_rect.width - 8) x = x + 8 self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, middle) end x = x + 8 self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, rightCorner) end #-------------------------------------------------------------------------- # ● 生成绘制内容 #-------------------------------------------------------------------------- def life_text sprintf("x%2d", @life) end #-------------------------------------------------------------------------- # ● 更新位置 #-------------------------------------------------------------------------- def update_position self.x = @enemy.screen_x - self.bitmap.width/2 + @offsetX-125 #血条位置 self.y = @enemy.screen_y + @offsetY -20 #血条位置 self.z = 200 end #-------------------------------------------------------------------------- # ● 更新可视状态 #-------------------------------------------------------------------------- def update_visibility self.visible = true if @enemy.hp != 0 self.visible = false if (@enemy.hp == 0) && !@anima end end #encoding:utf-8 #============================================================================== # ■ Spriteset_Battle #------------------------------------------------------------------------------ # 处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。 #============================================================================== class Spriteset_Battle #-------------------------------------------------------------------------- # ● 初始化对象 #-------------------------------------------------------------------------- def initialize create_viewports create_battleback1 create_battleback2 create_enemies create_actors create_pictures create_timer create_hp update end #-------------------------------------------------------------------------- # ● Hp 精灵生成 #-------------------------------------------------------------------------- def create_hp @hp_sprites = $game_troop.members.reverse.collect do |enemy| Sprite_Hp.new(@viewport1, enemy) end end #-------------------------------------------------------------------------- # ● 更新画面 #-------------------------------------------------------------------------- def update update_battleback1 update_battleback2 update_enemies update_actors update_pictures update_timer update_hp update_viewports end #-------------------------------------------------------------------------- # ● 更新敌人的精灵 #-------------------------------------------------------------------------- def update_hp @hp_sprites.each {|sprite| sprite.update } end end #encoding:utf-8 #============================================================================== # ■ Bitmap_extension #------------------------------------------------------------------------------ # Bitmap类的扩展 #============================================================================== class Bitmap #-------------------------------------------------------------------------- # ● 绘制边框 #-------------------------------------------------------------------------- def draw_border( x, y, width, height, color, thick) self.fill_rect( x, y, width, thick, color) self.fill_rect( x + width - thick, y, thick, height, color) self.fill_rect( x, y + height - thick, width, thick, color) self.fill_rect( x, y, thick, height, color) end #-------------------------------------------------------------------------- # ● 绘制边框 参数为 Rect #-------------------------------------------------------------------------- def draw_border( rect, color, thick) self.fill_rect( rect.x, rect.y, rect.width, thick, color) self.fill_rect( rect.x + rect.width - thick, rect.y, thick, rect.height, color) self.fill_rect( rect.x, rect.y + rect.height - thick, rect.width, thick, color) self.fill_rect( rect.x, rect.y, thick, rect.height, color) end end #encoding:utf-8 #============================================================================== # ■ Color_extension #------------------------------------------------------------------------------ # mColor类,包含常用色 #============================================================================== class MyColor #-------------------------------------------------------------------------- # ● 常用的颜色 #-------------------------------------------------------------------------- def self.black ; Color.new( 0, 0, 0) end def self.white ; Color.new( 255, 255, 255) end def self.red ; Color.new( 255, 0, 0) end def self.green ; Color.new( 0, 255, 0) end def self.blue ; Color.new( 0, 0, 255) end def self.gray ; Color.new( 128, 128, 128) end def self.yellow ; Color.new( 255, 255, 0) end def self.purple ; Color.new( 255, 0, 255) end def self.darkRed ; Color.new( 128, 0, 0) end def self.darkGreen;Color.new( 0, 128, 0) end def self.darkBlue; Color.new( 0, 0, 128) end def self.lighRed ; Color.new( 255, 128, 128) end end
#encoding:utf-8
#==============================================================================
# ■ Sprite_Hp
#------------------------------------------------------------------------------
# 显示血条的精灵。根据 绑定敌人 的状态自动变化。
#==============================================================================
class Sprite_Hp < Sprite
#--------------------------------------------------------------------------
# ● 初始化常量
#--------------------------------------------------------------------------
H = 36 #位图 高度
DUR = 0.5 #动画 持续时间
FPS = 60 #每秒 帧数
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize( viewport, enemy)
super(viewport)
initPara(enemy)
create_bitmap
update
end
#--------------------------------------------------------------------------
# ● 初始化参数
#--------------------------------------------------------------------------
def initPara(enemy)
@enemy = enemy #绑定敌人
@colorset = [ MyColor.darkGreen, MyColor.green, MyColor.blue, MyColor.purple, MyColor.yellow] #不同管血条的颜色,可以Color.new(r,g,b,a)来设置
@life = getLife.to_i #获取生命数
@tmphp = enemy.hp #用于动画的 临时血量
@tmpname = enemy.name #用于敌人的 名字
@perlife = ( @life == 0 ? enemy.hp : enemy.hp/@life)
#每条命的血量
@dvalue = 0 #临时血量差值
@ANIMA = false #动画状态
setPara(@enemy.enemy.note)
@nameRect = Rect.new( 0, 0, @length, 18) #名称矩形
@bgRect = Rect.new( 0, 18, @length, 18) #背景矩形
@hlRect = Rect.new( 4, 20, @length - 16, 8) #高光矩形
end
#--------------------------------------------------------------------------
# ● 设置参数(通过 注释)
#--------------------------------------------------------------------------
def setPara(note)
@offsetX = (/<OFFSETX\s*(\d+)>/ =~ note ? $1.to_i : 0)
@offsetY = (/<OFFSETY\s*(\d+)>/ =~ note ? $1.to_i : -20)
@length = (/<LEN\s*(\d+)>/ =~ note ? $1.to_i : 128)
#为了绘制高光,建议设置为 8 的倍数
end
#--------------------------------------------------------------------------
# ● 释放
#--------------------------------------------------------------------------
def dispose
self.bitmap.dispose
super
end
#--------------------------------------------------------------------------
# ● 生成位图
#--------------------------------------------------------------------------
def create_bitmap
self.bitmap = Bitmap.new( @length, H)
self.bitmap.fill_rect( @bgRect, color2) #绘制背景矩形
self.bitmap.font.size = 16
self.bitmap.font.bold = true
self.bitmap.font.italic = false
self.bitmap.font.color.set(255, 255, 255)
end
#--------------------------------------------------------------------------
# ● 底层颜色(始终填充整个矩形)
#--------------------------------------------------------------------------
def color1
if @life == 0
MyColor.darkBlue
else
@colorset[@life % @colorset.size - 1]
end
end
#--------------------------------------------------------------------------
# ● 血条颜色(变动矩形)
#--------------------------------------------------------------------------
def color2
@colorset[@life % @colorset.size ]
end
#--------------------------------------------------------------------------
# ● 获取生命条数
#--------------------------------------------------------------------------
def getLife
/<LIFE\s*(\d+)>/ =~ @enemy.enemy.note ? $1.to_s : 0
end
#--------------------------------------------------------------------------
# ● 血条长度
#--------------------------------------------------------------------------
def flexlen
if @tmphp % @perlife != 0
return (@tmphp % @perlife) * @length / @perlife
end
if (@tmphp != 0) && (@tmphp % @perlife == 0)
return @length
end
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
super
update_tmphp
update_life
update_bitmap
update_position
update_visibility
end
#--------------------------------------------------------------------------
# ● 更新临时血量(tmp Hp)
#--------------------------------------------------------------------------
def update_tmphp
if !@anima && (@tmphp != @enemy.hp)
@dvalue = @tmphp - @enemy.hp
@anima = true
@tmphp = @tmphp - @dvalue/(DUR * FPS)
elsif @anima && (@tmphp == @enemy.hp)
@anima = false
elsif @anima && (@tmphp != @enemy.hp)
@tmphp = @tmphp - @dvalue/(DUR * FPS)
@tmphp = @enemy.hp if @tmphp < @enemy.hp
end
end
#--------------------------------------------------------------------------
# ● 更新命数(life)
#--------------------------------------------------------------------------
def update_life
@life = @life - 1 if @tmphp/@perlife < @life
end
#--------------------------------------------------------------------------
# ● 更新源位图(Source Bitmap)
#--------------------------------------------------------------------------
def update_bitmap
redraw
end
#--------------------------------------------------------------------------
# ● 重绘
#--------------------------------------------------------------------------
def redraw
self.bitmap.clear
self.bitmap.fill_rect( @bgRect, color1) #绘制背景矩形
self.bitmap.fill_rect( @bgRect.x, @bgRect.y, flexlen, @bgRect.height, color2) if @tmphp != 0
#绘制血条矩形
self.bitmap.draw_border( @bgRect, MyColor.darkBlue, 2)
#绘制边框
draw_highlight( @hlRect)
#绘制高光
self.bitmap.draw_text(self.bitmap.rect, life_text, 2) if @life != 0
#绘制生命数(当生命数不为0)
self.bitmap.draw_text(@bgRect, @tmphp.to_i.to_s, 1)
#绘制生命值
self.bitmap.draw_text(0, 0, 120, 24, @tmpname)
#绘制敌人名字
end
#--------------------------------------------------------------------------
# ● 绘制高光
#--------------------------------------------------------------------------
def draw_highlight( dest_rect)
leftCorner = Rect.new(0,0,8,8)
middle = Rect.new(8,0,8,8)
rightCorner = Rect.new(16,0,8,8)
pic = Cache.picture("hightLight01")
x = dest_rect.x
y = dest_rect.y
i = 1
self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, leftCorner)
while x < (dest_rect.x + dest_rect.width - 8)
x = x + 8
self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, middle)
end
x = x + 8
self.bitmap.stretch_blt(Rect.new( x, y, 8, 8), pic, rightCorner)
end
#--------------------------------------------------------------------------
# ● 生成绘制内容
#--------------------------------------------------------------------------
def life_text
sprintf("x%2d", @life)
end
#--------------------------------------------------------------------------
# ● 更新位置
#--------------------------------------------------------------------------
def update_position
self.x = @enemy.screen_x - self.bitmap.width/2 + @offsetX-125 #血条位置
self.y = @enemy.screen_y + @offsetY -20 #血条位置
self.z = 200
end
#--------------------------------------------------------------------------
# ● 更新可视状态
#--------------------------------------------------------------------------
def update_visibility
self.visible = true if @enemy.hp != 0
self.visible = false if (@enemy.hp == 0) && !@anima
end
end
#encoding:utf-8
#==============================================================================
# ■ Spriteset_Battle
#------------------------------------------------------------------------------
# 处理战斗画面的精灵的类。本类在 Scene_Battle 类的内部使用。
#==============================================================================
class Spriteset_Battle
#--------------------------------------------------------------------------
# ● 初始化对象
#--------------------------------------------------------------------------
def initialize
create_viewports
create_battleback1
create_battleback2
create_enemies
create_actors
create_pictures
create_timer
create_hp
update
end
#--------------------------------------------------------------------------
# ● Hp 精灵生成
#--------------------------------------------------------------------------
def create_hp
@hp_sprites = $game_troop.members.reverse.collect do |enemy|
Sprite_Hp.new(@viewport1, enemy)
end
end
#--------------------------------------------------------------------------
# ● 更新画面
#--------------------------------------------------------------------------
def update
update_battleback1
update_battleback2
update_enemies
update_actors
update_pictures
update_timer
update_hp
update_viewports
end
#--------------------------------------------------------------------------
# ● 更新敌人的精灵
#--------------------------------------------------------------------------
def update_hp
@hp_sprites.each {|sprite| sprite.update }
end
end
#encoding:utf-8
#==============================================================================
# ■ Bitmap_extension
#------------------------------------------------------------------------------
# Bitmap类的扩展
#==============================================================================
class Bitmap
#--------------------------------------------------------------------------
# ● 绘制边框
#--------------------------------------------------------------------------
def draw_border( x, y, width, height, color, thick)
self.fill_rect( x, y, width, thick, color)
self.fill_rect( x + width - thick, y, thick, height, color)
self.fill_rect( x, y + height - thick, width, thick, color)
self.fill_rect( x, y, thick, height, color)
end
#--------------------------------------------------------------------------
# ● 绘制边框 参数为 Rect
#--------------------------------------------------------------------------
def draw_border( rect, color, thick)
self.fill_rect( rect.x, rect.y, rect.width, thick, color)
self.fill_rect( rect.x + rect.width - thick, rect.y, thick, rect.height, color)
self.fill_rect( rect.x, rect.y + rect.height - thick, rect.width, thick, color)
self.fill_rect( rect.x, rect.y, thick, rect.height, color)
end
end
#encoding:utf-8
#==============================================================================
# ■ Color_extension
#------------------------------------------------------------------------------
# mColor类,包含常用色
#==============================================================================
class MyColor
#--------------------------------------------------------------------------
# ● 常用的颜色
#--------------------------------------------------------------------------
def self.black ; Color.new( 0, 0, 0) end
def self.white ; Color.new( 255, 255, 255) end
def self.red ; Color.new( 255, 0, 0) end
def self.green ; Color.new( 0, 255, 0) end
def self.blue ; Color.new( 0, 0, 255) end
def self.gray ; Color.new( 128, 128, 128) end
def self.yellow ; Color.new( 255, 255, 0) end
def self.purple ; Color.new( 255, 0, 255) end
def self.darkRed ; Color.new( 128, 0, 0) end
def self.darkGreen;Color.new( 0, 128, 0) end
def self.darkBlue; Color.new( 0, 0, 128) end
def self.lighRed ; Color.new( 255, 128, 128) end
end
|
|