Class: Core::Game::Combat::Bar
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#visible ⇒ Object
Returns the value of attribute visible.
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
-
#z ⇒ Object
Returns the value of attribute z.
Instance Method Summary collapse
- #add(amount, speed) ⇒ Object
- #draw ⇒ Object
- #fade(speed = 15) ⇒ Object
-
#initialize(x, y, z, w, h, scheme, max, background) ⇒ Bar
constructor
A new instance of Bar.
- #set(val) ⇒ Object
- #subtract(amount, speed) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(x, y, z, w, h, scheme, max, background) ⇒ Bar
Returns a new instance of Bar.
7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
5 6 7 |
# File 'lib/game/combat/bar.rb', line 5 def max @max end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
5 6 7 |
# File 'lib/game/combat/bar.rb', line 5 def value @value end |
#visible ⇒ Object
Returns the value of attribute visible.
6 7 8 |
# File 'lib/game/combat/bar.rb', line 6 def visible @visible end |
#x ⇒ Object
Returns the value of attribute x.
6 7 8 |
# File 'lib/game/combat/bar.rb', line 6 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
6 7 8 |
# File 'lib/game/combat/bar.rb', line 6 def y @y end |
#z ⇒ Object
Returns the value of attribute z.
6 7 8 |
# File 'lib/game/combat/bar.rb', line 6 def z @z end |
Instance Method Details
#add(amount, speed) ⇒ Object
109 110 111 112 |
# File 'lib/game/combat/bar.rb', line 109 def add(amount, speed) @add = amount @speed = speed end |
#draw ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# 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) ⇒ Object
43 44 45 46 |
# File 'lib/game/combat/bar.rb', line 43 def fade(speed=15) @speed = speed @fade = 255 end |
#set(val) ⇒ Object
114 115 116 |
# File 'lib/game/combat/bar.rb', line 114 def set(val) @value = val end |
#subtract(amount, speed) ⇒ Object
104 105 106 107 |
# File 'lib/game/combat/bar.rb', line 104 def subtract(amount, speed) @sub = amount @speed = speed end |
#update ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# 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 |