Advertisement
DizzyFoxkit

Simple bar script

Dec 19th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Game_Actor < Game_Battler
  2.    
  3.     def needed_exp(current_level)
  4.     return @exp_list[current_level + 1] - @exp_list[current_level]
  5.   end
  6.  
  7.   def gained_exp(current_exp, current_level)
  8.     return current_exp - @exp_list[current_level]
  9.   end
  10.    
  11. end
  12.  
  13.  
  14. class Window_Base < Window
  15.    
  16.    
  17.     def bar_color(n)
  18.         case n
  19.         when 0
  20.             return Color.new(0, 0, 0)  # black
  21.         when 1
  22.             return Color.new(0, 255, 0)  # green
  23.         when 2
  24.             return Color.new(0, 0, 255)  # blue
  25.         when 3
  26.             return Color.new(255, 0, 0)  # red
  27.         when 4
  28.             return Color.new(255, 255, 255)  # white
  29.         when 5
  30.             return Color.new(230, 230, 230)  # offwhite
  31.         end
  32.     end
  33.  
  34.     def draw_hp_bar(actor, x, y, w = 100)
  35.         hp = actor.hp
  36.         max_hp = actor.maxhp
  37.         border_color = bar_color(0)
  38.         health_color = bar_color(1)
  39.         danger_color = bar_color(3)
  40.         hp_percentage = hp * 1.0 / max_hp
  41.         health_fill = w * hp_percentage
  42.         border = Rect.new(x - 1, y, w + 2, 10)
  43.         health = Rect.new(x, y + 1, health_fill, 8)
  44.         self.contents.fill_rect(border, border_color)
  45.         if hp <= max_hp / 3
  46.             self.contents.fill_rect(health, danger_color)
  47.         else
  48.             self.contents.fill_rect(health, health_color)
  49.         end
  50.        
  51.     end
  52.    
  53.     def draw_xp_bar(actor, x, y, w = 100)
  54.         exp = actor.exp
  55.         level = actor.level
  56.         gained_exp = actor.gained_exp(exp, level)
  57.         needed_exp = actor.needed_exp(level)
  58.         exp_percentage = (gained_exp * 1.0 / needed_exp) * w
  59.         background_color = bar_color(0)
  60.         first_bar_color = bar_color(4)
  61.         second_bar_color = bar_color(5)
  62.         background_bar = Rect.new(x - 1, y, w + 2, 10)
  63.         first_bar = Rect.new(x, y + 1, exp_percentage, 8)
  64.         second_bar = Rect.new(x, y + 3, exp_percentage, 4)
  65.         self.contents.fill_rect(background_bar, background_color)
  66.         self.contents.fill_rect(first_bar, first_bar_color)
  67.         self.contents.fill_rect(second_bar, second_bar_color)
  68.     end
  69.    
  70.    
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement