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
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
update the scorelabel whenever lk.setscore is caled
User prompt
Please fix the bug: 'ReferenceError: Lk is not defined' in or related to this line: 'Lk.setScore(Lk.getScore() + 1);' Line Number: 101
Code edit (1 edits merged)
Please save this source code
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: seedGraphics is not defined' in or related to this line: 'seedGraphics.tint = 0x00FF00;' Line Number: 82
Code edit (1 edits merged)
Please save this source code
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'destroy')' in or related to this line: 'self.destroy();' Line Number: 153
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ /**** * TODO: * Progression: - Unlock seed types based on harvest results - GameOver on no harvest. - Start with fewer clouds / seeds. - Seed types should earn player more or less - Feedback window with farmer on each harvest, announcing results, unlocks, and new goals. * Bugs: - The red button should be strictly only clickable (and possibly only visible) when intended. should reflect this as well. -Clouds still spawn on vector where they cn go offscreen sometimes. * Ideas: - Maybe, aside from new seed types just unlocking sequentially, there should be requests/orders/special deliveries to fulfill to vary the gameplay. - The game should have a win conditions, but what? Maybe turning the whole farm green? With each unlock, one field transforms from brown to green (and seed location there vanishes)? Or the other way around At the start, only one field is green, and with each new unlock a new field becomes green and a seed position there is enabled? Until everythng is green, game completed. ****/ // 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.alpha = 0.7; 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. //rainshowerGraphics.scale.x *= -1; self.rainshowerGraphics.scale.x *= -1; //rainshowerGraphics.scale.x *= -1; } } else { if (self.alpha > 0) { self.alpha -= 0.01; } } }; self.pop = function () { self.popped = true; /*self.attachAsset('rainshower', { anchorX: 0.5, anchorY: 0 });*/ wateredGraphics = self.addChild(new WateredArea(), { //wateredGraphics = game.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); }; }); // OldFarmer class var OldFarmer = Container.expand(function () { var self = Container.call(this); var farmerGraphics = self.attachAsset('oldFarmer', { anchorX: 0.5, anchorY: 0.5 }); }); // Particle class var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('waterDroplet', { anchorX: 0.5, anchorY: 0.5 }); self.speed = { x: 0, y: 0 }; self.update = function () { self.x += self.speed.x; self.y += self.speed.y; if (self.y > 2732) { 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; self.update = function () { if (currentTick < totalTicks) { var progress = currentTick / totalTicks; self.x = startX + distanceX * progress; self.y = startY + distanceY * 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) { //self.moveTo(1024, 100, 0.5); //self.moveTo(1024, 1350, 0.5); 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].alpha = 0.5; //seeds[i].growth = 1; seeds[i].watered = true; } } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to represent the sky }); /**** * Game Code ****/ var wateredCounter = 0; var harvestedCounter = 0; var background = game.attachAsset('background', { anchorX: 0.5, anchorY: 0, scaleX: 1, scaleY: 1 }); background.x = 1024; //background.width / 2; // 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', 'strawberry', 'pumpkin', 'peanut', 'pea', 'melon', 'pineapple', 'cabbage']; var seedTypes = ['cabbage']; 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 = []; function initFruitPositions() { for (var i = 0; i < 4; i++) { for (var j = 0; j < 5; j++) { var t = [575 + j * 180, 1200 + i * 150, 0]; fruitPositions.push(t); } } } ; initFruitPositions(); var gameLevel = 1; var seeds = []; var clouds = []; var cloudSpeedMaster = 2; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); // 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 oldFarmer = new OldFarmer(); oldFarmer.x = instructionText.x - oldFarmer.width - 500; // Left side of the instructions oldFarmer.y = instructionText.y - oldFarmer.height / 2 - 50; // Above the instructions game.addChild(oldFarmer); 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]; // Position from seedPositions array seed.y = seedPositions[i][1]; // Position from seedPositions array seeds.push(seed); game.addChild(seed); } } ; var cloudTargets = [[1224, 400], [824, 800], [1024, 1200], [1224, 1600], [824, 2000]]; function spawnClouds() { for (var i = 0; i < 5; i++) { var cloud = new Cloud(); if (Math.random() > 0.5) { if (Math.random() > 0.5) { cloud.x = -400; //cloud.speed.x = 1; } else { cloud.x = 2048 + 400; //cloud.speed.x = -1; } cloud.y = 200 + Math.random() * 2332; //Math.random() * 2732; //cloud.speed.y = cloud.y > 1366 ? -1 : 1; } else { if (Math.random() > 0.5) { cloud.y = -400; //cloud.speed.y = 1; } else { cloud.y = 2732 + 400; //cloud.speed.y = -1; } cloud.x = 200 + Math.random() * 1648; //Math.random() * 2048; //cloud.speed.x = cloud.x > 1024 ? -1 : 1; } 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; /* var diff = Math.random() * 0.5; if (Math.random() > 0.5) { cloud.speed.x += diff; cloud.speed.y -= diff; } else { cloud.speed.x -= diff; cloud.speed.y += diff; }*/ 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) { bigRedButton.attachAsset('buttonPressed', { anchorX: 0.5, anchorY: 0.5 }); if (seeds.length === 0) { oldFarmer.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++) { 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 showingLevelResults = false; function showLevelResults() { console.log('showLevelResults()'); showingLevelResults = true; instructionWindow.alpha = 1; instructionText.alpha = 1; game.addChild(instructionWindow); instructionText.setText('Good job!\n You harvested XX crops.\nNew Seed type unlocked!\nTry to get XX crops this year.'); game.addChild(instructionText); } ; // 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]); } // TODO: check seeds array for isHarvested.true and destroy them if so. Also check for next phase. // This should trigger once all watered crops are harvested. if (wateredCounter > 0 && wateredCounter == harvestedCounter && !showingLevelResults) { showLevelResults(); } };
===================================================================
--- original.js
+++ change.js
@@ -91,9 +91,9 @@
self.popped = true;
/*self.attachAsset('rainshower', {
anchorX: 0.5,
anchorY: 0
- });*/
+ });*/
wateredGraphics = self.addChild(new WateredArea(), {
//wateredGraphics = game.addChild(new WateredArea(), {
anchorX: 0.5,
anchorY: 0.5
@@ -193,8 +193,9 @@
self.update = null;
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
self.harvested = true;
+ harvestedCounter++;
}
};
};
self.update = function () {
@@ -209,8 +210,9 @@
}
}
} else {
if (self.watered && self.growth == 0) {
+ wateredCounter++;
self.seedGraphics.tint = 0x00FF00;
self.growth = 1;
LK.setTimeout(function () {
self.seedGraphics.destroy();
@@ -267,9 +269,9 @@
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);
+ //console.log('x/y distance: ', dx, dy);
}
if (Math.sqrt(dx * dx + dy * dy) < self.width / 2) {
//seeds[i].alpha = 0.5;
//seeds[i].growth = 1;
@@ -289,28 +291,17 @@
/****
* Game Code
****/
+var wateredCounter = 0;
+var harvestedCounter = 0;
var background = game.attachAsset('background', {
anchorX: 0.5,
anchorY: 0,
scaleX: 1,
scaleY: 1
});
background.x = 1024; //background.width / 2;
-/*
-var brownFields = ['BrownField', 'Brownfield1', 'Brownfield2'];
-var fieldOffsetX = 48 / 6;
-var fieldOffsetY = 32 / 7;
-for (var i = 0; i < 5; i++) {
- for (var j = 0; j < 6; j++) {
- var t = brownFields[Math.floor(Math.random() * brownFields.length)];
- game.attachAsset(t, {
- x: i * 400 + fieldOffsetX * 2,
- y: j * 450 + fieldOffsetY * 2
- });
- }
-}*/
// Create a semi-transparent black window behind the instruction text
var instructionWindow = LK.getAsset('blackWindow', {
width: 2048,
height: 2732,
@@ -348,17 +339,8 @@
for (var i = 0; i < 4; i++) {
for (var j = 0; j < 5; j++) {
var t = [575 + j * 180, 1200 + i * 150, 0];
fruitPositions.push(t);
- /*
- game.attachAsset('peanut5', {
- anchorX: 0.5,
- anchorY: 0.5,
- scaleX: 1,
- scaleY: 1,
- x: t[0],
- y: t[1]
- });*/
}
}
}
;
@@ -401,9 +383,9 @@
game.addChild(seed);
}
}
;
-var cloudTargets = [[1024, 400], [1024, 800], [1024, 1200], [1024, 1600], [1024, 2000]];
+var cloudTargets = [[1224, 400], [824, 800], [1024, 1200], [1224, 1600], [824, 2000]];
function spawnClouds() {
for (var i = 0; i < 5; i++) {
var cloud = new Cloud();
if (Math.random() > 0.5) {
@@ -439,55 +421,16 @@
cloud.speed.y -= diff;
} else {
cloud.speed.x -= diff;
cloud.speed.y += diff;
- }*/
+ }*/
cloud.speed.x *= cloudSpeedMaster;
cloud.speed.y *= cloudSpeedMaster;
clouds.push(cloud);
game.addChild(cloud);
}
}
;
-function spawnClouds2() {
- for (var i = 0; i < 5; i++) {
- var cloud = new Cloud();
- if (Math.random() > 0.5) {
- if (Math.random() > 0.5) {
- cloud.x = -400;
- cloud.speed.x = 1;
- } else {
- cloud.x = 2048 + 400;
- cloud.speed.x = -1;
- }
- cloud.y = 200 + Math.random() * 2332; //Math.random() * 2732;
- cloud.speed.y = cloud.y > 1366 ? -1 : 1;
- } else {
- if (Math.random() > 0.5) {
- cloud.y = -400;
- cloud.speed.y = 1;
- } else {
- cloud.y = 2732 + 400;
- cloud.speed.y = -1;
- }
- cloud.x = 200 + Math.random() * 1648; //Math.random() * 2048;
- cloud.speed.x = cloud.x > 1024 ? -1 : 1;
- }
- var diff = Math.random() * 0.5;
- if (Math.random() > 0.5) {
- cloud.speed.x += diff;
- cloud.speed.y -= diff;
- } else {
- cloud.speed.x -= diff;
- cloud.speed.y += diff;
- }
- 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) {
@@ -507,8 +450,9 @@
} else {
for (var i = 0; i < clouds.length; i++) {
clouds[i].pop();
}
+ buttonEnabled = false;
}
// Switch back to unpressed state of button after 1 second.
LK.setTimeout(function () {
bigRedButton.attachAsset('bigRedButton', {
@@ -517,8 +461,19 @@
});
}, 1000);
}
};
+var showingLevelResults = false;
+function showLevelResults() {
+ console.log('showLevelResults()');
+ showingLevelResults = true;
+ instructionWindow.alpha = 1;
+ instructionText.alpha = 1;
+ game.addChild(instructionWindow);
+ instructionText.setText('Good job!\n You harvested XX crops.\nNew Seed type unlocked!\nTry to get XX crops this year.');
+ game.addChild(instructionText);
+}
+;
// Update game state
game.update = function () {
var allCloudsEntered = true;
for (var i = 0; i < clouds.length; i++) {
@@ -540,5 +495,9 @@
for (var i = 0; i < clouds.length; i++) {
game.addChild(clouds[i]);
}
// TODO: check seeds array for isHarvested.true and destroy them if so. Also check for next phase.
+ // This should trigger once all watered crops are harvested.
+ if (wateredCounter > 0 && wateredCounter == harvestedCounter && !showingLevelResults) {
+ showLevelResults();
+ }
};
\ No newline at end of file
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.