./msn_side_scroller.lua

  1. --Enums for events 
  2. SS_GO_ARROW 					= 1 
  3. SS_PLAYER_1_HEALTH 			= 2 
  4. SS_PLAYER_2_HEALTH 			= 3 
  5. SS_SHOW_HUD						= 4 
  6. --SS_PLAYER_1_HEALTH_GAIN 	= 4 --Handled automatically by health update 
  7. --SS_PLAYER_2_HEALTH_GAIN 	= 5 
  8. SS_INTRO_SPLASH  				= 6 
  9. SS_STAGE_COMPLETE_1 			= 7 
  10. SS_STAGE_COMPLETE_2 			= 8 
  11. SS_STAGE_COMPLETE_3 			= 9 
  12. SS_BOSS_INTRO_1 				= 10 
  13. SS_BOSS_INTRO_2				= 11 
  14. SS_COMPLETION 					= 12 
  15. SS_INTRO_SPLASH_2				= 13 
  16. SS_STAGE_START_1				= 15 
  17. SS_STAGE_START_2				= 16 
  18. SS_STAGE_START_3				= 17 
  19. SS_INTRO_SPLASH_OUT			= 18 
  20.  
  21. --Position constants for pc lives digits 
  22. local LIVES_NUM_1_X = -26 
  23. local LIVES_NUM_2_X = 0 
  24. local LIVES_NUM_Y = 0 
  25.  
  26. local Ss_event_data = { 
  27. 	[SS_GO_ARROW] = { 
  28. 		name = "go!", 
  29. 		anim_data = { 
  30. 			[1] = {  
  31. 				anim = "go_color_anim", 
  32. 				cb = "loop" 
  33. 			}, 
  34. 			[2] = {  
  35. 				--This anim uses a bounce cycle, no need for cb 
  36. 				anim = "go_fade_move_anim", 
  37. 			}, 
  38. 		}, 
  39. 		image_data = { 
  40. 			[1] = { 
  41. 				image_element = "go_arrow_img", 
  42. 				image = "ui_ss_go_arrow" 
  43. 			}, 
  44. 			[2] = { 
  45. 				image_element = "go_arrow_blend_img", 
  46. 				image = "ui_ss_go_arrow"			 
  47. 			}, 
  48. 		}, 
  49. 		grp = "go_grp" 
  50. 	}, 
  51. 	 
  52. 	[SS_SHOW_HUD] = { 
  53. 		name = "show_hud", 
  54. 		anim_data = { 
  55. 			[1] = {  
  56. 				anim = "static_anim",				 
  57. 			}, 
  58. 		}, 
  59. 		grp = "static_grp" 
  60. 	},	 
  61. 	 
  62. 	[SS_STAGE_COMPLETE_1] = { 
  63. 		name = "stage_complete_1", 
  64. 		anim_data = { 
  65. 			[1] = {  
  66. 				anim = "stage_complete_anim",		 
  67. 			} 
  68. 		}, 
  69. 		image_data = { 
  70. 			[1] = { 
  71. 				image_element = "stage_img", 
  72. 				image = "ui_ss_stage" 
  73. 			}, 
  74. 			[2] = { 
  75. 				image_element = "complete_img", 
  76. 				image = "ui_ss_complete"			 
  77. 			}, 
  78. 		}, 
  79. 		grp = "stage_complete_grp" 
  80. 	},	 
  81.  
  82. 	[SS_STAGE_COMPLETE_2] = { 
  83. 		name = "stage_complete_2", 
  84. 		anim_data = { 
  85. 			[1] = {  
  86. 				anim = "stage_complete_anim",		 
  87. 			} 
  88. 		}, 
  89. 		image_data = { 
  90. 			[1] = { 
  91. 				image_element = "stage_img", 
  92. 				image = "ui_ss_stage" 
  93. 			}, 
  94. 			[2] = { 
  95. 				image_element = "complete_img", 
  96. 				image = "ui_ss_complete"			 
  97. 			}, 
  98. 		}, 
  99. 		grp = "stage_complete_grp" 
  100. 	},	 
  101. 	 
  102. 	[SS_STAGE_COMPLETE_3] = { 
  103. 		name = "stage_complete_3", 
  104. 		anim_data = { 
  105. 			[1] = {  
  106. 				anim = "stage_complete_anim",		 
  107. 			} 
  108. 		}, 
  109. 		image_data = { 
  110. 			[1] = { 
  111. 				image_element = "stage_img", 
  112. 				image = "ui_ss_stage" 
  113. 			}, 
  114. 			[2] = { 
  115. 				image_element = "complete_img", 
  116. 				image = "ui_ss_complete"			 
  117. 			}, 
  118. 		}, 
  119. 		grp = "stage_complete_grp" 
  120. 	},		 
  121. 	[SS_BOSS_INTRO_1] = { 
  122. 		name = "boss_intro_1", 
  123. 		anim_data = { 
  124. 			[1] = {  
  125. 				anim = "boss_intro_jyn_anim",	 
  126. 				cb	= "show_static_grp", 
  127. 			} 
  128. 		}, 
  129. 		image_data = { 
  130. 			[1] = { 
  131. 				image_element = "gat_img", 
  132. 				image = "ui_ss_boss_gat", 
  133. 			}, 
  134. 			 
  135. 			[2] = { 
  136. 				image_element = "jyn_img", 
  137. 				image = "ui_ss_boss_warren", 
  138. 			},		 
  139. 			[3] = { 
  140. 				image_element = "boss_title_img", 
  141. 				image = "ui_ss_boss_title_warren", 
  142. 			},		 
  143. 		},					 
  144. 		grp = "boss_jyn_grp" 
  145. 	}, 
  146. 	[SS_BOSS_INTRO_2] = { 
  147. 		name = "boss_intro_2", 
  148. 		anim_data = { 
  149. 			[1] = {  
  150. 				anim = "boss_intro_jyn_anim",	 
  151. 				cb	= "show_static_grp", 
  152. 			} 
  153. 		}, 
  154. 		image_data = { 
  155. 			[1] = { 
  156. 				image_element = "gat_img", 
  157. 				image = "ui_ss_boss_gat", 
  158. 			}, 
  159. 			 
  160. 			[2] = { 
  161. 				image_element = "jyn_img", 
  162. 				image = "ui_ss_boss_jyn", 
  163. 			},	 
  164. 			[3] = { 
  165. 				image_element = "boss_title_img", 
  166. 				image = "ui_ss_boss_title_jyn", 
  167. 			},				 
  168. 		}, 
  169. 		grp = "boss_jyn_grp" 
  170. 	},		 
  171. 	[SS_INTRO_SPLASH] = { 
  172. 		name = "intro_splash", 
  173. 		anim_data = { 
  174. 			[1] = {  
  175. 				anim = "winners_anim", 
  176. 				cb = "load_peg_ss_intro", 
  177. 			}, 
  178. 		}, 
  179. 		image_data = { 
  180. 			[1] = { 
  181. 				image_element = "intro_img", 
  182. 				image = "ui_ss_winners_dont_use_drugs", 
  183. 			},		 
  184. 		},		 
  185. 		grp = "winners_grp" 
  186. 	},		 
  187. 	[SS_INTRO_SPLASH_2] = { 
  188. 		name = "press_start", 
  189. 		anim_data = { 
  190. 			[1] = {  
  191. 				anim = "intro_anim", 
  192. 				cb = "intro_anim_done", 
  193. 			}, 
  194. 		}, 
  195. 		image_data = { 
  196. 			[1] = { 
  197. 				image_element = "city_bg_img", 
  198. 				image = "ui_ss_intro_bg", 
  199. 			},		 
  200. 			[2] = { 
  201. 				image_element = "johnny_img", 
  202. 				image = "ui_ss_gat_intro", 
  203. 			},			 
  204. 			[3] = { 
  205. 				image_element = "logo_img", 
  206. 				image = "ui_ss_rage_logo", 
  207. 			},				 
  208. 		},		 
  209. 		grp = "intro_grp" 
  210. 	},	 
  211. 	[SS_INTRO_SPLASH_OUT] = { 
  212. 		name = "intro_splash_out", 
  213. 		anim_data = { 
  214. 			[1] = {  
  215. 				anim = "intro_fade_anim", 
  216. 			}, 
  217. 		}, 
  218. 		image_data = { 
  219. 			[1] = { 
  220. 				image_element = "city_bg_img", 
  221. 				image = "ui_ss_intro_bg", 
  222. 			},		 
  223. 			[2] = { 
  224. 				image_element = "johnny_img", 
  225. 				image = "ui_ss_gat_intro", 
  226. 			},			 
  227. 			[3] = { 
  228. 				image_element = "logo_img", 
  229. 				image = "ui_ss_rage_logo", 
  230. 			},				 
  231. 		},		 
  232. 		grp = "intro_grp" 
  233. 	},	 
  234. 	[SS_COMPLETION] = { 
  235. 		name = "completion", 
  236. 		anim_data = { 
  237. 			[1] = {  
  238. 				anim = "end_anim",	 
  239. 			} 
  240. 		}, 
  241. 		image_data = { 
  242. 			[1] = { 
  243. 				image_element = "end_gat_img", 
  244. 				image = "ui_gat_end", 
  245. 			},		 
  246. 			[2] = { 
  247. 				image_element = "end_aisha_img", 
  248. 				image = "ui_aisha_end", 
  249. 			},		 
  250. 		},		 
  251. 		grp = "end_grp" 
  252. 	},		 
  253. 	[SS_STAGE_START_1] = { 
  254. 		name = "stage_start_1", 
  255. 		anim_data = { 
  256. 			[1] = {  
  257. 				anim = "stage_complete_anim", 
  258. 				cb = "show_static_grp", 
  259. 			} 
  260. 		}, 
  261. 		image_data = { 
  262. 			[1] = { 
  263. 				image_element = "stage_img", 
  264. 				image = "ui_ss_stage" 
  265. 			}, 
  266. 			[2] = { 
  267. 				image_element = "complete_img", 
  268. 				image = "ui_ss_stage_num_1"			 
  269. 			}, 
  270. 		}, 
  271. 		grp = "stage_complete_grp" 
  272. 	},		 
  273. 	[SS_STAGE_START_2] = { 
  274. 		name = "stage_start_2", 
  275. 		anim_data = { 
  276. 			[1] = {  
  277. 				anim = "stage_complete_anim",		 
  278. 				cb = "show_static_grp", 
  279. 			} 
  280. 		}, 
  281. 		image_data = { 
  282. 			[1] = { 
  283. 				image_element = "stage_img", 
  284. 				image = "ui_ss_stage" 
  285. 			}, 
  286. 			[2] = { 
  287. 				image_element = "complete_img", 
  288. 				image = "ui_ss_stage_num_2"			 
  289. 			}, 
  290. 		}, 
  291. 		grp = "stage_complete_grp" 
  292. 	},	 
  293. 	[SS_STAGE_START_3] = { 
  294. 		name = "stage_start_3", 
  295. 		anim_data = { 
  296. 			[1] = {  
  297. 				anim = "stage_complete_anim",		 
  298. 				cb = "show_static_grp", 
  299. 			} 
  300. 		}, 
  301. 		image_data = { 
  302. 			[1] = { 
  303. 				image_element = "stage_img", 
  304. 				image = "ui_ss_stage" 
  305. 			}, 
  306. 			[2] = { 
  307. 				image_element = "complete_img", 
  308. 				image = "ui_ss_stage_num_3"			 
  309. 			}, 
  310. 		}, 
  311. 		grp = "stage_complete_grp" 
  312. 	},			 
  313. } 
  314.  
  315. 		 
  316. --Boss images 
  317. local BOSS_NONE = 0 
  318. local BOSS_WARREN_WILLIAMS = 1 
  319. local BOSS_JYN = 2 
  320. local BOSS_SUPER_JYN = 3 
  321.  
  322. local Boss_data = { 
  323. 	[BOSS_WARREN_WILLIAMS] = { 
  324. 		icon = "ui_ss_boss_icon_warren", 
  325. 		title = "ui_ss_boss_text_warren", 
  326. 	}, 
  327. 	 
  328. 	[BOSS_JYN] = { 
  329. 		icon = "ui_ss_boss_icon_jyn", 
  330. 		title = "ui_ss_boss_text_jyn", 
  331. 	}, 
  332. 	 
  333. 	[BOSS_SUPER_JYN] = { 
  334. 		icon = "ui_ss_boss_icon_jyn", 
  335. 		title = "ui_ss_boss_text_super_jyn", 
  336. 	}, 
  337. } 
  338.  
  339.  
  340. local Msn_side_scroller_doc_h = -1 
  341. local Event_listener_h = -1 
  342. local Ss_peg_is_loaded = false 
  343. local Ss_intro_peg_is_loaded = false 
  344. local Ss_winners_peg_is_loaded = false 
  345. local Input_tracker = -1 
  346. local Mouse_input_tracker = -1 
  347. local P1_score = 0 
  348. local P2_score = 0 
  349. local P1_health = 0 
  350. local P2_health = 0 
  351. local Player_lives = 0 
  352. local Boss_health = 0 
  353. local Boss_id = 0 
  354. local Ss_loaded_from_checkpoint = false 
  355. local Ss_intro_anim_is_done = false 
  356. local Ss_press_start_called = false 
  357. local Ss_thread_peg_load_h = 0 
  358. local Ss_thread_sim_stop_event_h = 0 
  359. local Ss_thread_test_lives_h = 0 
  360. local Combo_counter = 0 
  361.  
  362.  
  363. function msn_side_scroller_init() 
  364. 	Msn_side_scroller_doc_h = vint_document_find("msn_side_scroller") 
  365. 	 
  366. 	-- JAM 5/16/13 :  Removing press start because of co-op, localization, PC, etc. - it was a cool feature :( 
  367. 	--[[Input_tracker = Vdo_input_tracker:new() 
  368. 	Input_tracker:add_input("all_unassigned", "msn_side_scroller_press_start", 50) 
  369. 	Input_tracker:add_input("pause", "msn_side_scroller_press_start", 50) 
  370. 	Input_tracker:add_input("select", "msn_side_scroller_press_start", 50) 
  371. 	 
  372. 	-- PC inputs 
  373. 	if game_get_platform() == "PC" then 
  374. 		 
  375. 		-- Use full screen bg image as target handle 
  376. 		local city_bg_img_h = vint_object_find("city_bg_img", 0, Msn_side_scroller_doc_h) 
  377. 		 
  378. 		Mouse_input_tracker = Vdo_input_tracker:new()				 
  379. 		Mouse_input_tracker:add_mouse_input("mouse_click", "msn_side_scroller_mouse_click", 0, city_bg_img_h) 
  380. 	end 
  381. 	 
  382. 	msn_side_scroller_controls_lock()	 
  383. 	]] 
  384. 	 
  385. 	--Hide screen until peg is loaded 
  386. 	local screen_grp_h = vint_object_find("screen_grp", 0, Msn_side_scroller_doc_h) 
  387. 	vint_set_property(screen_grp_h, "alpha", 0) 
  388. 	 
  389. 	--Hide all grps 
  390. 	--Loop through event data and hide all grps	 
  391. 	for idx, grp in pairs( Ss_event_data ) do 
  392. 		if grp ~= nil then 
  393. 			local grp_h = vint_object_find(Ss_event_data[idx].grp, 0, Msn_side_scroller_doc_h) 
  394. 			vint_set_property(grp_h, "visible", false) 
  395. 		end 
  396. 	end 
  397. 	 
  398. 	--Hide individual grps 
  399. 	local combo_grp_h = vint_object_find("combo_grp", 0, Msn_side_scroller_doc_h) 
  400. 	vint_set_property(combo_grp_h, "alpha", 0) 
  401. 	 
  402. 	local boss_health_grp_h = vint_object_find("boss_health_grp", 0, Msn_side_scroller_doc_h)	 
  403. 	vint_set_property(boss_health_grp_h, "alpha", 0)	 
  404. 	 
  405. 	local lives_grp_h = vint_object_find("lives_grp", 0, Msn_side_scroller_doc_h)	 
  406. 	vint_set_property(lives_grp_h, "visible", false) 
  407. 	 
  408. 	local multi_img_h = vint_object_find("multi_img", 0, Msn_side_scroller_doc_h)	 
  409. 	vint_set_property(multi_img_h, "visible", false) 
  410. 	 
  411. 	local p2_grp_h = vint_object_find("p2_grp", 0, Msn_side_scroller_doc_h) 
  412. 	vint_set_property(p2_grp_h, "visible", false) 
  413. 	 
  414. 	--Localize end text 
  415. 	local end_txt_1_h = vint_object_find("end_txt_1", 0, Msn_side_scroller_doc_h) 
  416. 	local end_txt_2_h = vint_object_find("end_txt_2", 0, Msn_side_scroller_doc_h) 
  417. 	local end_txt_3_h = vint_object_find("end_txt_3", 0, Msn_side_scroller_doc_h) 
  418. 	 
  419. 	vint_set_property(end_txt_1_h, "text_tag", "M15_ENDING_LINE_01") 
  420. 	vint_set_property(end_txt_2_h, "text_tag", "M15_ENDING_LINE_02") 
  421. 	vint_set_property(end_txt_3_h, "text_tag", "M15_ENDING_LINE_03") 
  422. 	 
  423. 	--Set end event to advance the press start screen automatically after ~8 secs 
  424. 	local press_start_anim_h = vint_set_property(Ss_event_data[SS_INTRO_SPLASH_2].anim_data[1].anim, 0, Msn_side_scroller_doc_h) 
  425. 	local press_start_done_twn_h = vint_object_find("press_start_done_twn", press_start_anim_h) 
  426. 	vint_set_property(press_start_done_twn_h, "end_event", "msn_side_scroller_press_start") 
  427. 	 
  428. 	vint_dataitem_add_subscription( "msn_side_scroll", "update", "msn_side_scroller_data_update" ) 
  429. 	Event_listener_h = vint_scriptevent_listen( "msn_side_scroll", "msn_side_scroller_event" ) 
  430. 	 
  431. 	--Set score at 0 to hide all number graphics initially 
  432. 	msn_side_scroller_score_update(0, 0) 
  433. end 
  434.  
  435. function msn_side_scroller_unload() 
  436. 	game_peg_list_unload_wait( { "ui_bms_ss", "ui_bms_ss_intro", "ui_ss_intro_bg", "ui_ss_winners_dont_use_drugs" } ) 
  437. end 
  438.  
  439. function msn_side_scroller_cleanup() 
  440. 	 
  441. 		 
  442. 	pause_map_restore() 
  443. 	 
  444. 	vint_scriptevent_stop_listening( Event_listener_h ) 
  445. 	 
  446. 	thread_kill(Ss_thread_peg_load_h) 
  447. 	thread_kill(Ss_thread_sim_stop_event_h) 
  448. 	thread_kill(Ss_thread_test_lives_h) 
  449. 	Ss_thread_peg_load_h = 0 
  450. 	Ss_thread_sim_stop_event_h = 0	 
  451. 	Ss_thread_test_lives_h = 0 
  452. end 
  453.  
  454.  
  455. function msn_side_scroller_intro_load() 
  456. 	Ss_thread_peg_load_h = thread_new("msn_side_scroller_load_peg_delay_intro") 
  457. 	 
  458. 	--msn_side_scroller_controls_unlock() 
  459. end 
  460.  
  461.  
  462. function msn_side_scroller_hud_load() 
  463. 	Ss_loaded_from_checkpoint = true 
  464. 	Ss_thread_peg_load_h = thread_new("msn_side_scroller_load_peg_delay_hud") 
  465. end 
  466.  
  467.  
  468. ------------------------------------------------------------------------------- 
  469. -- Function msn_side_scroller_load_peg_delay_intro() 
  470. -- 
  471. -- Dump pause map and loads intro peg a.k.a "Winners Don't Use Drugs" peg 
  472. -- 
  473. ------------------------------------------------------------------------------- 
  474. function msn_side_scroller_load_peg_delay_intro() 
  475. 	pause_map_dump(true) 
  476. 		 
  477. 	--msn_side_scroller_load_peg_ss()	 
  478. 	msn_side_scroller_load_peg_winners() 
  479. end 
  480.  
  481.  
  482. ------------------------------------------------------------------------------- 
  483. -- Function msn_side_scroller_load_peg_delay_hud() 
  484. -- 
  485. -- Dump pause map and loads intro hud peg ui_bms_ss 
  486. -- 
  487. ------------------------------------------------------------------------------- 
  488. function msn_side_scroller_load_peg_delay_hud() 
  489. 	pause_map_dump(true) 
  490. 		 
  491. 	--msn_side_scroller_load_peg_ss()	 
  492. 	msn_side_scroller_load_peg_ss() 
  493. end 
  494.  
  495.  
  496. ------------------------------------------------------------------------------- 
  497. -- Function msn_side_scroller_load_peg_winners() 
  498. -- 
  499. -- Loads intro peg a.k.a "Winners Don't Use Drugs" peg 
  500. -- 
  501. ------------------------------------------------------------------------------- 
  502. function msn_side_scroller_load_peg_winners() 
  503. 	game_peg_load_with_cb("msn_side_scroller_complete_load", 1, "ui_ss_winners_dont_use_drugs")	 
  504. end 
  505.  
  506.  
  507. ------------------------------------------------------------------------------- 
  508. -- Function msn_side_scroller_load_peg_ss() 
  509. -- 
  510. -- Unloads intro peg and loads the sheet for the sidescroller 
  511. -- 
  512. ------------------------------------------------------------------------------- 
  513. function msn_side_scroller_load_peg_ss() 
  514. 	 
  515. 	-- Unload intro peg if loaded 
  516. 	if Ss_intro_peg_is_loaded then 
  517. 		game_peg_unload_wait("ui_bms_ss_intro") 
  518. 		game_peg_unload_wait("ui_ss_intro_bg") 
  519. 		Ss_intro_peg_is_loaded = false 
  520. 	end 
  521. 	 
  522. 	-- Unload winners peg if it's loaded 
  523. 	if Ss_winners_peg_is_loaded then 
  524. 		game_peg_unload_wait("ui_ss_winners_dont_use_drugs") 
  525. 		Ss_winners_peg_is_loaded = false 
  526. 	end 
  527. 	 
  528. 	-- Load ui_bms_ss used for the side scroller HUD 
  529. 	game_peg_load_with_cb("msn_side_scroller_peg_complete_load_ss", 1, "ui_bms_ss") 
  530. end 
  531.  
  532.  
  533. ------------------------------------------------------------------------------- 
  534. -- Function msn_side_scroller_load_peg_ss_intro() 
  535. -- 
  536. -- Unloads winners peg and loads intro pegs 
  537. -- 
  538. ------------------------------------------------------------------------------- 
  539. function msn_side_scroller_load_peg_ss_intro() 
  540. 	game_peg_unload_wait("ui_ss_winners_dont_use_drugs") 
  541. 	Ss_winners_peg_is_loaded = false 
  542.  
  543. 	--Wait for intro peg to unload, then load ui_bms_ss 
  544. 	game_peg_load_with_cb("msn_side_scroller_peg_complete_load_ss_intro", 2, "ui_bms_ss_intro", "ui_ss_intro_bg")	 
  545. end 
  546.  
  547.  
  548. ------------------------------------------------------------------------------- 
  549. -- Function msn_side_scroller_peg_complete_load_ss() 
  550. -- 
  551. -- Sets flag that side scroller peg is loaded 
  552. -- 
  553. ------------------------------------------------------------------------------- 
  554. function msn_side_scroller_peg_complete_load_ss() 
  555. 	Ss_peg_is_loaded = true 
  556. 	 
  557. 	--Peg is loaded, show screen 
  558. 	local screen_grp_h = vint_object_find("screen_grp", 0, Msn_side_scroller_doc_h) 
  559. 	vint_set_property(screen_grp_h, "alpha", 1)	 
  560. end 
  561.  
  562.  
  563. ------------------------------------------------------------------------------- 
  564. -- Function msn_side_scroller_peg_complete_load_ss_intro() 
  565. -- 
  566. -- Kicks off intro screen anim 
  567. -- 
  568. ------------------------------------------------------------------------------- 
  569. function msn_side_scroller_peg_complete_load_ss_intro() 
  570. 	Ss_intro_peg_is_loaded = true 
  571. 	msn_side_scroller_update(SS_INTRO_SPLASH_2, true) 
  572. end 
  573.  
  574.  
  575. function test_side_scroller_stop_event() 
  576. 	delay(5) 
  577. 	msn_side_scroller_update(SS_GO_ARROW) 
  578. end 
  579.  
  580.  
  581. function test_lives() 
  582. 	--msn_side_scroller_update(SS_BOSS_INTRO_1) 
  583. 	--for i = 0, 100 do 
  584. 	--	delay(.05) 
  585. 	--	msn_side_scroller_health_update(0 + i/100, 0 + i/100, 0.2, i) 
  586. 	--end 
  587. 	 
  588. 	--[[for i=100, 0, -1 do 
  589. 		delay(.05) 
  590. 		debug_print("vint","Msn_side_scroller :::::::::::::: lives::::::::::: "..var_to_string(i).."\n\n") 
  591. 		msn_side_scroller_health_update(0.5, 0.5, 0.2, i) 
  592. 	end]]-- 
  593. end 
  594.  
  595.  
  596. function msn_side_scroller_complete_load() 
  597.  
  598. 	Ss_winners_peg_is_loaded = true 
  599.  
  600. 	--Peg is loaded, show screen 
  601. 	local screen_grp_h = vint_object_find("screen_grp", 0, Msn_side_scroller_doc_h) 
  602. 	vint_set_property(screen_grp_h, "alpha", 1) 
  603. 	 
  604. 	--For test only 
  605. 	--msn_side_scroller_update(SS_COMPLETION, true) 
  606. 	--msn_side_scroller_health_update(0.5,0.5,0.5,0) 
  607. 	--msn_side_scroller_health_update(0.5, 0.5, 0.3, 9) 
  608. end 
  609.  
  610.  
  611. function msn_side_scroller_data_update( di_h ) 
  612. 	local p1_health, p2_health, player_lives, boss_health, boss_id, p1_score, p2_score, combo = vint_dataitem_get(di_h) 
  613. 	 
  614. 	--If nothing changed return 
  615. 	if p1_health == nil or p2_health == nil or player_lives == nil or boss_health == nil or boss_id == nil or p1_score == nil or p2_score == nil or combo == nil then 
  616. 		return 
  617. 	end 
  618.  
  619. 	if boss_id ~= Boss_id then 
  620. 		Boss_id = boss_id 
  621. 	end 
  622. 	 
  623. 	--If score changed update the score 
  624. 	if p1_score ~= P1_score or p2_score ~= P2_score then 
  625. 		msn_side_scroller_score_update(p1_score, p2_score) 
  626. 	end 
  627.  
  628. 	--Update combo 
  629. 	if combo ~= 0 then 
  630. 		msn_side_scroller_combo_update(combo) 
  631. 	end 
  632. 	 
  633. 	--Update health and lives 
  634. 	if p1_health ~= P1_health or p2_health ~= P2_health or player_lives ~= Player_lives or Boss_health ~= boss_health then 
  635. 		msn_side_scroller_health_update(p1_health, p2_health, boss_health, player_lives) 
  636. 	end 
  637. end 
  638.  
  639.  
  640. --Listener for events from code 
  641. function msn_side_scroller_event( event_name, param ) 
  642. 	local event = nil 
  643. 	 
  644. 	if event_name == "intro_load" then 
  645. 		msn_side_scroller_intro_load() 
  646. 	end 
  647. 	 
  648. 	if event_name == "checkpoint_restart" then 
  649. 		msn_side_scroller_hud_load() 
  650. 	end	 
  651. 	 
  652. 	for k, i in pairs( Ss_event_data ) do 
  653. 		if i.name == event_name then 
  654. 			event = k 
  655. 			break 
  656. 		end 
  657. 	end	 
  658. 	 
  659. 	if event == nil then 
  660. 		return 
  661. 	end 
  662. 	 
  663. 	msn_side_scroller_update( event, param ) 
  664. end 
  665.  
  666.  
  667. ------------------------------------------------------------------------------- 
  668. -- Function msn_side_scroller_update() 
  669. -- 
  670. -- Plays or stops all events for the sidescroller mission 
  671. -- 
  672. -- @param event			-- event to play or stop 
  673. -- @param play_event		-- play or stop the event 
  674. -- 
  675. ------------------------------------------------------------------------------- 
  676. function msn_side_scroller_update(event, play_event) 
  677.  
  678. 	-- If we're trying to show the hud and the peg isn't loaded, then load it 
  679. 	if (event == SS_SHOW_HUD or event == SS_STAGE_START_1) and Ss_peg_is_loaded == false then 
  680. 		msn_side_scroller_load_peg_ss() 
  681. 		--msn_side_scroller_controls_unlock() 
  682. 	end 
  683.  
  684. 	local curr_event = Ss_event_data[event] 
  685. 	 
  686. 	--Show group and set images 
  687. 	local grp_h = vint_object_find(curr_event.grp, 0, Msn_side_scroller_doc_h) 
  688. 	 
  689. 	if play_event ~= nil then		 
  690. 		vint_set_property(grp_h, "visible", play_event) 
  691. 	end 
  692. 	 
  693. 	--Loop through all images and set them now that the peg is loaded 
  694. 	if curr_event.image_data ~= nil then 
  695. 		for i = 1, #curr_event.image_data do 
  696. 			local curr_image_data = curr_event.image_data[i] 
  697. 			local image_h = vint_object_find(curr_image_data.image_element, grp_h, Msn_side_scroller_doc_h) 
  698. 			vint_set_property(image_h, "image", curr_image_data.image) 
  699. 		end	 
  700. 	end 
  701. 	 
  702. 	--Loop through all anims and play them 
  703. 	for i = 1, #curr_event.anim_data do 
  704. 		local curr_anim_data = curr_event.anim_data[i] 
  705. 		local anim_h = vint_object_find(curr_anim_data.anim, 0, Msn_side_scroller_doc_h) 
  706. 		local end_event_twn_h = vint_object_find("end_event_twn", anim_h) 
  707. 				 
  708. 		--Handle callbacks or play only once 
  709. 		if curr_anim_data.cb == "loop" then 
  710. 			--Loop anim 
  711. 			vint_set_property(end_event_twn_h, "end_event", "msn_side_scroller_loop_anim_cb") 
  712. 		elseif curr_anim_data.cb  ~= nil then 
  713. 			--Go to a specific callback				 
  714. 			vint_set_property(end_event_twn_h, "end_event", "msn_side_scroller_"..curr_anim_data.cb) 
  715. 		else 
  716. 			vint_set_property(end_event_twn_h, "end_event", nil) 
  717. 		end 
  718. 		 
  719. 		vint_apply_start_values(anim_h) 
  720. 		 
  721. 		--Start/Stop event anim 
  722. 		if play_event == false then 
  723. 			vint_set_property(anim_h, "is_paused", true) 
  724. 			 
  725. 			--Return after we stop the last anim 
  726. 			if i == #curr_event.anim_data then 
  727. 				return 
  728. 			end			 
  729. 		else 
  730. 			lua_play_anim(anim_h, 0, Msn_side_scroller_doc_h) 
  731. 		end 
  732. 	end		 
  733. 	 
  734. 	--Special cases------------------------------------------------------- 
  735. 	--For stage complete hide all other grps 
  736. 	--Turn back on when animation is finished 
  737. 	if event ~= SS_PLAYER_1_HEALTH and event ~= SS_PLAYER_2_HEALTH and event ~= SS_GO_ARROW and event ~= SS_SHOW_HUD then 
  738. 		local static_grp_h = vint_object_find("static_grp", 0, Msn_side_scroller_doc_h) 
  739. 		vint_set_property(static_grp_h, "visible", false) 
  740. 	end 
  741. end 
  742.  
  743.  
  744. ------------------------------------------------------------------------------- 
  745. -- Looping callback 
  746. -- 
  747. function msn_side_scroller_loop_anim_cb(tween_handle) 
  748. 	local animation = vint_object_parent(tween_handle) 
  749. 	lua_play_anim(animation, 0, Msn_side_scroller_doc_h) 
  750. end 
  751.  
  752.  
  753. ------------------------------------------------------------------------------- 
  754. -- Show hud callback 
  755. -- 
  756. function msn_side_scroller_show_static_grp() 
  757. 	local static_grp_h = vint_object_find("static_grp", 0, Msn_side_scroller_doc_h) 
  758. 	vint_set_property(static_grp_h, "visible", true) 
  759. end 
  760.  
  761.  
  762.  
  763.  
  764. function msn_side_scroller_health_update(p1_health, p2_health, boss_health, lives) 
  765. 	 
  766. 	--Did we gain health?  If so, play health up animation 
  767. 	local p1_meter_fill_grp_h = vint_object_find("p1_meter_fill_grp", 0, Msn_side_scroller_doc_h) 
  768. 	local p2_meter_fill_grp_h = vint_object_find("p2_meter_fill_grp", 0, Msn_side_scroller_doc_h) 
  769. 	local p1_meter_fill_up_h = vint_object_find("p1_health_meter_up_img", p1_meter_fill_grp_h, Msn_side_scroller_doc_h) 
  770. 	local p2_meter_fill_up_h = vint_object_find("p2_health_meter_up_img", p2_meter_fill_grp_h, Msn_side_scroller_doc_h) 
  771. 	 
  772. 	vint_set_property(p1_meter_fill_up_h, "alpha", 0) 
  773. 	vint_set_property(p2_meter_fill_up_h, "alpha", 0) 
  774. 	 
  775. 	if p1_health > P1_health then 
  776. 		local p1_health_up_anim_h = vint_object_find("p1_health_up_anim") 
  777. 		lua_play_anim(p1_health_up_anim_h, 0)		 
  778. 	end 
  779. 	 
  780. 	if p2_health > P2_health then 
  781. 		local p2_health_up_anim_h = vint_object_find("p2_health_up_anim") 
  782. 		lua_play_anim(p2_health_up_anim_h, 0)				 
  783. 	end 
  784. 	 
  785. 	--Save states 
  786. 	P1_health = p1_health 
  787. 	Boss_health = boss_health 
  788. 	Player_lives = lives 
  789. 	 
  790. 	debug_print( "vint", "msn_side_scroller_health_update()\n" ) 
  791. 	 
  792. 	--Set p1's health 
  793. 	local meter_mask_h = vint_object_find("health_meter_mask_img", p1_meter_fill_grp_h, Msn_side_scroller_doc_h) 
  794. 	 
  795. 	local METER_FULL_PCT = 325 
  796. 	local meter_mask_x, meter_mask_y = vint_get_property(meter_mask_h, "anchor") 
  797. 	local new_x = METER_FULL_PCT * p1_health 
  798. 	 
  799. 	vint_set_property(meter_mask_h, "anchor", new_x, meter_mask_y) 
  800. 	 
  801. 	--Set p2's health 
  802. 	if p2_health ~= -1 and p2_health ~= nil then 
  803. 		local p2_grp_h = vint_object_find("p2_grp", 0, Msn_side_scroller_doc_h) 
  804. 		vint_set_property(p2_grp_h, "visible", true) 
  805. 				 
  806. 		local meter_mask_h = vint_object_find("health_meter_mask_img", p2_meter_fill_grp_h, Msn_side_scroller_doc_h) 
  807. 		 
  808. 		local METER_FULL_PCT = 325 
  809. 		local meter_mask_x, meter_mask_y = vint_get_property(meter_mask_h, "anchor") 
  810. 		local new_x = METER_FULL_PCT * p2_health 
  811. 		 
  812. 		vint_set_property(meter_mask_h, "anchor", new_x, meter_mask_y)	 
  813. 	end 
  814. 	 
  815. 	--Set boss health	 
  816. 	if boss_health ~= -1 then 
  817. 		local boss_health_grp_h = vint_object_find("boss_health_grp", 0, Msn_side_scroller_doc_h)		 
  818. 		local boss_meter_mask_h = vint_object_find("boss_meter_mask_img", 0, Msn_side_scroller_doc_h) 
  819. 		 
  820. 		local boss_meter_mask_x, boss_meter_mask_y = vint_get_property(boss_meter_mask_h, "anchor") 
  821. 		new_x = METER_FULL_PCT * boss_health 
  822. 		 
  823. 		vint_set_property(boss_meter_mask_h, "anchor", new_x, boss_meter_mask_y)			 
  824. 		vint_set_property(boss_health_grp_h, "alpha", 1)	 
  825. 	else 
  826. 		local boss_health_grp_h = vint_object_find("boss_health_grp", 0, Msn_side_scroller_doc_h)		 
  827. 		vint_set_property(boss_health_grp_h, "alpha", 0) 
  828. 	end 
  829. 	 
  830. 	--Set boss icon and name 
  831. 	local boss_icon_img_h = vint_object_find("boss_icon_img", 0, Msn_side_scroller_doc_h) 
  832. 	local boss_txt_img_h = vint_object_find("boss_txt_img", 0, Msn_side_scroller_doc_h) 
  833. 	 
  834. 	if Boss_id ~= 0 then 
  835. 		vint_set_property(boss_icon_img_h, "image", Boss_data[Boss_id].icon) 
  836. 		vint_set_property(boss_txt_img_h, "image", Boss_data[Boss_id].title) 
  837. 		 
  838. 		vint_set_property(boss_icon_img_h, "visible", true) 
  839. 		vint_set_property(boss_txt_img_h, "visible", true) 
  840. 	else 
  841. 		vint_set_property(boss_icon_img_h, "visible", false) 
  842. 		vint_set_property(boss_txt_img_h, "visible", false) 
  843. 	end 
  844. 	 
  845. 	--Set player's lives	 
  846. 	--lives are shared by both players in co-op 
  847. 	local lives_grp_h = vint_object_find("lives_grp", 0, Msn_side_scroller_doc_h)	 
  848. 	vint_set_property(lives_grp_h, "visible", true) 
  849. 	 
  850. 	local multi_img_h = vint_object_find("multi_img", 0, Msn_side_scroller_doc_h)	 
  851. 	vint_set_property(multi_img_h, "visible", true) 
  852. 	 
  853. 	if lives < 0 or lives == nil then 
  854. 		--Hide the lives because there aren't any 
  855. 		vint_set_property(lives_grp_h, "visible", false) 
  856. 		vint_set_property(multi_img_h, "visible", false)			 
  857. 	elseif lives >= 0 and lives < 10 then 
  858. 		--Position the digits for 1 digit 
  859. 		vint_set_property(lives_grp_h, "anchor", LIVES_NUM_1_X, LIVES_NUM_Y) 
  860. 	 
  861. 		msn_side_scroller_set_number(lives, "lives")		 
  862. 	elseif lives >= 10 and lives < 100 then 
  863. 		--Shift the digits over by 1 to make room for 2 digits 
  864. 		vint_set_property(lives_grp_h, "anchor", LIVES_NUM_2_X, LIVES_NUM_Y) 
  865. 		 
  866. 		msn_side_scroller_set_number(lives, "lives")	 
  867. 	elseif lives >= 100 then 
  868. 		--Player should never have more than 99 lives 
  869. 		--If they do cap it at 99 
  870. 		vint_set_property(lives_grp_h, "anchor", LIVES_NUM_2_X, LIVES_NUM_Y) 
  871. 		 
  872. 		msn_side_scroller_set_number(99, "lives")			 
  873. 	end 
  874. end 
  875.  
  876.  
  877. function msn_side_scroller_score_update(p1_new_score, p2_new_score) 
  878. 	--Update the score 
  879. 	P1_score = p1_new_score 
  880. 	msn_side_scroller_set_number(P1_score, "p1_score") 
  881. 	 
  882. 	if p2_new_score ~= nil and p2_new_score ~= -1 then 
  883. 		P2_score = p2_new_score 
  884. 		msn_side_scroller_set_number(P2_score, "p2_score") 
  885. 	end 
  886. end 
  887.  
  888.  
  889. function msn_side_scroller_combo_update(combo) 
  890. 	--Update combo txt 
  891. 	msn_side_scroller_set_number(combo, "combo") 
  892. 	 
  893. 	--Only play if the player gets a combo of 3 or more 
  894. 	if combo > 2 then 
  895. 		local combo_anim_h = vint_object_find("combo_anim", 0, Msn_side_scroller_doc_h)	 
  896. 		local combo_end_event_twn_h = vint_object_find("end_event_twn", combo_anim_h) 
  897. 	 
  898. 		vint_set_property(combo_end_event_twn_h, "end_event", "msn_side_scroller_combo_reset") 
  899. 	 
  900. 		lua_play_anim(combo_anim_h, 0)	 
  901. 	end 
  902. end 
  903.  
  904.  
  905. function msn_side_scroller_combo_reset() 
  906. 	--Update Score 
  907. 	--msn_side_scroller_score_update(Combo_counter) 
  908. 	 
  909. 	--Reset combo 
  910. 	Combo_counter = 0 
  911. end 
  912.  
  913.  
  914. ---------------------------------------------------------------------------------------------------- 
  915. -- Function: msn_side_scroller_set_number 
  916. -- 
  917. -- Description: Divide a number into separate digits so we can invdividually set images to a custom  
  918. -- pixel number font 
  919. -- 
  920. -- Params: 
  921. -- num		--The number to separate 
  922. -- grp		--Score or combo grp 
  923. ---------------------------------------------------------------------------------------------------- 
  924. function msn_side_scroller_set_number(num, grp) 
  925. 	local nums = {} 
  926.  
  927. 	--Reusing this function for combo and score. Make sure a parent grp is present to determine 
  928. 	--which numbers to set. 
  929. 	local parent_grp_h 
  930. 	local max_digits 
  931. 	local max_score 
  932. 	 
  933. 	if grp == "p1_score" then 
  934. 		parent_grp_h = vint_object_find("p1_score_grp", 0, Msn_side_scroller_doc_h) 
  935. 		max_digits = 6 
  936. 		max_score = 999999 
  937. 	elseif grp == "p2_score" then 
  938. 		parent_grp_h = vint_object_find("p2_score_grp", 0, Msn_side_scroller_doc_h) 
  939. 		max_digits = 6 
  940. 		max_score = 999999 
  941. 	elseif grp == "combo" then 
  942. 		parent_grp_h = vint_object_find("combo_grp", 0, Msn_side_scroller_doc_h) 
  943. 		max_digits = 6 
  944. 		max_score = 999999 
  945. 	elseif grp == "lives" then 
  946. 		parent_grp_h = vint_object_find("lives_grp", 0, Msn_side_scroller_doc_h)	 
  947. 		max_digits = 2 
  948. 		max_score = 99 
  949. 	end 
  950. 	 
  951. 	for i=1, max_digits do 
  952. 		nums[i] = vint_object_find("num_img_"..i, parent_grp_h, Msn_side_scroller_doc_h) 
  953. 		vint_set_property(nums[i], "visible", false) 
  954. 	end		 
  955. 	 
  956. 	local num_temp = num 
  957. 	 
  958. 	if num_temp > max_score then 
  959. 		num_temp = max_score 
  960. 	end 
  961. 	 
  962. 	--Handle negative numbers 
  963. 	if num_temp < 0 then 
  964. 		return 
  965. 	end 
  966. 	 
  967. 	--Handle 0 
  968. 	if num_temp == 0 and ( grp == "p1_score" or grp == "p2_score" or grp == "lives" ) then 
  969. 		vint_set_property(nums[max_digits], "image", "ui_ss_num_"..num_temp)		 
  970. 		vint_set_property(nums[max_digits], "visible", true) 
  971. 	end 
  972. 	 
  973. 	--Handle everything else 
  974. 	for n = 1, max_digits do 
  975. 	  if num_temp == 0 then 
  976. 		 break		  
  977. 	  else 
  978. 		 local d = num_temp - ( floor( num_temp / 10 ) * 10 ) 
  979. 		  
  980. 		 -- set the bmp for digit n to be number d 
  981. 		 vint_set_property(nums[(max_digits + 1) -n], "image", "ui_ss_num_"..d)		 
  982. 		 vint_set_property(nums[(max_digits + 1)-n], "visible", true) 
  983. 	  end 
  984. 	   
  985. 	  num_temp = floor( num_temp / 10 ) 
  986. 	end		 
  987. end 
  988.  
  989.  
  990. function msn_side_scroller_nav_a(event) 
  991. 	--For test only 
  992. 	Combo_counter = Combo_counter + 1 
  993. 	msn_side_scroller_combo_update(Combo_counter)	 
  994. end 
  995.  
  996.  
  997. function msn_side_scroller_intro_anim_done() 
  998. 	Ss_intro_anim_is_done = true		 
  999. end 
  1000.  
  1001.  
  1002. ------------------------------------------------------------------------------- 
  1003. -- Fades out the press start screen.  Gives controls back to game. 
  1004. -- 
  1005. function msn_side_scroller_press_start() 
  1006. 	if Ss_intro_anim_is_done and Ss_press_start_called == false then 
  1007. 		msn_side_scroller_update(SS_INTRO_SPLASH_OUT, true) 
  1008. 		 
  1009. 		--Input_tracker:remove_all() 
  1010. 		 
  1011. 		--if game_get_platform() == "PC" then  
  1012. 		--	Mouse_input_tracker:remove_all() 
  1013. 		--end 
  1014. 		 
  1015. 		--msn_side_scroller_controls_lock()	 
  1016. 		 
  1017. 		Ss_press_start_called = true 
  1018. 		 
  1019. 		--script event post here 
  1020. 		vint_scriptevent_post("intro_complete")		 
  1021. 	end 
  1022. end 
  1023.  
  1024.  
  1025. function msn_side_scroller_controls_lock() 
  1026. 	--[[Input_tracker:subscribe(false) 
  1027. 	 
  1028. 	if game_get_platform() == "PC" then 
  1029. 		Mouse_input_tracker:subscribe(false) 
  1030. 	end]] 
  1031. end 
  1032.  
  1033.  
  1034. function msn_side_scroller_controls_unlock() 
  1035. 	--[[Input_tracker:subscribe(true) 
  1036. 	 
  1037. 	if game_get_platform() == "PC" then 
  1038. 		Mouse_input_tracker:subscribe(true) 
  1039. 	end]] 
  1040. end 
  1041.  
  1042.  
  1043. function msn_side_scroller_mouse_click(event, target_handle) 
  1044.  
  1045. 	--[[-- Use full screen bg image as target handle 
  1046. 	local city_bg_img_h = vint_object_find("city_bg_img", 0, Msn_side_scroller_doc_h) 
  1047.  
  1048. 	if target_handle == city_bg_img_h then 
  1049. 		msn_side_scroller_press_start() 
  1050. 	end]] 
  1051. end 
  1052.