Language…
7 users online: HaruMKT, Isikoro, krizeth, monkey03297,  Nanako, playagmes169, qantuum - Guests: 254 - Bots: 319
Users: 64,795 (2,376 active)
Latest user: mathew

Help with sprite/object interaction [Resolved]

I don't know if this is the right place to post this but whatever, here goes. Basically I want to know how to make sprites interact with objects. Is there an easy way to check what block/object a sprite is touching? How would I make a custom block react to a specific sprite? There are a lot of good tutorials around here for coding sprites, but I have yet to see anything beyond the most basic in terms of block tuts. I would very much appreciate if someone could point me in the right direction.

Thanks in advance!

allow shy guy emojis in post footers you cowards!


Originally posted by Von Fahrenheit
I don't know if this is the right place to post this but whatever, here goes. Basically I want to know how to make sprites interact with objects. Is there an easy way to check what block/object a sprite is touching? How would I make a custom block react to a specific sprite? There are a lot of good tutorials around here for coding sprites, but I have yet to see anything beyond the most basic in terms of block tuts. I would very much appreciate if someone could point me in the right direction.

Thanks in advance!


For the sprite-object interaction code, I think this routine could help. For block - sprite interaction, via blocks, you could do something like this (assuming SpriteH offset being used):
Code
!Sprite = $1C		; Assume a Bullet Bill

SpriteH:
	LDX #$0C	; Index Loop.
.Loop
	LDA $9E,x	; $7FAB9E,x if it's a custom sprite
	CMP #!Sprite
	BEQ FoundSprite
	DEX
	BPL .Loop
	RTL

FoundSprite:
	; Your block-sprite interaction here.
 	; X holds the current sprite being processed, so be careful when using it for another purpose.
 	; I recommend you use Y for tables here.
	; Anyways, you can do whatever you like here - shatter the block, kill the sprite, and so on.
	RTL
	






Dream team (feed them, please):






I think I've seen that exact code before, but wouldn't that just run the interaction code no matter what sprite touches the block? I mean you check all the sprites and whatnot, but how would I know that the bullet bill (in this case) is the sprite that touches the block and not just some random koopa or something?

Edit: Basically wouldn't it run if there exists a bullet bill on screen and ANY sprite touches the block?

Edit 2: Thanks for the routine btw.

allow shy guy emojis in post footers you cowards!
Yeah, that's correct. What you want to instead is just this:

Code
!Sprite = $1C		; Assume a Bullet Bill

SpriteH:
	LDA $9E,x	; $7FAB9E,x if it's a custom sprite
	CMP #!Sprite
	BEQ CorrectSprite
	RTL

CorrectSprite:
	; stuff
	RTL

The index of the sprite touching the block is already in the X register, so there's no point in looping over all sprites.

On another note, this will only work for sprites that interact with blocks, so the Bullet Bill example wouldn't actually work.
My YouTube channel
Get the official ASMT resource pack here!

Bullit bills are exceptions because it doesn't interact with blocks. Instead, use a disassembly of it, put this code somewhere into the sprite, preferably at the end of it, call the routine where the bullet bill is running at every frame except if the sprites are locked (e.g. line 90 if word wrap isn't activated) and after "JSR *whateveryoucalledit*, put this code:
Code
LDA [$05]
XBA
INC $07
LDA [$05]
XBA
REP #$20
CMP #$xxxx
BNE NotTheRightMap16Number
; your code
NotTheRightMap16Number:
SEP #$20


Fadit: YCZ was faster...
Ok, thanks guys, really appreciate it!

allow shy guy emojis in post footers you cowards!