Advertisement
Guest User

wip_collision_prevention.bas

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