-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfriends.js
64 lines (61 loc) · 1.73 KB
/
friends.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
let goalkeeper = 0
let friend = 0
let countdown = 0
radio.setGroup(1)
radio.setTransmitSerialNumber(true)
// When we get a message, if the message contains our name then we've found a friend
// If not, then we can be the friend to someone else, so record their name
// and send a message back to them with their name so they know we are listening
radio.onDataPacketReceived(({ serial: serial2, receivedNumber }) => {
if (input.buttonIsPressed(Button.AB)) {
if (receivedNumber == control.deviceSerialNumber()) {
friend = serial2
}
} else {
if (goalkeeper == 0) {
goalkeeper = serial2
radio.sendNumber(serial2)
countdown = 12
led.plot(4, 0)
led.plot(4, 4)
} else {
if (goalkeeper == serial2) {
countdown = 12
}
}
}
})
//
basic.forever(() => {
if (goalkeeper != 0) {
countdown = countdown - 1
basic.pause(100)
if (countdown == 0) {
goalkeeper = 0
led.unplot(4, 0)
led.unplot(4, 4)
}
}
})
// If button is pressed, send notification that we are here
// Flash the top left pixel while we wait for a friend to listen,
// or display a tick if someone is listening
// If the button is not pressed, then remove friend
basic.forever(() => {
if (input.buttonIsPressed(Button.AB)) {
radio.sendNumber(0)
if (friend == 0) {
led.plot(0, 0)
basic.pause(500)
led.unplot(0, 0)
basic.pause(500)
} else {
basic.showIcon(IconNames.Yes)
}
} else {
if (friend != 0) {
basic.clearScreen()
friend = 0
}
}
})