class Core::Game::Combat::Bar
Attributes
max[R]
value[R]
visible[RW]
x[RW]
y[RW]
z[RW]
Public Class Methods
new(x, y, z, w, h, scheme, max, background)
click to toggle source
# File lib/game/combat/bar.rb, line 7 def initialize(x, y, z, w, h, scheme, max, background) schemes = [:health, :endurance, :timer] @background = background @x, @y, @z = x, y, z @w, @h = w, h @scheme = scheme @value = @max = max @speed = @sub = @add = 0 @fade = 256 @visible = true end
Public Instance Methods
add(amount, speed)
click to toggle source
# File lib/game/combat/bar.rb, line 109 def add(amount, speed) @add = amount @speed = speed end
draw()
click to toggle source
# File lib/game/combat/bar.rb, line 48 def draw if !@visible return end if @background cb = Gosu::Color.new(255, 0, 0, 0) Core.window.draw_quad(@x, @y, cb, @x+@w, @y, cb, @x+@w, @y+@h, cb, @x, @y+@h, cb, @z) case @scheme when :health cl = Gosu::Color.new(255, 255, 0, 0) cr = Gosu::Color.new(255, 0, 255, 0) else cl = Gosu::Color.new(255, 0, 0, 0) cr = Gosu::Color.new(255, 255, 255, 255) end else # TODO fluent fade case @scheme when :health if @value >= (@max / 4) * 3 cl = cr = Gosu::Color.new(255, 0, 255, 0) elsif @value >= @max / 2 cl = cr = Gosu::Color.new(255, 255, 255, 0) elsif @value >= @max / 4 cl = cr = Gosu::Color.new(255, 255, 180, 0) else cl = cr = Gosu::Color.new(255, 255, 0, 0) end when :timer if @value >= (@max / 4) * 3 cl = cr = Gosu::Color.new(255, 255, 0, 0) elsif @value >= @max / 2 cl = cr = Gosu::Color.new(255, 255, 180, 0) elsif @value >= @max / 4 cl = cr = Gosu::Color.new(255, 255, 255, 0) else cl = cr = Gosu::Color.new(255, 0, 255, 0) end else cl = cr = Gosu::Color.new(255, 255, 255, 255) end end if @fade <= 255 f = @fade if f < 0 f = 0 end cl.alpha = f cr.alpha = f end if @value > 0 w = @value / (@max / @w.to_f) Core.window.draw_quad(@x, @y, cl, @x+w, @y, cr, @x+w, @y+@h, cr, @x, @y+@h, cl, @z) end end
fade(speed=15)
click to toggle source
# File lib/game/combat/bar.rb, line 43 def fade(speed=15) @speed = speed @fade = 255 end
set(val)
click to toggle source
# File lib/game/combat/bar.rb, line 114 def set(val) @value = val end
subtract(amount, speed)
click to toggle source
# File lib/game/combat/bar.rb, line 104 def subtract(amount, speed) @sub = amount @speed = speed end
update()
click to toggle source
# File lib/game/combat/bar.rb, line 19 def update if !@visible return end if @sub > 0 @value -= @speed @sub -= @speed else @sub = 0 end if @add > 0 @value += @speed @add -= @speed else @add = 0 end if @fade > 0 and @fade <= 255 @fade -= @speed elsif @fade <= 0 @fade = 0 @visible = false end end