Hello all, first post here and very new to 6502 and NES development, however I am very familiar with C, C++, and game development in general (also very excited about working with the NES).
I have background tiles filling my screen, and I want to do a lookup during player movement to determine if my character sprite will be running into my "wall" tiles (controls are working fine). This is from a top-down perspective.
Using C/C++ (and with more memory resources of course : ) I would just have a matrix or long single dimensional array, divide my player x/y, and use that as my lookup to check a value.
e.g,
However I'm struggling with 8-bit limits.
Problem 1.
I'm loading my background in using 256 byte chunks, and have a loop for each chunk. The last chunk is of course less than 256 bytes. This works, but seems like it will make lookups very confusing, because I would need to know which chunk to start reading from. If I am able to somehow load all my background data in one chunk with some loop magic, this would possibly make the lookup easier (and background loading logic), but then I'm faced with problem number 2..
Problem 2.
How can I do a lookup when my matrix/array can be up to 960 bytes? (32 x 30 tiles) If my character is at screen location 200 152, my lookup index would be:
That value is beyond what I can fit into one byte.
In 6502 are there tricks to keep things as simple as possible or would I need to somehow work with "chunks" of data at a time? I'm curious how others solve this problem when working with datasets larger than 256 bytes.
I have background tiles filling my screen, and I want to do a lookup during player movement to determine if my character sprite will be running into my "wall" tiles (controls are working fine). This is from a top-down perspective.
Using C/C++ (and with more memory resources of course : ) I would just have a matrix or long single dimensional array, divide my player x/y, and use that as my lookup to check a value.
e.g,
Code:
myMatrix[y * MAP_WIDTH + x] // for single dimension.
However I'm struggling with 8-bit limits.
Problem 1.
I'm loading my background in using 256 byte chunks, and have a loop for each chunk. The last chunk is of course less than 256 bytes. This works, but seems like it will make lookups very confusing, because I would need to know which chunk to start reading from. If I am able to somehow load all my background data in one chunk with some loop magic, this would possibly make the lookup easier (and background loading logic), but then I'm faced with problem number 2..
Problem 2.
How can I do a lookup when my matrix/array can be up to 960 bytes? (32 x 30 tiles) If my character is at screen location 200 152, my lookup index would be:
Code:
pseudocode:
mapX = 200 / 8 (or 25)
mapY = 152 / 8 (or 19)
; here MAP_WIDTH is 32 (for each tile going across)
mapIndex = mapY * MAP_WIDTH + mapX (or 633)
mapX = 200 / 8 (or 25)
mapY = 152 / 8 (or 19)
; here MAP_WIDTH is 32 (for each tile going across)
mapIndex = mapY * MAP_WIDTH + mapX (or 633)
That value is beyond what I can fit into one byte.
In 6502 are there tricks to keep things as simple as possible or would I need to somehow work with "chunks" of data at a time? I'm curious how others solve this problem when working with datasets larger than 256 bytes.