Code edit (1 edits merged)
Please save this source code
User prompt
Aşağıdaki örnekte, Tube2 spawner konumunu x ekseninde 30 piksel sağa kaydırdım. Ayrıca, background2 ve tube_2 spawn edildiğinde oyun update döngüsü 2 saniye süreyle duraklayacak (yani oyun “donacak”) ve 2 saniye sonra normal update fonksiyonu devreye girecek şekilde ayarlandı. js Kopyala Düzenle function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; // Fade-Out: overlay.alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; stopSpawn = true; // Spawn işlemleri durdu while (game.children.length > 0) { game.removeChild(game.children[0]); } // Tek bir ScrollingBackground2 oluştur var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; game.scrollingBg2 = scrollingBg2; game.addChild(scrollingBg2); // Tube2'yi ayrı olarak ekle (x koordinatını 30 pixel sağa kaydırdım) var tube2 = new Tube2(); tube2.x = (2048 / 2) + 30; // Orijinal merkezden 30 pixel sağa tube2.y = tube2.height / 2 - 45; // İstenilen y konumuna ayarlandı game.addChild(tube2); // Fade-In: ScrollingBackground2'nin alpha'sını 0'dan 1'e çıkar 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); } // Oyun update'ini 2 saniye süreyle duraklatıyoruz game.update = function () {}; LK.setTimeout(function () { game.isFading = false; game.fadeCompleted = true; // Artık yalnızca ScrollingBackground2 ve tube2 update edilecek game.update = function () { if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } if (tube2 && tube2.update) { tube2.update(); } }; }, 2000); // 2000 ms = 2 saniye } }, fadeInStepTime); } }, stepTime); } Bu düzenleme ile: Tube2 spawner konumu: Tube2, (2048/2) + 30 olarak ayarlanarak orijinal merkeze göre 30 pixel sağa kaydırıldı. Oyun donması: Background2 ve Tube2 spawn edildikten sonra, game.update boş bir fonksiyon atanarak oyun 2 saniye süreyle durduruluyor. 2 saniye sonra, update fonksiyonu ScrollingBackground2 ve Tube2'nin update metodlarını çağıracak şekilde yeniden tanımlanıyor. Bu sayede istenilen davranış elde edilmiş olur.
User prompt
freeze background2 and tube_2 for 1 second then make them move to left
User prompt
move tube_2 spawner 15 pixel up and place it x location middle of the screen
User prompt
spawn tube_2 middle top of the screen
User prompt
spawn tube_ top of the screen
User prompt
decrase speed of tube_2 to make it fast as enemy velocity
User prompt
make tube_2 move fast as background2
User prompt
Tube2 sınıfı içinde fazladan background2 eklenmesi, sahnede iki background2’nin görünmesine sebep oluyor. Ayrıca tube_2’nin görünür olması için doğru sırayla eklenmesi gerekiyor. Aşağıdaki örnekte iki sorunu da çözmek için; Tube2 sınıfında background2 asset’ini kaldırdım, sadece tube_2 asset’i eklendi. Fade tamamlandıktan sonra tek bir ScrollingBackground2 oluşturup, üzerine tube_2 objesini (Tube2) ayrı olarak ekledim. update döngüsünde de yeni sahne (background2 ve tube_2) için güncelleme yapılıyor. Aşağıdaki örnek kodu inceleyebilirsiniz: js Kopyala Düzenle // Tube2: Sadece tube_2 görselini ekle, background2 ekleme. var Tube2 = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tube_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; // ScrollingBackground2 ile aynı hızda hareket etsin self.zIndex = 2000; // background2’nin üzerinde görünmesi için self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); Ayrıca, enhancedFadeEffect fonksiyonunu şu şekilde güncelledim: js Kopyala Düzenle function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; // Fade-Out: overlay.alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; stopSpawn = true; // Spawn işlemleri durdu // Mevcut sahneyi temizle while (game.children.length > 0) { game.removeChild(game.children[0]); } // Sadece bir tane ScrollingBackground2 oluştur var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; game.scrollingBg2 = scrollingBg2; game.addChild(scrollingBg2); // Tube2 objesini oluştur ve ekle (background2’nin üstünde) var tube2 = new Tube2(); tube2.x = 2048 + tube2.width / 2; tube2.y = tube2.height / 2 - 30; game.addChild(tube2); // Fade-In: ScrollingBackground2’nin alpha 0 -> 1 var fadeInDuration = 500; var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { scrollingBg2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Sadece yeni sahnedeki objeleri güncelle game.update = function () { if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } tube2.update(); }; } }, fadeInStepTime); } }, stepTime); } Bu düzenlemelerle: Tube2 artık kendi içinde background2 eklemeyecek, dolayısıyla sahnede yalnızca tek bir background2 olacak. Tube2 (tube_2 görseli) ScrollingBackground2’nin üzerinde, belirlenen zIndex değeriyle görünecektir.
User prompt
Aşağıdaki örnekte Tube2 sınıfını, tube_2 görselinin background2 görselinin üzerinde görünmesi için background2'yi tube_2 container’ının child’ı olarak ekleyecek şekilde güncelledim. Bu örnekte önce background2 ekleniyor (arka plan olarak kalacak) ve ardından tube_2 asset’i attach edilerek onun üstünde gösterilmesi sağlanıyor: js Kopyala Düzenle var Tube2 = Container.expand(function () { var self = Container.call(this); // Önce background2'yi ekliyoruz (arka plan, daha önce eklenen child'lar daha önce çizilir) var bg2 = LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5 }); // İstenilen konumlandırmayı yapabilirsiniz; örneğin tube_2 ile aynı merkezde olacak şekilde: bg2.x = 0; bg2.y = 0; self.addChild(bg2); // Sonra tube_2 görselini ekleyelim; böylece tube_2, bg2'nin üstünde çizilir. var tubeGraphics = self.attachAsset('tube_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; // Arka planla aynı hızda hareket edecek self.zIndex = 2000; // Diğer objelerin üstünde görünmesi için self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); Bu şekilde tube_2’nin kendi container’ı içerisinde background2 de yer aldığı için, tube_2 görseli background2’nin üstünde çizilecektir.
User prompt
now make background2 visivle it disappeared
User prompt
make background2 child of tube_2
User prompt
make tube_2 visible on background2
User prompt
move tube_2 spaw point 30 pixel up
User prompt
after fade out spawn tube_2 at the top of the screen and make it move fast as background2
User prompt
Please fix the bug: 'ReferenceError: rotatedTube is not defined' in or related to this line: 'if (rotatedTube && rotatedTube.update) {' Line Number: 455
User prompt
rotated tube hakkında her şeyi sil
User prompt
rotated tube sadece bir kez spawn olsun bir daha spawn olmasın
Code edit (2 edits merged)
Please save this source code
User prompt
/**** Assets ****/ LK.init.shape('overlay', {width:2048, height:2732, color:0x000000, shape:'box'}); LK.init.image('background', {width:2048, height:2732.07, id:'6758971de1c6df8afc3f801b'}); LK.init.image('background2', {width:2048, height:2850, id:'67d87d2ced4e4720c972d0f7'}); LK.init.image('coin', {width:150, height:150, id:'67d58381540f369ec40716a5'}); LK.init.image('control', {width:300, height:10, id:'67d757ae885017473a98979d'}); LK.init.image('counter_background', {width:135, height:135, id:'67d757ae885017473a98979c'}); LK.init.image('enemy', {width:150, height:150, id:'67589498e1c6df8afc3f7fdf', flipX:1}); LK.init.image('flyin_enemy', {width:150, height:165, id:'67d6cc20228891638f6d62af', flipX:1}); LK.init.image('heart', {width:100, height:100, id:'67d966dd24ccde20f6adb0eb'}); LK.init.image('particle', {width:100, height:100, id:'67d62caff0905a2251a97ad1'}); LK.init.image('player', {width:150, height:150, id:'67589443e1c6df8afc3f7fd5'}); LK.init.image('tup_1', {width:250, height:375, id:'67d76073885017473a989801'}); LK.init.image('weapon', {width:120, height:120, id:'67d579ab540f369ec4071660'}); /**** Classes ****/ // Coin, Enemy, FlyinEnemy, Player, Tube, Weapon sınıfları (senin kodunla aynı, kısaltmadım) // Arka plan 1 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; } }; }); // Arka plan 2 (Mirrored) var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); // Normal var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); // Mirror 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.zIndex = 10; // Düşük zIndex 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; } }; }); /**** Initialize Game ****/ var game = new LK.Game({ width: 2048, height: 2732, backgroundColor: 0x000000 }); /**** Global Variables ****/ var rotatedTube; var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; var hearts = []; game.controlActive = false; var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var clearTriggered = false; var stopSpawn = false; /**** Fade Effect Function ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) return; game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; // Fade-Out: overlay.alpha 0 -> 1 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]); } // Arka plan 2'yi game container'a ekliyoruz createScrollingBackground2(); // Tek seferlik rotated tube spawn if (!rotatedTube) { rotatedTube = new Container(); var rotatedTubeGraphics = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); rotatedTubeGraphics.rotation = Math.PI; rotatedTube.addChild(rotatedTubeGraphics); rotatedTube.x = 2048 / 2; rotatedTube.y = 100; rotatedTube.speed = 2; rotatedTube.zIndex = 2000; // Arka planın önünde rotatedTube.update = function () { this.x -= this.speed; if (this.x + 125 < 0) { this.x = 2048; } }; // *** Dikkat: rotatedTube da game’e ekleniyor (aynı parent) *** game.addChild(rotatedTube); } // Fade-In: background2 alpha 0 -> 1 var fadeInDuration = 500; var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { // game.scrollingBg2 container'ı var if (game.scrollingBg2) { game.scrollingBg2.alpha = currentStep / steps; } currentStep++; } else { LK.clearInterval(fadeInInterval); if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Artık sadece background2 ve rotatedTube var // Update: bu ikisini döngüde güncelle game.update = function () { // ScrollingBackground2 if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Rotated tube if (rotatedTube && rotatedTube.update) { rotatedTube.update(); } // İsterseniz bu sahnede başka objeler de ekleyebilirsiniz // ama spawn durduğundan yeni enemy vb. gelmez // zIndex sıralaması game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); }; } }, fadeInStepTime); } }, stepTime); } /**** createScrollingBackground2 ****/ function createScrollingBackground2() { var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; // *** Önemli: Stage yerine game’e ekliyoruz *** game.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; } /**** 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 control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); control.x = 0; control.y = -177.5; tube.addChild(control); control.update = function () { if (coinCounter >= 1 && player.intersects(control)) { game.controlActive = true; for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj !== rotatedTube && obj.update) { obj.update = function () {}; } } LK.setTimeout(function () { player.destroy(); }, 330); enhancedFadeEffect(); } }; if (!stopSpawn) { LK.setTimeout(spawnTube, 15000); } } spawnTube(); /**** Arka Plan 1 ve Oyuncu ****/ var scrollingBackground = new ScrollingBackground(); game.addChild(scrollingBackground); var player = new Player(); player.x = 2048 / 2 - 30; player.y = 2732 / 2 - 7; game.addChild(player); /**** 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 - 60; counterBackground.y = 40; var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = LK.gui.top.width / 2 - 83; 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 + 280; heart.y = 50; hearts.push(heart); } /**** Flyin Enemy Spawn (devre dışı) ****/ function spawnFlyinEnemy() { if (stopSpawn) return; var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { if (stopSpawn) return; var flyinEnemy = new FlyinEnemy(); flyinEnemy.x = 2048; flyinEnemy.y = 449; flyinEnemy.zIndex = 10; game.addChild(flyinEnemy); flyinEnemies.push(flyinEnemy); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); /**** Oyun Döngüsü ****/ game.update = function () { // Normal update (fade öncesi) scrollingBackground.update(); player.update(); if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Tüp, enemy vb. 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(); } } } } // Enemy spawn enemySpawnCounter++; if (!stopSpawn && enemySpawnCounter >= enemySpawnInterval) { // ... senin enemy spawn kontrolün ... enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random()*100)+30; } // Rotated tube (fade öncesi var mı diye?) if (rotatedTube && rotatedTube.update) { rotatedTube.update(); } // Z-index sıralama game.children.sort(function(a,b){ return (a.zIndex||0)-(b.zIndex||0); }); // Enemy, FlyinEnemy çarpışma vb. // ... }; game.down = function (x, y, obj) { // Silah fırlatma ve jump // ... }; LK.stage.addChild(game);
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'rotatedTube.addChild(rotatedTubeGraphics);' Line Number: 284
User prompt
/**** * Assets ****/ LK.init.shape('overlay', {width:2048, height:2732, color:0x000000, shape:'box'}); LK.init.image('background', {width:2048, height:2732.07, id:'67589498e1c6df8afc3f801b'}); LK.init.image('background2', {width:2048, height:2850, id:'67d87d2ced4e4720c972d0f7'}); LK.init.image('coin', {width:150, height:150, id:'67d58381540f369ec40716a5'}); LK.init.image('control', {width:300, height:10, id:'67d757ae885017473a98979d'}); LK.init.image('counter_background', {width:135, height:135, id:'67d757ae885017473a98979c'}); LK.init.image('enemy', {width:150, height:150, id:'67589498e1c6df8afc3f7fdf', flipX:1}); LK.init.image('flyin_enemy', {width:150, height:165, id:'67d6cc20228891638f6d62af', flipX:1}); LK.init.image('heart', {width:100, height:100, id:'67d966dd24ccde20f6adb0eb'}); LK.init.image('particle', {width:100, height:100, id:'67d62caff0905a2251a97ad1'}); LK.init.image('player', {width:150, height:150, id:'67589443e1c6df8afc3f7fd5'}); LK.init.image('tup_1', {width:250, height:375, id:'67d76073885017473a989801'}); LK.init.image('weapon', {width:120, height:120, id:'67d579ab540f369ec4071660'}); /**** * Classes ****/ // Coin sınıfı 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; }; }); // Düşman sınıfı 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(); } }; }); // Uçan düşman sınıfı 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Oyuncu sınıfı 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.zIndex = 20; self.hearts = 3; self.update = function () { 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.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(); } if (self.hearts <= 0) { self.destroy(); } }; }); // Arka plan sınıfı 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; } }; }); // Mirrored arka plan 2 için sınıf var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); // İlk background2 parçası (normal) var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); // İkinci background2 parçası (mirror) 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; } }; }); // Tüp sınıfı 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(); } }; }); // Silah sınıfı 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 }); /**** * Global Variables ****/ var rotatedTube; // Tek sefer spawn edilecek var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; var hearts = []; game.controlActive = false; var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var clearTriggered = false; var stopSpawn = false; // Fade sonrası tüm spawnlar duracak /**** * Fade Effect Function (Without Tween plugin) ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; // Fade-Out: overlay.alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Durdur: spawn işlemlerini engelle stopSpawn = true; // Tüm game objelerini temizle while (game.children.length > 0) { game.removeChild(game.children[0]); } // Mirrored background2'yi eklemek için ScrollingBackground2 kullanıyoruz createScrollingBackground2(); // Tek seferlik rotated tube spawn (eğer henüz spawn edilmediyse) if (!rotatedTube) { rotatedTube = new Container(); var rotatedTubeGraphics = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); rotatedTubeGraphics.rotation = Math.PI; // 180° döndür rotatedTube.addChild(rotatedTubeGraphics); rotatedTube.x = 2048 / 2; rotatedTube.y = 100; rotatedTube.speed = 2; rotatedTube.update = function () { this.x -= this.speed; if (this.x + 125 < 0) { this.x = 2048; } }; game.addChild(rotatedTube); } // Fade-In: ScrollingBackground2 (game.scrollingBg2) alpha 0 -> 1 // Ayarlamak için, setInterval ile alpha artışını sağlayın 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); } game.isFading = false; game.fadeCompleted = true; // Update döngüsünü, sadece yeni sahnedeki objeleri güncelleyecek şekilde ayarlıyoruz. game.update = function () { if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } if (rotatedTube && rotatedTube.update) { rotatedTube.update(); } }; } }, fadeInStepTime); } }, stepTime); } /**** * Yardımcı Fonksiyon: ScrollingBackground2 Oluştur ****/ function createScrollingBackground2() { var scrollingBg2 = new ScrollingBackground2(); // Başlangıçta alfa 0 olsun, fade in ile artacak scrollingBg2.alpha = 0; LK.stage.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; } /**** * Tube Spawn (her 15 saniyede bir) ****/ function spawnTube() { if (stopSpawn) { return; } // Eğer fade sonrası yeni sahnede isek spawn yapma var tube = new Tube(); tube.x = 2048 + 125; tube.y = 2732 / 2 - 120; game.addChild(tube); 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 (coinCounter >= 1 && player.intersects(control)) { game.controlActive = true; // Freeze game (bu bölüm artık yeni sahneye müdahale etmesin) for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj !== rotatedTube && obj.update) { obj.update = function () {}; } } LK.setTimeout(function () { player.destroy(); }, 330); enhancedFadeEffect(); } }; 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 - 7; /**** * 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 - 60; counterBackground.y = 40; var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = LK.gui.top.width / 2 - 83; 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 + 280; heart.y = 50; hearts.push(heart); } /**** * Flyin Enemy Spawn - Devre dışı bırakılıyor (fade sonrası) ****/ function spawnFlyinEnemy() { if (stopSpawn) { return; } var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { if (stopSpawn) { return; } var flyinEnemy = new FlyinEnemy(); flyinEnemy.x = 2048; flyinEnemy.y = 449; flyinEnemy.zIndex = 10; game.addChild(flyinEnemy); flyinEnemies.push(flyinEnemy); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); /**** * Oyun Döngüsü ****/ game.update = function () { // Fade öncesi normal güncelleme: arka plan, oyuncu, tube spawn, düşmanlar, çarpışma kontrolleri vb. 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 (!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; } if (game.rotatedTube && game.rotatedTube.update) { game.rotatedTube.update(); } game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); for (var j = enemies.length - 1; j >= 0; 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; 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--) { 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])) { var coin = new Coin(); coin.x = flyinEnemies[n].x + 60; coin.y = flyinEnemies[n].y + 130; 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 + 60; particleEffect.y = flyinEnemies[n].y + 130; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && 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); } } if (coinCounter > 1 && !clearTriggered) { for (var t = 0; t < game.children.length; t++) { var tube = game.children[t]; if (tube instanceof Tube) { var tubeTop = tube.y - 187.5; var playerBottom = player.y + 75; var horizontalDistance = Math.abs(player.x - tube.x); if (playerBottom >= tubeTop && playerBottom <= tubeTop + 20 && horizontalDistance < 115) { clearTriggered = true; stopSpawn = true; 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(); }, 400); break; } } } } }; game.down = function (x, y, obj) { if (player.isJumping) { 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); function createScrollingBackground2() { var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; LK.stage.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; }
User prompt
Aşağıdaki örnek, fade‐in tamamlandıktan sonra oyundaki tüm objeleri (enemy, flyin enemy, player, coin, tube vb.) yok edip, game container’ına yalnızca background2 ve rotated tube ekleyerek onların sola doğru güncel olarak hareket etmesini sağlayacak şekilde güncellendi. Bu örnekte: Fade-Out Aşamasında: Game container’ın tüm çocukları temizleniyor. (Not: Eğer LK.Game içinde removeAllChildren() fonksiyonu yoksa, while döngüsüyle tüm çocukları kaldırabilirsiniz.) Yeni Objelerin Eklenmesi: background2 ve rotated tube, game container’a ekleniyor. Her iki obje için de update fonksiyonu tanımlanıyor; background2 için basit bir sola kayma ve ekran dışına çıktığında tekrar sağa setleme, rotated tube için de aynı mantık uygulanıyor. Update Döngüsü Yeniden Tanımlanıyor: Fade‐in tamamlandığında, game.update fonksiyonu yalnızca game.container içindeki objelerin update fonksiyonlarını çağıracak şekilde yeniden tanımlanıyor. Aşağıdaki kodu deneyebilirsiniz: js Kopyala Düzenle function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; // Birden fazla fade etkisini önle } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; // 500ms fade out/in süresi var stepTime = duration / steps; var currentStep = 0; // Fade-Out Aşaması: overlay'nin alfa değeri artıyor var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Tüm oyun objelerini temizle (freeze etkisi kaldırılıyor) while (game.children.length > 0) { game.removeChild(game.children[0]); } // background2'yi oluşturup game container'a ekle (sola doğru hareket edecek) var background2 = LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5 }); background2.x = 2048 / 2; background2.y = 2732 / 2; background2.width = 2048; background2.height = 2732; background2.alpha = 0; // Basit sola kayma: ekranın solundan çıkınca tekrar sağa gel background2.update = function () { this.x -= 2; if (this.x + this.width < 0) { this.x = 2048; } }; game.addChild(background2); // Rotated tube'u oluşturup game container'a ekle rotatedTube = new Container(); var rotatedTubeGraphics = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); rotatedTubeGraphics.rotation = Math.PI; // 180° döndür rotatedTube.addChild(rotatedTubeGraphics); rotatedTube.x = 2048 / 2; rotatedTube.y = 100; rotatedTube.speed = 2; // background2 hızıyla uyumlu rotatedTube.update = function () { this.x -= this.speed; // Ekranın solundan çıkarsa, yeniden sağa set et (örnek mantık) if (this.x + 125 < 0) { this.x = 2048; } }; game.addChild(rotatedTube); // Fade-In Aşaması: background2'nin alfa değeri artıyor var fadeInDuration = 500; // 500ms fade-in süresi var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { background2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); // Fade-In tamamlandıktan sonra overlay kaldırılıyor if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Artık sadece background2 ve rotated tube game container'da var // Game update döngüsünü yalnızca bu iki objeyi güncelleyecek şekilde yeniden tanımlıyoruz. game.update = function () { for (var i = 0; i < game.children.length; i++) { if (game.children[i].update) { game.children[i].update(); } } }; } }, fadeInStepTime); } }, stepTime); } Açıklamalar Tüm Objelerin Temizlenmesi: Fade-out tamamlandığında, while (game.children.length > 0) { game.removeChild(game.children[0]); } ile game container’daki tüm objeler temizleniyor. Böylece freeze etkisi kaldırılıyor. Objelerin Game Container’a Eklenmesi: background2 ve rotated tube, artık doğrudan game container’a ekleniyor. Bu sayede game.update fonksiyonu içerisinde update ediliyorlar. Update Fonksiyonunun Yeniden Tanımlanması: Fade-in tamamlandığında, game.update yalnızca game.children (yani background2 ve rotated tube) üzerinde çalışıyor; böylece diğer objelerden kaynaklı herhangi bir güncelleme (örneğin enemy spawn veya çarpışma kontrolleri) devre dışı bırakılmış oluyor.
User prompt
Aşağıdaki örnekte, orijinal freeze kodunun oyun içindeki tüm objelerin update fonksiyonlarını kapatmasından dolayı background2 ve rotated tube’un güncellenip sola doğru hareket etmediği görülüyor. Freeze efektinin yalnızca gameplay kısmını dondurmasını ve fade‐out başladığı anda (yani overlay animasyonu başladığında) bu dondurmanın kaldırılmasını sağlamak için; Freeze İşlemini kontrol tetiklendiğinde uygulamak yerine, fade‐out başladığında game container’ı temizleyerek (yani freeze efektini sonlandırarak) background2 ve rotated tube’u sahneye (LK.stage) ekleyin. Böylece onların update fonksiyonları normal çalışmaya devam eder. Background2 ve Rotated Tube’yu game container’dan ziyade doğrudan LK.stage’e ekleyin, böylece game.children içindeki freeze etkisinden bağımsız olurlar. Aşağıdaki kod örneğinde freeze efektinin kaldırıldığı, fade‐out başladığı anda game.children temizlendiği ve ardından background2 ile rotated tube normal güncelleme döngüsünde sola doğru hareket eder hale getirildiği gösterilmiştir: js Kopyala Düzenle function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; // Birden fazla fade efektini önle } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; // 500ms fade out/in süresi var stepTime = duration / steps; var currentStep = 0; // Fade-Out Aşaması: Overlay'nin alfa değeri artıyor var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Freeze efektini burada kaldırmak için game container içindeki tüm objeleri temizleyin. // Böylece artık oyun objelerinin update fonksiyonları dondurulmuş olmaz. while (game.children.length > 0) { game.removeChild(game.children[0]); } // Background2'yi oluşturup LK.stage'e ekleyin (doğrudan stage'de olduğundan update/dönüş animasyonu devam eder) var background2 = LK.getAsset('background2', { anchorX: 0.5, anchorY: 0.5 }); background2.x = 2048 / 2; background2.y = 2732 / 2; background2.width = 2048; background2.height = 2732; background2.alpha = 0; if (!background2.parent) { LK.stage.addChild(background2); } // Rotated tube'u oluşturup stage'e ekleyin rotatedTube = new Container(); var rotatedTubeGraphics = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); rotatedTubeGraphics.rotation = Math.PI; // 180° döndür rotatedTube.addChild(rotatedTubeGraphics); rotatedTube.x = 2048 / 2; rotatedTube.y = 100; rotatedTube.speed = 2; // background2 hızıyla uyumlu rotatedTube.zIndex = 1000; LK.stage.addChild(rotatedTube); // Rotated tube update fonksiyonu, stage update döngüsünde çağrılmalı rotatedTube.update = function () { this.x -= this.speed; }; // Fade-In Aşaması: Background2'nin alfa değeri 0'dan 1'e çıkarılıyor var fadeInDuration = 500; var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { background2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); // Fade-In tamamlandıktan sonra overlay kaldırılıyor if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Artık ekranda sadece background2 ve sola hareket eden rotated tube var. } }, fadeInStepTime); } }, stepTime); } Açıklamalar Freeze Etkisini Kaldırma: Önceden kontrol tetiklenince tüm game.children objelerinin update fonksiyonu boşaltılıyordu. Bu yöntem background2 ve rotated tube gibi objelerin hareketini de engelliyordu. Yukarıdaki örnekte fade‐out başladığında game container tamamen temizlenerek freeze etkisi kaldırılır. Stage’e Eklenen Objeler: Background2 ve rotated tube, artık doğrudan LK.stage’e ekleniyor. Böylece game container’ın freeze etkisinden bağımsız olarak kendi update fonksiyonlarıyla sola doğru hareket edebiliyor.
/**** * Classes ****/ /**** Classes ****/ // Coin sınıfı 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; }; }); // Düşman sınıfı 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(); } }; }); // Uçan düşman sınıfı 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Oyuncu sınıfı 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.zIndex = 20; self.hearts = 3; self.update = function () { 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.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(); } if (self.hearts <= 0) { self.destroy(); } }; }); // Arka plan sınıfı 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; } }; }); // Mirrored arka plan 2 için sınıf 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; } }; }); // Tüp sınıfı 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 for spawning tube_2 at the top of the screen var Tube2 = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tube_2', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 2; // Match the speed of background2 self.zIndex = 2000; // Ensure it appears in front of the background self.update = function () { self.x -= self.speed; if (self.x < -self.width) { self.destroy(); } }; }); // Silah sınıfı 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 ****/ /**** Initialize Game ****/ var game = new LK.Game({ width: 2048, height: 2732, backgroundColor: 0x000000 }); /**** * Game Code ****/ /**** Global Variables ****/ /**** Assets ****/ // Removed rotatedTube variable var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; var hearts = []; game.controlActive = false; var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var clearTriggered = false; var stopSpawn = false; // Fade sonrası spawn duracak /**** Fade Effect Function ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; } game.isFading = true; var overlay = LK.getAsset('overlay', { anchorX: 0, anchorY: 0 }); overlay.alpha = 0; if (!overlay.parent) { LK.stage.addChild(overlay); } var steps = 20; var duration = 500; var stepTime = duration / steps; var currentStep = 0; // Fade-Out: overlay.alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; stopSpawn = true; // Spawn işlemleri durdu while (game.children.length > 0) { game.removeChild(game.children[0]); } // Mirrored background2 ekle createScrollingBackground2(); // Spawn Tube2 at the top of the screen after fade out var tube2 = new Tube2(); tube2.x = 2048 + tube2.width / 2; tube2.y = tube2.height / 2 - 30; game.addChild(tube2); // Fade-In: ScrollingBackground2'nin alpha 0 -> 1 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); } game.isFading = false; game.fadeCompleted = true; // Update döngüsünü, sadece yeni sahnedeki objeleri güncelleyecek şekilde sınırla game.update = function () { if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Removed rotatedTube update call }; } }, fadeInStepTime); } }, stepTime); } /**** Yardımcı Fonksiyon: ScrollingBackground2 Oluştur ****/ function createScrollingBackground2() { var scrollingBg2 = new ScrollingBackground2(); scrollingBg2.alpha = 0; LK.stage.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; // Add tube_2 to scrollingBg2 to ensure it is visible on background2 var tube2 = new Tube2(); tube2.x = 2048 + tube2.width / 2; tube2.y = tube2.height / 2 - 30; tube2.addChild(scrollingBg2); } /**** 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 control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); control.x = 0; control.y = -177.5; tube.addChild(control); control.update = function () { if (coinCounter >= 1 && player.intersects(control)) { game.controlActive = true; 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(); } }; 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 - 7; /**** 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 - 60; counterBackground.y = 40; var scoreText = new Text2('0', { size: 80, fill: 0xFFFFFF }); LK.gui.top.addChild(scoreText); scoreText.x = LK.gui.top.width / 2 - 83; 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 + 280; heart.y = 50; hearts.push(heart); } /**** Flyin Enemy Spawn (devre dışı) ****/ function spawnFlyinEnemy() { if (stopSpawn) { return; } var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { if (stopSpawn) { return; } var flyinEnemy = new FlyinEnemy(); flyinEnemy.x = 2048; flyinEnemy.y = 449; flyinEnemy.zIndex = 10; game.addChild(flyinEnemy); flyinEnemies.push(flyinEnemy); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); /**** 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 (!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); }); for (var j = enemies.length - 1; j >= 0; 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; 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--) { 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])) { var coin = new Coin(); coin.x = flyinEnemies[n].x + 60; coin.y = flyinEnemies[n].y + 130; 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 + 60; particleEffect.y = flyinEnemies[n].y + 130; game.addChild(particleEffect); LK.setTimeout(function () { particleEffect.destroy(); }, 150); flyinEnemies[n].destroy(); child.destroy(); flyinEnemies.splice(n, 1); break; } } if (flyinEnemies[n] && 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); } } if (coinCounter > 1 && !clearTriggered) { for (var t = 0; t < game.children.length; t++) { var tube = game.children[t]; if (tube instanceof Tube) { var tubeTop = tube.y - 187.5; var playerBottom = player.y + 75; var horizontalDistance = Math.abs(player.x - tube.x); if (playerBottom >= tubeTop && playerBottom <= tubeTop + 20 && horizontalDistance < 115) { clearTriggered = true; stopSpawn = true; 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(); }, 400); break; } } } } }; game.down = function (x, y, obj) { if (player.isJumping) { 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);
===================================================================
--- original.js
+++ change.js
@@ -306,9 +306,9 @@
// Add tube_2 to scrollingBg2 to ensure it is visible on background2
var tube2 = new Tube2();
tube2.x = 2048 + tube2.width / 2;
tube2.y = tube2.height / 2 - 30;
- scrollingBg2.addChild(tube2);
+ tube2.addChild(scrollingBg2);
}
/**** Tube Spawn (her 15 saniyede bir) ****/
function spawnTube() {
if (stopSpawn) {
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