User prompt
Haritanın bazı bölgelerine Cevher spawn olsun. Ürünleri mağazaya taşıyan taşıyıcıların olması ile ilgili kod ekle. Ürünler otomatik olarak mağazaya taşınmasın. Taşıyıcılar sayesinde ürünler taşınsın.
Code edit (1 edits merged)
Please save this source code
User prompt
Otomasyon Madencileri
Initial prompt
Factario tarzı bir oyun yapmak istiyorum. Ama bu strateji ve simulasyon tarzı. Madenciler hareket ederek madenlere gitsinler ve madenlerden Cevher çıkarsınlar. Bu cevheri götürüp fabrikada işlesinler ve işleyip ürün üretip bu ürünleri mağazada satmak istiyorum.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Factory: Converts ore to product over time var Factory = Container.expand(function () { var self = Container.call(this); var factorySprite = self.attachAsset('factory', { anchorX: 0.5, anchorY: 0.5 }); self.oreBuffer = 0; // ore waiting to be processed self.productBuffer = 0; // products ready to be sold self.processTime = 60; // ticks to process one ore self.processCounter = 0; self.update = function () { if (self.oreBuffer > 0) { self.processCounter++; if (self.processCounter >= self.processTime) { self.oreBuffer--; self.productBuffer++; self.processCounter = 0; } } else { self.processCounter = 0; } }; return self; }); // Mine: Contains ore, can be depleted var Mine = Container.expand(function () { var self = Container.call(this); var mineSprite = self.attachAsset('mine', { anchorX: 0.5, anchorY: 0.5 }); self.ore = 10; // initial ore self.setOre = function (amount) { self.ore = amount; }; return self; }); // Miner: Moves to mine, collects ore, brings to factory, repeats var Miner = Container.expand(function () { var self = Container.call(this); // Miner visual var minerSprite = self.attachAsset('miner', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 6; // px per tick self.state = 'idle'; // 'idle', 'toMine', 'toFactory', 'toShop' self.target = null; // {x, y} self.carrying = null; // 'ore' or 'product' or null self.mineTarget = null; // reference to Mine self.factoryTarget = null; // reference to Factory // Set miner to go to a mine self.goToMine = function (mine) { self.state = 'toMine'; self.target = { x: mine.x, y: mine.y }; self.mineTarget = mine; }; // Set miner to go to factory self.goToFactory = function (factory) { self.state = 'toFactory'; self.target = { x: factory.x, y: factory.y }; self.factoryTarget = factory; }; // Set miner to idle self.setIdle = function () { self.state = 'idle'; self.target = null; self.mineTarget = null; self.factoryTarget = null; }; // Move towards target self.moveTowards = function (tx, ty) { var dx = tx - self.x; var dy = ty - self.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < self.speed) { self.x = tx; self.y = ty; return true; } self.x += dx / dist * self.speed; self.y += dy / dist * self.speed; return false; }; // Called every tick self.update = function () { if (self.state === 'toMine' && self.mineTarget) { if (self.moveTowards(self.mineTarget.x, self.mineTarget.y)) { // Arrived at mine if (self.mineTarget.ore > 0 && !self.carrying) { self.mineTarget.ore--; self.carrying = 'ore'; self.goToFactory(factoryList[0]); } else { self.setIdle(); } } } else if (self.state === 'toFactory' && self.factoryTarget) { if (self.moveTowards(self.factoryTarget.x, self.factoryTarget.y)) { // Arrived at factory if (self.carrying === 'ore') { self.carrying = null; self.factoryTarget.oreBuffer++; self.setIdle(); } else { self.setIdle(); } } } else if (self.state === 'idle') { // Find nearest mine with ore var bestMine = null; var bestDist = Infinity; for (var i = 0; i < mineList.length; i++) { var m = mineList[i]; if (m.ore > 0) { var dx = m.x - self.x; var dy = m.y - self.y; var d = dx * dx + dy * dy; if (d < bestDist) { bestDist = d; bestMine = m; } } } if (bestMine) { self.goToMine(bestMine); } } }; return self; }); // Shop: Sells products for money var Shop = Container.expand(function () { var self = Container.call(this); var shopSprite = self.attachAsset('shop', { anchorX: 0.5, anchorY: 0.5 }); self.sell = function (factory) { if (factory.productBuffer > 0) { factory.productBuffer--; money += 10; updateMoneyText(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x222222 }); /**** * Game Code ****/ // Global game state var minerList = []; var mineList = []; var factoryList = []; var shopList = []; var money = 50; // UI var moneyText = new Text2('₺' + money, { size: 100, fill: 0xFFE066 }); moneyText.anchor.set(0.5, 0); LK.gui.top.addChild(moneyText); function updateMoneyText() { moneyText.setText('₺' + money); } // Add buttons for buying miners and mines var buyMinerBtn = new Text2('Madenci Al (₺30)', { size: 70, fill: "#fff" }); buyMinerBtn.anchor.set(0.5, 0.5); buyMinerBtn.x = 400; buyMinerBtn.y = 100; LK.gui.top.addChild(buyMinerBtn); var buyMineBtn = new Text2('Maden Aç (₺40)', { size: 70, fill: "#fff" }); buyMineBtn.anchor.set(0.5, 0.5); buyMineBtn.x = 900; buyMineBtn.y = 100; LK.gui.top.addChild(buyMineBtn); var buyFactoryBtn = new Text2('Fabrika Kur (₺60)', { size: 70, fill: "#fff" }); buyFactoryBtn.anchor.set(0.5, 0.5); buyFactoryBtn.x = 1500; buyFactoryBtn.y = 100; LK.gui.top.addChild(buyFactoryBtn); // Button events buyMinerBtn.down = function () { if (money >= 30) { money -= 30; updateMoneyText(); spawnMiner(); } }; buyMineBtn.down = function () { if (money >= 40) { money -= 40; updateMoneyText(); spawnMine(); } }; buyFactoryBtn.down = function () { if (money >= 60) { money -= 60; updateMoneyText(); spawnFactory(); } }; // Spawning functions function spawnMiner() { var miner = new Miner(); // Place at random near bottom miner.x = 400 + Math.random() * 1200; miner.y = 2300 + Math.random() * 200; minerList.push(miner); game.addChild(miner); } function spawnMine() { var mine = new Mine(); // Place at random in upper half mine.x = 300 + Math.random() * 1400; mine.y = 600 + Math.random() * 600; mineList.push(mine); game.addChild(mine); } function spawnFactory() { var factory = new Factory(); // Place at center factory.x = 1024; factory.y = 1600; factoryList.push(factory); game.addChild(factory); } function spawnShop() { var shop = new Shop(); shop.x = 1024; shop.y = 350; shopList.push(shop); game.addChild(shop); } // Initial setup spawnMine(); spawnMine(); spawnFactory(); spawnShop(); spawnMiner(); // Shop sell timer var shopSellTimer = LK.setInterval(function () { if (factoryList.length > 0 && shopList.length > 0) { shopList[0].sell(factoryList[0]); } }, 500); // Dragging mines/factories for placement (future feature, not implemented now) // Main game update game.update = function () { // Update all miners for (var i = 0; i < minerList.length; i++) { minerList[i].update(); } // Update all factories for (var i = 0; i < factoryList.length; i++) { factoryList[i].update(); } // Remove depleted mines (optional: respawn) for (var i = mineList.length - 1; i >= 0; i--) { if (mineList[i].ore <= 0) { mineList[i].destroy(); mineList.splice(i, 1); } } }; // Show product/ore/factory status as text overlays var statusTexts = []; function updateStatusTexts() { // Remove old for (var i = 0; i < statusTexts.length; i++) { statusTexts[i].destroy(); } statusTexts = []; // Mines for (var i = 0; i < mineList.length; i++) { var t = new Text2('Cevher: ' + mineList[i].ore, { size: 50, fill: "#fff" }); t.anchor.set(0.5, 1); t.x = mineList[i].x; t.y = mineList[i].y - 80; game.addChild(t); statusTexts.push(t); } // Factories for (var i = 0; i < factoryList.length; i++) { var t = new Text2('Cevher: ' + factoryList[i].oreBuffer + '\nÜrün: ' + factoryList[i].productBuffer, { size: 50, fill: "#fff" }); t.anchor.set(0.5, 1); t.x = factoryList[i].x; t.y = factoryList[i].y - 80; game.addChild(t); statusTexts.push(t); } } var statusTimer = LK.setInterval(updateStatusTexts, 400); // Prevent UI overlap with top left menu // (All UI is placed away from top left 100x100 px) buyMinerBtn.x = 400; buyMineBtn.x = 900; buyFactoryBtn.x = 1500; // No background, no music, no sound, as per requirements // End of MVP code
===================================================================
--- original.js
+++ change.js
Kazma cevheri kazma hareketli resmi.. In-Game asset. 2d. High contrast. No shadows
Cevher. In-Game asset. 2d. High contrast. No shadows
Üstten olacak şekilde hafif ormanlık ve dağlık olacak şekilde çayır.. In-Game asset. 2d. High contrast. Gölgelikler olsun. Map tarzı bir harita.. In-Game asset. 2d. High contrast. No shadows
Madenci. In-Game asset. 2d. High contrast. No shadows
Savaşçı. In-Game asset. 2d. High contrast. No shadows
Kılıç kalkan ok yay gibi savaş malzemeleri taşıyan at arabası. In-Game asset. 2d. High contrast. No shadows
Demirci, Eski savaş malzemeleri üretiyor. In-Game asset. 2d. High contrast. No shadows
Okçu savaşçı. In-Game asset. 2d. High contrast. No shadows
Eski çağ savaş malzemesi dükkanı. In-Game asset. 2d. High contrast. No shadows
Cevher. In-Game asset. 2d. High contrast. No shadows
Cevher. In-Game asset. 2d. High contrast. No shadows
Savaşçı kampı. In-Game asset. 2d. High contrast. No shadows
Büyük savaşçı kampı uzaktan görünüm. In-Game asset. 2d. High contrast. No shadows
Siyah sayfa. In-Game asset. 2d. High contrast. No shadows
Madenci. In-Game asset. 2d. High contrast. No shadows
Demirci ve madencilerin olduğu uzaktan bakış bir kamp alanı oluştur.. In-Game asset. 2d. High contrast. No shadows
Eski kılıçlı silahlar ve cevherlerin vs. olduğu uzaktan bakış depo alanı.. In-Game asset. 2d. High contrast. No shadows
Canavar. In-Game asset. 2d. High contrast. No shadows
Düşman canavar. In-Game asset. 2d. High contrast. No shadows
Düşman farklı canavar. In-Game asset. 2d. High contrast. No shadows
Kılıçlar savaş iconu. In-Game asset. 2d. High contrast. No shadows
Canavar. In-Game asset. 2d. High contrast. No shadows
Atlı savaşçı asker. In-Game asset. 2d. High contrast. No shadows
Mızraklı piyade asker. In-Game asset. 2d. High contrast. No shadows
Okçu piyade savaşçı. In-Game asset. 2d. High contrast. No shadows
Yaya Piyade savaşçı. In-Game asset. 2d. High contrast. No shadows
Zırhlı Savaşçı. In-Game asset. 2d. High contrast. No shadows
Yetişen yiyecek. In-Game asset. 2d. High contrast. No shadows
Yetişen Yiyecek. In-Game asset. 2d. High contrast. No shadows
Dalında çilek. In-Game asset. 2d. High contrast. No shadows
Dalında Meyve. In-Game asset. 2d. High contrast. No shadows
Oduncu. In-Game asset. 2d. High contrast. No shadows
Oduncu. In-Game asset. 2d. High contrast. No shadows
Oduncu. In-Game asset. 2d. High contrast. No shadows
Ağaç. In-Game asset. 2d. High contrast. No shadows
Ağaç. In-Game asset. 2d. High contrast. No shadows
Toplayıcı. In-Game asset. 2d. High contrast. No shadows
Toplayıcı. In-Game asset. 2d. High contrast. No shadows
İnşaat eski çağ. In-Game asset. 2d. High contrast. No shadows
Eski çağ savaş karavan. In-Game asset. 2d. High contrast. No shadows
Kalkan. In-Game asset. 2d. High contrast. No shadows
Kalkanlı Savaş Arabası. In-Game asset. 2d. High contrast. No shadows
Koçbaşı. In-Game asset. 2d. High contrast. No shadows
Kılıç. In-Game asset. 2d. High contrast. No shadows
Mızrak. In-Game asset. 2d. High contrast. No shadows
Ok ve Yay birlikte eski çağ. In-Game asset. 2d. High contrast. No shadows
Büyük savaş baltası. In-Game asset. 2d. High contrast. No shadows
Savaş Zırhı. In-Game asset. 2d. High contrast. No shadows
Miğfer. In-Game asset. 2d. High contrast. No shadows
Maden arayıcı eski çağ. In-Game asset. 2d. High contrast. No shadows
Arkaplan müziği için kullanacağım müzik ile ilgili bir icon. In-Game asset. 2d. High contrast. No shadows