MACRO change_all_tiles arg0, arg1, arg2
; arg0 = the tile type that you want to replace
; arg1 = metatile to change into (graphic)
; arg2 = collision to change into (tile type)
TILE_TO_REPLACE = arg0 ; the number collision type of your monster block.
LDX #$00
doReplaceTile:
LDA currentNametable
AND #%00000001
BEQ +isEvenCt
LDA #$24
STA temp1 ;; high byte of thing
;;; is odd col table.
LDA collisionTable2,x
CMP #TILE_TO_REPLACE
BEQ +isTileToReplace
JMP +notTileToReplace
+isTileToReplace
;; is tile_to_replace table.
LDA arg2
STA collisionTable2,x
JSR getTileToChange_forTileToReplace
JMP +doneWithTileUpdate
+isEvenCt
LDA #$20
STA temp1 ;; high byte of thing.
;;; is odd col table.
LDA collisionTable,x
CMP #TILE_TO_REPLACE
BEQ +isTileToReplace
JMP +notTileToReplace
+isTileToReplace
;; is tile_to_replace table.
LDA arg2
STA collisionTable,x
JSR getTileToChange_forTileToReplace
JMP +doneWithTileUpdate
getTileToChange_forTileToReplace:
TXA
STA temp
LSR
LSR
LSR
LSR
LSR
LSR
clc
ADC temp1
STA temp2 ;;;temp16+1
TXA
AND #%11110000
ASL
ASL
STA tempz
TXA
AND #%00001111
ASL
ORA tempz
STA temp3 ;temp16
;;; SET THE TILE NUMBER TO CHANGE TO.
LDA arg1 ;;arg1 ;; the tile to change.
;;; this is in tiles, so if you wanted the second "metatile",
;;; use 2, not 1. If you wanted the tile in the next row,
;;; use #$20, not #$10. Etc.
STA tempA
CLC
ADC #$01
STA tempB
CLC
ADC #$0F
STA tempC
CLC
ADC #$01
STA tempD
LDY #$00
LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
STA scrollUpdateRam,y
INY
LDA tempA
STA scrollUpdateRam,y
INY
LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
CLC
ADC #$01
STA scrollUpdateRam,y
INY
LDA tempB
STA scrollUpdateRam,y
INY
LDA temp3
CLC
ADC #$20
STA temp3
LDA temp2
ADC #$00
STA temp2
LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
STA scrollUpdateRam,y
INY
LDA tempC
STA scrollUpdateRam,y
INY
LDA temp2
STA scrollUpdateRam,y
INY
LDA temp3
CLC
ADC #$01
STA scrollUpdateRam,y
INY
LDA tempD
STA scrollUpdateRam,y
INY
TYA
STA maxScrollOffsetCounter
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Turn on update screen on next frame.
LDA updateScreenData
ORA #%0000100
STA updateScreenData
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RTS
+doneWithTileUpdate
JSR doWaitFrame
+notTileToReplace
INX
CPX #240
BEQ +skip ;; done
PlaySound #sfx_powerup
;;loop back !
JMP doReplaceTile ;; last tile_to_replace.
+skip
ENDM