User prompt
Please fix the bug: 'Script error.' in or related to this line: 'leaderboard.push({' Line Number: 337
User prompt
Make sure once a username is typed you no longer have to make another one and it straight away just shows you keybaird fro typing fast ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make it so it who’s teh keyboard with only the letters once you press enter
User prompt
Make sure enter as a button is put below
User prompt
Make sure they show numbers and symbols as well in keyboard when typinusernmae and her removed once enter ismoressed
User prompt
Make it so you can actually click on the keyboard while typing your username
User prompt
Mak edit so you have to type a username before starting ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'storage.leaderboard = leaderboard;' Line Number: 288 ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Add aledarebiar button so you can see it at all times
User prompt
Are usee to add alederbiar Doha tracks everybody’s data ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make it so when you press start it takes you into the part where you have to type fast
User prompt
Make an Intro screen asks for your username and has a "Start" button. The user enters a username and clicks Start.
User prompt
Please fix the bug: 'Timeout.tick error: undefined is not an object (evaluating 'document.activeElement')' in or related to this line: 'if (document.activeElement) {' Line Number: 505
User prompt
Code JavaScript to access keyboard to type
Code edit (1 edits merged)
Please save this source code
User prompt
Make it so you can acesss your keyboard while typing
User prompt
Make it so it shows your username on top of the screen when you click on letter sone by one and then their is a button called continue that takes you to the game
User prompt
Mak wit os there is a screen where you,lg in press return and than it takes you to the screen where you type ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make it so there is a screen where you have to type a username before starting and that is saved as your account when you play the game agian ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make sure button visibility is always tehre and that you can still type it even after typing that alphabet
User prompt
Don’t hide nay buttons once typing and always keep things as normal
User prompt
Make it so it doesn’t show or block any letters done
User prompt
Make it so the typing is like what an actual keyboard looks lile
User prompt
I meant make sure there’s ima space where we can type on keybaord
Code edit (1 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var LetterButton = Container.expand(function (letter, x, y) {
var self = Container.call(this);
self.letter = letter;
self.isPressed = false;
var buttonBg = self.attachAsset('letterButton', {
anchorX: 0.5,
anchorY: 0.5
});
var letterText = new Text2(letter, {
size: 60,
fill: 0xFFFFFF
});
letterText.anchor.set(0.5, 0.5);
self.addChild(letterText);
self.x = x;
self.y = y;
self.showCorrect = function () {
self.isPressed = true;
buttonBg.tint = 0x2E7D32;
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.showWrong = function () {
var originalTint = buttonBg.tint;
buttonBg.tint = 0xF44336;
tween(self, {
rotation: 0.2
}, {
duration: 50,
easing: tween.linear,
onFinish: function onFinish() {
tween(self, {
rotation: -0.2
}, {
duration: 50,
easing: tween.linear,
onFinish: function onFinish() {
tween(self, {
rotation: 0
}, {
duration: 50,
easing: tween.linear
});
}
});
}
});
LK.setTimeout(function () {
buttonBg.tint = originalTint;
}, 200);
};
self.down = function (x, y, obj) {
game.handleLetterPress(self.letter);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
// Game state variables
var alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var currentLetterIndex = 0;
var gameStarted = false;
var gameCompleted = false;
var startTime = 0;
var elapsedTime = 0;
var letterButtons = [];
var bestTime = storage.bestTime || null;
var leaderboard = storage.leaderboard || [];
// UI elements
var titleText = new Text2('Alphabet Speed Challenge', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
var instructionText = new Text2('Tap letters A to Z in order or type on keyboard', {
size: 45,
fill: 0xCCCCCC
});
instructionText.anchor.set(0.5, 0);
instructionText.x = 1024;
instructionText.y = 200;
game.addChild(instructionText);
var currentLetterText = new Text2('Current: A', {
size: 60,
fill: 0x4CAF50
});
currentLetterText.anchor.set(0.5, 0);
currentLetterText.x = 1024;
currentLetterText.y = 300;
game.addChild(currentLetterText);
var timerText = new Text2('Time: 0.00s', {
size: 50,
fill: 0xFFFFFF
});
timerText.anchor.set(0.5, 0);
timerText.x = 1024;
timerText.y = 380;
game.addChild(timerText);
var progressBarBg = game.attachAsset('progressBarBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 460
});
var progressBar = game.attachAsset('progressBar', {
anchorX: 0,
anchorY: 0.5,
x: 124,
y: 460
});
progressBar.scaleX = 0;
var bestTimeText = new Text2(bestTime ? 'Best: ' + bestTime.toFixed(2) + 's' : 'Best: --', {
size: 40,
fill: 0xFFD700
});
bestTimeText.anchor.set(0.5, 0);
bestTimeText.x = 1024;
bestTimeText.y = 500;
game.addChild(bestTimeText);
// Create leaderboard display
var leaderboardText = new Text2('Top Times:', {
size: 35,
fill: 0xFFFFFF
});
leaderboardText.anchor.set(0.5, 0);
leaderboardText.x = 1024;
leaderboardText.y = 550;
game.addChild(leaderboardText);
// Create leaderboard entries display
var leaderboardEntries = new Text2('', {
size: 25,
fill: 0xCCCCCC
});
leaderboardEntries.anchor.set(0.5, 0);
leaderboardEntries.x = 1024;
leaderboardEntries.y = 590;
game.addChild(leaderboardEntries);
// Function to update leaderboard display
function updateLeaderboardDisplay() {
var displayText = '';
var topTimes = leaderboard.slice(0, 5);
for (var i = 0; i < topTimes.length; i++) {
displayText += i + 1 + '. ' + topTimes[i].time.toFixed(2) + 's';
if (i < topTimes.length - 1) displayText += ' ';
}
leaderboardEntries.setText(displayText);
}
// Initial leaderboard display
updateLeaderboardDisplay();
// Create letter buttons in QWERTY keyboard layout
var qwertyRows = ['QWERTYUIOP', 'ASDFGHJKL', 'ZXCVBNM'];
var buttonWidth = 150;
var buttonHeight = 150;
var buttonSpacingX = 160;
var buttonSpacingY = 170;
var keyboardStartY = 650;
// Create a mapping from letter to button for easy access
var letterToButton = {};
for (var rowIndex = 0; rowIndex < qwertyRows.length; rowIndex++) {
var row = qwertyRows[rowIndex];
var rowWidth = row.length * buttonSpacingX;
var startX = 1024 - rowWidth / 2 + buttonSpacingX / 2;
for (var colIndex = 0; colIndex < row.length; colIndex++) {
var letter = row[colIndex];
var x = startX + colIndex * buttonSpacingX;
var y = keyboardStartY + rowIndex * buttonSpacingY;
var button = new LetterButton(letter, x, y);
letterButtons.push(button);
letterToButton[letter] = button;
game.addChild(button);
}
}
// Game functions
game.handleLetterPress = function (letter) {
var expectedLetter = alphabet[currentLetterIndex];
if (letter === expectedLetter) {
// Correct letter
if (!gameStarted) {
gameStarted = true;
startTime = Date.now();
}
LK.getSound('correct').play();
letterButtons[currentLetterIndex].showCorrect();
currentLetterIndex++;
// Update progress
var progress = currentLetterIndex / 26;
progressBar.scaleX = progress;
if (currentLetterIndex < 26) {
currentLetterText.setText('Current: ' + alphabet[currentLetterIndex]);
} else {
// Game completed
gameCompleted = true;
var finalTime = (Date.now() - startTime) / 1000;
elapsedTime = finalTime;
LK.getSound('complete').play();
currentLetterText.setText('COMPLETED!');
currentLetterText.fill = "#FFD700";
// Add to leaderboard
leaderboard.push({
time: finalTime,
date: Date.now()
});
// Sort leaderboard by time (best first) and keep top 10
leaderboard.sort(function (a, b) {
return a.time - b.time;
});
if (leaderboard.length > 10) {
leaderboard = leaderboard.slice(0, 10);
}
// Save leaderboard to storage
storage.leaderboard = leaderboard;
// Check for new best time
if (!bestTime || finalTime < bestTime) {
bestTime = finalTime;
storage.bestTime = bestTime;
bestTimeText.setText('NEW BEST: ' + bestTime.toFixed(2) + 's');
bestTimeText.fill = "#FF4444";
// Celebrate new best time
tween(bestTimeText, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bestTimeText, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeIn
});
}
});
} else {
bestTimeText.setText('Best: ' + bestTime.toFixed(2) + 's');
}
LK.setScore(Math.round(1 / finalTime * 1000)); // Score based on speed
// Update leaderboard display
updateLeaderboardDisplay();
// Show restart instruction
LK.setTimeout(function () {
instructionText.setText('Tap anywhere or press any key to restart');
}, 1000);
}
} else {
// Wrong letter
LK.getSound('wrong').play();
if (letterToButton[letter]) {
letterToButton[letter].showWrong();
}
}
};
game.resetGame = function () {
currentLetterIndex = 0;
gameStarted = false;
gameCompleted = false;
startTime = 0;
elapsedTime = 0;
currentLetterText.setText('Current: A');
currentLetterText.fill = "#4CAF50";
timerText.setText('Time: 0.00s');
instructionText.setText('Tap letters A to Z in order or type on keyboard');
progressBar.scaleX = 0;
// Reset all letter buttons
for (var i = 0; i < letterButtons.length; i++) {
var button = letterButtons[i];
button.isPressed = false;
button.scaleX = 1;
button.scaleY = 1;
}
};
// Keyboard event handling
game.keyPressed = function (key) {
if (gameCompleted) {
game.resetGame();
return;
}
// Convert key to uppercase for consistency
var upperKey = key.toUpperCase();
// Check if it's a valid letter A-Z
if (upperKey >= 'A' && upperKey <= 'Z') {
game.handleLetterPress(upperKey);
}
};
// Add keyboard event listener
LK.on('keydown', function (event) {
if (event.key) {
game.keyPressed(event.key);
}
});
game.down = function (x, y, obj) {
if (gameCompleted) {
game.resetGame();
}
};
game.update = function () {
if (gameStarted && !gameCompleted) {
elapsedTime = (Date.now() - startTime) / 1000;
timerText.setText('Time: ' + elapsedTime.toFixed(2) + 's');
}
}; ===================================================================
--- original.js
+++ change.js
@@ -96,17 +96,9 @@
var startTime = 0;
var elapsedTime = 0;
var letterButtons = [];
var bestTime = storage.bestTime || null;
-var username = storage.username || '';
-var showingIntro = true; // Show intro screen first
-var showingTypingChallenge = false; // Show typing challenge after intro
-var currentUsername = '';
-// Typing challenge variables
-var typingText = "The quick brown fox jumps over the lazy dog";
-var typingIndex = 0;
-var typingStartTime = 0;
-var typingStarted = false;
+var leaderboard = storage.leaderboard || [];
// UI elements
var titleText = new Text2('Alphabet Speed Challenge', {
size: 80,
fill: 0xFFFFFF
@@ -159,157 +151,38 @@
bestTimeText.anchor.set(0.5, 0);
bestTimeText.x = 1024;
bestTimeText.y = 500;
game.addChild(bestTimeText);
-// Intro screen elements
-var introContainer = new Container();
-var introTitle = new Text2('Alphabet Speed Challenge', {
- size: 100,
+// Create leaderboard display
+var leaderboardText = new Text2('Top Times:', {
+ size: 35,
fill: 0xFFFFFF
});
-introTitle.anchor.set(0.5, 0.5);
-introTitle.x = 1024;
-introTitle.y = 800;
-introContainer.addChild(introTitle);
-var usernameLabel = new Text2('Enter Username:', {
- size: 60,
+leaderboardText.anchor.set(0.5, 0);
+leaderboardText.x = 1024;
+leaderboardText.y = 550;
+game.addChild(leaderboardText);
+// Create leaderboard entries display
+var leaderboardEntries = new Text2('', {
+ size: 25,
fill: 0xCCCCCC
});
-usernameLabel.anchor.set(0.5, 0.5);
-usernameLabel.x = 1024;
-usernameLabel.y = 1100;
-introContainer.addChild(usernameLabel);
-var usernameInput = new Text2('', {
- size: 70,
- fill: 0x4CAF50
-});
-usernameInput.anchor.set(0.5, 0.5);
-usernameInput.x = 1024;
-usernameInput.y = 1200;
-introContainer.addChild(usernameInput);
-var startButton = new Container();
-var startButtonBg = startButton.attachAsset('letterButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2.5,
- scaleY: 1
-});
-startButtonBg.tint = 0x4CAF50;
-startButton.x = 1024;
-startButton.y = 1400;
-var startButtonText = new Text2('Start', {
- size: 70,
- fill: 0xFFFFFF
-});
-startButtonText.anchor.set(0.5, 0.5);
-startButton.addChild(startButtonText);
-startButton.down = function (x, y, obj) {
- if (currentUsername.length > 0) {
- username = currentUsername;
- storage.username = username;
- game.showTypingChallenge();
+leaderboardEntries.anchor.set(0.5, 0);
+leaderboardEntries.x = 1024;
+leaderboardEntries.y = 590;
+game.addChild(leaderboardEntries);
+// Function to update leaderboard display
+function updateLeaderboardDisplay() {
+ var displayText = '';
+ var topTimes = leaderboard.slice(0, 5);
+ for (var i = 0; i < topTimes.length; i++) {
+ displayText += i + 1 + '. ' + topTimes[i].time.toFixed(2) + 's';
+ if (i < topTimes.length - 1) displayText += ' ';
}
-};
-introContainer.addChild(startButton);
-game.addChild(introContainer);
-// Typing challenge screen elements
-var typingContainer = new Container();
-var typingTitle = new Text2('Type Fast Challenge', {
- size: 100,
- fill: 0xFFFFFF
-});
-typingTitle.anchor.set(0.5, 0.5);
-typingTitle.x = 1024;
-typingTitle.y = 400;
-typingContainer.addChild(typingTitle);
-var typingInstructions = new Text2('Type the text below as fast as you can!', {
- size: 60,
- fill: 0xCCCCCC
-});
-typingInstructions.anchor.set(0.5, 0.5);
-typingInstructions.x = 1024;
-typingInstructions.y = 500;
-typingContainer.addChild(typingInstructions);
-var typingTextDisplay = new Text2(typingText, {
- size: 50,
- fill: 0x4CAF50
-});
-typingTextDisplay.anchor.set(0.5, 0.5);
-typingTextDisplay.x = 1024;
-typingTextDisplay.y = 600;
-typingContainer.addChild(typingTextDisplay);
-var typingInput = new Text2('', {
- size: 50,
- fill: 0xFFFFFF
-});
-typingInput.anchor.set(0.5, 0.5);
-typingInput.x = 1024;
-typingInput.y = 700;
-typingContainer.addChild(typingInput);
-var typingProgress = new Text2('0 / ' + typingText.length, {
- size: 40,
- fill: 0xFFD700
-});
-typingProgress.anchor.set(0.5, 0.5);
-typingProgress.x = 1024;
-typingProgress.y = 800;
-typingContainer.addChild(typingProgress);
-var continueButton = new Container();
-var continueButtonBg = continueButton.attachAsset('letterButton', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 2.5,
- scaleY: 1
-});
-continueButtonBg.tint = 0x4CAF50;
-continueButton.x = 1024;
-continueButton.y = 1000;
-var continueButtonText = new Text2('Continue', {
- size: 70,
- fill: 0xFFFFFF
-});
-continueButtonText.anchor.set(0.5, 0.5);
-continueButton.addChild(continueButtonText);
-continueButton.visible = false; // Hidden until typing is complete
-continueButton.down = function (x, y, obj) {
- game.startGame();
-};
-typingContainer.addChild(continueButton);
-typingContainer.visible = false; // Hidden initially
-game.addChild(typingContainer);
-var welcomeText = new Text2('', {
- size: 50,
- fill: 0xFFD700
-});
-welcomeText.anchor.set(0.5, 0);
-welcomeText.x = 1024;
-welcomeText.y = 50;
-game.addChild(welcomeText);
-// Initialize screen visibility
-if (showingIntro) {
- // Hide all game elements initially
- titleText.visible = false;
- instructionText.visible = false;
- currentLetterText.visible = false;
- timerText.visible = false;
- progressBarBg.visible = false;
- progressBar.visible = false;
- bestTimeText.visible = false;
- welcomeText.visible = false;
- typingContainer.visible = false;
- for (var i = 0; i < letterButtons.length; i++) {
- letterButtons[i].visible = false;
- }
- // Set initial username if exists
- if (username) {
- currentUsername = username;
- usernameInput.setText(currentUsername);
- }
-} else {
- introContainer.visible = false;
- typingContainer.visible = false;
- welcomeText.setText('Welcome back, ' + username + '!');
+ leaderboardEntries.setText(displayText);
}
+// Initial leaderboard display
+updateLeaderboardDisplay();
// Create letter buttons in QWERTY keyboard layout
var qwertyRows = ['QWERTYUIOP', 'ASDFGHJKL', 'ZXCVBNM'];
var buttonWidth = 150;
var buttonHeight = 150;
@@ -356,8 +229,22 @@
elapsedTime = finalTime;
LK.getSound('complete').play();
currentLetterText.setText('COMPLETED!');
currentLetterText.fill = "#FFD700";
+ // Add to leaderboard
+ leaderboard.push({
+ time: finalTime,
+ date: Date.now()
+ });
+ // Sort leaderboard by time (best first) and keep top 10
+ leaderboard.sort(function (a, b) {
+ return a.time - b.time;
+ });
+ if (leaderboard.length > 10) {
+ leaderboard = leaderboard.slice(0, 10);
+ }
+ // Save leaderboard to storage
+ storage.leaderboard = leaderboard;
// Check for new best time
if (!bestTime || finalTime < bestTime) {
bestTime = finalTime;
storage.bestTime = bestTime;
@@ -383,8 +270,10 @@
} else {
bestTimeText.setText('Best: ' + bestTime.toFixed(2) + 's');
}
LK.setScore(Math.round(1 / finalTime * 1000)); // Score based on speed
+ // Update leaderboard display
+ updateLeaderboardDisplay();
// Show restart instruction
LK.setTimeout(function () {
instructionText.setText('Tap anywhere or press any key to restart');
}, 1000);
@@ -415,68 +304,10 @@
button.scaleX = 1;
button.scaleY = 1;
}
};
-// Keyboard event handling with improved key detection
+// Keyboard event handling
game.keyPressed = function (key) {
- // Handle special keys consistently
- if (key === 'Return') {
- key = 'Enter';
- }
- if (key === 'Delete') {
- key = 'Backspace';
- }
- if (showingIntro) {
- if (key === 'Enter') {
- if (currentUsername.length > 0) {
- username = currentUsername;
- storage.username = username;
- game.showTypingChallenge();
- }
- return;
- }
- if (key === 'Backspace') {
- currentUsername = currentUsername.slice(0, -1);
- usernameInput.setText(currentUsername);
- return;
- }
- // Add letter/number to username
- if (key >= 'A' && key <= 'Z' || key >= 'a' && key <= 'z' || key >= '0' && key <= '9') {
- if (currentUsername.length < 15) {
- currentUsername += key;
- usernameInput.setText(currentUsername);
- }
- }
- return;
- }
- if (showingTypingChallenge) {
- if (!typingStarted) {
- typingStarted = true;
- typingStartTime = Date.now();
- }
- if (key === 'Backspace') {
- if (typingIndex > 0) {
- typingIndex--;
- game.updateTypingDisplay();
- }
- return;
- }
- // Check if typed character matches expected character
- if (typingIndex < typingText.length && key === typingText[typingIndex]) {
- typingIndex++;
- game.updateTypingDisplay();
- // Check if typing is complete
- if (typingIndex >= typingText.length) {
- var typingTime = (Date.now() - typingStartTime) / 1000;
- LK.getSound('complete').play();
- continueButton.visible = true;
- }
- } else if (key >= ' ' && key <= '~') {
- // Wrong character, show visual feedback
- LK.getSound('wrong').play();
- }
- return;
- }
if (gameCompleted) {
game.resetGame();
return;
}
@@ -486,82 +317,15 @@
if (upperKey >= 'A' && upperKey <= 'Z') {
game.handleLetterPress(upperKey);
}
};
-// Ensure the game canvas can receive keyboard focus
-game.interactive = true;
-game.buttonMode = true;
-// Add keyboard event listener with better accessibility
+// Add keyboard event listener
LK.on('keydown', function (event) {
- // Prevent default browser behavior for better keyboard accessibility
- if (event.preventDefault) {
- event.preventDefault();
- }
if (event.key) {
game.keyPressed(event.key);
}
});
-// Add additional keyboard event for better compatibility
-LK.on('keyup', function (event) {
- // Allow for additional keyboard interactions if needed
-});
-// Ensure keyboard focus is maintained
-LK.setTimeout(function () {
- if (typeof document !== 'undefined' && document.activeElement) {
- document.activeElement.blur();
- }
- // Focus on the game canvas to ensure keyboard input is captured
- if (typeof document !== 'undefined' && document.body) {
- document.body.focus();
- }
-}, 100);
-game.showTypingChallenge = function () {
- showingIntro = false;
- showingTypingChallenge = true;
- introContainer.visible = false;
- typingContainer.visible = true;
- // Reset typing challenge
- typingIndex = 0;
- typingStarted = false;
- typingStartTime = 0;
- continueButton.visible = false;
- game.updateTypingDisplay();
-};
-game.updateTypingDisplay = function () {
- var typedText = typingText.substring(0, typingIndex);
- var remainingText = typingText.substring(typingIndex);
- // Update input display to show what's been typed
- typingInput.setText(typedText);
- typingProgress.setText(typingIndex + ' / ' + typingText.length);
-};
-game.startGame = function () {
- showingIntro = false;
- showingTypingChallenge = false;
- introContainer.visible = false;
- typingContainer.visible = false;
- titleText.visible = true;
- instructionText.visible = true;
- currentLetterText.visible = true;
- timerText.visible = true;
- progressBarBg.visible = true;
- progressBar.visible = true;
- bestTimeText.visible = true;
- welcomeText.visible = true;
- for (var i = 0; i < letterButtons.length; i++) {
- letterButtons[i].visible = true;
- }
- welcomeText.setText('Welcome, ' + username + '!');
- // Ensure keyboard accessibility for game
- LK.setTimeout(function () {
- if (typeof document !== 'undefined' && document.body) {
- document.body.focus();
- }
- }, 50);
-};
game.down = function (x, y, obj) {
- if (showingIntro || showingTypingChallenge) {
- return;
- }
if (gameCompleted) {
game.resetGame();
}
};