Advertisement
Guest User

collision_prevention.bas

a guest
Jun 25th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. set kernel multisprite
  2. set optimization noinlinedata
  3.  
  4. dim tx = temp1
  5. dim ty = temp2
  6. dim pptr = temp4
  7. dim dir = temp5
  8. dim cf = temp6
  9.  
  10. dim sc0 = score
  11. dim sc1 = score + 1
  12. dim sc2 = score + 2
  13.  
  14. dim dx = a
  15. dim dy = b
  16. dim jf = c
  17. dim sf = d
  18. dim pno = e
  19.  
  20. const pxb = player0x
  21. const pyb = player0y
  22.  
  23. pfheight = 7
  24.  
  25. mk1
  26.  
  27. playfield:
  28. ................
  29. ................
  30. ................
  31. ..............XX
  32. ..............XX
  33. ..............XX
  34. ..............XX
  35. ................
  36. ................
  37. ................
  38. ................
  39. end
  40.  
  41. player0:
  42. %00010000
  43. %01000010
  44. %00000000
  45. %10000001
  46. %00000000
  47. %01000010
  48. %00010000
  49. %10000000
  50. end
  51.  
  52. rem 0 0 upper left
  53. rem table order left middle = 0
  54. rem increasing counter clockwise
  55. rem -16 x offset -10 y offset
  56.  
  57. rem 0, 1, 3, 6, 7, 6, 3, 1
  58. rem -16, -15, -13, -10, -9, -10, -13, -15
  59.  
  60. rem 3, 5, 6, 5, 3, 1, 0, 1
  61. rem -7, -5, -4, -5, -7, -9, -10, -9
  62.  
  63. player1:
  64. %00000000
  65. %00000000
  66. %00000000
  67. %00000000
  68. %00011111
  69. %00001110
  70. %00001110
  71. %10000100
  72. end
  73.  
  74. rem 0 0 upper left
  75. rem table order left middle = 0
  76. rem increasing counter clockwise
  77. rem -24 x offset -8 y offset
  78.  
  79. rem 3, 4, 5, 6, 7, 6, 5, 4
  80. rem -21, -20, -19, -18, -17, -18, -19, -20
  81.  
  82. rem 4, 6, 7, 6, 4, 4, 4, 4
  83. rem -4, -2, -1, -2, -4, -4, -4, -4
  84.  
  85. player2:
  86. %00011100
  87. %00000000
  88. %00110001
  89. %00000001
  90. %10000001
  91. %10000001
  92. %00000000
  93. %00011000
  94. end
  95.  
  96. rem 0, 0, 4, 7, 7, 5, 3, 2
  97. rem -24, -24, -20, -17, -17, -19, -21, -22
  98.  
  99. rem 4, 5, 7, 5, 2, 0, 0, 2
  100. rem -4, -3, -1, -3, -6, -8, -8, -6
  101.  
  102. player3:
  103. %00010000
  104. %00010000
  105. %01111000
  106. %00011111
  107. %11111000
  108. %00111110
  109. %00001000
  110. %00001000
  111. end
  112.  
  113. rem 0, 2, 4, 6, 7, 4, 3, 1
  114. rem -24, -22, -20, -18, -17, -20, -21, -23
  115.  
  116. rem 4, 5, 7, 5, 3, 2, 0, 2
  117. rem -4, -3, -1, -3, -5, -6, -8, -6
  118.  
  119. player4:
  120. %00010000
  121. %00010000
  122. %00010000
  123. %01111110
  124. %00001000
  125. %00001000
  126. %00001000
  127. %00000000
  128. end
  129.  
  130. rem 1, 4, 4, 4, 6, 3, 3, 3
  131. rem -23, -20, -20, -20, -18, -21, -21, -21
  132.  
  133. rem 3, 3, 6, 3, 3, 3, 0, 3
  134. rem -5, -5, -2, -5, -5, -5, -8, -5
  135.  
  136.  
  137. player5:
  138. %00000000
  139. %00010000
  140. %00011100
  141. %00110000
  142. %10000001
  143. %10010111
  144. %00010100
  145. %00011100
  146. end
  147.  
  148. rem 0, 3, 3, 7, 7, 5, 3, 0
  149. rem -24, -21, -21, -17, -17, -19, -21, -24
  150.  
  151. rem 5, 5, 7, 7, 4, 2, 1, 3
  152. rem -3, -3, -1, -1, -4, -6, -7, -5
  153.  
  154. pno = 0 : cf = $FF : jf = $80
  155.  
  156. COLUPF = $92
  157. COLUBK = $9C
  158. COLUP2 = $56
  159. COLUP3 = $46
  160. COLUP4 = $36
  161. COLUP5 = $26
  162.  
  163. player0x = $16 : player1x = $16 : player2x = $16
  164. player3x = $16 : player4x = $16 : player5x = $16
  165. player0y = $0C : player1y = $18 : player2y = $24
  166. player3y = $30 : player4y = $3C : player5y = $48
  167.  
  168. main
  169.  
  170. temp2 = ((jf ^ $80) & INPT4) & $80 : jf = INPT4
  171. if temp2 then pno = pno_tbl[pno]
  172.  
  173. temp2 = ((SWCHA ^ $FF) & sf)/16 : sf = SWCHA
  174. temp2 = (sf/16) ^ $0F
  175. dir = dir_tbl[temp2]
  176.  
  177. if !temp2 then no_move
  178. gosub move_player
  179.  
  180. no_move
  181. COLUP0 = $1C
  182. COLUP1 = $66
  183.  
  184. drawscreen
  185. goto main
  186.  
  187. move_player
  188.  
  189. gosub test
  190. if !cf then move
  191.  
  192. rem if not odd-diagonal then done
  193. rem else check x, y individually
  194.  
  195. if !dir{0} then move_done
  196. dir = (dir - 1) & 7
  197. gosub test
  198. if !cf then move
  199. dir = (dir + 2) & 7
  200. gosub test
  201. if cf then move_done
  202. move
  203.  
  204. rem adjust player position according to direction
  205.  
  206. pxb[pno] = pxb[pno] + dx_tbl[dir]
  207. pyb[pno] = pyb[pno] + dy_tbl[dir]
  208. temp1 = pxb[pno] : temp2 = pyb[pno]
  209. gosub update_scr
  210. move_done
  211. return
  212.  
  213. test
  214. dx = dx_tbl[dir] + pxb[pno] : dy = dy_tbl[dir] + pyb[pno]
  215. pptr = pno_mul_tbl[pno] + dir : cf = $FF
  216.  
  217. tx = (px_tbl[pptr] + dx)/4 : ty = (py_tbl[pptr] + dy)/8
  218. if !pfread(tx, ty) then return
  219. pptr = pptr + 1
  220. tx = (px_tbl[pptr] + dx)/4 : ty = (py_tbl[pptr] + dy)/8
  221. if !pfread(tx, ty) then test_done
  222. pptr = pptr + 1
  223. tx = (px_tbl[pptr] + dx)/4 : ty = (py_tbl[pptr] + dy)/8
  224. if !pfread(tx, ty) then test_done
  225. pptr = pptr + 1
  226. tx = (px_tbl[pptr] + dx)/4 : ty = (py_tbl[pptr] + dy)/8
  227. if !pfread(tx, ty) then test_done
  228. pptr = pptr + 1
  229. tx = (px_tbl[pptr] + dx)/4 : ty = (py_tbl[pptr] + dy)/8
  230. if !pfread(tx, ty) then test_done
  231. cf = cf + 1
  232. test_done
  233. return
  234.  
  235.  
  236. data px_tbl
  237. -16, -15, -13, -10, -9, -10, -13, -15, -16, -15, -13, -10
  238. -21, -20, -19, -18, -17, -18, -19, -20, -21, -20, -19, -18
  239. -24, -24, -20, -17, -17, -19, -21, -22, -24, -24, -20, -17
  240. -24, -22, -20, -18, -17, -20, -21, -23, -24, -22, -20, -18
  241. -23, -20, -20, -20, -18, -21, -21, -21, -23, -20, -20, -20
  242. -24, -21, -21, -17, -17, -19, -21, -24, -24, -21, -21, -17
  243. end
  244.  
  245. data py_tbl
  246. -7, -5, -4, -5, -7, -9, -10, -9, -7, -5, -4, -5
  247. -4, -2, -1, -2, -4, -4, -4, -4, -4, -2, -1, -2
  248. -4, -3, -1, -3, -6, -8, -8, -6, -4, -3, -1, -3
  249. -4, -3, -1, -3, -5, -6, -8, -6, -4, -3, -1, -3
  250. -5, -5, -2, -5, -5, -5, -8, -5, -5, -5, -2, -5
  251. -3, -3, -1, -1, -4, -6, -7, -5, -3, -3, -1, -1
  252. end
  253.  
  254. data dx_tbl
  255. 0, 1, 1, 1, 0, -1, -1, -1
  256. end
  257.  
  258. data dy_tbl
  259. 1, 1, 0, -1, -1, -1, 0, 1
  260. end
  261.  
  262. data dir_tbl
  263. 0, 0, 4, 0, 6, 7, 5, 0, 2, 1, 3
  264. end
  265.  
  266. data pno_tbl
  267. 1, 2, 3, 4, 5, 0
  268. end
  269.  
  270. data pno_mul_tbl
  271. 0, 12, 24, 36, 48, 60
  272. end
  273.  
  274.  
  275.  
  276.  
  277. update_scr
  278. sc0 = 0 : sc1 = sc1 & 15
  279. if temp1 >= 100 then sc0 = sc0 + 16 : temp1 = temp1 - 100
  280. if temp1 >= 100 then sc0 = sc0 + 16 : temp1 = temp1 - 100
  281. if temp1 >= 50 then sc0 = sc0 + 5 : temp1 = temp1 - 50
  282. if temp1 >= 30 then sc0 = sc0 + 3 : temp1 = temp1 - 30
  283. if temp1 >= 20 then sc0 = sc0 + 2 : temp1 = temp1 - 20
  284. if temp1 >= 10 then sc0 = sc0 + 1 : temp1 = temp1 - 10
  285. sc1 = (temp1 * 4 * 4) | sc1
  286.  
  287. sc1 = sc1 & 240 : sc2 = 0
  288. if temp2 >= 100 then sc1 = sc1 + 1 : temp2 = temp2 - 100
  289. if temp2 >= 100 then sc1 = sc1 + 1 : temp2 = temp2 - 100
  290. if temp2 >= 50 then sc2 = sc2 + 80 : temp2 = temp2 - 50
  291. if temp2 >= 30 then sc2 = sc2 + 48 : temp2 = temp2 - 30
  292. if temp2 >= 20 then sc2 = sc2 + 32 : temp2 = temp2 - 20
  293. if temp2 >= 10 then sc2 = sc2 + 16 : temp2 = temp2 - 10
  294. sc2 = sc2 | temp2
  295. return
  296.  
  297. asm
  298. pfread
  299. clc
  300. adc #$08
  301. and #$1F
  302. cmp #$10
  303. and #$0F
  304. tax
  305. lda bit_masks,x
  306. bcc skip_PF2_and
  307. and (PF2pointer),y
  308. bcs skip_PF1_and
  309. skip_PF2_and
  310. and (PF1pointer),y
  311. skip_PF1_and
  312. return
  313.  
  314. bit_masks
  315. .byte $01, $02, $04, $08, $10, $20, $40, $80
  316. .byte $80, $40, $20, $10, $08, $04, $02, $01
  317. end
  318.  
  319. mk2
  320.  
  321. asm
  322. echo (.mk2 - .mk1)d
  323. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement