Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module HP_Bars
- Width = 100
- Height = 4
- Healthy_Color = Color.new(0, 255, 0)
- Injured_Color = Color.new(255, 255, 0)
- Critical_Color = Color.new(255, 0, 0)
- end
- class Sprite_Battler < Sprite_Base
- alias :th_battler_hp_bar_initialize :initialize
- def initialize(viewport, battler = nil)
- th_battler_hp_bar_initialize(viewport, battler)
- init_hp_bar if battler
- end
- def init_hp_bar
- @hp_bar = Sprite.new
- @hp_bar.bitmap = Bitmap.new(HP_Bars::Width, HP_Bars::Height)
- @hp_bar.bitmap.fill_rect(0, 0, HP_Bars::Width, HP_Bars::Height, HP_Bars::Healthy_Color)
- end
- alias :th_battler_hp_bar_dispose :dispose
- def dispose
- @hp_bar.dispose if @hp_bar
- th_battler_hp_bar_dispose
- end
- end
- alias :th_battler_hp_bar_update_position :update_position
- def update_position
- th_battler_hp_bar_update_position
- update_hp_position if @hp_bar
- end
- def update_hp_position
- @hp_bar.x = @battler.screen_x
- @hp_bar.y = @battler.screen_y
- @hp_bar.z = @battler.screen_z
- end
- def update_hp_position
- if bitmap
- @hp_bar.x = @battler.screen_x – bitmap.width / 2
- @hp_bar.y = @battler.screen_y – bitmap.height – 16
- @hp_bar.z = @battler.screen_z
- end
- end
- alias :th_battler_hp_bar_update :update
- def update
- th_battler_hp_bar_update
- update_hp_bar if @hp_bar
- end
- def update_hp_bar
- @hp_bar.bitmap.clear
- width = HP_Bars::Width * @battler.hp_rate
- height = HP_Bars::Height
- bar_color = HP_Bars::Healthy_Color
- @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
- end
- def update_hp_bar
- @hp_bar.bitmap.clear
- width = HP_Bars::Width * @battler.hp_rate
- height = HP_Bars::Height
- @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
- end
- def bar_color
- if @battler.hp_rate < 0.5
- HP_Bars::Injured_Color
- else
- HP_Bars::Healthy_Color
- end
- end
- def update_hp_bar
- p ‘update’
- @hp_bar.bitmap.clear
- width = HP_Bars::Width * @battler.hp_rate
- height = HP_Bars::Height
- @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
- end
- def init_hp_bar
- @last_hp = 0 ###
- @hp_bar = Sprite.new
- @hp_bar.bitmap = Bitmap.new(HP_Bars::Width, HP_Bars::Height)
- @hp_bar.bitmap.fill_rect(0, 0, HP_Bars::Width, HP_Bars::Height, HP_Bars::Healthy_Color)
- end
- def update_hp_bar
- return if @last_hp == @battler.hp ###
- @last_hp = @battler.hp ###
- p ‘update’
- @hp_bar.bitmap.clear
- width = HP_Bars::Width * @battler.hp_rate
- height = HP_Bars::Height
- @hp_bar.bitmap.fill_rect(0, 0, width, height, bar_color)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement