-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
82 lines (82 loc) · 2.15 KB
/
main.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
81
82
function bewegeDinoUm (pixel: number) {
for (let Index = 0; Index <= Math.abs(pixel) - 1; Index++) {
if (pixel > 0) {
dino.change(LedSpriteProperty.Y, -1)
} else {
dino.change(LedSpriteProperty.Y, 1)
}
basic.pause(100 + Index * 100)
}
return 0
}
input.onButtonPressed(Button.A, function () {
music.startMelody(music.builtInMelody(Melodies.JumpUp), MelodyOptions.OnceInBackground)
bewegeDinoUm(3)
basic.pause(500)
bewegeDinoUm(-3)
})
function neuesHindernis () {
for (let hindernis of hindernisse) {
hindernis.delete()
}
hindernisse = [game.createSprite(4, 3)]
if (Math.randomBoolean()) {
hindernisse.push(game.createSprite(4, 2))
hindernisse.push(game.createSprite(4, 1))
hindernisse.push(game.createSprite(4, 0))
} else {
hindernisse.push(game.createSprite(4, 4))
}
}
function init () {
music.setVolume(39)
punkte = 0
Leben = 3
neuesHindernis()
}
input.onButtonPressed(Button.B, function () {
bewegeDinoUm(-1)
basic.pause(1000)
bewegeDinoUm(1)
})
function bewegeHindernis () {
punkte += 1
if (keinHindernisMehr()) {
neuesHindernis()
} else {
for (let hindernis of hindernisse) {
hindernis.change(LedSpriteProperty.X, -1)
}
}
}
function keinHindernisMehr () {
return hindernisse[0].get(LedSpriteProperty.X) == 0
}
function berührtHindernis () {
for (let hindernis of hindernisse) {
if (hindernis.isTouching(dino)) {
return true
}
}
return false
}
let Leben = 0
let punkte = 0
let hindernisse: game.LedSprite[] = []
let dino: game.LedSprite = null
dino = game.createSprite(0, 3)
init()
basic.forever(function () {
basic.pause(500)
bewegeHindernis()
if (berührtHindernis()) {
Leben += -1
if (Leben == 0) {
music.startMelody(music.builtInMelody(Melodies.Funeral), MelodyOptions.Once)
basic.showString("" + (punkte))
init()
} else {
music.startMelody(music.builtInMelody(Melodies.PowerDown), MelodyOptions.OnceInBackground)
}
}
})