-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeam-em.ts
72 lines (67 loc) · 1.77 KB
/
beam-em.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
let Player: game.LedSprite = null
Player = game.createSprite(2, 4)
let Beam3: game.LedSprite = null
let Beam2: game.LedSprite = null
let Beam1: game.LedSprite = null
let Beam0: game.LedSprite = null
let Enemy: game.LedSprite = null
let EnemyPosition = 0
let Timer = 900
let Score = 0
function Game () {
while (true) {
EnemyPosition = randint(0, 4)
Enemy = game.createSprite(EnemyPosition, 0)
for (let index = 0; index < 5; index++) {
basic.pause(Timer)
Enemy.change(LedSpriteProperty.Y, 1)
if (Player.isTouching(Enemy)) {
EndGame()
}
}
if (Enemy.isDeleted()) {
Enemy.delete()
} else {
EndGame()
}
}
}
function Shot () {
Beam0 = game.createSprite(Player.get(LedSpriteProperty.X), 3)
Beam1 = game.createSprite(Player.get(LedSpriteProperty.X), 2)
Beam2 = game.createSprite(Player.get(LedSpriteProperty.X), 1)
Beam3 = game.createSprite(Player.get(LedSpriteProperty.X), 0)
basic.pause(650)
Beam0.delete()
Beam1.delete()
Beam2.delete()
Beam3.delete()
}
function EndGame() {
basic.showString("GG Score " + Score)
control.reset()
}
input.onPinPressed(TouchPin.P0, function () {
Game()
})
input.onButtonPressed(Button.A, function () {
Player.change(LedSpriteProperty.X, -1)
})
input.onButtonPressed(Button.B, function () {
Player.change(LedSpriteProperty.X, 1)
})
input.onButtonPressed(Button.AB, function () {
if (Enemy !== null) {
if (Player.get(LedSpriteProperty.X) == Enemy.get(LedSpriteProperty.X)) {
Score += 1
Enemy.delete()
}
Shot()
}
})
basic.forever(function () {
while (true) {
basic.pause(Timer)
Timer += -5
}
})