Romano338

Boomerang Bro

Jul 30th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.47 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;; Boomerang Brother, by mikeyk
  3. ;;
  4. ;; Description: Similar to his role in SMB3, this guy throws boomerangs at Mario.
  5. ;;
  6. ;; BIG FAT NOTE: This sprite depends on the boomerang sprite. Make sure you insert the
  7. ;; boomerang as the very next sprite. (ex. If this is sprite 1B, make the boomerang 1C)
  8. ;;
  9. ;; Uses first extra bit: NO
  10. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  11.  
  12.  
  13.  
  14. ;Graphical Properties for the tile the bro is holding up before throwing it
  15. !Throw_Tile = $4E
  16. !Throw_Prop = $83
  17. !Throw_XOff = $0A
  18.  
  19.  
  20.  
  21.  
  22. !JUMP_TIMER = !163E ;Decrements itself per frame!!!!
  23. !RAM_ThrowTimer = !1504 ;DOESN'T decrement itself!!!!!!!
  24.  
  25.  
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ; Routine that spawns the sprite to be thrown
  28. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  29.  
  30. SpawnThrowSprite:
  31. LDA !157C,x
  32. TAY
  33. LDA Throw_Offset,y
  34. STA $00
  35. LDA #$F2
  36. STA $01
  37. STZ $02
  38. STZ $03
  39.  
  40. LDA !new_sprite_num,x ; \ sprite number is this' number +1
  41. INC ; /
  42. SEC ; set spawn to be custom sprite
  43. %SpawnSprite() ; spawn sprite
  44. BCS + ; return if failed
  45.  
  46. LDA !157C,x ; \ same direction as bro is facing.
  47. STA !157C,y ; /
  48. LDA #$4E ; \ set timer until change direction
  49. STA !1540,y ; /
  50.  
  51. + RTS
  52.  
  53.  
  54. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  55. ; sprite data
  56. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  57.  
  58. ;16x16 body tile, 8x8 foot tile 1, 8x8 foot tile 2, dummy
  59. TILEMAP: db $46,$4A,$7F,$00 ;walking 1
  60. db $46,$5A,$2F,$00 ;walking 2
  61. db $48,$4A,$7F,$00 ;throwing 1
  62. db $48,$5A,$2F,$00 ;throwing 2
  63.  
  64. HORZ_DISP: db $00,$00,$08 ;facing left
  65. db $00,$08,$00 ;facing right
  66. VERT_DISP: db $F8,$08,$08
  67. TILE_SIZE: db $02,$00,$00
  68.  
  69. PROPERTIES: db $40,$00 ;xyppccct format
  70.  
  71.  
  72. Throw_Offset: db $100-!Throw_XOff,!Throw_XOff
  73.  
  74. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  75. ; init JSL
  76. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  77.  
  78. print "INIT ",pc
  79. %SubHorzPos()
  80. TYA
  81. STA !157C,x
  82.  
  83. TXA ; \ use sprite index as base for a touch of randomness
  84. AND #$03 ; |
  85. ASL #5 ; |
  86. STA !JUMP_TIMER,x ; / jump timer randomly $00, $20, $40, $60
  87. CLC
  88. ADC #$32
  89. STA !RAM_ThrowTimer,x
  90.  
  91. RTL
  92.  
  93. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  94. ; main sprite JSL
  95. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  96.  
  97. print "MAIN ",pc
  98. PHB ; \
  99. PHK ; | main sprite function, just calls local subroutine
  100. PLB ; |
  101. JSR START_HB_CODE ; |
  102. PLB ; |
  103. RTL ; /
  104.  
  105. DecTimers:
  106. LDA !RAM_ThrowTimer,x
  107. BEQ .done
  108. DEC !RAM_ThrowTimer,x
  109. .done:
  110. RTS
  111.  
  112. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  113. ; main sprite routine
  114. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  115.  
  116. ;indexed by 151C
  117. X_SPEED: db $00,$F8,$00,$08 ;rest at bottom, moving up, rest at top, moving down
  118. TIME_IN_POS: db $48,$10,$48,$10 ;moving up, rest at top, moving down, rest at bottom
  119.  
  120. ;indexed by C2
  121. TIME_TILL_THROW: db $F7,$62
  122.  
  123. ;STAR: INC !RAM_ThrowTimer,x
  124.  
  125. Return:
  126. RTS
  127. START_HB_CODE:
  128.  
  129. JSR SUB_GFX ; draw hammer bro gfx
  130. LDA !14C8,x ; \ if hammer bro status != 8...
  131. ;CMP #$02 ; } ... not (killed with spin jump [4] or STAR[2])
  132. ;BEQ STAR
  133. CMP #$08
  134. BNE Return ; / ... RETURN
  135. LDA $9D ; \ if sprites locked...
  136. BNE Return ; / return
  137.  
  138. JSR DecTimers ; decrement timers (that aren't self decrementing)
  139.  
  140. LDA #$00 ; sub_off_screen_x0
  141. %SubOffScreen() ; only process hammer bro while on screen
  142.  
  143. %SubHorzPos() ; \ always face mario
  144. TYA ; |
  145. STA !157C,x ; /
  146.  
  147. ;1570 = on screen frame counter
  148. ;151C = speed phase
  149. ; 00 = stand still
  150. ; 01 = move back
  151. ; 02 = stand still
  152. ; 03 = move forward
  153. ;1602 = animation display frame counter
  154.  
  155. INC !1570,x ; increment number of frames hammer bro has been on screen
  156.  
  157. ;Code to handle the "base" animation frame to display
  158. ;$1602 will be either 0 or 1, throwing code may offset it by 2.
  159. LDA !151C,x ; \
  160. AND #$01 ; | skip if we're in a "stant still" phase
  161. BEQ + ; /
  162.  
  163. LDA !1570,x ; \ calculate which frame to show:
  164. LSR #3 ; |
  165. AND #$01 ; | update every 16 cycles if normal
  166. BRA ++ ; / skip ahead and just store
  167.  
  168. + LDA !151C,x ; \ if in "stand still phase 0", set frame to 0
  169. BEQ ++ ; |
  170. LDA #$01 ; | if in "stand still phase 2", set frame to 1
  171. ++ STA !1602,x ; / write frame to show
  172.  
  173. ;Code to handle the throw timer
  174. LDA !RAM_ThrowTimer,x ; \
  175. CMP #$22 ; | Check throw timer
  176. BCS Jumping ; | skip if it's more than the limit already
  177. INC !1602,x ; | if not, move animation frame into the "throwing" range.
  178. INC !1602,x ; /
  179.  
  180. LDA !RAM_ThrowTimer,x ; \
  181. BNE + ; | if it's not time to throw yet, skip over stuff
  182. LDY !C2,x ; | set throw timer again (depending on $C2)
  183. LDA TIME_TILL_THROW,y ; |
  184. STA !RAM_ThrowTimer,x ; /
  185. + CMP #$01 ; \
  186. BNE Jumping ; | when timer = 1
  187. LDA !C2,x ; | invert $C2 for next reset of timer
  188. EOR #$01 ; | and spawn the sprite
  189. STA !C2,x ; | if not, skip ahead.
  190. JSR SpawnThrowSprite ; /
  191.  
  192. ;Code to handle the jumping part.
  193. Jumping:
  194. LDA !JUMP_TIMER,x ; \ if timer still above $28
  195. CMP #$28 ; | just go to normal walking code
  196. BCS Speed ; /
  197. LDA !JUMP_TIMER,x ; \
  198. CMP #$21 ; | if timer is $21, do jump
  199. BNE .reset ; / if not, do skip
  200. LDA !1570,x ; \
  201. LSR A ; |
  202. AND #01 ; |
  203. BEQ .reset ; /
  204. LDA #$D0 ; \ set y speed
  205. STA !AA,x ; | and just move to updating speeds
  206. BRA Speed_apply ; /
  207.  
  208. .reset
  209. CMP #$00 ; \
  210. BNE Speed ; | check if it's time to reset the jump timer
  211. LDA #$FE ; | and do if so.
  212. STA !JUMP_TIMER,x ; /
  213.  
  214. ;Code to handle the sprite's back and forth movement.
  215. Speed:
  216. LDA !151C,x ; \ speed phase in Y
  217. TAY ; /
  218. LDA !1540,x ; \ change speed phase and reset timer if timer is up.
  219. BEQ .change ; /
  220. LDA X_SPEED,y ; \ set x speed based on phase.
  221. STA !B6,x ; /
  222. BRA .apply
  223.  
  224. .change
  225. LDA TIME_IN_POS,y ; \
  226. STA !1540,x ; | set turning timer (decrements itself)
  227. LDA !151C,x ; |
  228. INC A ; | and increment the speed phase.
  229. AND #$03 ; |
  230. STA !151C,x ; /
  231. .apply
  232. JSL $01802A ; update position based on speed values
  233.  
  234.  
  235. LDA !1588,x ; \ if hammer bro is not touching the side of an object...
  236. AND #$03 ; | skip ahead
  237. BEQ + ; /
  238. LDA !151C,x ; \
  239. INC A ; | if he is, move to next speed phase.
  240. AND #$03 ; |
  241. STA !151C,x ; /
  242. +
  243.  
  244. ;Code to handle basic contact routine
  245. JSL $018032 ; interact with other sprites
  246. JSL $01A7DC ; check for mario/hammer bro contact
  247. RTS
  248.  
  249.  
  250.  
  251. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  252. ; graphics routine
  253. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  254.  
  255. SUB_GFX:
  256. %GetDrawInfo() ; after: Y = index to sprite tile map ($300)
  257. ; $00 = sprite x position relative to screen boarder
  258. ; $01 = sprite y position relative to screen boarder
  259. sublabel:
  260. LDA !1602,x ; \
  261. ASL #2 ; | $03 = index to frame start (frame to show * 2 tile per frame)
  262. STA $03 ; /
  263. LDA !157C,x ; \ $02 = sprite direction
  264. STA $02 ; /
  265. PHX ; push sprite index
  266.  
  267. LDX #$02 ; loop counter = (number of tiles) - 1
  268. .loop
  269. PHX ; push current tile number
  270.  
  271. TXA ; \ put tile number in A
  272. LDX $02 ; |
  273. BNE + ; | and if sprite faces left, add 3
  274. CLC ; | and put it back in X
  275. ADC #$03 ; |
  276. + TAX ; /
  277. LDA $00 ; \ tile x position + offset depending on direction
  278. CLC : ADC HORZ_DISP,x ; |
  279. STA $0300|!Base2,y ; /
  280.  
  281. PLX ; get tile number back in X
  282.  
  283. LDA $01 ; \ tile y position = sprite y location ($01) + tile displacement
  284. CLC ; |
  285. ADC VERT_DISP,x ; |
  286. STA $0301|!Base2,y ; /
  287.  
  288. LDA TILE_SIZE,x ; get size for current tile
  289. PHX ; \ preserve A (tile size) and X (tile number)
  290. PHA ; /
  291. TYA ; \ get index to sprite property map ($460)...
  292. LSR A ; | ...we use the sprite OAM index...
  293. LSR A ; | ...and divide by 4 OAM has 4 bytes per slot and this only 1.
  294. TAX ; |
  295. PLA ; | store tile size (2 = 16x16, 0 = 8x8)
  296. STA $0460|!Base2,x ; /
  297. PLX ; restore tile number
  298.  
  299. PHX ; save tile number again
  300. TXA ; \ X = index to horizontal displacement
  301. ORA $03 ; | get index of tile (index to first tile of frame + current tile number)
  302. TAX ; /
  303.  
  304. LDA TILEMAP,x ; \ store tile
  305. STA $0302|!Base2,y ; /
  306.  
  307. LDX $02 ; \
  308. LDA PROPERTIES,x ; | get tile PROPERTIES using sprite direction
  309. LDX $15E9|!Base2 ; |
  310. ORA !15F6,x ; | get palette info
  311. ORA $64 ; | put in level PROPERTIES
  312. STA $0303|!Base2,y ; / store tile PROPERTIES
  313.  
  314. PLX ; \ pull, X = current tile of the frame we're drawing
  315. INY ; | increase index to sprite tile map ($300)...
  316. INY ; | ...we wrote 1 16x16 tile...
  317. INY ; | ...sprite OAM is 8x8...
  318. INY ; | ...so increment 4 times
  319. DEX ; | go to next tile of frame and loop
  320. BPL .loop ; /
  321.  
  322. PLX ; pull, X = sprite index
  323.  
  324. LDA !RAM_ThrowTimer,x
  325. CMP #$02
  326. BCC .DontShowTTile
  327. CMP #30
  328. BCS .DontShowTTile
  329. LDA !1602,x
  330. CMP #$02
  331. BCS .ShowThrowTile
  332.  
  333. .DontShowTTile
  334. LDY #$FF ; \ 02, because we didn't write to 460 yet
  335. LDA #$02 ; | A = number of tiles drawn - 1
  336. JSL $01B7B3 ; / don't draw if offscreen
  337. RTS ; RETURN
  338.  
  339. .ShowThrowTile
  340. PHX ; preserve sprite index
  341.  
  342. LDA $00 ; \
  343. LDX $02 ; | x position + offset (depending on sprite direction)
  344. CLC : ADC Throw_Offset,x; |
  345. STA $0300|!Base2,y ; /
  346.  
  347. LDA $01 ; \
  348. CLC : ADC #$F2 ; | y position + offset
  349. STA $0301|!Base2,y ; /
  350.  
  351. LDA #!Throw_Tile ; \ store tile
  352. STA $0302|!Base2,y ; /
  353.  
  354. TYA ; \ get index to sprite property map ($460)...
  355. LSR A ; | ...we use the sprite OAM index...
  356. LSR A ; | ...and divide by 4 OAM has 4 bytes per slot and this only 1.
  357. TAX ; |
  358. LDA #$02 ; | store tile size (2 = 16x16, 0 = 8x8)
  359. STA $0460|!Base2,x ; /
  360.  
  361. LDA #!Throw_Prop ; \ load throw tile properties.
  362. BIT $02 ; | depending on sprite direction...
  363. BEQ + ; | ... add x-flip bit to properties
  364. ORA #$40 ; |
  365. + ORA $64 ; | put in level properties
  366. STA $0303|!Base2,y ; / store tile properties
  367.  
  368. PLX ; retore sprite index
  369.  
  370. LDY #$FF ; \
  371. LDA #$03 ; | A = number of tiles drawn - 1
  372. JSL $01B7B3 ; / don't draw if offscreen
  373. RTS ; RETURN
Add Comment
Please, Sign In to add comment