Code edit (3 edits merged)
Please save this source code
User prompt
after adding backgrund, add a cat in screen center.
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.playSound is not a function' in or related to this line: 'LK.playSound('fruitRipeSound');' Line Number: 237
Code edit (1 edits merged)
Please save this source code
User prompt
play a rainsound when the clouds rain
User prompt
play a windSound when clouds enter
Code edit (11 edits merged)
Please save this source code
User prompt
play a girlsound in startNextLevel
User prompt
play a buttonsound when button is pressed
Code edit (1 edits merged)
Please save this source code
Code edit (12 edits merged)
Please save this source code
User prompt
add a little explosion of stars when a questionMark i destroyed in line 234
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
at the start of the game, add 8 questionMark instances on a single row along the top right edge of the screen.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: cropsHarvested is not defined' in or related to this line: 'instructionText.setText('Good job!\n\nYou harvested ' + cropsHarvested + ' crops.\n\nNew Seed type unlocked!\n\nTry to get XX crops this year.');' Line Number: 527
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
in spawnclouds, please set speed.x and speed.y to normalized vector2 values indicating their approach towards the cloudTargets[i] position.
Code edit (10 edits merged)
Please save this source code
User prompt
please turn the wateredGraphic slightly blue
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ /**** * TODO: * Polish: - Maybe add sounds. Button. growth. harvest. rain. unlocks. girl laugh. * Ideas: - Maybe, aside from new seed types just unlocking sequentially, there should be requests/orders/special deliveries to fulfill to vary the gameplay. ****/ // BigRedButton class var BigRedButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('bigRedButton', { anchorX: 0.5, anchorY: 0.5 }); }); //<Assets used in the game will automatically appear here> // Cloud class var Cloud = Container.expand(function () { var self = Container.call(this); self.cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); var rainshowerGraphics; self.speed = { x: 0, y: 0 }; self.hw = self.width / 2; self.hh = self.height / 2; self.fullyEnteredStage = false; self.popped = false; self.fading = false; self.update = function () { if (!self.fading) { if (!self.popped) { self.x += self.speed.x; self.y += self.speed.y; if (self.fullyEnteredStage) { if (self.x < self.hw) { self.speed.x *= -1; self.x = self.hw; } else if (self.x > 2048 - self.hw) { self.x = 2048 - self.hw; self.speed.x *= -1; } if (self.y < self.hh) { self.y = self.hh; self.speed.y *= -1; } else if (self.y > 2232 - self.hh) { self.y = 2232 - self.hh; self.speed.y *= -1; } } else { if (self.x > self.hw && self.x < 2048 - self.hw) { if (self.y > self.hh && self.y < 2232 - self.hw) { self.fullyEnteredStage = true; } } } } else { // flip the rainshower asset horizontally. self.rainshowerGraphics.scale.x *= -1; } } else { if (self.alpha > 0) { self.alpha -= 0.01; } } }; self.pop = function () { self.popped = true; wateredGraphics = self.addChild(new WateredArea(), { anchorX: 0.5, anchorY: 0.5 }); self.rainshowerGraphics = self.addChild(new RainShower(), { anchorX: 0.5, anchorY: 0 }); cloudGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5 }); wateredGraphics.y += 400; // Destroy the water cloud //self.destroy(); LK.setTimeout(function () { //self.destroy(); //self.cloudGraphics.destroy(); self.rainshowerGraphics.destroy(); //self.cloudGraphics.destroy(); //self.detachAsset('cloud'); LK.setTimeout(function () { self.fading = true; }, 1000); }, 1000); }; }); // GirlFarmer class var GirlFarmer = Container.expand(function () { var self = Container.call(this); var farmerGraphics = self.attachAsset('girlFarmer', { anchorX: 0.5, anchorY: 0.5 }); }); // Particle class var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('star', { anchorX: 0.5, anchorY: 0.5 }); self.speed = { x: 0, y: 0, rotation: (0.5 - Math.random()) * 0.1 }; self.ticks = 0; self.update = function () { self.x += self.speed.x; self.y += self.speed.y; self.speed.y += 0.25; self.rotation += self.speed.rotation; self.ticks++; if (self.ticks > 120) { self.destroy(); } }; }); var RainShower = Container.expand(function () { var self = Container.call(this); var rainGraphics = self.attachAsset('rainshower', { anchorX: 0.5, anchorY: 0 }); self.update = function () { if (LK.ticks % 5 == 0) { rainGraphics.scale.x *= -1; } }; }); // Seed class var Seed = Container.expand(function () { var self = Container.call(this); self.watered = false; self.growth = 0; self.seedType; self.moveToScore = false; self.harvested = false; self.water = function () { self.watered = true; // Change color to indicate watering seedGraphics.tint = 0x0000FF; }; self.moveTo = function (targetX, targetY, duration) { var startX = self.x; var startY = self.y; var distanceX = targetX - startX; var distanceY = targetY - startY; var totalTicks = duration * 60; // Assuming 60 FPS var currentTick = 0; if (!revealedCropTypes.includes(self.seedType)) { revealedCropTypes.push(self.seedType); for (var i = questionMarks.length - 1; i >= 0; i--) { if (questionMarks[i].revealed == false) { questionMarks[i].revealed = true; //questionMarks[i].attachAsset(self.seedType + '5', { game.attachAsset(self.seedType + '5', { scaleX: 0.50, scaleY: 0.50, anchorX: 0.5, anchorY: 0.5, x: questionMarks[i].x, y: questionMarks[i].y }); // Create a little explosion of stars for (var j = 0; j < 10; j++) { var star = new Particle(); star.x = questionMarks[i].x; star.y = questionMarks[i].y; star.speed.x = (Math.random() - 0.5) * 10; star.speed.y = (Math.random() - 0.5) * 10; game.addChild(star); } questionMarks[i].destroy(); questionMarks.splice(i, 1); break; } } } self.update = function () { if (currentTick < totalTicks) { var progress = currentTick / totalTicks; //self.x = startX + distanceX * progress; //self.y = startY + distanceY * progress; self.x = startX + distanceX * easeOutElastic(progress); // * progress; self.y = startY + distanceY * easeOutElastic(progress); // * progress; currentTick++; } else { self.x = targetX; self.y = targetY; // Stop updating once the target is reached self.update = null; LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); self.harvested = true; harvestedCounter++; } }; }; self.update = function () { if (self.moveToScore) { for (var i = 0; i < fruitPositions.length; i++) { if (fruitPositions[i][2] == 0) { fruitPositions[i][2] = 1; self.moveTo(fruitPositions[i][0], fruitPositions[i][1], 0.5); break; } } } else { if (self.watered && self.growth == 0) { wateredCounter++; self.seedGraphics.tint = 0x00FF00; self.growth = 1; LK.setTimeout(function () { self.seedGraphics.destroy(); self.seedGraphics = self.attachAsset(self.seedType + '2', { anchorX: 0.5, anchorY: 1 //0.5 }); self.growth = 2; LK.setTimeout(function () { self.seedGraphics.destroy(); self.seedGraphics = self.attachAsset(self.seedType + '3', { anchorX: 0.5, anchorY: 1 //0.5 }); LK.setTimeout(function () { self.seedGraphics.destroy(); self.seedGraphics = self.attachAsset(self.seedType + '4', { anchorX: 0.5, anchorY: 1 //0.5 }); LK.setTimeout(function () { self.seedGraphics.destroy(); self.seedGraphics = self.attachAsset(self.seedType + '5', { anchorX: 0.5, anchorY: 0.5 }); LK.setTimeout(function () { self.moveToScore = true; }, 1000); }, 1000); }, 1000); }, 1000); }, 2000); } } ; }; }); var WateredArea = Container.expand(function () { var self = Container.call(this); var waterGraphics = self.attachAsset('wateredArea', { anchorX: 0.5, anchorY: 0.5, alpha: 0.6, //1, //0.6, tint: '0x0000ff' }); self.update = function () { if (self.scale.x < 2) { self.scale.x += 0.01; self.scale.y += 0.01; //for (var i in seeds) { for (var i = 0; i < seeds.length; i++) { var dx = Math.abs(self.parent.x - seeds[i].x); var dy = Math.abs(self.parent.y + 400 - seeds[i].y); if (false && i == 0) { //console.log('x/y distance: ', dx, dy); } if (Math.sqrt(dx * dx + dy * dy) < self.width / 2) { seeds[i].watered = true; } } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to represent the sky }); /**** * Game Code ****/ function easeOutBounce(x) { var n1 = 7.5625; var d1 = 2.75; if (x < 1 / d1) { return n1 * x * x; } else if (x < 2 / d1) { return n1 * (x -= 1.5 / d1) * x + 0.75; } else if (x < 2.5 / d1) { return n1 * (x -= 2.25 / d1) * x + 0.9375; } else { return n1 * (x -= 2.625 / d1) * x + 0.984375; } } ; function easeOutElastic(x) { //var c4 = 2 * Math.PI / 3; var c4 = 2 * Math.PI / .3; //return x === 0 ? 0 : x === 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1; //return x === 0 ? 0 : x === 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1; return x === 0 ? 0 : x === 1 ? 1 : 0.25 * Math.pow(2, -5 * x) * Math.cos((x * 10 - 0.75) * c4) + 1; } var wateredCounter = 0; var harvestedCounter = 0; var cropsHarvested = 0; var questionMarks = []; var background = game.attachAsset('background', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1 }); background.x = 1024; // Add 8 questionMark instances on a single row along the top right edge of the screen for (var i = 0; i < 8; i++) { var questionMark = LK.getAsset('questionMark', { anchorX: 0.5, anchorY: 0.5 }); questionMark.x = 2040 - questionMark.width / 2 - i * (questionMark.width + 10); questionMark.y = questionMark.height / 2 + 20; game.addChild(questionMark); questionMark.revealed = false; questionMarks.push(questionMark); } // Create a semi-transparent black window behind the instruction text var instructionWindow = LK.getAsset('blackWindow', { width: 2048, height: 2732, color: 0x000000, alpha: 0.7, shape: 'box', anchorX: 0.5 }); game.addChild(instructionWindow); // Add instruction text var instructionText = new Text2("The weather's been dry lately, but we finally got our new CLOUD CONTROL SYSTEM in place!\n\nJust push THE RED BUTTON when the CLOUDS are over the SEEDS, and we'll have a GREAT harvest!\n\nTap the button to begin.", { size: 62, weight: 800, font: 'Verdana, sans-serif', fill: "#aaffaa", align: "center", wordWrap: true, wordWrapWidth: 1948, stroke: '#000000', strokeThickness: 15 }); instructionText.anchor.set(0.5, 0); instructionText.x = 1024; instructionText.y = 400; instructionWindow.width = instructionText.width + 100; instructionWindow.height = instructionText.height + 100; instructionWindow.x = instructionText.x; instructionWindow.y = instructionText.y - 50; game.addChild(instructionText); var otherSeedTypes = ['corn', 'pumpkin', 'peanut', 'pea', 'melon', 'pineapple', 'cabbage']; var seedTypes = ['strawberry']; var seedPositions = [[150, 700], [270, 1200], [270, 1600], [270, 2300], [525, 800], [800, 2000], [920, 820], [1300, 750], [1550, 500], [1800, 750], [1600, 1100], [1625, 1550], [1700, 2000], [1700, 2350]]; var fruitPositions = []; var revealedCropTypes = []; function initFruitPositions() { fruitPositions = []; for (var i = 0; i < 4; i++) { for (var j = 0; j < 5; j++) { var t = [575 + j * 180, 1200 + i * 180, 0]; fruitPositions.push(t); } } } ; initFruitPositions(); var gameLevel = 0; var seeds = []; var clouds = []; var cloudSpeedMaster = 2; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff", strokeThickness: 10, stroke: "#000000" }); // Add the big red button to the game var bigRedButton = new BigRedButton(); bigRedButton.x = 1024; // Center of the screen bigRedButton.y = 2632 - bigRedButton.height / 2; // Bottom of the screen game.addChild(bigRedButton); // Add the old farmer to the game var girlFarmer = new GirlFarmer(); girlFarmer.x = 450; girlFarmer.y = instructionWindow.y - girlFarmer.height / 2; // Above the instructions game.addChild(girlFarmer); LK.getSound('girlSound').play(); scoreTxt.anchor.set(0.5, 0); var seeds = []; LK.gui.top.addChild(scoreTxt); function placeSeeds() { for (var i = 0; i < seedPositions.length; i++) { var seedType = seedTypes[Math.floor(Math.random() * seedTypes.length)]; var seed = new Seed(); seed.seedGraphics = seed.attachAsset(seedType + '1', { anchorX: 0.5, anchorY: 0.5 }); seed.seedType = seedType; //console.log('seedType is: ', seedType); seed.x = seedPositions[i][0]; seed.y = seedPositions[i][1]; seeds.push(seed); game.addChild(seed); } } ; var cloudTargets = [[1224, 400], [824, 800], [1024, 1200], [1224, 1600], [824, 2000]]; function spawnClouds() { LK.getSound('windSound').play(); for (var i = 0; i < 5; i++) { var cloud = new Cloud(); if (Math.random() > 0.5) { if (Math.random() > 0.5) { cloud.x = -400; } else { cloud.x = 2048 + 400; } cloud.y = 200 + Math.random() * 2332; //Math.random() * 2732; } else { if (Math.random() > 0.5) { cloud.y = -400; } else { cloud.y = 2732 + 400; } cloud.x = 200 + Math.random() * 1648; //Math.random() * 2048; } var dx = cloudTargets[i][0] - cloud.x; var dy = cloudTargets[i][1] - cloud.y; var distance = Math.sqrt(dx * dx + dy * dy); cloud.speed.x = dx / distance * cloudSpeedMaster; cloud.speed.y = dy / distance * cloudSpeedMaster; cloud.speed.x *= cloudSpeedMaster; cloud.speed.y *= cloudSpeedMaster; clouds.push(cloud); game.addChild(cloud); } } ; var buttonEnabled = true; // Handle touch events bigRedButton.down = function (x, y, obj) { if (buttonEnabled) { LK.getSound('buttonSound').play(); bigRedButton.attachAsset('buttonPressed', { anchorX: 0.5, anchorY: 0.5 }); if (showingLevelResults) { startNextLevel(); } // else { if (seeds.length === 0) { girlFarmer.alpha = 0; instructionText.alpha = 0; instructionWindow.alpha = 0; placeSeeds(); } if (clouds.length === 0) { spawnClouds(); buttonEnabled = false; } else { for (var i = 0; i < clouds.length; i++) { if (!clouds[i].popped) { clouds[i].pop(); } } buttonEnabled = false; } // Switch back to unpressed state of button after 1 second. LK.setTimeout(function () { bigRedButton.attachAsset('bigRedButton', { anchorX: 0.5, anchorY: 0.5 }); }, 1000); } }; var finalSeasonsLeft = 4; var showingLevelResults = false; var levelHarvestTargets = [1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]; function showLevelResults() { //console.log('showLevelResults()'); LK.getSound('girlSound').play(); showingLevelResults = true; instructionWindow.alpha = 0.7; instructionText.alpha = 1; girlFarmer.alpha = 1; game.addChild(girlFarmer); game.addChild(instructionWindow); //if (gameLevel < 7) { if (otherSeedTypes.length > 0) { if (harvestedCounter >= levelHarvestTargets[gameLevel]) { // Unlock new seed type. var temp = Math.floor(Math.random() * otherSeedTypes.length); seedTypes.push(otherSeedTypes[temp]); otherSeedTypes.splice(temp, 1); instructionText.setText('Good job!\n\nYou harvested ' + harvestedCounter + ' crops and unlocked a new seed type!\n\nGet ' + levelHarvestTargets[gameLevel + 1] + ' or more crops next time, to unlock new seed types.'); gameLevel++; } else { instructionText.setText('Good job!\n\nYou harvested ' + harvestedCounter + ' crops.\n\nGet ' + levelHarvestTargets[gameLevel + 1] + ' or more crops next time, to unlock new seed types.'); } } else { if (finalSeasonsLeft > 0) { if (finalSeasonsLeft == 1) { instructionText.setText('Good job!\n\nYou harvested ' + harvestedCounter + ' crops.\n\nJust one more harvest left this season!\n\nHarvest as much as possible to boost your score.'); } else { instructionText.setText('Good job!\n\nYou harvested ' + harvestedCounter + ' crops.\n\nThere are no more seed types to unlock, but you can keep playing and harvest ' + finalSeasonsLeft + ' more times to increase your score.'); } finalSeasonsLeft--; } else { instructionText.setText('Good job!\n\nYou harvested ' + harvestedCounter + ' crops.\n\nThat was the final harvest this season.\nThanks for playing :)'); LK.showGameOver(); } } game.addChild(instructionText); buttonEnabled = true; } ; function startNextLevel() { showingLevelResults = false; buttonEnabled = false; harvestedCounter = 0; wateredCounter = 0; // Remove window girlFarmer.alpha = 0; instructionWindow.alpha = 0; instructionText.alpha = 0; // Remove seeds for new level. for (var i = 0; i < seeds.length; i++) { seeds[i].destroy(); } seeds = []; ; // Remove clouds. for (var i = 0; i < clouds.length; i++) { clouds[i].destroy(); } clouds = []; initFruitPositions(); } ; // Update game state game.update = function () { var allCloudsEntered = true; for (var i = 0; i < clouds.length; i++) { clouds[i].update(); if (!buttonEnabled) { if (!clouds[i].fullyEnteredStage) { allCloudsEntered = false; } } } if (allCloudsEntered == true) { buttonEnabled = true; } /* // Sort water clouds by their Y value to ensure correct rendering order clouds.sort(function (a, b) { return a.y - b.y; }); // Re-add water clouds to the game in the correct order for (var i = 0; i < clouds.length; i++) { game.addChild(clouds[i]); }*/ // This should trigger once all watered crops are harvested. if (wateredCounter > 0 && wateredCounter == harvestedCounter && !showingLevelResults) { showLevelResults(); } };
===================================================================
--- original.js
+++ change.js
@@ -437,8 +437,9 @@
}
;
var cloudTargets = [[1224, 400], [824, 800], [1024, 1200], [1224, 1600], [824, 2000]];
function spawnClouds() {
+ LK.getSound('windSound').play();
for (var i = 0; i < 5; i++) {
var cloud = new Cloud();
if (Math.random() > 0.5) {
if (Math.random() > 0.5) {
A straight top down perspective illustration of a large empty field with fertile, plowed but unplanted brown soil.There should be a farmhouse near the top.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An ungerminated plant seed.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A fluffy white cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A lush pumpkin at the foot of its green stalk.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Erase the inpainted area.
A corn seed.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A single yellow corn seed.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A corn plant in early stage of growth.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A young, unripe corn plant.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A Delicious strawberry.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Delete the inpainted area.
A nice green pea pod.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
An interface element which is a gray circle with a question mark inside it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A little golden star.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase the white outline parts in the image.