Individual Bg Tile Collision with Sprites

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
mathe-matician
Posts: 14
Joined: Sat Aug 24, 2019 2:21 pm
Contact:

Individual Bg Tile Collision with Sprites

Post by mathe-matician » Sat Feb 22, 2020 10:05 am

I'm having trouble updating background tiles after chopping with the ax in my game.

I'm currently translating the background tile for where the player's ax is to check if it collides with a tree. I'm just hard coding the nametable address $21F0 where that tree tile is just to see how it would work. This updates this address to a blank tile, but since my player's collision routine looks at the original 32x30 buffer for collisions I can't move into that newly made blank space because it still thinks it is a tree (#$04). How can I update that specific tile number in the original background buffer?

Also, why doesn't

Code: Select all

LDA #$00
STA (S), Y 
update the value of that specific tile in the original buffer making this movement possible? Is it a similar problem kikutano has in the below forum?

I feel like I have all the pieces here from reading these articles that seem related to my issue: viewtopic.php?f=2&t=17482 and viewtopic.php?f=2&t=17392&start=30, but I can't seem to translate those discussions into a solution for my situation.

This is the code I run to check for the ax collision with the tree and to update the nametable tile.

Code: Select all

	
TileTranslate S, Q, playerax_r, playerax_r+3, background_lvl_1_1
	CMP #$04
	BNE chopdone

	LDA #$00
	STA (S), Y

	STA $2000
	STA $2001

	LDA $2002
	LDA #$21
	STA $2006
	LDA #$F0
	STA $2006

	LDA #$00
	STA $2007

	LDA #$00
	STA $2005
	STA $2005

	LDA #%10010000
	STA $2000

	LDA #%00011110
	STA $2001
	
	LDA #$03
	STA playerax_r+2

chopdone:
	RTS
The TileTranslate macro's code is from tokumaru's suggestion in this forum viewtopic.php?f=10&t=12995:

Code: Select all

	MACRO TileTranslate Reg1, Reg2, spritey, spritex, buffer
		LDA #$00
		STA Reg2
		LDA spritey
		AND #%11111000
		ASL
		ROL Reg2
		ASL
		ROL Reg2
		ADC #<buffer
		STA Reg1
		LDA Reg2
		ADC #>buffer
		STA Reg2
		LDA spritex
		LSR
		LSR
		LSR	
		TAY
		LDA (Reg1), Y
	ENDM
Feel free to poke around in the game attached. It is also worth noting I only have the right ax chop set up for this currently.
lumber_update16.nes
(24.02 KiB) Downloaded 47 times

mathe-matician
Posts: 14
Joined: Sat Aug 24, 2019 2:21 pm
Contact:

Re: Individual Bg Tile Collision with Sprites

Post by mathe-matician » Fri Feb 28, 2020 8:37 am

If it is helpful for the record, it is all starting to pull together in my brain.
Tokumaru's example here: viewtopic.php?f=2&t=17392&start=30 makes more sense.

I switched my 32x30 bg buffers to RLE and got it all to load properly. I'm going to apply this to the example above and hopefully my chopping problem days will be over :mrgreen:

Code: Select all

	;; put the map index (nametable address) in register A going into this
	LDA $2000
	;; multiply index by 2, since it is 16bit
	ASL
	TAY

	LDA lvl_1bg_ptr+0, y
	STA Pointer+0
	LDA lvl_1bg_ptr+1, y
	STA Pointer+1

	;; copy 1024 bytes from the location indicated by the pointer to VRAM
	LDA #$03
	STA BG256
	LDX #$00
	LDY #$00
CopyByte:
	LDA (Pointer), y
	TAX
	INY
CBLoop:	
	LDA (Pointer), y
	STA $2007
	DEX
	BNE CBLoop
	INY
	BNE CopyByte
	INC Pointer+1
	LDA BG256
	SEC
	SBC #$01
	STA BG256
	BNE CopyByte

Post Reply