-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.ts
217 lines (195 loc) · 5.11 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
let holding = false
let mainMenu = true
let fps = 7.5
let alive = false
let groundBrightness = 10
let blockBrightness = 150
let playerBrightness = 255
let jumpState = 0
let score = 0
// Main Menu
basic.plotLeds(`
. . # . .
. # . # .
# # # # #
# . . . #
# . . . #
`)
// A Button Handler
// B Button Handler
// Method is executed at start of running the game
function run() {
let y: number;
let block: number;
let x: number;
let blockPos = []
basic.setLedColor(basic.rgb(0, 255, 0))
holding = false
let blockOnScreen = false
alive = true
while (alive) {
basic.pause(1000 / fps)
// Jump if needed
if (jumpState >= 1) {
for (y = 0; y < 4; y++) {
led.unplot(1, y)
}
if (jumpState < 3) {
led.plotBrightness(1, 2 - jumpState, 255)
led.plotBrightness(1, 3 - jumpState, 255)
} else if (jumpState >= 3) {
led.plotBrightness(1, 0 + (jumpState - 3), 255)
led.plotBrightness(1, 1 + (jumpState - 3), 255)
}
jumpState += 1
if (jumpState == 6) {
jumpState = 0
}
}
// Move block
if (!blockOnScreen) {
if (randint(0, 5) == 5) {
// Spawn block
score += 1
block = randint(1, 3)
led.plotBrightness(4, block, blockBrightness)
blockPos[0] = Math.trunc(4)
blockPos[1] = Math.trunc(block)
basic.pause(200)
blockOnScreen = true
}
} else {
// Move block
x = blockPos[0]
y = blockPos[1]
if (led.pointBrightness(x, y) != playerBrightness) {
led.unplot(x, y)
}
x -= 1
if (x >= 0) {
blockPos[0] = Math.trunc(x)
if (led.pointBrightness(x, y) != playerBrightness) {
led.plotBrightness(x, y, blockBrightness)
}
} else {
blockOnScreen = false
}
// Check if player collides with block
if (led.pointBrightness(x, y) == playerBrightness) {
alive = false
dead()
}
}
}
}
// Method for handling if a player dies
function dead() {
basic.setLedColor(basic.rgb(255, 0, 0))
mainMenu = false
basic.clearScreen()
basic.plotLeds(`
. . . . .
. # . # .
. . . . .
. # # # .
# . . . #
`)
basic.pause(2000)
jumpState = 0
basic.clearScreen()
if (storage.getNumber(StorageSlots.s1) < score) {
storage.putNumber(StorageSlots.s1, score)
basic.showString("NEWHIGHSCORE")
} else {
basic.showString("SCORE")
}
basic.showNumber(score)
basic.clearScreen()
basic.plotLeds(`
. . # . .
. # . # .
# # # # #
# . . . #
# . . . #
`)
score = 0
mainMenu = true
basic.turnRgbLedOff()
}
// Method to start jumping
function jump() {
if (jumpState == 0) {
jumpState = 1
}
}
// Method for Main Menu
function start() {
mainMenu = false
basic.clearScreen()
for (let i = 0; i < 5; i++) {
led.plotBrightness(i, 4, groundBrightness)
}
led.plotBrightness(1, 2, playerBrightness)
led.plotBrightness(1, 3, playerBrightness)
holding = true
}
// Easter-Egg Jingle Method
// Button Events
input.onButtonEvent(Button.AB, input.buttonEventClick(), function jingle() {
// Axel F jingle because why not
music.playTone(Note.D, 200)
basic.pause(200)
music.playTone(Note.D, 200)
basic.pause(200)
music.playTone(Note.D, 200)
basic.pause(200)
music.playTone(Note.F, 200)
basic.pause(100)
music.playTone(Note.D, 200)
basic.pause(100)
music.playTone(Note.G, 200)
basic.pause(50)
music.playTone(Note.D, 200)
basic.pause(50)
music.playTone(Note.C, 200)
basic.pause(100)
music.playTone(Note.D, 200)
basic.pause(150)
music.playTone(Note.A, 200)
basic.pause(150)
music.playTone(Note.D, 200)
basic.pause(100)
music.playTone(Note.Bb, 200)
basic.pause(100)
music.playTone(Note.A, 200)
basic.pause(100)
music.playTone(Note.G, 200)
basic.pause(100)
music.playTone(Note.D, 200)
basic.pause(100)
music.playTone(Note.A, 200)
basic.pause(100)
music.playTone(Note.D5, 200)
basic.pause(150)
music.playTone(Note.D, 200)
basic.pause(100)
music.playTone(Note.C, 200)
basic.pause(100)
music.playTone(Note.C, 200)
basic.pause(100)
music.playTone(Note.E, 200)
basic.pause(100)
music.playTone(Note.D, 200)
})
input.onButtonEvent(Button.A, input.buttonEventClick(), function a_controller() {
if (mainMenu) {
start()
} else if (holding) {
run()
}
})
input.onButtonEvent(Button.B, input.buttonEventClick(), function b_controller() {
if (alive) {
jump()
}
})