TheoAllen

Theo - HP Bar Over Player

Nov 1st, 2013
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.61 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - HP Bar Over Player
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_MapHP] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2013.10.28 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   Perkenalan :
  16.   Script ini ngebikin kamu bisa nampilin HP Bar diatas player
  17.  
  18.   Cara penggunaan :
  19.   Pasang script ini dibawah material namun diatas main
  20.   Gunakan script call berikut untuk memunculkan / mematikan HP bar
  21.   - $game_party.maphp = true (ON)
  22.   - $game_party.maphp = false (OFF)
  23.  
  24.   Terms of use :
  25.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  26.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  27.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.  
  28.  
  29. =end
  30. # =============================================================================
  31. # Konfigurasi :
  32. # =============================================================================
  33. module Theo
  34.   module MapHP
  35.    
  36.   # -------------------------------------------------------------------------
  37.   # Berdasar apakah maksimal HP ditampilkan pada bar?
  38.   # 0 - Leader
  39.   # 1 - Battle Members
  40.   # 2 - All Members  
  41.   # -------------------------------------------------------------------------
  42.     Mode = 0
  43.   # -------------------------------------------------------------------------
  44.    
  45.   # -------------------------------------------------------------------------
  46.   # Setting untuk ukuran HP Bar
  47.   # -------------------------------------------------------------------------
  48.     Width   = 60    # Lebar
  49.     Height  = 5     # Tinggi
  50.   # -------------------------------------------------------------------------
  51.  
  52.   # -------------------------------------------------------------------------
  53.   # Setting untuk warna HP Bar
  54.   # Isi dengan Color.new(merah, hijau, biru)
  55.   # Masing2 attribut warna maksimal nilainya adalah 255
  56.   # -------------------------------------------------------------------------
  57.     BackColor   = Color.new(0,0,0)        # Warna background
  58.     FillColor1  = Color.new(238,180,34)   # Warna gradient samping kiri
  59.     FillColor2  = Color.new(227,207,87)   # Warna gradient samping kanan
  60.   # -------------------------------------------------------------------------
  61.  
  62.   # -------------------------------------------------------------------------
  63.   # Alterasi / Perubahan
  64.   # -------------------------------------------------------------------------
  65.     AlterSpeed  = 1   # Kecepatan bar berubah nilai (minimal: 1)
  66.     FadeSpeed   = 48  # Kecepatan fadeout/fadein saat bar dimatikan atau
  67.   #                     dihidupkan
  68.   # -------------------------------------------------------------------------
  69.  
  70.   end
  71. end
  72. # =============================================================================
  73. # Akhir dari konfigurasi
  74. # =============================================================================
  75. class Game_Party
  76.   attr_accessor :maphp
  77.  
  78.   alias theo_maphp_init initialize
  79.   def initialize
  80.     theo_maphp_init
  81.     @maphp = true
  82.   end
  83.  
  84.   def maphp_members
  85.     (Theo::MapHP::Mode == 1 ? battle_members : all_members)
  86.   end
  87.  
  88.   def mhp
  89.     maphp_members.inject(0) do |r, actor|
  90.       r += actor.mhp
  91.     end
  92.   end
  93.  
  94.   def hp
  95.     maphp_members.inject(0) do |r, actor|
  96.       r += actor.hp
  97.     end
  98.   end
  99.  
  100.   def hp_rate
  101.     hp / mhp.to_f
  102.   end
  103.  
  104. end
  105.  
  106. class HP_Background < Sprite
  107.   include Theo::MapHP
  108.   @@bitmap_graphic = nil
  109.  
  110.   def initialize(viewport)
  111.     super(viewport)
  112.     self.opacity = ($game_party.maphp ? 255 : 0)
  113.     set_bitmap
  114.     update
  115.   end
  116.  
  117.   def set_bitmap
  118.     unless @@bitmap_graphic
  119.       self.bitmap = Bitmap.new(Width + 2, Height + 2)
  120.       bitmap.fill_rect(bitmap.rect, BackColor)
  121.       @@bitmap_graphic = bitmap
  122.     else
  123.       self.bitmap = @@bitmap_graphic
  124.     end
  125.     self.ox = bitmap.width/2
  126.     self.oy = bitmap.height
  127.   end
  128.  
  129.   def update
  130.     super
  131.     update_placement
  132.     update_visibility
  133.   end
  134.  
  135.   def update_placement
  136.     self.x = $game_player.screen_x
  137.     self.y = $game_player.screen_y - 35
  138.   end
  139.  
  140.   def update_visibility
  141.     self.opacity += $game_party.maphp ? FadeSpeed : -FadeSpeed
  142.   end
  143.  
  144. end
  145.  
  146. class HP_Fill < Sprite
  147.   include Theo::MapHP
  148.   @@bitmap_graphic = nil
  149.  
  150.   def initialize(viewport)
  151.     super(viewport)
  152.     self.opacity = ($game_party.maphp ? 255 : 0)
  153.     set_bitmap
  154.     determine_method
  155.     update
  156.   end
  157.  
  158.   def set_bitmap
  159.     unless @@bitmap_graphic
  160.       self.bitmap = Bitmap.new(Width,Height)
  161.       bitmap.gradient_fill_rect(bitmap.rect, FillColor1, FillColor2)
  162.       @@bitmap_graphic = bitmap
  163.     else
  164.       self.bitmap = @@bitmap_graphic
  165.     end
  166.     self.ox = bitmap.width/2
  167.     self.oy = bitmap.height
  168.   end
  169.  
  170.   def determine_method
  171.     @method = (Mode == 0) ? method(:party_leader) : method(:whole_party)
  172.   end
  173.  
  174.   def update
  175.     super
  176.     update_placement
  177.     update_src_rect
  178.     update_visibility
  179.   end
  180.  
  181.   def update_placement
  182.     self.x = $game_player.screen_x
  183.     self.y = $game_player.screen_y - 36
  184.   end
  185.  
  186.   def update_src_rect
  187.     rate = @method.call
  188.     if src_rect.width < rate
  189.       src_rect.width = [src_rect.width + AlterSpeed,rate].min
  190.     elsif src_rect.width > rate
  191.       src_rect.width = [src_rect.width - AlterSpeed,rate].max
  192.     end
  193.   end
  194.  
  195.   def update_visibility
  196.     self.opacity += $game_party.maphp ? FadeSpeed : -FadeSpeed
  197.   end
  198.  
  199.   def whole_party
  200.     bitmap.width * $game_party.hp_rate
  201.   end
  202.  
  203.   def party_leader
  204.     bitmap.width * $game_party.leader.hp_rate
  205.   end
  206.  
  207. end
  208.  
  209. class HP_Bar
  210.  
  211.   def initialize(viewport)
  212.     @hp_bg = HP_Background.new(viewport)
  213.     @hp_fill = HP_Fill.new(viewport)
  214.     @hp_fill.z = 150
  215.   end
  216.  
  217.   def update
  218.     @hp_bg.update
  219.     @hp_fill.update
  220.   end
  221.  
  222.   def dispose
  223.     @hp_bg.dispose
  224.     @hp_fill.dispose
  225.   end
  226.  
  227. end
  228.  
  229. class Scene_Map < Scene_Base
  230.  
  231.   alias theo_maphp_start start
  232.   def start
  233.     theo_maphp_start
  234.     @hp_bar = HP_Bar.new(@viewport)
  235.   end
  236.  
  237.   alias theo_maphp_update update
  238.   def update
  239.     theo_maphp_update
  240.     @hp_bar.update
  241.   end
  242.  
  243.   alias theo_maphp_terminate terminate
  244.   def terminate
  245.     theo_maphp_terminate
  246.     @hp_bar.dispose
  247.   end
  248.  
  249. end
Advertisement
Add Comment
Please, Sign In to add comment