User prompt
the layer of seeds tomato potato carrots after duplicating and placing i have to click to show the seed make it visible always in slots without clicking again to show it! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
show the slots always full with seeds graphic ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Import of asset
User prompt
Duplicate from slot of seed always & let graphic of it in the original slot but if it's 0/5 then don't duplicate do it gray like its empty and you can't use that seed anymore. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
after placing seed in dirt show whats left in seeds slots. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
I still can't see seeds in slots of seeds after placing 1 in dirt! i think you have to duplicate seed after moving it to be placed and let one graphic of it in seed slot till reach the 0 and then you remove it! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Hide graphic of seed in dirt but let its original in seeds slots till it will be empty 0/5 then it will not be any graphic seed on the seeds slots okay ^^ . ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
After i place a seed in dirt i don't see what's left in the slots it must be there i mean i can see by number 4/5 but not with assets so they have to be there. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Let asset of seeds on the slots when using it like always show the seed in slot till it will be empty 0/5. also when placing a seed in the dirt don't let it on the top of it try to hide it in dirt. you can add animation of placing on the dirt like dirt shaking particles. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add 'Background1' asset as background for the game. Do the timer in each slot of dirt '60s' start counting down after placing the any seed. add the number 5/5 in the slots that have 5 seeds. If empty then its 0/5. reduce the number of seeds each time 1 seed is used. remove the green from dirt. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Import of asset
User prompt
Import of asset
Code edit (1 edits merged)
Please save this source code
User prompt
no need to remove the other slots just start with 5 seeds in the first 3 slots on the left & let the other slots empty when adding new seeds to the game later. remove dirt let only 3 slots of it the lower line horizontal. add timer '1 minute' in the middle of the dirt slots but don't show it only if a seed placed in the dirt. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
try to combine or store the seeds like 1 slot have all the 5 it will be 3 slots of 3 seeds 5 each
User prompt
remove timer. the start of the game with 5 tomatoseed, 5 potatoseed=cleared brown color with ellipse shape, 5 carrotseed orange color ellipse shape.
User prompt
if i hold on the seed asset by mouse then drag move the seed only and hold the slots of seeds positions.
User prompt
Show time on dirt ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Start the time of dirt immediately after placing a seed on it ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
The tomato seed can't be moved! we stop only the slots not the seeds from dragging so fix it so i can drag tomato seed to the dirt by mouse left button holded.
User prompt
Hide time of plants no playing till the 3rd time collect on the dirt that have seed
User prompt
allow movement for tomato seed and any other seed to drag it to dirt and make no affect till releasing seed. don't start time on dirt only if a seed placed on it!.
User prompt
When dragging any seed move only the seeds. the slots of seeds are unmovable!.
User prompt
add movement by mouse hold on objects like seeds on the bottom slots to place it on the dirt. after placing a seed in the dirt hide the seed but start the time on the dirt. don't start dirt time only if a seed placed on it!. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (2 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Plant = Container.expand(function () {
var self = Container.call(this);
var dirtGraphics = self.attachAsset('Dirt', {
anchorX: 0.5,
anchorY: 0.5
});
var plantGraphics = self.attachAsset('plant', {
anchorX: 0.5,
anchorY: 0.5
});
plantGraphics.alpha = 0;
self.maxGrowthTime = 60000; // 60 seconds in milliseconds
self.growthTimeRemaining = 0;
self.isReady = false;
self.gridX = 0;
self.gridY = 0;
self.seedPlanted = false;
self.harvestCount = 0;
self.growthTimer = null;
self.timerDisplay = null;
self.initialize = function () {
self.growthTimeRemaining = self.maxGrowthTime;
self.isReady = false;
self.seedPlanted = true;
};
self.update = function () {
if (self.seedPlanted && !self.isReady) {
self.growthTimeRemaining -= 1000 / 60; // Subtract time per frame (60 FPS)
if (self.timerDisplay) {
var secondsRemaining = Math.ceil(self.growthTimeRemaining / 1000);
self.timerDisplay.setText(secondsRemaining + 's');
}
if (self.growthTimeRemaining <= 0) {
self.growthTimeRemaining = 0;
self.isReady = true;
if (self.timerDisplay) {
self.timerDisplay.alpha = 0;
}
}
}
};
self.harvest = function () {
if (self.isReady) {
self.harvestCount++;
self.isReady = false;
self.seedPlanted = false;
self.growthTimeRemaining = self.maxGrowthTime;
if (self.timerDisplay) {
self.timerDisplay.alpha = 0;
}
return true;
}
return false;
};
self.down = function (x, y, obj) {
// Handled by game-level event handler
};
self.initialize();
return self;
});
var Seed = Container.expand(function () {
var self = Container.call(this);
var slotGraphics = self.attachAsset('slots', {
anchorX: 0.5,
anchorY: 0.5
});
var seedGraphics = null;
self.seedType = null;
self.slotIndex = 0;
self.initialX = 0;
self.initialY = 0;
self.isDragging = false;
self.seedGraphicsLocalX = 0;
self.seedGraphicsLocalY = 0;
self.seedCount = 5;
self.seedCountText = null;
self.setSeed = function (seedType) {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = seedType;
if (seedType) {
seedGraphics = self.attachAsset(seedType, {
anchorX: 0.5,
anchorY: 0.5
});
self.seedGraphicsRef = seedGraphics;
if (!self.seedCountText) {
self.seedCountText = new Text2(self.seedCount + '/5', {
size: 32,
fill: '#ffffff'
});
self.seedCountText.anchor.set(0.5, 0.5);
self.seedCountText.x = 40;
self.seedCountText.y = -40;
self.addChild(self.seedCountText);
} else {
self.seedCountText.setText(self.seedCount + '/5');
}
}
};
self.decrementSeedCount = function () {
if (self.seedCount > 0) {
self.seedCount--;
if (self.seedCountText) {
self.seedCountText.setText(self.seedCount + '/5');
}
}
};
self.getSeed = function () {
return self.seedType;
};
self.getSeedGraphics = function () {
return seedGraphics;
};
self.removeSeed = function () {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = null;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1b4332
});
/****
* Game Code
****/
// Add background
var background = game.addChild(LK.getAsset('Background1', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
background.scaleX = 2048 / background.width;
background.scaleY = 2732 / background.height;
var plants = [];
var totalRewards = storage.totalRewards || 0;
var dirtSlotSize = 350;
var dirtSlotSpacing = 60;
var dirtGridStartX = 2048 / 2 - (3 * dirtSlotSize + 2 * dirtSlotSpacing) / 2;
var dirtGridStartY = 2732 - 800;
// Create 3 dirt slots in horizontal line at bottom
for (var dirtIndex = 0; dirtIndex < 3; dirtIndex++) {
var plant = game.addChild(new Plant());
plant.gridX = dirtIndex;
plant.gridY = 0;
plant.x = dirtGridStartX + dirtIndex * (dirtSlotSize + dirtSlotSpacing) + dirtSlotSize / 2;
plant.y = dirtGridStartY;
plants.push(plant);
}
// Score display
var scoreText = new Text2('Rewards: 0', {
size: 64,
fill: '#ffffff'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function updateScoreDisplay() {
scoreText.setText('Rewards: ' + totalRewards);
storage.totalRewards = totalRewards;
}
updateScoreDisplay();
// Create individual timer displays for each plant - initially hidden
for (var i = 0; i < plants.length; i++) {
var plantTimer = new Text2('60s', {
size: 80,
fill: '#ffffff'
});
plantTimer.anchor.set(0.5, 0.5);
plantTimer.x = plants[i].x;
plantTimer.y = plants[i].y;
plantTimer.alpha = 0;
game.addChild(plantTimer);
plants[i].timerDisplay = plantTimer;
plants[i].lastHarvested = false;
}
// Create seed slots at bottom of screen - 3 slots only
var seeds = [];
var seedSlotSize = 120;
var seedSlotSpacing = 60;
var seedGridStartX = 2048 / 2 - (3 * seedSlotSize + 2 * seedSlotSpacing) / 2;
var seedGridStartY = 2732 - 280;
for (var seedIndex = 0; seedIndex < 3; seedIndex++) {
var seedSlot = game.addChild(new Seed());
seedSlot.slotIndex = seedIndex;
seedSlot.x = seedGridStartX + seedIndex * (seedSlotSize + seedSlotSpacing) + seedSlotSize / 2;
seedSlot.y = seedGridStartY;
seeds.push(seedSlot);
}
// Add seed types - each slot represents 5 of that seed
seeds[0].setSeed('tomatoseed');
seeds[1].setSeed('potatoseed');
seeds[2].setSeed('carrotseed');
var draggedSeed = null;
var draggedSeedStartSlot = null;
game.down = function (x, y, obj) {
// Check if clicking on a seed (not the slot itself)
for (var seedIndex = 0; seedIndex < seeds.length; seedIndex++) {
var seed = seeds[seedIndex];
// Only allow dragging if seed has a seedType and we're clicking on the seed
if (seed.seedType) {
var distance = Math.sqrt(Math.pow(x - seed.x, 2) + Math.pow(y - seed.y, 2));
// Check if click is within seed bounds (radius approximately 50 pixels for 100x100 seed)
if (distance < 60) {
draggedSeed = seed;
draggedSeedStartSlot = seedIndex;
seed.isDragging = true;
seed.initialX = seed.x;
seed.initialY = seed.y;
var seedGraphics = seed.getSeedGraphics();
if (seedGraphics) {
tween.stop(seedGraphics);
tween(seedGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
}
return;
}
}
}
for (var i = 0; i < plants.length; i++) {
var plant = plants[i];
var distance = Math.sqrt(Math.pow(x - plant.x, 2) + Math.pow(y - plant.y, 2));
if (distance < 80 && plant.isReady) {
plant.harvest();
totalRewards++;
updateScoreDisplay();
// Create harvest effect
var effect = game.addChild(LK.getAsset('harvestEffect', {
anchorX: 0.5,
anchorY: 0.5
}));
effect.x = plant.x;
effect.y = plant.y;
effect.alpha = 1;
tween(effect, {
alpha: 0,
y: plant.y - 60
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
effect.destroy();
}
});
break;
}
}
};
game.move = function (x, y, obj) {
if (draggedSeed) {
var seedGraphics = draggedSeed.getSeedGraphics();
if (seedGraphics) {
seedGraphics.x = x - draggedSeed.x;
seedGraphics.y = y - draggedSeed.y;
}
}
};
game.up = function (x, y, obj) {
if (draggedSeed) {
var placed = false;
for (var plantIndex = 0; plantIndex < plants.length; plantIndex++) {
var plant = plants[plantIndex];
var plantDistance = Math.sqrt(Math.pow(x - plant.x, 2) + Math.pow(y - plant.y, 2));
if (plantDistance < 175) {
if (draggedSeed.seedType) {
plant.seedPlanted = true;
draggedSeed.decrementSeedCount();
plant.initialize();
if (plant.timerDisplay) {
plant.timerDisplay.alpha = 1;
}
placed = true;
}
break;
}
}
var seedGraphics = draggedSeed.getSeedGraphics();
if (seedGraphics) {
tween.stop(seedGraphics);
if (!placed) {
tween(seedGraphics, {
x: 0,
y: 0,
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeOut
});
} else {
tween(seedGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
}
draggedSeed.isDragging = false;
draggedSeed = null;
draggedSeedStartSlot = null;
}
};
game.update = function () {
for (var i = 0; i < plants.length; i++) {
if (plants[i].seedPlanted) {
plants[i].update();
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Plant = Container.expand(function () {
var self = Container.call(this);
var dirtGraphics = self.attachAsset('Dirt', {
anchorX: 0.5,
anchorY: 0.5
});
var plantGraphics = self.attachAsset('plant', {
anchorX: 0.5,
anchorY: 0.5
});
plantGraphics.alpha = 0;
self.maxGrowthTime = 60000; // 60 seconds in milliseconds
self.growthTimeRemaining = 0;
self.isReady = false;
self.gridX = 0;
self.gridY = 0;
self.seedPlanted = false;
self.harvestCount = 0;
self.growthTimer = null;
self.timerDisplay = null;
self.initialize = function () {
self.growthTimeRemaining = self.maxGrowthTime;
self.isReady = false;
self.seedPlanted = true;
};
self.update = function () {
if (self.seedPlanted && !self.isReady) {
self.growthTimeRemaining -= 1000 / 60; // Subtract time per frame (60 FPS)
if (self.timerDisplay) {
var secondsRemaining = Math.ceil(self.growthTimeRemaining / 1000);
self.timerDisplay.setText(secondsRemaining + 's');
}
if (self.growthTimeRemaining <= 0) {
self.growthTimeRemaining = 0;
self.isReady = true;
if (self.timerDisplay) {
self.timerDisplay.alpha = 0;
}
}
}
};
self.harvest = function () {
if (self.isReady) {
self.harvestCount++;
self.isReady = false;
self.seedPlanted = false;
self.growthTimeRemaining = self.maxGrowthTime;
if (self.timerDisplay) {
self.timerDisplay.alpha = 0;
}
return true;
}
return false;
};
self.down = function (x, y, obj) {
// Handled by game-level event handler
};
self.initialize();
return self;
});
var Seed = Container.expand(function () {
var self = Container.call(this);
var slotGraphics = self.attachAsset('slots', {
anchorX: 0.5,
anchorY: 0.5
});
var seedGraphics = null;
self.seedType = null;
self.slotIndex = 0;
self.initialX = 0;
self.initialY = 0;
self.isDragging = false;
self.seedGraphicsLocalX = 0;
self.seedGraphicsLocalY = 0;
self.seedCount = 5;
self.seedCountText = null;
self.setSeed = function (seedType) {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = seedType;
if (seedType) {
seedGraphics = self.attachAsset(seedType, {
anchorX: 0.5,
anchorY: 0.5
});
self.seedGraphicsRef = seedGraphics;
if (!self.seedCountText) {
self.seedCountText = new Text2(self.seedCount + '/5', {
size: 32,
fill: '#ffffff'
});
self.seedCountText.anchor.set(0.5, 0.5);
self.seedCountText.x = 40;
self.seedCountText.y = -40;
self.addChild(self.seedCountText);
} else {
self.seedCountText.setText(self.seedCount + '/5');
}
}
};
self.decrementSeedCount = function () {
if (self.seedCount > 0) {
self.seedCount--;
if (self.seedCountText) {
self.seedCountText.setText(self.seedCount + '/5');
}
}
};
self.getSeed = function () {
return self.seedType;
};
self.getSeedGraphics = function () {
return seedGraphics;
};
self.removeSeed = function () {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = null;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1b4332
});
/****
* Game Code
****/
// Add background
var background = game.addChild(LK.getAsset('Background1', {
anchorX: 0.5,
anchorY: 0.5
}));
background.x = 2048 / 2;
background.y = 2732 / 2;
background.scaleX = 2048 / background.width;
background.scaleY = 2732 / background.height;
var plants = [];
var totalRewards = storage.totalRewards || 0;
var dirtSlotSize = 350;
var dirtSlotSpacing = 60;
var dirtGridStartX = 2048 / 2 - (3 * dirtSlotSize + 2 * dirtSlotSpacing) / 2;
var dirtGridStartY = 2732 - 800;
// Create 3 dirt slots in horizontal line at bottom
for (var dirtIndex = 0; dirtIndex < 3; dirtIndex++) {
var plant = game.addChild(new Plant());
plant.gridX = dirtIndex;
plant.gridY = 0;
plant.x = dirtGridStartX + dirtIndex * (dirtSlotSize + dirtSlotSpacing) + dirtSlotSize / 2;
plant.y = dirtGridStartY;
plants.push(plant);
}
// Score display
var scoreText = new Text2('Rewards: 0', {
size: 64,
fill: '#ffffff'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function updateScoreDisplay() {
scoreText.setText('Rewards: ' + totalRewards);
storage.totalRewards = totalRewards;
}
updateScoreDisplay();
// Create individual timer displays for each plant - initially hidden
for (var i = 0; i < plants.length; i++) {
var plantTimer = new Text2('60s', {
size: 80,
fill: '#ffffff'
});
plantTimer.anchor.set(0.5, 0.5);
plantTimer.x = plants[i].x;
plantTimer.y = plants[i].y;
plantTimer.alpha = 0;
game.addChild(plantTimer);
plants[i].timerDisplay = plantTimer;
plants[i].lastHarvested = false;
}
// Create seed slots at bottom of screen - 3 slots only
var seeds = [];
var seedSlotSize = 120;
var seedSlotSpacing = 60;
var seedGridStartX = 2048 / 2 - (3 * seedSlotSize + 2 * seedSlotSpacing) / 2;
var seedGridStartY = 2732 - 280;
for (var seedIndex = 0; seedIndex < 3; seedIndex++) {
var seedSlot = game.addChild(new Seed());
seedSlot.slotIndex = seedIndex;
seedSlot.x = seedGridStartX + seedIndex * (seedSlotSize + seedSlotSpacing) + seedSlotSize / 2;
seedSlot.y = seedGridStartY;
seeds.push(seedSlot);
}
// Add seed types - each slot represents 5 of that seed
seeds[0].setSeed('tomatoseed');
seeds[1].setSeed('potatoseed');
seeds[2].setSeed('carrotseed');
var draggedSeed = null;
var draggedSeedStartSlot = null;
game.down = function (x, y, obj) {
// Check if clicking on a seed (not the slot itself)
for (var seedIndex = 0; seedIndex < seeds.length; seedIndex++) {
var seed = seeds[seedIndex];
// Only allow dragging if seed has a seedType and we're clicking on the seed
if (seed.seedType) {
var distance = Math.sqrt(Math.pow(x - seed.x, 2) + Math.pow(y - seed.y, 2));
// Check if click is within seed bounds (radius approximately 50 pixels for 100x100 seed)
if (distance < 60) {
draggedSeed = seed;
draggedSeedStartSlot = seedIndex;
seed.isDragging = true;
seed.initialX = seed.x;
seed.initialY = seed.y;
var seedGraphics = seed.getSeedGraphics();
if (seedGraphics) {
tween.stop(seedGraphics);
tween(seedGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 100
});
}
return;
}
}
}
for (var i = 0; i < plants.length; i++) {
var plant = plants[i];
var distance = Math.sqrt(Math.pow(x - plant.x, 2) + Math.pow(y - plant.y, 2));
if (distance < 80 && plant.isReady) {
plant.harvest();
totalRewards++;
updateScoreDisplay();
// Create harvest effect
var effect = game.addChild(LK.getAsset('harvestEffect', {
anchorX: 0.5,
anchorY: 0.5
}));
effect.x = plant.x;
effect.y = plant.y;
effect.alpha = 1;
tween(effect, {
alpha: 0,
y: plant.y - 60
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
effect.destroy();
}
});
break;
}
}
};
game.move = function (x, y, obj) {
if (draggedSeed) {
var seedGraphics = draggedSeed.getSeedGraphics();
if (seedGraphics) {
seedGraphics.x = x - draggedSeed.x;
seedGraphics.y = y - draggedSeed.y;
}
}
};
game.up = function (x, y, obj) {
if (draggedSeed) {
var placed = false;
for (var plantIndex = 0; plantIndex < plants.length; plantIndex++) {
var plant = plants[plantIndex];
var plantDistance = Math.sqrt(Math.pow(x - plant.x, 2) + Math.pow(y - plant.y, 2));
if (plantDistance < 175) {
if (draggedSeed.seedType) {
plant.seedPlanted = true;
draggedSeed.decrementSeedCount();
plant.initialize();
if (plant.timerDisplay) {
plant.timerDisplay.alpha = 1;
}
placed = true;
}
break;
}
}
var seedGraphics = draggedSeed.getSeedGraphics();
if (seedGraphics) {
tween.stop(seedGraphics);
if (!placed) {
tween(seedGraphics, {
x: 0,
y: 0,
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeOut
});
} else {
tween(seedGraphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
}
draggedSeed.isDragging = false;
draggedSeed = null;
draggedSeedStartSlot = null;
}
};
game.update = function () {
for (var i = 0; i < plants.length; i++) {
if (plants[i].seedPlanted) {
plants[i].update();
}
}
};