Advertisement
Guest User

Untitled

a guest
May 9th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. define movingUp      1
  2. define movingRight   2
  3. define movingDown    4
  4. define movingLeft    8
  5. define movingUpLeft  9
  6. define movingUpRight 3
  7. define movingDownLeft 12
  8. define movingDownRight 6
  9.  
  10. define AREA_MAX_X $1F
  11. define AREA_MAX_Y $1F
  12.  
  13. define ballDirection $00
  14.  
  15. define ballX $20
  16. define ballY $21
  17.  
  18. define ballL $10 ; screen location of the ball
  19. define ballH $11 ; screen location of the ball
  20.  
  21. lda #$16
  22. sta ballX
  23. lda #$1b
  24. sta ballY
  25.  
  26. lda #$1a ;red
  27. sta $410
  28.  
  29. ldx #$18 ;number of blocks
  30.  
  31. lda #movingUpRight
  32. sta ballDirection
  33.  
  34. loop:
  35. lda #movingUp
  36. bit ballDirection
  37. bne up
  38. lda #movingDown
  39. bit ballDirection
  40. bne down
  41. up:
  42. dec ballY
  43. jmp checkLeftRight
  44. down:
  45. inc ballY
  46. checkLeftRight:
  47. lda #movingLeft
  48. bit ballDirection
  49. bne left
  50. lda #movingRight
  51. bit ballDirection
  52. bne right
  53. left:
  54. dec ballX
  55. jmp end_direction_check
  56. right:
  57. ;tya
  58. ;pha
  59. lda ballX
  60. cmp #AREA_MAX_X
  61. beq switch_to_left
  62. inc ballX ;not a wall, move to right
  63. jmp end_direction_check
  64. switch_to_left:
  65. ;hit a wall - reverse direction
  66. ;brk
  67. lda ballDirection; #$fd ; !2
  68. and #$fd ; !2
  69. ;sta ballDirection
  70. ora #movingLeft
  71. sta ballDirection
  72. jmp checkLeftRight
  73. end_direction_check:
  74. jsr ballCoordinatesToScreen
  75. ;draw new position
  76. lda #3 ;different color
  77. sta (ballL),y
  78. dex
  79. bne loop
  80. brk
  81.  
  82. ballCoordinatesToScreen:
  83.   ;ball = ballY * 32 + ballX + 0x0200
  84.   lda #0
  85.   sta ballH ; clear ballH as we'll be shifting later
  86.   lda ballY
  87.   sta ballL
  88.   asl ballL ;*2 max 3E
  89.   asl ballL ;*4 max 7C
  90.   asl ballL ;*8 max F8
  91.   asl ballL ;*16, can carry
  92.   rol ballH ;rotate high byte left
  93.   asl ballL; *32, can carry
  94.   rol ballH ;rotate high byte left
  95.   clc ;clear carry before the addition
  96.   lda ballL ; ballL = ballL + ballX
  97.   adc ballX
  98.   sta ballL
  99.   inc ballH ;increment by 2 to offset by 0x200
  100.   inc ballH
  101.   rts
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement