User prompt
Lets and in icons for all the tools so that they show in the UI
User prompt
Can you improve the farm plots so that they look more realistic
User prompt
Can you spread the tool UI out a little bit so that they aren't all clustered together
User prompt
lets move the active tool UI so that it is above the tool selector
User prompt
move the coins UI so that it is under the title
User prompt
Move the Active Tool UI to right above the farm plots
User prompt
lets work on cleaning up all the UIs so that they look cleaner
User prompt
Lets add in a store for players to sell the crops at
User prompt
Can we move up the farms size to a 5x5
User prompt
Now lets add in an inventory that can keep track of the seeds that the player buys from the shop
User prompt
Can we change the day/night cycle so instead of a sun it shows the in-game time
User prompt
Lets change the background from blue to a grassy green
User prompt
Now lets move the tool selector to the bottom center of the screen
User prompt
can we move the farm plot to the center of the screen
User prompt
Give the players 200 coins to start the game ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Lets and in a shop button and move the seeds and upgrades into that
User prompt
now add in buttons for people to be able to switch which tool they are using
User prompt
Add in buttons for the players to swap between tools and seeds
User prompt
make the farm land bigger
Code edit (1 edits merged)
Please save this source code
User prompt
Harvest Heroes: Farm & Grow
Initial prompt
I want to make a farming simulator type game where players start with basic hand tools and work their way up to more advance farming equipment players will start will a few seeds and basic tools to get their journey started
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
money: 200,
hoeLevel: 1,
wateringCanLevel: 1,
harvesterLevel: 1,
unlockedPlots: 1,
maxPlots: 16
});
/****
* Classes
****/
var CoinEffect = Container.expand(function () {
var self = Container.call(this);
var coinGraphic = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.animate = function (startX, startY) {
self.x = startX;
self.y = startY;
self.alpha = 1;
game.addChild(self);
// Animate coin floating up and fading out
tween(self, {
y: startY - 100,
alpha: 0
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
game.removeChild(self);
coinEffectsPool.push(self);
}
});
};
return self;
});
var Plot = Container.expand(function () {
var self = Container.call(this);
self.state = "empty"; // empty, seeded, growing, ready
self.growthProgress = 0;
self.growthRequired = 100;
self.value = 10;
self.unlocked = false;
var plotBackground = self.attachAsset('plot', {
anchorX: 0.5,
anchorY: 0.5
});
var soilGraphic = self.attachAsset('soil', {
anchorX: 0.5,
anchorY: 0.5
});
// The crop that shows on this plot
self.cropGraphic = null;
self.unlock = function () {
self.unlocked = true;
plotBackground.alpha = 1;
soilGraphic.alpha = 1;
};
self.lock = function () {
self.unlocked = false;
plotBackground.alpha = 0.3;
soilGraphic.alpha = 0.3;
self.clearCrop();
};
self.clearCrop = function () {
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
self.cropGraphic = null;
}
self.state = "empty";
self.growthProgress = 0;
};
self.plant = function () {
if (!self.unlocked || self.state !== "empty") {
return false;
}
self.state = "seeded";
self.seedType = activeSeed;
self.growthProgress = 0;
// Set crop values based on seed type
if (activeSeed === "carrot") {
self.growthRequired = 80;
self.value = 15;
} else if (activeSeed === "tomato") {
self.growthRequired = 120;
self.value = 25;
} else if (activeSeed === "wheat") {
self.growthRequired = 60;
self.value = 10;
}
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-seed', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the seed based on type
if (activeSeed === "carrot") {
self.cropGraphic.tint = 0xFF9900;
} else if (activeSeed === "tomato") {
self.cropGraphic.tint = 0xFF3333;
} else if (activeSeed === "wheat") {
self.cropGraphic.tint = 0xF5DEB3;
}
// Deduct seed cost
updateMoney(-seedCosts[activeSeed]);
return true;
};
self.water = function () {
if (!self.unlocked || self.state !== "seeded" && self.state !== "growing") {
return false;
}
var wateringEfficiency = 5 * storage.wateringCanLevel;
self.growthProgress += wateringEfficiency;
if (self.growthProgress >= self.growthRequired / 2 && self.state === "seeded") {
self.state = "growing";
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-growing', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the growing crop based on seed type
if (self.seedType === "carrot") {
self.cropGraphic.tint = 0xFF9900;
} else if (self.seedType === "tomato") {
self.cropGraphic.tint = 0xFF3333;
} else if (self.seedType === "wheat") {
self.cropGraphic.tint = 0xF5DEB3;
}
}
if (self.growthProgress >= self.growthRequired) {
self.state = "ready";
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-mature', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the mature crop based on seed type
if (self.seedType === "carrot") {
self.cropGraphic.tint = 0xFF9900;
} else if (self.seedType === "tomato") {
self.cropGraphic.tint = 0xFF3333;
} else if (self.seedType === "wheat") {
self.cropGraphic.tint = 0xF5DEB3;
}
}
return true;
};
self.harvest = function () {
if (!self.unlocked || self.state !== "ready") {
return 0;
}
var harvestValue = self.value * (1 + (storage.harvesterLevel - 1) * 0.2);
self.clearCrop();
return Math.floor(harvestValue);
};
self.update = function () {
if (currentWeather === "rain" && (self.state === "seeded" || self.state === "growing")) {
// Rain automatically waters plants a little bit
if (LK.ticks % 60 === 0) {
// Every second
self.growthProgress += 1;
if (self.growthProgress >= self.growthRequired / 2 && self.state === "seeded") {
self.state = "growing";
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-growing', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the growing crop based on seed type
if (self.seedType === "carrot") {
self.cropGraphic.tint = 0xFF9900;
} else if (self.seedType === "tomato") {
self.cropGraphic.tint = 0xFF3333;
} else if (self.seedType === "wheat") {
self.cropGraphic.tint = 0xF5DEB3;
}
}
if (self.growthProgress >= self.growthRequired) {
self.state = "ready";
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-mature', {
anchorX: 0.5,
anchorY: 0.5
});
// Tint the mature crop based on seed type
if (self.seedType === "carrot") {
self.cropGraphic.tint = 0xFF9900;
} else if (self.seedType === "tomato") {
self.cropGraphic.tint = 0xFF3333;
} else if (self.seedType === "wheat") {
self.cropGraphic.tint = 0xF5DEB3;
}
}
}
}
};
self.down = function (x, y, obj) {
if (!self.unlocked) {
return;
}
var gamePos = game.toLocal(self.parent.toGlobal(self.position));
if (activeTool === "hoe") {
// Check if player has enough money for the selected seed
if (money >= seedCosts[activeSeed]) {
if (self.plant()) {
LK.getSound('plant').play();
}
}
} else if (activeTool === "water") {
if (self.water()) {
LK.getSound('water').play();
}
} else if (activeTool === "harvest") {
var value = self.harvest();
if (value > 0) {
LK.getSound('harvest').play();
LK.getSound('coin').play();
updateMoney(value);
spawnCoinEffect(gamePos.x, gamePos.y);
}
}
};
// Initially plots should be locked unless specified
self.lock();
return self;
});
var SeedButton = Container.expand(function (seedType, cost) {
var self = Container.call(this);
self.seedType = seedType;
self.cost = cost;
var background = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
});
// Change button color to represent seed type
if (seedType === "carrot") {
background.tint = 0xFF9900;
} else if (seedType === "tomato") {
background.tint = 0xFF3333;
} else if (seedType === "wheat") {
background.tint = 0xF5DEB3;
}
var nameText = new Text2(seedType, {
size: 32,
fill: 0xFFFFFF
});
nameText.anchor.set(0.5, 0.5);
nameText.y = -15;
self.addChild(nameText);
var costText = new Text2(cost + " coins", {
size: 24,
fill: 0xFFFFFF
});
costText.anchor.set(0.5, 0.5);
costText.y = 15;
self.addChild(costText);
self.down = function (x, y, obj) {
if (money >= self.cost) {
activeSeed = self.seedType;
seedButtons.forEach(function (button) {
if (button.seedType === activeSeed) {
tween(button, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut
});
} else {
tween(button, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 200,
easing: tween.easeOut
});
}
});
}
};
return self;
});
var ShopButton = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
scaleY: 1.2
});
background.tint = 0x4169E1; // Royal blue for shop button
var titleText = new Text2("Shop", {
size: 50,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
self.addChild(titleText);
self.down = function (x, y, obj) {
toggleShopPanel();
};
return self;
});
var ShopPanel = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
// Make it wide enough
scaleY: 8 // Make it tall enough
});
background.tint = 0x333333;
background.alpha = 0.9;
var titleText = new Text2("Farm Shop", {
size: 70,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = -300;
self.addChild(titleText);
// Add close button
var closeButton = new Container();
var closeBg = closeButton.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.5,
scaleY: 0.5
});
closeBg.tint = 0xFF0000;
var closeText = new Text2("X", {
size: 40,
fill: 0xFFFFFF
});
closeText.anchor.set(0.5, 0.5);
closeButton.addChild(closeText);
closeButton.x = 350;
closeButton.y = -300;
closeButton.down = function () {
toggleShopPanel();
};
self.addChild(closeButton);
// Section titles
var seedTitle = new Text2("Seeds", {
size: 50,
fill: 0xFFFF00
});
seedTitle.anchor.set(0.5, 0);
seedTitle.y = -200;
self.addChild(seedTitle);
var upgradeTitle = new Text2("Upgrades", {
size: 50,
fill: 0xFFFF00
});
upgradeTitle.anchor.set(0.5, 0);
upgradeTitle.y = 50;
self.addChild(upgradeTitle);
// Containers for each section
self.seedContainer = new Container();
self.seedContainer.y = -150;
self.addChild(self.seedContainer);
self.upgradeContainer = new Container();
self.upgradeContainer.y = 100;
self.addChild(self.upgradeContainer);
return self;
});
var ToolButton = Container.expand(function (toolType) {
var self = Container.call(this);
self.toolType = toolType;
var assetName = 'tool-' + toolType;
var background = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
var toolGraphic = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.7,
scaleY: 0.7
});
var levelText = new Text2('Lv 1', {
size: 30,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0.5);
levelText.y = 40;
self.addChild(levelText);
// Add indicator to show which tool is active
var indicator = self.attachAsset('plot', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.3,
scaleY: 0.1,
y: -60
});
indicator.tint = 0xFFFFFF;
indicator.alpha = 0; // Initially hidden
self.setActive = function (isActive) {
indicator.alpha = isActive ? 1 : 0;
tween(self, {
scaleX: isActive ? 1.2 : 1.0,
scaleY: isActive ? 1.2 : 1.0
}, {
duration: 200,
easing: tween.easeOut
});
};
self.updateLevel = function (level) {
levelText.setText('Lv ' + level);
};
self.down = function (x, y, obj) {
activeTool = self.toolType;
// Update active tool indicator for all tools
toolButtons.forEach(function (button) {
button.setActive(button.toolType === activeTool);
});
// Show active tool name
updateToolDisplay();
};
return self;
});
var UpgradeButton = Container.expand(function (upgradeType, cost) {
var self = Container.call(this);
self.upgradeType = upgradeType;
self.cost = cost;
var background = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2
});
var title;
if (upgradeType === "hoe") {
title = "Upgrade Hoe";
} else if (upgradeType === "water") {
title = "Upgrade Watering Can";
} else if (upgradeType === "harvest") {
title = "Upgrade Harvester";
} else if (upgradeType === "plot") {
title = "Buy New Plot";
}
var titleText = new Text2(title, {
size: 36,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = -20;
self.addChild(titleText);
var costText = new Text2(cost + " coins", {
size: 28,
fill: 0xFFFFFF
});
costText.anchor.set(0.5, 0.5);
costText.y = 20;
self.addChild(costText);
self.updateCost = function (newCost) {
self.cost = newCost;
costText.setText(newCost + " coins");
};
self.down = function (x, y, obj) {
if (money >= self.cost) {
LK.getSound('upgrade').play();
updateMoney(-self.cost);
if (upgradeType === "hoe") {
storage.hoeLevel++;
self.updateCost(self.cost * 2);
toolButtons[0].updateLevel(storage.hoeLevel);
} else if (upgradeType === "water") {
storage.wateringCanLevel++;
self.updateCost(self.cost * 2);
toolButtons[1].updateLevel(storage.wateringCanLevel);
} else if (upgradeType === "harvest") {
storage.harvesterLevel++;
self.updateCost(self.cost * 2);
toolButtons[2].updateLevel(storage.harvesterLevel);
} else if (upgradeType === "plot") {
if (storage.unlockedPlots < storage.maxPlots) {
storage.unlockedPlots++;
self.updateCost(self.cost * 2);
plots[storage.unlockedPlots - 1].unlock();
// If all plots unlocked, hide this button
if (storage.unlockedPlots >= storage.maxPlots) {
self.visible = false;
}
}
}
}
};
return self;
});
var WeatherSystem = Container.expand(function () {
var self = Container.call(this);
self.weatherType = "sun"; // sun or rain
var gameTime = 0; // Game time in minutes (0-24)
var isDay = true;
// Create time display instead of sun
var timeBackground = self.attachAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.5
});
timeBackground.tint = 0x000066;
var timeText = new Text2("6:00 AM", {
size: 36,
fill: 0xFFFFFF
});
timeText.anchor.set(0.5, 0.5);
self.addChild(timeText);
var rainGraphic = self.attachAsset('weather-rain', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
// Initially hidden
y: 60 // Position below time display
});
self.changeWeather = function (type) {
self.weatherType = type;
if (type === "sun") {
tween(rainGraphic, {
alpha: 0
}, {
duration: 1000
});
} else if (type === "rain") {
tween(rainGraphic, {
alpha: 1
}, {
duration: 1000
});
}
};
// Update the time display
self.updateTime = function () {
// Format time to 12-hour format with AM/PM
var hours = Math.floor(gameTime);
var minutes = Math.floor(gameTime % 1 * 60);
var period = hours >= 12 ? "PM" : "AM";
var formattedHours = hours % 12;
if (formattedHours === 0) {
formattedHours = 12;
}
var timeString = formattedHours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + period;
timeText.setText(timeString);
// Change background color based on time of day
var isDayNow = hours >= 6 && hours < 18;
if (isDayNow !== isDay) {
isDay = isDayNow;
if (isDay) {
tween(timeBackground, {
tint: 0x000066
}, {
duration: 1000
});
} else {
tween(timeBackground, {
tint: 0x330033
}, {
duration: 1000
});
}
}
};
// Start time cycle and weather changes
self.startWeatherCycle = function () {
// Initialize game time to 6:00 AM
gameTime = 6;
// Update time every second
LK.setInterval(function () {
// Advance time by 10 minutes every second
gameTime = (gameTime + 10 / 60) % 24;
self.updateTime();
}, 1000);
// Weather changes
LK.setInterval(function () {
// 30% chance of rain, 70% sun
var newWeather = Math.random() < 0.3 ? "rain" : "sun";
self.changeWeather(newWeather);
currentWeather = newWeather;
}, 20000); // Change every 20 seconds
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4CAF50 // Grassy green background
});
/****
* Game Code
****/
// Global variables
var plots = [];
var toolButtons = [];
var seedButtons = [];
var upgradeButtons = [];
var activeTool = "hoe"; // Default tool
var activeSeed = "carrot"; // Default seed
var seedCosts = {
"carrot": 5,
"tomato": 10,
"wheat": 3
};
var shopButton;
var shopPanel;
var shopVisible = false;
var money = storage.money;
var moneyText;
var toolDisplayText;
var currentWeather = "sun";
var weatherSystem;
var coinEffectsPool = [];
// Function to update tool display text
function updateToolDisplay() {
var toolName = "";
switch (activeTool) {
case "hoe":
toolName = "Hoe (Plant Seeds)";
break;
case "water":
toolName = "Watering Can";
break;
case "harvest":
toolName = "Harvester";
break;
}
toolDisplayText.setText("Active Tool: " + toolName);
}
// Create plot grid
function createPlots() {
var plotSize = 200; // Reduce size to fit more plots
var gridSize = 4; // 4x4 grid instead of 3x3
var startX = 2048 / 2 - plotSize * gridSize / 2 + plotSize / 2;
var startY = 2732 / 2 - plotSize * gridSize / 2 + plotSize / 2; // Center vertically on screen
for (var row = 0; row < gridSize; row++) {
for (var col = 0; col < gridSize; col++) {
var plot = new Plot();
var index = row * gridSize + col;
plot.x = startX + col * plotSize;
plot.y = startY + row * plotSize;
// First plot starts unlocked
if (index < storage.unlockedPlots) {
plot.unlock();
}
game.addChild(plot);
plots.push(plot);
}
}
}
// Create toolbar with farming tools
function createToolbar() {
var toolTypes = ["hoe", "water", "harvest"];
var startX = 2048 / 2 - 220;
var toolbarY = 2600; // Move to bottom of screen
toolTypes.forEach(function (toolType, index) {
var button = new ToolButton(toolType);
button.x = startX + index * 220;
button.y = toolbarY;
// Set initial level
if (toolType === "hoe") {
button.updateLevel(storage.hoeLevel);
} else if (toolType === "water") {
button.updateLevel(storage.wateringCanLevel);
} else if (toolType === "harvest") {
button.updateLevel(storage.harvesterLevel);
}
// First button (hoe) is selected by default
if (index === 0) {
button.scaleX = 1.2;
button.scaleY = 1.2;
}
game.addChild(button);
toolButtons.push(button);
});
// Create shortcut buttons at the corners of the screen
// These are small, easily accessible buttons for quick tool switching
var shortcutSize = 80;
var shortcuts = [{
tool: "hoe",
x: 160,
y: 160,
key: "1"
}, {
tool: "water",
x: 260,
y: 160,
key: "2"
}, {
tool: "harvest",
x: 360,
y: 160,
key: "3"
}];
shortcuts.forEach(function (shortcut) {
var shortcutButton = new Container();
// Create background circle
var bg = shortcutButton.attachAsset('tool-' + shortcut.tool, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.6,
scaleY: 0.6
});
// Create key label
var keyLabel = new Text2(shortcut.key, {
size: 24,
fill: 0xFFFFFF
});
keyLabel.anchor.set(0.5, 0.5);
keyLabel.y = 30;
shortcutButton.addChild(keyLabel);
// Position the button
shortcutButton.x = shortcut.x;
shortcutButton.y = shortcut.y;
// Add interaction
shortcutButton.interactive = true;
shortcutButton.down = function () {
activeTool = shortcut.tool;
toolButtons.forEach(function (button) {
button.setActive(button.toolType === activeTool);
});
updateToolDisplay();
};
game.addChild(shortcutButton);
});
// Create seed buttons for shop panel
var seedTypes = [{
type: "carrot",
cost: seedCosts.carrot
}, {
type: "tomato",
cost: seedCosts.tomato
}, {
type: "wheat",
cost: seedCosts.wheat
}];
// We'll add these to the shop panel later in initGame
seedTypes.forEach(function (seed, index) {
var button = new SeedButton(seed.type, seed.cost);
// First button (carrot) is selected by default
if (index === 0) {
button.scaleX = 1.1;
button.scaleY = 1.1;
}
seedButtons.push(button);
});
}
// Create upgrade shop
function createUpgradeShop() {
var upgrades = [{
type: "hoe",
cost: 100
}, {
type: "water",
cost: 150
}, {
type: "harvest",
cost: 200
}, {
type: "plot",
cost: 300
}];
upgrades.forEach(function (upgrade, index) {
var button = new UpgradeButton(upgrade.type, upgrade.cost);
// Update costs based on current levels
if (upgrade.type === "hoe") {
button.updateCost(upgrade.cost * Math.pow(2, storage.hoeLevel - 1));
} else if (upgrade.type === "water") {
button.updateCost(upgrade.cost * Math.pow(2, storage.wateringCanLevel - 1));
} else if (upgrade.type === "harvest") {
button.updateCost(upgrade.cost * Math.pow(2, storage.harvesterLevel - 1));
} else if (upgrade.type === "plot") {
button.updateCost(upgrade.cost * Math.pow(2, storage.unlockedPlots - 1));
// Hide plot upgrade if all are unlocked
if (storage.unlockedPlots >= storage.maxPlots) {
button.visible = false;
}
}
upgradeButtons.push(button);
});
}
// Create UI elements
function createUI() {
// Create money counter
moneyText = new Text2(money.toString() + " coins", {
size: 70,
fill: 0xFFFF00
});
moneyText.anchor.set(0.5, 0);
LK.gui.top.addChild(moneyText);
// Create active tool display
toolDisplayText = new Text2("Active Tool: Hoe", {
size: 50,
fill: 0xFFFFFF
});
toolDisplayText.anchor.set(0.5, 0);
toolDisplayText.y = 80;
LK.gui.top.addChild(toolDisplayText);
// Create weather system with in-game time
weatherSystem = new WeatherSystem();
weatherSystem.x = 1800;
weatherSystem.y = 150;
game.addChild(weatherSystem);
weatherSystem.startWeatherCycle();
// Create title
var titleText = new Text2("Harvest Heroes", {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.y = 150;
LK.gui.top.addChild(titleText);
// Create shop button
shopButton = new ShopButton();
shopButton.x = 1900;
shopButton.y = 2400; // Move up to avoid overlapping with tool selector
game.addChild(shopButton);
// Create shop panel (initially hidden)
shopPanel = new ShopPanel();
shopPanel.x = 2048 / 2;
shopPanel.y = 2732 / 2;
shopPanel.visible = false;
game.addChild(shopPanel);
// Pre-create some coin effects for the pool
for (var i = 0; i < 10; i++) {
coinEffectsPool.push(new CoinEffect());
}
}
function updateMoney(amount) {
money += amount;
storage.money = money;
moneyText.setText(money.toString() + " coins");
}
function spawnCoinEffect(x, y) {
var coinEffect;
if (coinEffectsPool.length > 0) {
coinEffect = coinEffectsPool.pop();
} else {
coinEffect = new CoinEffect();
}
coinEffect.animate(x, y);
}
function toggleShopPanel() {
shopVisible = !shopVisible;
if (shopVisible) {
// Show shop panel with animation
shopPanel.visible = true;
shopPanel.alpha = 0;
tween(shopPanel, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeOut
});
} else {
// Hide shop panel with animation
tween(shopPanel, {
alpha: 0,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
shopPanel.visible = false;
}
});
}
}
// Initialize the game
function initGame() {
createPlots();
createToolbar();
createUpgradeShop();
createUI();
// Initialize active tool display
updateToolDisplay();
// Make the first tool button active (hoe is default)
toolButtons[0].setActive(true);
// Arrange seed buttons in shop panel
var seedStartX = -200;
seedButtons.forEach(function (button, index) {
button.x = seedStartX + index * 200;
button.y = 0;
shopPanel.seedContainer.addChild(button);
});
// Arrange upgrade buttons in shop panel
var upgradeStartX = -300;
var upgradeStartY = 0;
upgradeButtons.forEach(function (button, index) {
// 2 rows of 2 buttons
if (index < 2) {
button.x = upgradeStartX + index * 600;
button.y = upgradeStartY;
} else {
button.x = upgradeStartX + (index - 2) * 600;
button.y = upgradeStartY + 120;
}
shopPanel.upgradeContainer.addChild(button);
});
// Start background music
LK.playMusic('bgmusic');
}
initGame();
// Game update loop
game.update = function () {
// Update all plots
for (var i = 0; i < plots.length; i++) {
plots[i].update();
}
// Update score to track maximum money earned
if (money > LK.getScore()) {
LK.setScore(money);
}
};
// Game-level event handlers
game.down = function (x, y, obj) {
// This is handled by individual objects
};
game.up = function (x, y, obj) {
// Nothing needed here
};
game.move = function (x, y, obj) {
// Nothing needed here
}; ===================================================================
--- original.js
+++ change.js
@@ -506,46 +506,90 @@
});
var WeatherSystem = Container.expand(function () {
var self = Container.call(this);
self.weatherType = "sun"; // sun or rain
- var sunGraphic = self.attachAsset('weather-sun', {
+ var gameTime = 0; // Game time in minutes (0-24)
+ var isDay = true;
+ // Create time display instead of sun
+ var timeBackground = self.attachAsset('button', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0.5,
+ scaleX: 0.8,
+ scaleY: 0.5
});
+ timeBackground.tint = 0x000066;
+ var timeText = new Text2("6:00 AM", {
+ size: 36,
+ fill: 0xFFFFFF
+ });
+ timeText.anchor.set(0.5, 0.5);
+ self.addChild(timeText);
var rainGraphic = self.attachAsset('weather-rain', {
anchorX: 0.5,
anchorY: 0.5,
- alpha: 0 // Initially hidden
+ alpha: 0,
+ // Initially hidden
+ y: 60 // Position below time display
});
self.changeWeather = function (type) {
self.weatherType = type;
if (type === "sun") {
- tween(sunGraphic, {
- alpha: 1
- }, {
- duration: 1000
- });
tween(rainGraphic, {
alpha: 0
}, {
duration: 1000
});
} else if (type === "rain") {
- tween(sunGraphic, {
- alpha: 0
- }, {
- duration: 1000
- });
tween(rainGraphic, {
alpha: 1
}, {
duration: 1000
});
}
};
- // Start random weather changes
+ // Update the time display
+ self.updateTime = function () {
+ // Format time to 12-hour format with AM/PM
+ var hours = Math.floor(gameTime);
+ var minutes = Math.floor(gameTime % 1 * 60);
+ var period = hours >= 12 ? "PM" : "AM";
+ var formattedHours = hours % 12;
+ if (formattedHours === 0) {
+ formattedHours = 12;
+ }
+ var timeString = formattedHours + ":" + (minutes < 10 ? "0" : "") + minutes + " " + period;
+ timeText.setText(timeString);
+ // Change background color based on time of day
+ var isDayNow = hours >= 6 && hours < 18;
+ if (isDayNow !== isDay) {
+ isDay = isDayNow;
+ if (isDay) {
+ tween(timeBackground, {
+ tint: 0x000066
+ }, {
+ duration: 1000
+ });
+ } else {
+ tween(timeBackground, {
+ tint: 0x330033
+ }, {
+ duration: 1000
+ });
+ }
+ }
+ };
+ // Start time cycle and weather changes
self.startWeatherCycle = function () {
+ // Initialize game time to 6:00 AM
+ gameTime = 6;
+ // Update time every second
LK.setInterval(function () {
+ // Advance time by 10 minutes every second
+ gameTime = (gameTime + 10 / 60) % 24;
+ self.updateTime();
+ }, 1000);
+ // Weather changes
+ LK.setInterval(function () {
// 30% chance of rain, 70% sun
var newWeather = Math.random() < 0.3 ? "rain" : "sun";
self.changeWeather(newWeather);
currentWeather = newWeather;
@@ -769,11 +813,11 @@
});
toolDisplayText.anchor.set(0.5, 0);
toolDisplayText.y = 80;
LK.gui.top.addChild(toolDisplayText);
- // Create weather system
+ // Create weather system with in-game time
weatherSystem = new WeatherSystem();
- weatherSystem.x = 1900;
+ weatherSystem.x = 1800;
weatherSystem.y = 150;
game.addChild(weatherSystem);
weatherSystem.startWeatherCycle();
// Create title
Let's make a Farming Hoe so that we can till soil with it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Watering can. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Harvesting tool. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Create a tilled soil square. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Rain. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Sun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Gold coin with design in the center. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Plant seeds. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Wheat plant. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
overview of a grass field. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Farmer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Rectangle button for farming UI. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Barn. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
farmers Market stand. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
3 bar graphs and different heights. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Pile of seeds. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows