SHARE
TWEET

Untitled

a guest Jun 20th, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function board() {
  2.     for (let i = xb; i < (xb + yb); i++) {
  3.         led.plot(i, 4)
  4.     }
  5. }
  6. function left() {
  7.     xb += 0 - 1
  8.     basic.clearScreen()
  9.     board()
  10.     ball()
  11. }
  12. function right() {
  13.     xb += 1
  14.     basic.clearScreen()
  15.     board()
  16.     ball()
  17. }
  18. function ball() {
  19.     led.plot(x, y)
  20. }
  21. function topside() {
  22.     ydir = 1
  23.     if (x == 0) {
  24.         xdir = Math.randomRange(0,2)
  25.     } else if (x == 4) {
  26.         xdir = Math.randomRange(0,2) - 1
  27.     } else {
  28.         xdir = Math.randomRange(0,3) - 1
  29.     }
  30. }
  31. function leftside() {
  32.     xdir = 1
  33. }
  34. function rightside() {
  35.     xdir = -1
  36. }
  37. function corners() {
  38.     xdir = 0 - xdir
  39.     ydir = 0 - ydir
  40. }
  41. function checkhit() {
  42.     if (xb - 1 < x && xb + yb > x) {
  43.         scor += 1
  44.         ydir = -1
  45.         if (x == 0) {
  46.             xdir = Math.randomRange(0,2)
  47.         } else if (x == 4) {
  48.             xdir = Math.randomRange(0,2) - 1
  49.         } else {
  50.             xdir = Math.randomRange(0,3) - 1
  51.         }
  52.         if (scor > 1 && scor < 4) {
  53.             yb += 0 - 1
  54.         }
  55.         if (scor > 5 && scor < 12) {
  56.             time += 0 - 150
  57.         }
  58.     }
  59. }
  60. function moveball() {
  61.     x += xdir
  62.     y += ydir
  63.     basic.clearScreen()
  64.     ball()
  65.     board()
  66.     if (y == 0 && (x == 0 || x == 4)) {
  67.         corners()
  68.     } else if (x == 0 && y > 0 && y < 3) {
  69.         leftside()
  70.     } else if (x == 4 && y > 0 && y < 3) {
  71.         rightside()
  72.     } else if (y == 0) {
  73.         topside()
  74.     } else if (y == 3) {
  75.         checkhit()
  76.     } else if (y == 4) {
  77.         gam = false
  78.         basic.clearScreen()
  79.         basic.pause(1000)
  80.         basic.showNumber(scor)
  81.         basic.pause(1000)
  82.         basic.clearScreen()
  83.         if (scor < 12) {
  84.             basic.showIcon(IconNames.Sad)
  85.         } else {
  86.             basic.showIcon(IconNames.Happy)
  87.         }
  88.     }
  89. }
  90. input.onButtonPressed(Button.B, () => {
  91.     right()
  92. })
  93. input.onButtonPressed(Button.A, () => {
  94.     left()
  95. })
  96. basic.forever(() => {
  97.     while (gam == true) {
  98.         basic.pause(time)
  99.         moveball()
  100.     }
  101. })
  102. let x: number
  103. x = 0
  104. let y: number
  105. y = 0
  106. let xb: number
  107. xb = 0
  108. let yb: number
  109. yb = 0
  110. let xdir: number
  111. xdir = 0
  112. let ydir: number
  113. ydir = 0
  114. let scor: number
  115. scor = 0
  116. let gam: boolean
  117. gam = true
  118. let time: number
  119. time = 1000
  120. xb = 0
  121. yb = 4
  122. board()
  123. x = 2
  124. y = 0
  125. ball()
  126. xdir = 0
  127. ydir = 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top