Page 1 of 1

Tutorial/Code for collision &/or scrolling

Posted: Thu Feb 18, 2010 5:23 pm
by bigjt_2
Hello again, everyone.

Does anyone know of any tutorials or code examples for:

1. Sprite collision detection?

and not as necessary for me right now, but I'll take it if someone has it...

2. Horizontal scrolling using just NROM?

Regarding collision detection, I understand the basic principle of this but am very new to assembly and some example code of someone successfully implementing it would be tremendously useful. A tutorial would be even more awesome if one exists.

Regarding scrolling, I'm reading Deskin's NES doc and Loopy's two text files describing the write process to $2006 but for whatever reason it's just not clicking with me. I understand what happens from watching the name table in fce ultra xd and understand that it gradually offsets from the starting address of $2000. Again, mostly I just don't get how you would code it.

So far I've put together a couple simple experiments where I filled in a nametable and made a group of mario sprites move. This was done reading bunnyboy's docs. I can't seem to find any tutorials from him or anyone else on my above two questions, though. Also, I have done my best to sweep this forum and make sure I'm not wasting space by posting something similar to another post, but haven't found a post like this. If I've missed a post with a similar question that's been answered please point me that way.

Thanks again for your time and help, folks.

Re: Tutorial/Code for collision &/or scrolling

Posted: Thu Feb 18, 2010 6:22 pm
by tepples
bigjt_2 wrote:2. Horizontal scrolling using just NROM?
The commented disassembly of Super Mario Bros. is probably the most complete example of a horizontal scroller. Look for it on romhacking.net.
Regarding scrolling, I'm reading Deskin's NES doc and Loopy's two text files describing the write process to $2006 but for whatever reason it's just not clicking with me.
You don't have to worry about using $2006 for scrolling unless you're trying to A. split the screen to make a status bar, or B. turn rendering on late to make more time for VRAM updates. Most of the time you can get away with two writes to $2005 and one to $2000.

Re: Tutorial/Code for collision &/or scrolling

Posted: Thu Feb 18, 2010 7:04 pm
by tokumaru
tepples wrote:You don't have to worry about using $2006 for scrolling unless you're trying to A. split the screen to make a status bar, or B. turn rendering on late to make more time for VRAM updates. Most of the time you can get away with two writes to $2005 and one to $2000.
Man, we gotta write that in huge blinking letters on the wiki, here, and anywhere else we can think of. EVERYONE seems to think they have to use $2006 for scrolling.

About sprite collision, this is something that's not specific to the NES, it's common game programming knowledge. Check the net for "bounding box collision" and you'll find pages like this.

About scrolling, the basic concept is that you draw new portions of the level map as the camera scrolls to display them. Whenever the camera moves (usually it moves to follow the main character) you have to check in which direction it moved and make sure that the portion of the name tables that it's about to display contain the correct representation of the level. This involves using a routine that can read columns (when scrolling horizontally) and/or rows (when scrolling vertically) of blocks from your level map and buffering the data they return so that it can be written to VRAM during VBlank.