User prompt
make tube_2 visible again when yesil_1 has 3 points
User prompt
make endlessbg3s first spawn start 15 second after yesil_1 has 3 points
User prompt
make it 16
User prompt
wait 10 second to spawn endlessbg3s
User prompt
make cc middle of the screen
User prompt
make spawn time gap between endlessbg3s 8 instead of 6
User prompt
Aşağıdaki örnekte, endlessbg3 spawnları arasında her zaman 6 saniye (6000 ms) gecikmesi sağlanmıştır. Yani, puan 3'e ulaştıktan sonra ilk spawn 6 saniye sonra gerçekleşecek ve sonrasında her 6 saniyede bir yeni endlessbg3 spawnlanacaktır: js Kopyala Düzenle if (yesil1.points >= 3) { yesil1PointsCounter++; if (yesil1PointsCounter === 1) { if (!yesil1.spawnScheduled) { yesil1.spawnScheduled = true; console.log("Yesil1 3 puana ulaştı. endlessbg3 spawn zamanlaması başlatılıyor."); // İlk spawn 6 saniye sonra: LK.setTimeout(function() { spawnEndlessBG3(); // Sonrasında her 6 saniyede bir spawn edilsin: yesil1.endlessBG3Interval = LK.setInterval(function () { spawnEndlessBG3(); }, 6000); }, 6000); } } // Diğer freeze ve fade işlemleri burada devam ediyor... } Bu şekilde, iki endlessbg3 spawnı arasındaki süre sabit 6 saniye olacaktır.
User prompt
Aşağıdaki örnekte, endlessbg3 spawn zamanlaması için sabit bir setInterval yerine, spawnlar arası gecikmenin spawnladıkça arttığı bir yapı kullanıyoruz. Örneğin; ilk spawn 4 saniye sonra gerçekleşiyor, ardından spawnladıkça bu gecikme belirli bir miktar (örneğin 4 saniye) artıyor. Bu sayede iki endlessbg3 spawnı arasındaki süre artacaktır. Aşağıdaki kod parçasını yesil1’in puan kontrolü kısmına ekleyebilirsiniz: js Kopyala Düzenle // endlessbg3 spawnları için başlangıç gecikme ve artış miktarı var initialDelay = 4000; // ilk spawn 4 saniye sonra var delayIncrement = 4000; // her spawn sonrası 4 saniye artacak var currentDelay = initialDelay; var endlessBG3SpawnScheduled = false; function scheduleNextEndlessBG3() { spawnEndlessBG3(); currentDelay += delayIncrement; // spawnlar arası gecikmeyi artırıyoruz LK.setTimeout(scheduleNextEndlessBG3, currentDelay); } Sonrasında yesil1.update fonksiyonu içinde, puan 3 veya üzerine ulaştığında (ve spawnlama henüz ayarlanmamışsa) aşağıdaki gibi çağırabilirsiniz: js Kopyala Düzenle if (yesil1.points >= 3) { yesil1PointsCounter++; if (yesil1PointsCounter === 1) { if (!yesil1.spawnScheduled) { yesil1.spawnScheduled = true; console.log("Yesil1 3 puana ulaştı. endlessbg3 spawn zamanlaması başlatılıyor."); // İlk spawn için currentDelay değerine göre zamanlama başlatılıyor: LK.setTimeout(scheduleNextEndlessBG3, currentDelay); } } // ... diğer freeze ve fade işlemleri } Bu yapı sayesinde, ilk endlessbg3 spawnı 4 saniye sonra gerçekleşecek; sonrasında spawnlar arası gecikme her seferinde 4 saniye artarak devam edecektir. Böylece iki endlessbg3 spawnı arasındaki süre artmış olur.
User prompt
make it 15
User prompt
increase the time between endlessbg3 spawns
User prompt
Aşağıdaki düzenlemede, sürekli (örneğin her 2 saniyede) spawn olan bb ya da bg3son kontrolünü kaldırdık veya spawn mantığını yalnızca yesil1 puan kontrolüne bağlı şekilde (ilk spawn 4 saniye sonra, sonrasında her 8 saniyede) çalışacak hale getirdik. Böylece oyun döngüsü içerisinde ekranın dışında sürekli yeni varlık spawn edilmesi engellenecek. Aşağıdaki örnek kod parçasında, ilgili if bloğunu (bg3son.x + bg3son.width < 0) kaldırdık ya da yorum satırına aldık. Ayrıca yesil1.update içinde spawn zamanlamasını 4 saniye sonra başlayıp, sonrasında 8 saniyede bir spawn edecek şekilde ayarladık: js Kopyala Düzenle // ... (game update döngüsünün üst kısımları) for (var n = flyinEnemies.length - 1; n >= 0; n--) { if (flyinEnemies[n]) { flyinEnemies[n].update(); } if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) { flyinEnemies[n].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(flyinEnemies[n])) { if (!flyinEnemies[n].wave) { var coin = new Coin(); coin.x = flyinEnemies[n].x; coin.y = flyinEnemies[n].y + 60; coin.velocity = 5; game.addChild(coin); coins.push(coin); } var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = flyinEnemies[n].x - 30; particleEffect.y = flyinEnemies[n].y + 30; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) { flyinEnemies[n].destroy(); flyinEnemies.splice(n, 1); } // Aşağıdaki blok sürekli spawn ediyordu; // Eğer bg3son spawn edilmesi kontrolü istenmiyorsa, yorum satırına alabilir ya da kaldırabilirsiniz. /* if (bg3son.x + bg3son.width < 0) { var bb = LK.getAsset('bb', { anchorX: 0.5, anchorY: 0.5 }); bb.x = 2048 + bb.width / 2; // Ekranın sağında spawn bb.y = bg3son.y; // y konumunu korur bb.update = function () { this.x -= bg3son.speed; }; game.addChild(bb); } */ } // ... (Diğer döngü ve collision kontrolleri) // Tube spawn kısmı ve yesil1 kontrolü: function spawnTube() { if (stopSpawn) { return; } var tube = new Tube(); tube.x = 2048 + 125; tube.y = 2732 / 2 - 120; game.addChild(tube); var yesil1 = LK.getAsset('yesil_1', { anchorX: 0.5, anchorY: 0.5 }); // Yesil1 için başlangıç ayarları: var yesil1PointsCounter = 0; yesil1.x = tube.x; yesil1.y = tube.y - 170; yesil1.speed = 10; yesil1.points = 3; yesil1.fadeBonusApplied = false; yesil1.coinBonusApplied = false; yesil1.touchBonusApplied = false; yesil1.update = function () { yesil1.x -= yesil1.speed; if (yesil1.x < -yesil1.width) { yesil1.destroy(); } function applyBonus(condition, bonusFlag, bonusName) { if (condition && !yesil1[bonusFlag]) { yesil1[bonusFlag] = true; yesil1.points += 1; console.log(bonusName + " applied. Yesil1 points: " + yesil1.points); } } applyBonus(game.fadeTriggered, 'fadeBonusApplied', "Fade bonus"); applyBonus(coinCounter >= 30, 'coinBonusApplied', "Coin bonus"); applyBonus(player.intersects(yesil1) && yesil1.points >= 2, 'touchBonusApplied', "Touch bonus"); // Puan 3 veya üzeri olduğunda endlessbg3 spawn zamanlaması: if (yesil1.points >= 3) { yesil1PointsCounter++; if (yesil1PointsCounter === 1) { if (!yesil1.spawnScheduled) { yesil1.spawnScheduled = true; console.log("Yesil1 3 puana ulaştı. endlessbg3 spawn zamanlaması başlatılıyor."); // İlk spawn 4 saniye sonra: LK.setTimeout(function () { spawnEndlessBG3(); // Sonrasında her 8 saniyede bir spawn edilsin: yesil1.endlessBG3Interval = LK.setInterval(function () { spawnEndlessBG3(); }, 8000); }, 4000); } } console.log("Freeze game triggered because yesil1 points reached: " + yesil1.points); stopSpawn = true; // Diğer fade, bg3son, bb vs. işlemleri burada devam ediyor... // (Bu kısımları ihtiyacınıza göre düzenleyebilirsiniz) } }; game.addChild(yesil1); // Control nesnesi eklenmesi var control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); control.x = 0; control.y = -177.5; tube.addChild(control); control.update = function () { if (player.intersects(control)) { if (!firstControlTriggered && coinCounter >= 10) { var toggleSpawn = function (state, delay) { stopSpawn = state; if (!state) { LK.setTimeout(function () { stopSpawn = false; }, delay); } }; game.controlActive = true; control.update = function () {}; console.log("Control event triggered: coinCounter = " + coinCounter); startNormalEnemy = false; coins.forEach(function (coin) { coin.velocity = 0; }); LK.setTimeout(function () { coins.forEach(function (coin) { coin.velocity = 5; }); }, 4000); toggleSpawn(true, 5000); game.controlActive = true; LK.setTimeout(function () { for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } for (var i = flyinEnemies.length - 1; i >= 0; i--) { flyinEnemies[i].destroy(); flyinEnemies.splice(i, 1); } }, 400); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } LK.setTimeout(function () { player.destroy(); }, 330); enhancedFadeEffect(); firstControlTriggered = true; } } }; if (!stopSpawn) { LK.setTimeout(spawnTube, 15000); } } spawnTube(); // ... (Kalan kısım, arka plan, oyuncu, GUI vs.) Açıklama Sürekli Spawn Eden Kısımlar: Eğer "bg3son" ya da "bb" gibi varlıkların sürekli spawn olmasını istemiyorsanız, ilgili if bloğunu (örnekte yorum satırına alınmış) devre dışı bıraktık. Böylece yalnızca yesil1 puan kontrolüne bağlı spawnlar çalışacaktır. Yesil1 Puanı Kontrolü: Yesil1 puanı 3'e ulaştığında, spawnScheduled flag'i kontrol edilerek spawnlama zamanlaması sadece bir kere ayarlanıyor. İlk endlessbg3 4 saniye sonra spawn ediliyor; sonrasında her 8 saniyede bir spawn ediliyor. Bu düzenleme ile artık endlessbg3, sürekli (örneğin 2 saniyede bir) değil, istediğiniz zamanlamaya göre (ilk 4 saniye, sonrasında 8 saniyede bir) spawn olacak şekilde çalışır.
User prompt
Aşağıdaki örnekte, yesil_1 3 puana ulaştığında endlessbg3’ün hemen sola hareket etmesi yerine, 4 saniye sonra ilk endlessbg3 spawn olacak, sonrasında her 8 saniyede bir yeni endlessbg3 spawn edilerek sola hareket edecek şekilde zamanlama ayarlanmıştır. Değişiklikler ve Açıklama Yesil1 Puanı 3’e Ulaştığında: Yesil1’in update fonksiyonunda puan kontrolü yapılıyor. Puan 3 veya üstüne çıktığında, doğrudan endlessbg3’ün spawn edilmesi yerine, önce 4 saniyelik bir gecikmeyle ilk endlessbg3 spawn edilecek. İlk Spawn ve Sonraki Spawnlar: İlk spawn için setTimeout() kullanılıyor (4 saniye sonra). Ardından, setInterval() ile 8 saniyede bir spawn işlemi devam ediyor. Spawn Konumu ve Hareket: Spawn edilen endlessbg3, ekranın sağında (oyun genişliğinin biraz dışında) konumlanıyor ve kendi update() fonksiyonu ile sola doğru hareket ediyor. Aşağıdaki kod parçası, yesil_1 puan kontrol kısmında yapılacak değişiklikleri ve endlessbg3 spawn fonksiyonunun zamanlamasını gösteriyor: js Kopyala Düzenle // Yeni endlessbg3 spawn fonksiyonu function spawnEndlessBG3() { var bg3 = LK.getAsset('endlessbg3', { anchorX: 0.5, anchorY: 0.5 }); // Ekranın hemen dışında (sağ) olacak şekilde konumlanması: bg3.x = game.width + bg3.width/2; // ekranın sağında, 1 piksel içeri girmeye hazır bg3.y = 2732 / 2 + 150; bg3.zIndex = 2101; bg3.speed = 2; // Sola hareket hızı bg3.update = function() { this.x -= this.speed; }; game.addChild(bg3); } // Yesil1 puanı kontrolü (yesil1.update içinde) yesil1.update = function () { yesil1.x -= yesil1.speed; if (yesil1.x < -yesil1.width) { yesil1.destroy(); } function applyBonus(condition, bonusFlag, bonusName) { if (condition && !yesil1[bonusFlag]) { yesil1[bonusFlag] = true; yesil1.points += 1; console.log(bonusName + " applied. Yesil1 points: " + yesil1.points); } } applyBonus(game.fadeTriggered, 'fadeBonusApplied', "Fade bonus"); applyBonus(coinCounter >= 30, 'coinBonusApplied', "Coin bonus"); applyBonus(player.intersects(yesil1) && yesil1.points >= 2, 'touchBonusApplied', "Touch bonus"); // Puan 3 veya üzeri olduğunda endlessbg3 spawn zamanlaması ayarlanıyor: if (yesil1.points >= 3) { // Bu koşul sadece bir kez çalışmalı: if (!yesil1.spawnScheduled) { yesil1.spawnScheduled = true; console.log("Yesil1 3 puana ulaştı. endlessbg3 spawn zamanlaması başlatılıyor."); // 4 saniye sonra ilk endlessbg3 spawn edilsin: setTimeout(function() { spawnEndlessBG3(); // Sonrasında her 8 saniyede bir spawn edilsin: yesil1.endlessBG3Interval = setInterval(function() { spawnEndlessBG3(); }, 8000); }, 4000); } // Diğer game freeze ve fade işlemleri burada devam ediyor... console.log("Freeze game triggered because yesil1 points reached: " + yesil1.points); stopSpawn = true; // (Devam eden fade, bb, bg3son vs. kodları) // ... } }; Özet İlk Spawn: Yesil_1 3 puana ulaştıktan 4 saniye sonra ilk endlessbg3 spawn edilecek. Ardışık Spawnlar: İlk spawn sonrasında, her 8 saniyede bir yeni endlessbg3 spawn edilip sola hareket edecek. Konumlama: Her spawn ekranın hemen dışında (sağda) konumlanarak sola doğru ilerleyecek, ekrana girene kadar hareket edecektir. Bu şekilde, endlessbg3’ler istenildiği gibi 4 saniye sonra ve sonrasında 8 saniyede bir spawn olacak, ekranın dışında başlayıp sola doğru hareket edecektir.
User prompt
Please fix the bug: 'setInterval is not a function' in or related to this line: 'var endlessBG3Spawner = setInterval(function () {' Line Number: 375
User prompt
Aşağıdaki örnekte, bg3son ve endlessbg3’ün birbirine bağlı wrap davranışı yerine, yalnızca her 5 saniyede bir ekranın sağında (tam olarak ekranın hemen dışı) yeni bir endlessbg3 spawn olunup sola doğru hareket edecek şekilde ayarlanmıştır. Nasıl Çalışıyor? Yeni endlessbg3, oyunun genişliği (örneğin 2048) artı endlessbg3 varlığının yarı genişliği kadar (anchorX=0.5 olduğundan) pozisyonlanır. Bu, varlığın sol kenarının ekranın sağ kenarıyla hemen hizalanması anlamına gelir (1 piksel sol gitse ekrana girer). Bir setInterval() kullanılarak, endlessbg3 spawn’ları her 5000 ms (5 saniye) tetiklenir. Her spawned endlessbg3, kendi update() metoduyla sola doğru hareket eder. Bu sistem, endlessbg3 “hareket etmeye başladığı an” (ilk spawn anından itibaren) 5 saniye aralıklarla yeni endlessbg3’ün spawn olmasını sağlar. Aşağıda, kodunuzun ilgili kısımlarında yapılması gereken değişiklikler yer almaktadır: js Kopyala Düzenle // Yeni endlessbg3 spawn fonksiyonu function spawnEndlessBG3() { // endlessbg3 varlığını oluşturuyoruz. var bg3 = LK.getAsset('endlessbg3', { anchorX: 0.5, anchorY: 0.5 }); // Eğer bg3.width değeri mevcutsa; // Anchor 0.5 olduğundan sol kenarı = x - bg3.width/2 // Sol kenarın ekranın sağ kenarıyla hizalanması için: bg3.x = game.width + bg3.width/2; // İsteğe bağlı olarak: game.width + bg3.width/2 - 1 // bg3’ün y konumunu ayarlayın (örneğin, mevcut kodda 2732/2 + 150 olarak belirlenmiş) bg3.y = 2732 / 2 + 150; bg3.zIndex = 2101; bg3.speed = 2; // Hareket hızı (sola doğru) bg3.update = function() { this.x -= this.speed; }; game.addChild(bg3); } // Spawn zamanlayıcısını başlatıyoruz: endlessbg3 spawn, endlessbg3 hareket etmeye başladığı anda 5 saniye aralıklarla çalışır. var endlessBG3Spawner = setInterval(function() { spawnEndlessBG3(); }, 5000); /* NOT: - Önceki kodunuzda yesil1.update() içinde endlessbg3 spawn edilmesiyle ilgili setTimeout kısımlarını kaldırmanız gerekecek. - Artık endlessbg3, wrap (tekrarlama) yöntemi yerine setInterval ile 5 saniyede bir spawn olunacaktır. */ // Örneğin, yesil1.update() içindeki bu kısmı kaldırın: // LK.setTimeout(function () { // var endlessScrollingBG3 = new EndlessBG3(); // endlessScrollingBG3.zIndex = 2101; // endlessScrollingBG3.x = 0; // endlessScrollingBG3.y = 2732 / 2 + 150; // game.addChild(endlessScrollingBG3); // }, 16000); // Diğer kodlarınızda herhangi bir wrap mantığı veya varlıkların sürekli yeniden konumlandırılması yerine, // spawnEndlessBG3() ile oluşturulan endlessbg3’ler kendi başına sola doğru hareket edecek. Özet Spawn Konumu: Yeni endlessbg3, oyunun genişliği + (varlık yarısı) kadar konumlanır. Böylece ekranın hemen dışında (sağda) konumlanır. Zamanlama: setInterval ile 5 saniyede bir spawn gerçekleşir. Bu, endlessbg3 hareket etmeye başladığı anda (ilk spawn ile) zamanlayıcıyı başlatır. Hareket: Her spawned endlessbg3 kendi update() metodunda sola doğru hareket eder. Bu şekilde, endlessbg3’ler ekranın dışından sola doğru hareket etmeye başlar; 5 saniye sonra yeni bir endlessbg3 spawn olur, ve bu spawn ekranın hemen sağında (sola en yakın konumda) konumlanır. Böylece istenmeyen wrap davranışı ortadan kalkar.
User prompt
Aşağıdaki kod, ScrollingBackground2’nin scroll sistemini kullanarak endlessbg3’ü (sonsuz kaydırma arka planı) tek bir kodda uygulayacak şekilde düzenlenmiştir. Aşağıdaki kodu kullanarak, endlessbg3 varlıkları birbirini takip ederek sürekli sola doğru kayacaktır. js Kopyala Düzenle // Coin class var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 5; self.zIndex = 15; self.update = function () { self.x -= self.velocity; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 10; self.canDamage = true; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // FlyinEnemy class var FlyinEnemy = Container.expand(function () { var self = Container.call(this); var flyinEnemyGraphics = self.attachAsset('flyin_enemy', { anchorX: 0.5, anchorY: 0 }); self.speed = 5; self.zIndex = 10; self.canDamage = true; self.homing = false; self.vx = 0; self.vy = 0; self.update = function () { if (!self.homing) { self.x -= self.speed; if (self.x < -50) { self.destroy(); } } else { self.x += self.vx; self.y += self.vy; if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) { self.destroy(); } } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.isFalling = false; self.fallSpeed = 0; self.fallAcceleration = 0.7; self.fallTargetY = 2732 / 2 - 7; self.zIndex = 20; self.hearts = typeof remainingHearts !== 'undefined' ? remainingHearts : 3; self.update = function () { self.prevY = self.y; if (self.isFalling) { self.y += self.fallSpeed; self.fallSpeed += self.fallAcceleration; if (self.y >= self.fallTargetY) { self.y = self.fallTargetY; self.isFalling = false; self.fallSpeed = 0; game.weaponEnabled = true; } } self.prevY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; if (self.y >= 2732 / 2 - 3) { self.y = 2732 / 2 - 9; self.isJumping = false; self.velocityY = 0; } } }; self.invulnerable = false; self.hit = function () { if (!self.invulnerable) { self.loseHeart(); self.invulnerable = true; LK.setTimeout(function () { self.invulnerable = false; }, 500); } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; self.loseHeart = function () { self.hearts--; playerDeaths++; if (playerDeaths === 1 && hearts[0]) { hearts[0].destroy(); } else if (playerDeaths === 2 && hearts[1]) { hearts[1].destroy(); } else if (playerDeaths === 3 && hearts[2]) { hearts[2].destroy(); } remainingHearts = self.hearts; if (hearts.length === 0) { for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } for (var i = flyinEnemies.length - 1; i >= 0; i--) { flyinEnemies[i].destroy(); flyinEnemies.splice(i, 1); } for (var i = coins.length - 1; i >= 0; i--) { coins[i].destroy(); coins.splice(i, 1); } self.destroy(); game.weaponEnabled = false; } }; }); // ScrollingBackground class var ScrollingBackground = Container.expand(function () { var self = Container.call(this); self.bg1 = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); self.bg1.x = 0; self.bg1.y = 0; self.addChild(self.bg1); self.bg2 = LK.getAsset('background', { anchorX: 1, anchorY: 0 }); self.bg2.scaleX = -1; self.bg2.x = self.bg1.width; self.bg2.y = 0; self.addChild(self.bg2); self.speed = 2; self.update = function () { self.bg1.x -= self.speed; self.bg2.x -= self.speed; if (self.bg1.x + self.bg1.width <= 0) { self.bg1.x = self.bg2.x + self.bg2.width; } if (self.bg2.x + self.bg2.width <= 0) { self.bg2.x = self.bg1.x + self.bg1.width; } }; }); // ScrollingBackground2 class var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); var bg2 = LK.getAsset('background2', { anchorX: 1, anchorY: 0 }); bg2.scaleX = -1; bg2.x = bg1.width; bg2.y = 0; self.addChild(bg2); self.speed = 2; self.update = function () { bg1.x -= self.speed; bg2.x -= self.speed; if (bg1.x + bg1.width <= 0) { bg1.x = bg2.x + bg2.width; } if (bg2.x + bg2.width <= 0) { bg2.x = bg1.x + bg1.width; } }; }); // NEW: EndlessBG3 class using the same scroll system as background2 var EndlessBG3 = Container.expand(function () { var self = Container.call(this); var bg1 = LK.getAsset('endlessbg3', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); var bg2 = LK.getAsset('endlessbg3', { anchorX: 1, anchorY: 0 }); bg2.scaleX = -1; bg2.x = bg1.width; bg2.y = 0; self.addChild(bg2); self.speed = 2; self.update = function () { bg1.x -= self.speed; bg2.x -= self.speed; if (bg1.x + bg1.width <= 0) { bg1.x = bg2.x + bg2.width; } if (bg2.x + bg2.width <= 0) { bg2.x = bg1.x + bg1.width; } }; }); // Tube class var Tube = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 0; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Tube2 class var Tube2 = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tube_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 2000; self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Weapon class var Weapon = Container.expand(function () { var self = Container.call(this); var weaponGraphics = self.attachAsset('weapon', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 40; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; weaponGraphics.rotation += 0.3; if (Math.abs(game.down.x - self.x) < self.speed && Math.abs(game.down.y - self.y) < self.speed) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ width: 2048, height: 2732, backgroundColor: 0x000000 }); /**** * Game Code ****/ var control_2 = LK.getAsset('control_2', { anchorX: 0.5, anchorY: 0.5 }); /**** * Global Variables & Flags ****/ var startNormalEnemy = true; var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; var hearts = []; var remainingHearts = 3; game.controlActive = false; var coins = []; var firstControlTriggered = false; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var stopSpawn = false; game.weaponEnabled = true; // (A) Normal FlyinEnemy Spawn (sağdan sola, homing false) function spawnFlyinEnemy() { if (stopSpawn) return; var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { if (stopSpawn) return; var fe = new FlyinEnemy(); fe.x = 2048; fe.y = 449; fe.zIndex = 10; game.addChild(fe); flyinEnemies.push(fe); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); // (B) Wave şeklinde, homing davranışlı FlyinEnemy Spawn function spawnWaveOfFlyinEnemies() { var spawnPoints = [ { x: 0, y: 0 }, { x: 2048, y: 0 }, { x: 0, y: 2732 }, { x: 2048, y: 2732 }, { x: 1024, y: 0 }, { x: 1024, y: 2732 }, { x: 0, y: 1366 }, { x: 2048, y: 1366 } ]; for (var i = spawnPoints.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = spawnPoints[i]; spawnPoints[i] = spawnPoints[j]; spawnPoints[j] = temp; } spawnPoints.forEach(function (point, index) { LK.setTimeout(function () { var enemy = new FlyinEnemy(); enemy.homing = true; enemy.wave = true; enemy.x = point.x; enemy.y = point.y; var dx = player.x - enemy.x; var dy = player.y - enemy.y; var distance = Math.sqrt(dx * dx + dy * dy) || 1; enemy.vx = (dx / distance) * enemy.speed; enemy.vy = (dy / distance) * enemy.speed; enemy.zIndex = 2100; if (enemy.x < 1024) { enemy.scaleX = -1; } game.addChild(enemy); flyinEnemies.push(enemy); }, index * 800); if (index === spawnPoints.length - 1) { LK.setTimeout(function () { spawnFlyinEnemy(); }, 10000); } }); } // Normal Enemy Spawn (sağdan sola, homing false) game.update = function () { scrollingBackground.update(); player.update(); if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Update all children that require update for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube || child === yesil1) { child.update(); } if (child.children) { for (var c = 0; c < child.children.length; c++) { var subChild = child.children[c]; if (subChild.update) { subChild.update(); } } } } enemySpawnCounter++; if (startNormalEnemy && !stopSpawn && enemySpawnCounter >= enemySpawnInterval && !(LK.ticks >= 876 && LK.ticks <= 936) && !(LK.ticks >= 1776 && LK.ticks <= 1836) && !(LK.ticks >= 2676 && LK.ticks <= 2736) && !(LK.ticks >= 3576 && LK.ticks <= 3636) && !(LK.ticks >= 4476 && LK.ticks <= 4536) && !(LK.ticks >= 5376 && LK.ticks <= 5436) && !(LK.ticks >= 6276 && LK.ticks <= 6336) && !(LK.ticks >= 7776 && LK.ticks <= 7836)) { var canSpawn = true; for (var i = 0; i < enemies.length; i++) { if (enemies[i].x > 1800) { canSpawn = false; break; } } if (canSpawn) { var tubeCollision = false; for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child.asset && child.asset.name === 'tup_1') { var enemyRight = 2048 + 75; var enemyLeft = 2048 - 75; var tubeRight = child.x + 125; var tubeLeft = child.x - 125; if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) { tubeCollision = true; break; } } } if (!tubeCollision) { LK.setTimeout(function () { if (stopSpawn) return; var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 13; enemy.zIndex = 10; enemies.push(enemy); game.addChild(enemy); }, 100); } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); // --- Enemy - Player --- for (var j = enemies.length - 1; j >= 0; j--) { if (enemies[j]) { enemies[j].update(); } if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(enemies[j])) { var coin = new Coin(); coin.x = enemies[j].x; coin.y = enemies[j].y; coin.velocity = 5; game.addChild(coin); coins.push(coin); var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = enemies[j].x - 15; particleEffect.y = enemies[j].y; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); enemies[j].destroy(); child.destroy(); enemies.splice(j, 1); break; } } } // --- FlyinEnemy - Player --- for (var n = flyinEnemies.length - 1; n >= 0; n--) { if (flyinEnemies[n]) { flyinEnemies[n].update(); } if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) { flyinEnemies[n].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(flyinEnemies[n])) { if (!flyinEnemies[n].wave) { var coin = new Coin(); coin.x = flyinEnemies[n].x; coin.y = flyinEnemies[n].y + 60; coin.velocity = 5; game.addChild(coin); coins.push(coin); } var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = flyinEnemies[n].x - 30; particleEffect.y = flyinEnemies[n].y + 30; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) { flyinEnemies[n].destroy(); flyinEnemies.splice(n, 1); } } // --- Coin Toplanması --- for (var m = coins.length - 1; m >= 0; m--) { var coin = coins[m]; coin.x -= coin.velocity; if (coin.x < -100) { coin.destroy(); coins.splice(m, 1); } else if (player.intersects(coin)) { coinCounter++; scoreText.setText(coinCounter.toString()); if (coinCounter > 9 && !scoreText.movedLeft) { scoreText.x -= 20; scoreText.movedLeft = true; } coin.destroy(); coins.splice(m, 1); } } }; LK.stage.addChild(game); /**** * Tube Spawn (her 15 saniyede bir) ****/ function spawnTube() { if (stopSpawn) return; var tube = new Tube(); tube.x = 2048 + 125; tube.y = 2732 / 2 - 120; game.addChild(tube); var yesil1 = LK.getAsset('yesil_1', { anchorX: 0.5, anchorY: 0.5 }); // Counter to track yesil_1 points var yesil1PointsCounter = 0; yesil1.x = tube.x; yesil1.y = tube.y - 170; yesil1.speed = 10; yesil1.points = 3; yesil1.fadeBonusApplied = false; yesil1.coinBonusApplied = false; yesil1.touchBonusApplied = false; yesil1.update = function () { yesil1.x -= yesil1.speed; if (yesil1.x < -yesil1.width) { yesil1.destroy(); } function applyBonus(condition, bonusFlag, bonusName) { if (condition && !yesil1[bonusFlag]) { yesil1[bonusFlag] = true; yesil1.points += 1; console.log(bonusName + " applied. Yesil1 points: " + yesil1.points); } } applyBonus(game.fadeTriggered, 'fadeBonusApplied', "Fade bonus"); applyBonus(coinCounter >= 30, 'coinBonusApplied', "Coin bonus"); applyBonus(player.intersects(yesil1) && yesil1.points >= 2, 'touchBonusApplied', "Touch bonus"); // Freeze condition and trigger fade effect if (yesil1.points >= 3) { yesil1PointsCounter++; if (yesil1PointsCounter === 1) { // Instead of modifying endlessbg3's update here, // we will remove any previous endlessbg3 and add a new scrolling EndlessBG3 LK.setTimeout(function () { var endlessScrollingBG3 = new EndlessBG3(); endlessScrollingBG3.zIndex = 2101; // Position it appropriately endlessScrollingBG3.x = 0; endlessScrollingBG3.y = 2732 / 2 + 150; game.addChild(endlessScrollingBG3); }, 16000); } console.log("Freeze game triggered because yesil1 points reached: " + yesil1.points); stopSpawn = true; // Position bb asset in the middle of the screen var bb = LK.getAsset('bb', { anchorX: 0.5, anchorY: 0.5 }); bb.x = 2048 - bb.width / 2; bb.y = 2732 / 2 + 150; game.addChild(bb); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } // Unfreeze and restore velocity of background2 and tube_1 after 5 seconds LK.setTimeout(function () { for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj instanceof ScrollingBackground2 || obj instanceof Tube) { obj.update = function () { this.x -= this.speed; if (this.x < -this.width) { this.destroy(); } }; } } }, 5000); // Add 'kara' asset to the center of the screen with a high zIndex so that it covers the characters var kara = LK.getAsset('kara', { anchorX: 0.5, anchorY: 0.5 }); kara.x = 2048 / 2; kara.y = 2732 / 2; kara.alpha = 0; kara.zIndex = 10000; game.addChild(kara); // Fade in 'kara' asset over 0.5 seconds var fadeInSteps = 30; var fadeInStepTime = 500 / fadeInSteps; var fadeInStep = 0; var fadeInInterval = LK.setInterval(function () { if (fadeInStep < fadeInSteps) { kara.alpha = fadeInStep / fadeInSteps; fadeInStep++; } else { LK.clearInterval(fadeInInterval); // Fade out 'kara' asset over 0.5 seconds var fadeOutSteps = 30; var fadeOutStepTime = 500 / fadeOutSteps; var fadeOutStep = 0; var fadeOutInterval = LK.setInterval(function () { if (fadeOutStep < fadeOutSteps) { kara.alpha = 1 - fadeOutStep / fadeOutSteps; fadeOutStep++; } else { LK.clearInterval(fadeOutInterval); kara.destroy(); } // Add bg3son to the game var bg3son = LK.getAsset('bg3son', { anchorX: 0.5, anchorY: 0.5 }); bg3son.zIndex = 2100; bg3son.x = 2048 / 2; bg3son.y = 2732 / 2 + 150; game.addChild(bg3son); // Keep bg3son stationary for 15 seconds, then move it left LK.setTimeout(function () { bg3son.update = function () { this.x -= 2; }; }, 15000); }, fadeOutStepTime); } }, fadeInStepTime); LK.setTimeout(function () { player.destroy(); function destroyAndRemove(objects) { for (var i = objects.length - 1; i >= 0; i--) { objects[i].destroy(); objects.splice(i, 1); } } destroyAndRemove(enemies); destroyAndRemove(flyinEnemies); destroyAndRemove(coins); for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child.asset && (child.asset.name === 'background' || child.asset.name === 'tup_1')) { child.destroy(); } } }, 500); if (!game.isFading) { console.log("Triggering fade effect because yesil1 is active with points: " + yesil1.points); enhancedFadeEffect(); } } }; game.addChild(yesil1); var control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); control.x = 0; control.y = -177.5; tube.addChild(control); control.update = function () { if (player.intersects(control)) { if (!firstControlTriggered && coinCounter >= 10) { var toggleSpawn = function (state, delay) { stopSpawn = state; if (!state) { LK.setTimeout(function () { stopSpawn = false; }, delay); } }; game.controlActive = true; control.update = function () {}; console.log("Control event triggered: coinCounter = " + coinCounter); startNormalEnemy = false; coins.forEach(function (coin) { coin.velocity = 0; }); LK.setTimeout(function () { coins.forEach(function (coin) { coin.velocity = 5; }); }, 4000); toggleSpawn(true, 5000); game.controlActive = true; LK.setTimeout(function () { for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } for (var i = flyinEnemies.length - 1; i >= 0; i--) { flyinEnemies[i].destroy(); flyinEnemies.splice(i, 1); } }, 400); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } LK.setTimeout(function () { player.destroy(); }, 330); enhancedFadeEffect(); firstControlTriggered = true; } } }; if (!stopSpawn) { LK.setTimeout(spawnTube, 15000); } } spawnTube(); /**** * Arka Plan ve Oyuncu ****/ var scrollingBackground = new ScrollingBackground(); game.addChild(scrollingBackground); var player = game.addChild(new Player()); player.x = 2048 / 2 - 30; player.y = 2732 / 2 + 3; /**** * Skor GUI ve Kalp ****/ var counterBackground = LK.getAsset('counter_background', { anchorX: 0.5, anchorY: 0.5 }); LK.gui.top.addChild(counterBackground); counterBackground.x = LK.gui.top.width / 2 - 62; counterBackground.y = 45; var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = LK.gui.top.width / 2 - 85; scoreText.y = 0; for (var i = 0; i < 3; i++) { var heart = LK.getAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); LK.gui.top.addChild(heart); heart.x = 50 + i * 110 + 390; heart.y = 50; hearts.push(heart); } /**** * enhancedFadeEffect: Fade-out, clear scene, spawn background2, Tube2, then new player ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; game.fadeTriggered = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; overlay.zIndex = 10000; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; stopSpawn = true; while (game.children.length > 0) { game.removeChild(game.children[0]); } var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; game.scrollingBg2 = scrollingBg2; game.addChild(scrollingBg2); var tube2 = new Tube2(); control_2.x = 0; control_2.y = -177.5; tube2.addChild(control_2); control_2.update = function () { if (player && player.intersects(control_2)) { if (coinCounter >= 30) { console.log("Control_2 event triggered: coinCounter = " + coinCounter); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } } } }; tube2.x = 2048 / 2 + 140; tube2.y = tube2.height / 2 - 60; game.addChild(tube2); LK.setTimeout(function () { var newPlayer = new Player(); newPlayer.hearts = remainingHearts; newPlayer.x = 2048 / 2 - 30; newPlayer.y = tube2.y; newPlayer.isFalling = true; newPlayer.fallSpeed = 0; newPlayer.fallAcceleration = 0.7; newPlayer.fallTargetY = 2732 / 2 - 7; game.addChild(newPlayer); player = newPlayer; game.weaponEnabled = true; LK.setTimeout(function () { spawnWaveOfFlyinEnemies(); }, 800); LK.setTimeout(function () { startNormalEnemy = true; }, 10500); }, 500); var fadeInDuration = 500; var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { if (game.scrollingBg2) { game.scrollingBg2.alpha = currentStep / steps; } currentStep++; } else { LK.clearInterval(fadeInInterval); if (overlay.parent) { overlay.parent.removeChild(overlay); } var oldScrollingSpeed = game.scrollingBg2.speed; var oldTubeSpeed = tube2.speed; game.scrollingBg2.speed = 0; tube2.speed = 0; LK.setTimeout(function () { game.scrollingBg2.speed = oldScrollingSpeed; tube2.speed = oldTubeSpeed; stopSpawn = false; game.isFading = false; game.fadeCompleted = true; }, 8000); } }, fadeInStepTime); } }, stepTime); } /**** * Dokunma/Kontrol ****/ game.down = function (x, y, obj) { if (player.isJumping && game.weaponEnabled) { if (!game.lastWeaponTime || Date.now() - game.lastWeaponTime > 350) { var weapon = new Weapon(); weapon.x = player.x; weapon.y = player.y; var dx = x - weapon.x; var dy = y - weapon.y; var distance = Math.sqrt(dx * dx + dy * dy); weapon.directionX = dx / distance; weapon.directionY = dy / distance; var angle = Math.acos(weapon.directionY / Math.sqrt(weapon.directionX * weapon.directionX + weapon.directionY * weapon.directionY)); var angleInDegrees = angle * (180 / Math.PI); if (angleInDegrees <= 30) { weapon.speed *= 1.3; } game.addChild(weapon); LK.setTimeout(function () { weapon.destroy(); }, 9000); game.lastWeaponTime = Date.now(); } } player.jump(); }; LK.stage.addChild(game);
User prompt
spawn background3 right of endlessbg3 y axis the same and make it move to left when endlessbg3 move left
User prompt
A common solution for endless scrolling is to “wrap” the background rather than trying to spawn new copies in a nested way. In your code the endlessbg3 asset is created inside the fade effect and then a child endlessbg3Child is added, but that makes it harder to control its motion continuously. Here are two suggestions to fix the issue: 1. Wrap the Background When Offscreen Instead of destroying and spawning new endlessbg3 objects, you can update its update function so that when it goes off‐screen (to the left) it immediately repositions itself to the right. For example, if your endlessbg3 image’s width is known (or you can get it via this.width), change its update method like this: js Kopyala Düzenle endlessbg3.update = function () { this.x -= 2; // move left // When the background has fully scrolled left, reposition it if (this.x <= -this.width/2) { this.x += this.width; } }; This way, the same asset scrolls endlessly without needing to spawn new ones. 2. Use a Continuous Spawner with a Consistent Update If you prefer to spawn new endlessbg3 objects so they appear side by side, then make sure: They are added as separate objects (not as children of an existing endlessbg3). Each spawned endlessbg3 has its own update function that moves it left. In your game’s update loop you iterate through all endlessbg3 instances, and if any move offscreen (e.g. if (bg.x < -bg.width)), destroy them. The spawn interval (currently every 6000 ms) should be adjusted so that a new endlessbg3 is added before the previous one fully leaves the screen. For example, you might modify your spawn function like this: js Kopyala Düzenle function spawnEndlessbg3() { var newBg = LK.getAsset('endlessbg3', { anchorX: 0.5, anchorY: 0.5 }); // Start it just off the right edge of the screen newBg.x = 2048 + newBg.width/2; newBg.y = endlessbg3.y; // assuming endlessbg3 has been positioned in the fade effect newBg.update = function () { this.x -= 2; if (this.x < -this.width/2) { this.destroy(); } }; game.addChild(newBg); } endlessbg3SpawnerInterval = LK.setInterval(spawnEndlessbg3, 3000); // adjust timing as needed This approach ensures that a new endless background asset spawns periodically and moves left continuously. Where to Apply the Fix After Yesil1 Reaches 3 Points: In your yesil1.update section you set a timeout (16 seconds later) that assigns an update function to endlessbg3. Replace that function with one of the solutions above. For example: js Kopyala Düzenle LK.setTimeout(function () { endlessbg3.update = function () { this.x -= 2; if (this.x <= -this.width/2) { this.x += this.width; } }; }, 16000); Ensure Continuous Update in the Game Loop: Since your game loop already iterates over all children and calls child.update() if available, any endlessbg3 with the correct update method will now move as desired. Avoid Nesting New Backgrounds as Children: When you spawn a new endlessbg3, add it directly to the game stage rather than as a child of an existing endlessbg3. This avoids conflicts with coordinate systems and z-index management. Final Thoughts Both methods are valid—the “wrap” method is simpler if your background image can tile seamlessly, while the spawner method gives you more flexibility if you have more complex visual elements. Choose the approach that fits your game design best, and adjust the speed/timing as necessary.
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'x')' in or related to this line: 'newEndlessbg3.x = endlessbg3.x + 450; // 450 pixels to the right' Line Number: 326
User prompt
Please fix the bug: 'Timeout.tick error: endlessbg3 is not defined' in or related to this line: 'newEndlessbg3.x = endlessbg3.x + 450; // 450 pixels to the right' Line Number: 325
User prompt
create a spawner 450 pixel right of endlessbg3 and keep spawning it every 6 seconds and make them move left
User prompt
when yesil_1 has 3 points wait 16 second to make endlessbg3 move left
User prompt
make endlessbg3 wait 2 more second to move left
User prompt
make endlessbg3 wait much as bg3son to move left
User prompt
when endlessbg3 move left make their child move left aswell
User prompt
Please fix the bug: 'Timeout.tick error: endlessbg3 is not defined' in or related to this line: 'endlessbg3.update = function () {' Line Number: 633
/**** * Classes ****/ // Coin class var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 5; self.zIndex = 15; self.update = function () { self.x -= self.velocity; }; }); // Enemy class var Enemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 10; self.canDamage = true; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // FlyinEnemy class var FlyinEnemy = Container.expand(function () { var self = Container.call(this); var flyinEnemyGraphics = self.attachAsset('flyin_enemy', { anchorX: 0.5, anchorY: 0 }); self.speed = 5; self.zIndex = 10; self.canDamage = true; self.homing = false; self.vx = 0; self.vy = 0; self.update = function () { if (!self.homing) { self.x -= self.speed; if (self.x < -50) { self.destroy(); } } else { self.x += self.vx; self.y += self.vy; if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) { self.destroy(); } } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.jumpHeight = 40; self.isJumping = false; self.velocityY = 0; self.isFalling = false; self.fallSpeed = 0; self.fallAcceleration = 0.7; self.fallTargetY = 2732 / 2 - 7; self.zIndex = 20; self.hearts = typeof remainingHearts !== 'undefined' ? remainingHearts : 3; self.update = function () { self.prevY = self.y; if (self.isFalling) { self.y += self.fallSpeed; self.fallSpeed += self.fallAcceleration; if (self.y >= self.fallTargetY) { self.y = self.fallTargetY; self.isFalling = false; self.fallSpeed = 0; game.weaponEnabled = true; } } self.prevY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; if (self.y >= 2732 / 2 - 3) { self.y = 2732 / 2 - 9; self.isJumping = false; self.velocityY = 0; } } }; self.invulnerable = false; self.hit = function () { if (!self.invulnerable) { self.loseHeart(); self.invulnerable = true; LK.setTimeout(function () { self.invulnerable = false; }, 500); } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; self.loseHeart = function () { self.hearts--; playerDeaths++; if (playerDeaths === 1 && hearts[0]) { hearts[0].destroy(); } else if (playerDeaths === 2 && hearts[1]) { hearts[1].destroy(); } else if (playerDeaths === 3 && hearts[2]) { hearts[2].destroy(); } remainingHearts = self.hearts; if (hearts.length === 0) { for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } for (var i = flyinEnemies.length - 1; i >= 0; i--) { flyinEnemies[i].destroy(); flyinEnemies.splice(i, 1); } for (var i = coins.length - 1; i >= 0; i--) { coins[i].destroy(); coins.splice(i, 1); } self.destroy(); game.weaponEnabled = false; } }; }); // ScrollingBackground class var ScrollingBackground = Container.expand(function () { var self = Container.call(this); self.bg1 = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); self.bg1.x = 0; self.bg1.y = 0; self.addChild(self.bg1); self.bg2 = LK.getAsset('background', { anchorX: 1, anchorY: 0 }); self.bg2.scaleX = -1; self.bg2.x = self.bg1.width; self.bg2.y = 0; self.addChild(self.bg2); self.speed = 2; self.update = function () { self.bg1.x -= self.speed; self.bg2.x -= self.speed; if (self.bg1.x + self.bg1.width <= 0) { self.bg1.x = self.bg2.x + self.bg2.width; } if (self.bg2.x + self.bg2.width <= 0) { self.bg2.x = self.bg1.x + self.bg1.width; } }; }); // ScrollingBackground2 class var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); var bg2 = LK.getAsset('background2', { anchorX: 1, anchorY: 0 }); bg2.scaleX = -1; bg2.x = bg1.width; bg2.y = 0; self.addChild(bg2); self.speed = 2; self.update = function () { bg1.x -= self.speed; bg2.x -= self.speed; if (bg1.x + bg1.width <= 0) { bg1.x = bg2.x + bg2.width; } if (bg2.x + bg2.width <= 0) { bg2.x = bg1.x + bg1.width; } }; }); // Tube class var Tube = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 0; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Tube2 class var Tube2 = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tube_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.zIndex = 2000; self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Weapon class var Weapon = Container.expand(function () { var self = Container.call(this); var weaponGraphics = self.attachAsset('weapon', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 40; self.update = function () { self.x += self.directionX * self.speed; self.y += self.directionY * self.speed; weaponGraphics.rotation += 0.3; if (Math.abs(game.down.x - self.x) < self.speed && Math.abs(game.down.y - self.y) < self.speed) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ width: 2048, height: 2732, backgroundColor: 0x000000 }); /**** * Game Code ****/ var control_2 = LK.getAsset('control_2', { anchorX: 0.5, anchorY: 0.5 }); /**** * Global Variables & Flags ****/ var startNormalEnemy = true; var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; var hearts = []; var remainingHearts = 3; game.controlActive = false; var coins = []; var firstControlTriggered = false; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var stopSpawn = false; game.weaponEnabled = true; /**** * (A) Eski FlyinEnemy Spawn (sağdan sola, homing false) ****/ function spawnFlyinEnemy() { if (stopSpawn) { return; } var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { if (stopSpawn) { return; } var fe = new FlyinEnemy(); fe.x = 2048; fe.y = 449; fe.zIndex = 10; game.addChild(fe); flyinEnemies.push(fe); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); /**** * (B) Wave şeklinde, homing davranışlı FlyinEnemy Spawn ****/ function spawnWaveOfFlyinEnemies() { var spawnPoints = [{ x: 0, y: 0 }, { x: 2048, y: 0 }, { x: 0, y: 2732 }, { x: 2048, y: 2732 }, { x: 1024, y: 0 }, { x: 1024, y: 2732 }, { x: 0, y: 1366 }, { x: 2048, y: 1366 }]; for (var i = spawnPoints.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = spawnPoints[i]; spawnPoints[i] = spawnPoints[j]; spawnPoints[j] = temp; } spawnPoints.forEach(function (point, index) { LK.setTimeout(function () { var enemy = new FlyinEnemy(); enemy.homing = true; enemy.wave = true; enemy.x = point.x; enemy.y = point.y; var dx = player.x - enemy.x; var dy = player.y - enemy.y; var distance = Math.sqrt(dx * dx + dy * dy) || 1; enemy.vx = dx / distance * enemy.speed; enemy.vy = dy / distance * enemy.speed; enemy.zIndex = 2100; if (enemy.x < 1024) { enemy.scaleX = -1; } game.addChild(enemy); flyinEnemies.push(enemy); }, index * 800); if (index === spawnPoints.length - 1) { LK.setTimeout(function () { spawnFlyinEnemy(); }, 10000); } }); } /**** * Normal Enemy Spawn (sağdan sola, homing false) ****/ game.update = function () { scrollingBackground.update(); player.update(); if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube || child === yesil1) { child.update(); } if (child.children) { for (var c = 0; c < child.children.length; c++) { var subChild = child.children[c]; if (subChild.update) { subChild.update(); } } } } enemySpawnCounter++; if (startNormalEnemy && !stopSpawn && enemySpawnCounter >= enemySpawnInterval && !(LK.ticks >= 876 && LK.ticks <= 936) && !(LK.ticks >= 1776 && LK.ticks <= 1836) && !(LK.ticks >= 2676 && LK.ticks <= 2736) && !(LK.ticks >= 3576 && LK.ticks <= 3636) && !(LK.ticks >= 4476 && LK.ticks <= 4536) && !(LK.ticks >= 5376 && LK.ticks <= 5436) && !(LK.ticks >= 6276 && LK.ticks <= 6336) && !(LK.ticks >= 7776 && LK.ticks <= 7836)) { var canSpawn = true; for (var i = 0; i < enemies.length; i++) { if (enemies[i].x > 1800) { canSpawn = false; break; } } if (canSpawn) { var tubeCollision = false; for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child.asset && child.asset.name === 'tup_1') { var enemyRight = 2048 + 75; var enemyLeft = 2048 - 75; var tubeRight = child.x + 125; var tubeLeft = child.x - 125; if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) { tubeCollision = true; break; } } } if (!tubeCollision) { LK.setTimeout(function () { if (stopSpawn) { return; } var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 13; enemy.zIndex = 10; enemies.push(enemy); game.addChild(enemy); }, 100); } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); // --- Enemy - Player --- for (var j = enemies.length - 1; j >= 0; j--) { if (enemies[j]) { enemies[j].update(); } if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.hit(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(enemies[j])) { var coin = new Coin(); coin.x = enemies[j].x; coin.y = enemies[j].y; coin.velocity = 5; game.addChild(coin); coins.push(coin); var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = enemies[j].x - 15; particleEffect.y = enemies[j].y; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); enemies[j].destroy(); child.destroy(); enemies.splice(j, 1); break; } } } // --- FlyinEnemy - Player --- for (var n = flyinEnemies.length - 1; n >= 0; n--) { if (flyinEnemies[n]) { flyinEnemies[n].update(); } if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) { flyinEnemies[n].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.hit(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(flyinEnemies[n])) { if (!flyinEnemies[n].wave) { var coin = new Coin(); coin.x = flyinEnemies[n].x; coin.y = flyinEnemies[n].y + 60; coin.velocity = 5; game.addChild(coin); coins.push(coin); } var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = flyinEnemies[n].x - 30; particleEffect.y = flyinEnemies[n].y + 30; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) { flyinEnemies[n].destroy(); flyinEnemies.splice(n, 1); } if (bg3son.x + bg3son.width < 0) { var bb = LK.getAsset('bb', { anchorX: 0.5, anchorY: 0.5 }); bb.x = 2048 + bb.width / 2; // Spawn at the right of the screen bb.y = bg3son.y; // Keep the y position the same bb.update = function () { this.x -= bg3son.speed; // Move bb to the left as fast as bg3son }; game.addChild(bb); } } // --- Coin Toplanması --- for (var m = coins.length - 1; m >= 0; m--) { var coin = coins[m]; coin.x -= coin.velocity; if (coin.x < -100) { coin.destroy(); coins.splice(m, 1); } else if (player.intersects(coin)) { coinCounter++; scoreText.setText(coinCounter.toString()); if (coinCounter > 9 && !scoreText.movedLeft) { scoreText.x -= 20; scoreText.movedLeft = true; } coin.destroy(); coins.splice(m, 1); } } }; LK.stage.addChild(game); /**** * Tube Spawn (her 15 saniyede bir) ****/ function spawnTube() { if (stopSpawn) { return; } var tube = new Tube(); tube.x = 2048 + 125; tube.y = 2732 / 2 - 120; game.addChild(tube); var yesil1 = LK.getAsset('yesil_1', { anchorX: 0.5, anchorY: 0.5 }); // Counter to track yesil_1 points var yesil1PointsCounter = 0; yesil1.x = tube.x; yesil1.y = tube.y - 170; yesil1.speed = 10; yesil1.points = 3; yesil1.fadeBonusApplied = false; yesil1.coinBonusApplied = false; yesil1.touchBonusApplied = false; yesil1.update = function () { yesil1.x -= yesil1.speed; if (yesil1.x < -yesil1.width) { yesil1.destroy(); } function applyBonus(condition, bonusFlag, bonusName) { if (condition && !yesil1[bonusFlag]) { yesil1[bonusFlag] = true; yesil1.points += 1; console.log(bonusName + " applied. Yesil1 points: " + yesil1.points); } } applyBonus(game.fadeTriggered, 'fadeBonusApplied', "Fade bonus"); applyBonus(coinCounter >= 30, 'coinBonusApplied', "Coin bonus"); applyBonus(player.intersects(yesil1) && yesil1.points >= 2, 'touchBonusApplied', "Touch bonus"); // Freeze condition and trigger fade effect if (yesil1.points >= 3) { yesil1PointsCounter++; if (yesil1PointsCounter === 1) { LK.setTimeout(function () { endlessbg3.update = function () { this.x -= 2; // Move endlessbg3 to the left }; }, 12000); // Trigger after 12 seconds } console.log("Freeze game triggered because yesil1 points reached: " + yesil1.points); stopSpawn = true; // Position bb asset in the middle of the screen var bb = LK.getAsset('bb', { anchorX: 0.5, anchorY: 0.5 }); bb.x = 2048 - bb.width / 2; // Position bb to the right of the screen bb.y = 2732 / 2 + 150; // Keep the y-axis the same game.addChild(bb); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } // Unfreeze and restore velocity of background2 and tube_1 after 5 seconds LK.setTimeout(function () { for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj instanceof ScrollingBackground2 || obj instanceof Tube) { obj.update = function () { this.x -= this.speed; if (this.x < -this.width) { this.destroy(); } }; } } }, 5000); // Add 'kara' asset to the center of the screen with a high zIndex so that it covers the characters var kara = LK.getAsset('kara', { anchorX: 0.5, anchorY: 0.5 }); kara.x = 2048 / 2; kara.y = 2732 / 2; kara.alpha = 0; kara.zIndex = 10000; // Ensures kara is drawn in front game.addChild(kara); // Fade in 'kara' asset over 0.5 seconds var fadeInSteps = 30; var fadeInStepTime = 500 / fadeInSteps; var fadeInStep = 0; var fadeInInterval = LK.setInterval(function () { if (fadeInStep < fadeInSteps) { kara.alpha = fadeInStep / fadeInSteps; fadeInStep++; } else { LK.clearInterval(fadeInInterval); // Fade out 'kara' asset over 0.5 seconds var fadeOutSteps = 30; var fadeOutStepTime = 500 / fadeOutSteps; var fadeOutStep = 0; var fadeOutInterval = LK.setInterval(function () { if (fadeOutStep < fadeOutSteps) { kara.alpha = 1 - fadeOutStep / fadeOutSteps; fadeOutStep++; } else { LK.clearInterval(fadeOutInterval); kara.destroy(); } // Add bg3son to the game var bg3son = LK.getAsset('bg3son', { anchorX: 0.5, anchorY: 0.5 }); bg3son.zIndex = 2100; // Explicitly set zIndex for bg3son bg3son.x = 2048 / 2; bg3son.y = 2732 / 2 + 150; game.addChild(bg3son); // Add endlessbg3 directly to the game endlessbg3 = LK.getAsset('endlessbg3', { anchorX: 0.5, anchorY: 0.5 }); endlessbg3.zIndex = 2101; // Explicitly set zIndex for endlessbg3 endlessbg3.x = bg3son.x + bg3son.width / 2 + 450; // Move 450 pixels to the right endlessbg3.y = 2732 / 2 + 150; // Move 150 pixels down game.addChild(endlessbg3); // Spawn another endlessbg3 600 pixels to the right of the existing endlessbg3 var endlessbg3Child = LK.getAsset('endlessbg3', { anchorX: 0.5, anchorY: 0.5 }); endlessbg3Child.zIndex = 2101; endlessbg3Child.x = endlessbg3.x + 600; // 600 pixels to the right endlessbg3Child.y = endlessbg3.y; endlessbg3.addChild(endlessbg3Child); // Make it a child of the first endlessbg3 // Keep bg3son stationary for 15 seconds, then move it left LK.setTimeout(function () { bg3son.update = function () { this.x -= 2; // Global movement speed is maintained }; }, 15000); }, fadeOutStepTime); } }, fadeInStepTime); LK.setTimeout(function () { player.destroy(); function destroyAndRemove(objects) { for (var i = objects.length - 1; i >= 0; i--) { objects[i].destroy(); objects.splice(i, 1); } } destroyAndRemove(enemies); destroyAndRemove(flyinEnemies); destroyAndRemove(coins); // Destroy background and tube_1 for (var i = game.children.length - 1; i >= 0; i--) { var child = game.children[i]; if (child.asset && (child.asset.name === 'background' || child.asset.name === 'tup_1')) { child.destroy(); } } }, 500); if (!game.isFading) { console.log("Triggering fade effect because yesil1 is active with points: " + yesil1.points); enhancedFadeEffect(); } } }; game.addChild(yesil1); var control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); control.x = 0; control.y = -177.5; tube.addChild(control); control.update = function () { if (player.intersects(control)) { if (!firstControlTriggered && coinCounter >= 10) { var toggleSpawn = function toggleSpawn(state, delay) { stopSpawn = state; if (!state) { LK.setTimeout(function () { stopSpawn = false; }, delay); } }; game.controlActive = true; control.update = function () {}; console.log("Control event triggered: coinCounter = " + coinCounter); startNormalEnemy = false; coins.forEach(function (coin) { coin.velocity = 0; }); LK.setTimeout(function () { coins.forEach(function (coin) { coin.velocity = 5; }); }, 4000); toggleSpawn(true, 5000); game.controlActive = true; LK.setTimeout(function () { for (var i = enemies.length - 1; i >= 0; i--) { enemies[i].destroy(); enemies.splice(i, 1); } for (var i = flyinEnemies.length - 1; i >= 0; i--) { flyinEnemies[i].destroy(); flyinEnemies.splice(i, 1); } }, 400); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } LK.setTimeout(function () { player.destroy(); }, 330); enhancedFadeEffect(); firstControlTriggered = true; } } }; if (!stopSpawn) { LK.setTimeout(spawnTube, 15000); } } spawnTube(); /**** * Arka Plan ve Oyuncu ****/ var scrollingBackground = new ScrollingBackground(); game.addChild(scrollingBackground); var player = game.addChild(new Player()); player.x = 2048 / 2 - 30; player.y = 2732 / 2 + 3; /**** * Skor GUI ve Kalp ****/ var counterBackground = LK.getAsset('counter_background', { anchorX: 0.5, anchorY: 0.5 }); LK.gui.top.addChild(counterBackground); counterBackground.x = LK.gui.top.width / 2 - 62; counterBackground.y = 45; var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = LK.gui.top.width / 2 - 85; scoreText.y = 0; for (var i = 0; i < 3; i++) { var heart = LK.getAsset('heart', { anchorX: 0.5, anchorY: 0.5 }); LK.gui.top.addChild(heart); heart.x = 50 + i * 110 + 390; heart.y = 50; hearts.push(heart); } /**** * enhancedFadeEffect: Fade-out, clear scene, spawn background2, Tube2, then new player ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; game.fadeTriggered = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; // Ensure overlay stays on top overlay.zIndex = 10000; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; stopSpawn = true; while (game.children.length > 0) { game.removeChild(game.children[0]); } var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; game.scrollingBg2 = scrollingBg2; game.addChild(scrollingBg2); var tube2 = new Tube2(); control_2.x = 0; control_2.y = -177.5; tube2.addChild(control_2); control_2.update = function () { if (player && player.intersects(control_2)) { if (coinCounter >= 30) { console.log("Control_2 event triggered: coinCounter = " + coinCounter); for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } } } }; tube2.x = 2048 / 2 + 140; tube2.y = tube2.height / 2 - 60; game.addChild(tube2); LK.setTimeout(function () { var newPlayer = new Player(); newPlayer.hearts = remainingHearts; newPlayer.x = 2048 / 2 - 30; newPlayer.y = tube2.y; newPlayer.isFalling = true; newPlayer.fallSpeed = 0; newPlayer.fallAcceleration = 0.7; newPlayer.fallTargetY = 2732 / 2 - 7; game.addChild(newPlayer); player = newPlayer; game.weaponEnabled = true; LK.setTimeout(function () { spawnWaveOfFlyinEnemies(); }, 800); LK.setTimeout(function () { startNormalEnemy = true; }, 10500); }, 500); var fadeInDuration = 500; var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { if (game.scrollingBg2) { game.scrollingBg2.alpha = currentStep / steps; } currentStep++; } else { LK.clearInterval(fadeInInterval); if (overlay.parent) { overlay.parent.removeChild(overlay); } var oldScrollingSpeed = game.scrollingBg2.speed; var oldTubeSpeed = tube2.speed; game.scrollingBg2.speed = 0; tube2.speed = 0; LK.setTimeout(function () { game.scrollingBg2.speed = oldScrollingSpeed; tube2.speed = oldTubeSpeed; stopSpawn = false; game.isFading = false; game.fadeCompleted = true; }, 8000); } }, fadeInStepTime); } }, stepTime); } /**** * Oyun Döngüsü ****/ game.update = function () { scrollingBackground.update(); player.update(); if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube) { child.update(); } if (child.children) { for (var c = 0; c < child.children.length; c++) { var subChild = child.children[c]; if (subChild.update) { subChild.update(); } } } } enemySpawnCounter++; if (startNormalEnemy && !stopSpawn && enemySpawnCounter >= enemySpawnInterval && !(LK.ticks >= 876 && LK.ticks <= 936) && !(LK.ticks >= 1776 && LK.ticks <= 1836) && !(LK.ticks >= 2676 && LK.ticks <= 2736) && !(LK.ticks >= 3576 && LK.ticks <= 3636) && !(LK.ticks >= 4476 && LK.ticks <= 4536) && !(LK.ticks >= 5376 && LK.ticks <= 5436) && !(LK.ticks >= 6276 && LK.ticks <= 6336) && !(LK.ticks >= 7776 && LK.ticks <= 7836)) { var canSpawn = true; for (var i = 0; i < enemies.length; i++) { if (enemies[i].x > 1800) { canSpawn = false; break; } } if (canSpawn) { var tubeCollision = false; for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child.asset && child.asset.name === 'tup_1') { var enemyRight = 2048 + 75; var enemyLeft = 2048 - 75; var tubeRight = child.x + 125; var tubeLeft = child.x - 125; if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) { tubeCollision = true; break; } } } if (!tubeCollision) { LK.setTimeout(function () { if (stopSpawn) { return; } var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 13; enemy.zIndex = 10; enemies.push(enemy); game.addChild(enemy); }, 100); } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); // Çarpışma Kontrolleri for (var j = enemies.length - 1; j >= 0; j--) { if (enemies[j]) { enemies[j].update(); } if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(enemies[j])) { var coin = new Coin(); coin.x = enemies[j].x; coin.y = enemies[j].y; coin.velocity = 5; game.addChild(coin); coins.push(coin); var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = enemies[j].x - 15; particleEffect.y = enemies[j].y; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); enemies[j].destroy(); child.destroy(); enemies.splice(j, 1); break; } } } for (var n = flyinEnemies.length - 1; n >= 0; n--) { if (flyinEnemies[n]) { flyinEnemies[n].update(); } if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) { flyinEnemies[n].canDamage = false; LK.effects.flashScreen(0xff0000, 750, 0.0001); player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(flyinEnemies[n])) { if (!flyinEnemies[n].wave) { var coin = new Coin(); coin.x = flyinEnemies[n].x; coin.y = flyinEnemies[n].y + 60; coin.velocity = 5; game.addChild(coin); coins.push(coin); } var particleEffect = LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5, color: 0x808080 }); particleEffect.x = flyinEnemies[n].x - 30; particleEffect.y = flyinEnemies[n].y + 30; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) { flyinEnemies[n].destroy(); flyinEnemies.splice(n, 1); } } for (var m = coins.length - 1; m >= 0; m--) { var coin = coins[m]; coin.x -= coin.velocity; if (coin.x < -100) { coin.destroy(); coins.splice(m, 1); } else if (player.intersects(coin)) { coinCounter++; scoreText.setText(coinCounter.toString()); if (coinCounter > 9 && !scoreText.movedLeft) { scoreText.x -= 20; scoreText.movedLeft = true; } coin.destroy(); coins.splice(m, 1); } } }; LK.stage.addChild(game); // Dokunma/Kontrol game.down = function (x, y, obj) { if (player.isJumping && game.weaponEnabled) { if (!game.lastWeaponTime || Date.now() - game.lastWeaponTime > 350) { var weapon = new Weapon(); weapon.x = player.x; weapon.y = player.y; var dx = x - weapon.x; var dy = y - weapon.y; var distance = Math.sqrt(dx * dx + dy * dy); weapon.directionX = dx / distance; weapon.directionY = dy / distance; var angle = Math.acos(weapon.directionY / Math.sqrt(weapon.directionX * weapon.directionX + weapon.directionY * weapon.directionY)); var angleInDegrees = angle * (180 / Math.PI); if (angleInDegrees <= 30) { weapon.speed *= 1.3; } game.addChild(weapon); LK.setTimeout(function () { weapon.destroy(); }, 9000); game.lastWeaponTime = Date.now(); } } player.jump(); }; // Oyunu Sahneye Ekle LK.stage.addChild(game);
/****
* Classes
****/
// Coin class
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = 5;
self.zIndex = 15;
self.update = function () {
self.x -= self.velocity;
};
});
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.zIndex = 10;
self.canDamage = true;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// FlyinEnemy class
var FlyinEnemy = Container.expand(function () {
var self = Container.call(this);
var flyinEnemyGraphics = self.attachAsset('flyin_enemy', {
anchorX: 0.5,
anchorY: 0
});
self.speed = 5;
self.zIndex = 10;
self.canDamage = true;
self.homing = false;
self.vx = 0;
self.vy = 0;
self.update = function () {
if (!self.homing) {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
} else {
self.x += self.vx;
self.y += self.vy;
if (self.x < -200 || self.x > 2248 || self.y < -200 || self.y > 2932) {
self.destroy();
}
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.jumpHeight = 40;
self.isJumping = false;
self.velocityY = 0;
self.isFalling = false;
self.fallSpeed = 0;
self.fallAcceleration = 0.7;
self.fallTargetY = 2732 / 2 - 7;
self.zIndex = 20;
self.hearts = typeof remainingHearts !== 'undefined' ? remainingHearts : 3;
self.update = function () {
self.prevY = self.y;
if (self.isFalling) {
self.y += self.fallSpeed;
self.fallSpeed += self.fallAcceleration;
if (self.y >= self.fallTargetY) {
self.y = self.fallTargetY;
self.isFalling = false;
self.fallSpeed = 0;
game.weaponEnabled = true;
}
}
self.prevY = self.y;
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7;
if (self.y >= 2732 / 2 - 3) {
self.y = 2732 / 2 - 9;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.invulnerable = false;
self.hit = function () {
if (!self.invulnerable) {
self.loseHeart();
self.invulnerable = true;
LK.setTimeout(function () {
self.invulnerable = false;
}, 500);
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
}
};
self.loseHeart = function () {
self.hearts--;
playerDeaths++;
if (playerDeaths === 1 && hearts[0]) {
hearts[0].destroy();
} else if (playerDeaths === 2 && hearts[1]) {
hearts[1].destroy();
} else if (playerDeaths === 3 && hearts[2]) {
hearts[2].destroy();
}
remainingHearts = self.hearts;
if (hearts.length === 0) {
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = flyinEnemies.length - 1; i >= 0; i--) {
flyinEnemies[i].destroy();
flyinEnemies.splice(i, 1);
}
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].destroy();
coins.splice(i, 1);
}
self.destroy();
game.weaponEnabled = false;
}
};
});
// ScrollingBackground class
var ScrollingBackground = Container.expand(function () {
var self = Container.call(this);
self.bg1 = LK.getAsset('background', {
anchorX: 0,
anchorY: 0
});
self.bg1.x = 0;
self.bg1.y = 0;
self.addChild(self.bg1);
self.bg2 = LK.getAsset('background', {
anchorX: 1,
anchorY: 0
});
self.bg2.scaleX = -1;
self.bg2.x = self.bg1.width;
self.bg2.y = 0;
self.addChild(self.bg2);
self.speed = 2;
self.update = function () {
self.bg1.x -= self.speed;
self.bg2.x -= self.speed;
if (self.bg1.x + self.bg1.width <= 0) {
self.bg1.x = self.bg2.x + self.bg2.width;
}
if (self.bg2.x + self.bg2.width <= 0) {
self.bg2.x = self.bg1.x + self.bg1.width;
}
};
});
// ScrollingBackground2 class
var ScrollingBackground2 = Container.expand(function () {
var self = Container.call(this);
var bg1 = LK.getAsset('background2', {
anchorX: 0,
anchorY: 0
});
bg1.x = 0;
bg1.y = 0;
self.addChild(bg1);
var bg2 = LK.getAsset('background2', {
anchorX: 1,
anchorY: 0
});
bg2.scaleX = -1;
bg2.x = bg1.width;
bg2.y = 0;
self.addChild(bg2);
self.speed = 2;
self.update = function () {
bg1.x -= self.speed;
bg2.x -= self.speed;
if (bg1.x + bg1.width <= 0) {
bg1.x = bg2.x + bg2.width;
}
if (bg2.x + bg2.width <= 0) {
bg2.x = bg1.x + bg1.width;
}
};
});
// Tube class
var Tube = Container.expand(function () {
var self = Container.call(this);
var tubeGraphics = self.attachAsset('tup_1', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.zIndex = 0;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
});
// Tube2 class
var Tube2 = Container.expand(function () {
var self = Container.call(this);
var tubeGraphics = self.attachAsset('tube_2', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.zIndex = 2000;
self.update = function () {
self.x -= self.speed;
if (self.x < -self.width) {
self.destroy();
}
};
});
// Weapon class
var Weapon = Container.expand(function () {
var self = Container.call(this);
var weaponGraphics = self.attachAsset('weapon', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 40;
self.update = function () {
self.x += self.directionX * self.speed;
self.y += self.directionY * self.speed;
weaponGraphics.rotation += 0.3;
if (Math.abs(game.down.x - self.x) < self.speed && Math.abs(game.down.y - self.y) < self.speed) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
width: 2048,
height: 2732,
backgroundColor: 0x000000
});
/****
* Game Code
****/
var control_2 = LK.getAsset('control_2', {
anchorX: 0.5,
anchorY: 0.5
});
/****
* Global Variables & Flags
****/
var startNormalEnemy = true;
var coinCounter = 0;
var flyinEnemies = [];
var playerDeaths = 0;
var hearts = [];
var remainingHearts = 3;
game.controlActive = false;
var coins = [];
var firstControlTriggered = false;
var enemies = [];
var enemySpawnInterval = Math.floor(Math.random() * 100) + 30;
var enemySpawnCounter = 0;
var stopSpawn = false;
game.weaponEnabled = true;
/****
* (A) Eski FlyinEnemy Spawn (sağdan sola, homing false)
****/
function spawnFlyinEnemy() {
if (stopSpawn) {
return;
}
var delay = Math.random() * 2000 + 2000;
LK.setTimeout(function () {
if (stopSpawn) {
return;
}
var fe = new FlyinEnemy();
fe.x = 2048;
fe.y = 449;
fe.zIndex = 10;
game.addChild(fe);
flyinEnemies.push(fe);
spawnFlyinEnemy();
}, delay);
}
spawnFlyinEnemy();
/****
* (B) Wave şeklinde, homing davranışlı FlyinEnemy Spawn
****/
function spawnWaveOfFlyinEnemies() {
var spawnPoints = [{
x: 0,
y: 0
}, {
x: 2048,
y: 0
}, {
x: 0,
y: 2732
}, {
x: 2048,
y: 2732
}, {
x: 1024,
y: 0
}, {
x: 1024,
y: 2732
}, {
x: 0,
y: 1366
}, {
x: 2048,
y: 1366
}];
for (var i = spawnPoints.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = spawnPoints[i];
spawnPoints[i] = spawnPoints[j];
spawnPoints[j] = temp;
}
spawnPoints.forEach(function (point, index) {
LK.setTimeout(function () {
var enemy = new FlyinEnemy();
enemy.homing = true;
enemy.wave = true;
enemy.x = point.x;
enemy.y = point.y;
var dx = player.x - enemy.x;
var dy = player.y - enemy.y;
var distance = Math.sqrt(dx * dx + dy * dy) || 1;
enemy.vx = dx / distance * enemy.speed;
enemy.vy = dy / distance * enemy.speed;
enemy.zIndex = 2100;
if (enemy.x < 1024) {
enemy.scaleX = -1;
}
game.addChild(enemy);
flyinEnemies.push(enemy);
}, index * 800);
if (index === spawnPoints.length - 1) {
LK.setTimeout(function () {
spawnFlyinEnemy();
}, 10000);
}
});
}
/****
* Normal Enemy Spawn (sağdan sola, homing false)
****/
game.update = function () {
scrollingBackground.update();
player.update();
if (game.scrollingBg2 && game.scrollingBg2.update) {
game.scrollingBg2.update();
}
for (var t = 0; t < game.children.length; t++) {
var child = game.children[t];
if (child instanceof Tube || child === yesil1) {
child.update();
}
if (child.children) {
for (var c = 0; c < child.children.length; c++) {
var subChild = child.children[c];
if (subChild.update) {
subChild.update();
}
}
}
}
enemySpawnCounter++;
if (startNormalEnemy && !stopSpawn && enemySpawnCounter >= enemySpawnInterval && !(LK.ticks >= 876 && LK.ticks <= 936) && !(LK.ticks >= 1776 && LK.ticks <= 1836) && !(LK.ticks >= 2676 && LK.ticks <= 2736) && !(LK.ticks >= 3576 && LK.ticks <= 3636) && !(LK.ticks >= 4476 && LK.ticks <= 4536) && !(LK.ticks >= 5376 && LK.ticks <= 5436) && !(LK.ticks >= 6276 && LK.ticks <= 6336) && !(LK.ticks >= 7776 && LK.ticks <= 7836)) {
var canSpawn = true;
for (var i = 0; i < enemies.length; i++) {
if (enemies[i].x > 1800) {
canSpawn = false;
break;
}
}
if (canSpawn) {
var tubeCollision = false;
for (var t = 0; t < game.children.length; t++) {
var child = game.children[t];
if (child.asset && child.asset.name === 'tup_1') {
var enemyRight = 2048 + 75;
var enemyLeft = 2048 - 75;
var tubeRight = child.x + 125;
var tubeLeft = child.x - 125;
if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) {
tubeCollision = true;
break;
}
}
}
if (!tubeCollision) {
LK.setTimeout(function () {
if (stopSpawn) {
return;
}
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2 - 13;
enemy.zIndex = 10;
enemies.push(enemy);
game.addChild(enemy);
}, 100);
}
enemySpawnCounter = 0;
enemySpawnInterval = Math.floor(Math.random() * 100) + 30;
}
enemySpawnCounter = 0;
enemySpawnInterval = Math.floor(Math.random() * 100) + 30;
}
game.children.sort(function (a, b) {
return (a.zIndex || 0) - (b.zIndex || 0);
});
// --- Enemy - Player ---
for (var j = enemies.length - 1; j >= 0; j--) {
if (enemies[j]) {
enemies[j].update();
}
if (player.intersects(enemies[j]) && enemies[j].canDamage) {
enemies[j].canDamage = false;
LK.effects.flashScreen(0xff0000, 750, 0.0001);
player.hit();
if (player.hearts <= 0) {
LK.showGameOver();
}
}
for (var k = game.children.length - 1; k >= 0; k--) {
var child = game.children[k];
if (child instanceof Weapon && child.intersects(enemies[j])) {
var coin = new Coin();
coin.x = enemies[j].x;
coin.y = enemies[j].y;
coin.velocity = 5;
game.addChild(coin);
coins.push(coin);
var particleEffect = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0x808080
});
particleEffect.x = enemies[j].x - 15;
particleEffect.y = enemies[j].y;
game.addChild(particleEffect);
LK.setTimeout(function () {
particleEffect.destroy();
}, 150);
enemies[j].destroy();
child.destroy();
enemies.splice(j, 1);
break;
}
}
}
// --- FlyinEnemy - Player ---
for (var n = flyinEnemies.length - 1; n >= 0; n--) {
if (flyinEnemies[n]) {
flyinEnemies[n].update();
}
if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) {
flyinEnemies[n].canDamage = false;
LK.effects.flashScreen(0xff0000, 750, 0.0001);
player.hit();
if (player.hearts <= 0) {
LK.showGameOver();
}
}
for (var k = game.children.length - 1; k >= 0; k--) {
var child = game.children[k];
if (child instanceof Weapon && child.intersects(flyinEnemies[n])) {
if (!flyinEnemies[n].wave) {
var coin = new Coin();
coin.x = flyinEnemies[n].x;
coin.y = flyinEnemies[n].y + 60;
coin.velocity = 5;
game.addChild(coin);
coins.push(coin);
}
var particleEffect = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0x808080
});
particleEffect.x = flyinEnemies[n].x - 30;
particleEffect.y = flyinEnemies[n].y + 30;
game.addChild(particleEffect);
LK.setTimeout(function () {
particleEffect.destroy();
}, 150);
flyinEnemies[n].destroy();
child.destroy();
flyinEnemies.splice(n, 1);
break;
}
}
if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) {
flyinEnemies[n].destroy();
flyinEnemies.splice(n, 1);
}
if (bg3son.x + bg3son.width < 0) {
var bb = LK.getAsset('bb', {
anchorX: 0.5,
anchorY: 0.5
});
bb.x = 2048 + bb.width / 2; // Spawn at the right of the screen
bb.y = bg3son.y; // Keep the y position the same
bb.update = function () {
this.x -= bg3son.speed; // Move bb to the left as fast as bg3son
};
game.addChild(bb);
}
}
// --- Coin Toplanması ---
for (var m = coins.length - 1; m >= 0; m--) {
var coin = coins[m];
coin.x -= coin.velocity;
if (coin.x < -100) {
coin.destroy();
coins.splice(m, 1);
} else if (player.intersects(coin)) {
coinCounter++;
scoreText.setText(coinCounter.toString());
if (coinCounter > 9 && !scoreText.movedLeft) {
scoreText.x -= 20;
scoreText.movedLeft = true;
}
coin.destroy();
coins.splice(m, 1);
}
}
};
LK.stage.addChild(game);
/****
* Tube Spawn (her 15 saniyede bir)
****/
function spawnTube() {
if (stopSpawn) {
return;
}
var tube = new Tube();
tube.x = 2048 + 125;
tube.y = 2732 / 2 - 120;
game.addChild(tube);
var yesil1 = LK.getAsset('yesil_1', {
anchorX: 0.5,
anchorY: 0.5
});
// Counter to track yesil_1 points
var yesil1PointsCounter = 0;
yesil1.x = tube.x;
yesil1.y = tube.y - 170;
yesil1.speed = 10;
yesil1.points = 3;
yesil1.fadeBonusApplied = false;
yesil1.coinBonusApplied = false;
yesil1.touchBonusApplied = false;
yesil1.update = function () {
yesil1.x -= yesil1.speed;
if (yesil1.x < -yesil1.width) {
yesil1.destroy();
}
function applyBonus(condition, bonusFlag, bonusName) {
if (condition && !yesil1[bonusFlag]) {
yesil1[bonusFlag] = true;
yesil1.points += 1;
console.log(bonusName + " applied. Yesil1 points: " + yesil1.points);
}
}
applyBonus(game.fadeTriggered, 'fadeBonusApplied', "Fade bonus");
applyBonus(coinCounter >= 30, 'coinBonusApplied', "Coin bonus");
applyBonus(player.intersects(yesil1) && yesil1.points >= 2, 'touchBonusApplied', "Touch bonus");
// Freeze condition and trigger fade effect
if (yesil1.points >= 3) {
yesil1PointsCounter++;
if (yesil1PointsCounter === 1) {
LK.setTimeout(function () {
endlessbg3.update = function () {
this.x -= 2; // Move endlessbg3 to the left
};
}, 12000); // Trigger after 12 seconds
}
console.log("Freeze game triggered because yesil1 points reached: " + yesil1.points);
stopSpawn = true;
// Position bb asset in the middle of the screen
var bb = LK.getAsset('bb', {
anchorX: 0.5,
anchorY: 0.5
});
bb.x = 2048 - bb.width / 2; // Position bb to the right of the screen
bb.y = 2732 / 2 + 150; // Keep the y-axis the same
game.addChild(bb);
for (var i = 0; i < game.children.length; i++) {
var obj = game.children[i];
if (obj.update) {
obj.update = function () {};
}
}
// Unfreeze and restore velocity of background2 and tube_1 after 5 seconds
LK.setTimeout(function () {
for (var i = 0; i < game.children.length; i++) {
var obj = game.children[i];
if (obj instanceof ScrollingBackground2 || obj instanceof Tube) {
obj.update = function () {
this.x -= this.speed;
if (this.x < -this.width) {
this.destroy();
}
};
}
}
}, 5000);
// Add 'kara' asset to the center of the screen with a high zIndex so that it covers the characters
var kara = LK.getAsset('kara', {
anchorX: 0.5,
anchorY: 0.5
});
kara.x = 2048 / 2;
kara.y = 2732 / 2;
kara.alpha = 0;
kara.zIndex = 10000; // Ensures kara is drawn in front
game.addChild(kara);
// Fade in 'kara' asset over 0.5 seconds
var fadeInSteps = 30;
var fadeInStepTime = 500 / fadeInSteps;
var fadeInStep = 0;
var fadeInInterval = LK.setInterval(function () {
if (fadeInStep < fadeInSteps) {
kara.alpha = fadeInStep / fadeInSteps;
fadeInStep++;
} else {
LK.clearInterval(fadeInInterval);
// Fade out 'kara' asset over 0.5 seconds
var fadeOutSteps = 30;
var fadeOutStepTime = 500 / fadeOutSteps;
var fadeOutStep = 0;
var fadeOutInterval = LK.setInterval(function () {
if (fadeOutStep < fadeOutSteps) {
kara.alpha = 1 - fadeOutStep / fadeOutSteps;
fadeOutStep++;
} else {
LK.clearInterval(fadeOutInterval);
kara.destroy();
}
// Add bg3son to the game
var bg3son = LK.getAsset('bg3son', {
anchorX: 0.5,
anchorY: 0.5
});
bg3son.zIndex = 2100; // Explicitly set zIndex for bg3son
bg3son.x = 2048 / 2;
bg3son.y = 2732 / 2 + 150;
game.addChild(bg3son);
// Add endlessbg3 directly to the game
endlessbg3 = LK.getAsset('endlessbg3', {
anchorX: 0.5,
anchorY: 0.5
});
endlessbg3.zIndex = 2101; // Explicitly set zIndex for endlessbg3
endlessbg3.x = bg3son.x + bg3son.width / 2 + 450; // Move 450 pixels to the right
endlessbg3.y = 2732 / 2 + 150; // Move 150 pixels down
game.addChild(endlessbg3);
// Spawn another endlessbg3 600 pixels to the right of the existing endlessbg3
var endlessbg3Child = LK.getAsset('endlessbg3', {
anchorX: 0.5,
anchorY: 0.5
});
endlessbg3Child.zIndex = 2101;
endlessbg3Child.x = endlessbg3.x + 600; // 600 pixels to the right
endlessbg3Child.y = endlessbg3.y;
endlessbg3.addChild(endlessbg3Child); // Make it a child of the first endlessbg3
// Keep bg3son stationary for 15 seconds, then move it left
LK.setTimeout(function () {
bg3son.update = function () {
this.x -= 2; // Global movement speed is maintained
};
}, 15000);
}, fadeOutStepTime);
}
}, fadeInStepTime);
LK.setTimeout(function () {
player.destroy();
function destroyAndRemove(objects) {
for (var i = objects.length - 1; i >= 0; i--) {
objects[i].destroy();
objects.splice(i, 1);
}
}
destroyAndRemove(enemies);
destroyAndRemove(flyinEnemies);
destroyAndRemove(coins);
// Destroy background and tube_1
for (var i = game.children.length - 1; i >= 0; i--) {
var child = game.children[i];
if (child.asset && (child.asset.name === 'background' || child.asset.name === 'tup_1')) {
child.destroy();
}
}
}, 500);
if (!game.isFading) {
console.log("Triggering fade effect because yesil1 is active with points: " + yesil1.points);
enhancedFadeEffect();
}
}
};
game.addChild(yesil1);
var control = LK.getAsset('control', {
anchorX: 0.5,
anchorY: 0.5
});
control.x = 0;
control.y = -177.5;
tube.addChild(control);
control.update = function () {
if (player.intersects(control)) {
if (!firstControlTriggered && coinCounter >= 10) {
var toggleSpawn = function toggleSpawn(state, delay) {
stopSpawn = state;
if (!state) {
LK.setTimeout(function () {
stopSpawn = false;
}, delay);
}
};
game.controlActive = true;
control.update = function () {};
console.log("Control event triggered: coinCounter = " + coinCounter);
startNormalEnemy = false;
coins.forEach(function (coin) {
coin.velocity = 0;
});
LK.setTimeout(function () {
coins.forEach(function (coin) {
coin.velocity = 5;
});
}, 4000);
toggleSpawn(true, 5000);
game.controlActive = true;
LK.setTimeout(function () {
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
enemies.splice(i, 1);
}
for (var i = flyinEnemies.length - 1; i >= 0; i--) {
flyinEnemies[i].destroy();
flyinEnemies.splice(i, 1);
}
}, 400);
for (var i = 0; i < game.children.length; i++) {
var obj = game.children[i];
if (obj.update) {
obj.update = function () {};
}
}
LK.setTimeout(function () {
player.destroy();
}, 330);
enhancedFadeEffect();
firstControlTriggered = true;
}
}
};
if (!stopSpawn) {
LK.setTimeout(spawnTube, 15000);
}
}
spawnTube();
/****
* Arka Plan ve Oyuncu
****/
var scrollingBackground = new ScrollingBackground();
game.addChild(scrollingBackground);
var player = game.addChild(new Player());
player.x = 2048 / 2 - 30;
player.y = 2732 / 2 + 3;
/****
* Skor GUI ve Kalp
****/
var counterBackground = LK.getAsset('counter_background', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(counterBackground);
counterBackground.x = LK.gui.top.width / 2 - 62;
counterBackground.y = 45;
var scoreText = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreText);
scoreText.x = LK.gui.top.width / 2 - 85;
scoreText.y = 0;
for (var i = 0; i < 3; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(heart);
heart.x = 50 + i * 110 + 390;
heart.y = 50;
hearts.push(heart);
}
/****
* enhancedFadeEffect: Fade-out, clear scene, spawn background2, Tube2, then new player
****/
function enhancedFadeEffect() {
if (game.isFading || game.fadeCompleted || !game.controlActive) {
return;
}
game.isFading = true;
game.fadeTriggered = true;
var overlay = LK.getAsset('overlay', {
anchorX: 0,
anchorY: 0
});
overlay.alpha = 0;
// Ensure overlay stays on top
overlay.zIndex = 10000;
if (!overlay.parent) {
LK.stage.addChild(overlay);
}
var steps = 20;
var duration = 500;
var stepTime = duration / steps;
var currentStep = 0;
var fadeOutInterval = LK.setInterval(function () {
if (currentStep < steps) {
overlay.alpha = currentStep / steps;
currentStep++;
} else {
LK.clearInterval(fadeOutInterval);
currentStep = 0;
stopSpawn = true;
while (game.children.length > 0) {
game.removeChild(game.children[0]);
}
var scrollingBg2 = new ScrollingBackground2();
scrollingBg2.alpha = 0;
game.scrollingBg2 = scrollingBg2;
game.addChild(scrollingBg2);
var tube2 = new Tube2();
control_2.x = 0;
control_2.y = -177.5;
tube2.addChild(control_2);
control_2.update = function () {
if (player && player.intersects(control_2)) {
if (coinCounter >= 30) {
console.log("Control_2 event triggered: coinCounter = " + coinCounter);
for (var i = 0; i < game.children.length; i++) {
var obj = game.children[i];
if (obj.update) {
obj.update = function () {};
}
}
}
}
};
tube2.x = 2048 / 2 + 140;
tube2.y = tube2.height / 2 - 60;
game.addChild(tube2);
LK.setTimeout(function () {
var newPlayer = new Player();
newPlayer.hearts = remainingHearts;
newPlayer.x = 2048 / 2 - 30;
newPlayer.y = tube2.y;
newPlayer.isFalling = true;
newPlayer.fallSpeed = 0;
newPlayer.fallAcceleration = 0.7;
newPlayer.fallTargetY = 2732 / 2 - 7;
game.addChild(newPlayer);
player = newPlayer;
game.weaponEnabled = true;
LK.setTimeout(function () {
spawnWaveOfFlyinEnemies();
}, 800);
LK.setTimeout(function () {
startNormalEnemy = true;
}, 10500);
}, 500);
var fadeInDuration = 500;
var fadeInStepTime = fadeInDuration / steps;
var fadeInInterval = LK.setInterval(function () {
if (currentStep < steps) {
if (game.scrollingBg2) {
game.scrollingBg2.alpha = currentStep / steps;
}
currentStep++;
} else {
LK.clearInterval(fadeInInterval);
if (overlay.parent) {
overlay.parent.removeChild(overlay);
}
var oldScrollingSpeed = game.scrollingBg2.speed;
var oldTubeSpeed = tube2.speed;
game.scrollingBg2.speed = 0;
tube2.speed = 0;
LK.setTimeout(function () {
game.scrollingBg2.speed = oldScrollingSpeed;
tube2.speed = oldTubeSpeed;
stopSpawn = false;
game.isFading = false;
game.fadeCompleted = true;
}, 8000);
}
}, fadeInStepTime);
}
}, stepTime);
}
/****
* Oyun Döngüsü
****/
game.update = function () {
scrollingBackground.update();
player.update();
if (game.scrollingBg2 && game.scrollingBg2.update) {
game.scrollingBg2.update();
}
for (var t = 0; t < game.children.length; t++) {
var child = game.children[t];
if (child instanceof Tube) {
child.update();
}
if (child.children) {
for (var c = 0; c < child.children.length; c++) {
var subChild = child.children[c];
if (subChild.update) {
subChild.update();
}
}
}
}
enemySpawnCounter++;
if (startNormalEnemy && !stopSpawn && enemySpawnCounter >= enemySpawnInterval && !(LK.ticks >= 876 && LK.ticks <= 936) && !(LK.ticks >= 1776 && LK.ticks <= 1836) && !(LK.ticks >= 2676 && LK.ticks <= 2736) && !(LK.ticks >= 3576 && LK.ticks <= 3636) && !(LK.ticks >= 4476 && LK.ticks <= 4536) && !(LK.ticks >= 5376 && LK.ticks <= 5436) && !(LK.ticks >= 6276 && LK.ticks <= 6336) && !(LK.ticks >= 7776 && LK.ticks <= 7836)) {
var canSpawn = true;
for (var i = 0; i < enemies.length; i++) {
if (enemies[i].x > 1800) {
canSpawn = false;
break;
}
}
if (canSpawn) {
var tubeCollision = false;
for (var t = 0; t < game.children.length; t++) {
var child = game.children[t];
if (child.asset && child.asset.name === 'tup_1') {
var enemyRight = 2048 + 75;
var enemyLeft = 2048 - 75;
var tubeRight = child.x + 125;
var tubeLeft = child.x - 125;
if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) {
tubeCollision = true;
break;
}
}
}
if (!tubeCollision) {
LK.setTimeout(function () {
if (stopSpawn) {
return;
}
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2 - 13;
enemy.zIndex = 10;
enemies.push(enemy);
game.addChild(enemy);
}, 100);
}
enemySpawnCounter = 0;
enemySpawnInterval = Math.floor(Math.random() * 100) + 30;
}
enemySpawnCounter = 0;
enemySpawnInterval = Math.floor(Math.random() * 100) + 30;
}
game.children.sort(function (a, b) {
return (a.zIndex || 0) - (b.zIndex || 0);
});
// Çarpışma Kontrolleri
for (var j = enemies.length - 1; j >= 0; j--) {
if (enemies[j]) {
enemies[j].update();
}
if (player.intersects(enemies[j]) && enemies[j].canDamage) {
enemies[j].canDamage = false;
LK.effects.flashScreen(0xff0000, 750, 0.0001);
player.loseHeart();
if (player.hearts <= 0) {
LK.showGameOver();
}
}
for (var k = game.children.length - 1; k >= 0; k--) {
var child = game.children[k];
if (child instanceof Weapon && child.intersects(enemies[j])) {
var coin = new Coin();
coin.x = enemies[j].x;
coin.y = enemies[j].y;
coin.velocity = 5;
game.addChild(coin);
coins.push(coin);
var particleEffect = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0x808080
});
particleEffect.x = enemies[j].x - 15;
particleEffect.y = enemies[j].y;
game.addChild(particleEffect);
LK.setTimeout(function () {
particleEffect.destroy();
}, 150);
enemies[j].destroy();
child.destroy();
enemies.splice(j, 1);
break;
}
}
}
for (var n = flyinEnemies.length - 1; n >= 0; n--) {
if (flyinEnemies[n]) {
flyinEnemies[n].update();
}
if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) {
flyinEnemies[n].canDamage = false;
LK.effects.flashScreen(0xff0000, 750, 0.0001);
player.loseHeart();
if (player.hearts <= 0) {
LK.showGameOver();
}
}
for (var k = game.children.length - 1; k >= 0; k--) {
var child = game.children[k];
if (child instanceof Weapon && child.intersects(flyinEnemies[n])) {
if (!flyinEnemies[n].wave) {
var coin = new Coin();
coin.x = flyinEnemies[n].x;
coin.y = flyinEnemies[n].y + 60;
coin.velocity = 5;
game.addChild(coin);
coins.push(coin);
}
var particleEffect = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
color: 0x808080
});
particleEffect.x = flyinEnemies[n].x - 30;
particleEffect.y = flyinEnemies[n].y + 30;
game.addChild(particleEffect);
LK.setTimeout(function () {
particleEffect.destroy();
}, 150);
flyinEnemies[n].destroy();
child.destroy();
flyinEnemies.splice(n, 1);
break;
}
}
if (flyinEnemies[n] && !flyinEnemies[n].homing && flyinEnemies[n].x < -50) {
flyinEnemies[n].destroy();
flyinEnemies.splice(n, 1);
}
}
for (var m = coins.length - 1; m >= 0; m--) {
var coin = coins[m];
coin.x -= coin.velocity;
if (coin.x < -100) {
coin.destroy();
coins.splice(m, 1);
} else if (player.intersects(coin)) {
coinCounter++;
scoreText.setText(coinCounter.toString());
if (coinCounter > 9 && !scoreText.movedLeft) {
scoreText.x -= 20;
scoreText.movedLeft = true;
}
coin.destroy();
coins.splice(m, 1);
}
}
};
LK.stage.addChild(game);
// Dokunma/Kontrol
game.down = function (x, y, obj) {
if (player.isJumping && game.weaponEnabled) {
if (!game.lastWeaponTime || Date.now() - game.lastWeaponTime > 350) {
var weapon = new Weapon();
weapon.x = player.x;
weapon.y = player.y;
var dx = x - weapon.x;
var dy = y - weapon.y;
var distance = Math.sqrt(dx * dx + dy * dy);
weapon.directionX = dx / distance;
weapon.directionY = dy / distance;
var angle = Math.acos(weapon.directionY / Math.sqrt(weapon.directionX * weapon.directionX + weapon.directionY * weapon.directionY));
var angleInDegrees = angle * (180 / Math.PI);
if (angleInDegrees <= 30) {
weapon.speed *= 1.3;
}
game.addChild(weapon);
LK.setTimeout(function () {
weapon.destroy();
}, 9000);
game.lastWeaponTime = Date.now();
}
}
player.jump();
};
// Oyunu Sahneye Ekle
LK.stage.addChild(game);
Single 2D Mario Character. In-Game asset. 2d. Blank background.
2D Single Monster. In-Game asset. 2d. Blank background. High contrast. No shadows.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
marionun ingiliz boru anahtarı aleti. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
red heart mario. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
completely black simple counter without sharp edges
sea and sky,pixel,realistic but detailles benzer renkler mavi ve mavi Single Game Texture. In-Game asset. 2d. Blank background. low contrast. No shadows