Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # =============================================================================
- # Image Based HUD
- # =============================================================================
- =begin
- Isian HUD namain "Gauge"
- Back HUD namain "BackGauge"
- Taruh di Graphics/system
- =end
- Alter_Speed = 10
- # 1000 for instant change
- HideSwitch = 1
- # Switch buat nyembunyiin HUD (kalo ON)
- # -----------------------------------------------------------------------------
- # Script calls
- # -----------------------------------------------------------------------------
- # buat nambah HUD
- # add_hud(x,y,id,max)
- # -----------------------------------------------------------------------------
- # -----------------------------------------------------------------------------
- # buat remove HUD
- # remove_hud(id)
- # -----------------------------------------------------------------------------
- # =============================================================================
- # Script
- # =============================================================================
- class HUD_Value < Sprite
- def initialize(data,viewport = nil)
- @data = data
- super(viewport)
- self.bitmap = Cache.system("Gauge")
- @ori_width = src_rect.width
- @src_width = rate
- update_visibility
- update_placement
- update_gauge
- end
- def var
- $game_variables[@data.id]
- end
- def rate
- var/@data.max.to_f
- end
- def update
- super
- update_visibility
- update_placement
- update_gauge
- update_width
- end
- def update_visibility
- self.visible = !$game_switches[HideSwitch]
- end
- def update_placement
- self.x = @data.x
- self.y = @data.y
- end
- def update_gauge
- src_rect.width = @ori_width * @src_width
- end
- def update_width
- spd = Alter_Speed * 0.001
- @src_width = [@src_width + spd,rate].min if @src_width < rate
- @src_width = [@src_width - spd,rate].max if @src_width > rate
- end
- end
- class HUD
- def initialize(data,viewport = nil)
- @hud = HUD_Value.new(data,viewport)
- @hud.z += 50
- @back_hud = Sprite.new(viewport)
- @back_hud.bitmap = Cache.system("BackGauge")
- end
- def update
- @hud.update
- @back_hud.update
- end
- def dispose
- @hud.dispose
- @back_hud.dispose
- end
- end
- class ImgHUDs < Array
- def update
- each {|hud| hud.update }
- end
- def dispose
- each {|hud| hud.dispose }
- end
- end
- class DataHUD
- attr_accessor :x
- attr_accessor :y
- attr_accessor :id
- attr_accessor :max
- def initialize(x,y,id,max)
- @x = x
- @y = y
- @id = id
- @max = max
- end
- end
- class Game_Temp
- attr_accessor :refresh_hud
- alias theo_imghud_init initialize
- def initialize
- theo_imghud_init
- @refresh_hud = false
- end
- end
- class Game_System
- attr_reader :huds
- alias theo_imghud_init initialize
- def initialize
- theo_imghud_init
- @huds = {}
- end
- def add_hud(x,y,id,max)
- @huds[id] = DataHUD.new(x,y,id,max)
- end
- def remove_hud(id)
- @huds.delete(id)
- end
- end
- class Game_Interpreter
- def add_hud(x,y,id,max)
- $game_system.add_hud(x,y,id,max)
- puts $game_system.huds.size
- $game_temp.refresh_hud = true
- end
- def remove_hud(id)
- $game_system.remove_hud(id)
- puts $game_system.huds.size
- $game_temp.refresh_hud = true
- end
- end
- class Scene_Map < Scene_Base
- alias theo_imghud_start start
- def start
- theo_imghud_start
- create_imghud
- end
- def create_imghud
- @huds = ImgHUDs.new
- $game_system.huds.values.each do |data|
- @huds.push(HUD.new(data))
- end
- end
- alias theo_imghud_update update
- def update
- theo_imghud_update
- @huds.update
- if $game_temp.refresh_hud
- dispose_hud
- create_imghud
- $game_temp.refresh_hud = false
- end
- end
- def dispose_hud
- @huds.dispose
- end
- alias theo_imghud_terminate terminate
- def terminate
- theo_imghud_terminate
- dispose_hud
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment