User prompt
Yeni bir tarla yeri açmak için 20 paramız olması lazım tarla açmamız için şuan olan tarlanın alt tarafındaki boş yere bir tuş ekle.
User prompt
Mısır ekme colddown süresini tarlaların üstünde göster
User prompt
Mısırları topladığımda tarlaya bidaha mısır ekmem için 5 saniye beklemem gerek.
User prompt
Mısırları biz ekmediğimiz sürece kendisi otomatik ekmesin
User prompt
Sadece ilk mısırların çıkma süresi 5 olsun sonra 1er saniye artsın çıkma süresi her ekimde.
User prompt
Please fix the bug: 'Uncaught TypeError: icon.containsPoint is not a function' in or related to this line: 'if (icon.containsPoint({' Line Number: 589
User prompt
Please fix the bug: 'Uncaught TypeError: game.cookArea.containsPoint is not a function' in or related to this line: 'if (game.cookArea.visible && game.cookArea.containsPoint({' Line Number: 906
User prompt
Please fix the bug: 'Uncaught TypeError: game.cornBox.containsPoint is not a function' in or related to this line: 'if (game.cornBox.visible && game.cornBox.containsPoint({' Line Number: 888
User prompt
Mısırların olma sürelerini yukarlarına yaz almaya hazır olduklarında ready yazsın üstlerinde.
User prompt
4 tane tarla olsun şuanlık
User prompt
Please fix the bug: 'Uncaught TypeError: game.orderArea.containsPoint is not a function' in or related to this line: 'if (game.orderArea.visible && game.orderArea.containsPoint({' Line Number: 853
User prompt
Tarla sayısını 4de düşür
User prompt
3 ekran olsun ekranlar arasında geçiş yapabileceğim yön tuşları olsun bunlara basınca sırasıyla tarla, mısır toplama ve satış yeri gelsin hepsi tek bir ekranda olmasın.
User prompt
Please fix the bug: 'Uncaught TypeError: f.containsPoint is not a function' in or related to this line: 'if (f.containsPoint({' Line Number: 718
User prompt
Please fix the bug: 'Uncaught TypeError: unlockBtnContainer.containsPoint is not a function' in or related to this line: 'if (unlockBtnContainer.containsPoint({' Line Number: 688
User prompt
Please fix the bug: 'Uncaught TypeError: unlockBtn.containsPoint is not a function' in or related to this line: 'if (unlockBtn.containsPoint({' Line Number: 685
Code edit (1 edits merged)
Please save this source code
User prompt
Mısır Satıcısı: Tarladan Tezgaha
Initial prompt
Yapacağımız oyun bir mısır satma oyunu olacak. Oyunun ilk ekranında tarla yerleri olacak. Bu tarla yerlerinden ilk başta 4 tane olacak. Sonra para ile alınabilecek 12 tane daha tarım yeri olacak. Tarım yerlerinden mısır ekeceğiz. Mısır tohumları olacak ilk başta bize 4 tane tohum verilicek. İlk ektiğimiz ürünler 5 saniyede oluşacak. Biz bu ürünleri tıklayarak alacağız. Ve diğer ekran geçişi yapacağız. Diğer ekranda geçiş yaptığımızda mısırları mısır üzerinden teker teker toplayarak bir kutunun içine koyacağız. Kutunun içine koyduğumuz mısırları pişirme yerine götüreceğiz.Müşteri olucak ve bizden rastgeli soslu mısır isticek.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // CookArea: Cooks raw corn, can be tapped to cook, then send to order area var CookArea = Container.expand(function () { var self = Container.call(this); var cookAsset = self.attachAsset('cook', { anchorX: 0.5, anchorY: 0.5 }); cookAsset.width = 220; cookAsset.height = 220; self.rawCorn = 0; self.cookedCorn = 0; // Cooked corn icon var cookedAsset = self.attachAsset('cooked', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); cookedAsset.width = 120; cookedAsset.height = 120; // Texts var rawTxt = new Text2('0', { size: 60, fill: "#fff" }); rawTxt.anchor.set(0.5, 0.2); self.addChild(rawTxt); var cookedTxt = new Text2('0', { size: 60, fill: 0xFFB347 }); cookedTxt.anchor.set(0.5, 0.8); self.addChild(cookedTxt); self.addRawCorn = function (n) { self.rawCorn += n; rawTxt.setText(self.rawCorn); LK.effects.flashObject(cookAsset, 0xffff00, 200); }; self.removeRawCorn = function (n) { if (self.rawCorn >= n) { self.rawCorn -= n; rawTxt.setText(self.rawCorn); return true; } return false; }; self.addCookedCorn = function (n) { self.cookedCorn += n; cookedTxt.setText(self.cookedCorn); cookedAsset.alpha = 1; LK.effects.flashObject(cookedAsset, 0xffb347, 200); }; self.removeCookedCorn = function (n) { if (self.cookedCorn >= n) { self.cookedCorn -= n; cookedTxt.setText(self.cookedCorn); if (self.cookedCorn === 0) cookedAsset.alpha = 0; return true; } return false; }; self.down = function (x, y, obj) { if (self.rawCorn > 0) { // Cook one corn (takes time) self.removeRawCorn(1); LK.effects.flashObject(cookAsset, 0xffb347, 200); LK.setTimeout(function () { self.addCookedCorn(1); }, game.cookTime); } else if (self.cookedCorn > 0) { // Send cooked corn to order area var globalCook = self.toGlobal({ x: 0, y: 0 }); var orderPos = game.orderArea.getGlobalCenter(); var flyingCorn = LK.getAsset('cooked', { anchorX: 0.5, anchorY: 0.5, x: globalCook.x, y: globalCook.y, width: 100, height: 100 }); game.addChild(flyingCorn); tween(flyingCorn, { x: orderPos.x, y: orderPos.y, alpha: 0.2 }, { duration: 500, easing: tween.cubicOut, onFinish: function onFinish() { flyingCorn.destroy(); if (self.removeCookedCorn(1)) { game.orderArea.addCorn(1); } } }); } }; self.getGlobalCenter = function () { var pos = self.toGlobal({ x: 0, y: 0 }); return { x: pos.x, y: pos.y }; }; self.reset = function () { self.rawCorn = 0; self.cookedCorn = 0; rawTxt.setText('0'); cookedTxt.setText('0'); cookedAsset.alpha = 0; }; return self; }); // CornBox: Stores harvested corn, can be tapped to send to cook area var CornBox = Container.expand(function () { var self = Container.call(this); var boxAsset = self.attachAsset('box', { anchorX: 0.5, anchorY: 0.5 }); boxAsset.width = 220; boxAsset.height = 220; self.cornCount = 0; // Corn count text var cornTxt = new Text2('0', { size: 80, fill: 0xFFF700 }); cornTxt.anchor.set(0.5, 0.5); self.addChild(cornTxt); self.addCorn = function (n) { self.cornCount += n; cornTxt.setText(self.cornCount); LK.effects.flashObject(boxAsset, 0xffff00, 200); }; self.removeCorn = function (n) { if (self.cornCount >= n) { self.cornCount -= n; cornTxt.setText(self.cornCount); return true; } return false; }; self.down = function (x, y, obj) { if (self.cornCount > 0) { // Animate corn to cook area var globalBox = self.toGlobal({ x: 0, y: 0 }); var cookPos = game.cookArea.getGlobalCenter(); var flyingCorn = LK.getAsset('corn', { anchorX: 0.5, anchorY: 0.5, x: globalBox.x, y: globalBox.y, width: 100, height: 100 }); game.addChild(flyingCorn); tween(flyingCorn, { x: cookPos.x, y: cookPos.y, alpha: 0.2 }, { duration: 500, easing: tween.cubicOut, onFinish: function onFinish() { flyingCorn.destroy(); if (self.removeCorn(1)) { game.cookArea.addRawCorn(1); } } }); } }; self.getGlobalCenter = function () { var pos = self.toGlobal({ x: 0, y: 0 }); return { x: pos.x, y: pos.y }; }; self.reset = function () { self.cornCount = 0; cornTxt.setText('0'); }; return self; }); // CornField: Represents a single field where corn can be planted, grown, and harvested var CornField = Container.expand(function () { var self = Container.call(this); // States: 'empty', 'growing', 'ready' self.state = 'empty'; self.index = 0; // set by game self.cornType = null; // for future upgrades // Field asset var fieldAsset = self.attachAsset('field', { anchorX: 0.5, anchorY: 0.5 }); fieldAsset.width = 320; fieldAsset.height = 320; // Corn asset (hidden unless growing/ready) var cornAsset = self.attachAsset('corn', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); cornAsset.width = 180; cornAsset.height = 180; // Show field as locked if not unlocked var lockAsset = self.attachAsset('lock', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); lockAsset.width = 120; lockAsset.height = 120; // Plant corn if field is empty self.down = function (x, y, obj) { if (self.state === 'empty' && !self.locked) { self.plant(); } else if (self.locked) { // Try to unlock if enough coins if (game.coins >= game.unlockCost) { game.coins -= game.unlockCost; self.unlock(); game.updateCoins(); } else { LK.effects.flashObject(lockAsset, 0xff0000, 500); } } else if (self.state === 'ready') { self.harvest(); } }; self.plant = function () { self.state = 'growing'; cornAsset.alpha = 1; cornAsset.scaleX = 0.5; cornAsset.scaleY = 0.5; tween(cornAsset, { scaleX: 1, scaleY: 1 }, { duration: 400, easing: tween.easeOut }); // Start grow timer self.growTimeout = LK.setTimeout(function () { self.state = 'ready'; LK.effects.flashObject(cornAsset, 0xffff00, 400); }, game.cornGrowTime); }; self.harvest = function () { if (self.state !== 'ready') return; self.state = 'empty'; cornAsset.alpha = 0; // Animate corn flying to box var globalCorn = self.toGlobal({ x: 0, y: 0 }); var boxPos = game.cornBox.getGlobalCenter(); var flyingCorn = LK.getAsset('corn', { anchorX: 0.5, anchorY: 0.5, x: globalCorn.x, y: globalCorn.y, width: 120, height: 120 }); game.addChild(flyingCorn); tween(flyingCorn, { x: boxPos.x, y: boxPos.y, alpha: 0.2 }, { duration: 600, easing: tween.cubicOut, onFinish: function onFinish() { flyingCorn.destroy(); game.cornBox.addCorn(1); } }); }; self.locked = false; self.lock = function () { self.locked = true; lockAsset.alpha = 1; cornAsset.alpha = 0; self.state = 'empty'; }; self.unlock = function () { self.locked = false; lockAsset.alpha = 0; }; self.setLocked = function (locked) { if (locked) self.lock();else self.unlock(); }; self.reset = function () { self.state = 'empty'; cornAsset.alpha = 0; if (self.growTimeout) LK.clearTimeout(self.growTimeout); }; return self; }); // OrderArea: Handles customer orders, sauces, and delivery var OrderArea = Container.expand(function () { var self = Container.call(this); var orderAsset = self.attachAsset('order', { anchorX: 0.5, anchorY: 0.5 }); orderAsset.width = 260; orderAsset.height = 260; self.cornCount = 0; self.currentOrder = null; self.sauces = ['ketchup', 'mayonnaise', 'cheese']; self.selectedSauces = []; // Corn icon var cornAsset = self.attachAsset('cooked', { anchorX: 0.5, anchorY: 0.5, alpha: 0 }); cornAsset.width = 120; cornAsset.height = 120; // Order text var orderTxt = new Text2('', { size: 50, fill: "#fff" }); orderTxt.anchor.set(0.5, 0.1); self.addChild(orderTxt); // Sauce icons self.sauceIcons = []; for (var i = 0; i < self.sauces.length; i++) { var s = self.sauces[i]; var icon = self.attachAsset(s, { anchorX: 0.5, anchorY: 0.5, x: -60 + i * 60, y: 80, alpha: 0.5 }); icon.width = 60; icon.height = 60; icon.sauce = s; self.sauceIcons.push(icon); } // Delivery button var deliverBtn = self.attachAsset('deliver', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 120, alpha: 0.7 }); deliverBtn.width = 100; deliverBtn.height = 60; // Add corn to order area self.addCorn = function (n) { self.cornCount += n; cornAsset.alpha = 1; LK.effects.flashObject(cornAsset, 0xffb347, 200); self.updateOrderText(); }; self.removeCorn = function (n) { if (self.cornCount >= n) { self.cornCount -= n; if (self.cornCount === 0) cornAsset.alpha = 0; self.updateOrderText(); return true; } return false; }; self.updateOrderText = function () { if (!self.currentOrder) { orderTxt.setText(''); return; } var txt = 'Sipariş: '; for (var i = 0; i < self.currentOrder.sauces.length; i++) { txt += self.currentOrder.sauces[i]; if (i < self.currentOrder.sauces.length - 1) txt += ', '; } orderTxt.setText(txt); }; self.newOrder = function () { // Random sauces (1-3) var n = 1 + Math.floor(Math.random() * self.sauces.length); var sauces = []; var used = {}; while (sauces.length < n) { var idx = Math.floor(Math.random() * self.sauces.length); var s = self.sauces[idx]; if (!used[s]) { sauces.push(s); used[s] = true; } } self.currentOrder = { sauces: sauces }; self.selectedSauces = []; self.updateOrderText(); for (var i = 0; i < self.sauceIcons.length; i++) { self.sauceIcons[i].alpha = 0.5; } }; // Sauce selection self.sauceDown = function (sauce) { if (!self.currentOrder) return; if (self.selectedSauces.length >= self.currentOrder.sauces.length) return; if (self.selectedSauces.indexOf(sauce) !== -1) return; self.selectedSauces.push(sauce); for (var i = 0; i < self.sauceIcons.length; i++) { if (self.sauceIcons[i].sauce === sauce) { self.sauceIcons[i].alpha = 1; } } }; // Deliver order self.deliver = function () { if (!self.currentOrder) return; if (self.cornCount < 1) return; // Check sauces var ok = true; for (var i = 0; i < self.currentOrder.sauces.length; i++) { if (self.selectedSauces.indexOf(self.currentOrder.sauces[i]) === -1) { ok = false; break; } } if (ok && self.selectedSauces.length === self.currentOrder.sauces.length) { // Success self.removeCorn(1); LK.effects.flashObject(orderAsset, 0x00ff00, 400); game.coins += game.orderReward; game.updateCoins(); self.currentOrder = null; self.selectedSauces = []; LK.setTimeout(function () { self.newOrder(); }, 800); } else { // Wrong sauces LK.effects.flashObject(orderAsset, 0xff0000, 400); self.selectedSauces = []; for (var i = 0; i < self.sauceIcons.length; i++) { self.sauceIcons[i].alpha = 0.5; } } }; // Event handling self.down = function (x, y, obj) { // Check if sauce icon tapped for (var i = 0; i < self.sauceIcons.length; i++) { var icon = self.sauceIcons[i]; if (icon.containsPoint({ x: x - self.x, y: y - self.y })) { self.sauceDown(icon.sauce); return; } } // Check if deliver button tapped if (deliverBtn.containsPoint({ x: x - self.x, y: y - self.y })) { self.deliver(); return; } }; self.getGlobalCenter = function () { var pos = self.toGlobal({ x: 0, y: 0 }); return { x: pos.x, y: pos.y }; }; self.reset = function () { self.cornCount = 0; self.currentOrder = null; self.selectedSauces = []; cornAsset.alpha = 0; self.updateOrderText(); for (var i = 0; i < self.sauceIcons.length; i++) { self.sauceIcons[i].alpha = 0.5; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2e7d32 }); /**** * Game Code ****/ // --- Game constants --- game.cornGrowTime = 5000; // ms game.cookTime = 2000; // ms game.orderReward = 5; game.unlockCost = 20; game.maxFields = 16; // --- Game state --- game.coins = storage.coins || 10; game.unlockedFields = storage.unlockedFields || 4; // --- UI: Coins display --- var coinsTxt = new Text2(game.coins + '₺', { size: 90, fill: 0xFFFDE7 }); coinsTxt.anchor.set(0.5, 0); LK.gui.top.addChild(coinsTxt); game.updateCoins = function () { coinsTxt.setText(game.coins + '₺'); storage.coins = game.coins; storage.unlockedFields = game.unlockedFields; }; // --- Field grid --- game.fields = []; var fieldRows = 2; var fieldCols = 2; var fieldSpacing = 340; var fieldStartX = 400; var fieldStartY = 600; function updateFieldGrid() { // Determine grid size based on unlocked fields var n = game.unlockedFields; if (n <= 4) { fieldRows = 2; fieldCols = 2; } else if (n <= 9) { fieldRows = 3; fieldCols = 3; } else { fieldRows = 4; fieldCols = 4; } } function layoutFields() { updateFieldGrid(); for (var i = 0; i < game.maxFields; i++) { var row = Math.floor(i / fieldCols); var col = i % fieldCols; var x = fieldStartX + col * fieldSpacing; var y = fieldStartY + row * fieldSpacing; game.fields[i].x = x; game.fields[i].y = y; } } // Create fields for (var i = 0; i < game.maxFields; i++) { var field = new CornField(); field.index = i; game.addChild(field); game.fields.push(field); } function updateFieldLocks() { for (var i = 0; i < game.maxFields; i++) { if (i < game.unlockedFields) { game.fields[i].setLocked(false); } else { game.fields[i].setLocked(true); } } } updateFieldLocks(); layoutFields(); // --- Corn Box --- game.cornBox = new CornBox(); game.cornBox.x = 2048 - 300; game.cornBox.y = 700; game.addChild(game.cornBox); // --- Cook Area --- game.cookArea = new CookArea(); game.cookArea.x = 2048 - 300; game.cookArea.y = 1100; game.addChild(game.cookArea); // --- Order Area --- game.orderArea = new OrderArea(); game.orderArea.x = 2048 - 300; game.orderArea.y = 1550; game.addChild(game.orderArea); game.orderArea.newOrder(); // --- Unlock Button --- var unlockBtn = LK.getAsset('unlock', { anchorX: 0.5, anchorY: 0.5, x: 2048 - 300, y: 2000, width: 200, height: 100, alpha: 0.8 }); game.addChild(unlockBtn); var unlockTxt = new Text2('Tarla Aç (' + game.unlockCost + '₺)', { size: 50, fill: "#fff" }); unlockTxt.anchor.set(0.5, 0.5); unlockTxt.x = unlockBtn.x; unlockTxt.y = unlockBtn.y; game.addChild(unlockTxt); function updateUnlockBtn() { if (game.unlockedFields >= game.maxFields) { unlockBtn.alpha = 0.3; unlockTxt.setText('Tüm Tarlalar Açık'); } else { unlockBtn.alpha = 0.8; unlockTxt.setText('Tarla Aç (' + game.unlockCost + '₺)'); } } updateUnlockBtn(); // --- Touch handling --- game.down = function (x, y, obj) { // Check unlock button if (unlockBtn.containsPoint({ x: x, y: y })) { if (game.coins >= game.unlockCost && game.unlockedFields < game.maxFields) { game.coins -= game.unlockCost; game.unlockedFields += 1; game.updateCoins(); updateFieldLocks(); layoutFields(); updateUnlockBtn(); } else { LK.effects.flashObject(unlockBtn, 0xff0000, 400); } return; } // Check fields for (var i = 0; i < game.fields.length; i++) { var f = game.fields[i]; if (f.containsPoint({ x: x, y: y })) { f.down(x - f.x, y - f.y, obj); return; } } // Check corn box if (game.cornBox.containsPoint({ x: x, y: y })) { game.cornBox.down(x - game.cornBox.x, y - game.cornBox.y, obj); return; } // Check cook area if (game.cookArea.containsPoint({ x: x, y: y })) { game.cookArea.down(x - game.cookArea.x, y - game.cookArea.y, obj); return; } // Check order area if (game.orderArea.containsPoint({ x: x, y: y })) { game.orderArea.down(x - game.orderArea.x, y - game.orderArea.y, obj); return; } }; // --- Game update --- game.update = function () { // Nothing needed for now }; // --- Reset function for new game --- game.resetGame = function () { game.coins = 10; game.unlockedFields = 4; game.updateCoins(); updateFieldLocks(); layoutFields(); updateUnlockBtn(); for (var i = 0; i < game.fields.length; i++) { game.fields[i].reset(); } game.cornBox.reset(); game.cookArea.reset(); game.orderArea.reset(); game.orderArea.newOrder(); }; // --- Asset definitions (for static analysis) --- // These are not real code, but LK will auto-create these assets as used above: // field: green box, corn: yellow ellipse, lock: gray lock, box: brown box, cook: pot, cooked: orange ellipse, order: tray, ketchup/mayonnaise/cheese: colored circles, deliver: blue button, unlock: green button // --- End of code ---
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,723 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+// CookArea: Cooks raw corn, can be tapped to cook, then send to order area
+var CookArea = Container.expand(function () {
+ var self = Container.call(this);
+ var cookAsset = self.attachAsset('cook', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ cookAsset.width = 220;
+ cookAsset.height = 220;
+ self.rawCorn = 0;
+ self.cookedCorn = 0;
+ // Cooked corn icon
+ var cookedAsset = self.attachAsset('cooked', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ cookedAsset.width = 120;
+ cookedAsset.height = 120;
+ // Texts
+ var rawTxt = new Text2('0', {
+ size: 60,
+ fill: "#fff"
+ });
+ rawTxt.anchor.set(0.5, 0.2);
+ self.addChild(rawTxt);
+ var cookedTxt = new Text2('0', {
+ size: 60,
+ fill: 0xFFB347
+ });
+ cookedTxt.anchor.set(0.5, 0.8);
+ self.addChild(cookedTxt);
+ self.addRawCorn = function (n) {
+ self.rawCorn += n;
+ rawTxt.setText(self.rawCorn);
+ LK.effects.flashObject(cookAsset, 0xffff00, 200);
+ };
+ self.removeRawCorn = function (n) {
+ if (self.rawCorn >= n) {
+ self.rawCorn -= n;
+ rawTxt.setText(self.rawCorn);
+ return true;
+ }
+ return false;
+ };
+ self.addCookedCorn = function (n) {
+ self.cookedCorn += n;
+ cookedTxt.setText(self.cookedCorn);
+ cookedAsset.alpha = 1;
+ LK.effects.flashObject(cookedAsset, 0xffb347, 200);
+ };
+ self.removeCookedCorn = function (n) {
+ if (self.cookedCorn >= n) {
+ self.cookedCorn -= n;
+ cookedTxt.setText(self.cookedCorn);
+ if (self.cookedCorn === 0) cookedAsset.alpha = 0;
+ return true;
+ }
+ return false;
+ };
+ self.down = function (x, y, obj) {
+ if (self.rawCorn > 0) {
+ // Cook one corn (takes time)
+ self.removeRawCorn(1);
+ LK.effects.flashObject(cookAsset, 0xffb347, 200);
+ LK.setTimeout(function () {
+ self.addCookedCorn(1);
+ }, game.cookTime);
+ } else if (self.cookedCorn > 0) {
+ // Send cooked corn to order area
+ var globalCook = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ var orderPos = game.orderArea.getGlobalCenter();
+ var flyingCorn = LK.getAsset('cooked', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: globalCook.x,
+ y: globalCook.y,
+ width: 100,
+ height: 100
+ });
+ game.addChild(flyingCorn);
+ tween(flyingCorn, {
+ x: orderPos.x,
+ y: orderPos.y,
+ alpha: 0.2
+ }, {
+ duration: 500,
+ easing: tween.cubicOut,
+ onFinish: function onFinish() {
+ flyingCorn.destroy();
+ if (self.removeCookedCorn(1)) {
+ game.orderArea.addCorn(1);
+ }
+ }
+ });
+ }
+ };
+ self.getGlobalCenter = function () {
+ var pos = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ return {
+ x: pos.x,
+ y: pos.y
+ };
+ };
+ self.reset = function () {
+ self.rawCorn = 0;
+ self.cookedCorn = 0;
+ rawTxt.setText('0');
+ cookedTxt.setText('0');
+ cookedAsset.alpha = 0;
+ };
+ return self;
+});
+// CornBox: Stores harvested corn, can be tapped to send to cook area
+var CornBox = Container.expand(function () {
+ var self = Container.call(this);
+ var boxAsset = self.attachAsset('box', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ boxAsset.width = 220;
+ boxAsset.height = 220;
+ self.cornCount = 0;
+ // Corn count text
+ var cornTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFF700
+ });
+ cornTxt.anchor.set(0.5, 0.5);
+ self.addChild(cornTxt);
+ self.addCorn = function (n) {
+ self.cornCount += n;
+ cornTxt.setText(self.cornCount);
+ LK.effects.flashObject(boxAsset, 0xffff00, 200);
+ };
+ self.removeCorn = function (n) {
+ if (self.cornCount >= n) {
+ self.cornCount -= n;
+ cornTxt.setText(self.cornCount);
+ return true;
+ }
+ return false;
+ };
+ self.down = function (x, y, obj) {
+ if (self.cornCount > 0) {
+ // Animate corn to cook area
+ var globalBox = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ var cookPos = game.cookArea.getGlobalCenter();
+ var flyingCorn = LK.getAsset('corn', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: globalBox.x,
+ y: globalBox.y,
+ width: 100,
+ height: 100
+ });
+ game.addChild(flyingCorn);
+ tween(flyingCorn, {
+ x: cookPos.x,
+ y: cookPos.y,
+ alpha: 0.2
+ }, {
+ duration: 500,
+ easing: tween.cubicOut,
+ onFinish: function onFinish() {
+ flyingCorn.destroy();
+ if (self.removeCorn(1)) {
+ game.cookArea.addRawCorn(1);
+ }
+ }
+ });
+ }
+ };
+ self.getGlobalCenter = function () {
+ var pos = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ return {
+ x: pos.x,
+ y: pos.y
+ };
+ };
+ self.reset = function () {
+ self.cornCount = 0;
+ cornTxt.setText('0');
+ };
+ return self;
+});
+// CornField: Represents a single field where corn can be planted, grown, and harvested
+var CornField = Container.expand(function () {
+ var self = Container.call(this);
+ // States: 'empty', 'growing', 'ready'
+ self.state = 'empty';
+ self.index = 0; // set by game
+ self.cornType = null; // for future upgrades
+ // Field asset
+ var fieldAsset = self.attachAsset('field', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ fieldAsset.width = 320;
+ fieldAsset.height = 320;
+ // Corn asset (hidden unless growing/ready)
+ var cornAsset = self.attachAsset('corn', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ cornAsset.width = 180;
+ cornAsset.height = 180;
+ // Show field as locked if not unlocked
+ var lockAsset = self.attachAsset('lock', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ lockAsset.width = 120;
+ lockAsset.height = 120;
+ // Plant corn if field is empty
+ self.down = function (x, y, obj) {
+ if (self.state === 'empty' && !self.locked) {
+ self.plant();
+ } else if (self.locked) {
+ // Try to unlock if enough coins
+ if (game.coins >= game.unlockCost) {
+ game.coins -= game.unlockCost;
+ self.unlock();
+ game.updateCoins();
+ } else {
+ LK.effects.flashObject(lockAsset, 0xff0000, 500);
+ }
+ } else if (self.state === 'ready') {
+ self.harvest();
+ }
+ };
+ self.plant = function () {
+ self.state = 'growing';
+ cornAsset.alpha = 1;
+ cornAsset.scaleX = 0.5;
+ cornAsset.scaleY = 0.5;
+ tween(cornAsset, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 400,
+ easing: tween.easeOut
+ });
+ // Start grow timer
+ self.growTimeout = LK.setTimeout(function () {
+ self.state = 'ready';
+ LK.effects.flashObject(cornAsset, 0xffff00, 400);
+ }, game.cornGrowTime);
+ };
+ self.harvest = function () {
+ if (self.state !== 'ready') return;
+ self.state = 'empty';
+ cornAsset.alpha = 0;
+ // Animate corn flying to box
+ var globalCorn = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ var boxPos = game.cornBox.getGlobalCenter();
+ var flyingCorn = LK.getAsset('corn', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: globalCorn.x,
+ y: globalCorn.y,
+ width: 120,
+ height: 120
+ });
+ game.addChild(flyingCorn);
+ tween(flyingCorn, {
+ x: boxPos.x,
+ y: boxPos.y,
+ alpha: 0.2
+ }, {
+ duration: 600,
+ easing: tween.cubicOut,
+ onFinish: function onFinish() {
+ flyingCorn.destroy();
+ game.cornBox.addCorn(1);
+ }
+ });
+ };
+ self.locked = false;
+ self.lock = function () {
+ self.locked = true;
+ lockAsset.alpha = 1;
+ cornAsset.alpha = 0;
+ self.state = 'empty';
+ };
+ self.unlock = function () {
+ self.locked = false;
+ lockAsset.alpha = 0;
+ };
+ self.setLocked = function (locked) {
+ if (locked) self.lock();else self.unlock();
+ };
+ self.reset = function () {
+ self.state = 'empty';
+ cornAsset.alpha = 0;
+ if (self.growTimeout) LK.clearTimeout(self.growTimeout);
+ };
+ return self;
+});
+// OrderArea: Handles customer orders, sauces, and delivery
+var OrderArea = Container.expand(function () {
+ var self = Container.call(this);
+ var orderAsset = self.attachAsset('order', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ orderAsset.width = 260;
+ orderAsset.height = 260;
+ self.cornCount = 0;
+ self.currentOrder = null;
+ self.sauces = ['ketchup', 'mayonnaise', 'cheese'];
+ self.selectedSauces = [];
+ // Corn icon
+ var cornAsset = self.attachAsset('cooked', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ cornAsset.width = 120;
+ cornAsset.height = 120;
+ // Order text
+ var orderTxt = new Text2('', {
+ size: 50,
+ fill: "#fff"
+ });
+ orderTxt.anchor.set(0.5, 0.1);
+ self.addChild(orderTxt);
+ // Sauce icons
+ self.sauceIcons = [];
+ for (var i = 0; i < self.sauces.length; i++) {
+ var s = self.sauces[i];
+ var icon = self.attachAsset(s, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -60 + i * 60,
+ y: 80,
+ alpha: 0.5
+ });
+ icon.width = 60;
+ icon.height = 60;
+ icon.sauce = s;
+ self.sauceIcons.push(icon);
+ }
+ // Delivery button
+ var deliverBtn = self.attachAsset('deliver', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: 120,
+ alpha: 0.7
+ });
+ deliverBtn.width = 100;
+ deliverBtn.height = 60;
+ // Add corn to order area
+ self.addCorn = function (n) {
+ self.cornCount += n;
+ cornAsset.alpha = 1;
+ LK.effects.flashObject(cornAsset, 0xffb347, 200);
+ self.updateOrderText();
+ };
+ self.removeCorn = function (n) {
+ if (self.cornCount >= n) {
+ self.cornCount -= n;
+ if (self.cornCount === 0) cornAsset.alpha = 0;
+ self.updateOrderText();
+ return true;
+ }
+ return false;
+ };
+ self.updateOrderText = function () {
+ if (!self.currentOrder) {
+ orderTxt.setText('');
+ return;
+ }
+ var txt = 'Sipariş: ';
+ for (var i = 0; i < self.currentOrder.sauces.length; i++) {
+ txt += self.currentOrder.sauces[i];
+ if (i < self.currentOrder.sauces.length - 1) txt += ', ';
+ }
+ orderTxt.setText(txt);
+ };
+ self.newOrder = function () {
+ // Random sauces (1-3)
+ var n = 1 + Math.floor(Math.random() * self.sauces.length);
+ var sauces = [];
+ var used = {};
+ while (sauces.length < n) {
+ var idx = Math.floor(Math.random() * self.sauces.length);
+ var s = self.sauces[idx];
+ if (!used[s]) {
+ sauces.push(s);
+ used[s] = true;
+ }
+ }
+ self.currentOrder = {
+ sauces: sauces
+ };
+ self.selectedSauces = [];
+ self.updateOrderText();
+ for (var i = 0; i < self.sauceIcons.length; i++) {
+ self.sauceIcons[i].alpha = 0.5;
+ }
+ };
+ // Sauce selection
+ self.sauceDown = function (sauce) {
+ if (!self.currentOrder) return;
+ if (self.selectedSauces.length >= self.currentOrder.sauces.length) return;
+ if (self.selectedSauces.indexOf(sauce) !== -1) return;
+ self.selectedSauces.push(sauce);
+ for (var i = 0; i < self.sauceIcons.length; i++) {
+ if (self.sauceIcons[i].sauce === sauce) {
+ self.sauceIcons[i].alpha = 1;
+ }
+ }
+ };
+ // Deliver order
+ self.deliver = function () {
+ if (!self.currentOrder) return;
+ if (self.cornCount < 1) return;
+ // Check sauces
+ var ok = true;
+ for (var i = 0; i < self.currentOrder.sauces.length; i++) {
+ if (self.selectedSauces.indexOf(self.currentOrder.sauces[i]) === -1) {
+ ok = false;
+ break;
+ }
+ }
+ if (ok && self.selectedSauces.length === self.currentOrder.sauces.length) {
+ // Success
+ self.removeCorn(1);
+ LK.effects.flashObject(orderAsset, 0x00ff00, 400);
+ game.coins += game.orderReward;
+ game.updateCoins();
+ self.currentOrder = null;
+ self.selectedSauces = [];
+ LK.setTimeout(function () {
+ self.newOrder();
+ }, 800);
+ } else {
+ // Wrong sauces
+ LK.effects.flashObject(orderAsset, 0xff0000, 400);
+ self.selectedSauces = [];
+ for (var i = 0; i < self.sauceIcons.length; i++) {
+ self.sauceIcons[i].alpha = 0.5;
+ }
+ }
+ };
+ // Event handling
+ self.down = function (x, y, obj) {
+ // Check if sauce icon tapped
+ for (var i = 0; i < self.sauceIcons.length; i++) {
+ var icon = self.sauceIcons[i];
+ if (icon.containsPoint({
+ x: x - self.x,
+ y: y - self.y
+ })) {
+ self.sauceDown(icon.sauce);
+ return;
+ }
+ }
+ // Check if deliver button tapped
+ if (deliverBtn.containsPoint({
+ x: x - self.x,
+ y: y - self.y
+ })) {
+ self.deliver();
+ return;
+ }
+ };
+ self.getGlobalCenter = function () {
+ var pos = self.toGlobal({
+ x: 0,
+ y: 0
+ });
+ return {
+ x: pos.x,
+ y: pos.y
+ };
+ };
+ self.reset = function () {
+ self.cornCount = 0;
+ self.currentOrder = null;
+ self.selectedSauces = [];
+ cornAsset.alpha = 0;
+ self.updateOrderText();
+ for (var i = 0; i < self.sauceIcons.length; i++) {
+ self.sauceIcons[i].alpha = 0.5;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2e7d32
+});
+
+/****
+* Game Code
+****/
+// --- Game constants ---
+game.cornGrowTime = 5000; // ms
+game.cookTime = 2000; // ms
+game.orderReward = 5;
+game.unlockCost = 20;
+game.maxFields = 16;
+// --- Game state ---
+game.coins = storage.coins || 10;
+game.unlockedFields = storage.unlockedFields || 4;
+// --- UI: Coins display ---
+var coinsTxt = new Text2(game.coins + '₺', {
+ size: 90,
+ fill: 0xFFFDE7
+});
+coinsTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(coinsTxt);
+game.updateCoins = function () {
+ coinsTxt.setText(game.coins + '₺');
+ storage.coins = game.coins;
+ storage.unlockedFields = game.unlockedFields;
+};
+// --- Field grid ---
+game.fields = [];
+var fieldRows = 2;
+var fieldCols = 2;
+var fieldSpacing = 340;
+var fieldStartX = 400;
+var fieldStartY = 600;
+function updateFieldGrid() {
+ // Determine grid size based on unlocked fields
+ var n = game.unlockedFields;
+ if (n <= 4) {
+ fieldRows = 2;
+ fieldCols = 2;
+ } else if (n <= 9) {
+ fieldRows = 3;
+ fieldCols = 3;
+ } else {
+ fieldRows = 4;
+ fieldCols = 4;
+ }
+}
+function layoutFields() {
+ updateFieldGrid();
+ for (var i = 0; i < game.maxFields; i++) {
+ var row = Math.floor(i / fieldCols);
+ var col = i % fieldCols;
+ var x = fieldStartX + col * fieldSpacing;
+ var y = fieldStartY + row * fieldSpacing;
+ game.fields[i].x = x;
+ game.fields[i].y = y;
+ }
+}
+// Create fields
+for (var i = 0; i < game.maxFields; i++) {
+ var field = new CornField();
+ field.index = i;
+ game.addChild(field);
+ game.fields.push(field);
+}
+function updateFieldLocks() {
+ for (var i = 0; i < game.maxFields; i++) {
+ if (i < game.unlockedFields) {
+ game.fields[i].setLocked(false);
+ } else {
+ game.fields[i].setLocked(true);
+ }
+ }
+}
+updateFieldLocks();
+layoutFields();
+// --- Corn Box ---
+game.cornBox = new CornBox();
+game.cornBox.x = 2048 - 300;
+game.cornBox.y = 700;
+game.addChild(game.cornBox);
+// --- Cook Area ---
+game.cookArea = new CookArea();
+game.cookArea.x = 2048 - 300;
+game.cookArea.y = 1100;
+game.addChild(game.cookArea);
+// --- Order Area ---
+game.orderArea = new OrderArea();
+game.orderArea.x = 2048 - 300;
+game.orderArea.y = 1550;
+game.addChild(game.orderArea);
+game.orderArea.newOrder();
+// --- Unlock Button ---
+var unlockBtn = LK.getAsset('unlock', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 2048 - 300,
+ y: 2000,
+ width: 200,
+ height: 100,
+ alpha: 0.8
+});
+game.addChild(unlockBtn);
+var unlockTxt = new Text2('Tarla Aç (' + game.unlockCost + '₺)', {
+ size: 50,
+ fill: "#fff"
+});
+unlockTxt.anchor.set(0.5, 0.5);
+unlockTxt.x = unlockBtn.x;
+unlockTxt.y = unlockBtn.y;
+game.addChild(unlockTxt);
+function updateUnlockBtn() {
+ if (game.unlockedFields >= game.maxFields) {
+ unlockBtn.alpha = 0.3;
+ unlockTxt.setText('Tüm Tarlalar Açık');
+ } else {
+ unlockBtn.alpha = 0.8;
+ unlockTxt.setText('Tarla Aç (' + game.unlockCost + '₺)');
+ }
+}
+updateUnlockBtn();
+// --- Touch handling ---
+game.down = function (x, y, obj) {
+ // Check unlock button
+ if (unlockBtn.containsPoint({
+ x: x,
+ y: y
+ })) {
+ if (game.coins >= game.unlockCost && game.unlockedFields < game.maxFields) {
+ game.coins -= game.unlockCost;
+ game.unlockedFields += 1;
+ game.updateCoins();
+ updateFieldLocks();
+ layoutFields();
+ updateUnlockBtn();
+ } else {
+ LK.effects.flashObject(unlockBtn, 0xff0000, 400);
+ }
+ return;
+ }
+ // Check fields
+ for (var i = 0; i < game.fields.length; i++) {
+ var f = game.fields[i];
+ if (f.containsPoint({
+ x: x,
+ y: y
+ })) {
+ f.down(x - f.x, y - f.y, obj);
+ return;
+ }
+ }
+ // Check corn box
+ if (game.cornBox.containsPoint({
+ x: x,
+ y: y
+ })) {
+ game.cornBox.down(x - game.cornBox.x, y - game.cornBox.y, obj);
+ return;
+ }
+ // Check cook area
+ if (game.cookArea.containsPoint({
+ x: x,
+ y: y
+ })) {
+ game.cookArea.down(x - game.cookArea.x, y - game.cookArea.y, obj);
+ return;
+ }
+ // Check order area
+ if (game.orderArea.containsPoint({
+ x: x,
+ y: y
+ })) {
+ game.orderArea.down(x - game.orderArea.x, y - game.orderArea.y, obj);
+ return;
+ }
+};
+// --- Game update ---
+game.update = function () {
+ // Nothing needed for now
+};
+// --- Reset function for new game ---
+game.resetGame = function () {
+ game.coins = 10;
+ game.unlockedFields = 4;
+ game.updateCoins();
+ updateFieldLocks();
+ layoutFields();
+ updateUnlockBtn();
+ for (var i = 0; i < game.fields.length; i++) {
+ game.fields[i].reset();
+ }
+ game.cornBox.reset();
+ game.cookArea.reset();
+ game.orderArea.reset();
+ game.orderArea.newOrder();
+};
+// --- Asset definitions (for static analysis) ---
+// These are not real code, but LK will auto-create these assets as used above:
+// field: green box, corn: yellow ellipse, lock: gray lock, box: brown box, cook: pot, cooked: orange ellipse, order: tray, ketchup/mayonnaise/cheese: colored circles, deliver: blue button, unlock: green button
+// --- End of code ---
\ No newline at end of file
Mısır. In-Game asset. 2d. High contrast. No shadows
Arkaplanı sil
Arkaplanı sil
Arkaplanı olmasın.
Arkaplanı sil
Tahta arkaplan. In-Game asset. 2d. High contrast. No shadows
Arkaplanı sil
Cadde arka planı. In-Game asset. 2d. High contrast. No shadows
Konuşma balonu. In-Game asset. 2d. High contrast. No shadows
Ketçap kutusu. In-Game asset. 2d. High contrast. No shadows
Mayonez kutusu. In-Game asset. 2d. High contrast. No shadows
Dökülmüş ketçap. In-Game asset. 2d. High contrast. No shadows
Dökülmüş mayonez. In-Game asset. 2d. High contrast. No shadows
Delete hand
Türkiye bayrağı. In-Game asset. 2d. High contrast. No shadows
İngiliz bayrağı. In-Game asset. 2d. High contrast. No shadows
Fransa bayrağı. In-Game asset. 2d. High contrast. No shadows