./genki_common.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. GENKI_FLY_TOP_OF_COOL	= 30 
  28. GENKI_FLY_SUPER_ETHICAL	= 31 
  29. GENKI_FLY_CLEARED			= 32 
  30. GENKI_FLY_ETHICAL			= 33 
  31. GENKI_FLY_UNETHICAL		= 34 
  32.  
  33. GENKI_RUN_SHARK			= 40 
  34.  
  35. GENKI_ESCORT_FIRE			= 50 
  36.  
  37. GENKI_BALL_BOUNCE			= 60 
  38.  
  39. --find enums for each mode 
  40.  
  41.  
  42.  
  43. Data = { 
  44. 	[RM_FIRE_TRAP] = {  
  45. 			animation = "fire_anim",  
  46. 			tween = "end_event_twn", 
  47. 			grps = {"fire_grp"}, 
  48. 			sfx = "RM_HUD_Fire_Trap" 
  49. 	}, 
  50. 	[RM_ELECTRIC_TRAP] = {  
  51. 			animation = "trap_electric_anim",  
  52. 			tween = "end_event_twn", 
  53. 			grps = { "trap_electric_grp" }, 
  54. 			sfx = "RM_HUD_Electricity_Trap", 
  55. 	}, 
  56. 	[RM_FIRE_TRAP_KILL] = {  
  57. 			animation = "do_nothing_anim", 
  58. 			tween = "end_event_twn", 
  59. 			grps = { "do_nothing_grp" }, 
  60. 			sfx = "RM_Player_Killed_by_Fire_Trap", 
  61. 	}, 
  62. 	[RM_ELECTRIC_TRAP_KILL] = {  
  63. 			animation = "do_nothing_anim", 
  64. 			tween = "end_event_twn", 
  65. 			grps = { "do_nothing_grp" }, 
  66. 			sfx = "RM_Player_Killed_by_Fire_Trap", 
  67. 	}, 
  68. 	[RM_PRESENT_AWARDED] = {  
  69. 			animation = "do_nothing_anim",  
  70. 			tween = "end_event_twn", 
  71. 			grps = { "do_nothing_grp" }, 
  72. 			sfx = "RM_Player_Gets_Present", 
  73. 	}, 
  74. 	[RM_PRESENT_SPAWN] = {  
  75. 			animation = "present_anim",  
  76. 			tween = "end_event_twn", 
  77. 			grps = { "present_grp" }, 
  78. 			sfx = "RM_Present_Spawned", 
  79. 	}, 
  80. 	[RM_PRESENT_EXPLODED] = {  
  81. 			animation = "do_nothing_anim", 
  82. 			tween = "end_event_twn", 
  83. 			grps = { "do_nothing_grp" }, 
  84. 			sfx = "RM_Player_Damaged_by_Present", 
  85. 	}, 
  86. 	[RM_PRESENT_WARNING] = {  
  87. 			animation = "do_nothing_anim", 
  88. 			tween = "end_event_twn", 
  89. 			grps = { "do_nothing_grp" }, 
  90. 			sfx = "RM_Present_About_to_Explode", 
  91. 	}, 
  92. 	[RM_MULTI_5X] = {  
  93. 			animation = "5x_anim",  
  94. 			tween = "end_event_twn", 
  95. 			grps = { "multiplier_grp" }, 
  96. 			sfx = "RM_5X_Multiplier", 
  97. 	}, 
  98. 	[RM_HUNTER_SPAWN] = {  
  99. 			animation = "hunter_anim",  
  100. 			tween = "end_event_twn", 
  101. 			grps = { "hunter_grp" }, 
  102. 			sfx = "RM_Hunters_Spawned", 
  103. 	}, 
  104. 	[RM_HUNTER_KILLED] = {  
  105. 			animation = "do_nothing_anim",  
  106. 			tween = "end_event_twn", 
  107. 			grps = { "do_nothing_grp" }, 
  108. 			sfx = "RM_Kills_Hunter", 
  109. 	}, 
  110. 	[RM_HUNTER_KILL_PLAYER] = {  
  111. 			animation = "do_nothing_anim",  
  112. 			tween = "end_event_twn", 
  113. 			grps = { "do_nothing_grp" }, 
  114. 			sfx = "RM_Killed_by_Hunter", 
  115. 	}, 
  116. 	[RM_ENEMY_TRAP] = {  
  117. 			animation = "do_nothing_anim",  
  118. 			tween = "end_event_twn", 
  119. 			grps = { "do_nothing_grp" }, 
  120. 			sfx = "RM_Kill_Enemy_With_Trap", 
  121. 	}, 
  122. 	[RM_HUMAN_SHIELD] = {  
  123. 			animation = "do_nothing_anim",  
  124. 			tween = "end_event_twn", 
  125. 			grps = { "do_nothing_grp" }, 
  126. 			sfx = "RM_Take_Human_Shield", 
  127. 	}, 
  128. 	[RM_TARGET_ETHICAL] = {  
  129. 			animation = "ethical_anim",  
  130. 			tween = "end_event_twn", 
  131. 			grps = { "ethical_grp" }, 
  132. 			sfx = "RM_HUD_Ethical", 
  133. 	},	 
  134. 	[RM_TARGET_UNETHICAL] = {  
  135. 			animation = "unethical_anim",  
  136. 			tween = "end_event_twn", 
  137. 			grps = { "unethical_grp" }, 
  138. 			sfx = "RM_HUD_Unethical", 
  139. 	}, 
  140. 	[RM_TARGET_MONEY] = {  
  141. 			animation = "money_shot_anim",  
  142. 			tween = "end_event_twn", 
  143. 			grps = { "money_shot_grp" }, 
  144. 			sfx = "RM_Shoot_Money_Target", 
  145. 	}, 
  146. 	[RM_TARGET_TIME_BONUS] = {  
  147. 			animation = "time_bonus_anim",  
  148. 			tween = "end_event_twn", 
  149. 			grps = { "time_bonus_grp", "genki_head_grp" }, 
  150. 			sfx = "RM_HUD_Time_Bonus", 
  151. 	}, 
  152. 	[RM_TARGET_HEALTH] = {  
  153. 			animation = "health_anim",  
  154. 			tween = "end_event_twn", 
  155. 			grps = { "health_grp" }, 
  156. 			sfx = "RM_HUD_Health", 
  157. 	},	 
  158. 	[RM_HEAD_SHOT] = {  
  159. 			animation = "do_nothing_anim", 
  160. 			tween = "end_event_twn", 
  161. 			grps = { "do_nothing_grp" }, 
  162. 			sfx = "RM_Headshot", 
  163. 	}, 
  164. 	[RM_NUT_SHOT] = {  
  165. 			animation = "do_nothing_anim",  
  166. 			tween = "end_event_twn", 
  167. 			grps = { "do_nothing_grp" }, 
  168. 			sfx = "RM_Nutshot", 
  169. 	}, 
  170. 	[RM_TIME_LOW] = {  
  171. 			animation = "time_low_anim",  
  172. 			tween = "end_event_twn", 
  173. 			grps = { "timer_grp", "genki_head_grp" }, 
  174. 			sfx = "RM_HUD_Timer", 
  175. 	}, 
  176. 	[RM_EXIT_SPAWN] = {  
  177. 			animation = "exit_spawn_anim",  
  178. 			tween = "end_event_twn", 
  179. 			grps = { "exit_spawned_grp" }, 
  180. 			sfx = "RM_Exiting", 
  181. 	},	 
  182. 	[RM_START_MATCH] = {  
  183. 			animation = "do_nothing_anim",  
  184. 			tween = "end_event_twn", 
  185. 			grps = { "do_nothing_grp" }, 
  186. 			sfx = "RM_Start_Match", 
  187. 	},	 
  188. 	[GENKI_FLY_TOP_OF_COOL] = {  
  189. 			animation = "top_of_cool_anim",  
  190. 			tween = "end_event_twn", 
  191. 			grps = { "top_of_cool_grp" }, 
  192. 			sfx = "Panda_HUD_Cool", 
  193. 			no_switch_sfx = true, 
  194. 	},	 
  195. 	[GENKI_FLY_SUPER_ETHICAL] = {  
  196. 			animation = "super_ethical_anim",  
  197. 			tween = "end_event_twn", 
  198. 			grps = { "super_ethical_grp" }, 
  199. 			sfx = "Panda_HUD_Super_Ethical", 
  200. 			no_switch_sfx = true,		 
  201. 	},	 
  202. 	[GENKI_FLY_CLEARED] = {  
  203. 			animation = "cleared_anim",  
  204. 			tween = "end_event_twn", 
  205. 			grps = { "cleared_grp" }, 
  206. 			sfx = "Panda_HUD_Cleared", 
  207. 			no_switch_sfx = true, 
  208. 	},	 
  209. 	[GENKI_FLY_ETHICAL] = {  
  210. 			animation = "ethical_anim",  
  211. 			tween = "end_event_twn", 
  212. 			grps = { "ethical_grp" }, 
  213. 			sfx = "Panda_HUD_Ethical", 
  214. 			no_switch_sfx = true, 
  215. 	},	 
  216. 	[GENKI_FLY_UNETHICAL] = {  
  217. 			animation = "unethical_anim",  
  218. 			tween = "end_event_twn", 
  219. 			grps = { "unethical_grp" }, 
  220. 			sfx = "Panda_HUD_Unethical", 
  221. 			no_switch_sfx = true, 
  222. 	},	 
  223. 	[GENKI_RUN_SHARK] = {  
  224. 			animation = "shark_anim",  
  225. 			tween = "end_event_twn", 
  226. 			grps = { "shark_grp" }, 
  227. 			sfx = "Jungle_HUD_Water_Bear", 
  228. 			no_switch_sfx = true, 
  229. 	},	 
  230. 	[GENKI_ESCORT_FIRE] = {  
  231. 			animation = "fire_car_anim",  
  232. 			tween = "end_event_twn", 
  233. 			grps = { "fire_car_grp" }, 
  234. 			sfx = "Escort_HUD_Flame", 
  235. 			no_switch_sfx = true, 
  236. 	},	 
  237. 	[GENKI_BALL_BOUNCE] = {  
  238. 			animation = "bounce_anim",  
  239. 			tween = "end_event_twn", 
  240. 			grps = { "bounce_grp" }, 
  241. 			sfx = "Yarnball_HUD_Shockwave", 
  242. 			no_switch_sfx = true, 
  243. 	}, 
  244. } 
  245.  
  246. Genki_run_doc_handle = -1 
  247. Genki_ball_doc_handle = -1 
  248. Genki_fly_doc_handle = -1 
  249. Genki_escort_doc_handle = -1 
  250.  
  251. local Event_played = -1 
  252. local Timer_audio = 0 
  253. local Event_is_playing = false 
  254. local Running_man_peg_loaded = false 
  255. local Panda_is_sad = false 
  256. local Rm_hud_event_audio_id = -1 
  257.  
  258. Genki_common_doc_handle = -1 
  259.  
  260. function genki_ball_init() 
  261. 	genki_common_init() 
  262. end 
  263. function genki_escort_init() 
  264. 	genki_common_init() 
  265. end 
  266. function genki_fly_init() 
  267. 	genki_common_init() 
  268. end 
  269. function genki_run_init() 
  270. 	genki_common_init() 
  271. end 
  272.  
  273. function genki_common_init() 
  274.  
  275. 	--assign doc handle 
  276. 	Genki_run_doc_handle = vint_document_find("genki_run") 
  277. 	Genki_ball_doc_handle = vint_document_find("genki_ball") 
  278. 	Genki_fly_doc_handle = vint_document_find("genki_fly") 
  279. 	Genki_escort_doc_handle = vint_document_find("genki_escort") 
  280. 	 
  281. 	if Genki_run_doc_handle ~= nil and Genki_run_doc_handle > 0 then 
  282. 		Genki_common_doc_handle = Genki_run_doc_handle 
  283. 		-- unload the full screen map to pillage memory 
  284. 		pause_map_dump() 
  285. 	elseif Genki_ball_doc_handle ~= nil and Genki_ball_doc_handle > 0 then 
  286. 		Genki_common_doc_handle = Genki_ball_doc_handle 
  287. 	elseif Genki_fly_doc_handle ~= nil and Genki_fly_doc_handle > 0 then 
  288. 		Genki_common_doc_handle = Genki_fly_doc_handle 
  289. 		pause_map_dump() 
  290. 	elseif Genki_escort_doc_handle ~= nil and Genki_escort_doc_handle > 0 then 
  291. 		Genki_common_doc_handle = Genki_escort_doc_handle 
  292. 	end 
  293. 		 
  294. 	 
  295. 	 
  296. 	-- Jon, uncomment this line if you want to test outside the activity.. but remember to comment it back before you check in. 
  297. 	-- Love, Darryl 
  298. 	--thread_new("test_running_man") 
  299. 	 
  300. 	for key, event in pairs(Data) do 
  301. 		local anim_h = vint_object_find(event.animation) 
  302. 		local tween_h = vint_object_find(event.tween, anim_h) 
  303. 		vint_set_property(tween_h, "end_event", "end_event_anim") 
  304. 		vint_apply_start_values(anim_h) 
  305. 		 
  306. 		for key2, group_name in pairs (event.grps) do 
  307. 			local group_h = vint_object_find(group_name) 
  308. 			vint_set_property(group_h, "visible", false) 
  309. 		end			 
  310. 	end 
  311. 	 
  312. 	-- Set up looping tweens that need to switch images 
  313. 	local unethical_anim = Vdo_anim_object:new("unethical_anim", 0, Genki_common_doc_handle) 
  314. 	local trap_electric_anim = Vdo_anim_object:new("trap_eletric_anim", 0, Genki_common_doc_handle) 
  315. 	 
  316. 	local panda_shock_twn = Vdo_tween_object:new("panda_shock_twn", trap_electric_anim.handle) 
  317. 	panda_shock_twn:set_end_event("hud_running_man_switch_panda")	 
  318. 	 
  319. 	local panda_twn = Vdo_tween_object:new("panda_twn", unethical_anim.handle) 
  320. 	panda_twn:set_end_event("hud_running_man_switch_panda") 
  321. end 
  322.  
  323. --------------------- 
  324. --testing stuff start 
  325. --------------------- 
  326.  
  327. function test_running_man() 
  328. 	delay(1) 
  329. 	hud_running_man_load_complete() 
  330. end 
  331.  
  332. function hud_running_man_load_complete() 
  333. 	if Genki_common_doc_handle == Genki_run_doc_handle or Genki_common_doc_handle == Genki_fly_doc_handle then 
  334. 		game_peg_load_with_cb("hud_running_man_peg_loaded", 1, "ui_bms_rm") 
  335. 	end 
  336. end 
  337.  
  338. function hud_running_man_peg_loaded() 
  339. 	Running_man_peg_loaded = true 
  340. 	hud_running_man_event_update(RM_START_MATCH) 
  341. end 
  342.  
  343. ------------------- 
  344. --testing stuff end 
  345. ------------------- 
  346.  
  347. function hud_running_man_event_update(event_idx, timer) 
  348. 	-- check if we're using the time low event 
  349. 	if event_idx == RM_TIME_LOW then 
  350. 		hud_running_man_play_time_low(event_idx, timer) 
  351. 		return 
  352. 	end 
  353. 	 
  354. 	if Running_man_peg_loaded == false then 
  355. 		if	Genki_common_doc_handle == Genki_run_doc_handle or Genki_common_doc_handle == Genki_fly_doc_handle then 
  356. 			return 
  357. 		end 
  358. 	end 
  359. 	 
  360. 	 
  361. 	--Always interrupt an existing event to play something newer 
  362. 	if Event_is_playing then 
  363. 		end_event_anim() 
  364. 	end 
  365. 	 
  366. 	-- DEBUG TEXT MESSAGE 
  367. 	-- local do_nothing_txt = Vdo_base_object:new("do_nothing_txt", 0, Genki_common_doc_handle) 
  368. 	-- do_nothing_txt:set_text("Event "..event_idx.." fired") 
  369. 	 
  370. 	for key, group_name in pairs(Data[event_idx].grps) do 
  371. 		local group_h = vint_object_find(group_name) 
  372. 		vint_set_property(group_h, "visible", true) 
  373. 	end 
  374. 		 
  375. 	local anim_h = vint_object_find(Data[event_idx].animation) 
  376. 	lua_play_anim(anim_h) 
  377. 	 
  378. 	if Data[event_idx].sfx ~= nil then 
  379. 	 
  380. 		if Data[event_idx].no_switch_sfx then 
  381. 			Rm_hud_event_audio_id = audio_object_post_event(Data[event_idx].sfx)		 
  382. 		else 
  383. 			Rm_hud_event_audio_id = audio_object_post_event("Activity", {"Activity_Type","Running_Man"}, {"Running_Man",Data[event_idx].sfx}) 
  384. 		end 
  385. 	end 
  386. 	 
  387. 	Event_is_playing = true 
  388. 	Event_played = event_idx 
  389. end 
  390.  
  391. function end_event_anim() 
  392. 	-- hide grps that were used and stop animation 
  393. 	for key, group_name in pairs(Data[Event_played].grps) do 
  394. 		local group_h = vint_object_find(group_name) 
  395. 		vint_set_property(group_h, "visible", false) 
  396. 	end 
  397. 	 
  398. 	-- stop animation 
  399. 	vint_set_property(vint_object_find(Data[Event_played].animation),"is_paused", true) 
  400. 	 
  401. 	-- Mark it ended 
  402. 	Event_is_playing = false 
  403. end 
  404.  
  405. function genki_ball_cleanup() 
  406. 	genki_common_cleanup() 
  407. end 
  408. function genki_escort_cleanup() 
  409. 	genki_common_cleanup() 
  410. end 
  411. function genki_fly_cleanup() 
  412. 	genki_common_cleanup() 
  413. end 
  414. function genki_run_cleanup() 
  415. 	genki_common_cleanup() 
  416. end 
  417.  
  418. function genki_common_cleanup()	 
  419. 	if Genki_common_doc_handle == Genki_run_doc_handle or Genki_common_doc_handle == Genki_fly_doc_handle then 
  420. 		game_peg_unload("ui_bms_rm") 
  421. 		pause_map_restore() 
  422. 	end 
  423. end 
  424.  
  425. function hud_running_man_switch_panda(twn_handle) 
  426. 	 
  427. 	local anim_h = vint_object_parent(twn_handle) 
  428. 	 
  429. 	local unethical_anim_h = vint_object_find("unethical_anim") 
  430. 	local trap_electric_anim_h = vint_object_find("trap_electric_anim") 
  431. 		 
  432. 	local panda_img 
  433. 	 
  434. 	if anim_h == unethical_anim_h then 
  435. 		 
  436. 		panda_img = Vdo_base_object:new("panda_img", 0, Genki_common_doc_handle)	 
  437. 	 
  438. 		if Panda_is_sad then 
  439. 			panda_img:set_image("ui_rm_nuetral_panda")				 
  440. 			Panda_is_sad = false		 
  441. 		else 
  442. 			panda_img:set_image("ui_rm_sad_panda")	 
  443. 			Panda_is_sad = true 
  444. 		end 
  445. 		 
  446. 	elseif anim_h == trap_electric_anim_h then 
  447. 		 
  448. 		panda_img = Vdo_base_object:new("panda_shocked", 0, Genki_common_doc_handle) 
  449. 				 
  450. 		if Panda_is_sad then 
  451. 			panda_img:set_image("ui_rm_panda_shocked")				 
  452. 			Panda_is_sad = false		 
  453. 		else 
  454. 			panda_img:set_image("ui_rm_panda_skeleton")	 
  455. 			Panda_is_sad = true 
  456. 		end 
  457. 	 
  458. 	end	 
  459. end 
  460.  
  461.  
  462. function hud_running_man_play_time_low(event_idx, timer) 
  463.  
  464. 	local timer_grp = Vdo_base_object:new("timer_grp", 0, Genki_common_doc_handle) 
  465. 	local genki_head_grp = Vdo_base_object:new("genki_head_grp", 0, Genki_common_doc_handle) 
  466. 	local anim_h = vint_object_find("time_low_anim") 
  467. 	local timer_txt = Vdo_base_object:new("timer_txt", 0, Genki_common_doc_handle) 
  468. 	 
  469. 	if Event_is_playing == false and timer > -1 then 
  470. 		timer_txt:set_text(format_time(timer/1000, false, false)) 
  471. 		lua_play_anim(anim_h) 
  472. 		Timer_audio = audio_object_post_event("Activity", {"Activity_Type","Running_Man"}, {"Running_Man","RM_HUD_Timer"}) 
  473. 		 
  474. 		timer_grp:set_visible(true) 
  475. 		genki_head_grp:set_visible(true) 
  476. 		Event_is_playing = true 
  477. 	elseif timer > -1 then 
  478. 		timer_txt:set_text(format_time(timer/1000, false, false)) 
  479. 		if timer <= 0 then 
  480. 			if Timer_audio > 0 then 
  481. 				audio_stop(Timer_audio) 
  482. 				Timer_audio = 0 
  483. 			end 
  484. 		end 
  485. 	elseif timer == -1 then 
  486. 		timer_grp:set_visible(false) 
  487. 		genki_head_grp:set_visible(false) 
  488. 		vint_set_property(anim_h, "is_paused", true) 
  489. 		 
  490. 		if Timer_audio > 0 then 
  491. 			audio_stop(Timer_audio) 
  492. 			Timer_audio = 0 
  493. 		end 
  494. 		 
  495. 		Event_is_playing = false 
  496. 	end 
  497.  
  498. end