./countdown.lua

  1. local COUNTDOWN_DISPLAY_1 = 3 
  2. local COUNTDOWN_DISPLAY_2 = 2 
  3. local COUNTDOWN_DISPLAY_3 = 1 
  4. local COUNTDOWN_DISPLAY_GO = 0 
  5.  
  6. local COUNTDOWN_DISPLAY_DATA = { 
  7. 	[COUNTDOWN_DISPLAY_1] = { sfx = "UI_HUD_Countdown", txt = "3", header_anim = "header_in_anim"}, 
  8. 	[COUNTDOWN_DISPLAY_2] = { sfx = "UI_HUD_Countdown", txt = "2"}, 
  9. 	[COUNTDOWN_DISPLAY_3] = { sfx = "UI_HUD_Countdown", txt = "1"}, 
  10. 	[COUNTDOWN_DISPLAY_GO] = { sfx = "UI_HUD_Countdown_End", txt = "COUNTDOWN_GO", header_anim = "header_out_anim"}, 
  11. } 
  12.  
  13. local Countdown_title = false		--no countdown title by default... 
  14. local Countdown_anims_playing = {}	--storage for all of our animations... 
  15.  
  16. --Init 
  17. function countdown_init() 
  18. 	--Hide Everything 
  19. 	local h = vint_object_find("header_txt") 
  20. 	vint_set_property(h, "alpha", 0) 
  21. 	 
  22. 	local h = vint_object_find("number_txt") 
  23. 	vint_set_property(h, "alpha", 0) 
  24. end 
  25.  
  26. function countdown_cleanup() 
  27. end 
  28.  
  29. ------------------------------------------------------------------------------- 
  30. -- Sets the countdown title 
  31. -- @param	title_str	String for title 
  32. -- 
  33. function countdown_set_title(title_str) 
  34. 	local h = vint_object_find("header_txt") 
  35. 	vint_set_property(h, "text_tag", title_str) 
  36. 	Countdown_title = true 
  37. end 
  38.  
  39. ------------------------------------------------------------------------------- 
  40. -- Plays a number count... 
  41. -- @parem id		COUNTDOWN_DISPLAY_1, COUNTDOWN_DISPLAY_2, COUNTDOWN_DISPLAY_3, COUNTDOWN_DISPLAY_GO 
  42. function countdown_display(id) 
  43.  
  44. 	local data = COUNTDOWN_DISPLAY_DATA[id] 
  45. 	 
  46. 	--Set text tag of countdown  "#" or "GO!" 
  47. 	local number_txt_h = vint_object_find("number_txt") 
  48. 	vint_set_property(number_txt_h, "text_tag", data.txt) 
  49. 	 
  50. 	--always play number in animation... 
  51. 	local anim_h = vint_object_find("number_anim") 
  52. 	lua_play_anim(anim_h) 
  53. 	 
  54. 	Countdown_anims_playing[1] = anim_h 
  55. 	 
  56. 	--play custom anim if needed... (fade in or out of title) 
  57. 	if Countdown_title == true then 
  58. 		if data.header_anim ~= nil then 
  59. 			local anim_h = vint_object_find(data.header_anim) 
  60. 			lua_play_anim(anim_h) 
  61. 			Countdown_anims_playing[2] = anim_h 
  62. 		end 
  63. 	end 
  64. 	 
  65. 	--play sound... 
  66. 	if data.sfx ~= nil then 
  67. 		game_UI_audio_play(data.sfx) 
  68. 	end 
  69. end 
  70.  
  71. ------------------------------------------------------------------------------- 
  72. -- Pauses animations and hides the screen... 
  73. -- 
  74. function countdown_pause() 
  75. 	local h = vint_object_find("countdown_grp") 
  76. 	vint_set_property(h, "visible", false) 
  77. 	countdown_pause_anims(true) 
  78. end 
  79.  
  80. ------------------------------------------------------------------------------- 
  81. -- Unpauses animations and shows the screen... (called from c++) 
  82. -- 
  83. function countdown_unpause() 
  84. 	local h = vint_object_find("countdown_grp") 
  85. 	vint_set_property(h, "visible", true) 
  86. 	countdown_pause_anims(false) 
  87. end 
  88.  
  89. ------------------------------------------------------------------------------- 
  90. -- Pauses or unpaused all animations... 
  91. -- @param	is_paused 	True if you want to pause, false if you do not... 
  92. -- 
  93. function countdown_pause_anims(is_paused) 
  94. 	for i=1, #Countdown_anims_playing do 
  95. 		vint_set_property(Countdown_anims_playing[i], "is_paused", is_paused) 
  96. 	end 
  97. end 
  98.  
  99. function test_countdown_1() 
  100. 	countdown_display(COUNTDOWN_DISPLAY_1) 
  101. end 
  102.  
  103. function test_countdown_2() 
  104. 	countdown_display(COUNTDOWN_DISPLAY_2) 
  105. end 
  106.  
  107. function test_countdown_3() 
  108. 	countdown_display(COUNTDOWN_DISPLAY_3) 
  109. end 
  110.  
  111. function test_countdown_4() 
  112. 	countdown_display(COUNTDOWN_DISPLAY_GO) 
  113. end 
  114.  
  115. function test_countdown_title() 
  116. 	countdown_set_title("WAVE 15") 
  117. end