User prompt
LET ANIMALS COME OUT ON THE GRASS
User prompt
LET'S TAKE THE EGGS AND PUT THEM SOMEWHERE, AND THE EGGS AND THE ANIMALS ARE COMING TOGETHER. FIX THAT TOO.
Code edit (1 edits merged)
Please save this source code
User prompt
Egg Farm Tycoon
Initial prompt
ADD A TUS, LET'S BUY AN ANIMAL FROM THERE, LET THERE BE 5 EGGS AND LET 1 ANIMAL COME FROM EACH EGG FROM 4 RANDOM ANIMALS AND LET EACH ANIMAL GIVE 1 MONEY EVERY 4 SECONDS, BUT NOT EVERY ANIMAL GIVE 1 MONEY EVERY 4 SECONDS. SOME ARE 2, SOME ARE 3,4,5,6,9,15 RANDOMLY.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Animal = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.lastEarningTime = LK.ticks; // Animal types: 0=chicken, 1=cow, 2=pig, 3=sheep var assetNames = ['chicken', 'cow', 'pig', 'sheep']; var earningRates = [1, 3, 6, 15]; // coins per cycle var animalGraphics = self.attachAsset(assetNames[type], { anchorX: 0.5, anchorY: 0.5 }); self.earningRate = earningRates[type]; self.update = function () { // Generate coins every 4 seconds (240 ticks at 60fps) if (LK.ticks - self.lastEarningTime >= 240) { self.generateCoins(); self.lastEarningTime = LK.ticks; } }; self.generateCoins = function () { coins += self.earningRate; updateCoinDisplay(); // Visual feedback - coin animation var coinEffect = new CoinEffect(); coinEffect.x = self.x; coinEffect.y = self.y - 50; game.addChild(coinEffect); LK.getSound('coinCollect').play(); }; return self; }); var CoinEffect = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); // Animate coin floating up and fading out tween(self, { y: self.y - 100, alpha: 0 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); return self; }); var Egg = Container.expand(function () { var self = Container.call(this); var eggGraphics = self.attachAsset('egg', { anchorX: 0.5, anchorY: 0.5 }); self.isHatched = false; self.down = function (x, y, obj) { if (!self.isHatched) { self.hatch(); } }; self.hatch = function () { if (self.isHatched) return; self.isHatched = true; LK.getSound('hatch').play(); // Random animal type (0-3) var animalType = Math.floor(Math.random() * 4); var animal = new Animal(animalType); // Position animal randomly on grass animal.x = 200 + Math.random() * 1600; // Random X position across grass width animal.y = 1250 + Math.random() * 700; // Random Y position on grass area // Add animal to game and animals array game.addChild(animal); animals.push(animal); // Remove egg from game and eggs array var eggIndex = eggs.indexOf(self); if (eggIndex !== -1) { eggs.splice(eggIndex, 1); } self.destroy(); }; return self; }); var ShopButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('shopButton', { anchorX: 0.5, anchorY: 0.5 }); var buttonText = new Text2('Buy Egg (10 coins)', { size: 24, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); self.addChild(buttonText); self.down = function (x, y, obj) { if (coins >= 10) { self.purchaseEgg(); } }; self.purchaseEgg = function () { coins -= 10; updateCoinDisplay(); LK.getSound('purchase').play(); // Create new egg and add to game var newEgg = new Egg(); // Position egg in egg area grid layout var gridX = eggs.length % 5; var gridY = Math.floor(eggs.length / 5); newEgg.x = 200 + gridX * 120; newEgg.y = 600 + gridY * 180; game.addChild(newEgg); eggs.push(newEgg); // Flash button green LK.effects.flashObject(self, 0x00FF00, 500); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game variables var coins = storage.coins || 0; var eggs = []; var animals = []; // UI elements var coinDisplay = new Text2('Coins: 0', { size: 60, fill: 0xFFD700 }); coinDisplay.anchor.set(0.5, 0); LK.gui.top.addChild(coinDisplay); var titleText = new Text2('Egg Farm Tycoon', { size: 80, fill: 0x228B22 }); titleText.anchor.set(0.5, 0); titleText.x = 1024; titleText.y = 100; game.addChild(titleText); // Shop button var shopButton = new ShopButton(); shopButton.x = 1024; shopButton.y = 2500; game.addChild(shopButton); // Instructions var instructText = new Text2('Tap eggs to hatch them!', { size: 40, fill: 0x333333 }); instructText.anchor.set(0.5, 0); instructText.x = 1024; instructText.y = 200; game.addChild(instructText); // Egg area label var eggAreaLabel = new Text2('EGGS', { size: 50, fill: 0x8B4513 }); eggAreaLabel.anchor.set(0.5, 0); eggAreaLabel.x = 500; eggAreaLabel.y = 500; game.addChild(eggAreaLabel); // Add grass background for animals var grassBackground = LK.getAsset('grass', { anchorX: 0.5, anchorY: 0 }); grassBackground.x = 1024; grassBackground.y = 1200; game.addChild(grassBackground); // Animal area label var animalAreaLabel = new Text2('ANIMALS ON GRASS', { size: 50, fill: 0xFFFFFF }); animalAreaLabel.anchor.set(0.5, 0); animalAreaLabel.x = 1024; animalAreaLabel.y = 1100; game.addChild(animalAreaLabel); // Create initial 5 eggs in egg area for (var i = 0; i < 5; i++) { var egg = new Egg(); egg.x = 200 + i % 5 * 120; egg.y = 600 + Math.floor(i / 5) * 180; game.addChild(egg); eggs.push(egg); } function updateCoinDisplay() { coinDisplay.setText('Coins: ' + coins); storage.coins = coins; } // Initialize coin display updateCoinDisplay(); game.update = function () { // Update shop button affordability if (coins >= 10) { shopButton.alpha = 1.0; } else { shopButton.alpha = 0.6; } };
===================================================================
--- original.js
+++ change.js
@@ -75,13 +75,11 @@
LK.getSound('hatch').play();
// Random animal type (0-3)
var animalType = Math.floor(Math.random() * 4);
var animal = new Animal(animalType);
- // Position animal in animal area
- var animalGridX = animals.length % 6;
- var animalGridY = Math.floor(animals.length / 6);
- animal.x = 200 + animalGridX * 130;
- animal.y = 1200 + animalGridY * 150;
+ // Position animal randomly on grass
+ animal.x = 200 + Math.random() * 1600; // Random X position across grass width
+ animal.y = 1250 + Math.random() * 700; // Random Y position on grass area
// Add animal to game and animals array
game.addChild(animal);
animals.push(animal);
// Remove egg from game and eggs array
@@ -180,15 +178,23 @@
eggAreaLabel.anchor.set(0.5, 0);
eggAreaLabel.x = 500;
eggAreaLabel.y = 500;
game.addChild(eggAreaLabel);
+// Add grass background for animals
+var grassBackground = LK.getAsset('grass', {
+ anchorX: 0.5,
+ anchorY: 0
+});
+grassBackground.x = 1024;
+grassBackground.y = 1200;
+game.addChild(grassBackground);
// Animal area label
-var animalAreaLabel = new Text2('ANIMALS', {
+var animalAreaLabel = new Text2('ANIMALS ON GRASS', {
size: 50,
- fill: 0x228B22
+ fill: 0xFFFFFF
});
animalAreaLabel.anchor.set(0.5, 0);
-animalAreaLabel.x = 500;
+animalAreaLabel.x = 1024;
animalAreaLabel.y = 1100;
game.addChild(animalAreaLabel);
// Create initial 5 eggs in egg area
for (var i = 0; i < 5; i++) {
Tavuk pixel. In-Game asset. 2d. High contrast. No shadows
Inek pixel. In-Game asset. 2d. High contrast. No shadows
Domuz pixel. In-Game asset. 2d. High contrast. No shadows
Koyun pixel. In-Game asset. 2d. High contrast. No shadows
Egg pixel. In-Game asset. 2d. High contrast. No shadows
rabbit pixel. In-Game asset. 2d. High contrast. No shadows
Ordek pixel. In-Game asset. 2d. High contrast. No shadows
Dragon egg pixel. In-Game asset. 2d. High contrast. No shadows
Goat pixel. In-Game asset. 2d. High contrast. No shadows
Horse pixel. In-Game asset. 2d. High contrast. No shadows
DARK DRAGON PIXEL. In-Game asset. 2d. High contrast. No shadows
Ice dragon pixel. In-Game asset. 2d. High contrast. No shadows
Pixel
Turkey Pixel. In-Game asset. 2d. High contrast. No shadows
Bear pixel. In-Game asset. 2d. High contrast. No shadows
Fox pixel. In-Game asset. 2d. High contrast. No shadows
Coin pixel. In-Game asset. 2d. High contrast. No shadows
Elephant 8 bit. In-Game asset. 2d. High contrast. No shadows
Lion 8 bit. In-Game asset. 2d. High contrast. No shadows
Giraffe 8 bit. In-Game asset. 2d. High contrast. No shadows
Tiger 8 bit. In-Game asset. 2d. High contrast. No shadows
Zebra 8bit. In-Game asset. 2d. High contrast. No shadows
Panda 8bit. In-Game asset. 2d. High contrast. No shadows
Rhino 8bit. In-Game asset. 2d. High contrast. No shadows
T rex pixel. In-Game asset. 2d. High contrast. No shadows
Triceraptos pixel. In-Game asset. 2d. High contrast. No shadows
Stegosaurus pixel. In-Game asset. 2d. High contrast. No shadows
Brontosaurus pixel. In-Game asset. 2d. High contrast. No shadows
Veliciraptor pixel. In-Game asset. 2d. High contrast. No shadows
Pteranodon pixel. In-Game asset. 2d. High contrast. No shadows
Hippo 8 bit. In-Game asset. 2d. High contrast. No shadows