Advertisement
DizzyFoxkit

Simple bar script

Dec 15th, 2013
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.67 KB | None | 0 0
  1. class Window_Base < Window
  2.    
  3.    
  4.     def bar_color(n)
  5.         case n
  6.         when 0
  7.             return Color.new(0, 0, 0)  # black
  8.         when 1
  9.             return Color.new(0, 255, 0)  # green
  10.         when 2
  11.             return Color.new(0, 0, 255)  # blue
  12.         when 3
  13.             return Color.new(255, 0, 0)  # red
  14.         end
  15.     end
  16.  
  17.     def draw_hp_bar(actor, x, y, w = 100)
  18.         hp = actor.hp
  19.         max_hp = actor.maxhp
  20.         border_color = bar_color(0)
  21.         health_color = bar_color(1)
  22.         hp_percentage = hp * 1.0 / max_hp
  23.         health_fill = w * hp_percentage
  24.         border = Rect.new(x - 1, y, w + 2, 10)
  25.         health = Rect.new(x, y, health_fill, 8)
  26.         self.contents.fill_rect(border, border_color)
  27.         self.contents.fill_rect(health, health_color)
  28.     end
  29.    
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement