I am building my first 'game' with a map with single screen rooms. As I've leaned more and more I've done changes to my code to make it as efficient as possible, given my very basic knowlege.
Currently my game world concists of multiple layers of indirect addressing. It is probably considered bad practice, but I can't come up with a better way to structure my data and still keep the map size down in the ROM.
The layout is as follows:
All screens are stored as data words, referring to 17 bytes arrays (byte 16 for attributes stored as words referring to arrays) which in turn are referring data words referring to arrays containing the meta tiles.
Everything works just fine, since the pointers are only loaded at screen transitions, but given the discussions abouts structs and arrays I would need some advice on how to make the code better (since I suspect you guys shiver when you see the example below).
Thanks in advance.
Code: Select all
WorldData: ;contains all screens in the game. Screens can be reused
.dw StartScreen, Restaurant, Pawnshop, Town1, Town1 ; ...
;Arrays containing the meta tile columns
StartScreen:
.db $00,$01,$02,$01,$00,$02,$00,$01,$02,$01,$00,$02,$00,$01,$02,$01, $00
Restaurant:
.db $00,$01,$02,$05,$06,$07,$06,$07,$06,$07,$06,$08,$09,$0A,$02,$00, $04
Town1:
.db $00,$01,$00,$01,$00,$01,$00,$01,$00,$01,$00,$01,$00,$01,$00,$01, $00
Pawnshop:
.db $00,$01,$02,$05,$06,$07,$06,$08,$09,$0A,$06,$07,$06,$05,$02,$00, $01
MetaTileDefinitions: ;Words referring to the actual meta tile arrays
.dw CityTile1, CityTile2, CityTile3, CityTile4, CityTile5, HouseTileL, HouseTileWin, HouseTileWall, DoorTileL, DoorTileM, DoorTileR
;Arrays containing the actual tiles
CityTile1:
.db $27,$27,$27,$27,$27,$27,$37,$37,$37,$37,$36,$34,$36,$34,$32,$32,$32,$32,$32,$32,$32
.db $27,$27,$27,$27,$27,$3E,$3E,$3E,$3E,$3E,$36,$34,$36,$34,$32,$32,$32,$32,$32,$32,$32
CityTile2:
.db $27,$27,$27,$27,$27,$3E,$3E,$3E,$36,$34,$36,$34,$32,$32,$32,$32,$32,$32,$32,$32,$32
.db $27,$27,$27,$27,$27,$27,$27,$3E,$36,$34,$36,$34,$32,$32,$32,$32,$32,$32,$32,$32,$32
CityTile3:
.db $27,$27,$27,$43,$42,$37,$37,$35,$36,$34,$45,$47,$49,$4B,$4B,$4B,$4D,$4F,$A5,$32,$32
.db $27,$27,$27,$27,$27,$27,$3E,$3E,$3E,$3E,$44,$46,$48,$4A,$4A,$4A,$4C,$4E,$A5,$32,$32
;...