User prompt
necesitamos una hotbar y algo de ambientacion
User prompt
quiero que esten todas las plots centradas y necesitamos el boton de tienda y una tienda funcional con el inventario
Code edit (1 edits merged)
Please save this source code
User prompt
Harvest Haven
Initial prompt
quiero que crees un juego de granjas con vista isométrica que tenga un bucle jugable con una tienda sistema de inventario
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var FarmPlot = Container.expand(function () {
var self = Container.call(this);
var plotGraphics = self.attachAsset('farmPlot', {
anchorX: 0.5,
anchorY: 0.5
});
self.cropType = null;
self.plantTime = 0;
self.growthStage = 0;
self.currentCrop = null;
self.isEmpty = true;
self.isReady = false;
self.plantCrop = function (cropType) {
if (!self.isEmpty) return false;
self.cropType = cropType;
self.plantTime = LK.ticks;
self.growthStage = 0;
self.isEmpty = false;
self.isReady = false;
// Create seedling
self.currentCrop = self.addChild(LK.getAsset('seedling', {
anchorX: 0.5,
anchorY: 0.5,
y: -20
}));
LK.getSound('plant').play();
return true;
};
self.harvestCrop = function () {
if (!self.isReady) return null;
var harvestedCrop = {
type: self.cropType,
value: cropData[self.cropType].value
};
// Remove crop visual
if (self.currentCrop) {
self.currentCrop.destroy();
self.currentCrop = null;
}
// Reset plot
self.cropType = null;
self.plantTime = 0;
self.growthStage = 0;
self.isEmpty = true;
self.isReady = false;
LK.getSound('harvest').play();
return harvestedCrop;
};
self.update = function () {
if (self.isEmpty || !self.cropType) return;
var elapsed = LK.ticks - self.plantTime;
var growthTime = cropData[self.cropType].growthTime;
if (elapsed >= growthTime && !self.isReady) {
// Crop is ready
self.isReady = true;
if (self.currentCrop) {
self.currentCrop.destroy();
}
self.currentCrop = self.addChild(LK.getAsset(self.cropType, {
anchorX: 0.5,
anchorY: 0.5,
y: -20
}));
// Add glow effect for ready crops
tween(self.currentCrop, {
alpha: 0.7
}, {
duration: 500,
easing: tween.easeInOut
});
tween(self.currentCrop, {
alpha: 1.0
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (self.currentCrop && self.isReady) {
tween(self.currentCrop, {
alpha: 0.7
}, {
duration: 500,
easing: tween.easeInOut
});
tween(self.currentCrop, {
alpha: 1.0
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
if (self.currentCrop && self.isReady) {
self.update();
}
}
});
}
}
});
} else if (elapsed < growthTime && elapsed > growthTime * 0.5 && self.growthStage === 0) {
// Half grown
self.growthStage = 1;
if (self.currentCrop) {
tween(self.currentCrop, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300
});
}
}
};
self.down = function (x, y, obj) {
if (self.isReady) {
var harvest = self.harvestCrop();
if (harvest) {
// Add to inventory
if (!inventory[harvest.type]) {
inventory[harvest.type] = 0;
}
inventory[harvest.type]++;
coins += harvest.value;
updateUI();
}
} else if (self.isEmpty && selectedSeed && seeds[selectedSeed] > 0) {
if (self.plantCrop(selectedSeed)) {
seeds[selectedSeed]--;
updateUI();
}
}
};
return self;
});
var HotbarSlot = Container.expand(function (seedType, index) {
var self = Container.call(this);
self.seedType = seedType;
self.index = index;
self.isSelected = false;
var slotBg = self.attachAsset('hotbarSlot', {
anchorX: 0.5,
anchorY: 0.5
});
self.selectedBg = self.addChild(LK.getAsset('hotbarSlotSelected', {
anchorX: 0.5,
anchorY: 0.5
}));
self.selectedBg.visible = false;
// Add seed visual
if (seedType) {
var seedVisual = self.addChild(LK.getAsset(seedType, {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.8,
scaleY: 0.8
}));
}
// Add count text
self.countText = new Text2('0', {
size: 30,
fill: 0xFFFFFF
});
self.countText.anchor.set(0.5, 0.5);
self.countText.x = 0;
self.countText.y = 40;
self.addChild(self.countText);
self.updateCount = function (count) {
self.countText.setText(count.toString());
self.alpha = count > 0 ? 1.0 : 0.5;
};
self.setSelected = function (selected) {
self.isSelected = selected;
self.selectedBg.visible = selected;
if (selected) {
tween(self, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeInOut
});
} else {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeInOut
});
}
};
self.down = function (x, y, obj) {
if (seeds[self.seedType] > 0) {
selectedSeed = self.seedType;
updateHotbar();
}
};
return self;
});
var InventoryPanel = Container.expand(function () {
var self = Container.call(this);
var panelBg = self.attachAsset('inventoryPanel', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2('INVENTORY', {
size: 80,
fill: 0x000000
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -600;
self.addChild(titleText);
var closeBtn = self.addChild(LK.getAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -600
}));
var closeBtnText = new Text2('X', {
size: 40,
fill: 0xFFFFFF
});
closeBtnText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeBtnText);
self.inventoryTexts = [];
self.updateInventory = function () {
// Clear existing texts
self.inventoryTexts.forEach(function (text) {
text.destroy();
});
self.inventoryTexts = [];
var yPos = -400;
// Show seeds
Object.keys(seeds).forEach(function (seedType) {
if (seeds[seedType] > 0) {
var seedName = cropData[seedType].name;
var text = new Text2('Seeds: ' + seedName + ' x' + seeds[seedType], {
size: 40,
fill: 0x000000
});
text.anchor.set(0.5, 0.5);
text.x = 0;
text.y = yPos;
self.addChild(text);
self.inventoryTexts.push(text);
yPos += 80;
}
});
// Show harvested crops
Object.keys(inventory).forEach(function (cropType) {
if (inventory[cropType] > 0) {
var cropName = cropData[cropType].name;
var text = new Text2('Crops: ' + cropName + ' x' + inventory[cropType], {
size: 40,
fill: 0x000000
});
text.anchor.set(0.5, 0.5);
text.x = 0;
text.y = yPos;
self.addChild(text);
self.inventoryTexts.push(text);
yPos += 80;
}
});
};
closeBtn.down = function (x, y, obj) {
self.visible = false;
isInventoryOpen = false;
};
return self;
});
var ShopPanel = Container.expand(function () {
var self = Container.call(this);
var panelBg = self.attachAsset('shopPanel', {
anchorX: 0.5,
anchorY: 0.5
});
var titleText = new Text2('SHOP', {
size: 80,
fill: 0x000000
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -600;
self.addChild(titleText);
var closeBtn = self.addChild(LK.getAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: -600
}));
var closeBtnText = new Text2('X', {
size: 40,
fill: 0xFFFFFF
});
closeBtnText.anchor.set(0.5, 0.5);
closeBtn.addChild(closeBtnText);
// Seed shop items
var seedItems = [{
name: 'Lettuce Seeds',
type: 'crop1',
price: 5,
y: -300
}, {
name: 'Tomato Seeds',
type: 'crop2',
price: 10,
y: -100
}, {
name: 'Corn Seeds',
type: 'crop3',
price: 20,
y: 100
}];
seedItems.forEach(function (item) {
var itemText = new Text2(item.name + ' - ' + item.price + ' coins', {
size: 50,
fill: 0x000000
});
itemText.anchor.set(0.5, 0.5);
itemText.x = -300;
itemText.y = item.y;
self.addChild(itemText);
var buyBtn = self.addChild(LK.getAsset('buyButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: item.y
}));
var buyText = new Text2('BUY', {
size: 30,
fill: 0xFFFFFF
});
buyText.anchor.set(0.5, 0.5);
buyBtn.addChild(buyText);
buyBtn.down = function (x, y, obj) {
if (coins >= item.price) {
coins -= item.price;
if (!seeds[item.type]) {
seeds[item.type] = 0;
}
seeds[item.type] += 5;
LK.getSound('purchase').play();
updateUI();
}
};
});
closeBtn.down = function (x, y, obj) {
self.visible = false;
isShopOpen = false;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game data
var cropData = {
'crop1': {
name: 'Lettuce',
growthTime: 300,
value: 8
},
// 5 seconds
'crop2': {
name: 'Tomato',
growthTime: 600,
value: 18
},
// 10 seconds
'crop3': {
name: 'Corn',
growthTime: 900,
value: 35
} // 15 seconds
};
// Game state
var coins = storage.coins || 50;
var seeds = storage.seeds || {
'crop1': 5,
'crop2': 2,
'crop3': 1
};
var inventory = storage.inventory || {};
var selectedSeed = 'crop1';
var isShopOpen = false;
var isInventoryOpen = false;
// UI elements
var coinsText = new Text2('Coins: ' + coins, {
size: 60,
fill: 0xFFD700
});
coinsText.anchor.set(0, 0);
coinsText.x = 150;
coinsText.y = 50;
LK.gui.topLeft.addChild(coinsText);
var seedText = new Text2('Selected: ' + cropData[selectedSeed].name + ' (' + (seeds[selectedSeed] || 0) + ')', {
size: 50,
fill: 0xFFFFFF
});
seedText.anchor.set(0.5, 0);
seedText.x = 0;
seedText.y = 50;
LK.gui.top.addChild(seedText);
// Shop button
var shopBtn = LK.getAsset('shopButton', {
anchorX: 0.5,
anchorY: 0.5
});
var shopBtnText = new Text2('SHOP', {
size: 40,
fill: 0xFFFFFF
});
shopBtnText.anchor.set(0.5, 0.5);
shopBtn.addChild(shopBtnText);
LK.gui.topRight.addChild(shopBtn);
// Inventory button
var invBtn = LK.getAsset('inventoryButton', {
anchorX: 0.5,
anchorY: 0.5
});
var invBtnText = new Text2('INVENTORY', {
size: 35,
fill: 0xFFFFFF
});
invBtnText.anchor.set(0.5, 0.5);
invBtn.addChild(invBtnText);
invBtn.x = -100;
invBtn.y = 0;
LK.gui.topRight.addChild(invBtn);
// Create farm plots in isometric grid
var farmPlots = [];
var plotsPerRow = 4;
var plotsPerCol = 6;
var plotSpacingX = 140;
var plotSpacingY = 100;
// Calculate proper centering
var totalWidth = (plotsPerRow - 1) * plotSpacingX + (plotsPerCol - 1) * 30;
var totalHeight = (plotsPerCol - 1) * plotSpacingY;
var startX = (2048 - totalWidth) / 2;
var startY = (2732 - totalHeight) / 2;
for (var row = 0; row < plotsPerCol; row++) {
for (var col = 0; col < plotsPerRow; col++) {
var plot = new FarmPlot();
plot.x = startX + col * plotSpacingX - row * 30;
plot.y = startY + row * plotSpacingY;
game.addChild(plot);
farmPlots.push(plot);
}
}
// Shop and inventory panels
var shopPanel = new ShopPanel();
shopPanel.x = 1024;
shopPanel.y = 1366;
shopPanel.visible = false;
game.addChild(shopPanel);
var inventoryPanel = new InventoryPanel();
inventoryPanel.x = 1024;
inventoryPanel.y = 1366;
inventoryPanel.visible = false;
game.addChild(inventoryPanel);
// Button event handlers
shopBtn.down = function (x, y, obj) {
if (!isInventoryOpen) {
shopPanel.visible = true;
isShopOpen = true;
}
};
invBtn.down = function (x, y, obj) {
if (!isShopOpen) {
inventoryPanel.visible = true;
inventoryPanel.updateInventory();
isInventoryOpen = true;
}
};
// Create hotbar
var hotbarSlots = [];
var hotbarContainer = new Container();
hotbarContainer.x = 1024;
hotbarContainer.y = 2600;
game.addChild(hotbarContainer);
// Create hotbar slots for each seed type
var seedTypes = ['crop1', 'crop2', 'crop3'];
seedTypes.forEach(function (seedType, index) {
var slot = new HotbarSlot(seedType, index);
slot.x = (index - 1) * 140;
slot.y = 0;
hotbarContainer.addChild(slot);
hotbarSlots.push(slot);
});
// Add environmental grass elements
var grassElements = [];
for (var i = 0; i < 15; i++) {
var grassType = 'grass' + (Math.floor(Math.random() * 3) + 1);
var grass = game.addChild(LK.getAsset(grassType, {
anchorX: 0.5,
anchorY: 0.5
}));
// Position grass randomly around the farm area
grass.x = Math.random() * 2048;
grass.y = Math.random() * 2732;
grass.alpha = 0.6;
// Animate grass gently
tween(grass, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(grass, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 2000 + Math.random() * 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
// Loop animation
if (grass.parent) {
grass.parent.update();
}
}
});
}
});
grassElements.push(grass);
}
function updateHotbar() {
hotbarSlots.forEach(function (slot) {
var count = seeds[slot.seedType] || 0;
slot.updateCount(count);
slot.setSelected(slot.seedType === selectedSeed);
});
}
// Initialize hotbar
updateHotbar();
// Remove old seed selection behavior - hotbar handles it now
game.down = function (x, y, obj) {
// Hotbar slots handle their own clicks now
};
function updateUI() {
coinsText.setText('Coins: ' + coins);
seedText.setText('Selected: ' + cropData[selectedSeed].name + ' (' + (seeds[selectedSeed] || 0) + ')');
updateHotbar();
// Save progress
storage.coins = coins;
storage.seeds = seeds;
storage.inventory = inventory;
}
game.update = function () {
// Update all farm plots
farmPlots.forEach(function (plot) {
// Plot update is called automatically
});
}; ===================================================================
--- original.js
+++ change.js
@@ -137,8 +137,73 @@
}
};
return self;
});
+var HotbarSlot = Container.expand(function (seedType, index) {
+ var self = Container.call(this);
+ self.seedType = seedType;
+ self.index = index;
+ self.isSelected = false;
+ var slotBg = self.attachAsset('hotbarSlot', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.selectedBg = self.addChild(LK.getAsset('hotbarSlotSelected', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ self.selectedBg.visible = false;
+ // Add seed visual
+ if (seedType) {
+ var seedVisual = self.addChild(LK.getAsset(seedType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }));
+ }
+ // Add count text
+ self.countText = new Text2('0', {
+ size: 30,
+ fill: 0xFFFFFF
+ });
+ self.countText.anchor.set(0.5, 0.5);
+ self.countText.x = 0;
+ self.countText.y = 40;
+ self.addChild(self.countText);
+ self.updateCount = function (count) {
+ self.countText.setText(count.toString());
+ self.alpha = count > 0 ? 1.0 : 0.5;
+ };
+ self.setSelected = function (selected) {
+ self.isSelected = selected;
+ self.selectedBg.visible = selected;
+ if (selected) {
+ tween(self, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ } else {
+ tween(self, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (seeds[self.seedType] > 0) {
+ selectedSeed = self.seedType;
+ updateHotbar();
+ }
+ };
+ return self;
+});
var InventoryPanel = Container.expand(function () {
var self = Container.call(this);
var panelBg = self.attachAsset('inventoryPanel', {
anchorX: 0.5,
@@ -422,26 +487,77 @@
inventoryPanel.updateInventory();
isInventoryOpen = true;
}
};
-// Seed selection
-game.down = function (x, y, obj) {
- if (!isShopOpen && !isInventoryOpen) {
- // Cycle through available seeds
- var seedTypes = Object.keys(seeds).filter(function (type) {
- return seeds[type] > 0;
- });
- if (seedTypes.length > 0) {
- var currentIndex = seedTypes.indexOf(selectedSeed);
- var nextIndex = (currentIndex + 1) % seedTypes.length;
- selectedSeed = seedTypes[nextIndex];
- updateUI();
+// Create hotbar
+var hotbarSlots = [];
+var hotbarContainer = new Container();
+hotbarContainer.x = 1024;
+hotbarContainer.y = 2600;
+game.addChild(hotbarContainer);
+// Create hotbar slots for each seed type
+var seedTypes = ['crop1', 'crop2', 'crop3'];
+seedTypes.forEach(function (seedType, index) {
+ var slot = new HotbarSlot(seedType, index);
+ slot.x = (index - 1) * 140;
+ slot.y = 0;
+ hotbarContainer.addChild(slot);
+ hotbarSlots.push(slot);
+});
+// Add environmental grass elements
+var grassElements = [];
+for (var i = 0; i < 15; i++) {
+ var grassType = 'grass' + (Math.floor(Math.random() * 3) + 1);
+ var grass = game.addChild(LK.getAsset(grassType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ }));
+ // Position grass randomly around the farm area
+ grass.x = Math.random() * 2048;
+ grass.y = Math.random() * 2732;
+ grass.alpha = 0.6;
+ // Animate grass gently
+ tween(grass, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 2000 + Math.random() * 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(grass, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 2000 + Math.random() * 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ // Loop animation
+ if (grass.parent) {
+ grass.parent.update();
+ }
+ }
+ });
}
- }
+ });
+ grassElements.push(grass);
+}
+function updateHotbar() {
+ hotbarSlots.forEach(function (slot) {
+ var count = seeds[slot.seedType] || 0;
+ slot.updateCount(count);
+ slot.setSelected(slot.seedType === selectedSeed);
+ });
+}
+// Initialize hotbar
+updateHotbar();
+// Remove old seed selection behavior - hotbar handles it now
+game.down = function (x, y, obj) {
+ // Hotbar slots handle their own clicks now
};
function updateUI() {
coinsText.setText('Coins: ' + coins);
seedText.setText('Selected: ' + cropData[selectedSeed].name + ' (' + (seeds[selectedSeed] || 0) + ')');
+ updateHotbar();
// Save progress
storage.coins = coins;
storage.seeds = seeds;
storage.inventory = inventory;
buy button. In-Game asset. 2d. High contrast. No shadows
inventory button. In-Game asset. 2d. High contrast. No shadows
shop button. In-Game asset. 2d. High contrast. No shadows
X button. In-Game asset. 2d. High contrast. No shadows
dirt. In-Game asset. 2d. High contrast. No shadows
lechuga. In-Game asset. 2d. High contrast. No shadows
tomate. In-Game asset. 2d. High contrast. No shadows
semilla. In-Game asset. 2d. High contrast. No shadows
sell button. In-Game asset. 2d. High contrast. No shadows
maiz. In-Game asset. 2d. High contrast. No shadows
sell all button. In-Game asset. 2d. High contrast. No shadows
upgrade button. In-Game asset. 2d. High contrast. No shadows
Hotbar slot. In-Game asset. 2d. High contrast. No shadows
Quita el cesped de abajo
Flying minion flower. In-Game asset. 2d. High contrast. No shadows
Aspersor. In-Game asset. 2d. High contrast. No shadows
Que sea verde y hectagonal
Arbol de habilidades botón. In-Game asset. 2d. High contrast. No shadows
calabaza. In-Game asset. 2d. High contrast. No shadows
sandia entera
planta uva. In-Game asset. 2d. High contrast. No shadows
trufa. In-Game asset. 2d. High contrast. No shadows
orquidea. In-Game asset. 2d. High contrast. No shadows