Geekboy

Untitled

Oct 26th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Player bullet handlers
  2. ;
  3. ;PBT located at $8D00
  4. ;First 64 bytes is PBT's FBT, all are filled with values indicating player
  5. ;bullet's LSB base location (multiples of 3 starting at $8D40
  6. ;Last 64*3 bytes is PBT's actual bullet data entries, described below, but
  7. ;is up to called routine's interpretation.
  8. ;
  9. ;FBT's location is in (pbtfreebullet). If bit 6 is ever set, then the FBT
  10. ;is full.
  11. ;
  12. ;Important note: Character's X and Y positions are not stored as normal. There
  13. ;are two bits of accuracy at the start so you're going to have to right-shift
  14. ;twice to get the actual X,Y positions.
  15. ;
  16. ;Y = YYYY YYSS , where S is subpixel data
  17. ;X = XXXX XXSS , where S is subpixel data
  18. ;
  19.  
  20. ;Player bullet structure (3 bytes)
  21. ;+0 : YTTTTTTT, T=Timer 0-127, Y=1 if focused shot
  22. ;+1 : Y position if applicable
  23. ;+2 : X position if applicable
  24.  
  25. ;The routine that is being called must be able to distinguish between
  26. ;unfocused and focused modes, since there won't be seperation at
  27. ;this stage of the routine call.
  28. ;
  29. ;Several things to edit.
  30. ;(1) PBTPlayerRoutineTables : How bullets are created. Below it are links.
  31. ;(2) PBTPlayerTypeTables : Types of bullets and how they move
  32. ;
  33. ;You can make creative use of the game timers to tell bullets apart
  34. ;(gametimer1) by creating only certain ones on certain slices of masked time.
  35. ;A good mask might be like %00000111 so you get 8 different time slices on
  36. ;each processing. Also pay attention to firing delays or you might not ever
  37. ;get a single bullet out.
  38. ;
  39. ;Other than that, good luck. You're gonna need it.
  40.  
  41.  
  42. #DEFINE PBTSHOT(xofs,yofs,count) call PBTCreate \ .db xofs,yofs,count
  43.  
  44.  
  45.  
  46. PlayerShoot:
  47.  ld a,(characterID)
  48.  add a,a
  49.  ld e,a
  50.  ld d,0
  51.  ld hl,PBTPlayerRoutineTables
  52.  add hl,de
  53.  ld e,(hl)
  54.  inc hl
  55.  ld d,(hl)
  56.  ld hl,charweapon1
  57.  bit isfocused,(iy+danmakuflags)
  58.  jr z,_
  59.  inc hl
  60.  inc de
  61.  inc de  ;if focused, charweapon2, and inc pointer to a focused standpoint
  62. _:
  63.  ld a,(hl)
  64.  add a,a
  65.  add a,a  ;x4 for weapon power thing
  66.  ld L,a
  67.  ld h,0
  68.  add hl,de
  69.  ld a,(hl)
  70.  inc hl
  71.  ld h,(hl)
  72.  ld L,a
  73.  jp (hl)
  74.  
  75. PBTMainDraw:
  76.  xor a
  77.  call PBTFillBulletDetails
  78.  ld (itemp1),sp
  79.  ld sp,$8D40
  80.  ld a,64
  81. PBTMainDrawLoop:
  82.  ex af,af'
  83. dec sp
  84. pop af
  85. pop de
  86. cp $FF
  87. jp z,PBTMainDrawRet
  88. ld hl,(itemp2) ;unfocused
  89. bit 7,a
  90. jr z,_
  91. ld hl,(itemp3) ;focused
  92. _:
  93. jp (hl)        ;routine being jumped to MUST keep B intact
  94. PBTMainDrawRet:
  95. ex af,af'
  96.  dec a
  97.  jr nz,PBTMainDrawLoop
  98.  ld sp,(itemp1)
  99.  ret
  100.  
  101. PBTMainMove:
  102.  ld a,4
  103.  call PBTFillBulletDetails
  104.  ld (itemp1),sp
  105.  ld sp,$8D40
  106.  ld a,64
  107. PBTMainMoveLoop:
  108.  ex af,af'
  109. dec sp
  110. pop af   ;A=tCCCCCCC, where t=type, C=counter
  111. pop de   ;E=Ypos ; D=Xpos (no accuracy bits, negative values may be used)
  112. cp $FF
  113. jp z,PBTMainMoveRet
  114. ld hl,(itemp2) ;unfocused
  115. bit 7,a
  116. jr z,_
  117. ld hl,(itemp3) ;focused
  118. _:
  119. jp (hl)        ;routine being jumped to MUST keep B intact
  120. PBTMainMoveRet:
  121. ex af,af'
  122.  dec a
  123.  jr nz,PBTMainMoveLoop
  124.  ld sp,(itemp1)
  125.  ret
  126. PBTNoCreate:
  127.  pop hl
  128.  inc hl
  129.  inc hl
  130.  inc hl
  131.  jp (hl)
  132. PBTCreate: ;in: macro'd. Xofs,Yofs,Count
  133.  ld hl,pbtfreebullet
  134.  bit 6,(hl)
  135.  jp nz,PBTNoCreate     ;stop routine if over 64 bullets
  136.  ld a,(hl) ;1.read
  137.  inc (hl)  ;2.increment
  138.  ld L,a
  139.  ld h,$8D
  140.  ld L,(hl) ;got bullet position
  141.  push hl
  142.  pop ix
  143.  ld de,(chary)
  144.  srl e \ srl e ;y
  145.  srl d \ srl d ;x
  146.  pop hl
  147.  ld a,d
  148.  add a,(hl)
  149.  inc hl
  150.  ld (ix+2),a
  151.  ld a,e
  152.  add a,(hl)
  153.  inc hl
  154.  ld (ix+1),a
  155.  ld a,(mdanmaku)  ;isfocused == bit 1. Need to shift to bit 7.
  156.  rrca
  157.  rrca
  158.  and $80
  159.  or (hl) ;combining new counter with focused mask
  160.  inc hl
  161.  ld (ix+0),a
  162.  jp (hl)
  163.  
  164. PBTCreate2: ;D=Xofs,E=Yofs,A=Count
  165.  push af
  166.   ld hl,pbtfreebullet
  167.   bit 6,(hl)
  168.   jr z,_        ;stop routine if over 64 bullets. Jump past if no stop.
  169.  pop af
  170.  ret
  171. _:
  172.   ld a,(hl) ;1.read
  173.   inc (hl)  ;2.increment
  174.   ld L,a
  175.   ld h,$8D
  176.   ld L,(hl) ;got bullet position
  177.   push hl
  178.   pop ix
  179.   ld a,(charx)
  180.   srl a \ srl a
  181.   add a,d
  182.   ld (ix+2),a
  183.   ld a,(chary)
  184.   srl a \ srl a
  185.   add a,e
  186.   ld (ix+1),a
  187.   ld a,(mdanmaku)
  188.   rrca
  189.   rrca
  190.   and $80
  191.  pop bc
  192.  or b    ;combining masks for b7=focused, b0-b6=counter
  193.  ld (ix+0),a
  194.  ret
  195.  
  196.  
  197.  
  198. PBTDestroy: ;must be called in MOVE routine b4 SP is changed to save values
  199.  ld hl,-3
  200.  add hl,sp
  201.  ld (hl),$FF
  202.  ex de,hl
  203.  ld hl,pbtfreebullet
  204.  dec (hl)
  205.  ld L,(hl)
  206.  ld h,$8D
  207.  ld (hl),e
  208.  jp PBTMainMoveRet
  209.  
  210. PBTFillBulletDetails:
  211.  ld c,a
  212.  ld b,0   ;offset (0 if render cycle, 4 if move/collide cycle)
  213.  ld a,(characterID)
  214.  add a,a
  215.  ld hl,PBTPlayerTypeTables
  216.  add a,L
  217.  ld L,a
  218.  jr nc,$+3
  219.  inc h
  220.  ld e,(hl)
  221.  inc hl
  222.  ld d,(hl) ;got address to character's bullet table in DE
  223.  ld a,(charweapon1)  ;unfocused weapon type
  224.  add a,a  ;x2
  225.  add a,a  ;x4
  226.  add a,a  ;x8  ;weapon power type now available.
  227.  add a,e
  228.  ld L,a
  229.  ld h,d
  230.  jr nc,_
  231.  inc h
  232. _:
  233.  add hl,bc
  234.  ld a,(hl)
  235.  inc hl
  236.  ld h,(hl)
  237.  ld L,a
  238.  ld (itemp2),hl  ;unfocused weapon type in itemp2 variable
  239.  ld a,(charweapon2)  ;focused weapon type
  240.  add a,a  ;x2
  241.  add a,a  ;x4
  242.  add a,a  ;x8
  243.  add a,2  ;+more offset for focused type
  244.  add a,e
  245.  ld L,a
  246.  ld h,d
  247.  jr nc,_
  248.  inc h
  249. _:
  250.  add hl,bc
  251.  ld a,(hl)
  252.  inc hl
  253.  ld h,(hl)
  254.  ld L,a
  255.  ld (itemp3),hl  ;focused weapon type in itemp3 variable
  256.  ret
  257.  
  258. ;-----------------------------------------------------------------------------
  259. ;PLAYER BULLET CREATION TABLES
  260. ;
  261.  
  262.  
  263. PBTPlayerRoutineTables:
  264. .dw PBTPRT00  ;Devblock  (ChID0) DO NOT CHANGE THESE ENTRIES
  265. .dw PBTPRT01  ;Iambian   (ChID1)
  266. .dw PBTPRT02  ;Netham45  (ChID2)
  267. .dw PBTPRT03  ;???       (ChID3)
  268. .dw PBTPRT04  ;???       (ChID4)
  269. .dw PBTPRT05  ;???       (ChID5)
  270. .dw PBTPRT06  ;Netham45L (ChID6)
  271. .dw PBTPRT07  ;???       (ChID7)
  272.  
  273. PBTPRT00:  ;Devblock  (ChID0)
  274. .dw DevBlockUnfPwr1   ;direct links to the routines that is about to be used
  275. .dw DevBlockFocPwr1
  276. .dw DevBlockUnfPwr2   ;direct links to the routines that is about to be used
  277. .dw DevBlockFocPwr2
  278. PBTPRT01:  ;Iambian   (ChID1)
  279. .dw TestRoutineUnFocPwr1
  280. .dw TestRoutineFocusPwr1
  281. .dw TestRoutineUnFocPwr2
  282. .dw TestRoutineFocusPwr2
  283. PBTPRT02:  ;Netham45  (ChID2)
  284. .dw TestRoutineUnFocPwr1
  285. .dw TestRoutineFocusPwr1
  286. .dw TestRoutineUnFocPwr2
  287. .dw TestRoutineFocusPwr2
  288. PBTPRT03:  ;???       (ChID3)
  289. .dw TestRoutineUnFocPwr1
  290. .dw TestRoutineFocusPwr1
  291. .dw TestRoutineUnFocPwr2
  292. .dw TestRoutineFocusPwr2
  293. PBTPRT04:  ;???       (ChID4)
  294. .dw TestRoutineUnFocPwr1
  295. .dw TestRoutineFocusPwr1
  296. .dw TestRoutineUnFocPwr2
  297. .dw TestRoutineFocusPwr2
  298. PBTPRT05:  ;Nanami    (ChID5)
  299. .dw TestRoutineUnFocPwr1
  300. .dw TestRoutineFocusPwr1
  301. .dw TestRoutineUnFocPwr2
  302. .dw TestRoutineFocusPwr2
  303. PBTPRT06:  ;Netham45L (ChID6)
  304. .dw ShotHyperdrive
  305. .dw TestRoutineFocusPwr1
  306. .dw TestRoutineUnFocPwr2
  307. .dw TestRoutineFocusPwr2
  308. PBTPRT07:  ;???       (ChID7)
  309. .dw TestRoutineUnFocPwr1
  310. .dw TestRoutineFocusPwr1
  311. .dw TestRoutineUnFocPwr2
  312. .dw TestRoutineFocusPwr2
  313.  
  314.  
  315. ;-----------------------------------------------------------------------------
  316. ;PLAYER BULLET RENDER/MOVE/COLLISION TABLES
  317. ;
  318.  
  319. PBTPlayerTypeTables:
  320. .dw PBTPTT00  ;Devblock  (ChID0) DO NOT CHANGE THESE ENTRIES
  321. .dw PBTPTT01  ;Iambian   (ChID1)
  322. .dw PBTPTT02  ;Netham45  (ChID2)
  323. .dw PBTPTT03  ;???       (ChID3)
  324. .dw PBTPTT04  ;???       (ChID4)
  325. .dw PBTPTT05  ;Nanami    (ChID5)
  326. .dw PBTPTT06  ;Netham45L (ChID6)
  327. .dw PBTPTT07  ;???       (ChID7)
  328.  
  329. ;SO FAR EVERY ENTRY IN THIS TABLE IS DUMMY ENTRIES. FILL IN WITH ACTUAL
  330. ;DATA CONNECTED TO ASSEMBLY ROUTINES WHENEVER YOU ARE READY TO CODE THIS
  331. ;HORRIBLE MESS.
  332. PBTPTT00:         ;Devblock  (ChID0)
  333. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  334. .dw PBTShot00Draw ;-Focused   shot power 1 render
  335. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  336. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  337. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  338. .dw PBTShot00Draw ;-Focused   shot power 2 render
  339. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  340. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  341. PBTPTT01:         ;Iambian   (ChID1)
  342. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  343. .dw PBTShot00Draw ;-Focused   shot power 1 render
  344. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  345. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  346. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  347. .dw PBTShot00Draw ;-Focused   shot power 2 render
  348. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  349. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  350. PBTPTT02:         ;Netham45  (ChID2)
  351. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  352. .dw PBTShot00Draw ;-Focused   shot power 1 render
  353. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  354. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  355. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  356. .dw PBTShot00Draw ;-Focused   shot power 2 render
  357. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  358. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  359. PBTPTT03:         ;???       (ChID3)
  360. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  361. .dw PBTShot00Draw ;-Focused   shot power 1 render
  362. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  363. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  364. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  365. .dw PBTShot00Draw ;-Focused   shot power 2 render
  366. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  367. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  368. PBTPTT04:         ;???       (ChID4)
  369. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  370. .dw PBTShot00Draw ;-Focused   shot power 1 render
  371. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  372. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  373. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  374. .dw PBTShot00Draw ;-Focused   shot power 2 render
  375. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  376. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  377. PBTPTT05:         ;Nanami    (ChID5)PB00MoveCollide: ;dummy routine
  378. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  379. .dw PBTShot00Draw ;-Focused   shot power 1 render
  380. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  381. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  382. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  383. .dw PBTShot00Draw ;-Focused   shot power 2 render
  384. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  385. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  386. PBTPTT06:         ;Netham45L (ChID6)
  387. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  388. .dw PBTShot00Draw ;-Focused   shot power 1 render
  389. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  390. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  391. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  392. .dw PBTShot00Draw ;-Focused   shot power 2 render
  393. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  394. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  395. PBTPTT07:         ;???       (ChID7)PB00Draw         ;dummy routine
  396. .dw PBTShot00Draw ;-Unfocused shot power 1 render
  397. .dw PBTShot00Draw ;-Focused   shot power 1 render
  398. .dw PBTShot00Move ;-Unfocused shot power 1 move/collide/remove
  399. .dw PBTShot00Move ;-Focused   shot power 1 move/collide/remove
  400. .dw PBTShot00Draw ;-Unfocused shot power 2 render
  401. .dw PBTShot00Draw ;-Focused   shot power 2 render
  402. .dw PBTShot00Move ;-Unfocused shot power 2 move/collide/remove
  403. .dw PBTShot00Move ;-Focused   shot power 2 move/collide/remove
  404.  
  405. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  406. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  407. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  408. ;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  409.  
  410. ;=============================================================================
  411. ;CHARACTER FIRING CODE (what happens when you push the fire button)
  412. ;
  413.  
  414. DevBlockUnfPwr1:  ;These routines pretty much all do the same thing
  415. TestRoutineUnFocPwr1:
  416. TestRoutineUnFocPwr2:
  417. DevBlockUnfPwr2:
  418. ;This routine fires a single centered shot on even cycles and
  419. ;two side shots on odd cycles, every other game cycle
  420.  ld hl,firedelay
  421.  dec (hl)
  422.  ret nz
  423.  ld (hl),2  ;FIRE DELAY FOR STANDARD SHOT IS TWO
  424.  ld hl,charweapondat
  425.  inc (hl)
  426.  bit 0,(hl)  ;check to see if even or odd. Using it to alternate bullet sets
  427.  ld hl,(chary)
  428.  jp z,_      ;jump to two side bullets thing
  429.  PBTSHOT(3,-1,0) ;xofs,yofs,cnt. centered bullet
  430.  ret
  431. _:
  432.  PBTSHOT(0,-1,0) ;left side
  433.  PBTSHOT(6,-1,0) ;right side
  434.  ret
  435.  
  436. DevBlockFocPwr1:  ;Again, these routines all pretty much do the same thing
  437. DevBlockFocPwr2:
  438. TestRoutineFocusPwr1:
  439. TestRoutineFocusPwr2:
  440. ;This routine fires two centered shots every game cycle
  441. ;
  442.  ld hl,firedelay
  443.  dec (hl)
  444.  ret nz
  445.  ld (hl),1  ;ONE GAME CYCLE. THIS CYCLING PROBABLY ISN'T NEEDED THO.
  446.  PBTSHOT(2,-1,0) ;left center
  447.  PBTSHOT(4,-1,0) ;right center
  448.  ret
  449.  
  450.  
  451. ShotHyperdrive:
  452.  PBTSHOT(3,-1,0)
  453.  PBTSHOT(3,-1,0)
  454.  PBTSHOT(3,-1,0)
  455.  PBTSHOT(3,-1,0)
  456.  PBTSHOT(3,-1,0)
  457.  PBTSHOT(3,-1,0)
  458.  PBTSHOT(3,-1,0)
  459.  PBTSHOT(3,-1,0)
  460.  ret
  461. ;=============================================================================
  462. ;BULLET RENDERING CODE (cycle 2)
  463. ;
  464.  
  465. PBTShot00Draw:    ;standard 2x3 bullet
  466. ;E=Y D=X normalized (00yy yyyy,00xx xxxx)
  467.  ld c,d    ;keeping a backup of C for later screen merriment :)
  468.  ex de,hl  ;HL=00xxxxxx 00yyyyyy
  469.  sla h
  470.  sla h     ;HL=xxxxxx00 00yyyyyy
  471.  xor a
  472.  add hl,hl
  473.  rla
  474.  add hl,hl
  475.  rla
  476.  add hl,hl ;HL=xxx0000y yyyyy000 A=00000xxx (after next instruction)
  477.  rla
  478.  or L
  479.  ld L,a
  480.  ld a,h
  481.  and %00000001
  482.  or  %10000000
  483.  ld h,a         ;HL=address get. 99ccs. Not the best but filters out bad coord
  484.  ld a,c         ;saved X
  485.  ld b,7
  486.  and b
  487.  xor b          ;checking to see if xxx=7 (straddling bullet)
  488.  jr z,_  ;skip to special case bullets straddling the 8 bit boundary
  489.  xor b
  490.  add a,$20 ;bullet2x2 table, except we're drawing 2x3's
  491.  ld d,$40
  492.  ld e,a
  493.  ld a,(de)
  494.  ld c,a
  495.  ld de,8
  496.  ld a,(hl)
  497.  or c
  498.  ld (hl),a
  499.  add hl,de
  500.  ld a,(hl)
  501.  or c
  502.  ld (hl),a
  503.  add hl,de
  504.  ld a,(hl)
  505.  or c
  506.  ld (hl),a
  507.  jp PBTMainDrawRet     ;go back to main loop
  508. _:
  509.  ld de,7
  510.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  511.  set 0,(hl) \ inc hl \ set 7,(hl) \ add hl,de
  512.  set 0,(hl) \ inc hl \ set 7,(hl)
  513.  jp PBTMainDrawRet
  514.  
  515.  
  516. ;=============================================================================
  517. ;BULLET MOVEMENT/COLLISION CODE (cycle 5)
  518. ;
  519.  
  520. PBTShot00Move:    ;standard move by however manieth.
  521. ;E=Y D=X
  522.  inc e \ inc d           ;modify for collision routine
  523.  ld ix,PBTShot00MoveCont ;return address for collision routine
  524.  jp SmallBulletCollision ;IN: DE=XY,
  525. PBTShot00MoveCont:
  526.  dec e \ dec d     ;unmodify from collision routine
  527.  ld a,-3           ;Move the Y direction up by 3 pixels
  528.  add a,e           ;
  529.  bit 7,a           ;
  530.  jp nz,PBTDestroy  ;But if it went above the top (carry), then kill the bullet
  531.  ld e,a            ;Else store the result back to E and wait for the push
  532.  push de           ;save result of movement
  533.  
  534. ;********************************
  535. ;If you needed to modify the counter, you will need the following code.
  536. ;AND DON'T FORGET TO PRESERVE BIT 7 OF L SINCE THAT IS THE FOCUSED FLAG.
  537.  dec sp \ pop hl   ;ENTER CODE
  538.  inc L
  539.  ld a,L
  540.  and %01111111
  541.  cp 10
  542.  jr nz,_
  543.  push hl \ inc sp  ;EXIT CODE
  544.  pop de            ;back to the way it was...
  545.  jp PBTDestroy     ;and get rid of the bullet.
  546. _:
  547.  push hl \ inc sp  ;EXIT CODE
  548. ;********************************
  549.  pop de            ;then advance SP so the bullet table handler can continue
  550.  jp PBTMainMoveRet ;stack unavailable
  551.  
  552.  
  553. SmallBulletCollision: ;E=Y D=X (bullet)
  554.  ld hl,$8E01 ;starting off with byte needed to see if anything is there
  555.  ld bc,$0A08 ;ten enemies, using C as a constant for adjustments
  556. SmallBulletCollisionLoop:
  557.  xor a
  558.  cp (hl)
  559.  jr z,SmallBulletCollisionSkip
  560.  inc L
  561.  inc L
  562.  inc L  ;position Y
  563.  ld a,(hl)
  564.  sub e   ;bY-eY. 10-12. Carry means no collide
  565.  jr nc,SmallBulletCollisionSkipY
  566.  add a,c
  567.  jr nc,SmallBulletCollisionSkipY
  568.  inc L
  569.  ld a,(hl) ;position X
  570.  sub d   ;same deal as above. Skipping comments.
  571.  jr nc,SmallBulletCollisionSkipX
  572.  add a,c    ;
  573.  jr nc,SmallBulletCollisionSkipX
  574. ;Collision happened. We may trash this bullet entry now via calling.
  575.  ld c,1  ;BASE WEAPON POWER
  576.  call DamageEnemy
  577.  jp PBTDestroy
  578. SmallBulletCollisionSkip:
  579.  ld a,20
  580.  jp _
  581. SmallBulletCollisionSkipY:
  582.  ld a,17
  583.  jp _
  584. SmallBulletCollisionSkipX:
  585.  ld a,16
  586. _:
  587.  add a,L
  588.  ld L,a
  589.  djnz SmallBulletCollisionLoop
  590. SmallBulletCollisionBossCheck:
  591.  
  592.  xor a
  593.  cp (hl)
  594.  jp z,SmallBulletCollideReturn
  595.  inc L
  596.  inc L
  597.  inc L  ;position Y
  598.  ld a,(hl)
  599.  sub e   ;bY-eY. 10-12. Carry means no collide
  600.  jp nc,SmallBulletCollideReturn
  601.  add a,c    ;(bY-eY)-8. (22-20)-8. Carry means CAN collide, else no collide
  602.  jp nc,SmallBulletCollideReturn
  603.  inc L
  604.  ld a,(hl) ;position X
  605.  sub d   ;same deal as above. Skipping comments.
  606.  jp nc,SmallBulletCollideReturn
  607.  add a,c    ;
  608.  jp nc,SmallBulletCollideReturn
  609.  ld c,1 ;BASE POWER
  610.  call DamageBoss
  611.  jp PBTDestroy
  612. SmallBulletCollideReturn;
  613.  jp (ix)
  614.  
  615. Add100ToScore:
  616.  ld a,8
  617.  ld (scoretime),a  ;resetting score timer
  618.  ld de,100
  619.  ld hl,(tempscore)
  620.  add hl,de
  621.  ld (tempscore),hl
  622.  ld e,0
  623.  ld hl,(tempscore+2)
  624.  adc hl,de
  625.  ld (tempscore+2),hl
  626.  ret
  627.  
  628. DamageBoss:
  629.  ld a,(charpower)
  630.  add a,c ;base power
  631.  ld hl,bossArmor
  632.  sub (hl)
  633.  jr nc,_
  634.  xor a   ;cannot pierce that armor.
  635. _:
  636.  ld c,a
  637.  ld b,0
  638.  ld hl,(bossHP)
  639.  sbc hl,bc
  640.  jr nc,_
  641.  ld hl,0  ;boss HP never go below 0. Check when script system is invoked
  642. _:
  643.  ld (bossHP),hl
  644.  jp Add100ToScore
  645.  
  646. DamageEnemy:
  647.  inc L
  648.  ld a,(hl) ;enemyHP
  649.  or a
  650.  jp z,Add100ToScore    ;skip trying to kill enemy. Enemy is invincible.
  651.  ld a,(charpower)
  652.  add a,c
  653.  ld c,a
  654.  ld a,(hl) ;curhp-dmg
  655.  sub c
  656.  ld (hl),a
  657.  jr z,$+4
  658.  jp nc,Add100ToScore   ;enemy still alive. Don't destruct
  659.  ld a,-5
  660.  add a,L
  661.  ld L,a
  662.  ld (hl),$00 ;remove enemy. Might want to make a fancy explosion. Not now.
  663.  jp Add100ToScore
Advertisement
Add Comment
Please, Sign In to add comment