Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Scene_Map
- alias start_custom_hud start
- def start
- start_custom_hud
- create_hud
- end
- def create_hud
- @actor = $game_party.members.first
- h = 104
- @hud_viewport = Viewport.new(0, Graphics.height-h, Graphics.width, h)
- @face = Sprite.new(@hud_viewport)
- @face.bitmap = Cache.picture('Face')
- @face.x, @face.y = 4, 4
- @hp_bar_back = Sprite.new(@hud_viewport)
- @hp_bar_back.bitmap = Cache.picture('HpBar_Back')
- @hp_bar_back.x = (Graphics.width-@hp_bar_back.bitmap.width)/2
- @hp_bar_back.y = 65
- @hp_bar = Sprite.new(@hud_viewport)
- @hp_bar.bitmap = Cache.picture('HpBar')
- @hp_bar.x, @hp_bar.y = @hp_bar_back.x, @hp_bar_back.y
- @hp_bar.z = @hp_bar_back.z + 1
- @hp_bar.src_rect = Rect.new(0, 0,
- (@hp_bar.bitmap.width*@actor.hp_rate).to_i, @hp_bar.bitmap.height)
- @hp_text = Sprite.new(@hud_viewport)
- @hp_text.bitmap = Bitmap.new(@hp_bar.bitmap.width, @hp_bar.bitmap.height)
- @hp_text.x, @hp_text.y, @hp_text.z = @hp_bar.x, @hp_bar.y, @hp_bar.z+1
- draw_hp_value
- @mp_bar = Sprite.new(@hud_viewport)
- @mp_bar.bitmap = Cache.picture('MpBar')
- @mp_bar.x = @hp_bar.x + 1
- @mp_bar.y = @hp_bar.y + 25
- @mp_bar.src_rect = Rect.new(0, 0,
- (@mp_bar.bitmap.width*@actor.mp_rate).to_i, @mp_bar.bitmap.height)
- end
- def update_hp
- current_length = @hp_bar.src_rect.width
- target_length = (@hp_bar.bitmap.width * @actor.hp_rate).to_i
- return if current_length == target_length
- update_gauge(@hp_bar, current_length, target_length, 10)
- draw_hp_value
- end
- def draw_hp_value
- bitmap = @hp_text.bitmap
- bitmap.clear
- rect = Rect.new(0, 0, bitmap.width-5, bitmap.height)
- bitmap.font.outline = true
- bitmap.font.bold = true
- bitmap.font.size = 14
- mhp_size = bitmap.text_size(@actor.mhp.to_s).width
- bitmap.draw_text(rect, @actor.mhp.to_i.to_s ,2)
- rect = Rect.new(0, 0, bitmap.width - 5 - mhp_size, bitmap.height)
- bitmap.font.size = 20
- bitmap.draw_text(rect, @actor.hp.to_i.to_s + "/", 2)
- end
- def update_mp
- current_length = @mp_bar.src_rect.width
- target_length = (@mp_bar.bitmap.width * @actor.mp_rate).to_i
- return if current_length == target_length
- update_gauge(@mp_bar, current_length, target_length, 10)
- end
- def update_gauge(spr, current_length, target_length, speed)
- dw = target_length - current_length
- dw = dw.abs > speed ? (dw>0? speed : -speed) : dw
- spr.src_rect = Rect.new(0, 0, spr.src_rect.width+dw, spr.src_rect.height)
- end
- def update_hud
- update_hp
- update_mp
- end
- alias update_custom_hud update
- def update
- update_custom_hud
- update_hud
- end
- alias terminate_custom_hud terminate
- def terminate
- terminate_custom_hud
- dispose_hud
- end
- def dispose_hud
- [@face, @hp_bar, @hp_bar_back, @mp_bar, @hp_text].each{|item|
- item.bitmap.dispose if item.bitmap
- item.dispose
- }
- @hud_viewport.dispose
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement