-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.ts
140 lines (140 loc) · 4.23 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
controller.up.onEvent(ControllerButtonEvent.Pressed, function () {
dino.vy = -60
})
controller.A.onEvent(ControllerButtonEvent.Pressed, function () {
dino.setImage(img`
........................
........................
........................
...........ccc..........
...........cccc.........
.......ccc..ccccccc.....
.......cccccc555555cc...
........ccb5555555555c..
.....cc..b555555555555c.
.....cccb55555bcc555555c
......cb555555555c55d55c
......b5555555555555555c
...cc.b555dd5555bb1bbbc.
....ccd55ddddd5bbbb335c.
...ccbdddddddd5bbbb335c.
.ccccddddddddd55bb3335c.
cdcccdddddb55bb55b3335c.
cddbddddddb555bb553335c.
cddddddddddb5555b5555c..
ccddddddbd55bb55cbccc...
.ccddddbbbdd55ccbbc.....
...ccbbbcbddddccdddc....
.....ccccdd555dccccc....
........cccccccc........
`)
})
sprites.onCreated(SpriteKind.Food, function (sprite) {
sprite.x = 170
sprite.y = randint(0, 120)
sprite.vx = -100
})
controller.down.onEvent(ControllerButtonEvent.Released, function () {
dino.vy = 0
})
sprites.onOverlap(SpriteKind.Food, SpriteKind.Player, function (sprite, otherSprite) {
sprite.destroy()
info.changeScoreBy(1)
music.powerUp.play()
if (info.score() == 20) {
game.splash("Congratulations")
game.reset()
}
})
controller.A.onEvent(ControllerButtonEvent.Released, function () {
dino.setImage(img`
........................
........................
...........cc...........
...........cccc.........
.......cc...ccccccc.....
.......cccccc555555cc...
........ccb5555555555c..
.....cc..b555555555555c.
.....cccb555555ff155555c
.....ccb55555555ff55d55c
......b5555555555555555c
...c..b555d55555bb13bbc.
...cccd55ddddd55bb3335c.
....cbdddddddddd55b335c.
..cccdddddb55bdddd5555c.
..cccdddddb555bbbbcccc..
...ccddddddb5555cbcdc...
ccccbdddddddcb55cbcc....
cddddddddd55dbccbbc.....
cbdddddddd555dbbbcc.....
.ccbdddbbdd555bbcdbcc...
...cccbbbbdd55ccdddbc...
......cccbdddbccccccc...
........cdd555dc........
`)
})
controller.up.onEvent(ControllerButtonEvent.Released, function () {
dino.vy = 0
})
controller.down.onEvent(ControllerButtonEvent.Pressed, function () {
dino.vy = 60
})
let newPizza: Sprite = null
let dino: Sprite = null
info.setScore(0)
dino = sprites.create(img`
........................
........................
...........cc...........
...........cccc.........
.......cc...ccccccc.....
.......cccccc555555cc...
........ccb5555555555c..
.....cc..b555555555555c.
.....cccb555555ff155555c
.....ccb55555555ff55d55c
......b5555555555555555c
...c..b555d55555bb13bbc.
...cccd55ddddd55bb3335c.
....cbdddddddddd55b335c.
..cccdddddb55bdddd5555c.
..cccdddddb555bbbbcccc..
...ccddddddb5555cbcdc...
ccccbdddddddcb55cbcc....
cddddddddd55dbccbbc.....
cbdddddddd555dbbbcc.....
.ccbdddbbdd555bbcdbcc...
...cccbbbbdd55ccdddbc...
......cccbdddbccccccc...
........cdd555dc........
`, SpriteKind.Player)
dino.x = 20
game.onUpdateInterval(1000, function () {
newPizza = sprites.create(img`
. . . . . . b b b b . . . . . .
. . . . . . b 4 4 4 b . . . . .
. . . . . . b b 4 4 4 b . . . .
. . . . . b 4 b b b 4 4 b . . .
. . . . b d 5 5 5 4 b 4 4 b . .
. . . . b 3 2 3 5 5 4 e 4 4 b .
. . . b d 2 2 2 5 7 5 4 e 4 4 e
. . . b 5 3 2 3 5 5 5 5 e e e e
. . b d 7 5 5 5 3 2 3 5 5 e e e
. . b 5 5 5 5 5 2 2 2 5 5 d e e
. b 3 2 3 5 7 5 3 2 3 5 d d e 4
. b 2 2 2 5 5 5 5 5 5 d d e 4 .
b d 3 2 d 5 5 5 d d d 4 4 . . .
b 5 5 5 5 d d 4 4 4 4 . . . . .
4 d d d 4 4 4 . . . . . . . . .
4 4 4 4 . . . . . . . . . . . .
`, SpriteKind.Food)
})
game.onUpdateInterval(500, function () {
for (let pizza of sprites.allOfKind(SpriteKind.Food)) {
if (pizza.x < 0) {
pizza.destroy()
music.knock.play()
}
}
})