-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpong.js
68 lines (68 loc) · 1.35 KB
/
pong.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
let canHit = ""
let brightness = 0
let ball: game.LedSprite = null
let x = 0
let direction = 0
basic.forever(() => {
x = x + direction
if (brightness == 255) {
brightness = 0
} else {
brightness = 255
}
if (x == -1) {
direction = 0
canHit = "0"
led.setBrightness(brightness)
}
if (x == 5) {
direction = 0
canHit = "0"
led.setBrightness(brightness)
}
if (direction != 0) {
ball.change(LedSpriteProperty.X, direction)
if (ball.get(LedSpriteProperty.X) == 0) {
canHit = "a"
}
if (ball.get(LedSpriteProperty.X) == 4) {
canHit = "b"
}
}
basic.pause(150)
})
input.onButtonPressed(Button.AB, () => {
ball.delete()
direction = 0
if (Math.randomBoolean()) {
x = 0
canHit = "a"
} else {
x = 4
canHit = "b"
}
ball = game.createSprite(x, 2)
led.setBrightness(255)
})
input.onButtonPressed(Button.A, () => {
if (canHit == "a") {
direction = 1
canHit = "0"
}
})
input.onButtonPressed(Button.B, () => {
if (canHit == "b") {
direction = -1
canHit = "0"
}
})
direction = 0
if (Math.randomBoolean()) {
x = 0
canHit = "a"
} else {
x = 4
canHit = "b"
}
ball = game.createSprite(x, 2)
led.setBrightness(255)