module ALLY_HUD
Toggle = 27
Xcoord = 405
Ycoord = 210
end
class Window_Base < Window
#===============================================================#
# draw_ally_health
# Controls the drawing of the arc hp bar for allies.
#===============================================================#
def draw_ally_health(i = 0, x = 0, y = 0, actor = 0, siren = 0)
#=============================================================#
# Small formula determines which picture should be displayed. #
#=============================================================#
q = (i * 10) # Total amount of pictures needed.
w = ($game_party.actors[actor].maxhp.to_f / q.to_f) # Hp per picture.
for c in (1..q)
a = (w * c) # Top hp range
b = (w * c) - w # Low hp range
if ($game_party.actors[1].hp > b && $game_party.actors[actor].hp <= a)
j = c.floor
end
end
# This is the siren effect. It is activated at low health and switches
# the background graphic, making it appear to flash red.
if siren == 0
background = RPG::Cache.picture("Ally_Hud/" + "Background-" + (i.to_s))
else
background = RPG::Cache.picture("Ally_Hud/" + "Background-" + (i.to_s) + "-2")
end
# This is the green health bar. The formula determins the ending number.
# places pictures in intervals of 10 for each upgrade. Example:
# No upgrade = Images: 1-10. First upgrade includes 1-20 (11-20 are new pics).
# Look at pictures folder for a better understanding.
if j != nil
arc = RPG::Cache.picture("Ally_Hud/" + (j.to_s))
else
arc = nil
end
cw = background.width
ch = background.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x, y, background, src_rect)
if arc != nil
self.contents.blt(x, y, arc, src_rect)
else
end
end
def draw_ally_face(x, y, actor)
#==========================================================================#
# Looks for the actors face named according to rmxp database
# in folder pictures/Ally_Hud/Faces
#==========================================================================#
name = $game_party.actors[actor].name
face = RPG::Cache.picture("Ally_Hud/Faces/" + name)
cw = face.width
ch = face.height
src_rect = Rect.new(0, 0, cw, ch)
self.contents.blt(x, y, face, src_rect)
end
def draw_ally_hud(x, y, actor, siren)
health = case $game_party.actors[actor].maxhp
when 0..124 then 1
when 125..174 then 2
when 175..224 then 3
else
health = 4
end
draw_ally_health(health, x, y, actor, siren)
draw_ally_face(x, y, actor)
end
end
#==============================================================================#
# Window Ally HUD
# The actual window that holds all the graphics
#==============================================================================#
class Window_Ally_HUD < Window_Base
def initialize(actor)
@act = actor
@siren = false
@alert = 0
@wait = 0
super(0, 0, 245, 107)
self.contents = Bitmap.new(width - 32, height - 32)
self.windowskin = RPG::Cache.windowskin("001-Blue01")
self.opacity = 255
@actor = $game_party.actors[@act]
if @actor != nil
reset
refresh
end
end
def reset
@old_hp = @actor.hp
@max_hp = @actor.maxhp
@old_alert = @alert
end
def refresh
self.contents.clear
reset
draw_ally_hud(0, 0, @act, @alert)
end
def update
if @actor != nil
if @old_hp != @actor.hp or
@max_hp != @actor.maxhp or
@old_alert = @alert
refresh
end
end
if (@actor.hp.to_f / @actor.maxhp < 0.25)
# Wait timer
if (@wait < 11)
@wait += 1
elsif (@wait == 11)
@wait = 0
end
# When @wait is 0-2 @alert = 0
# When @wait is 3-5 @alert = 1
case @wait
when 0..5
@alert = 0
when 6..11
@alert = 1
end
else
# Resets if not in use
@wait = 0
@alert = 0
end
end
end
#==============================================================================#
# Scene Map
# Aliases the ally hud to the map scene
#==============================================================================#
class Scene_Map
alias ally_hud_main main
def main
@ally_1 = $game_party.actors[1]
@ally_2 = $game_party.actors[2]
# if @ally_1 exists then create the hud.
if @ally_1 != nil
@ally_1_hud = Window_Ally_HUD.new(1)
@ally_1_hud.x = ALLY_HUD::Xcoord
@ally_1_hud.y = ALLY_HUD::Ycoord
@ally_1_hud.visible = $game_switches[PLAYER_HUD::Toggle]
end
# if @ally_2 exists then create the hud.
if @ally_2 != nil
@ally_2_hud = Window_Ally_HUD.new(2)
@ally_2_hud.x = ALLY_HUD::Xcoord
@ally_2_hud.y = ALLY_HUD::Ycoord - 85
@ally_2_hud.visible = $game_switches[PLAYER_HUD::Toggle]
end
# Original main code
ally_hud_main
# Dispose @ally_1 only
if @ally_1 != nil
@ally_1_hud.dispose
end
# Dispose @ally_2 only
if @ally_2 != nil
@ally_2_hud.dispose
end
end
alias ally_hud_update update
def update
if @ally_1 != nil
@ally_1_hud.visible = $game_switches[PLAYER_HUD::Toggle]
@ally_1_hud.update
end
if @ally_2 != nil
@ally_2_hud.visible = $game_switches[PLAYER_HUD::Toggle]
@ally_2_hud.update
end
ally_hud_update
end
end