Advertisement
marlosgama

Untitled

Feb 9th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.17 KB | None | 0 0
  1. #==============================================================================
  2. # ** Sprite_HUD
  3. #------------------------------------------------------------------------------
  4. #  Esta classe lida com a exibição de HP, MP, experiência,
  5. # face e nível do jogador.
  6. #------------------------------------------------------------------------------
  7. #  Autor: Valentine
  8. #==============================================================================
  9.  
  10. class Sprite_HUD < Sprite
  11.  
  12.   attr_reader :exp_sprite
  13.  
  14.   def initialize
  15.     super
  16.     self.bitmap = Bitmap.new(255, 107)
  17.     self.x = 11
  18.     self.y = 9
  19.     self.z = 50
  20.     self.bitmap.font.size = 18
  21.     self.bitmap.font.bold = true
  22.     @back = Cache.system('HUD')
  23.     @bars = Cache.system('HUDBars')
  24.     create_exp_bar
  25.     refresh
  26.   end
  27.  
  28.   def dispose
  29.     super
  30.     @exp_sprite.bitmap.dispose
  31.     @exp_sprite.dispose
  32.   end
  33.  
  34.   def create_exp_bar
  35.         @exp_sprite = Sprite2.new
  36.         @exp_sprite.bitmap = Bitmap.new(308, 22)
  37.     @exp_sprite.bitmap.font.size = 18
  38.     @exp_sprite.bitmap.font.bold = true
  39.     @exp_sprite.x = adjust_x
  40.     @exp_sprite.y = adjust_y
  41.     @exp_sprite.dragable = true
  42.         @exp_sprite.z = self.z
  43.   end
  44.  
  45.   def adjust_x
  46.     Graphics.width / 2 - 139
  47.   end
  48.  
  49.   def adjust_y
  50.     Graphics.height - 28
  51.   end
  52.  
  53.   def refresh
  54.     draw_background
  55.     draw_face
  56.     draw_hp_bar
  57.     draw_mp_bar
  58.     draw_exp_bar
  59.     draw_level
  60.   end
  61.  
  62.   def draw_background
  63.     self.bitmap.clear
  64.     rect = Rect.new(0, 0, 248, 98)
  65.     self.bitmap.blt(7, 0, @back, rect)
  66.   end
  67.  
  68.   def draw_face
  69.     face = Cache.face($game_actors[1].face_name)
  70.     rect = Rect.new($game_actors[1].face_index % 4 * 96, $game_actors[1].face_index / 4 * 96, 96, 96)
  71.     self.bitmap.blt(8, 1, face, rect)
  72.   end
  73.  
  74.   def draw_hp_bar
  75.     rect = Rect.new(0, 0, 123 * $game_actors[1].hp / $game_actors[1].mhp, 26)
  76.     self.bitmap.blt(53, 2, @bars, rect)
  77.     self.bitmap.draw_text(57, 7, 25, 18, Vocab::hp_a)
  78.     self.bitmap.draw_text(0, 7, 175, 18, "#{$game_actors[1].hp}/#{$game_actors[1].mhp}", 2)
  79.   end
  80.  
  81.   def draw_mp_bar
  82.     rect = Rect.new(0, 26, 123 * $game_actors[1].mp / $game_actors[1].mmp, 26)
  83.     self.bitmap.blt(53, 30, @bars, rect)
  84.     self.bitmap.draw_text(54, 35, 25, 18, Vocab::mp_a)
  85.     self.bitmap.draw_text(0, 35, 175, 18, "#{$game_actors[1].mp}/#{$game_actors[1].mmp}", 2)
  86.   end
  87.  
  88.   def draw_exp_bar
  89.     @exp_sprite.bitmap.clear
  90.     rect1 = Rect.new(0, 98, @exp_sprite.bitmap.width, @exp_sprite.bitmap.height)
  91.     rect2 = Rect.new(0, 52, 308 * $game_actors[1].now_exp / $game_actors[1].next_exp, @exp_sprite.bitmap.height)
  92.     exp = $game_actors[1].level >= Configs::MAX_LEVEL ? Vocab::MaxLevel : $game_actors[1].next_exp - $game_actors[1].now_exp
  93.     @exp_sprite.bitmap.blt(0, 0, @back, rect1)
  94.     @exp_sprite.bitmap.blt(0, 0, @bars, rect2)
  95.     @exp_sprite.bitmap.draw_text(4, 2, 25, 18, Vocab::Exp)
  96.     @exp_sprite.bitmap.draw_text(0, 2, 308, 18, exp, 1)
  97.   end
  98.  
  99.   def draw_level
  100.     rect = Rect.new(0, 120, 29, 30)
  101.     self.bitmap.blt(0, 37, @back, rect)
  102.     self.bitmap.draw_text(0, 43, 30, 18, $game_actors[1].level, 1)
  103.   end
  104.  
  105.   def update
  106.     super
  107.     @exp_sprite.update
  108.   end
  109.  
  110. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement