./msn_spaceship.lua

  1. Msn_spaceship_doc_h = -1 
  2.  
  3. local HEALTH_MAX_ROT = -45 
  4. local HEALTH_MIN_ROT = -136 
  5. local WEAPON_MAX_ROT = -136 
  6. local WEAPON_MIN_ROT = -45 
  7. local METER_MAX = 91 
  8.  
  9. local Health_meter_img_h = -1 
  10. local Health_mask_img_h = -1 
  11. local Weapon_meter_img_h = -1 
  12. local Weapon_mask_img_h = -1 
  13.  
  14. local Msn_spaceship_thread_test_health_h = -1 
  15.  
  16.  
  17. function msn_spaceship_init() 
  18. 	Msn_spaceship_doc_h = vint_document_find("msn_spaceship") 
  19.  
  20. 	Health_meter_img_h = vint_object_find("health_meter_img", 0, Msn_spaceship_doc_h) 
  21. 	Health_mask_img_h = vint_object_find("health_mask_img", 0, Msn_spaceship_doc_h) 
  22. 	 
  23. 	Weapon_meter_img_h = vint_object_find("weapon_meter_img", 0, Msn_spaceship_doc_h) 
  24. 	Weapon_mask_img_h = vint_object_find("weapon_mask_img", 0, Msn_spaceship_doc_h) 
  25. 	 
  26. 	vint_set_property(Health_meter_img_h, "visible", false)		 
  27. 	vint_set_property(Weapon_meter_img_h, "visible", false)	 
  28. 	 
  29. 	vint_dataitem_add_subscription( "msn_spaceship_di", "update", "msn_spaceship_hud_update" ) 
  30. 		 
  31. 	--For test 
  32. 	--Msn_spaceship_thread_test_health_h = thread_new("msn_spaceship_test_meters") 
  33. end 
  34.  
  35.  
  36. function msn_spaceship_cleanup() 
  37. 	thread_kill(Msn_spaceship_thread_test_health_h) 
  38. 	Msn_spaceship_thread_test_health_h = -1 
  39. end 
  40.  
  41.  
  42. ---------------------------------------------------------------------------------------- 
  43. --Test function - test the meters 
  44. -- 
  45. function msn_spaceship_test_meters() 
  46. 	local new_pct = 0 
  47. 	 
  48. 	while true do 
  49. 		for i=0, 100 do 
  50. 			delay(0.005) 
  51. 			new_pct = new_pct + 1 
  52. 			msn_spaceship_hud_update(new_pct * .01, new_pct * .01) 
  53. 		end 
  54. 		 
  55. 		for i=100, 0, -1 do 
  56. 			delay(0.005) 
  57. 			new_pct = new_pct - 1  
  58. 			msn_spaceship_hud_update(new_pct * .01, new_pct * .01) 
  59. 		end 
  60. 	end 
  61. end 
  62.  
  63.  
  64. ---------------------------------------------------------------------------------------- 
  65. --Update the spaceship health and weapon meters 
  66. -- 
  67. function msn_spaceship_hud_update(di_h)	 
  68. 	local health_pct, weapon_pct = vint_dataitem_get(di_h) 
  69. 	 
  70. 	if (health_pct == nil or weapon_pct == nil) then 
  71. 		return 
  72. 	end 
  73.  
  74. 	--Update health meter 
  75. 	local new_health_mask_rot = (health_pct * METER_MAX) + HEALTH_MIN_ROT		 
  76. 	vint_set_property(Health_mask_img_h, "rotation", new_health_mask_rot * DEG_TO_RAD)	 
  77. 	vint_set_property(Health_meter_img_h, "visible", true) 
  78. 	 
  79. 	--Update weapon meter 
  80. 	local new_weapon_mask_rot = (weapon_pct * METER_MAX * -1) + WEAPON_MIN_ROT 		 
  81. 	vint_set_property(Weapon_mask_img_h, "rotation", new_weapon_mask_rot * DEG_TO_RAD)	 
  82. 	vint_set_property(Weapon_meter_img_h, "visible", true) 
  83. end 
  84.  
  85.  
  86.