Code edit (1 edits merged)
Please save this source code
User prompt
Change the word background color to bright pink
User prompt
Change the word background color to bright purple
User prompt
change the word background mixing of red and purple
User prompt
add background asset
Code edit (3 edits merged)
Please save this source code
User prompt
each word get only 5 points
Code edit (1 edits merged)
Please save this source code
User prompt
display the two levels in the menu startign UI
User prompt
level 1 --only 5 words
User prompt
display the two levels in UI
User prompt
after loosing or winning the game display the accuracy and score
User prompt
add two levels
Code edit (2 edits merged)
Please save this source code
User prompt
Adjust word falling speed to ensure each word takes 80 seconds to reach the bottom
User prompt
Adjust word falling speed to ensure each word takes 55 seconds to reach the bottom
User prompt
every word take 25 sec to fall on the bottom
User prompt
Ensure a new word spawns every 50 seconds after the previous word
User prompt
if one letter is coming after 20 sec another word has to come
User prompt
add delete option in the game
Code edit (2 edits merged)
Please save this source code
User prompt
add when player correctly type the each word it will give the 2 points
User prompt
add when player correctly type the each word it will give the one points
User prompt
add when player correctly type the each word it will give the 5 points
User prompt
fix the bug when the player clicking the letters in the keyboard its not responding
/**** * 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); self.wordText = wordText; self.speed = speed || 2; self.typed = ""; self.completed = false; var background = self.attachAsset('wordBackground', { anchorX: 0.5, anchorY: 0.5 }); self.wordDisplay = new Text2(wordText, { size: 60, fill: 0xFFFFFF }); self.wordDisplay.anchor.set(0.5, 0.5); self.addChild(self.wordDisplay); self.progressDisplay = new Text2("", { size: 60, fill: 0x00FF00 }); self.progressDisplay.anchor.set(0.5, 0.5); self.addChild(self.progressDisplay); self.updateTyped = function (typedText) { self.typed = typedText; self.progressDisplay.setText(typedText); if (typedText === self.wordText) { self.completed = true; return true; } return false; }; self.update = function () { self.y += self.speed; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a2e }); /**** * Game Code ****/ var words = ["type", "hero", "word", "game", "play", "fast", "quick"]; var longWords = ["keyboard", "challenge", "practice", "improvement", "experience", "development", "professional", "application", "performance", "intelligence"]; var activeWords = []; var gameActive = false; var currentInput = ""; var spawnInterval = 50000; var lastSpawnTime = 0; var score = 0; var difficulty = storage.difficulty || 1; var level = 1; var levelThreshold = 100; var baseSpeed = 1; var wordCount = 0; var gameTicks = 0; 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 levelDisplay = new Text2("Level: 1", { size: 50, fill: 0x00FF00 }); levelDisplay.anchor.set(0.5, 0); levelDisplay.y = 140; LK.gui.top.addChild(levelDisplay); 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); var keyboard = new Container(); game.addChild(keyboard); keyboard.y = 2400; function startGame() { gameActive = true; activeWords = []; currentInput = ""; score = 0; wordCount = 0; gameTicks = 0; spawnInterval = 1500; difficulty = 1; level = 1; scoreDisplay.setText("Score: 0"); updateInput(""); LK.playMusic('bgMusic'); } function endGame() { gameActive = false; if (score > storage.highScore) { storage.highScore = score; highScoreDisplay.setText("High Score: " + storage.highScore); } LK.stopMusic(); LK.showGameOver(); } function getRandomWord() { 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, 108 / 80); fallingWord.x = Math.random() * (2048 - 400) + 200; fallingWord.y = 100; game.addChild(fallingWord); activeWords.push(fallingWord); wordCount++; if (wordCount % 10 === 0) { increaseDifficulty(); } } function increaseDifficulty() { difficulty += 0.2; spawnInterval = Math.max(800, spawnInterval - 100); storage.difficulty = difficulty; } function checkInput(_char) { var newInput = currentInput + _char; updateInput(newInput); for (var i = 0; i < activeWords.length; i++) { var word = activeWords[i]; if (word.wordText.toLowerCase().startsWith(newInput.toLowerCase())) { if (newInput.length === word.wordText.length) { score += word.wordText.length * 10 + 2; LK.setScore(score); scoreDisplay.setText("Score: " + score); if (score >= levelThreshold * level) { levelDisplay.setText("Level: " + level); level++; increaseDifficulty(); LK.effects.flashScreen(0x00ff00, 1000); } LK.getSound('correctWord').play(); LK.effects.flashObject(word, 0x00ff00, 400); tween(word, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { game.removeChild(word); activeWords.splice(activeWords.indexOf(word), 1); } }); updateInput(""); return true; } word.updateTyped(newInput); return true; } } return false; } function clearInput() { updateInput(""); for (var i = 0; i < activeWords.length; i++) { activeWords[i].updateTyped(""); } } 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 = 80; var spacing = 40; 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; keyButton.interactive = true; keyButton.down = function (x, y, obj) { if (this.keyValue) { checkInput(this.keyValue); } if (obj.children && obj.children[0]) { tween(obj.children[0], { tint: 0x3498db }, { duration: 100 }); } }; keyButton.up = function (x, y, obj) { if (obj.children && obj.children[0]) { tween(obj.children[0], { tint: 0x555555 }, { duration: 100 }); } }; keyboard.addChild(keyButton); keyboardButtons.push(keyButton); } } // Add delete key and space bar similar to above... } createKeyboard(); startGame(); game.update = function () { if (!gameActive) { return; } var now = Date.now(); if (now - lastSpawnTime >= spawnInterval) { spawnWord(); lastSpawnTime = now; } for (var i = activeWords.length - 1; i >= 0; i--) { var word = activeWords[i]; word.update(); if (word.y > 2732) { LK.getSound('wordHitBottom').play(); game.removeChild(word); activeWords.splice(i, 1); endGame(); } } };
===================================================================
--- original.js
+++ change.js
@@ -60,45 +60,15 @@
var words = ["type", "hero", "word", "game", "play", "fast", "quick"];
var longWords = ["keyboard", "challenge", "practice", "improvement", "experience", "development", "professional", "application", "performance", "intelligence"];
var activeWords = [];
var gameActive = false;
-var startMenu = new Container();
-game.addChild(startMenu);
-var level1Button = new Text2("Level 1", {
- size: 100,
- fill: 0xFFFFFF
-});
-level1Button.anchor.set(0.5, 0.5);
-level1Button.x = 2048 / 2;
-level1Button.y = 1000;
-level1Button.interactive = true;
-level1Button.down = function () {
- level = 1;
- startGame();
- game.removeChild(startMenu);
-};
-startMenu.addChild(level1Button);
-var level2Button = new Text2("Level 2", {
- size: 100,
- fill: 0xFFFFFF
-});
-level2Button.anchor.set(0.5, 0.5);
-level2Button.x = 2048 / 2;
-level2Button.y = 1200;
-level2Button.interactive = true;
-level2Button.down = function () {
- level = 2;
- startGame();
- game.removeChild(startMenu);
-};
-startMenu.addChild(level2Button);
var currentInput = "";
-var spawnInterval = 50000; // Set the interval time period between word spawns to 50 seconds
+var spawnInterval = 50000;
var lastSpawnTime = 0;
var score = 0;
var difficulty = storage.difficulty || 1;
var level = 1;
-var levelThreshold = 100; // Score threshold to advance to the next level
+var levelThreshold = 100;
var baseSpeed = 1;
var wordCount = 0;
var gameTicks = 0;
var scoreDisplay = new Text2("Score: 0", {
@@ -170,9 +140,9 @@
inputDisplay.setText(text);
}
function spawnWord() {
var word = getRandomWord();
- var fallingWord = new FallingWord(word, 108 / 80); // Adjust speed to ensure 80 seconds to fall
+ var fallingWord = new FallingWord(word, 108 / 80);
fallingWord.x = Math.random() * (2048 - 400) + 200;
fallingWord.y = 100;
game.addChild(fallingWord);
activeWords.push(fallingWord);
@@ -199,9 +169,9 @@
if (score >= levelThreshold * level) {
levelDisplay.setText("Level: " + level);
level++;
increaseDifficulty();
- LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green to indicate level up
+ LK.effects.flashScreen(0x00ff00, 1000);
}
LK.getSound('correctWord').play();
LK.effects.flashObject(word, 0x00ff00, 400);
tween(word, {
@@ -262,18 +232,18 @@
keyButton.down = function (x, y, obj) {
if (this.keyValue) {
checkInput(this.keyValue);
}
- if (obj.children && obj.children.length > 0 && obj.children[0]) {
+ if (obj.children && obj.children[0]) {
tween(obj.children[0], {
tint: 0x3498db
}, {
duration: 100
});
}
};
keyButton.up = function (x, y, obj) {
- if (obj.children && obj.children.length > 0 && obj.children[0]) {
+ if (obj.children && obj.children[0]) {
tween(obj.children[0], {
tint: 0x555555
}, {
duration: 100
@@ -283,60 +253,12 @@
keyboard.addChild(keyButton);
keyboardButtons.push(keyButton);
}
}
- // Delete key
- var deleteKey = new Container();
- var deleteBackground = LK.getAsset('wordBackground', {
- width: buttonSize,
- height: buttonSize,
- anchorX: 0.5,
- anchorY: 0.5,
- tint: 0x555555
- });
- deleteKey.addChild(deleteBackground);
- var deleteText = new Text2("DEL", {
- size: 60,
- fill: 0xFFFFFF
- });
- deleteText.anchor.set(0.5, 0.5);
- deleteKey.addChild(deleteText);
- deleteKey.x = 2048 - (buttonSize + spacing) * 1.5;
- deleteKey.y = rows * (buttonSize + spacing) + buttonSize / 2;
- deleteKey.interactive = true;
- deleteKey.down = function () {
- if (currentInput.length > 0) {
- updateInput(currentInput.slice(0, -1));
- }
- };
- keyboard.addChild(deleteKey);
- // 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.y = rows * (buttonSize + spacing) + 40;
- spaceBar.x = 2048 / 2;
- spaceBar.interactive = true;
- spaceBar.down = function () {
- checkInput(" ");
- };
- keyboard.addChild(spaceBar);
+ // Add delete key and space bar similar to above...
}
createKeyboard();
startGame();
-// Game loop
game.update = function () {
if (!gameActive) {
return;
}
@@ -347,13 +269,12 @@
}
for (var i = activeWords.length - 1; i >= 0; i--) {
var word = activeWords[i];
word.update();
- if (word.y > 2700) {
+ if (word.y > 2732) {
LK.getSound('wordHitBottom').play();
game.removeChild(word);
activeWords.splice(i, 1);
- clearInput();
endGame();
}
}
};
\ No newline at end of file