-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroller.ts
80 lines (80 loc) · 1.85 KB
/
scroller.ts
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
69
70
71
72
73
74
75
76
77
78
79
80
let delay = 0
let counter = 0
let status = 0
let score = 0
input.onButtonPressed(Button.AB, function () {
if (status == 1) {
center = 2
sprite = 2
score = 0
counter = 0
playfield = [17, 19, 17, 19, 17]
status = 0
}
})
function drawSprite() {
led.plotBrightness(sprite, 4, 255)
}
function drawPlayfield() {
basic.clearScreen()
for (let y = 0; y <= 5 - 1; y++) {
for (let x = 0; x <= 5 - 1; x++) {
if ((playfield[y] & (1 << x)) > 0) {
led.plotBrightness(x, y, 64)
}
}
}
}
input.onButtonPressed(Button.A, function () {
if (sprite > 0) {
sprite += -1
}
})
input.onButtonPressed(Button.B, function () {
if (sprite < 4) {
sprite += 1
}
})
let playfield: number[] = []
let sprite = 0
let center = 0
delay = 1000
playfield = [17, 19, 17, 19, 17]
center = 2
sprite = 2
status = 0
led.setDisplayMode(DisplayMode.Greyscale)
basic.forever(function () {
if (status == 0) {
playfield[4] = playfield[3]
playfield[3] = playfield[2]
playfield[2] = playfield[1]
playfield[1] = playfield[0]
center = center + Math.randomRange(-1, 1)
if (center < 0) {
center = 0
}
if (center > 5) {
center = 4
}
playfield[0] = 31 & (~(1 << center)) & (~(1 << (center - 1))) & (~(1 << (center + 1)))
if ((playfield[4] & (1 << sprite)) > 0) {
status = 1
}
score = score + 1
counter = counter + 1
if (counter > 100) {
counter = 0
delay = delay - 10
if (delay < 400) {
delay = 400
}
}
drawPlayfield()
drawSprite()
}
if (status == 1) {
basic.showString("Game over! Score:" + score)
}
basic.pause(delay)
})