Howdy. This might be a trivial problem, but I wanted to bounce some ideas off you guys.
In my game I have levels and sublevels, numbered in a scheme similar to SMB: 1-1, 1-2, 1-3, 2-1, 2-2, 2-3, 3-1, etc. I'm looking for input on how I should handle the numbering under the hood, considering that levels start from 1, but tables index from 0.
For the record, I use the level number as an index into a table of pointers to level data. The level data itself contains pointers to sublevel data.
I thought of a few solutions:
1) store level # in RAM as-is (ie, level 1 is #$01), and subtract one before indexing into tables
2) store level # in RAM as level-1 (ie, level 1 is #$00), and add one when displaying on the screen
3) store level # in RAM as-is (level1 = #$01), put dummy entries at the beginning of tables.
4) store level # in RAM as-is, and offset the start of the table:
5) create a level 0 and use it as a bonus level or a demo level.
I don't really like solutions 1, 2 or 3 because they seem wasteful. Plus I potentially have a hard-to-find bug if I forget to make the adjustment somewhere. To me #2 seems the lesser of three evils.
Solution 4 isn't wasteful because the adjustment is made by the assembler, but it's still prone to bugs if I forget to offset a table somewhere.
Solution 5 works for levels, but not sublevels.
Any other ideas? How do commercial games usually handle this?
In my game I have levels and sublevels, numbered in a scheme similar to SMB: 1-1, 1-2, 1-3, 2-1, 2-2, 2-3, 3-1, etc. I'm looking for input on how I should handle the numbering under the hood, considering that levels start from 1, but tables index from 0.
For the record, I use the level number as an index into a table of pointers to level data. The level data itself contains pointers to sublevel data.
I thought of a few solutions:
1) store level # in RAM as-is (ie, level 1 is #$01), and subtract one before indexing into tables
2) store level # in RAM as level-1 (ie, level 1 is #$00), and add one when displaying on the screen
3) store level # in RAM as-is (level1 = #$01), put dummy entries at the beginning of tables.
4) store level # in RAM as-is, and offset the start of the table:
Code:
level_table:
.word level1, level2, level3 ;pointers to level data
;--in level load routine
lda level
asl
tay
lda level_table-2, y ;offset table by 2
;blah blah blah
.word level1, level2, level3 ;pointers to level data
;--in level load routine
lda level
asl
tay
lda level_table-2, y ;offset table by 2
;blah blah blah
5) create a level 0 and use it as a bonus level or a demo level.
I don't really like solutions 1, 2 or 3 because they seem wasteful. Plus I potentially have a hard-to-find bug if I forget to make the adjustment somewhere. To me #2 seems the lesser of three evils.
Solution 4 isn't wasteful because the adjustment is made by the assembler, but it's still prone to bugs if I forget to offset a table somewhere.
Solution 5 works for levels, but not sublevels.
Any other ideas? How do commercial games usually handle this?