Msn_spaceship_doc_h = -1
local HEALTH_MAX_ROT = -45
local HEALTH_MIN_ROT = -136
local WEAPON_MAX_ROT = -136
local WEAPON_MIN_ROT = -45
local METER_MAX = 91
local Health_meter_img_h = -1
local Health_mask_img_h = -1
local Weapon_meter_img_h = -1
local Weapon_mask_img_h = -1
local Msn_spaceship_thread_test_health_h = -1
function msn_spaceship_init()
Msn_spaceship_doc_h = vint_document_find("msn_spaceship")
Health_meter_img_h = vint_object_find("health_meter_img", 0, Msn_spaceship_doc_h)
Health_mask_img_h = vint_object_find("health_mask_img", 0, Msn_spaceship_doc_h)
Weapon_meter_img_h = vint_object_find("weapon_meter_img", 0, Msn_spaceship_doc_h)
Weapon_mask_img_h = vint_object_find("weapon_mask_img", 0, Msn_spaceship_doc_h)
vint_set_property(Health_meter_img_h, "visible", false)
vint_set_property(Weapon_meter_img_h, "visible", false)
vint_dataitem_add_subscription( "msn_spaceship_di", "update", "msn_spaceship_hud_update" )
--For test
--Msn_spaceship_thread_test_health_h = thread_new("msn_spaceship_test_meters")
end
function msn_spaceship_cleanup()
thread_kill(Msn_spaceship_thread_test_health_h)
Msn_spaceship_thread_test_health_h = -1
end
----------------------------------------------------------------------------------------
--Test function - test the meters
--
function msn_spaceship_test_meters()
local new_pct = 0
while true do
for i=0, 100 do
delay(0.005)
new_pct = new_pct + 1
msn_spaceship_hud_update(new_pct * .01, new_pct * .01)
end
for i=100, 0, -1 do
delay(0.005)
new_pct = new_pct - 1
msn_spaceship_hud_update(new_pct * .01, new_pct * .01)
end
end
end
----------------------------------------------------------------------------------------
--Update the spaceship health and weapon meters
--
function msn_spaceship_hud_update(di_h)
local health_pct, weapon_pct = vint_dataitem_get(di_h)
if (health_pct == nil or weapon_pct == nil) then
return
end
--Update health meter
local new_health_mask_rot = (health_pct * METER_MAX) + HEALTH_MIN_ROT
vint_set_property(Health_mask_img_h, "rotation", new_health_mask_rot * DEG_TO_RAD)
vint_set_property(Health_meter_img_h, "visible", true)
--Update weapon meter
local new_weapon_mask_rot = (weapon_pct * METER_MAX * -1) + WEAPON_MIN_ROT
vint_set_property(Weapon_mask_img_h, "rotation", new_weapon_mask_rot * DEG_TO_RAD)
vint_set_property(Weapon_meter_img_h, "visible", true)
end