User prompt
Örnek Değişiklik: Mevcut kodunuzda enhancedFadeEffect fonksiyonunda rotated tube'ü eklediğiniz kısımda şu satırı: javascript Kopyala Düzenle game.addChild(game.rotatedTube); yerine, rotated tube'ü stage'e ekleyin: javascript Kopyala Düzenle game.rotatedTube.zIndex = 1000; // Yüksek bir z-index değeri atayın LK.stage.addChild(game.rotatedTube); Bu değişiklik, rotated tube'ün background2'nin üzerinde görünmesini sağlamalıdır. Eğer yine görünmezse, background2'nin eklenme sırasını ve alpha değerlerini de kontrol etmenizi öneririm.
User prompt
function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; // Prevent multiple fade effects and ensure single run } 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 duration var stepTime = duration / steps; var currentStep = 0; // Fade-Out: Alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Fade-out complete: add center background with alpha 0 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); } // Create a persistent rotated tube instead of using a temporary asset game.rotatedTube = new Container(); // Create a container for the tube var rotatedTubeGraphics = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); rotatedTubeGraphics.rotation = Math.PI; // Rotate 180 degrees game.rotatedTube.addChild(rotatedTubeGraphics); game.rotatedTube.x = 2048 / 2; game.rotatedTube.y = 100; game.rotatedTube.speed = 2; // Match background2 speed game.rotatedTube.zIndex = 20; // Ensure it's visible above other elements // Add the rotated tube to the game game.addChild(game.rotatedTube); // Define a custom update function for the rotated tube game.rotatedTube.update = function() { this.x -= this.speed; // No destruction logic here }; // Fade-In for background2: Alpha 0 -> 1 var fadeInDuration = 500; // 500ms fade-in duration var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { background2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); // Remove overlay after fade-in is complete if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Fade effect complete, ensure it doesn't repeat // Add scrolling and mirror effect to background2 createScrollingBackground2(); } }, fadeInStepTime); } }, stepTime); } // Modify the game.update function to ensure our rotated tube is updated // Add this code to the game.update function, anywhere before the end game.update = function() { // Keep all existing code... // Near the end of the function, add this check for the rotated tube if (game.rotatedTube && game.rotatedTube.update) { game.rotatedTube.update(); } // Rest of the existing 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 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; // Enemy ilk başta oyuncuya zarar verebilir 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; // FlyinEnemy de oyuncuya zarar verebilir 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; // Add hearts to the player self.update = function () { // Önce mevcut y değeri korunuyor (collision kontrolü için önceki frame değeri) self.prevY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Yerçekimi 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++; // Increment player death count // Destroy hearts based on the number of player deaths 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; } }; }); var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); // First background2 piece (normal) var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); // Second background2 piece (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 // Set backgroundColor to black }); /**** * Game Code ****/ // Global flag to prevent multiple fade effects game.isFading = false; game.fadeCompleted = false; // Ensure fade effect runs only once var flashActive = false; // Global flag to control flash effect activation /**** * Fade Effect Function (Without Tween plugin) * This function darkens the screen using the overlay asset over 0.5 seconds, then restores it over another 0.5 seconds. ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; // Prevent multiple fade effects and ensure single run } 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 duration var stepTime = duration / steps; var currentStep = 0; // Fade-Out: Alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Fade-out complete: add center background with alpha 0 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); } // Add tube asset rotated 180 degrees to the center top var tube = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); tube.x = 2048 / 2; tube.y = 100; // Position at the top center tube.rotation = Math.PI; // Rotate 180 degrees tube.speed = 5; // Set speed to match enemy's velocity tube.update = function () { tube.x -= tube.speed; if (tube.x + tube.width < 0) { tube.destroy(); } }; if (!tube.parent) { LK.stage.addChild(tube); } // Fade-In for background2: Alpha 0 -> 1 var fadeInDuration = 500; // 500ms fade-in duration var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { background2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); // Remove overlay after fade-in is complete if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Fade effect complete, ensure it doesn't repeat // Add scrolling and mirror effect to background2 createScrollingBackground2(); } }, fadeInStepTime); } }, stepTime); } /**** * Global Variables ****/ var coinCounter = 0; var flyinEnemies = []; var playerDeaths = 0; // Track the number of times the player has died var hearts = []; // Store heart assets for easy access game.controlActive = false; // Flag to ensure fade effect only triggers after control interaction var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var clearTriggered = false; var stopSpawn = false; // 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); // Kontrol asset'ini tüpün child'ı olarak ekleyin. var control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); // Kontrolün tüp içindeki konumu, tüpün üst kenarına denk gelecek şekilde ayarlanıyor. control.x = 0; // Tüpün merkezine göre control.y = -177.5; // Tüp yüksekliğinin yarısı kadar yukarı tube.addChild(control); // Activate control if score is 1 or greater control.update = function () { if (coinCounter >= 1 && player.intersects(control)) { // Set controlActive flag game.controlActive = true; // Freeze game for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } // Character disappears after 0.33 seconds (330ms) LK.setTimeout(function () { player.destroy(); }, 330); // Call the enhanced fade effect 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 */ 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; // Add three heart assets to the top-left corner 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 + 380; // Move hearts 100 pixels to the left from previous position heart.y = 55; // Move hearts 5 pixels up from previous position hearts.push(heart); // Store heart in the array } /* Uçan düşmanları oluştur */ function spawnFlyinEnemy() { var delay = Math.random() * 2000 + 2000; if (!stopSpawn) { 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 () { // Arka plan ve oyuncu güncellemesi scrollingBackground.update(); player.update(); // Update scrolling background2 if it exists if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Tube güncellemesi ve z-index sıralaması for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube) { child.update(); // Removed sorting from inside the loop } // Check for control activation if (child.children) { for (var c = 0; c < child.children.length; c++) { var subChild = child.children[c]; if (subChild.update) { subChild.update(); } } } } // Düşman spawn işlemleri 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; } // Sort game children by zIndex once per frame after all updates game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); // Normal düşman güncelleme & çarpışma kontrolü for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; // Bu enemy artık oyuncuya zarar veremez LK.effects.flashScreen(0xff0000, 750, 0.0001); // 750ms süren kırmızı flash 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; } } } // Uçan düşman güncelleme & çarpışma kontrolü 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); // 750ms süren kırmızı flash 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); } } // Coin güncelleme & çarpışma kontrolü 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); } } // --- Yeni Özellik --- // Eğer coinCounter 1'den fazla ise ve oyuncunun alt kenarı tüpün üst kenarıyla neredeyse hizalanıyorsa, // (player.y + 75) tüpün üst kenarı (tube.y - 187.5) ile arası 20 piksel veya daha azsa, // ve oyuncu ile tüp yatayda iyi hizalı (mesafe < 115) ise tetiklenecek. 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; // Tüm oyun objelerini dondur 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; } } } } }; // Dokunma/Mouse event: jump + weapon 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(); LK.stage.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; }
User prompt
move character 30 pixel left
User prompt
move character 100 pixel right
User prompt
move character 100 pixel right
User prompt
destroy the heart on the most left when character dies for the first time destroy the heart in the middle if character dies for 2. time if character dies for 3. time destroy the last heart
User prompt
move hearts 100 pixel left 5 pixel up
User prompt
move hearts 400 pixel right
User prompt
move hearts 600 pixel right
User prompt
move hearts 10 pixel down 30 pixel right
User prompt
move hearts 50 pixel right
User prompt
move hearts 100 pixel left
User prompt
move hearts 300 pixel left
User prompt
move heart 400 pixel left
User prompt
move hearts 400 pixel left
User prompt
move hearts 1200 pixel right
User prompt
move hearts to 600 pixel left
User prompt
heart asseti sol üste ve onun yanında bir tane yanındakinin yanına bir tane daha heart koy yani 3 tane hear yan yana sol üstte dursun
User prompt
Sorununuzun nedeni, oyuncunun global invulnerability (dokunulmazlık) mekanizmasının farklı enemy tiplerinden gelen çarpmaları birbirinden ayırarak saymaması. Bu mekanizma, oyuncu bir düşmandan zarar aldıktan sonra belirli bir süre (1 saniye) ek zarar almasını engelliyor; bu da farklı düşman tiplerinden gelen çarpmaların toplamda 4 darbe gibi görünmesine neden oluyor. Bunu çözmek için, oyuncunun loseHeart() fonksiyonundaki invulnerability kontrolünü kaldırıp, her çarpışmada (her enemy örneği için; enemy ya da flyin enemy) 1 kalp düşmesini sağlayabiliriz. Böylece her enemy (ve flyin enemy) yalnızca kendi canDamage bayrağı sayesinde tek seferlik hasar verecek, fakat farklı düşmanlar geldiğinde toplam hasar birbirine eklenecek. Aşağıdaki örnekte, oyuncunun loseHeart() fonksiyonu güncellenmiş ve global invulnerability mekanizması kaldırılmıştır: javascript Kopyala Düzenle 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; // Oyuncunun 3 kalbi var // Global invulnerability kaldırıldı self.update = function () { self.prevY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Yerçekimi 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; } }; // Her çağrıda kalp sayısını 1 azaltır self.loseHeart = function () { self.hearts--; if (self.hearts <= 0) { self.destroy(); } }; }); Ayrıca, her enemy (Enemy ve FlyinEnemy) sınıfına eklediğimiz "canDamage" bayrağı sayesinde, her enemy yalnızca ilk çarpışmada oyuncuya zarar verecek şekilde kontrol ediliyor: javascript Kopyala Düzenle // Enemy 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; // İlk başta oyuncuya zarar verebilir self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); Benzer şekilde: javascript Kopyala Düzenle // FlyinEnemy 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; // İlk başta oyuncuya zarar verebilir self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); Son olarak, oyun döngüsünde her enemy ve flyin enemy ile çarpışma kontrolünü yaparken, oyuncu ile temas eden enemy’nin canDamage değeri true ise: Kırmızı flash efekti (750 ms sürecek) tetiklenir, Oyuncu loseHeart() çağrısı ile hasar alır, İlgili enemy’nin canDamage değeri false yapılır. Örneğin, Enemy için: javascript Kopyala Düzenle for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Enemy henüz hasar vermediyse if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; // Bu enemy bir daha hasar veremez LK.effects.flashScreen(0xff0000, 750, 0.0001); // 750 ms süren kırmızı flash player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } // Weapon ile çarpışma kontrolü (değişiklik yok) // ... } Aynı mantığı FlyinEnemy için de uygulayın. Bu güncellemelerle: Eğer oyuncu sadece Enemy ile çarpışırsa, toplam 3 farklı çarpışma (her enemy sadece bir kez hasar verir) sonucunda oyuncu yok olacaktır. Aynı şekilde, sadece FlyinEnemy ile çarpışırsa 3 darbe yeterli olacaktır. Farklı düşman tiplerinden gelen darbeler de toplam 3 hasar olarak hesaplanacaktır.
Code edit (1 edits merged)
Please save this source code
User prompt
1. Enemy ve FlyinEnemy Sınıflarına canDamage Özelliği Ekleyin Her enemy örneğine, oyuncuya zarar verebilme durumunu belirten bir özellik ekleyin. Bu özellik ilk başta true olsun; çarpışma gerçekleştiğinde false yapın. javascript Kopyala Düzenle // 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; // Enemy ilk başta oyuncuya zarar verebilir 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; // FlyinEnemy de oyuncuya zarar verebilir self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); 2. Çarpışma Kontrollerinde Sadece İlk Temas İşlensin ve Flash Süresini 100ms Yapın Game döngüsünde, her enemy ile oyuncu arasındaki çarpışmayı kontrol ederken önce enemy’nin canDamage özelliğini kontrol edin. Eğer true ise: Kırmızı flash efekti 100 ms sürecek şekilde tetikleyin. Oyuncuya zarar verin. Sonrasında enemy’nin canDamage değerini false yapın ki sonraki frame’lerde aynı enemy tekrar zarar vermesin. Enemy için: javascript Kopyala Düzenle for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Sadece enemy henüz oyuncuya zarar vermediyse kontrol edelim if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; // Bu enemy artık oyuncuya zarar veremez LK.effects.flashScreen(0xff0000, 100, 0.0001); // 100ms süren kırmızı flash player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } // Weapon ile çarpışma kontrolü (değişiklik yok) 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; } } } FlyinEnemy için: javascript Kopyala Düzenle for (var n = flyinEnemies.length - 1; n >= 0; n--) { flyinEnemies[n].update(); // Sadece flyinEnemy henüz oyuncuya zarar vermediyse kontrol edelim if (player.intersects(flyinEnemies[n]) && flyinEnemies[n].canDamage) { flyinEnemies[n].canDamage = false; LK.effects.flashScreen(0xff0000, 100, 0.0001); // 100ms süren kırmızı flash 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); } } Açıklama canDamage Özelliği: Enemy ve FlyinEnemy sınıflarına eklediğimiz canDamage özelliği, her düşmanın oyuncuya yalnızca bir kez zarar verebilmesini sağlar. İlk temasta true olan bu değer, çarpışma gerçekleştiğinde false olarak ayarlanır. Flash Süresi: LK.effects.flashScreen fonksiyonundaki ikinci parametre 100 ms olarak ayarlanmıştır. Böylece, enemy ile çarpışma sonucu ekran kırmızı flash efekti 100 ms sürecektir.
User prompt
Bir çözüm, flash efektini tetikleyen kodu, oyuncu henüz invulnerable değilken ilk çarpışmada çalıştırmak üzere bir flag ile kontrol etmek olabilir. Böylece efekt yalnızca ilk çarpışmada tetiklenir ve invulnerability süresi boyunca yeniden çağrılmaz. Ayrıca, flash efektinin süresini de ayarlayabilirsiniz. Örneğin, şöyle bir flag ekleyip kontrol edebilirsiniz: javascript Kopyala Düzenle // Global bir flag ekleyelim var flashActive = false; // Çarpışma kontrolünde: if (player.intersects(enemies[j])) { if (!flashActive) { flashActive = true; LK.effects.flashScreen(0xff0000, 10, 0.0001); // Kısa bir süre sonra flashActive'i sıfırlayalım LK.setTimeout(function() { flashActive = false; }, 50); // 50ms sonra yeniden flash yapılabilir } player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } Bu şekilde, flash efektinin invulnerability süresinde sürekli tetiklenmesi önlenir. Aynı yöntemi diğer çarpışmalar için de uygulayabilirsiniz.
Code edit (1 edits merged)
Please save this source code
User prompt
Ekrandaki kırmızı flaş süresini azaltmak için, LK.effects.flashScreen çağrısındaki süre parametrelerini düşürmeniz gerekiyor. Şu anda bu fonksiyon şu şekilde çağrılıyor: javascript Kopyala Düzenle LK.effects.flashScreen(0xff0000, 100, 0.5); Burada 100 değeri flaşın süresi (muhtemelen milisaniye cinsinden) ve 0.5 değeri de fade-out/in süresi olabilir. Eğer ekranın kırmızı kalma süresini saniyenin 10'da 1'i (yaklaşık 0.1 saniye) yapmak istiyorsanız, bu değerleri örneğin 10 ve 0.05 olarak değiştirebilirsiniz: javascript Kopyala Düzenle LK.effects.flashScreen(0xff0000, 10, 0.05); Bunu hem normal düşman hem de uçan düşman çarpışmaları için uygulayabilirsiniz. Örnek olarak: javascript Kopyala Düzenle // Normal düşman çarpışma kontrolü if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 10, 0.05); // Kırmızı flaş süresi 0.1 saniyeye ayarlandı player.loseHeart(); // Oyuncunun kalbi azalır if (player.hearts <= 0) { LK.showGameOver(); } } // Uçan düşman çarpışma kontrolü if (player.intersects(flyinEnemies[n])) { LK.effects.flashScreen(0xff0000, 10, 0.05); // Kırmızı flaş süresi 0.1 saniyeye ayarlandı player.loseHeart(); if (player.hearts <= 0) { LK.showGameOver(); } } Bu değişiklikle, oyuncu bir düşmanla temas ettiğinde ekran kırmızıya sadece 0.1 saniye sürecek, kısa ve ani bir flaş efekti oluşturacaktır. Eğer bu değerler istediğiniz etkiyi vermiyorsa, ince ayar yaparak (örneğin süreyi biraz daha artırarak veya azaltarak) ideal değeri bulabilirsiniz.
/**** * 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; // Enemy ilk başta oyuncuya zarar verebilir 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; // FlyinEnemy de oyuncuya zarar verebilir 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; // Add hearts to the player self.update = function () { // Önce mevcut y değeri korunuyor (collision kontrolü için önceki frame değeri) self.prevY = self.y; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Yerçekimi 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--; 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; } }; }); var ScrollingBackground2 = Container.expand(function () { var self = Container.call(this); // First background2 piece (normal) var bg1 = LK.getAsset('background2', { anchorX: 0, anchorY: 0 }); bg1.x = 0; bg1.y = 0; self.addChild(bg1); // Second background2 piece (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 // Set backgroundColor to black }); /**** * Game Code ****/ // Global flag to prevent multiple fade effects game.isFading = false; game.fadeCompleted = false; // Ensure fade effect runs only once var flashActive = false; // Global flag to control flash effect activation /**** * Fade Effect Function (Without Tween plugin) * This function darkens the screen using the overlay asset over 0.5 seconds, then restores it over another 0.5 seconds. ****/ function enhancedFadeEffect() { if (game.isFading || game.fadeCompleted || !game.controlActive) { return; // Prevent multiple fade effects and ensure single run } 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 duration var stepTime = duration / steps; var currentStep = 0; // Fade-Out: Alpha 0 -> 1 var fadeOutInterval = LK.setInterval(function () { if (currentStep < steps) { overlay.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeOutInterval); currentStep = 0; // Fade-out complete: add center background with alpha 0 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); } // Add tube asset rotated 180 degrees to the center top var tube = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); tube.x = 2048 / 2; tube.y = 100; // Position at the top center tube.rotation = Math.PI; // Rotate 180 degrees tube.speed = 5; // Set speed to match enemy's velocity tube.update = function () { tube.x -= tube.speed; if (tube.x + tube.width < 0) { tube.destroy(); } }; if (!tube.parent) { LK.stage.addChild(tube); } // Fade-In for background2: Alpha 0 -> 1 var fadeInDuration = 500; // 500ms fade-in duration var fadeInStepTime = fadeInDuration / steps; var fadeInInterval = LK.setInterval(function () { if (currentStep < steps) { background2.alpha = currentStep / steps; currentStep++; } else { LK.clearInterval(fadeInInterval); // Remove overlay after fade-in is complete if (overlay.parent) { overlay.parent.removeChild(overlay); } game.isFading = false; game.fadeCompleted = true; // Fade effect complete, ensure it doesn't repeat // Add scrolling and mirror effect to background2 createScrollingBackground2(); } }, fadeInStepTime); } }, stepTime); } /**** * Global Variables ****/ var coinCounter = 0; var flyinEnemies = []; game.controlActive = false; // Flag to ensure fade effect only triggers after control interaction var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; var clearTriggered = false; var stopSpawn = false; // 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); // Kontrol asset'ini tüpün child'ı olarak ekleyin. var control = LK.getAsset('control', { anchorX: 0.5, anchorY: 0.5 }); // Kontrolün tüp içindeki konumu, tüpün üst kenarına denk gelecek şekilde ayarlanıyor. control.x = 0; // Tüpün merkezine göre control.y = -177.5; // Tüp yüksekliğinin yarısı kadar yukarı tube.addChild(control); // Activate control if score is 1 or greater control.update = function () { if (coinCounter >= 1 && player.intersects(control)) { // Set controlActive flag game.controlActive = true; // Freeze game for (var i = 0; i < game.children.length; i++) { var obj = game.children[i]; if (obj.update) { obj.update = function () {}; } } // Character disappears after 0.33 seconds (330ms) LK.setTimeout(function () { player.destroy(); }, 330); // Call the enhanced fade effect 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 - 200; player.y = 2732 / 2 - 7; /* Skor GUI */ 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; // Add three heart assets to the top-left corner 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 + 480; // Move hearts 400 pixels to the right heart.y = 60; // Move hearts 10 pixels down } /* Uçan düşmanları oluştur */ function spawnFlyinEnemy() { var delay = Math.random() * 2000 + 2000; if (!stopSpawn) { 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 () { // Arka plan ve oyuncu güncellemesi scrollingBackground.update(); player.update(); // Update scrolling background2 if it exists if (game.scrollingBg2 && game.scrollingBg2.update) { game.scrollingBg2.update(); } // Tube güncellemesi ve z-index sıralaması for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube) { child.update(); // Removed sorting from inside the loop } // Check for control activation if (child.children) { for (var c = 0; c < child.children.length; c++) { var subChild = child.children[c]; if (subChild.update) { subChild.update(); } } } } // Düşman spawn işlemleri 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; } // Sort game children by zIndex once per frame after all updates game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); // Normal düşman güncelleme & çarpışma kontrolü for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j]) && enemies[j].canDamage) { enemies[j].canDamage = false; // Bu enemy artık oyuncuya zarar veremez LK.effects.flashScreen(0xff0000, 750, 0.0001); // 750ms süren kırmızı flash 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; } } } // Uçan düşman güncelleme & çarpışma kontrolü 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); // 750ms süren kırmızı flash 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); } } // Coin güncelleme & çarpışma kontrolü 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); } } // --- Yeni Özellik --- // Eğer coinCounter 1'den fazla ise ve oyuncunun alt kenarı tüpün üst kenarıyla neredeyse hizalanıyorsa, // (player.y + 75) tüpün üst kenarı (tube.y - 187.5) ile arası 20 piksel veya daha azsa, // ve oyuncu ile tüp yatayda iyi hizalı (mesafe < 115) ise tetiklenecek. 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; // Tüm oyun objelerini dondur 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; } } } } }; // Dokunma/Mouse event: jump + weapon 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(); LK.stage.addChild(scrollingBg2); game.scrollingBg2 = scrollingBg2; }
===================================================================
--- original.js
+++ change.js
@@ -362,9 +362,9 @@
anchorX: 0.5,
anchorY: 0.5
});
LK.gui.top.addChild(heart);
- heart.x = 50 + i * 110 + 80; // Move hearts 600 pixels to the right
+ heart.x = 50 + i * 110 + 480; // Move hearts 400 pixels to the right
heart.y = 60; // Move hearts 10 pixels down
}
/* Uçan düşmanları oluştur */
function spawnFlyinEnemy() {
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