Advertisement
Guest User

HUD

a guest
Aug 6th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.70 KB | None | 0 0
  1. #==============================================================================
  2. # ■ Window_Base
  3. #==============================================================================
  4. class Window_Base2 < Window
  5.   def initialize(x, y, width, height)
  6.     super()
  7.     self.x = x
  8.     self.y = y
  9.     self.width = width
  10.     self.height = height
  11.     self.z = 100
  12.   end
  13.   def dispose
  14.     if self.contents != nil
  15.       self.contents.dispose
  16.     end
  17.     super
  18.   end
  19.   def update
  20.     super
  21.   end
  22. end
  23.  
  24.  
  25.  
  26. #===============================================================================
  27. # HUD
  28. # Thanks to Ngọa Hổ
  29. # Re-Scripted by MrShir
  30. #===============================================================================
  31. class GUI < Window_Base2
  32.   def initialize
  33.     super(-16, -16, 640+32, 480+32)
  34.     self.z = 10
  35.     self.contents = Bitmap.new(640,480)
  36.     self.contents.font.name = ".VnArial"
  37.     self.contents.font.size = 14
  38.     @window_pos = Sprite.new
  39.     @window_pos.bitmap = Bitmap.new(200, 80)
  40.   #  @window_pos.bitmap.font.name = [".VnArial"]
  41.     @window_pos.bitmap.font.size = 14
  42.     @window_pos.bitmap.font.color = ColorLib.white
  43.     @window_pos.x = 487
  44.     @window_pos.y = -2
  45.     @window_pos.z = 13
  46.     @exp_list = []
  47.     actor = $data_actors[1]
  48.     @exp_list[1] = 0
  49.     pow_i = 2.4 + actor.exp_inflation / 100.0
  50.     for i in 2..100
  51.       if i > actor.final_level
  52.         @exp_list[i] = 0
  53.       else
  54.         n = actor.exp_basis * ((i + 3) ** pow_i) / (5 ** pow_i)
  55.         @exp_list[i] = @exp_list[i-1] + Integer(n)
  56.       end
  57.     end
  58.     refresh_pos
  59.     refresh
  60.   end
  61.   alias old_dispose dispose
  62.   def dispose
  63.     old_dispose
  64.     @window_pos.dispose
  65.   end
  66.   #-----------------------------------------------------------------------------
  67.   def refresh
  68.     self.contents.clear
  69.     @old_hp = $game_party.actors[0].hp
  70.     @old_mp = $game_party.actors[0].sp
  71.    
  72.     @old_exp = $game_party.actors[0].exp_s.to_i
  73.     @next_exp = $game_party.actors[0].next_exp_s.to_i
  74.  
  75.     @level = $game_party.actors[0].level
  76.    
  77.     @next_exp -= @exp_list[@level]
  78.     @old_exp -=  @exp_list[@level]
  79.    
  80.     @maxhp = $game_party.actors[0].maxhp
  81.     @maxmp = $game_party.actors[0].maxsp
  82.    
  83.     self.contents.blt(0, 0, Bitmap.new("Graphics/Sprite/top_hud"), Rect.new(0, 0, 640, 200))
  84.     draw_gradient_bar(55,19, @old_hp, @maxhp, "hp", 87, 8)
  85.     self.contents.font.color = Color.new(255, 255, 255)
  86.     draw_gradient_bar(55,29, @old_mp, @maxmp, "mp", 87,8)
  87.     self.contents.font.color = Color.new(255, 255, 255)
  88.     self.contents.draw_text(60, 1, 65, 15,"tªn NV",1)
  89.   #  self.contents.draw_text(105, 1, 10, 15,$game_party.actors[0].level.to_s,1)
  90.    
  91.     if @old_exp != 0
  92.       # thuật toán tạo % hiện ở dạng xx.xxx%, tác giả : Ngọa Hổ
  93.       kn_hien_co = (@old_exp.to_f*100).to_i
  94.       kn_can_co = @next_exp
  95.       phantram_begin=(kn_hien_co.to_f/kn_can_co).to_f
  96.       phantram_ok = (phantram_begin*100).to_i
  97.       phantram = (phantram_ok.to_f/100).to_f
  98.     else
  99.       phantram=0
  100.     end
  101.  
  102.    
  103.     draw_gradient_bar(30, 463, phantram.abs, 100, "exp", 339, 15)
  104.     self.contents.blt(0, 415, Bitmap.new("Graphics/Sprite/bot_hud"), Rect.new(0, 0, 640, 64))
  105.     self.contents.font.color = Color.new(255, 255, 255)
  106.     self.contents.draw_text(33, 460, 40, 22, phantram.to_s+"%")
  107.     self.contents.draw_text(83, 460, 640, 22, "Kinh NghiÖm : "+@old_exp.to_s+" / "+@next_exp.to_s+"    (CÊp : "+@level.to_s+")")
  108.  
  109.   end
  110.   def refresh_pos
  111.    @x = $game_player.x
  112.    @y = $game_player.y
  113.    @id = $game_map.map_id
  114.    map_name = load_data("Data/MapInfos.rxdata")[@id].name
  115.    @window_pos.bitmap.clear
  116.    @window_pos.bitmap.draw_text(0, 0, 149, 20, map_name,2)
  117.    @window_pos.bitmap.draw_text(0, 14, 145, 20, @x.to_s,2)
  118.    @window_pos.bitmap.draw_text(0, 25, 145, 20, @y.to_s,2)
  119.  end
  120.  def need_update_pos
  121.    return true if @x != $game_player.x
  122.    return true if @y != $game_player.y
  123.    return true if @id != $game_map.map_id
  124.    return false
  125.  end
  126.  def need_update
  127.    return true if @old_hp != $game_party.actors[0].hp
  128.    return true if @old_mp != $game_party.actors[0].sp
  129.    return true if @old_exp != $game_party.actors[0].exp_s
  130.    return true if @level != $game_party.actors[0].level
  131.    return false
  132.  end
  133. #------------------------------------------------------------------------------
  134.   def draw_gradient_bar(x, y, min, max, file, width = nil, height = nil, back = "")
  135.     bar = Bitmap.new("Graphics/Sprite/"+file) rescue Bitmap.new("Graphics/Sprite/hp")
  136.     back = Bitmap.new("Graphics/Sprite/"+back) rescue Bitmap.new("Graphics/Sprite/back")
  137.     cx = 1
  138.     cy = 1
  139.     dx = 1
  140.     dy = 1
  141.     zoom_x = width != nil ? width : back.width
  142.     zoom_y = height != nil ? height : back.height
  143.     percent = min / max.to_f if max != 0
  144.     percent = 0 if max == 0
  145.     back_dest_rect = Rect.new(x,y,zoom_x,zoom_y)
  146.     bar_dest_rect = Rect.new(x+cx,y+cy,zoom_x * percent-cx*2,zoom_y-cy*2) rescue print("x:"+x.to_s+" y:"+y.to_s+" min:"+min.to_s+" max:"+max.to_s)
  147.     back_source_rect = Rect.new(0,0,back.width,back.height)
  148.     bar_source_rect = Rect.new(0,0,bar.width* percent,bar.height)
  149.     self.contents.stretch_blt(back_dest_rect, back, back_source_rect)
  150.     self.contents.stretch_blt(bar_dest_rect, bar, bar_source_rect)
  151.   end
  152.  
  153.  def hide
  154.    self.z = -10
  155.    @window_pos.z = -1
  156.  end
  157.  def show
  158.    self.z = 10
  159.    @window_pos.z = 13
  160.  end
  161.  
  162. end
  163.  
  164.  
  165. #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  166.  
  167. class Scene_Map
  168.   alias old_main main
  169.   def main
  170.     $gui = GUI.new
  171.     old_main
  172.     $gui.dispose
  173.   end
  174.  
  175.   alias world_update update
  176.   def update
  177.     $gui.refresh if $gui.need_update
  178.     $gui.refresh_pos if $gui.need_update_pos
  179.     world_update  
  180.   end
  181.  
  182. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement