MyTetra Share
Делитесь знаниями!
HUD
Время создания: 15.12.2016 19:56
Автор: DeadElf79
Текстовые метки: hud, rose to freedom
Раздел: Ruby - RGSS3
Запись: deadelf79/mytetra/raw/master/data/base/14818210117ahvtm6g9g/text.html на github.com

# de79 hud script

# made for 'Rose to freedom'

module De79Hud

# Elements of HUD

SW_HPBAR = 3

SW_ITEMBAR = 4

SW_HANDBAR = 5

# Armors

DB_BODY_TYPE = 3

DB_SHIELD_TYPE = 1

DB_KEY_TYPE = 4

end


class De79HPBar < Sprite

def initialize

super

self.visible = false

self.bitmap = Bitmap.new( "Graphics/System/hpbar" )

self.x = 0

self.y = Graphics.height - bitmap.height

self.z = 180

# configs related with image file

@hpx, @hpy = 25, 6

@mpx, @mpy = 25, 26

@xpx, @xpy = 25, 46


@last_hp = -1

@last_mp = -1

@last_xp = -1

load_bars

end


def update

if $game_switches[ De79Hud::SW_HPBAR ]

show

update_hp

update_mp

update_xp

else

hide

end

end

def load_bars

@hpb = Sprite.new

@hpb.bitmap = Bitmap.new( 80, 16 )

@hpb.x, @hpb.y = x + @hpx, y + @hpy

@hpb.z = self.z + 1


@mpb = Sprite.new

@mpb.bitmap = Bitmap.new( 80, 16 )

@mpb.x, @mpb.y = x + @mpx, y + @mpy

@mpb.z = self.z + 1


@xpb = Sprite.new

@xpb.bitmap = Bitmap.new( 80, 16 )

@xpb.x, @xpb.y = x + @xpx, y + @xpy

@xpb.z = self.z + 1

end


def show

self.visible = true

@hpb.visible = true

@mpb.visible = true

@xpb.visible = true

end


def hide

self.visible = false

@hpb.visible = false

@mpb.visible = false

@xpb.visible = false

end


def update_hp

if @last_hp != $game_party.leader.hp

@hpb.bitmap.clear

ac = $game_party.leader

x = 0

y1 = 0

y2 = 4

width = (80 * (ac.hp.to_f/ac.mhp)).to_i

height1 = y2

height2 = @hpb.bitmap.height - height1

color1 = Color.new(172, 50, 50, 160)

color2 = Color.new(217, 87, 99, 200)

color3 = Color.new(69, 40, 60, 160)

@hpb.bitmap.gradient_fill_rect(x, y1, width, height1, color1, color2, true)

@hpb.bitmap.gradient_fill_rect(x, y2, width, height2, color2, color3, true)

@last_hp = $game_party.leader.hp

end

end


def update_mp

if @last_mp != $game_party.leader.mp

@mpb.bitmap.clear

ac = $game_party.leader

x = 0

y1 = 0

y2 = 4

width = (80 * (ac.mp.to_f/ac.mmp)).to_i

height1 = y2

height2 = @mpb.bitmap.height - height1

color1 = Color.new(48, 96, 130, 160)

color2 = Color.new(55, 148, 110, 200)

color3 = Color.new(63, 63, 116, 160)

@mpb.bitmap.gradient_fill_rect(x, y1, width, height1, color1, color2, true)

@mpb.bitmap.gradient_fill_rect(x, y2, width, height2, color2, color3, true)

@last_mp = $game_party.leader.mp

end

end


def update_xp

ac = $game_party.leader

if @last_xp != ac.exp

current_lvl = ac.exp - ac.current_level_exp

next_lvl = ac.next_level_exp - ac.current_level_exp

@xpb.bitmap.clear

x = 0

y1 = 0

y2 = 4

width = (80 * (current_lvl.to_f/next_lvl)).to_i

height1 = y2

height2 = @xpb.bitmap.height - height1

color1 = Color.new(48, 96, 130, 160)

color2 = Color.new(55, 148, 110, 200)

color3 = Color.new(63, 63, 116, 160)

@xpb.bitmap.gradient_fill_rect(x, y1, width, height1, color1, color2, true)

@xpb.bitmap.gradient_fill_rect(x, y2, width, height2, color2, color3, true)

@last_xp = $game_party.leader.exp

end

end


def dispose

@hpb.bitmap.dispose

@mpb.bitmap.dispose

@mpb.bitmap.dispose

@hpb.dispose

@mpb.dispose

@mpb.dispose

super

end

end


class De79ItemBar < Sprite

def initialize

super

self.visible = false

self.bitmap = Bitmap.new("Graphics/System/itembar")

self.x = Graphics.width - self.bitmap.width

self.y = Graphics.height - self.bitmap.height

# configs related with image file

@wcx, @wcy = 33, 19

