Code: Select all

```
CheckCollide:
TXA
; ADC scroll
STA collideX
LSR
LSR
LSR
LSR ; divide x by 16 to get into metatile space
STA tempX
TYA
STA collideY
LSR
LSR
LSR
LSR ; divide y by 16 to get into metatile space
ASL
ASL
ASL
ASL ; multiply y by 16 to change rows of level table
STA tempY
LDA tempX
ADC tempY ; X/16 + (Y/16)*16
TAX
LDA (Level1), x ; load what current metatile you are in
STA currentMetatile
CheckCurrentTile:
LDA collideX
AND #%00001111
LSR
LSR
LSR ; divide by 8
ADC #$01
STA metatileX ; find out if player in right or left of metatile
LDA collideY
AND #$00001111
LSR
LSR
LSR ; divide by 8
ADC #$01
ASL
ASL ; multiply by 4
STA metatileY ; find out if player in top or bottom of metatile
; 0 0 0 0 0 0 0 0
; | | | |_ X
; | | |___ X
; | |_____ Y
; |_______ Y
CLC
LDA metatileX
ADC metatileY
STA metatileCorner ; calculate what corner the player is in
LDA metatileCorner
AND #%00000101 ; x = 01, y = 01
BEQ +
JMP TopLeft
+
LDA metatileCorner
AND #%00000110 ; x = 10, y = 01
BEQ +
JMP TopRight
+
LDA metatileCorner
AND #%00001001 ; x = 01, y = 10
BEQ +
JMP BottomLeft
+
JMP BottomRight ; x = 10, y = 10
TopRight:
LDX currentMetatile
LDA (CastleTR), x ; find out what block type player is on
TAX
LDA (TileProperties), x
AND #%00000001 ; only check tile collision
RTS
TopLeft:
LDX currentMetatile
LDA (CastleTL), x ; find out what block type player is on
TAX
LDA (TileProperties), x
AND #%00000001 ; only check tile collision
RTS
BottomRight:
LDX currentMetatile
LDA (CastleBR), x ; find out what block type player is on
TAX
LDA (TileProperties), x
AND #%00000001 ; only check tile collision
RTS
BottomLeft:
LDX currentMetatile
LDA (CastleBL), x ; find out what block type player is on
TAX
LDA (TileProperties), x
AND %00000001 ; only check tile collision
RTS
```

Code: Select all

```
;===================================Meta Tiles===============================================
CastleTL: .db $00, $00, $00, $00, $07, $07, $07, $07
CastleTR: .db $00, $07, $07, $00, $07, $07, $07, $07
CastleBL: .db $00, $00, $00, $07, $00, $07, $07, $07
CastleBR: .db $00, $07, $00, $07, $00, $07, $07, $07
;==================================Tile Properties===========================================
;0 0 0 0 0 0 0 0
;| | | | | | | |_ Collidable
;| | | | | | |___ One Way Platform
;| | | | | |_____ Ladder
;| | | | |_______ Kills
;| | | |_________ Slippery
;| | |___________ ?
;| |_____________ ?
;|_______________ ?
TileProperties:
.db %00000001, %00000000, %00000100, %00000000 ; $00 to $1F
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
.db %00000000, %00000000, %00000000, %00000000
etc. etc.
```