-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain_Menu.js
More file actions
368 lines (346 loc) · 16.6 KB
/
Copy pathMain_Menu.js
File metadata and controls
368 lines (346 loc) · 16.6 KB
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
const buttonWidth = 900
const buttonHeight = 100
let menuStage = 0
let Music1, Music2, controls, RobotRock, mrBeast, flag
let collisionStat = false
let dynamicStat = false
let sensitivityLevel = 3, TTGhost = false, qLength = 2, rLength = 15
// Settings packager is responsible for making settings accessable to the other files so it can be applied
function settingsPackager(Playermap = undefined) {
window.sessionStorage.clear()
// sessionStorage is cleared to prevent an override
let selectedSettings = {sens: sensitivityLevel, diff:TTGhost, qL: qLength, rL: rLength, noCol:collisionStat, dyCol: dynamicStat}
let JSONSettings = JSON.stringify(selectedSettings)
// The JSONObject is stringified so it can be used in local storage
// If the player has selected time trial and a map on it, the packager also sends the map data
if (Playermap){
window.sessionStorage.setItem("map", Playermap)
}
// The settings are then saved in session storage
window.sessionStorage.setItem("Settings", JSONSettings)
}
/***
* @param {string} - Takes Player Map as an input, if undefined, map data is not stored.
*/
function preload() {
soundFormats("mp3")
Music1 = loadSound('FT')
Music2 = loadSound('FTh [music]')
RobotRock = loadSound('Audio/Robot Rock')
//mrBeast = loadSound('Audio/mrbeast')
controls = loadImage('images/pixil-frame-0 (2).png')
flag = loadImage('images/ezgif-1-7a5892843b.gif')
}
function setup() {
createCanvas(windowWidth, windowHeight)
colorMode(RGB)
textSize(54)
backgroundMusic()
backgroundMusic = undefined
}
function playButton() {
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, height / 4 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Play", width / 2, height / 4)
push()
textSize(80)
textAlign(CENTER, TOP)
fill("black")
textStyle(BOLDITALIC)
text("Pole 2025", width/2, 0)
fill("grey")
text("Position ", width/2, 0)
pop()
}
function settingsButton() {
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 2 * height / 4 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Settings", width / 2, 2 * height / 4)
}
function timeTrialButton() {
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, height / 4 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Time Trial", width / 2, height / 4)
}
function NormalGameButton() {
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 2 * height / 4 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Grand Prix (WIP?)", width / 2, 2 * height / 4)
}
function backButton() {
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 3 * height / 4 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Back", width / 2, 3 * height / 4)
}
function draw() {
/** The menu is placed into stages
* These stages determine what buttons are shown to the player
*/
background(255)
image(flag, 0, 0, width, height)
if (menuStage === 0) { // The First stage visible to the player is the default stage of the menu
playButton()
settingsButton()
} else if (menuStage === 1) { // The second stage shows the gamemode options to the player
NormalGameButton()
timeTrialButton()
backButton()
} else if (menuStage === 2) { // The third stage displays the maps to the player in time trial
timeTrialMaps()
} else if (menuStage === 3) { // The fourth stage displays the main settings buttons to the player
settingsButtons()
} else if (menuStage === 4) { // The fifth stage displays the game altering settings to the player
superSettingsButtons()
} else if (menuStage === 5){ // The fifth stage shows the controls to the player
controlsScreen()
}
}
function timeTrialMaps() {
// Create a custom button with text on it containing the name with each map
// Any button with a text colour of gold is an event map
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 1 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 2 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 3 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 4 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 5 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 6 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
push()
text("Vortex Velocity Raceway", width / 2, 1 * height / 7) // The track used in the weekly championship is highlighted in gold
pop()
text(`Viper’s Nest Circuit`, width / 2, 2 * height / 7)
text("Silver Sands Speedway - w Chicane", width / 2, 3 * height / 7)
push()
text("Silver Sands Speedway - w/o Chicane", width / 2, 4 * height / 7)
pop()
push()
fill('gold')
text("Avus", width / 2, 5 * height / 7)
pop()
text("Back", width / 2, 6 * height / 7)
}
function settingsButtons() {
// create a custom button with text on it containing the value of each variable
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 2 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 3 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 4 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 5 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 6 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 7 * height / 8 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Settings", width / 2, 1 * height / 8)
text(`Sensitivity ${sensitivityLevel}`, width / 2, 2 * height / 8)
text(`Time Trial Ghost ${TTGhost}`, width / 2, 3 * height / 8) // Has no effect
text(`Qualifying Length ${qLength}`, width / 2, 4 * height / 8)
text(`Race Length ${rLength}`, width / 2, 5 * height / 8)
text(`Controls`, width / 2, 6 * height / 8)
text("Next", width / 2, 7 * height / 8)
}
function superSettingsButtons() {
// create a custom button with text on it containing the value of each variable
fill(122, 122, 122)
rect(width / 2 - buttonWidth / 2, 2 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 3 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 4 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 5 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
rect(width / 2 - buttonWidth / 2, 6 * height / 7 - buttonHeight / 2, buttonWidth, buttonHeight, 30)
fill(255)
textFont('Titillium Web')
textAlign(CENTER, CENTER)
text("Super Not-So-Secret Secret Settings", width / 2, 1 * height / 7)
text(`Disable Collisions ${collisionStat}`, width / 2, 2 * height / 7)
text(`Turn on Dymanic Collision ${dynamicStat}`, width / 2, 3 * height / 7)
text("Found a bug? Click me!", width / 2, 4*height/7)
text(`Back to Settings`, width / 2, 5 * height / 7)
text(`Back to Menu`, width / 2, 6 * height / 7)
}
//display the controls image
function controlsScreen(){
imageMode(CENTER)
noSmooth()
image(controls, width / 2, height / 4, width, 3*height/4)
}
function mouseClicked() {
/**
* The mouseClicked() function is a mess. I know.
* Each outer if statement is dedicated to a stage of the menu seen above
* Inner if statements check to see if the user has clicked within the boundary of a button.
*/
if (menuStage < 2) {
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > height / 4 - buttonHeight / 2 && mouseY < height / 4 + buttonHeight / 2) {
if (menuStage != 2) {
menuStage++
} else if (menuStage === 2) {
window.sessionStorage.setItem("map", "map1")
window.location.assign("Time_Trial.html")
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 2 * height / 4 - buttonHeight / 2 && mouseY < 2 * height / 4 + buttonHeight / 2) {
if (menuStage === 0) {
menuStage = 3
} else if (menuStage === 1) {
//alert("The Following Gamemode is work in progress. You will currently be able to play qualifying only.")
settingsPackager()
window.location.assign("Quali.html")
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 3 * height / 4 - buttonHeight / 2 && mouseY < 3 * height / 4 + buttonHeight / 2) {
if (menuStage > 0) {
menuStage--
}
}
} else if (menuStage === 2) {
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > height / 7 - buttonHeight / 2 && mouseY < height / 7 + buttonHeight / 2) {
settingsPackager("map1")
window.location.assign("Time_Trial.html")
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 2 * height / 7 - buttonHeight / 2 && mouseY < 2 * height / 7 + buttonHeight / 2) {
settingsPackager("map2")
window.location.assign("Time_Trial.html")
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 3 * height / 7 - buttonHeight / 2 && mouseY < 3 * height / 7 + buttonHeight / 2) {
settingsPackager("map3")
window.location.assign("Time_Trial.html")
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 4 * height / 7 - buttonHeight / 2 && mouseY < 4 * height / 7 + buttonHeight / 2) {
settingsPackager("map5")
window.location.assign("Time_Trial.html")
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 5 * height / 7 - buttonHeight / 2 && mouseY < 5 * height / 7 + buttonHeight / 2) {
settingsPackager("map4")
window.location.assign("Time_Trial.html")
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 6 * height / 7 - buttonHeight / 2 && mouseY < 6 * height / 7 + buttonHeight / 2) {
menuStage--
}
} else if (menuStage == 3) {
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 2 * height / 8 - buttonHeight / 2 && mouseY < 2 * height / 8 + buttonHeight / 2) {
sensitivityLevel++
// Increment the value of sensitivity and reset to 1 if the value is greater than 5
if (sensitivityLevel == 6) {
sensitivityLevel = 1
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 3 * height / 8 - buttonHeight / 2 && mouseY < 3 * height / 8 + buttonHeight / 2) {
TTGhost = !TTGhost
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 4 * height / 8 - buttonHeight / 2 && mouseY < 4 * height / 8 + buttonHeight / 2) {
// Prompt the player to enter a quali length
let tempQLength = parseInt(prompt("Please enter a length for Qualifying"))
// Check the player's input is even an integer
if (!Number.isInteger(tempQLength)) {
console.warn("Invalid Input")
} else {
// Check whether the player's input is within range
if (!(tempQLength > 0 && tempQLength < 15)) {
console.warn("Invalid Input")
} else {
// Update the length of Qualifying if these checks are passed
qLength = tempQLength
}
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 5 * height / 8 - buttonHeight / 2 && mouseY < 5 * height / 8 + buttonHeight / 2) {
// Prompt the player to enter a quali length
let tempRLength = parseInt(prompt("Please enter a length for the Race"))
// Check the player's input is even an integer
if (!Number.isInteger(tempRLength)) {
console.warn("Invalid Input")
} else {
// Check whether the player's input is within range
if (tempRLength < 0 || tempRLength > 100) {
console.warn("Invalid Input")
} else {
// Update the length of Qualifying if these checks are passed
rLength = tempRLength
}
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 6 * height / 8 - buttonHeight / 2 && mouseY < 6 * height / 8 + buttonHeight / 2) {
menuStage = 5
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 7 * height / 8 - buttonHeight / 2 && mouseY < 7 * height / 8 + buttonHeight / 2) {
menuStage++
}
} else if (menuStage===5){
menuStage = 3
}else {
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 2 * height / 7 - buttonHeight / 2 && mouseY < 2 * height / 7 + buttonHeight / 2) {
if (dynamicStat) {
alert("Please disable dynamic collisions to enable this!")
} else {
collisionStat = !collisionStat
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 3 * height / 7 - buttonHeight / 2 && mouseY < 3 * height / 7 + buttonHeight / 2) {
if (collisionStat) {
alert("Please disable no collisions to enable this!")
} else {
dynamicStat = !dynamicStat
}
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 4 * height / 7 - buttonHeight / 2 && mouseY < 4 * height / 7 + buttonHeight / 2) {
window.open("https://github.com/benkarting30/PolePosition2025Game/issues") // Sends the player to the issues page of the github where they can report bugs
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 5 * height / 7 - buttonHeight / 2 && mouseY < 5 * height / 7 + buttonHeight / 2) {
menuStage--
}
if (mouseX > width / 2 - buttonWidth / 2 && mouseX < width / 2 + buttonWidth / 2 && mouseY > 6 * height / 7 - buttonHeight / 2 && mouseY < 6 * height / 7 + buttonHeight / 2) {
menuStage = 0
window.sessionStorage.removeItem("settings")
settingsPackager()
}
}
}
function backgroundMusic() {
/*The backgroundMusic function contains easter eggs for the player to find
1. There is 1 in the 64 bit ingeter limit chance that the incorrect music plays (music1)
2. There is a 1/50 chance that the correct music plays but louder
3. There is a 1/100 chance that "Daft Punk - Robot Rock" plays instead of the correct music
*/
if (floor(random(0, 9223372036854775807)) == 9223372036854775807) {
Music1.play()
Music1.loop()
Music1.setVolume(0.3)
userStartAudio()
} else if (floor(random(0, 50))==0) {
Music2.play()
Music2.loop()
Music2.setVolume(0.8)
userStartAudio()
} else if (floor(random(0, 100)) ==0){
RobotRock.play()
RobotRock.loop()
RobotRock.setVolume(0.5)
// } else if (floor(random(0, 250)) == 2){
// mrBeast.play()
// mrBeast.loop()
// mrBeast.setVolume(0.5)
} else {
Music2.play()
Music2.loop()
Music2.setVolume(0.3)
userStartAudio()
}
}