/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add background image to the game
var background = LK.getAsset('bg1', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Function to increment points based on pointsPerSecond
function incrementPoints() {
points += pointsPerSecond;
pointsText.setText('Points: ' + points);
if (points >= 800 && !backgroundChanged) {
var newBackground = LK.getAsset('Bg2', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.removeChild(background);
background = newBackground;
game.addChild(background);
// Re-add all game elements to ensure they render on top of the new background
game.removeChild(treeSeedling);
game.addChild(treeSeedling);
game.removeChild(upgradeButton);
game.addChild(upgradeButton);
game.removeChild(upgradeNameText);
game.addChild(upgradeNameText);
game.removeChild(upgradeCostText);
game.addChild(upgradeCostText);
game.removeChild(upgradeButton2);
game.addChild(upgradeButton2);
game.removeChild(upgradeNameText2);
game.addChild(upgradeNameText2);
game.removeChild(upgradeCostText2);
game.addChild(upgradeCostText2);
game.removeChild(upgradeButton3);
game.addChild(upgradeButton3);
game.removeChild(upgradeNameText3);
game.addChild(upgradeNameText3);
game.removeChild(upgradeCostText3);
game.addChild(upgradeCostText3);
game.removeChild(upgradeButton4);
game.addChild(upgradeButton4);
game.removeChild(upgradeNameText4);
game.addChild(upgradeNameText4);
game.removeChild(upgradeCostText4);
game.addChild(upgradeCostText4);
backgroundChanged = true;
} else if (points >= 500000 && currentTreeLevel < 4) {
treeGrowthStageText.setText('Growth Stage: Colossal');
var newTree = LK.getAsset('Colossal_tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 4;
} else if (points >= 50000 && currentTreeLevel < 3) {
treeGrowthStageText.setText('Growth Stage: Giant');
var newTree = LK.getAsset('Giant_tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 3;
} else if (points >= 15000 && currentTreeLevel < 2) {
treeGrowthStageText.setText('Growth Stage: Big');
var newTree = LK.getAsset('Tree_big', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 2;
} else if (points >= 500 && currentTreeLevel < 1) {
treeGrowthStageText.setText('Growth Stage: Normal');
var newTree = LK.getAsset('Tree_normal', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 1;
} else if (currentTreeLevel == 0) {
treeGrowthStageText.setText('Growth Stage: Seedling');
if (treeSeedling.width !== 280) {
var newTree = LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
}
}
}
// Set an interval to call incrementPoints every second
LK.setInterval(incrementPoints, 1000);
// Function to determine the growth stage based on the size of the tree asset
function getTreeGrowthStage(treeAsset) {
var size = treeAsset.width * treeAsset.height;
if (size >= 800 * 765.63) {
return 'Colossal';
} else if (size >= 500 * 500) {
return 'Giant';
} else if (size >= 250 * 259.11) {
return 'Big';
} else if (size >= 100 * 111.79) {
return 'Normal';
} else {
return 'Seedling';
}
}
// Retrieve the tree seedling asset and place it at the bottom of the screen
var treeSeedling = LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.addChild(treeSeedling);
// Retrieve the upgrade button asset and place it at the middle-right of the screen
var upgradeButton = LK.getAsset('Upgrade_button', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2
});
game.addChild(upgradeButton);
// Create a Text2 object to display the name 'watering can' above the upgrade button
var upgradeNameText = new Text2('watering can', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText.anchor.set(0.5, 1.0);
upgradeNameText.x = upgradeButton.x - upgradeButton.width / 2;
upgradeNameText.y = upgradeButton.y - upgradeButton.height / 2 - 10;
game.addChild(upgradeNameText);
// Create a Text2 object to display the cost above the upgrade button
var upgradeCostText = new Text2('Cost: 50', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText.anchor.set(0.5, 1.0);
upgradeCostText.x = upgradeButton.x - upgradeButton.width / 2;
upgradeCostText.y = upgradeNameText.y - 40;
game.addChild(upgradeCostText);
// Retrieve the second upgrade button asset and place it below the first upgrade button
var upgradeButton2 = LK.getAsset('Upgrade_button2', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 400
});
game.addChild(upgradeButton2);
// Create a Text2 object to display the name 'fertilizer' above the second upgrade button
var upgradeNameText2 = new Text2('fertilizer', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText2.anchor.set(0.5, 1.0);
upgradeNameText2.x = upgradeButton2.x - upgradeButton2.width / 2;
upgradeNameText2.y = upgradeButton2.y - upgradeButton2.height / 2 - 10;
game.addChild(upgradeNameText2);
// Create a Text2 object to display the cost above the second upgrade button
var upgradeCostText2 = new Text2('Cost: 100', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText2.anchor.set(0.5, 1.0);
upgradeCostText2.x = upgradeButton2.x - upgradeButton2.width / 2;
upgradeCostText2.y = upgradeNameText2.y - 40;
game.addChild(upgradeCostText2);
// Add touch event to upgradeButton
upgradeButton.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton, 0x000000, 500);
if (points >= upgradeCost) {
LK.getSound('Buy_upgrade').play();
points -= upgradeCost;
upgradeCost *= 1.3; // Increase the cost by 30%
upgradeCostText.setText('Cost: ' + Math.ceil(upgradeCost));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 1;
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.1
}, {
duration: 1000,
easing: tween.easeOut
});
// Create watering can animation above the tree
var wateringCan = LK.getAsset('watering_can', {
anchorX: 0.5,
anchorY: 0.5,
x: treeSeedling.x - 100,
y: treeSeedling.y - treeSeedling.height - 200,
alpha: 0
});
game.addChild(wateringCan);
// Animate watering can appearing, moving over tree, and disappearing
tween(wateringCan, {
alpha: 1
}, {
duration: 300,
onFinish: function onFinish() {
// Move watering can across tree
tween(wateringCan, {
x: treeSeedling.x + 100
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Fade out watering can
tween(wateringCan, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
game.removeChild(wateringCan);
}
});
}
});
}
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Retrieve the third upgrade button asset and place it below the second upgrade button
var upgradeButton3 = LK.getAsset('Upgrade_button_3', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 800
});
game.addChild(upgradeButton3);
// Create a Text2 object to display the name 'soil' above the third upgrade button
var upgradeNameText3 = new Text2('soil', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText3.anchor.set(0.5, 1.0);
upgradeNameText3.x = upgradeButton3.x - upgradeButton3.width / 2;
upgradeNameText3.y = upgradeButton3.y - upgradeButton3.height / 2 - 10;
game.addChild(upgradeNameText3);
// Create a Text2 object to display the cost above the third upgrade button
var upgradeCostText3 = new Text2('Cost: 500', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText3.anchor.set(0.5, 1.0);
upgradeCostText3.x = upgradeButton3.x - upgradeButton3.width / 2;
upgradeCostText3.y = upgradeNameText3.y - 40;
game.addChild(upgradeCostText3);
// Retrieve the fourth upgrade button asset and place it below the third upgrade button
var upgradeButton4 = LK.getAsset('Upgrade_button4', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 1200
});
game.addChild(upgradeButton4);
// Create a Text2 object to display the name 'sunlight' above the fourth upgrade button
var upgradeNameText4 = new Text2('sunlight', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText4.anchor.set(0.5, 1.0);
upgradeNameText4.x = upgradeButton4.x - upgradeButton4.width / 2;
upgradeNameText4.y = upgradeButton4.y - upgradeButton4.height / 2 - 10;
game.addChild(upgradeNameText4);
// Create a Text2 object to display the cost above the fourth upgrade button
var upgradeCostText4 = new Text2('Cost: 2000', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText4.anchor.set(0.5, 1.0);
upgradeCostText4.x = upgradeButton4.x - upgradeButton4.width / 2;
upgradeCostText4.y = upgradeNameText4.y - 40;
game.addChild(upgradeCostText4);
// Add touch event to upgradeButton4
upgradeButton4.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 4 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton4, 0x000000, 500);
if (points >= upgradeCost4) {
LK.getSound('Buy_upgrade_3').play();
points -= upgradeCost4;
upgradeCost4 *= 2.2; // Increase the cost by 120%
upgradeCostText4.setText('Cost: ' + Math.ceil(upgradeCost4));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 50; // UpgradeButton4 gives even more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.25
}, {
duration: 2000,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to upgradeButton3
upgradeButton3.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 3 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton3, 0x000000, 500);
if (points >= upgradeCost3) {
LK.getSound('Buy_upgrade_3').play();
points -= upgradeCost3;
upgradeCost3 *= 1.8; // Increase the cost by 80%
upgradeCostText3.setText('Cost: ' + Math.ceil(upgradeCost3));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 15; // UpgradeButton3 gives more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.2
}, {
duration: 1500,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to upgradeButton2
upgradeButton2.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 2 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton2, 0x000000, 500);
if (points >= upgradeCost2) {
LK.getSound('Buy_upgrade_2').play();
points -= upgradeCost2;
upgradeCost2 *= 1.6; // Increase the cost by 60%
upgradeCostText2.setText('Cost: ' + Math.ceil(upgradeCost2));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 3; // UpgradeButton2 gives more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.15
}, {
duration: 1200,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to treeSeedling
treeSeedling.down = function (x, y, obj) {
// Increase points
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
// Apply drop effect
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
// Variable to track the growth stage of the tree
var treeGrowthStage = getTreeGrowthStage(treeSeedling);
// Variable to track points
var points = 0;
// Variable to track the cost of the first upgrade
var upgradeCost = 50;
// Variable to track the cost of the second upgrade
var upgradeCost2 = 100;
// Variable to track points per second
var upgradeCost3 = 500;
var pointsPerSecond = 0;
// Variable to track the cost of the third upgrade
// Variable to track the cost of the fourth upgrade
var upgradeCost4 = 2000;
// Variable to track if background has been changed
var backgroundChanged = false;
// Variable to track current tree level to prevent downgrade
var currentTreeLevel = 0; // 0=Seedling, 1=Normal, 2=Big, 3=Giant, 4=Colossal
// Function to update the X position of points
function updatePointsX(newX) {
pointsText.x = newX;
}
// Function to update the Y position of points
function updatePointsY(newY) {
pointsText.y = newY;
}
// Create a Text2 object to display the tree growth stage
var treeGrowthStageText = new Text2('Growth Stage: ' + getTreeGrowthStage(treeSeedling), {
size: 100,
fill: 0xFFFFFF
});
// Create a Text2 object to display the points
var pointsText = new Text2('Points: ' + points, {
size: 100,
fill: 0xFFFFFF
});
pointsText.anchor.set(0.5, -1);
LK.gui.top.addChild(pointsText);
// Set the anchor point to the center of the top edge
treeGrowthStageText.anchor.set(0.5, 0);
// Position the text at the top-center of the screen
LK.gui.top.addChild(treeGrowthStageText);
; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Add background image to the game
var background = LK.getAsset('bg1', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Function to increment points based on pointsPerSecond
function incrementPoints() {
points += pointsPerSecond;
pointsText.setText('Points: ' + points);
if (points >= 800 && !backgroundChanged) {
var newBackground = LK.getAsset('Bg2', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.removeChild(background);
background = newBackground;
game.addChild(background);
// Re-add all game elements to ensure they render on top of the new background
game.removeChild(treeSeedling);
game.addChild(treeSeedling);
game.removeChild(upgradeButton);
game.addChild(upgradeButton);
game.removeChild(upgradeNameText);
game.addChild(upgradeNameText);
game.removeChild(upgradeCostText);
game.addChild(upgradeCostText);
game.removeChild(upgradeButton2);
game.addChild(upgradeButton2);
game.removeChild(upgradeNameText2);
game.addChild(upgradeNameText2);
game.removeChild(upgradeCostText2);
game.addChild(upgradeCostText2);
game.removeChild(upgradeButton3);
game.addChild(upgradeButton3);
game.removeChild(upgradeNameText3);
game.addChild(upgradeNameText3);
game.removeChild(upgradeCostText3);
game.addChild(upgradeCostText3);
game.removeChild(upgradeButton4);
game.addChild(upgradeButton4);
game.removeChild(upgradeNameText4);
game.addChild(upgradeNameText4);
game.removeChild(upgradeCostText4);
game.addChild(upgradeCostText4);
backgroundChanged = true;
} else if (points >= 500000 && currentTreeLevel < 4) {
treeGrowthStageText.setText('Growth Stage: Colossal');
var newTree = LK.getAsset('Colossal_tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 4;
} else if (points >= 50000 && currentTreeLevel < 3) {
treeGrowthStageText.setText('Growth Stage: Giant');
var newTree = LK.getAsset('Giant_tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 3;
} else if (points >= 15000 && currentTreeLevel < 2) {
treeGrowthStageText.setText('Growth Stage: Big');
var newTree = LK.getAsset('Tree_big', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 2;
} else if (points >= 500 && currentTreeLevel < 1) {
treeGrowthStageText.setText('Growth Stage: Normal');
var newTree = LK.getAsset('Tree_normal', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
currentTreeLevel = 1;
} else if (currentTreeLevel == 0) {
treeGrowthStageText.setText('Growth Stage: Seedling');
if (treeSeedling.width !== 280) {
var newTree = LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.removeChild(treeSeedling);
treeSeedling = newTree;
game.addChild(treeSeedling);
treeSeedling.down = function (x, y, obj) {
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
}
}
}
// Set an interval to call incrementPoints every second
LK.setInterval(incrementPoints, 1000);
// Function to determine the growth stage based on the size of the tree asset
function getTreeGrowthStage(treeAsset) {
var size = treeAsset.width * treeAsset.height;
if (size >= 800 * 765.63) {
return 'Colossal';
} else if (size >= 500 * 500) {
return 'Giant';
} else if (size >= 250 * 259.11) {
return 'Big';
} else if (size >= 100 * 111.79) {
return 'Normal';
} else {
return 'Seedling';
}
}
// Retrieve the tree seedling asset and place it at the bottom of the screen
var treeSeedling = LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 1.0,
x: 2048 / 2,
y: 2732
});
game.addChild(treeSeedling);
// Retrieve the upgrade button asset and place it at the middle-right of the screen
var upgradeButton = LK.getAsset('Upgrade_button', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2
});
game.addChild(upgradeButton);
// Create a Text2 object to display the name 'watering can' above the upgrade button
var upgradeNameText = new Text2('watering can', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText.anchor.set(0.5, 1.0);
upgradeNameText.x = upgradeButton.x - upgradeButton.width / 2;
upgradeNameText.y = upgradeButton.y - upgradeButton.height / 2 - 10;
game.addChild(upgradeNameText);
// Create a Text2 object to display the cost above the upgrade button
var upgradeCostText = new Text2('Cost: 50', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText.anchor.set(0.5, 1.0);
upgradeCostText.x = upgradeButton.x - upgradeButton.width / 2;
upgradeCostText.y = upgradeNameText.y - 40;
game.addChild(upgradeCostText);
// Retrieve the second upgrade button asset and place it below the first upgrade button
var upgradeButton2 = LK.getAsset('Upgrade_button2', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 400
});
game.addChild(upgradeButton2);
// Create a Text2 object to display the name 'fertilizer' above the second upgrade button
var upgradeNameText2 = new Text2('fertilizer', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText2.anchor.set(0.5, 1.0);
upgradeNameText2.x = upgradeButton2.x - upgradeButton2.width / 2;
upgradeNameText2.y = upgradeButton2.y - upgradeButton2.height / 2 - 10;
game.addChild(upgradeNameText2);
// Create a Text2 object to display the cost above the second upgrade button
var upgradeCostText2 = new Text2('Cost: 100', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText2.anchor.set(0.5, 1.0);
upgradeCostText2.x = upgradeButton2.x - upgradeButton2.width / 2;
upgradeCostText2.y = upgradeNameText2.y - 40;
game.addChild(upgradeCostText2);
// Add touch event to upgradeButton
upgradeButton.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton, 0x000000, 500);
if (points >= upgradeCost) {
LK.getSound('Buy_upgrade').play();
points -= upgradeCost;
upgradeCost *= 1.3; // Increase the cost by 30%
upgradeCostText.setText('Cost: ' + Math.ceil(upgradeCost));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 1;
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.1
}, {
duration: 1000,
easing: tween.easeOut
});
// Create watering can animation above the tree
var wateringCan = LK.getAsset('watering_can', {
anchorX: 0.5,
anchorY: 0.5,
x: treeSeedling.x - 100,
y: treeSeedling.y - treeSeedling.height - 200,
alpha: 0
});
game.addChild(wateringCan);
// Animate watering can appearing, moving over tree, and disappearing
tween(wateringCan, {
alpha: 1
}, {
duration: 300,
onFinish: function onFinish() {
// Move watering can across tree
tween(wateringCan, {
x: treeSeedling.x + 100
}, {
duration: 1500,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Fade out watering can
tween(wateringCan, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
game.removeChild(wateringCan);
}
});
}
});
}
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Retrieve the third upgrade button asset and place it below the second upgrade button
var upgradeButton3 = LK.getAsset('Upgrade_button_3', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 800
});
game.addChild(upgradeButton3);
// Create a Text2 object to display the name 'soil' above the third upgrade button
var upgradeNameText3 = new Text2('soil', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText3.anchor.set(0.5, 1.0);
upgradeNameText3.x = upgradeButton3.x - upgradeButton3.width / 2;
upgradeNameText3.y = upgradeButton3.y - upgradeButton3.height / 2 - 10;
game.addChild(upgradeNameText3);
// Create a Text2 object to display the cost above the third upgrade button
var upgradeCostText3 = new Text2('Cost: 500', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText3.anchor.set(0.5, 1.0);
upgradeCostText3.x = upgradeButton3.x - upgradeButton3.width / 2;
upgradeCostText3.y = upgradeNameText3.y - 40;
game.addChild(upgradeCostText3);
// Retrieve the fourth upgrade button asset and place it below the third upgrade button
var upgradeButton4 = LK.getAsset('Upgrade_button4', {
anchorX: 1.0,
anchorY: 0.5,
x: 2048 - 50,
y: 2732 / 2 + 1200
});
game.addChild(upgradeButton4);
// Create a Text2 object to display the name 'sunlight' above the fourth upgrade button
var upgradeNameText4 = new Text2('sunlight', {
size: 50,
fill: 0xFFFFFF
});
upgradeNameText4.anchor.set(0.5, 1.0);
upgradeNameText4.x = upgradeButton4.x - upgradeButton4.width / 2;
upgradeNameText4.y = upgradeButton4.y - upgradeButton4.height / 2 - 10;
game.addChild(upgradeNameText4);
// Create a Text2 object to display the cost above the fourth upgrade button
var upgradeCostText4 = new Text2('Cost: 2000', {
size: 40,
fill: 0xFFFFFF
});
upgradeCostText4.anchor.set(0.5, 1.0);
upgradeCostText4.x = upgradeButton4.x - upgradeButton4.width / 2;
upgradeCostText4.y = upgradeNameText4.y - 40;
game.addChild(upgradeCostText4);
// Add touch event to upgradeButton4
upgradeButton4.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 4 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton4, 0x000000, 500);
if (points >= upgradeCost4) {
LK.getSound('Buy_upgrade_3').play();
points -= upgradeCost4;
upgradeCost4 *= 2.2; // Increase the cost by 120%
upgradeCostText4.setText('Cost: ' + Math.ceil(upgradeCost4));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 50; // UpgradeButton4 gives even more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.25
}, {
duration: 2000,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to upgradeButton3
upgradeButton3.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 3 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton3, 0x000000, 500);
if (points >= upgradeCost3) {
LK.getSound('Buy_upgrade_3').play();
points -= upgradeCost3;
upgradeCost3 *= 1.8; // Increase the cost by 80%
upgradeCostText3.setText('Cost: ' + Math.ceil(upgradeCost3));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 15; // UpgradeButton3 gives more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.2
}, {
duration: 1500,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to upgradeButton2
upgradeButton2.down = function (x, y, obj) {
// Logic for upgrading the tree
console.log("Upgrade button 2 pressed");
// Apply drop effect
LK.effects.flashObject(upgradeButton2, 0x000000, 500);
if (points >= upgradeCost2) {
LK.getSound('Buy_upgrade_2').play();
points -= upgradeCost2;
upgradeCost2 *= 1.6; // Increase the cost by 60%
upgradeCostText2.setText('Cost: ' + Math.ceil(upgradeCost2));
pointsText.setText('Points: ' + points);
// Increase points per second
pointsPerSecond += 3; // UpgradeButton2 gives more points per second
// Make tree grow taller with tween animation
tween(treeSeedling, {
scaleY: treeSeedling.scaleY + 0.15
}, {
duration: 1200,
easing: tween.easeOut
});
// Additional logic for upgrading the tree can be added here
} else {
console.log("Not enough points to upgrade");
LK.getSound('insufficient_sound').play();
}
};
// Add touch event to treeSeedling
treeSeedling.down = function (x, y, obj) {
// Increase points
points += 3;
LK.getSound('Click').play();
pointsText.setText('Points: ' + points);
// Apply drop effect
LK.effects.flashObject(treeSeedling, 0x000000, 500);
};
// Variable to track the growth stage of the tree
var treeGrowthStage = getTreeGrowthStage(treeSeedling);
// Variable to track points
var points = 0;
// Variable to track the cost of the first upgrade
var upgradeCost = 50;
// Variable to track the cost of the second upgrade
var upgradeCost2 = 100;
// Variable to track points per second
var upgradeCost3 = 500;
var pointsPerSecond = 0;
// Variable to track the cost of the third upgrade
// Variable to track the cost of the fourth upgrade
var upgradeCost4 = 2000;
// Variable to track if background has been changed
var backgroundChanged = false;
// Variable to track current tree level to prevent downgrade
var currentTreeLevel = 0; // 0=Seedling, 1=Normal, 2=Big, 3=Giant, 4=Colossal
// Function to update the X position of points
function updatePointsX(newX) {
pointsText.x = newX;
}
// Function to update the Y position of points
function updatePointsY(newY) {
pointsText.y = newY;
}
// Create a Text2 object to display the tree growth stage
var treeGrowthStageText = new Text2('Growth Stage: ' + getTreeGrowthStage(treeSeedling), {
size: 100,
fill: 0xFFFFFF
});
// Create a Text2 object to display the points
var pointsText = new Text2('Points: ' + points, {
size: 100,
fill: 0xFFFFFF
});
pointsText.anchor.set(0.5, -1);
LK.gui.top.addChild(pointsText);
// Set the anchor point to the center of the top edge
treeGrowthStageText.anchor.set(0.5, 0);
// Position the text at the top-center of the screen
LK.gui.top.addChild(treeGrowthStageText);
;
Tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Giant_tree. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
panel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
close button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Sticker_approved_code. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
watering can button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fertilizer button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
soil button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bg of rocks waterfall. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
nighttime scene or a different landscape altogether, such as a forest, desert, or underwater setting. The choice of `bg2` would depend on the narrative or progression of the game, offering variety and enhancing the player's experience by changing the visual context as they advance.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Sun button. In-Game asset. 2d. High contrast. No shadows
watering can. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows. In-Game asset. 2d. High contrast. No shadows