The way i'm doing it is on my code there's a label which points to the name table used on my game like so:

Code: Select all

```
nameTable:
.incbin "mapa.nam"
.byte $FF ; The nametable does not have byte $FF, just a way to know when
; it should stop reading data, think of it as a \0 on a C-string.
```

Code: Select all

```
LDA $0203
LSR A
LSR A
LSR A
TAX
LDA $0200
LSR A
LSR A
LSR A
TAY
```

Then to finally finish it all of i would do x + y * 32 (32 being the size of a whole line of tiles on one screen), since there's no multiplying instruction for the 6502, i had to improvise a little:

Code: Select all

```
LDA #<nameTable
STA playerTileLow
LDA #>nameTable
STA playerTileHigh
LoopY:
CLC
LDA playerTileLow
ADC #$20
STA playerTileLow
LDA playerTileHigh
ADC #$00
STA playerTileHigh
DEY
BNE LoopY
LoopX:
CLC
LDA playerTileLow
ADC #$01
STA playerTileLow
LDA playerTileHigh
ADC #$00
STA playerTileHigh
DEX
BNE LoopX
```

Code: Select all

```
;This is just for checking collision on the right side of the sprite, but it's basically the same for the remaining directions
;Also, X is 0 here
LDY #$02
LDA (playerTileLow), y
CMP #$24
BEQ @didntColideRight
STX canColideRight
JMP @EndRight
@didntColideRight:
LDY #$22
LDA (playerTileLow), y
CMP #$24
BEQ @didntColideRight2
STX canColideRight
@didntColideRight2:
```

I think it is because of the way i did the indexing (x+y*32), does somebody know a possible reason for this? Or maybe a better way to handle collision on the NES?

Edit

Movement code when moving right:

Code: Select all

```
LDA control
AND #%00000001
BEQ endRight
LDA canColideRigt
CMP #$01
BEQ @dontNeedToCheckColision
LDA $020b
AND #%00000111 ; Stop only when right side of the sprite will hit something
BEQ endRight
@dontNeedToCheckColision:
LDX #$00
@LoopSprites:
INC $0203, x
INX
INX
INX
INX
CPX #$10
BNE @LoopSprites
endRight:
```