./hud_running_man.lua

  1. --Enums for events 
  2. RM_FIRE_TRAP 				= 1 
  3. RM_ELECTRIC_TRAP 			= 2 
  4. RM_FIRE_TRAP_KILL 		= 3 
  5. RM_ELECTRIC_TRAP_KILL 	= 4 
  6. RM_PRESENT_AWARDED		= 5 
  7. RM_PRESENT_SPAWN			= 6 
  8. RM_PRESENT_EXPLODED		= 7 
  9. RM_PRESENT_WARNING 		= 8 
  10. RM_MULTI_5X					= 9 
  11. RM_HUNTER_SPAWN			= 10 
  12. RM_HUNTER_KILLED			= 11 
  13. RM_HUNTER_KILL_PLAYER	= 12 
  14. RM_ENEMY_TRAP				= 13 
  15. RM_HUMAN_SHIELD			= 14 
  16. RM_TARGET_ETHICAL			= 15 
  17. RM_TARGET_UNETHICAL		= 16 
  18. RM_TARGET_MONEY			= 17 
  19. RM_TARGET_TIME_BONUS		= 18 
  20. RM_TARGET_HEALTH			= 19 
  21. RM_HEAD_SHOT				= 20 
  22. RM_NUT_SHOT					= 21 
  23. RM_TIME_LOW					= 22 
  24. RM_EXIT_SPAWN				= 23 
  25. RM_START_MATCH				= 24 
  26.  
  27. Data = { 
  28. 	[RM_FIRE_TRAP] = {  
  29. 			animation = "fire_anim",  
  30. 			tween = "end_event_twn", 
  31. 			grps = {"fire_grp"}, 
  32. 			sfx = "RM_HUD_Fire_Trap" 
  33. 	}, 
  34. 	[RM_ELECTRIC_TRAP] = {  
  35. 			animation = "trap_electric_anim",  
  36. 			tween = "end_event_twn", 
  37. 			grps = { "trap_electric_grp" }, 
  38. 			sfx = "RM_HUD_Electricity_Trap", 
  39. 	}, 
  40. 	[RM_FIRE_TRAP_KILL] = {  
  41. 			animation = "do_nothing_anim", 
  42. 			tween = "end_event_twn", 
  43. 			grps = { "do_nothing_grp" }, 
  44. 			sfx = "RM_Player_Killed_by_Fire_Trap", 
  45. 	}, 
  46. 	[RM_ELECTRIC_TRAP_KILL] = {  
  47. 			animation = "do_nothing_anim", 
  48. 			tween = "end_event_twn", 
  49. 			grps = { "do_nothing_grp" }, 
  50. 			sfx = "RM_Player_Killed_by_Fire_Trap", 
  51. 	}, 
  52. 	[RM_PRESENT_AWARDED] = {  
  53. 			animation = "do_nothing_anim",  
  54. 			tween = "end_event_twn", 
  55. 			grps = { "do_nothing_grp" }, 
  56. 			sfx = "RM_Player_Gets_Present", 
  57. 	}, 
  58. 	[RM_PRESENT_SPAWN] = {  
  59. 			animation = "present_anim",  
  60. 			tween = "end_event_twn", 
  61. 			grps = { "present_grp" }, 
  62. 			sfx = "RM_Present_Spawned", 
  63. 	}, 
  64. 	[RM_PRESENT_EXPLODED] = {  
  65. 			animation = "do_nothing_anim", 
  66. 			tween = "end_event_twn", 
  67. 			grps = { "do_nothing_grp" }, 
  68. 			sfx = "RM_Player_Damaged_by_Present", 
  69. 	}, 
  70. 	[RM_PRESENT_WARNING] = {  
  71. 			animation = "do_nothing_anim", 
  72. 			tween = "end_event_twn", 
  73. 			grps = { "do_nothing_grp" }, 
  74. 			sfx = "RM_Present_About_to_Explode", 
  75. 	}, 
  76. 	[RM_MULTI_5X] = {  
  77. 			animation = "5x_anim",  
  78. 			tween = "end_event_twn", 
  79. 			grps = { "fan_grp", "multiplier_grp" }, 
  80. 			sfx = "RM_5X_Multiplier", 
  81. 	}, 
  82. 	[RM_HUNTER_SPAWN] = {  
  83. 			animation = "hunter_anim",  
  84. 			tween = "end_event_twn", 
  85. 			grps = { "hunter_grp" }, 
  86. 			sfx = "RM_Hunters_Spawned", 
  87. 	}, 
  88. 	[RM_HUNTER_KILLED] = {  
  89. 			animation = "do_nothing_anim",  
  90. 			tween = "end_event_twn", 
  91. 			grps = { "do_nothing_grp" }, 
  92. 			sfx = "RM_Kills_Hunter", 
  93. 	}, 
  94. 	[RM_HUNTER_KILL_PLAYER] = {  
  95. 			animation = "do_nothing_anim",  
  96. 			tween = "end_event_twn", 
  97. 			grps = { "do_nothing_grp" }, 
  98. 			sfx = "RM_Killed_by_Hunter", 
  99. 	}, 
  100. 	[RM_ENEMY_TRAP] = {  
  101. 			animation = "do_nothing_anim",  
  102. 			tween = "end_event_twn", 
  103. 			grps = { "do_nothing_grp" }, 
  104. 			sfx = "RM_Kill_Enemy_With_Trap", 
  105. 	}, 
  106. 	[RM_HUMAN_SHIELD] = {  
  107. 			animation = "do_nothing_anim",  
  108. 			tween = "end_event_twn", 
  109. 			grps = { "do_nothing_grp" }, 
  110. 			sfx = "RM_Take_Human_Shield", 
  111. 	}, 
  112. 	[RM_TARGET_ETHICAL] = {  
  113. 			animation = "ethical_anim",  
  114. 			tween = "end_event_twn", 
  115. 			grps = { "ethical_grp" }, 
  116. 			sfx = "RM_HUD_Ethical", 
  117. 	},	 
  118. 	[RM_TARGET_UNETHICAL] = {  
  119. 			animation = "unethical_anim",  
  120. 			tween = "end_event_twn", 
  121. 			grps = { "unethical_grp" }, 
  122. 			sfx = "RM_HUD_Unethical", 
  123. 	}, 
  124. 	[RM_TARGET_MONEY] = {  
  125. 			animation = "money_shot_anim",  
  126. 			tween = "end_event_twn", 
  127. 			grps = { "money_shot_grp" }, 
  128. 			sfx = "RM_Shoot_Money_Target", 
  129. 	}, 
  130. 	[RM_TARGET_TIME_BONUS] = {  
  131. 			animation = "time_bonus_anim",  
  132. 			tween = "end_event_twn", 
  133. 			grps = { "time_bonus_grp", "genki_head_grp" }, 
  134. 			sfx = "RM_HUD_Time_Bonus", 
  135. 	}, 
  136. 	[RM_TARGET_HEALTH] = {  
  137. 			animation = "health_anim",  
  138. 			tween = "end_event_twn", 
  139. 			grps = { "health_grp" }, 
  140. 			sfx = "RM_HUD_Health", 
  141. 	},	 
  142. 	[RM_HEAD_SHOT] = {  
  143. 			animation = "do_nothing_anim", 
  144. 			tween = "end_event_twn", 
  145. 			grps = { "do_nothing_grp" }, 
  146. 			sfx = "RM_Headshot", 
  147. 	}, 
  148. 	[RM_NUT_SHOT] = {  
  149. 			animation = "do_nothing_anim",  
  150. 			tween = "end_event_twn", 
  151. 			grps = { "do_nothing_grp" }, 
  152. 			sfx = "RM_Nutshot", 
  153. 	}, 
  154. 	[RM_TIME_LOW] = {  
  155. 			animation = "time_low_anim",  
  156. 			tween = "end_event_twn", 
  157. 			grps = { "timer_grp", "fan_grp", "genki_head_grp" }, 
  158. 			sfx = "RM_HUD_Timer", 
  159. 	}, 
  160. 	[RM_EXIT_SPAWN] = {  
  161. 			animation = "exit_spawn_anim",  
  162. 			tween = "end_event_twn", 
  163. 			grps = { "exit_spawned_grp" }, 
  164. 			sfx = "RM_Exiting", 
  165. 	},	 
  166. 	[RM_START_MATCH] = {  
  167. 			animation = "do_nothing_anim",  
  168. 			tween = "end_event_twn", 
  169. 			grps = { "do_nothing_grp" }, 
  170. 			sfx = "RM_Start_Match", 
  171. 	},	 
  172. } 
  173.  
  174. Hud_running_man_doc_handle = -1 
  175.  
  176. local Event_played = -1 
  177. local Timer_audio = 0 
  178. local Event_is_playing = false 
  179. local Running_man_peg_loaded = false 
  180. local Panda_is_sad = false 
  181. local Rm_hud_event_audio_id = -1 
  182.  
  183.  
  184.  
  185. function hud_running_man_init() 
  186. 	Hud_running_man_doc_handle = vint_document_find("hud_running_man") 
  187. 		 
  188. 	-- unload the full screen map to pillage memory 
  189. 	pause_map_dump() 
  190. 	 
  191. 	-- Jon, uncomment this line if you want to test outside the activity.. but remember to comment it back before you check in. 
  192. 	-- Love, Darryl 
  193. 	--thread_new("test_running_man") 
  194. 	 
  195. 	for key, event in pairs(Data) do 
  196. 		local anim_h = vint_object_find(event.animation) 
  197. 		local tween_h = vint_object_find(event.tween, anim_h) 
  198. 		vint_set_property(tween_h, "end_event", "end_event_anim") 
  199. 		vint_apply_start_values(anim_h) 
  200. 		 
  201. 		for key2, group_name in pairs (event.grps) do 
  202. 			local group_h = vint_object_find(group_name) 
  203. 			vint_set_property(group_h, "visible", false) 
  204. 		end			 
  205. 	end 
  206. 	 
  207. 	-- Set up looping tweens 
  208. 	local unethical_anim = Vdo_anim_object:new("unethical_anim", 0, Hud_running_man_doc_handle) 
  209. 	local trap_electric_anim = Vdo_anim_object:new("trap_eletric_anim", 0, Hud_running_man_doc_handle) 
  210. 	local health_anim = Vdo_anim_object:new("health_anim", 0, Hud_running_man_doc_handle) 
  211. 	local money_shot_anim = Vdo_anim_object:new("money_shot_anim", 0, Hud_running_man_doc_handle) 
  212. 	 
  213. 	local panda_shock_twn = Vdo_tween_object:new("panda_shock_twn", trap_electric_anim.handle) 
  214. 	panda_shock_twn:set_end_event("hud_running_man_switch_panda")	 
  215. 	 
  216. 	local panda_twn = Vdo_tween_object:new("panda_twn", unethical_anim.handle) 
  217. 	panda_twn:set_end_event("hud_running_man_switch_panda") 
  218. end 
  219.  
  220. function test_running_man() 
  221. 	delay(1) 
  222. 	hud_running_man_load_complete() 
  223. end 
  224.  
  225. function hud_running_man_load_complete() 
  226. 	game_peg_load_with_cb("hud_running_man_peg_loaded", 1, "ui_bms_rm") 
  227. end 
  228.  
  229. function hud_running_man_peg_loaded() 
  230. 	Running_man_peg_loaded = true 
  231. 	hud_running_man_event_update(RM_START_MATCH) 
  232. end 
  233.  
  234. function hud_running_man_event_update(event_idx, timer) 
  235. 	-- check if we're using the time low event 
  236. 	if event_idx == RM_TIME_LOW then 
  237. 		hud_running_man_play_time_low(event_idx, timer) 
  238. 		return 
  239. 	end 
  240. 	 
  241. 	if Running_man_peg_loaded == false then 
  242. 		return 
  243. 	end 
  244. 	 
  245. 	--Always interrupt an existing event to play something newer 
  246. 	if Event_is_playing then 
  247. 		end_event_anim() 
  248. 	end 
  249. 	 
  250. 	-- DEBUG TEXT MESSAGE 
  251. 	-- local do_nothing_txt = Vdo_base_object:new("do_nothing_txt", 0, Hud_running_man_doc_handle) 
  252. 	-- do_nothing_txt:set_text("Event "..event_idx.." fired") 
  253. 	 
  254. 	for key, group_name in pairs(Data[event_idx].grps) do 
  255. 		local group_h = vint_object_find(group_name) 
  256. 		vint_set_property(group_h, "visible", true) 
  257. 	end 
  258. 		 
  259. 	local anim_h = vint_object_find(Data[event_idx].animation) 
  260. 	lua_play_anim(anim_h) 
  261. 	 
  262. 	if Data[event_idx].sfx ~= nil then 
  263. 		Rm_hud_event_audio_id = audio_object_post_event("Activity", {"Activity_Type","Running_Man"}, {"Running_Man",Data[event_idx].sfx}) 
  264. 	end 
  265. 	 
  266. 	Event_is_playing = true 
  267. 	Event_played = event_idx 
  268. end 
  269.  
  270. function end_event_anim() 
  271. 	-- hide grps that were used and stop animation 
  272. 	for key, group_name in pairs(Data[Event_played].grps) do 
  273. 		local group_h = vint_object_find(group_name) 
  274. 		vint_set_property(group_h, "visible", false) 
  275. 	end 
  276. 	 
  277. 	-- stop animation 
  278. 	vint_set_property(vint_object_find(Data[Event_played].animation),"is_paused", true) 
  279. 	 
  280. 	-- Mark it ended 
  281. 	Event_is_playing = false 
  282. end 
  283.  
  284. function hud_running_man_cleanup()	 
  285. 	game_peg_unload("ui_bms_rm") 
  286. 	 
  287. 	pause_map_restore() 
  288. end 
  289.  
  290. function hud_running_man_switch_panda(twn_handle) 
  291. 	 
  292. 	local anim_h = vint_object_parent(twn_handle) 
  293. 	 
  294. 	local unethical_anim_h = vint_object_find("unethical_anim") 
  295. 	local trap_electric_anim_h = vint_object_find("trap_electric_anim") 
  296. 		 
  297. 	local panda_img 
  298. 	 
  299. 	if anim_h == unethical_anim_h then 
  300. 		 
  301. 		panda_img = Vdo_base_object:new("panda_img", 0, Hud_running_man_doc_handle)	 
  302. 	 
  303. 		if Panda_is_sad then 
  304. 			panda_img:set_image("ui_rm_nuetral_panda")				 
  305. 			Panda_is_sad = false		 
  306. 		else 
  307. 			panda_img:set_image("ui_rm_sad_panda")	 
  308. 			Panda_is_sad = true 
  309. 		end 
  310. 		 
  311. 	elseif anim_h == trap_electric_anim_h then 
  312. 		 
  313. 		panda_img = Vdo_base_object:new("panda_shocked", 0, Hud_running_man_doc_handle) 
  314. 				 
  315. 		if Panda_is_sad then 
  316. 			panda_img:set_image("ui_rm_panda_shocked")				 
  317. 			Panda_is_sad = false		 
  318. 		else 
  319. 			panda_img:set_image("ui_rm_panda_skeleton")	 
  320. 			Panda_is_sad = true 
  321. 		end 
  322. 	 
  323. 	end	 
  324. end 
  325.  
  326.  
  327. function hud_running_man_play_time_low(event_idx, timer) 
  328.  
  329. 	local timer_grp = Vdo_base_object:new("timer_grp", 0, Hud_running_man_doc_handle) 
  330. 	local genki_head_grp = Vdo_base_object:new("genki_head_grp", 0, Hud_running_man_doc_handle) 
  331. 	local anim_h = vint_object_find("time_low_anim") 
  332. 	local timer_txt = Vdo_base_object:new("timer_txt", 0, Hud_running_man_doc_handle) 
  333. 	 
  334. 	if Event_is_playing == false and timer > -1 then 
  335. 		timer_txt:set_text(format_time(timer/1000), false, false) 
  336. 		lua_play_anim(anim_h) 
  337. 		Timer_audio = audio_object_post_event("Activity", {"Activity_Type","Running_Man"}, {"Running_Man","RM_HUD_Timer"}) 
  338. 		 
  339. 		timer_grp:set_visible(true) 
  340. 		genki_head_grp:set_visible(true) 
  341. 		Event_is_playing = true 
  342. 	elseif timer > -1 then 
  343. 		timer_txt:set_text(format_time(timer/1000), false, false) 
  344. 		if timer <= 0 then 
  345. 			if Timer_audio > 0 then 
  346. 				audio_stop(Timer_audio) 
  347. 				Timer_audio = 0 
  348. 			end 
  349. 		end 
  350. 	elseif timer == -1 then 
  351. 		timer_grp:set_visible(false) 
  352. 		genki_head_grp:set_visible(true) 
  353. 		vint_set_property(anim_h, "is_paused", true) 
  354. 		 
  355. 		if Timer_audio > 0 then 
  356. 			audio_stop(Timer_audio) 
  357. 			Timer_audio = 0 
  358. 		end 
  359. 		 
  360. 		Event_is_playing = false 
  361. 	end 
  362.  
  363. end