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: 100,
hoeLevel: 1,
wateringCanLevel: 1,
harvesterLevel: 1,
unlockedPlots: 1
});
/****
* 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.growthProgress = 0;
if (self.cropGraphic) {
self.removeChild(self.cropGraphic);
}
self.cropGraphic = self.attachAsset('crop-seed', {
anchorX: 0.5,
anchorY: 0.5
});
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
});
}
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
});
}
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
});
}
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
});
}
}
}
};
self.down = function (x, y, obj) {
if (!self.unlocked) {
return;
}
var gamePos = game.toLocal(self.parent.toGlobal(self.position));
if (activeTool === "hoe") {
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 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);
self.updateLevel = function (level) {
levelText.setText('Lv ' + level);
};
self.down = function (x, y, obj) {
activeTool = self.toolType;
toolButtons.forEach(function (button) {
if (button.toolType === activeTool) {
tween(button, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
} else {
tween(button, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeOut
});
}
});
};
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 < 9) {
storage.unlockedPlots++;
self.updateCost(self.cost * 2);
plots[storage.unlockedPlots - 1].unlock();
// If all plots unlocked, hide this button
if (storage.unlockedPlots >= 9) {
self.visible = false;
}
}
}
}
};
return self;
});
var WeatherSystem = Container.expand(function () {
var self = Container.call(this);
self.weatherType = "sun"; // sun or rain
var sunGraphic = self.attachAsset('weather-sun', {
anchorX: 0.5,
anchorY: 0.5
});
var rainGraphic = self.attachAsset('weather-rain', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0 // Initially hidden
});
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
self.startWeatherCycle = function () {
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: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Global variables
var plots = [];
var toolButtons = [];
var upgradeButtons = [];
var activeTool = "hoe"; // Default tool
var money = storage.money;
var moneyText;
var currentWeather = "sun";
var weatherSystem;
var coinEffectsPool = [];
// Create plot grid
function createPlots() {
var plotSize = 220; // Size including margin
var startX = 2048 / 2 - plotSize;
var startY = 500;
for (var row = 0; row < 3; row++) {
for (var col = 0; col < 3; col++) {
var plot = new Plot();
var index = row * 3 + 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 = 1500;
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 upgrade shop
function createUpgradeShop() {
var upgrades = [{
type: "hoe",
cost: 100
}, {
type: "water",
cost: 150
}, {
type: "harvest",
cost: 200
}, {
type: "plot",
cost: 300
}];
var startX = 2048 / 2 - 400;
var shopY = 2000;
upgrades.forEach(function (upgrade, index) {
var button = new UpgradeButton(upgrade.type, upgrade.cost);
// For 4 buttons, let's make 2 rows of 2
if (index < 2) {
button.x = startX + index * 800;
button.y = shopY;
} else {
button.x = startX + (index - 2) * 800;
button.y = shopY + 120;
}
// 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 >= 9) {
button.visible = false;
}
}
game.addChild(button);
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 weather system
weatherSystem = new WeatherSystem();
weatherSystem.x = 1900;
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);
// 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);
}
// Initialize the game
function initGame() {
createPlots();
createToolbar();
createUpgradeShop();
createUI();
// 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
@@ -1,6 +1,534 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1", {
+ money: 100,
+ hoeLevel: 1,
+ wateringCanLevel: 1,
+ harvesterLevel: 1,
+ unlockedPlots: 1
+});
+
+/****
+* 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.growthProgress = 0;
+ if (self.cropGraphic) {
+ self.removeChild(self.cropGraphic);
+ }
+ self.cropGraphic = self.attachAsset('crop-seed', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ 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
+ });
+ }
+ 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
+ });
+ }
+ 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
+ });
+ }
+ 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
+ });
+ }
+ }
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (!self.unlocked) {
+ return;
+ }
+ var gamePos = game.toLocal(self.parent.toGlobal(self.position));
+ if (activeTool === "hoe") {
+ 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 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);
+ self.updateLevel = function (level) {
+ levelText.setText('Lv ' + level);
+ };
+ self.down = function (x, y, obj) {
+ activeTool = self.toolType;
+ toolButtons.forEach(function (button) {
+ if (button.toolType === activeTool) {
+ tween(button, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ } else {
+ tween(button, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ }
+ });
+ };
+ 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 < 9) {
+ storage.unlockedPlots++;
+ self.updateCost(self.cost * 2);
+ plots[storage.unlockedPlots - 1].unlock();
+ // If all plots unlocked, hide this button
+ if (storage.unlockedPlots >= 9) {
+ self.visible = false;
+ }
+ }
+ }
+ }
+ };
+ return self;
+});
+var WeatherSystem = Container.expand(function () {
+ var self = Container.call(this);
+ self.weatherType = "sun"; // sun or rain
+ var sunGraphic = self.attachAsset('weather-sun', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var rainGraphic = self.attachAsset('weather-rain', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0 // Initially hidden
+ });
+ 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
+ self.startWeatherCycle = function () {
+ 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB // Sky blue background
+});
+
+/****
+* Game Code
+****/
+// Global variables
+var plots = [];
+var toolButtons = [];
+var upgradeButtons = [];
+var activeTool = "hoe"; // Default tool
+var money = storage.money;
+var moneyText;
+var currentWeather = "sun";
+var weatherSystem;
+var coinEffectsPool = [];
+// Create plot grid
+function createPlots() {
+ var plotSize = 220; // Size including margin
+ var startX = 2048 / 2 - plotSize;
+ var startY = 500;
+ for (var row = 0; row < 3; row++) {
+ for (var col = 0; col < 3; col++) {
+ var plot = new Plot();
+ var index = row * 3 + 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 = 1500;
+ 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 upgrade shop
+function createUpgradeShop() {
+ var upgrades = [{
+ type: "hoe",
+ cost: 100
+ }, {
+ type: "water",
+ cost: 150
+ }, {
+ type: "harvest",
+ cost: 200
+ }, {
+ type: "plot",
+ cost: 300
+ }];
+ var startX = 2048 / 2 - 400;
+ var shopY = 2000;
+ upgrades.forEach(function (upgrade, index) {
+ var button = new UpgradeButton(upgrade.type, upgrade.cost);
+ // For 4 buttons, let's make 2 rows of 2
+ if (index < 2) {
+ button.x = startX + index * 800;
+ button.y = shopY;
+ } else {
+ button.x = startX + (index - 2) * 800;
+ button.y = shopY + 120;
+ }
+ // 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 >= 9) {
+ button.visible = false;
+ }
+ }
+ game.addChild(button);
+ 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 weather system
+ weatherSystem = new WeatherSystem();
+ weatherSystem.x = 1900;
+ 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);
+ // 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);
+}
+// Initialize the game
+function initGame() {
+ createPlots();
+ createToolbar();
+ createUpgradeShop();
+ createUI();
+ // 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
+};
\ No newline at end of file
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