Code edit (4 edits merged)
Please save this source code
User prompt
add the intervel time perios between word by word 7sec
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading '0')' in or related to this line: 'tween(obj.children[0], {' Line Number: 261
User prompt
Please fix the bug: 'inputBackground is not defined' in or related to this line: 'inputBackground.y = -50;' Line Number: 111
User prompt
Please fix the bug: 'LK.gui.bottom.swapChildren is not a function' in or related to this line: 'LK.gui.bottom.swapChildren(inputDisplay, inputBackground);' Line Number: 121
Code edit (1 edits merged)
Please save this source code
User prompt
Typing Hero FRVR
Initial prompt
Typing Hero FRVR Become a keyboard ninja! Words are falling fast — type them before they hit the bottom. Boost your typing speed, sharpen your spelling, and level up your reflexes in this fast-paced, fun typing challenge! 🎯 How to Play: Watch the words fall from the top. Type them exactly before they hit the bottom. Each correct word earns points and slows down the fall — but only for a moment! 🎓 Perfect For: Kids, students, and adults wanting to improve their typing skills. Anyone who loves fast, addictive mini-games with a purpose. 🧠 Train your brain + fingers while having fun!
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, difficulty: 1 }); /**** * Classes ****/ var FallingWord = Container.expand(function (wordText, speed) { var self = Container.call(this); // Word properties self.wordText = wordText; self.speed = speed || 2; self.typed = ""; self.completed = false; // Create background for the word var background = self.attachAsset('wordBackground', { anchorX: 0.5, anchorY: 0.5 }); // Create text element self.wordDisplay = new Text2(wordText, { size: 60, fill: 0xFFFFFF }); self.wordDisplay.anchor.set(0.5, 0.5); self.addChild(self.wordDisplay); // Create progress indicator (what's been typed correctly so far) self.progressDisplay = new Text2("", { size: 60, fill: 0x00FF00 }); self.progressDisplay.anchor.set(0.5, 0.5); self.addChild(self.progressDisplay); // Update what has been typed correctly self.updateTyped = function (typedText) { self.typed = typedText; self.progressDisplay.setText(typedText); // Check if word is completed if (typedText === self.wordText) { self.completed = true; return true; } return false; }; // Check if character matches the next expected one self.matchesNextChar = function (_char) { return self.wordText.substring(self.typed.length, self.typed.length + 1).toLowerCase() === _char.toLowerCase(); }; // Update method called every frame self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ // Game settings and variables var words = ["typing", "hero", "word", "game", "play", "fast", "quick", "jump", "over", "fox", "lazy", "dog", "letter", "keyboard", "speed", "challenge", "practice", "improve", "skill", "focus", "learn", "master", "type", "write", "read"]; var longWords = ["keyboard", "challenge", "practice", "improvement", "experience", "development", "professional", "application", "performance", "intelligence", "communication", "organization", "understanding", "appreciation", "participation", "environment", "opportunity", "relationship", "consideration", "determination"]; var activeWords = []; var gameActive = false; var currentInput = ""; var spawnInterval = 2000; // Initial spawn interval in ms var lastSpawnTime = 0; var score = 0; var difficulty = storage.difficulty || 1; var baseSpeed = 1; var wordCount = 0; var gameTicks = 0; // UI elements var scoreDisplay = new Text2("Score: 0", { size: 70, fill: 0xFFFFFF }); scoreDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(scoreDisplay); var highScoreDisplay = new Text2("High Score: " + storage.highScore, { size: 50, fill: 0xFFCC00 }); highScoreDisplay.anchor.set(0.5, 0); highScoreDisplay.y = 80; LK.gui.top.addChild(highScoreDisplay); var inputDisplay = new Text2("", { size: 80, fill: 0xFFFFFF }); var inputBackground = new Text2("", { size: 80, fill: 0x000000 }); inputBackground.anchor.set(0.5, 1); inputBackground.y = -50; LK.gui.bottom.addChild(inputBackground); inputDisplay.anchor.set(0.5, 1); inputDisplay.y = -20; LK.gui.bottom.addChild(inputDisplay); // Initialize keyboard var keyboard = new Container(); game.addChild(keyboard); keyboard.y = 2400; keyboard.isActive = false; // Game methods function startGame() { gameActive = true; activeWords = []; currentInput = ""; score = 0; wordCount = 0; gameTicks = 0; spawnInterval = 2000; LK.setScore(0); scoreDisplay.setText("Score: 0"); updateInput(""); LK.playMusic('bgMusic'); } function endGame() { gameActive = false; // Update high score if (score > storage.highScore) { storage.highScore = score; highScoreDisplay.setText("High Score: " + storage.highScore); } LK.stopMusic(); LK.showGameOver(); } function getRandomWord() { // Choose longer words as difficulty increases var wordPool = difficulty > 2 ? longWords.concat(words) : words; return wordPool[Math.floor(Math.random() * wordPool.length)]; } function updateInput(text) { currentInput = text; inputDisplay.setText(text); } function spawnWord() { var word = getRandomWord(); var fallingWord = new FallingWord(word, baseSpeed + difficulty * 0.5); // Position randomly along the top of the screen fallingWord.x = Math.random() * (2048 - 400) + 200; // Keep away from edges fallingWord.y = 100; game.addChild(fallingWord); activeWords.push(fallingWord); wordCount++; // Increase difficulty based on words spawned if (wordCount % 10 === 0) { increaseDifficulty(); } } function increaseDifficulty() { difficulty += 0.2; spawnInterval = Math.max(800, spawnInterval - 100); storage.difficulty = difficulty; } function checkInput(_char2) { // Add character to current input var newInput = currentInput + _char2; updateInput(newInput); // Check if we have active words that match the input for (var i = 0; i < activeWords.length; i++) { var word = activeWords[i]; // If the current input is the start of the word if (word.wordText.toLowerCase().startsWith(newInput.toLowerCase())) { // If the word is completed if (newInput.length === word.wordText.length) { // Word is fully typed score += word.wordText.length * 10; LK.setScore(score); scoreDisplay.setText("Score: " + score); // Play sound and animation LK.getSound('correctWord').play(); LK.effects.flashObject(word, 0x00ff00, 400); // Remove the word tween(word, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { game.removeChild(word); activeWords.splice(activeWords.indexOf(word), 1); } }); updateInput(""); return true; } // Update the word's typed progress word.updateTyped(newInput); return true; } } // If we get here, the input doesn't match any active word // Consider if we want to add a negative feedback return false; } function clearInput() { updateInput(""); // Reset all word progress displays for (var i = 0; i < activeWords.length; i++) { activeWords[i].updateTyped(""); } } // Keyboard input handling var keyboardButtons = []; var keyboardLayout = [['Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'], ['A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'], ['Z', 'X', 'C', 'V', 'B', 'N', 'M']]; function createKeyboard() { var buttonSize = 150; var spacing = 20; var rows = keyboardLayout.length; for (var row = 0; row < rows; row++) { var keys = keyboardLayout[row]; var rowWidth = keys.length * (buttonSize + spacing); var startX = (2048 - rowWidth) / 2; for (var i = 0; i < keys.length; i++) { var key = keys[i]; var keyButton = new Container(); var keyBackground = LK.getAsset('wordBackground', { width: buttonSize, height: buttonSize, anchorX: 0.5, anchorY: 0.5, tint: 0x555555 }); keyButton.addChild(keyBackground); var keyText = new Text2(key, { size: 60, fill: 0xFFFFFF }); keyText.anchor.set(0.5, 0.5); keyButton.addChild(keyText); keyButton.x = startX + i * (buttonSize + spacing) + buttonSize / 2; keyButton.y = row * (buttonSize + spacing) + buttonSize / 2; keyButton.keyValue = key; // Add key press handler keyButton.interactive = true; keyButton.down = function (x, y, obj) { checkInput(obj.keyValue); // Visual feedback if (obj.children && obj.children[0]) { tween(obj.children[0], { tint: 0x3498db }, { duration: 100 }); } }; keyButton.up = function (x, y, obj) { // Reset visual state if (obj.children && obj.children[0]) { tween(obj.children[0], { tint: 0x555555 }, { duration: 100 }); } }; keyboard.addChild(keyButton); keyboardButtons.push(keyButton); } } // Add space bar var spaceBar = new Container(); var spaceBackground = LK.getAsset('wordBackground', { width: 800, height: buttonSize, anchorX: 0.5, anchorY: 0.5, tint: 0x555555 }); spaceBar.addChild(spaceBackground); var spaceText = new Text2("SPACE", { size: 60, fill: 0xFFFFFF }); spaceText.anchor.set(0.5, 0.5); spaceBar.addChild(spaceText); spaceBar.x = 2048 / 2; spaceBar.y = rows * (buttonSize + spacing) + buttonSize / 2; spaceBar.interactive = true; spaceBar.down = function (x, y, obj) { checkInput(" "); tween(obj.children[0], { tint: 0x3498db }, { duration: 100 }); }; spaceBar.up = function (x, y, obj) { tween(obj.children[0], { tint: 0x555555 }, { duration: 100 }); }; keyboard.addChild(spaceBar); keyboardButtons.push(spaceBar); // Add delete button var deleteButton = new Container(); var deleteBackground = LK.getAsset('wordBackground', { width: 200, height: buttonSize, anchorX: 0.5, anchorY: 0.5, tint: 0xff5555 }); deleteButton.addChild(deleteBackground); var deleteText = new Text2("DEL", { size: 60, fill: 0xFFFFFF }); deleteText.anchor.set(0.5, 0.5); deleteButton.addChild(deleteText); deleteButton.x = 2048 - 150; deleteButton.y = rows * (buttonSize + spacing) + buttonSize / 2; deleteButton.interactive = true; deleteButton.down = function (x, y, obj) { clearInput(); tween(obj.children[0], { tint: 0xff0000 }, { duration: 100 }); }; deleteButton.up = function (x, y, obj) { tween(obj.children[0], { tint: 0xff5555 }, { duration: 100 }); }; keyboard.addChild(deleteButton); keyboardButtons.push(deleteButton); } // Create the keyboard createKeyboard(); // Start button var startButton = new Container(); var startButtonBg = LK.getAsset('wordBackground', { width: 600, height: 200, anchorX: 0.5, anchorY: 0.5, tint: 0x2ecc71 }); startButton.addChild(startButtonBg); var startButtonText = new Text2("START GAME", { size: 80, fill: 0xFFFFFF }); startButtonText.anchor.set(0.5, 0.5); startButton.addChild(startButtonText); startButton.x = 2048 / 2; startButton.y = 2732 / 2; startButton.interactive = true; startButton.down = function () { startGame(); startButton.visible = false; }; game.addChild(startButton); // Game title var gameTitle = new Text2("Typing Hero FRVR", { size: 140, fill: 0xFFFFFF }); gameTitle.anchor.set(0.5, 0.5); gameTitle.x = 2048 / 2; gameTitle.y = 600; game.addChild(gameTitle); // Instructions var instructions = new Text2("Type the falling words before they reach the bottom", { size: 60, fill: 0xFFFFFF }); instructions.anchor.set(0.5, 0.5); instructions.x = 2048 / 2; instructions.y = 700; game.addChild(instructions); // Game update loop game.update = function () { if (!gameActive) { return; } gameTicks++; // Spawn new words at intervals if (Date.now() - lastSpawnTime > spawnInterval) { spawnWord(); lastSpawnTime = Date.now(); } // Update all active words for (var i = activeWords.length - 1; i >= 0; i--) { var word = activeWords[i]; // Check if word has reached bottom if (word.y > 2200) { // Play hit bottom sound LK.getSound('wordHitBottom').play(); // Flash screen and remove word LK.effects.flashScreen(0xff0000, 300); game.removeChild(word); activeWords.splice(i, 1); // End game if word hits bottom endGame(); return; } } }; // Start background music LK.playMusic('bgMusic');
===================================================================
--- original.js
+++ change.js
@@ -248,21 +248,25 @@
keyButton.interactive = true;
keyButton.down = function (x, y, obj) {
checkInput(obj.keyValue);
// Visual feedback
- tween(obj.children[0], {
- tint: 0x3498db
- }, {
- duration: 100
- });
+ if (obj.children && obj.children[0]) {
+ tween(obj.children[0], {
+ tint: 0x3498db
+ }, {
+ duration: 100
+ });
+ }
};
keyButton.up = function (x, y, obj) {
// Reset visual state
- tween(obj.children[0], {
- tint: 0x555555
- }, {
- duration: 100
- });
+ if (obj.children && obj.children[0]) {
+ tween(obj.children[0], {
+ tint: 0x555555
+ }, {
+ duration: 100
+ });
+ }
};
keyboard.addChild(keyButton);
keyboardButtons.push(keyButton);
}