Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define movingUp 1
- define movingRight 2
- define movingDown 4
- define movingLeft 8
- define movingUpLeft 9
- define movingUpRight 3
- define movingDownLeft 12
- define movingDownRight 6
- define AREA_MAX_X $1F
- define AREA_MAX_Y $1F
- define ballDirection $00
- define ballX $20
- define ballY $21
- define ballL $10 ; screen location of the ball
- define ballH $11 ; screen location of the ball
- lda #$16
- sta ballX
- lda #$1b
- sta ballY
- lda #$1a ;red
- sta $410
- ldx #$18 ;number of blocks
- lda #movingUpRight
- sta ballDirection
- loop:
- lda #movingUp
- bit ballDirection
- bne up
- lda #movingDown
- bit ballDirection
- bne down
- up:
- dec ballY
- jmp checkLeftRight
- down:
- inc ballY
- checkLeftRight:
- lda #movingLeft
- bit ballDirection
- bne left
- lda #movingRight
- bit ballDirection
- bne right
- left:
- dec ballX
- jmp end_direction_check
- right:
- ;tya
- ;pha
- lda ballX
- cmp #AREA_MAX_X
- beq switch_to_left
- inc ballX ;not a wall, move to right
- jmp end_direction_check
- switch_to_left:
- ;hit a wall - reverse direction
- ;brk
- lda ballDirection; #$fd ; !2
- and #$fd ; !2
- ;sta ballDirection
- ora #movingLeft
- sta ballDirection
- jmp checkLeftRight
- end_direction_check:
- jsr ballCoordinatesToScreen
- ;draw new position
- lda #3 ;different color
- sta (ballL),y
- dex
- bne loop
- brk
- ballCoordinatesToScreen:
- ;ball = ballY * 32 + ballX + 0x0200
- lda #0
- sta ballH ; clear ballH as we'll be shifting later
- lda ballY
- sta ballL
- asl ballL ;*2 max 3E
- asl ballL ;*4 max 7C
- asl ballL ;*8 max F8
- asl ballL ;*16, can carry
- rol ballH ;rotate high byte left
- asl ballL; *32, can carry
- rol ballH ;rotate high byte left
- clc ;clear carry before the addition
- lda ballL ; ballL = ballL + ballX
- adc ballX
- sta ballL
- inc ballH ;increment by 2 to offset by 0x200
- inc ballH
- rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement