Skip to content

Commit ac00654

Browse files
authored
4.3.5.5 (MOBILE 4.3! 25/08/2024)
1 parent 470ed13 commit ac00654

File tree

11 files changed

+475
-275
lines changed

11 files changed

+475
-275
lines changed

JavaScript/BeatzGame.js

Lines changed: 127 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* Title: Beatz
33
* Author: Victor//GuayabR
44
* Date: 16/05/2024
5-
* Version: MOBILE 4.3.3.3 test (release.version.subversion.bugfix)
5+
* Version: MOBILE 4.3.5.5 test (release.version.subversion.bugfix)
66
* GitHub Repository: https://github.com/GuayabR/Beatz
77
**/
88

99
// CONSTANTS
1010

1111
const userDevice = detectDeviceType();
1212

13-
const VERSION = "MOBILE 4.3.3.3";
13+
const VERSION = "MOBILE 4.3.5.5";
1414
var PUBLICVERSION = `4.3! (${userDevice} Port)`;
1515
console.log("Version: " + VERSION);
1616

@@ -609,7 +609,8 @@ function preloadSongs() {
609609
"https://guayabr.github.io/Beatz/Resources/Songs/VVV.mp3",
610610
"https://guayabr.github.io/Beatz/Resources/Songs/Magic Touch.mp3",
611611
"https://guayabr.github.io/Beatz/Resources/Songs/Uptown Funk.mp3",
612-
"https://guayabr.github.io/Beatz/Resources/Songs/Lunar Abyss.mp3"
612+
"https://guayabr.github.io/Beatz/Resources/Songs/Lunar Abyss.mp3",
613+
"https://guayabr.github.io/Beatz/Resources/Songs/Lost.mp3"
613614
];
614615
} else {
615616
console.log(`Loading songs locally, fetching: ${useFetch}`);
@@ -721,6 +722,7 @@ function preloadSongs() {
721722
"Resources/Songs/Magic Touch.mp3",
722723
"Resources/Songs/Uptown Funk.mp3",
723724
"Resources/Songs/Lunar Abyss.mp3",
725+
"Resources/Songs/Lost.mp3",
724726

725727
"Resources/Songs/testingsong.mp3"
726728
];
@@ -953,6 +955,7 @@ const songConfigs = {
953955
"Magic Touch": { BPM: 127, noteSpeed: 12 },
954956
"Uptown Funk": { BPM: 115, noteSpeed: 12 },
955957
"Lunar Abyss": { BPM: 138, noteSpeed: 10 },
958+
Lost: { BPM: 105, noteSpeed: 12 },
956959

957960
// Song Versions
958961
"Finesse (feat. Cardi B)": { BPM: 105, noteSpeed: 22 },
@@ -1224,6 +1227,7 @@ function getDynamicSpeed(songSrc) {
12241227
{ timestamp: 222, noteSpeed: 8, notes: [] },
12251228
{ timestamp: 222.72, noteSpeed: 8, endScreenDrawn: true }
12261229
],
1230+
Lost: [{ timestamp: 187.545, noteSpeed: 12, endScreenDrawn: true }],
12271231
testingsong: [
12281232
{ timestamp: 1, noteSpeed: 10 },
12291233
{ timestamp: 2, noteSpeed: 10, BPM: BPM * 2 },
@@ -1348,6 +1352,7 @@ const songToAlbumMap = {
13481352
"Magic Touch": "Magic Touch",
13491353
"Uptown Funk": "Uptown Special",
13501354
"Lunar Abyss": "Lunar Abyss",
1355+
Lost: "Meteora 20'",
13511356

13521357
// Song Versions
13531358

@@ -1447,6 +1452,7 @@ function preloadImages() {
14471452
"Resources/Covers/Magic Touch.jpg",
14481453
"Resources/Covers/Uptown Special.jpg",
14491454
"Resources/Covers/Lunar Abyss.jpg",
1455+
"Resources/Covers/Meteora 20'.jpg",
14501456

14511457
// Song Versions
14521458

@@ -1673,8 +1679,16 @@ function filterSongs() {
16731679
let resultsCount = 0;
16741680
let firstVisibleButton = null; // To store the first visible song button
16751681

1676-
// Find the last song index
1677-
const lastSongIndex = songList.length;
1682+
// Check if the last song in the songList is "Resources/Songs/testingsong.mp3"
1683+
let lastSongIndex;
1684+
1685+
// If the last song is "Resources/Songs/testingsong.mp3", set lastSongIndex to songList.length - 1
1686+
if (songList[songList.length - 1] === "Resources/Songs/testingsong.mp3") {
1687+
lastSongIndex = songList.length - 1;
1688+
} else {
1689+
// Otherwise, set lastSongIndex to songList.length
1690+
lastSongIndex = songList.length;
1691+
}
16781692

16791693
songButtons.forEach((button) => {
16801694
const songText = button.textContent.toLowerCase();
@@ -1883,12 +1897,12 @@ document.getElementById("closeKeywordListModal").onclick = function () {
18831897

18841898
// Global cooldown management
18851899
let lastFunctionCallTime = 0;
1886-
const COOLDOWN_PERIOD = 100; // Cooldown period in milliseconds
1900+
const COOLDOWN_PERIOD = 150; // Cooldown period in milliseconds
18871901

18881902
function canActivate() {
18891903
const currentTime = Date.now();
18901904
if (currentTime - lastFunctionCallTime < COOLDOWN_PERIOD) {
1891-
console.log("Cooldown in effect. Please wait before calling another function.");
1905+
logNotice("Cooldown in effect. Please wait before calling another function.", "", 2250);
18921906
return false;
18931907
}
18941908
lastFunctionCallTime = currentTime;
@@ -2281,6 +2295,7 @@ function getArtist(songSrc) {
22812295
"Magic Touch": "Romos",
22822296
"Uptown Funk": "Mark Ronson, Bruno Mars",
22832297
"Lunar Abyss": "Lchavasse",
2298+
Lost: "Linkin Park",
22842299

22852300
// Song Versions
22862301

@@ -2491,6 +2506,8 @@ window.onload = function () {
24912506
});
24922507
};
24932508

2509+
let canvasScalingInterval;
2510+
24942511
function togglePause() {
24952512
if (!endScreenDrawn) {
24962513
gamePaused = !gamePaused;
@@ -2499,6 +2516,7 @@ function togglePause() {
24992516
currentSong.pause();
25002517
playSoundEffect("Resources/SFX/clickBtn2.mp3", 0.5);
25012518
canvasUpdating = false;
2519+
clearInterval(canvasScalingInterval);
25022520
console.log("Game Paused");
25032521
} else {
25042522
let pauseDuration = Date.now() - songPausedTime;
@@ -2507,11 +2525,77 @@ function togglePause() {
25072525
lastTime += pauseDuration; // Adjust lastTime to prevent jump in timeDelta
25082526
canvasUpdating = true;
25092527
updateCanvas(globalTimestamp);
2528+
2529+
manageCanvasScalingInterval(true); // Start interval when game is unpaused
2530+
25102531
console.log("Game Unpaused");
25112532
}
25122533
}
25132534
}
25142535

2536+
function fallbackPause() {
2537+
if (!endScreenDrawn) {
2538+
currentSong.pause();
2539+
playSoundEffect("Resources/SFX/hoverBtn.mp3", 0.5);
2540+
canvasUpdating = false;
2541+
clearInterval(canvasScalingInterval);
2542+
}
2543+
}
2544+
2545+
function manageCanvasScalingInterval(startInterval) {
2546+
clearInterval(canvasScalingInterval); // Clear any existing interval
2547+
2548+
if (startInterval && pulseOnBPM) {
2549+
let scaleUpDuration, scaleDownDuration, waitTime;
2550+
2551+
// Determine animation durations based on BPM
2552+
if (BPM < 200) {
2553+
scaleUpDuration = 0.11; // Scaling up duration for BPM < 200
2554+
scaleDownDuration = 0.18; // Scaling down duration for BPM < 200
2555+
waitTime = 4.2;
2556+
} else if (BPM >= 200 && BPM < 250) {
2557+
scaleUpDuration = 0.15; // Scaling up duration for 200 <= BPM < 250
2558+
scaleDownDuration = 0.2; // Scaling down duration for 200 <= BPM < 250
2559+
waitTime = 2.2;
2560+
} else if (BPM >= 250) {
2561+
scaleUpDuration = 0.1; // Scaling up duration for BPM >= 250
2562+
scaleDownDuration = 0.15; // Scaling down duration for BPM >= 250
2563+
waitTime = 3;
2564+
}
2565+
2566+
const img = document.getElementById("songCoverImage");
2567+
const musicIco = document.getElementById("bouncingIcon");
2568+
2569+
// Create a new interval for scaling the canvas and pulsing the title color
2570+
canvasScalingInterval = setInterval(() => {
2571+
// Apply cubic-bezier easing for scaling up
2572+
title.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94), color ${MILLISECONDS_PER_BEAT / 25000}s`;
2573+
title.style.transform = "scale(1.03)";
2574+
title.style.color = getRandomColor(); // Change to a random color
2575+
2576+
img.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94)`;
2577+
img.style.transform = "scale(1.025)";
2578+
2579+
musicIco.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94)`;
2580+
musicIco.style.transform = "scale(1.4)";
2581+
2582+
// Set a timeout to scale back down after the up animation
2583+
setTimeout(() => {
2584+
// Apply ease-in easing for scaling down
2585+
title.style.transition = `transform ${scaleDownDuration}s ease-in, color ${MILLISECONDS_PER_BEAT / 1000}s`;
2586+
title.style.transform = "scale(1)";
2587+
title.style.color = "white";
2588+
2589+
img.style.transition = `transform ${scaleDownDuration}s ease-in`;
2590+
img.style.transform = "scale(1)";
2591+
2592+
musicIco.style.transition = `transform ${scaleDownDuration}s ease-in`;
2593+
musicIco.style.transform = "scale(1)";
2594+
}, MILLISECONDS_PER_BEAT / waitTime); // Wait to scale down
2595+
}, MILLISECONDS_PER_BEAT);
2596+
}
2597+
}
2598+
25152599
function formatTimestampDS(seconds) {
25162600
if (seconds < 60) {
25172601
// Format as SS.ss for timestamps less than 60 seconds
@@ -2630,64 +2714,7 @@ function startGame(index, versionPath, setIndex) {
26302714
right: []
26312715
};
26322716

2633-
let scaleUp = true; // Variable to track scaling direction
2634-
2635-
// Clear any existing interval if there is one
2636-
if (typeof canvasScalingInterval !== "undefined") {
2637-
clearInterval(canvasScalingInterval);
2638-
}
2639-
2640-
// Only proceed if pulseOnBPM is true
2641-
if (pulseOnBPM) {
2642-
// Determine animation durations based on BPM
2643-
let scaleUpDuration, scaleDownDuration, waitTime;
2644-
if (BPM < 200) {
2645-
scaleUpDuration = 0.11; // Scaling up duration for BPM < 200
2646-
scaleDownDuration = 0.18; // Scaling down duration for BPM < 200
2647-
waitTime = 4.2;
2648-
} else if (BPM >= 200 && BPM < 250) {
2649-
scaleUpDuration = 0.15; // Scaling up duration for 200 <= BPM < 250
2650-
scaleDownDuration = 0.2; // Scaling down duration for 200 <= BPM < 250
2651-
waitTime = 2.2;
2652-
} else if (BPM >= 250) {
2653-
scaleUpDuration = 0.1; // Scaling up duration for BPM >= 250
2654-
scaleDownDuration = 0.15; // Scaling down duration for BPM >= 250
2655-
waitTime = 3;
2656-
}
2657-
2658-
const img = document.getElementById("songCoverImage");
2659-
const musicIco = document.getElementById("bouncingIcon");
2660-
2661-
// Create a new interval for scaling the canvas and pulsing the title color
2662-
canvasScalingInterval = setInterval(() => {
2663-
if (scaleUp) {
2664-
// Apply cubic-bezier easing for scaling up
2665-
title.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94), color ${MILLISECONDS_PER_BEAT / 25000}s`;
2666-
title.style.transform = "scale(1.03)";
2667-
title.style.color = getRandomColor(); // Change to a random color
2668-
2669-
img.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94)`;
2670-
img.style.transform = "scale(1.025)";
2671-
2672-
musicIco.style.transition = `transform ${scaleUpDuration}s cubic-bezier(0.17, 0.71, 0.51, 0.94)`;
2673-
musicIco.style.transform = "scale(1.4)";
2674-
2675-
// Set a timeout to scale back down after the up animation
2676-
setTimeout(() => {
2677-
// Apply ease-in easing for scaling down
2678-
title.style.transition = `transform ${scaleDownDuration}s ease-in, color ${MILLISECONDS_PER_BEAT / 1000}s`;
2679-
title.style.transform = "scale(1)";
2680-
title.style.color = "white";
2681-
2682-
img.style.transition = `transform ${scaleDownDuration}s ease-in`;
2683-
img.style.transform = "scale(1)";
2684-
2685-
musicIco.style.transition = `transform ${scaleDownDuration}s ease-in`;
2686-
musicIco.style.transform = "scale(1)";
2687-
}, MILLISECONDS_PER_BEAT / waitTime); // Wait to scale down
2688-
}
2689-
}, MILLISECONDS_PER_BEAT);
2690-
}
2717+
manageCanvasScalingInterval(true);
26912718

26922719
const songTitle = getSongTitle(currentSongPath);
26932720
const songConfig = getDynamicSpeed(currentSongPath);
@@ -2801,7 +2828,7 @@ function startGame(index, versionPath, setIndex) {
28012828

28022829
// Update the page title
28032830
indexToDisplay = setIndex >= 0 ? setIndex : currentSongIndex;
2804-
document.title = `Song ${indexToDisplay + 1}: ${getSongTitle(currentSongPath)} | Beatz Testing 4.3!`;
2831+
document.title = `Song ${indexToDisplay + 1}: ${getSongTitle(currentSongPath)} | Beatz 4.3!`;
28052832

28062833
console.log(`indexToDisplay converted in startGame: ${indexToDisplay}`);
28072834
};
@@ -3120,7 +3147,6 @@ function updateCanvas(timestamp, setIndex) {
31203147

31213148
if (gamePaused) {
31223149
// Calculate the time difference between frames
3123-
let timeDelta = (timestamp - lastTime) / 1000; // timeDelta in seconds
31243150
lastTime = timestamp;
31253151

31263152
if (!pausedTextDrawn) {
@@ -3337,6 +3363,40 @@ function updateCanvas(timestamp, setIndex) {
33373363
drawTapBoxes();
33383364
}
33393365

3366+
if (getDynamicSpeed(currentSongPath) === null && nextSpeedChange !== "No speed changes.") {
3367+
// Fallback for overlapping dynamic speeds with no dynamic speed data.
3368+
clearInterval(speedUpdater);
3369+
console.log(`Dynamic speeds encountered an "Overlap//Null" error. Speed updater cleared.`);
3370+
logError(`Overlap//Null, Speed updater cleared.`);
3371+
} else {
3372+
const dynamicSpeedsForSong = getDynamicSpeed(currentSongPath);
3373+
3374+
if (dynamicSpeedsForSong !== null && nextSpeedChange === "No speed changes.") {
3375+
// If dynamic speeds are found for this song but next speed change is not recognized
3376+
const nextSpeedExistsInDynamicSpeeds = dynamicSpeedsForSong.some((speedObj) => speedObj.noteSpeed === nextSpeedChange);
3377+
3378+
if (!nextSpeedExistsInDynamicSpeeds) {
3379+
// Mismatch in dynamic speeds detected
3380+
clearInterval(speedUpdater);
3381+
console.log(`Dynamic speeds encountered a "Mismatch//FoundNotCorrect" error. Pausing updates.`);
3382+
logError("Mismatch//FoundNotCorrect, Pausing updates and restarting song.", 10000);
3383+
logNotice("Please notify @GuayabR on twitter for this error. https://x.com/@GuayabR ", "", 10000);
3384+
logNotice("Please specify what song you were playing and if this happened at the start of the song or at a specific timestamp.", "", 10000);
3385+
logNotice(`Song: ${getSongTitle(currentSongPath)}, Index: ${currentSongIndex}`, "", 10000);
3386+
logNotice(`Dynamic speeds for ${getSongTitle(currentSongPath)}: ${dynamicSpeedInfo}`, "", 10000);
3387+
logNotice("Would be greatly appreciated! Thanks for playing Beatz!", "", 10000);
3388+
3389+
// Stop canvas updates for 1 second
3390+
setTimeout(() => {
3391+
// Restart the song after 1 second
3392+
restartSong();
3393+
}, 1000);
3394+
3395+
fallbackPause(); // Exit to avoid further canvas updates
3396+
}
3397+
}
3398+
}
3399+
33403400
if (FPS <= 32) {
33413401
PERFECT_HIT_RANGE_MIN = 534;
33423402
PERFECT_HIT_RANGE_MAX = 576;

0 commit comments

Comments
 (0)