Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: Lk is not defined' in or related to this line: 'Lk.getSound('correctWord').play();' Line Number: 114
Code edit (5 edits merged)
Please save this source code
User prompt
play the tap sound when a lettertile is tapped
Code edit (8 edits merged)
Please save this source code
User prompt
play the background music when the game starts, and let it repeat until gameover
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: submitButon is not defined' in or related to this line: 'submitButon.destroy();' Line Number: 293
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
please implement function gameWon such that it displays a message 'Congratulations! You found all the worrd!' for a few seconds before calling KLshowGameOver.
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: letterTilesArr is not a function' in or related to this line: 'letterTilesArr(letterTile);' Line Number: 235
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'anchor')' in or related to this line: 'scoreTxt.anchor.set(0.5, 0);' Line Number: 132
Code edit (2 edits merged)
Please save this source code
User prompt
when a word is correct, remove it from the levels[currentLevel].words array
Code edit (1 edits merged)
Please save this source code
Code edit (15 edits merged)
Please save this source code
User prompt
make a small star explosion on the blackboard when a word is correct
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: blackBoardText is not defined' in or related to this line: 'blackBoardArr.push(blackBoardText);' Line Number: 129
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ var Cat = Container.expand(function () { var self = Container.call(this); var catGraphics = self.attachAsset('cat', { anchorX: 0.5, anchorY: 0.5 }); self.count = 0; self.down = function (x, y, obj) { gameWon(); self.update = function () { if (self.y > 1580) { self.y -= 10; } self.count++; if (self.count > 90) { self.y = 1670; self.count = 0; self.update = null; } }; }; return self; }); //<Assets used in the game will automatically appear here> // Class for Letter Tiles var LetterTile = Container.expand(function () { var self = Container.call(this); self.letter = ''; var tileGraphics = self.attachAsset('tile', { anchorX: 0.5, anchorY: 0.5 }); var letterText = new Text2(self.letter, { size: 100, fill: "#000000", weight: 300 }); letterText.anchor.set(0.5, 0.5); self.addChild(letterText); self.setLetter = function (letter) { self.letter = letter; letterText.setText(letter); }; self.clickable = true; self.down = function (x, y, obj) { if (self.clickable) { writeLetterOnBlackboard(self.letter); currentWord += self.letter; self.alpha = 0.5; self.clickable = false; // Make it unclickable } }; return self; }); var Rabbit = Container.expand(function () { var self = Container.call(this); var rabbitGraphics = self.attachAsset('rabbit', { anchorX: 0.5, anchorY: 0.5 }); self.count = 0; self.down = function (x, y, obj) { self.update = function () { if (self.y > 1550) { self.y -= 10; } self.count++; if (self.count > 90) { self.y = 1700; self.count = 0; self.update = null; } }; }; return self; }); var SubmitButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('submitButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('Submit', { size: 100, fill: "#000000" }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { console.log("Submit button clicked: ", currentWord); // Add logic to handle submit action if (levels[currentLevel].words.includes(currentWord)) { // Remove the correct word from the levels[currentLevel].words array levels[currentLevel].words = levels[currentLevel].words.filter(function (word) { return word !== currentWord; }); //console.log('correct'); var scoreIncrement = currentWord.length; LK.setScore(LK.getScore() + scoreIncrement); scoreTxt.setText('Score: ' + LK.getScore()); // Create star explosion effect createStarExplosion(500, 400 + blackboardOffsetY); blackBoardArr = []; blackboardOffsetX = 0; blackboardOffsetY += 120; game.children.forEach(function (child) { if (child instanceof LetterTile) { child.alpha = 1; child.clickable = true; } }); currentWord = ""; //console.log('length: ', levels[currentLevel].words.length); if (levels[currentLevel].words.length == 0) { advanceToNextLevel(); } } else { //console.log('incorrect'); // Destroy the letters on the blackboard clearBlackBoard(); // Reset the letter tiles game.children.forEach(function (child) { if (child instanceof LetterTile) { child.alpha = 1; child.clickable = true; } }); blackboardOffsetX = 0; currentWord = ""; } }; return self; }); var Teacher = Container.expand(function () { var self = Container.call(this); var teacherGraphics = self.attachAsset('teacher', { anchorX: 0.5, anchorY: 0.5 }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ function clearBlackBoard() { blackBoardArr.forEach(function (child) { child.destroy(); }); blackBoardArr = []; } var blackBoardArr = []; var wholeBlackBoardArr = []; var currentWord = ""; var levelTxt = new Text2('Level 1', { size: 60, fill: "#ADD8E6", stroke: "#000000", strokeThickness: 10, weight: 800 }); levelTxt.anchor.set(1.2, 0); LK.gui.topRight.addChild(levelTxt); var scoreTxt = new Text2('Score: 0', { size: 60, fill: "#ADE6D8", stroke: "#000000", strokeThickness: 10, weight: 800 }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var blackboardOffsetX = 0; var blackboardOffsetY = 0; function writeLetterOnBlackboard(letter) { var blackboardText = new Text2(letter, { size: 120, fill: "#ffffff", stroke: "#000000", strokeThickness: 10 }); blackboardText.anchor.set(0.5, 0.5); blackboardText.x = 400 + blackboardOffsetX; blackboardText.y = 400 + blackboardOffsetY; game.addChild(blackboardText); blackBoardArr.push(blackboardText); wholeBlackBoardArr.push(blackboardText); blackboardOffsetX += 110; // Adjust the offset value as needed // Check if this is the first letter clicked if (blackboardOffsetX === 110) { submitButton = new SubmitButton(); submitButton.x = 2048 / 2; submitButton.y = 2400; game.addChild(submitButton); } } var submitButton; // Add background graphic object covering the whole screen var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 50, y: 2732 / 2 - 200 }); game.addChild(background); var rabbit = new Rabbit(); rabbit.x = 250; rabbit.y = 1700; game.addChild(rabbit); var cat = new Cat(); cat.x = 1800; cat.y = 1670; game.addChild(cat); var tables = LK.getAsset('tables', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 - 50, y: 2732 / 2 - 200 }); game.addChild(tables); var teacher = new Teacher(); teacher.x = 2048 / 2 + 380; teacher.y = 2732 / 2 - 250; game.addChild(teacher); // Function to reset the game state for the new level function resetGameStateForNewLevel() { // Logic to reset the game state for the new level letterTilesArr.forEach(function (child) { child.destroy(); }); wholeBlackBoardArr.forEach(function (child) { child.destroy(); }); blackboardOffsetX = 0; blackboardOffsetXY = 0; currentWord = ""; displayLettersInLine(); } var letterTilesArr = []; // Function to display letters in a line centered at height 2000 function displayLettersInLine() { var startX = 2048 / 2 - letters.length * 220 / 2 + 100; var y = 2000; for (var i = 0; i < letters.length; i++) { var x = startX + i * 220; var letterTile = new LetterTile(); letterTile.setLetter(letters[i]); letterTile.x = x; letterTile.y = y; game.addChild(letterTile); letterTilesArr.push(letterTile); } } // Function to advance to the next level function advanceToNextLevel() { if (currentLevel < levels.length - 1) { currentLevel++; letters = getLettersForCurrentLevel(); levelTxt.setText('Level ' + (currentLevel + 1)); clearBlackBoard(); blackboardOffsetY = 0; resetGameStateForNewLevel(); } else { console.log("All levels completed!"); gameWon(); } } function gameWon() { submitButon.destroy(); var congratsText = new Text2('Congratulations!\nYou found all the words!', { size: 150, fill: "#ffffff", stroke: "#000000", strokeThickness: 10, align: 'center', weight: 800 }); congratsText.anchor.set(0.5, 0.5); congratsText.x = 2048 / 2; congratsText.y = 900; game.addChild(congratsText); LK.setTimeout(function () { congratsText.destroy(); LK.showGameOver(); }, 3000); // Display the message for 3 seconds } // Define levels with different sets of letters and acceptable words var levels3 = [{ letters: ['N', 'W', 'O'], words: ['NOW', 'WON', 'OWN'] }, { letters: ['A', 'E', 'T'], words: ['TEA', 'EAT', 'ATE'] }, { letters: ['A', 'M', 'R'], words: ['MAR', 'ARM', 'RAM'] }, { letters: ['A', 'T', 'P'], words: ['APT', 'PAT', 'TAP'] }, { letters: ['A', 'T', 'R'], words: ['TAR', 'ART', 'RAT'] }, { letters: ['O', 'T', 'P'], words: ['OPT', 'TOP', 'POT'] }, { letters: ['A', 'E', 'R'], words: ['EAR', 'ARE', 'ERA'] }]; var levels4 = [{ letters: ['E', 'C', 'A', 'R'], words: ['ACRE', 'CARE', 'RACE', 'ACER'] }, { letters: ['E', 'S', 'N', 'T'], words: ['NETS', 'TENS', 'SENT', 'NEST'] }, { letters: ['E', 'L', 'A', 'M'], words: ['LAME', 'MALE', 'MEAL'] }, { letters: ['S', 'D', 'E', 'U'], words: ['DUES', 'SUED', 'USED'] }, { letters: ['P', 'S', 'A', 'N'], words: ['NAPS', 'SNAP', 'PANS', 'SPAN'] }, { letters: ['A', 'L', 'R', 'I'], words: ['LAIR', 'LIAR', 'RAIL'] }, { letters: ['T', 'D', 'E', 'I'], words: ['DIET', 'EDIT', 'TIDE', 'TIED'] }]; var levels5 = [{ letters: ['T', 'E', 'L', 'A', 'R'], words: ['ALERT', 'ALTER', 'LATER'] }, { letters: ['E', 'S', 'M', 'L', 'I'], words: ['LIMES', 'SMILE', 'MILES', 'SLIME'] }, { letters: ['S', 'R', 'T', 'I', 'E'], words: ['RITES', 'TIERS', 'TRIES', 'TIRES'] }, { letters: ['P', 'S', 'A', 'E', 'H'], words: ['HEAPS', 'SHAPE', 'PHASE'] }, { letters: ['O', 'D', 'Y', 'R', 'W'], words: ['DOWRY', 'ROWDY', 'WORDY'] }, { letters: ['E', 'B', 'O', 'R', 'S'], words: ['BORES', 'ROBES', 'SOBER'] }, { letters: ['P', 'L', 'E', 'S', 'O'], words: ['LOPES', 'POLES', 'SLOPE'] }]; // Initialize the first level's letters and show level 1 when the game starts var currentLevel = 0; function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } } shuffleArray(levels3); shuffleArray(levels4); shuffleArray(levels5); var levels = levels3.concat(levels4, levels5); var letters = getLettersForCurrentLevel(); displayLettersInLine(); // Current level index // Function to get letters for the current level function getLettersForCurrentLevel() { return levels[currentLevel].letters; } // Initialize variables // Update function game.update = function () { // Game update logic }; function createStarExplosion(x, y) { for (var i = 0; i < 20; i++) { var star = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: Math.random() * 0.5 + 0.5, scaleY: Math.random() * 0.5 + 0.5, x: x, y: y }); game.addChild(star); var angle = Math.random() * Math.PI * 2; var speed = Math.random() * 10 + 5; var vx = Math.cos(angle) * speed; var vy = Math.sin(angle) * speed; (function (star, vx, vy) { var lifetime = 30; var tick = 0; var interval = LK.setInterval(function () { star.x += vx; star.y += vy; star.alpha -= 1 / lifetime; tick++; if (tick >= lifetime) { star.destroy(); LK.clearInterval(interval); } }, 16); })(star, vx, vy); } }
===================================================================
--- original.js
+++ change.js
@@ -165,17 +165,19 @@
var levelTxt = new Text2('Level 1', {
size: 60,
fill: "#ADD8E6",
stroke: "#000000",
- strokeThickness: 10
+ strokeThickness: 10,
+ weight: 800
});
levelTxt.anchor.set(1.2, 0);
LK.gui.topRight.addChild(levelTxt);
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: "#ADE6D8",
stroke: "#000000",
- strokeThickness: 10
+ strokeThickness: 10,
+ weight: 800
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var blackboardOffsetX = 0;
@@ -195,14 +197,15 @@
wholeBlackBoardArr.push(blackboardText);
blackboardOffsetX += 110; // Adjust the offset value as needed
// Check if this is the first letter clicked
if (blackboardOffsetX === 110) {
- var submitButton = new SubmitButton();
+ submitButton = new SubmitButton();
submitButton.x = 2048 / 2;
submitButton.y = 2400;
game.addChild(submitButton);
}
}
+var submitButton;
// Add background graphic object covering the whole screen
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
@@ -272,17 +275,20 @@
gameWon();
}
}
function gameWon() {
- var congratsText = new Text2('Congratulations! You found all the words!', {
- size: 100,
+ submitButon.destroy();
+ var congratsText = new Text2('Congratulations!\nYou found all the words!', {
+ size: 150,
fill: "#ffffff",
stroke: "#000000",
- strokeThickness: 10
+ strokeThickness: 10,
+ align: 'center',
+ weight: 800
});
congratsText.anchor.set(0.5, 0.5);
congratsText.x = 2048 / 2;
- congratsText.y = 2732 / 2;
+ congratsText.y = 900;
game.addChild(congratsText);
LK.setTimeout(function () {
congratsText.destroy();
LK.showGameOver();
A smooth, clean, blank and empty scrabble tile for a game.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A clean, warm and welcoming classroom in a school, facing the blackboard.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A small golden star. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.