@bcx, @bcy = 77, 19

@scx, @scy = 121, 19

@kcx, @kcy = 165, 19


@last_w = 0

@last_b = 0

@last_s = 0

@last_k = 0


@wb = Sprite.new

@wb.ox, @wb.oy = 12, 12

@wb.x, @wb.y = self.x + @wcx, self.y + @wcy

@wb.bitmap = Bitmap.new(24,24)


@bb = Sprite.new

@bb.ox, @bb.oy = 12, 12

@bb.x, @bb.y = self.x + @bcx, self.y + @bcy

@bb.bitmap = Bitmap.new(24,24)


@sb = Sprite.new

@sb.ox, @sb.oy = 12, 12

@sb.x, @sb.y = self.x + @scx, self.y + @scy

@sb.bitmap = Bitmap.new(24,24)


@kb = Sprite.new

@kb.ox, @kb.oy = 12, 12

@kb.x, @kb.y = self.x + @kcx, self.y + @kcy

@kb.bitmap = Bitmap.new(24,24)


@iconset = Cache.system("Iconset")

end


def update

if $game_switches[ De79Hud::SW_ITEMBAR ]

show

update_w

update_b

update_s

update_k

else

hide

end

end


def show

self.visible = true

@wb.visible = true

@bb.visible = true

@sb.visible = true

@kb.visible = true

end


def hide

self.visible = false

@wb.visible = false

@bb.visible = false

@sb.visible = false

@kb.visible = false

end


def update_w

w = equipped(:weapon)

if @last_w != w

draw_icon( @wb, w )

@last_w = w

end

end


def update_b

b = equipped(:body)

if @last_b != b

draw_icon( @bb, b )

@last_b = b

end

end


def update_s

s = equipped(:shield)

if @last_s != s

draw_icon( @sb, s )

@last_s = s

end

end


def update_k

k = equipped(:key)

if @last_k != k

draw_icon( @kb, k )

@last_k = k

end

end


def equipped(eqclass)

case eqclass

when :weapon

$game_party.leader.equips.each { |item|

return item.icon_index if item.is_a? RPG::Weapon

}

return 0

when :body

$game_party.leader.equips.each do |item|

if item.is_a? RPG::Armor

if item.etype_id == De79Hud::DB_BODY_TYPE

return item.icon_index

end

end

end

return 0

when :shield

$game_party.leader.equips.each do |item|

if item.is_a? RPG::Armor

if item.etype_id == De79Hud::DB_SHIELD_TYPE

return item.icon_index

end

end

end

return 0

when :key

$game_party.leader.equips.each do |item|

if item.is_a? RPG::Armor

if item.etype_id == De79Hud::DB_KEY_TYPE

return item.icon_index

end

end

end

return 0

end

end


def draw_icon(sprite, icon_index)

icon_index = 0 if icon_index.nil?

copy = @iconset

rect = Rect.new( icon_index % 16 * 24, icon_index / 16 * 24, 24, 24 )

sprite.bitmap.blt( 0, 0, copy, rect, 255 )

end


def dispose

@wb.bitmap.dispose

@bb.bitmap.dispose

@sb.bitmap.dispose

@kb.bitmap.dispose

@wb.dispose

@bb.dispose

@sb.dispose

@kb.dispose

super

end

end


class De79HandBar < Sprite

def initialize

super

hide

self.bitmap = Bitmap.new("Graphics/System/handbar")

self.x = Graphics.width/2 - self.bitmap.width/2

self.y = Graphics.height - 1.5 * self.bitmap.height

end


def update

$game_switches[ De79Hud::SW_HANDBAR ] ? show : hide

end


def show

self.visible = true

end


def hide

self.visible = false

end

end


class Scene_Map < Scene_Base

alias de79hud_create_all_windows create_all_windows

def create_all_windows

de79hud_create_all_windows

create_hpbar

create_itembar

create_handbar

end


def create_hpbar

@hpbar = De79HPBar.new

end


def create_itembar

@itembar = De79ItemBar.new

end


def create_handbar

@handbar = De79HandBar.new

end


alias de79hud_update update

def update

de79hud_update

update_de79hud

update_check_hand

end


def update_de79hud

@hpbar.update

@itembar.update

@handbar.update

end


def update_check_hand

x = $game_player.x

y = $game_player.y

direction = $game_player.direction

case direction

when 2 # down

y += 1

when 4 # left

x -= 1

when 6 # right

x += 1

when 8 # up

y -= 1

end

$game_map.events.each_value do |event|

if event.x == x && event.y == y

if !event.through && event.trigger == 0 && event.normal_priority?

$game_switches[ De79Hud::SW_HANDBAR ] = true

return

end

end

end

$game_switches[ De79Hud::SW_HANDBAR ] = false

end

end

 
MyTetra Share v.0.59
Яндекс индекс цитирования