Code edit (1 edits merged)
Please save this source code
User prompt
make more space between boxes
User prompt
Do some spacing between the boxesand move it to the left edge
User prompt
make the boxes horizontal from left edge to the right edge you can do 2 lines of boxes
User prompt
add the new assets of seeds to the game in the boxes
User prompt
Import of asset
User prompt
set the fading up animation for all coins and seeds when i collect it ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
respawn tomato and potato not just carrot
User prompt
track the placed asset if tomatoseed placed in soil then i collect tomatoseeds, if i placed potatoseed i collect potato seeds, if i placed carrotseed i colllect carrotseeds. do random numbers for all seeds sometime 1-2-3 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Change 'dirt' to 'soil'
User prompt
Didn't work i collect only carrots! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
change text 'Rewards' to 'coins'.
User prompt
try to focus on the placed seeds if tomato placed then later i have to collect tomato so on for other seeds. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
no seeds respawned add animation respawning for tomato potato carrots to be bouncing 2 times like coins. do random number 1 or 2 or 3 of the seeds to make more seeds. also change 'slots' of the seeds to 'woodbox'. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
respawn seeds tow a random number from 1-3 i only collected coins! and for the coins random number from 2-4. when i collect remove coins & seeds don't let it on dirt. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
change animation to jumping and bouncing 2 times on dirt then hold still for coins and the placed seed ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'stage.addChild(coinAsset);' Line Number: 86
User prompt
Respawn random number of coins 1-5 and number of the placed seeds 1-3 from the dirt after time is finished the count down. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
change 'harvesteffect' to 'coin' because its coin and do random collecting of the placed seed from 1 to 3. also show coin and the random number of the seed when time is finished counting you can do it with animation small jumping beside dirt to collect them. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Remove plant asset
User prompt
there still be more empty dirt by i couldn't pick up any seed to place it!
User prompt
if there's empty dirt then can pickup seeds and place it in it. if all dirt slots are full with seeds and time is moving then seeds can't be picked up. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
I said after placing not in the start! you prevent it from the start of the game!! ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
If time is moving in dirt then can't pickup any seed from slots ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
if dirt already have seed in it and time is moving then seeds can't be placed as a rule!
/****
* 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('Soil', {
anchorX: 0.5,
anchorY: 0.5
});
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;
// Don't reset plantedSeedType here - it's already set before initialize is called
self.harvestCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 coins
};
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.spawnCoins(); //{spawnCoins_call}
}
}
};
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.spawnCoins = function () {
var coinCount = Math.floor(Math.random() * 3) + 2; // Random 2-4 coins
var seedCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 seeds
for (var c = 0; c < coinCount; c++) {
var angle = Math.PI * 2 * c / coinCount; // Distribute coins in circle
var offsetX = Math.cos(angle) * 150;
var offsetY = Math.sin(angle) * 150;
var coinAsset = LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
coinAsset.x = self.x;
coinAsset.y = self.y;
coinAsset.alpha = 1;
coinAsset.isCollectable = true;
coinAsset.coinValue = 1;
gameInstance.addChild(coinAsset);
spawnedCoins.push(coinAsset);
// First bounce up
tween(coinAsset, {
y: self.y - 100
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFirstBounce() {
// Fall back down
tween(coinAsset, {
y: self.y
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFirstLand() {
// Second bounce up
tween(coinAsset, {
y: self.y - 60
}, {
duration: 250,
easing: tween.easeOut,
onFinish: function onSecondBounce() {
// Fall back down and stay still
tween(coinAsset, {
y: self.y
}, {
duration: 150,
easing: tween.easeIn
});
}
});
}
});
}
});
}
var actualSeedCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 seeds
for (var s = 0; s < actualSeedCount; s++) {
var seedType = self.plantedSeedType; // Use the planted seed type
if (!seedType) {
seedType = 'carrotseed'; // Default fallback only if no seed type exists
}
var seedAsset = LK.getAsset(seedType, {
anchorX: 0.5,
//{seedAsset_a}
anchorY: 0.5 //{seedAsset_b}
}); //{seedAsset_c}
seedAsset.plantedSeedType = seedType; // Track the seed type on spawned asset
seedAsset.x = self.x;
seedAsset.y = self.y;
seedAsset.alpha = 1;
seedAsset.isCollectable = true;
seedAsset.seedValue = 1;
gameInstance.addChild(seedAsset);
spawnedSeeds.push(seedAsset);
// First bounce up
tween(seedAsset, {
//{seedAsset_d}
y: self.y - 100 //{seedAsset_e}
}, {
//{seedAsset_f}
duration: 300,
//{seedAsset_g}
easing: tween.easeOut,
//{seedAsset_h}
onFinish: function onFirstSeedBounce() {
// Fall back down//{seedAsset_i}
tween(seedAsset, {
//{seedAsset_j}
y: self.y //{seedAsset_k}
}, {
//{seedAsset_l}
duration: 200,
//{seedAsset_m}
easing: tween.easeIn,
//{seedAsset_n}
onFinish: function onFirstSeedLand() {
// Second bounce up//{seedAsset_o}
tween(seedAsset, {
//{seedAsset_p}
y: self.y - 60 //{seedAsset_q}
}, {
//{seedAsset_r}
duration: 250,
//{seedAsset_s}
easing: tween.easeOut,
//{seedAsset_t}
onFinish: function onSecondSeedBounce() {
// Fall back down and stay still//{seedAsset_u}
tween(seedAsset, {
//{seedAsset_v}
y: self.y //{seedAsset_w}
}, {
//{seedAsset_x}
duration: 150,
//{seedAsset_y}
easing: tween.easeIn //{seedAsset_z}
}); //{seedAsset_A}
} //{seedAsset_B}
}); //{seedAsset_C}
} //{seedAsset_D}
}); //{seedAsset_E}
} //{seedAsset_F}
}); //{seedAsset_G}
} //{seedAsset_H}
};
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('woodbox', {
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');
}
if (seedGraphics) {
seedGraphics.alpha = 1;
}
}
};
self.decrementSeedCount = function () {
if (self.seedCount > 0) {
self.seedCount--;
if (self.seedCountText) {
self.seedCountText.setText(self.seedCount + '/5');
}
if (self.seedCount <= 0 && seedGraphics) {
seedGraphics.alpha = 1;
}
}
};
self.getSeed = function () {
return self.seedType;
};
self.getSeedGraphics = function () {
return seedGraphics;
};
self.removeSeed = function () {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = null;
};
self.hideSeedGraphics = function () {
if (seedGraphics) {
seedGraphics.alpha = 0;
}
};
self.showSeedGraphics = function () {
if (seedGraphics) {
seedGraphics.alpha = 1;
}
};
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 gameInstance = game;
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('coins: 0', {
size: 64,
fill: '#ffffff'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function updateScoreDisplay() {
scoreText.setText('coins: ' + 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 - multiple rows to show all seed types
var seeds = [];
var seedSlotSize = 120;
var seedSlotSpacing = 40;
var seedsPerRow = 3;
var seedGridStartX = 2048 / 2 - (seedsPerRow * seedSlotSize + (seedsPerRow - 1) * seedSlotSpacing) / 2;
var seedGridStartY = 2732 - 380;
var seedRowSpacing = 160;
var seedTypes = ['tomatoseed', 'potatoseed', 'carrotseed', 'ananasseed', 'appleseed', 'brocoliseed', 'eggplantseed', 'garlicseed', 'lemonseed', 'Orangeseed', 'pumpkinseed', 'watermelonseed'];
for (var seedIndex = 0; seedIndex < seedTypes.length; seedIndex++) {
var rowIndex = Math.floor(seedIndex / seedsPerRow);
var colIndex = seedIndex % seedsPerRow;
var seedSlot = game.addChild(new Seed());
seedSlot.slotIndex = seedIndex;
seedSlot.x = seedGridStartX + colIndex * (seedSlotSize + seedSlotSpacing) + seedSlotSize / 2;
seedSlot.y = seedGridStartY + rowIndex * seedRowSpacing;
seeds.push(seedSlot);
seedSlot.setSeed(seedTypes[seedIndex]);
}
var draggedSeed = null;
var draggedSeedStartSlot = null;
var draggedSeedDuplicate = null;
var spawnedCoins = [];
var spawnedSeeds = [];
game.down = function (x, y, obj) {
// Check if clicking on spawned coins
for (var c = spawnedCoins.length - 1; c >= 0; c--) {
var coin = spawnedCoins[c];
var coinDistance = Math.sqrt(Math.pow(x - coin.x, 2) + Math.pow(y - coin.y, 2));
if (coinDistance < 80 && coin.isCollectable) {
totalRewards += coin.coinValue;
updateScoreDisplay();
coin.isCollectable = false;
tween(coin, {
alpha: 0,
y: coin.y - 150
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onCoinCollected() {
coin.destroy();
spawnedCoins.splice(spawnedCoins.indexOf(coin), 1);
}
});
return;
}
}
// Check if clicking on spawned seeds
for (var s = spawnedSeeds.length - 1; s >= 0; s--) {
var seed = spawnedSeeds[s];
var seedDistance = Math.sqrt(Math.pow(x - seed.x, 2) + Math.pow(y - seed.y, 2));
if (seedDistance < 80 && seed.isCollectable) {
// Add seeds back to inventory - find matching seed slot by type
var seedTypeToRestore = seed.plantedSeedType || 'carrotseed';
for (var seedSlotIdx = 0; seedSlotIdx < seeds.length; seedSlotIdx++) {
if (seeds[seedSlotIdx].seedType === seedTypeToRestore) {
seeds[seedSlotIdx].seedCount = Math.min(seeds[seedSlotIdx].seedCount + seed.seedValue, 5);
if (seeds[seedSlotIdx].seedCountText) {
seeds[seedSlotIdx].seedCountText.setText(seeds[seedSlotIdx].seedCount + '/5');
}
break;
}
} //{2L_ext}
seed.isCollectable = false;
tween(seed, {
alpha: 0,
y: seed.y - 150
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onSeedCollected() {
seed.destroy();
spawnedSeeds.splice(spawnedSeeds.indexOf(seed), 1);
}
});
return;
}
}
// 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 seed count > 0
if (seed.seedType && seed.seedCount > 0) {
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);
// Create a duplicate seed graphic for dragging
draggedSeedDuplicate = LK.getAsset(seed.seedType, {
anchorX: 0.5,
anchorY: 0.5
});
draggedSeedDuplicate.x = x;
draggedSeedDuplicate.y = y;
game.addChild(draggedSeedDuplicate);
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();
var coinCount = plant.harvestCount;
totalRewards += coinCount;
updateScoreDisplay();
// Create coin effect with count text
var effect = game.addChild(LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
}));
effect.x = plant.x;
effect.y = plant.y;
effect.alpha = 1;
// Create text showing coin count
var coinText = new Text2('+' + coinCount, {
size: 48,
fill: '#FFD700'
});
coinText.anchor.set(0.5, 0.5);
coinText.x = plant.x;
coinText.y = plant.y - 80;
game.addChild(coinText);
// Animate coin jumping up and fading
tween(effect, {
alpha: 0,
y: plant.y - 100
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
effect.destroy();
}
});
// Animate coin text jumping and fading
tween(coinText, {
alpha: 0,
y: plant.y - 150
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinishText() {
coinText.destroy();
}
});
break;
}
}
};
game.move = function (x, y, obj) {
if (draggedSeed) {
if (draggedSeedDuplicate) {
draggedSeedDuplicate.x = x;
draggedSeedDuplicate.y = 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;
plant.plantedSeedType = draggedSeed.seedType; // Store which seed type was planted
draggedSeed.decrementSeedCount();
plant.initialize();
if (plant.timerDisplay) {
plant.timerDisplay.alpha = 1;
}
var dirtGraphics = plant.children[0];
if (dirtGraphics) {
var originalX = dirtGraphics.x;
tween(dirtGraphics, {
x: originalX + 8
}, {
duration: 50,
easing: tween.easeInOut
});
tween(dirtGraphics, {
x: originalX - 8
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(dirtGraphics, {
x: originalX
}, {
duration: 50,
easing: tween.easeInOut
});
}
});
}
draggedSeed.showSeedGraphics();
placed = true;
}
break;
}
}
if (draggedSeedDuplicate) {
draggedSeedDuplicate.destroy();
draggedSeedDuplicate = null;
}
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
});
seedGraphics.alpha = draggedSeed.seedCount <= 0 ? 0.3 : 1;
} 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('Soil', {
anchorX: 0.5,
anchorY: 0.5
});
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;
// Don't reset plantedSeedType here - it's already set before initialize is called
self.harvestCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 coins
};
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.spawnCoins(); //{spawnCoins_call}
}
}
};
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.spawnCoins = function () {
var coinCount = Math.floor(Math.random() * 3) + 2; // Random 2-4 coins
var seedCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 seeds
for (var c = 0; c < coinCount; c++) {
var angle = Math.PI * 2 * c / coinCount; // Distribute coins in circle
var offsetX = Math.cos(angle) * 150;
var offsetY = Math.sin(angle) * 150;
var coinAsset = LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
coinAsset.x = self.x;
coinAsset.y = self.y;
coinAsset.alpha = 1;
coinAsset.isCollectable = true;
coinAsset.coinValue = 1;
gameInstance.addChild(coinAsset);
spawnedCoins.push(coinAsset);
// First bounce up
tween(coinAsset, {
y: self.y - 100
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFirstBounce() {
// Fall back down
tween(coinAsset, {
y: self.y
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFirstLand() {
// Second bounce up
tween(coinAsset, {
y: self.y - 60
}, {
duration: 250,
easing: tween.easeOut,
onFinish: function onSecondBounce() {
// Fall back down and stay still
tween(coinAsset, {
y: self.y
}, {
duration: 150,
easing: tween.easeIn
});
}
});
}
});
}
});
}
var actualSeedCount = Math.floor(Math.random() * 3) + 1; // Random 1-3 seeds
for (var s = 0; s < actualSeedCount; s++) {
var seedType = self.plantedSeedType; // Use the planted seed type
if (!seedType) {
seedType = 'carrotseed'; // Default fallback only if no seed type exists
}
var seedAsset = LK.getAsset(seedType, {
anchorX: 0.5,
//{seedAsset_a}
anchorY: 0.5 //{seedAsset_b}
}); //{seedAsset_c}
seedAsset.plantedSeedType = seedType; // Track the seed type on spawned asset
seedAsset.x = self.x;
seedAsset.y = self.y;
seedAsset.alpha = 1;
seedAsset.isCollectable = true;
seedAsset.seedValue = 1;
gameInstance.addChild(seedAsset);
spawnedSeeds.push(seedAsset);
// First bounce up
tween(seedAsset, {
//{seedAsset_d}
y: self.y - 100 //{seedAsset_e}
}, {
//{seedAsset_f}
duration: 300,
//{seedAsset_g}
easing: tween.easeOut,
//{seedAsset_h}
onFinish: function onFirstSeedBounce() {
// Fall back down//{seedAsset_i}
tween(seedAsset, {
//{seedAsset_j}
y: self.y //{seedAsset_k}
}, {
//{seedAsset_l}
duration: 200,
//{seedAsset_m}
easing: tween.easeIn,
//{seedAsset_n}
onFinish: function onFirstSeedLand() {
// Second bounce up//{seedAsset_o}
tween(seedAsset, {
//{seedAsset_p}
y: self.y - 60 //{seedAsset_q}
}, {
//{seedAsset_r}
duration: 250,
//{seedAsset_s}
easing: tween.easeOut,
//{seedAsset_t}
onFinish: function onSecondSeedBounce() {
// Fall back down and stay still//{seedAsset_u}
tween(seedAsset, {
//{seedAsset_v}
y: self.y //{seedAsset_w}
}, {
//{seedAsset_x}
duration: 150,
//{seedAsset_y}
easing: tween.easeIn //{seedAsset_z}
}); //{seedAsset_A}
} //{seedAsset_B}
}); //{seedAsset_C}
} //{seedAsset_D}
}); //{seedAsset_E}
} //{seedAsset_F}
}); //{seedAsset_G}
} //{seedAsset_H}
};
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('woodbox', {
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');
}
if (seedGraphics) {
seedGraphics.alpha = 1;
}
}
};
self.decrementSeedCount = function () {
if (self.seedCount > 0) {
self.seedCount--;
if (self.seedCountText) {
self.seedCountText.setText(self.seedCount + '/5');
}
if (self.seedCount <= 0 && seedGraphics) {
seedGraphics.alpha = 1;
}
}
};
self.getSeed = function () {
return self.seedType;
};
self.getSeedGraphics = function () {
return seedGraphics;
};
self.removeSeed = function () {
if (seedGraphics) {
seedGraphics.destroy();
seedGraphics = null;
}
self.seedType = null;
};
self.hideSeedGraphics = function () {
if (seedGraphics) {
seedGraphics.alpha = 0;
}
};
self.showSeedGraphics = function () {
if (seedGraphics) {
seedGraphics.alpha = 1;
}
};
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 gameInstance = game;
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('coins: 0', {
size: 64,
fill: '#ffffff'
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
function updateScoreDisplay() {
scoreText.setText('coins: ' + 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 - multiple rows to show all seed types
var seeds = [];
var seedSlotSize = 120;
var seedSlotSpacing = 40;
var seedsPerRow = 3;
var seedGridStartX = 2048 / 2 - (seedsPerRow * seedSlotSize + (seedsPerRow - 1) * seedSlotSpacing) / 2;
var seedGridStartY = 2732 - 380;
var seedRowSpacing = 160;
var seedTypes = ['tomatoseed', 'potatoseed', 'carrotseed', 'ananasseed', 'appleseed', 'brocoliseed', 'eggplantseed', 'garlicseed', 'lemonseed', 'Orangeseed', 'pumpkinseed', 'watermelonseed'];
for (var seedIndex = 0; seedIndex < seedTypes.length; seedIndex++) {
var rowIndex = Math.floor(seedIndex / seedsPerRow);
var colIndex = seedIndex % seedsPerRow;
var seedSlot = game.addChild(new Seed());
seedSlot.slotIndex = seedIndex;
seedSlot.x = seedGridStartX + colIndex * (seedSlotSize + seedSlotSpacing) + seedSlotSize / 2;
seedSlot.y = seedGridStartY + rowIndex * seedRowSpacing;
seeds.push(seedSlot);
seedSlot.setSeed(seedTypes[seedIndex]);
}
var draggedSeed = null;
var draggedSeedStartSlot = null;
var draggedSeedDuplicate = null;
var spawnedCoins = [];
var spawnedSeeds = [];
game.down = function (x, y, obj) {
// Check if clicking on spawned coins
for (var c = spawnedCoins.length - 1; c >= 0; c--) {
var coin = spawnedCoins[c];
var coinDistance = Math.sqrt(Math.pow(x - coin.x, 2) + Math.pow(y - coin.y, 2));
if (coinDistance < 80 && coin.isCollectable) {
totalRewards += coin.coinValue;
updateScoreDisplay();
coin.isCollectable = false;
tween(coin, {
alpha: 0,
y: coin.y - 150
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onCoinCollected() {
coin.destroy();
spawnedCoins.splice(spawnedCoins.indexOf(coin), 1);
}
});
return;
}
}
// Check if clicking on spawned seeds
for (var s = spawnedSeeds.length - 1; s >= 0; s--) {
var seed = spawnedSeeds[s];
var seedDistance = Math.sqrt(Math.pow(x - seed.x, 2) + Math.pow(y - seed.y, 2));
if (seedDistance < 80 && seed.isCollectable) {
// Add seeds back to inventory - find matching seed slot by type
var seedTypeToRestore = seed.plantedSeedType || 'carrotseed';
for (var seedSlotIdx = 0; seedSlotIdx < seeds.length; seedSlotIdx++) {
if (seeds[seedSlotIdx].seedType === seedTypeToRestore) {
seeds[seedSlotIdx].seedCount = Math.min(seeds[seedSlotIdx].seedCount + seed.seedValue, 5);
if (seeds[seedSlotIdx].seedCountText) {
seeds[seedSlotIdx].seedCountText.setText(seeds[seedSlotIdx].seedCount + '/5');
}
break;
}
} //{2L_ext}
seed.isCollectable = false;
tween(seed, {
alpha: 0,
y: seed.y - 150
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onSeedCollected() {
seed.destroy();
spawnedSeeds.splice(spawnedSeeds.indexOf(seed), 1);
}
});
return;
}
}
// 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 seed count > 0
if (seed.seedType && seed.seedCount > 0) {
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);
// Create a duplicate seed graphic for dragging
draggedSeedDuplicate = LK.getAsset(seed.seedType, {
anchorX: 0.5,
anchorY: 0.5
});
draggedSeedDuplicate.x = x;
draggedSeedDuplicate.y = y;
game.addChild(draggedSeedDuplicate);
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();
var coinCount = plant.harvestCount;
totalRewards += coinCount;
updateScoreDisplay();
// Create coin effect with count text
var effect = game.addChild(LK.getAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
}));
effect.x = plant.x;
effect.y = plant.y;
effect.alpha = 1;
// Create text showing coin count
var coinText = new Text2('+' + coinCount, {
size: 48,
fill: '#FFD700'
});
coinText.anchor.set(0.5, 0.5);
coinText.x = plant.x;
coinText.y = plant.y - 80;
game.addChild(coinText);
// Animate coin jumping up and fading
tween(effect, {
alpha: 0,
y: plant.y - 100
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
effect.destroy();
}
});
// Animate coin text jumping and fading
tween(coinText, {
alpha: 0,
y: plant.y - 150
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinishText() {
coinText.destroy();
}
});
break;
}
}
};
game.move = function (x, y, obj) {
if (draggedSeed) {
if (draggedSeedDuplicate) {
draggedSeedDuplicate.x = x;
draggedSeedDuplicate.y = 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;
plant.plantedSeedType = draggedSeed.seedType; // Store which seed type was planted
draggedSeed.decrementSeedCount();
plant.initialize();
if (plant.timerDisplay) {
plant.timerDisplay.alpha = 1;
}
var dirtGraphics = plant.children[0];
if (dirtGraphics) {
var originalX = dirtGraphics.x;
tween(dirtGraphics, {
x: originalX + 8
}, {
duration: 50,
easing: tween.easeInOut
});
tween(dirtGraphics, {
x: originalX - 8
}, {
duration: 50,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(dirtGraphics, {
x: originalX
}, {
duration: 50,
easing: tween.easeInOut
});
}
});
}
draggedSeed.showSeedGraphics();
placed = true;
}
break;
}
}
if (draggedSeedDuplicate) {
draggedSeedDuplicate.destroy();
draggedSeedDuplicate = null;
}
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
});
seedGraphics.alpha = draggedSeed.seedCount <= 0 ? 0.3 : 1;
} 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();
}
}
};