collision_routines.s 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. block_activation_table
  2. dc.l Null_Routine
  3. dc.l Player_On_Bridge ;these used to be something
  4. dc.l Null_Routine
  5. dc.l Null_Routine
  6. dc.l Null_Routine
  7. dc.l Player_Stepped_On_Switch
  8. dc.l Player_Activates_Event
  9. dc.l Player_Activates_Door
  10. dc.l Player_Activates_Door2 ;second block of door
  11. dc.l Player_Activates_Big_Door
  12. dc.l Drop_Big_Key
  13. ***********************************************
  14. ********* PLAYER ON BRIDGE *********
  15. ***********************************************
  16. Player_On_Bridge
  17. tst.b man_direction
  18. beq.s player_not_moving_on_bridge
  19. cmp.w #1,man_frame_count
  20. bne.s player_not_moving_on_bridge
  21. tst.w player_current_frame
  22. beq.s make_wood_noise
  23. cmp.w #3,player_current_frame
  24. beq.s make_wood_noise2
  25. player_not_moving_on_bridge
  26. rts
  27. make_wood_noise
  28. move.w #Sound_Wood,sound_chan4
  29. rts
  30. make_wood_noise2
  31. move.w #Sound_Wood2,sound_chan4
  32. rts
  33. ***********************************************
  34. ********* PLAYER ACTIVATES DOOR2 *********
  35. ***********************************************
  36. Player_Activates_Door2
  37. sub.w #16,d6 ;nice dodgy code - i.e slip into next routine
  38. subq.l #2,a0
  39. ***********************************************
  40. ********* PLAYER ACTIVATES DOOR *********
  41. ***********************************************
  42. Player_Activates_Door
  43. tst Number_Of_Keys
  44. bne.s use_key
  45. rts
  46. use_key
  47. subq.w #1,Number_Of_Keys
  48. clr.l (a0) ;clear those blocks/stop multiple blocks added
  49. move.l #Use_Key_On_Door,a5
  50. lsr #4,d6 ;get block x,y
  51. move.w d6,2(a5)
  52. lsr #4,d7
  53. move.w d7,4(a5)
  54. subq.w #1,d7
  55. move.w d6,16(a5)
  56. move.w d7,18(a5)
  57. subq.w #1,d7
  58. move.w d6,30(a5)
  59. move.w d7,32(a5)
  60. move.l switch_list_pointer,a1
  61. move.l a5,(a1)+
  62. move.l #$ffffffff,(a1)
  63. move.l a1,switch_list_pointer
  64. move.w Number_of_Keys,d7
  65. bsr Remove_Key_Char
  66. rts
  67. ***********************************************
  68. ********* PLAYER ACTIVATES BIG DOOR *********
  69. ***********************************************
  70. Player_Activates_Big_Door
  71. tst end_of_level_key
  72. bne.s use_eol_key
  73. rts
  74. use_eol_key
  75. clr.w end_of_level_key
  76. *Find out which block was activated
  77. move.w (a0),d0
  78. sub.w #285,d0
  79. lsl #4,d0 ;find block
  80. sub.w d0,d6
  81. clr.l (a0) ;clear those blocks/stop multiple blocks added
  82. sub.w #16,d6
  83. move.l #Blow_Up_Big_Door,a5
  84. lsr #4,d6 ;get block x,y
  85. move.w d6,2(a5)
  86. lsr #4,d7
  87. move.w d7,4(a5)
  88. subq.w #1,d7
  89. move.w d6,20(a5)
  90. move.w d7,22(a5)
  91. subq.w #1,d7
  92. move.w d6,38(a5)
  93. move.w d7,40(a5)
  94. subq.w #1,d7
  95. move.w d6,56(a5)
  96. move.w d7,58(a5)
  97. move.l switch_list_pointer,a1
  98. move.l a5,(a1)+
  99. move.l #$ffffffff,(a1)
  100. move.l a1,switch_list_pointer
  101. rts
  102. ***********************************************
  103. ********* REMOVE SWITCH *********
  104. ***********************************************
  105. Remove_Switch
  106. move.w d6,d0
  107. move.w d7,d1
  108. andi.w #$fff0,d0
  109. andi.w #$fff0,d1
  110. move.l #Switch_Cover_Object,d2
  111. bsr Simple_Add_Alien_To_List
  112. move.w scroll_x_position,d2
  113. andi.w #$fff0,d2
  114. sub.w d2,d0
  115. sub.w scroll_y_position,d1
  116. move.l #Switch_Down_Graphics,a5
  117. bsr Draw_Block_Into_Copyback
  118. move.w #Sound_Switch,sound_chan4
  119. rts
  120. ***********************************************
  121. ********* REMOVE BLUE SWITCH *********
  122. ***********************************************
  123. Remove_Blue_Switch
  124. move.w d6,d0
  125. move.w d7,d1
  126. andi.w #$fff0,d0
  127. andi.w #$fff0,d1
  128. move.l #Switch_Blue_Cover_Object,d2
  129. bsr Simple_Add_Alien_To_List
  130. move.w scroll_x_position,d2
  131. andi.w #$fff0,d2
  132. sub.w d2,d0
  133. sub.w scroll_y_position,d1
  134. move.l #Switch_Blue_Down_Graphics,a5
  135. bsr Draw_Block_Into_Copyback
  136. move.w #Sound_Switch,sound_chan4
  137. rts
  138. ***********************************************
  139. ********* PLAYER STEPPED ON SWITCH *********
  140. ***********************************************
  141. Player_Stepped_On_Switch
  142. *d4 = block number
  143. sub.w #FIRST_SWITCH_BLOCK,d4
  144. move.l #switch_table,a1
  145. ext.l d4
  146. asl #2,d4
  147. move.l (a1,d4),d5
  148. beq.s empty_switch_entry
  149. move.l switch_list_pointer,a1
  150. move.l d5,(a1)+
  151. move.l #$ffffffff,(a1)
  152. move.l a1,switch_list_pointer
  153. empty_switch_entry
  154. cmp.w #8,d4
  155. bgt.s stepped_on_blue_switch
  156. move.w #402,(a0)
  157. bsr Remove_Switch
  158. rts
  159. stepped_on_blue_switch
  160. move.w #403,(a0)
  161. bsr Remove_Blue_Switch
  162. rts
  163. ***********************************************
  164. ********* DROP BIG KEY *********
  165. ***********************************************
  166. Drop_Big_Key
  167. tst.w number_of_hostages
  168. bne.s not_all_collected_yet
  169. bsr Collected_Last_Hostage
  170. not_all_collected_yet
  171. rts
  172. ***********************************************
  173. ********* PLAYER ACTIVATES EVENT *********
  174. ***********************************************
  175. Player_Activates_Event
  176. *d4 = block number
  177. sub.w #FIRST_EVENT_BLOCK,d4
  178. move.l #event_table,a0
  179. ext.l d4
  180. asl #2,d4
  181. move.l (a0,d4),d7
  182. beq.s empty_activate_entry
  183. clr.l (a0,d4) ;cant activate event again
  184. move.l switch_list_pointer,a1
  185. move.l d7,(a1)+
  186. move.l #$ffffffff,(a1)
  187. move.l a1,switch_list_pointer
  188. empty_activate_entry
  189. rts
  190. ***********************************************
  191. ********* WHAT IS PLAYER STANDING ON *********
  192. ***********************************************
  193. What_Is_Player_Standing_On
  194. *Init vars
  195. *a0 will point to area
  196. *
  197. move.l current_map_pointer,a0
  198. moveq #0,d0
  199. move.w actual_player_map_x_position,d0
  200. move.w actual_player_map_y_position,d1
  201. add.w #16,d0 ;position right in middle of player
  202. add.w #16,d1
  203. move.w d0,d6 ;x and y pos
  204. move.w d1,d7
  205. asr #4,d0
  206. asr #4,d1
  207. mulu #BIGGEST_MAP_X*2,d1
  208. add.l d1,a0
  209. asl d0
  210. add.l d0,a0 ;gives block
  211. moveq #0,d0
  212. move.w (a0),d0
  213. move.w d0,d4
  214. asl.w #BLOCK_STRUCT_MULT,d0
  215. move.l #block_data_information,a1
  216. moveq #0,d1
  217. move.b block_type(a1,d0.l),d1
  218. andi.w #$0f,d1 ;mask off unwanted data
  219. beq.s nothing_to_run
  220. lsl #2,d1
  221. move.l #block_activation_table,a1
  222. move.l (a1,d1),a1
  223. jsr (a1)
  224. nothing_to_run
  225. rts
  226. Null_Routine
  227. rts
  228. Slope_Down_Right_Routine
  229. tst last_x_direc
  230. beq.s skip_move
  231. add.w #32,player_move_x
  232. skip_move
  233. rts
  234. PLAYER_ON_SLOPE_RIGHT EQU 0
  235. player_move_x dc.w 0
  236. player_move_y dc.w 0
  237. PLAYER_TEST_HEIGHT EQU 15
  238. PLAYER_TEST_WIDTH EQU 15
  239. ***********************************************
  240. ********* DO PLAYER Y COLLISION *********
  241. ***********************************************
  242. Do_Player_Y_Collision
  243. *test player sides
  244. *d0 and d1 sent
  245. add.w #8,d0 ;add in a bit so collision not big square round player
  246. add.w #12,d1
  247. move.l #y_collision_struct,a3
  248. move.w #PLAYER_TEST_WIDTH,d3
  249. bsr test_y_collision_side
  250. tst.w y_collision(a3)
  251. beq.s test_other_sidey
  252. add.w #16-12,y_position(a3)
  253. bra.s done_y_collision
  254. test_other_sidey
  255. add.w #16,d1
  256. move.l #y_collision_struct,a3
  257. move.w #PLAYER_TEST_WIDTH,d3
  258. bsr test_y_collision_side
  259. tst.w y_collision(a3)
  260. beq.s done_this_sidey
  261. sub.w #16+12,y_position(a3)
  262. bra.s done_y_collision
  263. done_this_sidey
  264. sub.w #12,d1
  265. done_y_collision
  266. rts
  267. ***********************************************
  268. ********* DO PLAYER X COLLISION *********
  269. ***********************************************
  270. Do_Player_X_Collision
  271. *test player sides
  272. *d0 and d1 sent
  273. add.w #8,d0 ;add in a bit
  274. add.w #12,d1
  275. move.l #x_collision_struct,a3
  276. move.w #PLAYER_TEST_HEIGHT,d4
  277. bsr test_x_collision_side
  278. tst.w x_collision(a3)
  279. beq.s test_other_side
  280. add.w #16-8,x_position(a3)
  281. bra.s done_x_collision
  282. test_other_side
  283. add.w #16,d0
  284. move.l #x_collision_struct,a3
  285. move.w #PLAYER_TEST_HEIGHT,d4
  286. bsr test_x_collision_side
  287. tst.w x_collision(a3)
  288. beq.s no_collision_this_side
  289. sub.w #16+8,x_position(a3)
  290. bra.s done_x_collision
  291. no_collision_this_side
  292. sub.w #16+8,d0
  293. rts
  294. done_this_side
  295. sub.w #8,d0
  296. done_x_collision
  297. rts
  298. ***********************************************
  299. ********* TEST Y COLLISION SIDE *********
  300. ***********************************************
  301. Test_Y_Collision_Side
  302. *send in x and y in d0,d1 and width in d3
  303. *send struct in a3
  304. move.l current_map_pointer,a0
  305. addq.l #MAP_BLOCK_SIZE,a0
  306. ***********Obtain first map block ****************************
  307. moveq #0,d2
  308. move.w d1,d2
  309. move.w d2,d4
  310. asr.w #4,d2 ;give map y line
  311. muls #BIGGEST_MAP_X*MAP_BLOCK_SIZE,d2
  312. add.l d2,a0
  313. move.l a0,a1
  314. moveq #0,d2
  315. move.w d0,d2
  316. andi.w #$fff0,d2
  317. asr.w #3,d2 ;word map ;get map x pos
  318. move.l a0,a2 ;store for later
  319. add.l d2,a0 ;where currently is
  320. *************first map block in a0*****************************
  321. *******************Do tests on first block tested**************
  322. moveq #0,d2
  323. clr.l y_block_left(a3) ;clears sign as well
  324. move.w (a0),d2
  325. asl.w #BLOCK_STRUCT_MULT,d2
  326. move.l #block_data_information,a4
  327. btst.b #COLLISION_FLAG,block_details(a4,d2)
  328. bne.s simple_hit_block_left
  329. ******************Done tests on first block********************
  330. ******************Do tests on second block*********************
  331. do_tests_on_sec_block
  332. simple_test_next_block_in_line
  333. moveq #0,d2
  334. move.w d0,d2
  335. add.w d3,d2
  336. andi.w #$fff0,d2
  337. asr.w #3,d2 ;cos word map
  338. move.l a1,a0
  339. add.l d2,a0
  340. moveq #0,d2
  341. move.w (a0),d2
  342. asl.w #BLOCK_STRUCT_MULT,d2
  343. btst.b #COLLISION_FLAG,block_details(a4,d2)
  344. bne.s simple_hit_block_right
  345. simple_not_hit_a_block
  346. clr.w y_collision(a3)
  347. bra.s quit_simple_y_collision
  348. simple_hit_block_right
  349. move.w #1,y_block_sign(a3)
  350. simple_hit_block_left
  351. move.w #1,y_collision(a3)
  352. andi.w #$fff0,d4
  353. move.w d4,y_position(a3)
  354. *Determine status of blocks left and right of hit point
  355. moveq #0,d2
  356. move.w -MAP_BLOCK_SIZE(a0),d2
  357. asl.w #BLOCK_STRUCT_MULT,d2
  358. btst.b #COLLISION_FLAG,block_details(a4,d2)
  359. beq.s block_left_free
  360. move.b #1,y_block_left(a3)
  361. block_left_free
  362. moveq #0,d2
  363. move.w MAP_BLOCK_SIZE(a0),d2
  364. asl.w #BLOCK_STRUCT_MULT,d2
  365. btst.b #COLLISION_FLAG,block_details(a4,d2)
  366. beq.s quit_simple_y_collision
  367. move.b #1,y_block_right(a3)
  368. quit_simple_y_collision
  369. rts
  370. ***********************************************
  371. ********* TEST X COLLISION SIDE *********
  372. ***********************************************
  373. test_x_collision_side
  374. *send in d0 and d1 the x and y - not scaled
  375. *send height in d4
  376. *send x collision struct in a3
  377. *routine does not hurt d0 or d1
  378. move.l current_map_pointer,a0
  379. add.l #MAP_BLOCK_SIZE,a0
  380. moveq #0,d2
  381. move.w d1,d2
  382. add.w d1,d4 ;test block below if height bigger than one block
  383. asr.w #4,d2
  384. asr.w #4,d4
  385. muls #BIGGEST_MAP_X*MAP_BLOCK_SIZE,d2 ;give map y line
  386. muls #BIGGEST_MAP_X*MAP_BLOCK_SIZE,d4
  387. move.l a0,a1
  388. add.l d4,a1
  389. add.l d2,a0 ;position in map data of object
  390. moveq #0,d2
  391. move.w d0,d4 ;save player x for use in positioning if player hit block
  392. move.w d0,d2
  393. andi.w #$fff0,d2
  394. asr.w #3,d2 ;word map ;get map x pos
  395. add.l d2,a1
  396. add.l d2,a0 ;where currently is
  397. clr.l x_block_up(a3) ;clears sign as well
  398. moveq #0,d2
  399. move.l #block_data_information,a2
  400. move.w (a0),d2
  401. asl.w #BLOCK_STRUCT_MULT,d2
  402. btst.b #COLLISION_FLAG,block_details(a2,d2)
  403. bne.s have_hit_top_block
  404. move.l a1,a0
  405. moveq #0,d2
  406. move.w (a1),d2
  407. asl.w #BLOCK_STRUCT_MULT,d2
  408. btst.b #COLLISION_FLAG,block_details(a2,d2)
  409. bne.s have_hit_bottom_block
  410. clr.w x_collision(a3)
  411. bra.s finished_x_collision
  412. have_hit_bottom_block
  413. move.w #1,x_block_sign(a3)
  414. have_hit_top_block
  415. move.w #1,x_collision(a3)
  416. andi.w #$fff0,d4
  417. move.w d4,x_position(a3)
  418. add.l d2,a2
  419. move.l a2,x_block_data_struct(a3)
  420. *Determine status of blocks above and below hit point
  421. move.l #block_data_information,a2
  422. moveq #0,d2
  423. move.w -(BIGGEST_MAP_X*MAP_BLOCK_SIZE)(a0),d2
  424. asl.w #BLOCK_STRUCT_MULT,d2
  425. btst.b #COLLISION_FLAG,block_details(a2,d2)
  426. beq.s block_up_free
  427. move.b #1,x_block_up(a3)
  428. block_up_free
  429. move.w (BIGGEST_MAP_X*MAP_BLOCK_SIZE)(a0),d2
  430. asl.w #BLOCK_STRUCT_MULT,d2
  431. btst.b #COLLISION_FLAG,block_details(a2,d2)
  432. beq.s finished_x_collision
  433. move.b #1,x_block_down(a3)
  434. finished_x_collision
  435. rts
  436. rsreset
  437. x_collision rs.w 1
  438. x_position rs.w 1
  439. x_block_data_struct rs.l 1
  440. x_block_mem_pos rs.l 1
  441. x_block_up rs.b 1
  442. x_block_down rs.b 1
  443. x_block_sign rs.w 1
  444. x_collision_struct
  445. dc.w 0
  446. dc.w 0
  447. dc.l 0
  448. dc.l 0
  449. dc.w 0
  450. dc.w 0
  451. rsreset
  452. y_collision rs.w 1
  453. y_position rs.w 1
  454. y_block_data_struct rs.l 1
  455. y_block_mem_pos rs.l 1
  456. y_block_left rs.b 1
  457. y_block_right rs.b 1
  458. y_block_sign rs.w 1
  459. EVEN
  460. y_collision_struct
  461. dc.w 0
  462. dc.w 0
  463. dc.l 0
  464. dc.l 0
  465. dc.w 0
  466. dc.w 0