User prompt
Simple Farming System (Upit): There are 4 farm areas. Area 1 is open. Others are locked. Unlock prices: Area 2 = 20,000 Area 3 = 40,000 Area 4 = 60,000 Each area has different vegetables. Rewards: Area 1 = normal money Area 2 = 2x money Area 3 = 3x money Area 4 = 4x money
User prompt
Change the growth animation wait time from 5 seconds to 30 seconds.
User prompt
Place wheat plants in rows and columns to form a neat grid inside the fences. For example, make 5 rows and 10 columns of wheat plants. Space each wheat plant evenly so they look organized. Make sure the wheat fills most of the space inside the fenced area to look plentiful. Adjust spacing so wheat doesn’t overlap with fences.
User prompt
Wheat hit and growth cycle in Upit: When player hits the wheat, give money. Change wheat image to small sprout after hit. During 5 seconds, animate wheat growing back to full size. When fully grown, wheat waits to be hit again. This cycle repeats every time player hits the wheat.
User prompt
How to add hit animation for wheat in Upit: When player hits the wheat, give money immediately. Instead of disappearing right away, change wheat image to a small sprout. For 5 seconds, animate the wheat growing back from sprout to full size. After 5 seconds, remove the wheat completely. How to add hit animation for wheat in Upit: When player hits the wheat, give money immediately. Instead of disappearing right away, change wheat image to a small sprout. For 5 seconds, animate the wheat growing back from sprout to full size. After 5 seconds, remove the wheat completely.
User prompt
“There will be 4 fences shaped like the letter L. Place one L-shaped fence at each corner of the collected area. Each L-shaped fence can use a different image. In short, the corners of the collected area will each have an L-shaped fence.”
User prompt
All fence pieces must be perfect squares and the same size. Ensure the images keep their correct proportions (no distortion when resizing). When placing PNG images, maintain their transparency and quality so they look clean and sharp. Avoid any blurring or pixelation by using high-resolution PNGs.All fence pieces must be perfect squares and the same size. Ensure the images keep their correct proportions (no distortion when resizing). When placing PNG images, maintain their transparency and quality so they look clean and sharp. Avoid any blurring or pixelation by using high-resolution PNGs.
User prompt
Use one image for all fence pieces. This single image will represent each fence section at every corner. The fences can be a bit bigger than the image size if needed. The fences should have a side (side-on) view perspective.
User prompt
“Do not place fences exactly at the edges of the center area. Move them a little farther away from the center, so they are near but not touching the center borders.”
User prompt
“The fences will align exactly with the left and right edges of the center area, not with the screen edges.”
User prompt
Move all 4 fenced areas farther away from the center. The 2 fences on the left side should line up with the left edge of the center area. The 2 fences on the right side should line up with the right edge of the center area. Keep all fences at equal distance from the center. Make sure the layout is symmetrical.
User prompt
Remove the house completely. It should not be in the game.
User prompt
Place the house at the highest point of the center area. The house should be clearly visible and stand out. It should be positioned above everything else in the center. The house will be a separate image.
User prompt
The player should not spawn at the exact center of the map. Instead, the player should spawn just above the center area. There are 4 fenced areas around the center. Each fenced area should have one gate, facing the center. All fence pieces and gates should be separate images.
User prompt
Place one tree at the top right corner. Place one tree at the top left corner. Place one tree at the bottom left corner. Place one tree at the bottom right corner. All trees should be the same size. Place one tree to the left of the center. Place one tree to the right of the center. The two center trees should be aligned with the corner trees on the right side (same Y position). Each tree will be added as a separate image.
User prompt
Place one tree at the top right corner. Place one tree at the top left corner. Place one tree at the bottom left corner. Place one tree at the bottom right corner. All trees should be the same size. Place one tree to the left of the center. Place one tree to the right of the center. Each tree will be added as a separate image
User prompt
One tree at the top right corner, One tree at the top left corner, One tree at the bottom left corner, One tree at the bottom right corner. All trees should be the same size. Each tree will be added as a separate image.”
User prompt
"Place one tree in each corner of the game: One tree at the top right corner, One tree at the top left corner, One tree at the bottom left corner, One tree at the bottom right corner. Each tree will be added as a separate image."
User prompt
Fence and Gate Description: The fences around each wheat field should be larger to better enclose the area. There should be a gate (an opening) in the fence to allow players to enter and exit the wheat fields. Players must enter the fields only through the gate (not by crossing the fences). The gate should be clearly visible and positioned logically on the fence, providing access to the enclosed area.
User prompt
Walking Animation Description: The PNG sprite sheet contains 3 frames for the walking animation. Each frame represents a different movement state: Frame 1: Idle / Standing still (the character is not moving) Frame 2: Running (the character is moving fast) Frame 3: Right step (the character’s right foot stepping forward) Animation timing: Each frame should be displayed for about 0.3 seconds to create smooth motion. When the player is idle, always show Frame 1. When the player is running, cycle through Frame 2 and Frame 3 repeatedly to simulate walking. Logic summary: If playerSpeed == 0 → display Frame 1 (idle) If playerSpeed > 0 → animate by alternating Frame 2 and Frame 3 every 0.3 seconds ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
I want to add a walking animation for the player character when they move.
User prompt
I want the player character to have animations, such as walking, idle, and harvesting. The animations should change based on the player's actions — for example, when the player moves, the walking animation plays; when the player stops, the idle animation plays; and when the player harvests wheat, a harvesting animation plays. This makes the game feel more lively and interactive.
User prompt
I want to add animated GIFs for the wheat and the house, so they have simple movements or animations.
User prompt
The farmer holds a sickle in their hand.
Code edit (1 edits merged)
Please save this source code
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Farmer class var Farmer = Container.expand(function () { var self = Container.call(this); // Create animation frames var idleFrame = self.attachAsset('farmer', { anchorX: 0.5, anchorY: 0.5, alpha: 1 }); // Frame 2 (running) var runningFrame = self.attachAsset('farmer_walk', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); // Frame 3 (right step) var rightStepFrame = self.attachAsset('farmer_walk', { anchorX: 0.5, anchorY: 0.5, alpha: 0, rotation: 0.1 }); self.speed = 18; // px per move self.targetX = self.x; self.targetY = self.y; self.moving = false; self.lastMoving = false; self.animationTimer = 0; self.animationFrame = 0; self.frameTime = 18; // 0.3 seconds at 60fps // Animation frame switching self.switchToFrame = function (frameNum) { idleFrame.alpha = 0; runningFrame.alpha = 0; rightStepFrame.alpha = 0; if (frameNum === 0) { // Idle idleFrame.alpha = 1; } else if (frameNum === 1) { // Running runningFrame.alpha = 1; } else if (frameNum === 2) { // Right step rightStepFrame.alpha = 1; } }; // Move farmer towards target self.update = function () { // Animation handling if (self.moving) { self.animationTimer++; if (self.animationTimer >= self.frameTime) { self.animationTimer = 0; self.animationFrame = self.animationFrame === 1 ? 2 : 1; // Toggle between frames 1 and 2 self.switchToFrame(self.animationFrame); } } else if (!self.moving && self.lastMoving) { // Just stopped moving - switch to idle self.switchToFrame(0); } self.lastMoving = self.moving; if (!self.moving) return; var dx = self.targetX - self.x; var dy = self.targetY - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < self.speed) { self.x = self.targetX; self.y = self.targetY; self.moving = false; // Switch to idle frame when stopping self.switchToFrame(0); } else { self.x += self.speed * dx / dist; self.y += self.speed * dy / dist; } }; // Set movement target self.moveTo = function (x, y) { self.targetX = x; self.targetY = y; // Start movement if (!self.moving) { self.moving = true; self.animationFrame = 1; self.animationTimer = 0; self.switchToFrame(self.animationFrame); } }; return self; }); // Field class var Field = Container.expand(function () { var self = Container.call(this); self.index = 0; // 0-3 self.locked = false; self.lockCost = 0; self.lockNode = null; self.fenceNodes = []; self.wheats = []; self.unlockBtn = null; // Draw fences self.drawFences = function (x, y, w, h) { self.fenceNodes = []; // Determine which side the gate should be based on field index // Gates always face the center var gateSide = -1; // 0=top, 1=right, 2=bottom, 3=left if (self.index === 0) gateSide = 1; // Top-left field: gate on right else if (self.index === 1) gateSide = 3; // Top-right field: gate on left else if (self.index === 2) gateSide = 0; // Bottom-left field: gate on top else if (self.index === 3) gateSide = 2; // Bottom-right field: gate on bottom // Gate size and position var gateWidth = 120; var gateHeight = 30; var gatePos = 0; // Calculate gate position (centered on each side) if (gateSide === 0 || gateSide === 2) { gatePos = x + (w - gateWidth) / 2; } else { gatePos = y + (h - gateWidth) / 2; } // Top fence if (gateSide === 0) { // Left section var topLeft = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: (w - gateWidth) / 2, height: 30, x: x, y: y }); self.fenceNodes.push(topLeft); self.addChild(topLeft); // Right section var topRight = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: (w - gateWidth) / 2, height: 30, x: x + (w + gateWidth) / 2, y: y }); self.fenceNodes.push(topRight); self.addChild(topRight); // Gate var topGate = LK.getAsset('gate', { anchorX: 0, anchorY: 0, width: gateWidth, height: gateHeight, x: gatePos, y: y }); self.fenceNodes.push(topGate); self.addChild(topGate); } else { // Full top fence var top = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: w, height: 30, x: x, y: y }); self.fenceNodes.push(top); self.addChild(top); } // Bottom fence if (gateSide === 2) { // Left section var bottomLeft = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: (w - gateWidth) / 2, height: 30, x: x, y: y + h - 30 }); self.fenceNodes.push(bottomLeft); self.addChild(bottomLeft); // Right section var bottomRight = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: (w - gateWidth) / 2, height: 30, x: x + (w + gateWidth) / 2, y: y + h - 30 }); self.fenceNodes.push(bottomRight); self.addChild(bottomRight); // Gate var bottomGate = LK.getAsset('gate', { anchorX: 0, anchorY: 0, width: gateWidth, height: gateHeight, x: gatePos, y: y + h - 30 }); self.fenceNodes.push(bottomGate); self.addChild(bottomGate); } else { // Full bottom fence var bottom = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: w, height: 30, x: x, y: y + h - 30 }); self.fenceNodes.push(bottom); self.addChild(bottom); } // Left fence if (gateSide === 3) { // Top section var leftTop = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: (h - gateWidth) / 2, x: x, y: y }); self.fenceNodes.push(leftTop); self.addChild(leftTop); // Bottom section var leftBottom = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: (h - gateWidth) / 2, x: x, y: y + (h + gateWidth) / 2 }); self.fenceNodes.push(leftBottom); self.addChild(leftBottom); // Gate var leftGate = LK.getAsset('gate', { anchorX: 0, anchorY: 0, width: 30, height: gateWidth, x: x, y: gatePos }); self.fenceNodes.push(leftGate); self.addChild(leftGate); } else { // Full left fence var left = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: h, x: x, y: y }); self.fenceNodes.push(left); self.addChild(left); } // Right fence if (gateSide === 1) { // Top section var rightTop = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: (h - gateWidth) / 2, x: x + w - 30, y: y }); self.fenceNodes.push(rightTop); self.addChild(rightTop); // Bottom section var rightBottom = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: (h - gateWidth) / 2, x: x + w - 30, y: y + (h + gateWidth) / 2 }); self.fenceNodes.push(rightBottom); self.addChild(rightBottom); // Gate var rightGate = LK.getAsset('gate', { anchorX: 0, anchorY: 0, width: 30, height: gateWidth, x: x + w - 30, y: gatePos }); self.fenceNodes.push(rightGate); self.addChild(rightGate); } else { // Full right fence var right = LK.getAsset('fence', { anchorX: 0, anchorY: 0, width: 30, height: h, x: x + w - 30, y: y }); self.fenceNodes.push(right); self.addChild(right); } }; // Place wheat self.placeWheats = function (x, y, w, h, count) { self.wheats = []; // Define grid size var rows = 5; var cols = 10; // Choose vegetable asset per area var vegAssetId = 'wheat'; if (self.index === 1) vegAssetId = 'carrot'; if (self.index === 2) vegAssetId = 'tomato'; if (self.index === 3) vegAssetId = 'eggplant'; // Fallback if asset not found, use wheat if (!LK.assets[vegAssetId]) vegAssetId = 'wheat'; // Calculate asset size for spacing var vegAsset = LK.getAsset(vegAssetId, { anchorX: 0.5, anchorY: 1 }); var wheatW = vegAsset.width; var wheatH = vegAsset.height; // Padding from fences var padX = 60; var padY = 60; // Compute available area for wheat grid var gridW = w - 2 * padX; var gridH = h - 2 * padY; // Compute spacing between wheat plants var spacingX = (gridW - wheatW) / (cols - 1); var spacingY = (gridH - wheatH) / (rows - 1); // Place wheat/vegetable in grid for (var row = 0; row < rows; ++row) { for (var col = 0; col < cols; ++col) { var wx = x + padX + col * spacingX + wheatW / 2; var wy = y + padY + row * spacingY + wheatH; var wheat = new Wheat(); wheat.x = wx; wheat.y = wy; wheat.fieldIndex = self.index; wheat.vegAssetId = vegAssetId; wheat.setVegAsset && wheat.setVegAsset(vegAssetId); // If method exists self.addChild(wheat); self.wheats.push(wheat); } } }; // Lock overlay self.showLock = function (centerX, centerY) { if (self.lockNode) return; self.lockNode = LK.getAsset('lock', { anchorX: 0.5, anchorY: 0.5, x: centerX, y: centerY }); self.addChild(self.lockNode); // Unlock text var unlockTxt = new Text2('Unlock\n$' + self.lockCost, { size: 60, fill: "#fff" }); unlockTxt.anchor.set(0.5, 0.5); unlockTxt.x = centerX; unlockTxt.y = centerY + 70; self.unlockBtn = unlockTxt; self.addChild(unlockTxt); }; self.hideLock = function () { if (self.lockNode) { self.lockNode.destroy(); self.lockNode = null; } if (self.unlockBtn) { self.unlockBtn.destroy(); self.unlockBtn = null; } }; return self; }); // Wheat class var Wheat = Container.expand(function () { var self = Container.call(this); self.vegAssetId = 'wheat'; self.wheatAsset = self.attachAsset('wheat', { anchorX: 0.5, anchorY: 1 }); var sproutAsset = self.attachAsset('sprout', { anchorX: 0.5, anchorY: 1, alpha: 0, scaleX: 0.5, scaleY: 0.5 }); self.harvested = false; self.regrowTime = 1800; // 30 seconds at 60fps self.regrowCounter = 0; self.fieldIndex = 0; // which field this wheat belongs to self.regrowing = false; self.removeAfter = 0; // Change vegetable asset if needed self.setVegAsset = function (assetId) { if (self.wheatAsset) { self.wheatAsset.destroy(); } self.vegAssetId = assetId || 'wheat'; self.wheatAsset = self.attachAsset(self.vegAssetId, { anchorX: 0.5, anchorY: 1 }); // Make sure sprout is on top self.removeChild(sproutAsset); self.addChild(sproutAsset); }; // Show/hide wheat and handle regrow animation self.setHarvested = function (harvested) { self.harvested = harvested; if (harvested) { // Hide wheat, show sprout if (self.wheatAsset) self.wheatAsset.alpha = 0; sproutAsset.alpha = 1; sproutAsset.scaleX = 0.5; sproutAsset.scaleY = 0.5; self.regrowCounter = self.regrowTime; self.regrowing = true; } else { // Show wheat, hide sprout if (self.wheatAsset) self.wheatAsset.alpha = 1; sproutAsset.alpha = 0; self.regrowing = false; } }; // Regrow logic and removal after 5 seconds self.update = function () { if (self.harvested && self.regrowing) { if (self.regrowCounter > 0) { // Animate sprout growing to wheat size var t = 1 - self.regrowCounter / self.regrowTime; sproutAsset.scaleX = 0.5 + 0.5 * t; sproutAsset.scaleY = 0.5 + 0.5 * t; self.regrowCounter--; } if (self.regrowCounter <= 0) { // Sprout is now full size, switch back to wheat and allow harvest again sproutAsset.scaleX = 1; sproutAsset.scaleY = 1; self.setHarvested(false); } } }; // For hit detection self.isHarvestable = function () { return !self.harvested; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb // Sky blue }); /**** * Game Code ****/ // Lock icon (ellipse, gray) // Sickle (ellipse, yellow) // House (box) // Farmer (box) // Wheat (ellipse) // Field fence (rectangle) // --- Game constants --- var FIELD_W = 900; var FIELD_H = 900; var FIELD_GAP = 120; // Increased gap to move fences further from center var FIELD_COUNT = 4; var WHEAT_PER_FIELD = 10; // Area unlock prices and reward multipliers var FIELD_LOCK_COSTS = [0, 20000, 40000, 60000]; // Area 1 open, others locked var FIELD_REWARD_MULT = [1, 2, 3, 4]; // Area 1=1x, 2=2x, 3=3x, 4=4x // --- Game state --- var fields = []; var farmer = null; var money = 0; var moneyTxt = null; var sickle = null; var dragging = false; var dragOffsetX = 0; var dragOffsetY = 0; var unlockFieldIndex = -1; // --- Layout calculation --- // Fields: 2x2 grid, with house in center // [0][1] // [2][3] var fieldPositions = [{ x: 0, y: 0 }, // top-left { x: FIELD_W + FIELD_GAP, y: 0 }, // top-right { x: 0, y: FIELD_H + FIELD_GAP }, // bottom-left { x: FIELD_W + FIELD_GAP, y: FIELD_H + FIELD_GAP } // bottom-right ]; // Center everything in game area var totalW = FIELD_W * 2 + FIELD_GAP; var totalH = FIELD_H * 2 + FIELD_GAP; var offsetX = Math.floor((2048 - totalW) / 2); var offsetY = Math.floor((2732 - totalH) / 2); // --- Create fields --- for (var i = 0; i < FIELD_COUNT; ++i) { var f = new Field(); f.index = i; f.locked = FIELD_LOCK_COSTS[i] > 0; f.lockCost = FIELD_LOCK_COSTS[i]; var pos = fieldPositions[i]; var fx = offsetX + pos.x; var fy = offsetY + pos.y; f.drawFences(fx, fy, FIELD_W, FIELD_H); f.placeWheats(fx, fy, FIELD_W, FIELD_H, WHEAT_PER_FIELD); if (f.locked) { // Center of field f.showLock(fx + FIELD_W / 2, fy + FIELD_H / 2); } game.addChild(f); fields.push(f); } // Center reference point for positions var centerX = offsetX + FIELD_W; var centerY = offsetY + FIELD_H - 250; // --- Create farmer --- farmer = new Farmer(); farmer.x = centerX; farmer.y = centerY - 120; // Start at center area game.addChild(farmer); // --- Create sickle (attached to farmer's hand) --- sickle = LK.getAsset('sickle', { anchorX: 0.2, // hand position, left side of ellipse anchorY: 0.7, // slightly below center x: 0, y: 30 }); sickle.alpha = 1; farmer.addChild(sickle); // --- Money display --- moneyTxt = new Text2('$0', { size: 100, fill: "#fff" }); moneyTxt.anchor.set(0.5, 0); LK.gui.top.addChild(moneyTxt); // --- Helper: update money display --- function updateMoneyDisplay() { moneyTxt.setText('$' + money); } // --- Helper: unlock field if enough money --- function tryUnlockField(fieldIdx) { var f = fields[fieldIdx]; if (!f.locked) return; if (money >= f.lockCost) { money -= f.lockCost; updateMoneyDisplay(); f.locked = false; f.hideLock(); // Flash field green for (var i = 0; i < f.fenceNodes.length; ++i) { LK.effects.flashObject(f.fenceNodes[i], 0x00ff00, 600); } } else { // Not enough money, flash red LK.effects.flashScreen(0xff0000, 400); } } // --- Touch/mouse handling --- var lastDownX = 0, lastDownY = 0; var harvestMode = false; var harvestWheat = null; // Helper: find wheat under (x, y) in unlocked fields function findHarvestableWheat(x, y) { for (var i = 0; i < fields.length; ++i) { var f = fields[i]; if (f.locked) continue; for (var j = 0; j < f.wheats.length; ++j) { var w = f.wheats[j]; if (w.isHarvestable()) { // Use bounding box for hit var wx = w.x, wy = w.y; var ww = 60, wh = 80; if (x >= wx - ww / 2 && x <= wx + ww / 2 && y >= wy - wh && y <= wy) { return w; } } } } return null; } // Helper: find locked field under (x, y) function findLockedField(x, y) { for (var i = 0; i < fields.length; ++i) { var f = fields[i]; if (!f.locked) continue; // Use field area var pos = fieldPositions[i]; var fx = offsetX + pos.x; var fy = offsetY + pos.y; if (x >= fx && x <= fx + FIELD_W && y >= fy && y <= fy + FIELD_H) { return i; } } return -1; } // --- Game event handlers --- // Move farmer or harvest wheat game.down = function (x, y, obj) { lastDownX = x; lastDownY = y; // Check if tapping on locked field unlock button var lockedIdx = findLockedField(x, y); if (lockedIdx >= 0) { var f = fields[lockedIdx]; // If tap is near lock icon or unlock text var centerX = offsetX + fieldPositions[lockedIdx].x + FIELD_W / 2; var centerY = offsetY + fieldPositions[lockedIdx].y + FIELD_H / 2; var dist = Math.sqrt((x - centerX) * (x - centerX) + (y - centerY) * (y - centerY)); if (dist < 120) { tryUnlockField(lockedIdx); return; } } // Check for wheat var w = findHarvestableWheat(x, y); if (w) { harvestMode = true; harvestWheat = w; // Animate sickle (in farmer's hand) tween(sickle, { rotation: Math.PI * 2 }, { duration: 300, easing: tween.easeIn, onFinish: function onFinish() { sickle.rotation = 0; } }); // Harvest w.setHarvested(true); var reward = 100 * (FIELD_REWARD_MULT[w.fieldIndex] || 1); money += reward; updateMoneyDisplay(); // Flash wheat LK.effects.flashObject(w, 0xffff00, 300); // No setHarvested(false) here; regrow/removal handled in Wheat.update harvestMode = false; harvestWheat = null; return; } // Move farmer with animation farmer.moveTo(x, y); dragging = true; dragOffsetX = x - farmer.x; dragOffsetY = y - farmer.y; }; // Drag farmer game.move = function (x, y, obj) { if (dragging) { farmer.moveTo(x - dragOffsetX, y - dragOffsetY); } if (harvestMode && harvestWheat) { sickle.x = x; sickle.y = y; } }; // End drag/harvest game.up = function (x, y, obj) { dragging = false; harvestMode = false; harvestWheat = null; }; // --- Main update loop --- game.update = function () { // Update farmer farmer.update(); // Update wheat regrow for (var i = 0; i < fields.length; ++i) { var f = fields[i]; for (var j = 0; j < f.wheats.length; ++j) { f.wheats[j].update(); } } }; // --- Initial money display --- updateMoneyDisplay(); // --- Place trees at corners --- // Tree size var treeWidth = 400; var treeHeight = 532; // Top left corner tree var topLeftTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: offsetX / 2, y: offsetY / 2 }); game.addChild(topLeftTree); // Top right corner tree var topRightTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: 2048 - offsetX / 2, y: offsetY / 2 }); game.addChild(topRightTree); // Bottom left corner tree var bottomLeftTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: offsetX / 2, y: 2732 - offsetY / 2 }); game.addChild(bottomLeftTree); // Bottom right corner tree var bottomRightTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: 2048 - offsetX / 2, y: 2732 - offsetY / 2 }); game.addChild(bottomRightTree); // --- Place trees at middle sides aligned with corner trees --- // Tree to the left of center var leftCenterTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: offsetX / 2, y: topRightTree.y }); game.addChild(leftCenterTree); // Tree to the right of center var rightCenterTree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5, x: 2048 - offsetX / 2, y: topRightTree.y }); game.addChild(rightCenterTree);
===================================================================
--- original.js
+++ change.js
@@ -324,15 +324,22 @@
self.wheats = [];
// Define grid size
var rows = 5;
var cols = 10;
- // Calculate wheat asset size (use Wheat asset size for spacing)
- var wheatAsset = LK.getAsset('wheat', {
+ // Choose vegetable asset per area
+ var vegAssetId = 'wheat';
+ if (self.index === 1) vegAssetId = 'carrot';
+ if (self.index === 2) vegAssetId = 'tomato';
+ if (self.index === 3) vegAssetId = 'eggplant';
+ // Fallback if asset not found, use wheat
+ if (!LK.assets[vegAssetId]) vegAssetId = 'wheat';
+ // Calculate asset size for spacing
+ var vegAsset = LK.getAsset(vegAssetId, {
anchorX: 0.5,
anchorY: 1
});
- var wheatW = wheatAsset.width;
- var wheatH = wheatAsset.height;
+ var wheatW = vegAsset.width;
+ var wheatH = vegAsset.height;
// Padding from fences
var padX = 60;
var padY = 60;
// Compute available area for wheat grid
@@ -340,17 +347,19 @@
var gridH = h - 2 * padY;
// Compute spacing between wheat plants
var spacingX = (gridW - wheatW) / (cols - 1);
var spacingY = (gridH - wheatH) / (rows - 1);
- // Place wheat in grid
+ // Place wheat/vegetable in grid
for (var row = 0; row < rows; ++row) {
for (var col = 0; col < cols; ++col) {
var wx = x + padX + col * spacingX + wheatW / 2;
var wy = y + padY + row * spacingY + wheatH;
var wheat = new Wheat();
wheat.x = wx;
wheat.y = wy;
wheat.fieldIndex = self.index;
+ wheat.vegAssetId = vegAssetId;
+ wheat.setVegAsset && wheat.setVegAsset(vegAssetId); // If method exists
self.addChild(wheat);
self.wheats.push(wheat);
}
}
@@ -390,9 +399,10 @@
});
// Wheat class
var Wheat = Container.expand(function () {
var self = Container.call(this);
- var wheatAsset = self.attachAsset('wheat', {
+ self.vegAssetId = 'wheat';
+ self.wheatAsset = self.attachAsset('wheat', {
anchorX: 0.5,
anchorY: 1
});
var sproutAsset = self.attachAsset('sprout', {
@@ -407,22 +417,36 @@
self.regrowCounter = 0;
self.fieldIndex = 0; // which field this wheat belongs to
self.regrowing = false;
self.removeAfter = 0;
+ // Change vegetable asset if needed
+ self.setVegAsset = function (assetId) {
+ if (self.wheatAsset) {
+ self.wheatAsset.destroy();
+ }
+ self.vegAssetId = assetId || 'wheat';
+ self.wheatAsset = self.attachAsset(self.vegAssetId, {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ // Make sure sprout is on top
+ self.removeChild(sproutAsset);
+ self.addChild(sproutAsset);
+ };
// Show/hide wheat and handle regrow animation
self.setHarvested = function (harvested) {
self.harvested = harvested;
if (harvested) {
// Hide wheat, show sprout
- wheatAsset.alpha = 0;
+ if (self.wheatAsset) self.wheatAsset.alpha = 0;
sproutAsset.alpha = 1;
sproutAsset.scaleX = 0.5;
sproutAsset.scaleY = 0.5;
self.regrowCounter = self.regrowTime;
self.regrowing = true;
} else {
// Show wheat, hide sprout
- wheatAsset.alpha = 1;
+ if (self.wheatAsset) self.wheatAsset.alpha = 1;
sproutAsset.alpha = 0;
self.regrowing = false;
}
};
@@ -460,21 +484,23 @@
/****
* Game Code
****/
-// --- Game constants ---
-// Field fence (rectangle)
-// Wheat (ellipse)
-// Farmer (box)
-// House (box)
-// Sickle (ellipse, yellow)
// Lock icon (ellipse, gray)
+// Sickle (ellipse, yellow)
+// House (box)
+// Farmer (box)
+// Wheat (ellipse)
+// Field fence (rectangle)
+// --- Game constants ---
var FIELD_W = 900;
var FIELD_H = 900;
var FIELD_GAP = 120; // Increased gap to move fences further from center
var FIELD_COUNT = 4;
var WHEAT_PER_FIELD = 10;
-var FIELD_LOCK_COSTS = [0, 1000, 3000, 8000]; // field 0 open, others locked
+// Area unlock prices and reward multipliers
+var FIELD_LOCK_COSTS = [0, 20000, 40000, 60000]; // Area 1 open, others locked
+var FIELD_REWARD_MULT = [1, 2, 3, 4]; // Area 1=1x, 2=2x, 3=3x, 4=4x
// --- Game state ---
var fields = [];
var farmer = null;
var money = 0;
@@ -654,9 +680,10 @@
}
});
// Harvest
w.setHarvested(true);
- money += 100;
+ var reward = 100 * (FIELD_REWARD_MULT[w.fieldIndex] || 1);
+ money += reward;
updateMoneyDisplay();
// Flash wheat
LK.effects.flashObject(w, 0xffff00, 300);
// No setHarvested(false) here; regrow/removal handled in Wheat.update