Congrats!
The first thing you should do is start naming your labels and variables more meaningful things.
SkipBounceRight2? Why not SkipBounceLeft? It is not a good habit to copy and paste things and change just enough so it works right. If you read your code later, you'll have to think twice as hard about what the code is doing.
MovePaddle1y
DownPaddle1y
Why not UpPaddle1y? The labels should be immediately clear. Related code should follow a format.
Code: Select all
paddle1y .rs 1;This one's labeling doesn't match the others.
paddle12 .rs 1;These could be read as PaddleTwelve
paddle13 .rs 1;PaddleThirteen
paddle14 .rs 1;PaddleFourteen
;Which hides their purpose a little bit.
You actually don't need paddle12, paddle13, and paddle14 at all.
Right now you are using 4 zero page RAM locations for each paddle's y position.
This has two problems:
1. You have to update all 4 every time the paddle moves.
2. You're using 3 more bytes of zero page RAM than you need.
You can update only one byte of RAM that contains the actual Y position of the paddle:
Code: Select all
MovePaddle1y:
LDA buttons1
AND #%00001000
BEQ MovePaddle1yDone
LDA paddle1y
SEC
SBC #$01
STA paddle1y
MovePaddle1yDone:
Then do this when you update the sprites:
Code: Select all
LDA paddle1y;Paddle1y is in A.
STA $0204
LDY #$37;We're using Y instead of A
STY $0205;Because A holds a value we'll add to
;For the other sprites in the paddle.
LDY #$00
STY $0206
LDY #$08
STY $0207
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CLC
ADC #$08;We've added 8 to the top y position.
STA $0208;Paddle1y+8 is in A.
LDY #$47
STY $0209
LDY #$00
STY $020A
LDY #$08
STY $020B
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CLC
ADC #$08;Paddle1y+16 is in A.
STA $020C
LDY #$57
STY $020D
LDY #$00
STY $020E
LDY #$08
STY $020F
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CLC
ADC #$08;Paddle1y+24 is in A.
STA $0210
LDY #$67
STY $0211
LDY #$00
STY $0212
LDY #$08
STY $0213
That updates all the sprites properly without the extra RAM.
In fact, you can take it a little further. I said earlier that anytime you need to duplicate complicated code, it's probably worth turning it into a subroutine. Right now you have the "update paddle sprites" code duplicated for each paddle.
You can make a subroutine using the ,x addressing mode.
lda $0200,x loads the value at the location $02XX. If X is FF it loads from $02FF.
If X is 8, it loads $0208.
Remember how we had to put things in temp RAM to set up our checkcollision routine? Here we need to do some setup, but we'll just use A, X, and Y.
Code: Select all
;load the y position of the paddle in A.
;Load the X position of the paddle in Y.
;Then load the location of the first byte of the paddle you want to draw in X.
;JSR to this subroutine and it will draw the paddle.
DrawPaddle:
STA $0200,x;This works because before we jsr'd to DrawPaddle, we loaded the y position in A.
STA temp1;We need to store it in temp RAM instead of keeping it in A
;For the subroutine. This is because you can't STY $0200,x. ST ,x is only available for A.
LDA #$37
STA $0201,x
LDA #$00
STA $0202,x
TYA;Move the value in Y(the X position of the paddle) into A.
STA $0203,x
inx
inx
inx
inx;We want to work with a new sprite now, so we advance four bytes.
LDA temp1
CLC
ADC #$08
STA temp1
STA $0200,x
LDA #$47
STA $0201,x
LDA #$00
STA $0202,xx
TYA
STA $0203,x
inx
inx
inx
inx
;*insert the same sort of thing for the final two sprites*
rts
Then, you can use it like this:
Code: Select all
lda paddle1y
ldy paddle1x
ldx #$04;The ball occupies $0200, $0201, $0202, and $0203, so we start with $0204.
jsr DrawPaddle
;The first paddle's sprites are updated! You don't even have to update X to do more, since the DrawPaddle routine automatically moves it to the next free sprite.
lda paddle2y
ldy paddle2x
jsr DrawPaddle
;The second paddle's sprites are updated!
;You can even draw more paddles in other locations!
lda #$80
ldy #$80
jsr DrawPaddle
If you use subroutines instead of hard coding everything it makes it very easy to add new objects to the game.
One last thing. The CURSE of nesasm.
Whenever you are using a zero page variable, put < before it.
Code: Select all
lda temp1
;becomes
lda <temp1
lda paddle1y
;becomes
lda <paddle1y
This makes your code faster.
lda temp1 is like typing lda $XXXX which takes 4 cycles.
lda <temp1 is like typing lda $XX which takes 3 cycles.
It's faster, and there's no drawback to doing it 99% of the time.
The one percent is when you want to do lda temp1,x. In that case lda <temp1,x and lda temp1,x can possibly do different things.