Premetto di non avere alcuna competenza sul Ruby. In un progetto (con combattimento in tempo reale) sto usando un HUD, e mi sono chiesto se può essere usato anche durante gli scontri con i boss per visualizzare la loro energia. Lo script in questione è questo:
Question
Magimario
Premetto di non avere alcuna competenza sul Ruby. In un progetto (con combattimento in tempo reale) sto usando un HUD, e mi sono chiesto se può essere usato anche durante gli scontri con i boss per visualizzare la loro energia. Lo script in questione è questo:
#======================================================================
========
# ■ Kingdom Hearts HUD
#------------------------------------------------------------------------------
# by Skive
# skivedaft@yahoo.com
#
# --
#
# released on 5th March 2006
#==============================================================================
#==============================================================================
# ■ Sprite_HP
#------------------------------------------------------------------------------
# the HUD's hp bar
#==============================================================================
class Sprite_HP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@hp = @actor.hp
@maxhp = @actor.maxhp
draw_bar(20, 6)
self.angle = 270
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @hp != @actor.hp or @maxhp != @actor.maxhp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
max = (@actor.hp * 360) / @actor.maxhp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(74, 112, 29)
when 2
color = Color.new(77, 120, 29)
when 3
color = Color.new(80, 131, 28)
when 4
color = Color.new(85, 144, 27)
when 5
color = Color.new(89, 156, 26)
when 6
color = Color.new(93, 167, 26)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end
#==============================================================================
# ■ Sprite_SP
#------------------------------------------------------------------------------
# the HUD's sp bar
#==============================================================================
class Sprite_SP < Sprite
#--------------------------------------------------------------------------
# ● instances
#--------------------------------------------------------------------------
attr_writer :actor
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(actor = nil)
super(nil)
self.z = 202
self.bitmap = Bitmap.new(60, 26)
@actor = actor
if !@actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
end
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
@sp = @actor.sp
@maxsp = @actor.maxsp
draw_bar(20, 6)
self.angle = 90
self.mirror = true
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
if @actor.nil?
self.bitmap.clear
return
end
if @sp != @actor.sp or @maxsp != @actor.maxsp
refresh
end
end
#--------------------------------------------------------------------------
# ● draw_bar
#--------------------------------------------------------------------------
def draw_bar(radius, width)
max = (@actor.sp * 360) / @actor.maxsp
for j in 1..width
for i in 0..max
bx = Math.cos( (i * Math::PI) / 360) * (radius + j)
by = Math.sin( (i * Math::PI) / 360) * (radius + j)
case j
when 1
color = Color.new(29, 82, 112)
when 2
color = Color.new(29, 86, 120)
when 3
color = Color.new(28, 90, 131)
when 4
color = Color.new(27, 96, 144)
when 5
color = Color.new(26, 102, 156)
when 6
color = Color.new(26, 106, 167)
end
self.bitmap.set_pixel(30 + bx, by, color)
end
end
end
end
#==============================================================================
# ■ Sprite_HUD
#------------------------------------------------------------------------------
# draws the HUD on the map
#==============================================================================
class Sprite_HUD < Sprite
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize(corner = 4)
super(nil)
self.z = 200
for actor in $game_party.actors
next if actor.dead?
@actor = actor
@actor_index = $game_party.actors.index(@actor)
break
end
@hp_sprite = Sprite_HP.new(@actor)
@sp_sprite = Sprite_SP.new(@actor)
self.bitmap = Bitmap.new(60, 60)
case corner
when 1
x = 16
y = 16
when 2
x = 640 - 52 - 16
y = 16
when 3
x = 16
y = 480 - 52 - 16
when 4
x = 640 - 52 - 16
y = 480 - 52 - 16
end
self.x = x
self.y = y
@hp_sprite.x = x + 27
@hp_sprite.y = y - 3
@sp_sprite.x = x + 27 - 1
@sp_sprite.y = y - 3 - 1 + 60
refresh
end
#--------------------------------------------------------------------------
# ● refresh
#--------------------------------------------------------------------------
def refresh
self.bitmap.clear
return if @actor.nil?
bmp = RPG::Cache.character(@actor.character_name, @actor.character_hue)
rect = Rect.new(0, 0, bmp.width / 4, (bmp.height / 4))
self.bitmap.blt(27 - bmp.width / 8, 5, bmp, rect)
self.bitmap.blt(0, 0, RPG::Cache.picture("hud"), Rect.new(0, 0, 60, 60))
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
super
@hp_sprite.update
@sp_sprite.update
if @actor != $game_party.actors[@actor_index]
@actor = $game_party.actors[@actor_index]
@hp_sprite.actor = @actor
@sp_sprite.actor = @actor
@hp_sprite.refresh
@sp_sprite.refresh
refresh
end
end
end
#==============================================================================
# ■ Scene_Map
#------------------------------------------------------------------------------
# draws the hud on the map screen
# @khhud_corner is the corner you want the hud to be displayed in.
# 1 is upper left, 2 is upper right, 3 is bottom left and 4 is bottom right
#==============================================================================
class Scene_Map
alias main_khhud main
alias update_khhud update
alias transfer_khhud transfer_player
#--------------------------------------------------------------------------
# ● initialize
#--------------------------------------------------------------------------
def initialize
@khhud_corner = 4 # 1 or 2 or 3 or 4
end
#--------------------------------------------------------------------------
# ● main
#--------------------------------------------------------------------------
def main
@hud = Sprite_HUD.new(@khhud_corner)
main_khhud
@hud.dispose
end
#--------------------------------------------------------------------------
# ● update
#--------------------------------------------------------------------------
def update
@hud.update
update_khhud
end
end
Grazie in anticipo a chiunque sia disposto ad aiutarmi
Link to comment
Share on other sites
0 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now