Originally posted by: JKeefe56
I hate to ask something like this, because I feel like it's asking too much. But I'm working on a puzzle game. I can make a level of it, but then I get stuck. Is there anyone willing to write out a code to show me, that would do something like this, just so I can see how it is done?
Just load a background screen and then when a certain button is pressed it loads the next background?
I've gotten stuck here a few times. Or if there's a NN that covers this that I missed, could you point me in that direction?
LoadNametable:
LDA $2002 ;normal loading routine
LDA #$20
STA $2006
LDA #$00
STA $2006
SetNametable:
LDA BG_ptr ;BG_ptr is a variable in your zero page which tells the game
ASL A ;which level you're on. Everytime you beat a level, increment this.
TAY
LDA bkgd_pointer_table, y ;pointer table which takes the BG_ptr variable and
STA AddrLow ;tells it which level data to load.
LDA bkgd_pointer_table+1, y
STA AddrHigh
LDX #$04
LDY #$00
LoadBackgroundsLoop:
LDA [AddrLow], y ;load nametable
STA $2007 ;draw tile
INY ;X is 0, so move on to get new counter number
BNE LoadBackgroundsLoop
;;Outer Loop
INC AddrHigh
DEX
BNE LoadBackgroundsLoop
RTS
bkgd_pointer_table: ;;table of addresses for backgrounds. if BG_ptr is #$00, it will
;;load the first one. #$01, the second. etc
.dw gamebkgd0 ;;level 0 background
.dw gamebkgd1 ;;level 1 background
.dw gamebkgd2 ;;level 2 background
.dw gamebkgd3 ;;level 3 background
.dw gamebkgd4 ;;level 4 background
.dw gamebkgd5 ;;level 5 background
.dw gamebkgd6 ;;level 6 background
.dw gamebkgd7 ;;level 7 background
.dw gamebkgd8 ;;level 8 background
.dw gamebkgd9 ;;level 9 background
.dw gamebkgd10 ;;level 10 background
.dw gamebkgd11 ;;level 11 background
.dw gamebkgd12 ;;level 12 background
.dw gamebkgd13 ;;level 13 background
.dw gamebkgd14 ;;level 14 background
.dw gamebkgd15 ;;level 15 background
gamebkgd0: ;a full table of tile numbers that fill up the screen. you'll need one of these for
;every ".dw" in the pointer table.
.db $05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05,$05, etc, etc