SHARE
TWEET

Untitled

a guest Aug 3rd, 2016 120 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module HP_Bars
  2. Width = 100
  3. Height = 4
  4. Healthy_Color = Color.new(0, 255, 0)
  5. Injured_Color = Color.new(255, 255, 0)
  6. Critical_Color = Color.new(255, 0, 0)
  7. end
  8.  
  9. class Sprite_Battler < Sprite_Base
  10.  
  11. alias :th_battler_hp_bar_initialize :initialize
  12. def initialize(viewport, battler = nil)
  13. th_battler_hp_bar_initialize(viewport, battler)
  14. init_hp_bar if battler
  15. end
  16.  
  17. def init_hp_bar
  18. @hp_bar = Sprite.new
  19. @hp_bar.bitmap = Bitmap.new(HP_Bars::Width, HP_Bars::Height)
  20. @hp_bar.bitmap.fill_rect(0, 0, HP_Bars::Width, HP_Bars::Height, HP_Bars::Healthy_Color)
  21. end
  22.  
  23. alias :th_battler_hp_bar_dispose :dispose
  24. def dispose
  25. @hp_bar.dispose if @hp_bar
  26. th_battler_hp_bar_dispose
  27. end
  28. end
  29.  
  30. alias :th_battler_hp_bar_update_position :update_position
  31. def update_position
  32. th_battler_hp_bar_update_position
  33. update_hp_position if @hp_bar
  34. end
  35.  
  36. def update_hp_position
  37. @hp_bar.x = @battler.screen_x
  38. @hp_bar.y = @battler.screen_y
  39. @hp_bar.z = @battler.screen_z
  40. end
  41.  
  42. def update_hp_position
  43. if bitmap
  44. @hp_bar.x = @battler.screen_x – bitmap.width / 2
  45. @hp_bar.y = @battler.screen_y – bitmap.height16
  46. @hp_bar.z = @battler.screen_z
  47. end
  48. end
  49.  
  50. alias :th_battler_hp_bar_update :update
  51. def update
  52. th_battler_hp_bar_update
  53. update_hp_bar if @hp_bar
  54. end
  55.  
  56. def update_hp_bar
  57. @hp_bar.bitmap.clear
  58. width = HP_Bars::Width * @battler.hp_rate
  59. height = HP_Bars::Height
  60. bar_color = HP_Bars::Healthy_Color
  61. @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
  62. end
  63.  
  64. def update_hp_bar
  65. @hp_bar.bitmap.clear
  66. width = HP_Bars::Width * @battler.hp_rate
  67. height = HP_Bars::Height
  68. @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
  69. end
  70.  
  71. def bar_color
  72. if @battler.hp_rate < 0.5
  73. HP_Bars::Injured_Color
  74. else
  75. HP_Bars::Healthy_Color
  76. end
  77. end
  78.  
  79. def update_hp_bar
  80. p ‘update’
  81. @hp_bar.bitmap.clear
  82. width = HP_Bars::Width * @battler.hp_rate
  83. height = HP_Bars::Height
  84. @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
  85. end
  86.  
  87. def init_hp_bar
  88. @last_hp = 0 ###
  89. @hp_bar = Sprite.new
  90. @hp_bar.bitmap = Bitmap.new(HP_Bars::Width, HP_Bars::Height)
  91. @hp_bar.bitmap.fill_rect(0, 0, HP_Bars::Width, HP_Bars::Height, HP_Bars::Healthy_Color)
  92. end
  93.  
  94. def update_hp_bar
  95. return if @last_hp == @battler.hp ###
  96. @last_hp = @battler.hp ###
  97. p ‘update’
  98. @hp_bar.bitmap.clear
  99. width = HP_Bars::Width * @battler.hp_rate
  100. height = HP_Bars::Height
  101. @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
  102. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top