User prompt
tüpe üstten girmek iAşağıdaki kodda, tüp ile temas kontrolü güncellendi: X ekseni toleransı 110 piksel yerine 115 piksel olarak belirlendi. Eğer oyuncunun alt kısmı (player.y + 75) ile tüpün üst kısmı (tube.y - 187.5) arasındaki fark 15 piksellik toleransın altındaysa ve x eksenindeki mesafe 115 pikselden küçükse, 0.05 saniye (50 ms) sonra oyuncu (karakter) yok ediliyor. Aşağıdaki güncellenmiş kodu inceleyebilirsiniz: js Kopyala Düzenle /**** * Assets ****/ LK.init.image('background', {width:2048, height:2732.07, id:'6758971de1c6df8afc3f801b'}); LK.init.image('coin', {width:150, height:150, id:'67d58381540f369ec40716a5'}); 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('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 ****/ // Define a class for coins var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 5; // Coin, tüpün üzerinde çıkması için tüpten daha yüksek z-index'e sahip olsun self.zIndex = 15; self.update = function () { self.x -= self.velocity; }; }); // Define a class for enemies 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for flying enemies 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for the player character 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; // Player, diğerlerinden daha üstte görünmeli self.zIndex = 20; self.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Gravity if (self.y >= 2732 / 2 - 3) { // Use the initial player.y value self.y = 2732 / 2 - 9; // Land 6 pixels higher than initial position self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; }); // ScrollingBackground: orijinal ve mirrored arka plan var ScrollingBackground = Container.expand(function () { var self = Container.call(this); // Orijinal arka plan self.bg1 = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); self.bg1.x = 0; self.bg1.y = 0; self.addChild(self.bg1); // Mirrored arka plan (flipX) 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); // Arka plan kayma hızı 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; } }; }); // Define a class for tubes var Tube = Container.expand(function () { var self = Container.call(this); var tubeGraphics = self.attachAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); // Tube hızını enemy ile aynı yapıyoruz self.speed = 5; // Tube, diğer nesnelerin arkasında kalacak şekilde en düşük z-index'e sahip olsun self.zIndex = 0; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for the weapon 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; // Yok etme kontrolü 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: 0x87CEEB }); /**** * Global Variables ****/ var coinCounter = 0; var flyinEnemies = []; var coins = []; var enemies = []; var enemySpawnInterval = Math.floor(Math.random() * 100) + 30; var enemySpawnCounter = 0; // Flag to ensure the clear effect triggers only once per collision event var clearTriggered = false; // Flag to stop tube and enemy spawn after tube collision var stopSpawn = false; /**** * Game Code ****/ // Tube spawn fonksiyonu (her 15 saniyede bir spawn oluyor) function spawnTube() { if (stopSpawn) { return; } var tube = new Tube(); // Tube sağ kenardan spawn olsun tube.x = 2048 + 125; tube.y = 2732 / 2 - 120; game.addChild(tube); LK.setTimeout(spawnTube, 15000); } spawnTube(); var centerText = new Text2('0', { size: 200, fill: 0xFF0000, anchorX: 0.5, anchorY: 0.5 }); centerText.x = 2048 / 2; centerText.y = 2732 / 2; game.addChild(centerText); /* 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; /* Uçan düşmanları oluştur */ function spawnFlyinEnemy() { var delay = Math.random() * 2000 + 2000; // 2000-4000 ms 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(); // 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(); game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); } } // 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) { // Tube ile çakışma kontrolü 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); // 100 ms delay: tube spawnundan sonra enemy spawn } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } // Normal düşmanların güncellenmesi ve çarpışma kontrolü for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Weapon çarpışması: coin üretimi 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; } } } // Flying enemy güncellemesi ve çarpışma kontrolü for (var n = flyinEnemies.length - 1; n >= 0; n--) { flyinEnemies[n].update(); if (player.intersects(flyinEnemies[n])) { LK.effects.flashScreen(0xff0000, 1000); 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üncellemesi ve ç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++; centerText.setText(coinCounter.toString()); 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 karakterin skoru 1 veya daha fazla ise ve karakter Tube'nin üst kısmına giriyorsa, // (Player'nin alt kısmı: player.y + 75, Tube'nin üst kısmı: tube.y - 187.5) // x eksenindeki tolerans 115 yerine 110 piksel yerine 115 olarak kontrol ediliyor. if (coinCounter >= 1 && !clearTriggered) { for (var t = 0; t < game.children.length; t++) { var tube = game.children[t]; if (tube instanceof Tube) { if (Math.abs((player.y + 75) - (tube.y - 187.5)) < 15 && Math.abs(player.x - tube.x) < 115) { clearTriggered = true; stopSpawn = true; // Yeni tüp ve enemy spawnları durdurulsun // 0.05 saniye sonra oyuncu yok edilsin LK.setTimeout(function () { player.destroy(); }, 50); } } } } }; // 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(); }; // Önemli: Oyunu çalıştırmayı unutmayın LK.stage.addChild(game); Açıklamalar: Tolerans Güncellemesi: Tube ile temas kontrolü sırasında, x ekseni toleransı Math.abs(player.x - tube.x) < 115 olarak ayarlandı (önceki değere göre biraz genişletildi). Karakterin Yok Edilmesi: Eğer oyuncunun alt kısmı (player.y + 75) ile tüpün üst kısmı (tube.y - 187.5) arasındaki fark 15 pikselin altında ve x eksenindeki mesafe 115 piksellik toleransın altındaysa, clearTriggered ve stopSpawn flag'ları true yapılır. Ardından 0.05 saniye sonra (50 ms) oyuncu player.destroy() ile yok edilir. Bu modifikasyonlarla, oyuncu tüpe üstten girdiğinde belirlenen toleranslarda temas algılanır ve 0.05 saniye sonra oyuncu yok edilir.çin
User prompt
karakter tüpe üstten değdiğinde 0.05 saniye sonra yok olsun
User prompt
karakter tüpe üstten değdiği zaman her şeyi yok etmek yerine her şeyin konumunu dondur
Code edit (1 edits merged)
Please save this source code
User prompt
Prevent normal enemy spawn between 14.6 and 15.6, 29.6 to 30.6 , 44.6 to 45.6 , 59.6 to 60.6 , 74.6 to 75.6 , 89.6 to 90.6, 104.6 to 105.6 to 129.6 to 130.6 seconds after game start
User prompt
Prevent normal enemy spawn between 14.6 second to 15.6 second after game start
User prompt
dont spawn normal enemy every 14.1 second to 15.1 second after game start
User prompt
dont spawn normal enemy every 14,1-015,1 second after game start
User prompt
spawn tube ever 15 seconds
User prompt
Aşağıdaki örnekte, enemy spawn işlemi 0.1 saniye (100 ms) gecikmeli olarak çalışıyor. Bu gecikme sayesinde tüp (tube) spawn işlemi enemy’den önce gerçekleşiyor. Enemy spawn kodu, spawn noktasında (x = 2048) tüpün var olup olmadığını kontrol ediyor; eğer spawn bölgesinde tüp varsa enemy spawn edilmiyor. Aşağıdaki kod parçasında güncellenen enemy spawn kısmını görebilirsiniz: js Kopyala Düzenle // Oyun döngüsünde enemy spawn işlemi: enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; // 0.1 saniye gecikmeli enemy spawn: tüpün spawn olabilmesi için zaman tanıyoruz. LK.setTimeout(function () { var tubeCollision = false; for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; // "tup_1" asset'ine sahip nesneleri tüp olarak kontrol ediyoruz. if (child.asset && child.asset.name === 'tup_1') { // Enemy spawn bölgesi: x = 2048 ±75 (örneğin enemy genişliği 150 olarak alındı) var enemyRight = 2048 + 75; var enemyLeft = 2048 - 75; // Tüpün alanı: tube.x ±125 (tüp genişliği 250) var tubeRight = child.x + 125; var tubeLeft = child.x - 125; // Eğer enemy spawn bölgesi tüpün alanıyla kesişiyorsa if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) { tubeCollision = true; break; } } } // Eğer spawn noktasında tüp yoksa enemy spawn et. if (!tubeCollision) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 13; enemy.zIndex = 10; enemies.push(enemy); game.addChild(enemy); } }, 100); // 100 ms = 0.1 saniye gecikme } Açıklamalar: Gecikmeli Enemy Spawn: LK.setTimeout(..., 100) kullanılarak enemy spawn işlemi 100 ms geciktiriliyor. Bu sayede tüp spawn işlemi enemy spawn’dan önce gerçekleşiyor. Tube Collision Check: Enemy spawn noktasında, (x = 2048) tüpün varlığı, tüpün alanı (tube.x ±125) ile enemy spawn bölgesinin (2048 ±75) kesişmesiyle kontrol ediliyor. Eğer kesişim varsa enemy spawn edilmiyor. Koordinat ve Ölçüler: Tube, sağ kenardan x = 2048 + 125 değerinde spawn oluyor. Böylece tüpün alanı [2048, 2048+250] oluyor ve enemy spawn bölgesiyle (1973–2073) çakışıyorsa enemy spawn atlanıyor. Bu sayede enemy, tüp spawn işleminden 0.1 saniye sonra kontrol edilip, tüpün spawn olduğu konumda enemy spawn edilmemiş oluyor.
User prompt
tube enemyden 0.1 saniye önce spawn olsun spawn olduğu konumda enemy spawn olmasın
User prompt
/**** * Assets ****/ LK.init.image('background', {width:2048, height:2732.07, id:'6758971de1c6df8afc3f801b'}); LK.init.image('coin', {width:150, height:150, id:'67d58381540f369ec40716a5'}); 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('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: Coin'ler tüpten daha üstte (ör. zIndex 15) görünmeli var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5 }); self.velocity = 5; self.zIndex = 15; self.update = function () { self.x -= self.velocity; }; }); // Enemy: zIndex değeri 10 olarak belirlendi 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Flying Enemy 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Player: zIndex 20 (en üstte) 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.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Gravity 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; } }; }); // ScrollingBackground: arka plan 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; } }; }); // Tube: tüp enemy ile aynı hızda hareket etmeli, zIndex 5 (arka planın üzerinde, diğerlerinin arkasında) 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 = 5; self.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Weapon 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: 0x87CEEB }); /**** * Game Code ****/ // Tube spawn fonksiyonu function spawnTube() { var tube = new Tube(); tube.x = 2048 + 125; // Sağ kenardan spawn tube.y = 2732 / 2 - 120; game.addChild(tube); LK.setTimeout(spawnTube, 5000); } spawnTube(); var centerText = new Text2('0', { size: 200, fill: 0xFF0000, anchorX: 0.5, anchorY: 0.5 }); centerText.x = 2048 / 2; centerText.y = 2732 / 2; game.addChild(centerText); var coinCounter = 0; var flyinEnemies = []; var coins = []; var scrollingBackground = new ScrollingBackground(); game.addChild(scrollingBackground); var player = game.addChild(new Player()); player.x = 2048 / 2 - 200; player.y = 2732 / 2 - 7; var enemies = []; var enemySpawnInterval = 50; var enemySpawnCounter = 0; 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; function spawnFlyinEnemy() { var delay = Math.random() * 2000 + 2000; LK.setTimeout(function () { var flyinEnemy = new FlyinEnemy(); flyinEnemy.x = 2048; flyinEnemy.y = 449; game.addChild(flyinEnemy); flyinEnemies.push(flyinEnemy); spawnFlyinEnemy(); }, delay); } spawnFlyinEnemy(); game.update = function () { scrollingBackground.update(); player.update(); // Tube güncellemesi for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child instanceof Tube) { child.update(); } } enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { 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) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 13; enemies.push(enemy); game.addChild(enemy); } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); 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; 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])) { LK.effects.flashScreen(0xff0000, 1000); 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; 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++; centerText.setText(coinCounter.toString()); scoreText.setText(coinCounter.toString()); if (coinCounter > 9 && !scoreText.movedLeft) { scoreText.x -= 20; scoreText.movedLeft = true; } coin.destroy(); coins.splice(m, 1); } } }; 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); tube spawn olmuyor çözümü bu galiba
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Kopyala is not defined' in or related to this line: 'Kopyala;' Line Number: 178
User prompt
Please fix the bug: 'js is not defined' in or related to this line: 'js;' Line Number: 178
User prompt
Please fix the bug: 'Kopyala is not defined' in or related to this line: 'Kopyala;' Line Number: 178
User prompt
Please fix the bug: 'js is not defined' in or related to this line: 'js;' Line Number: 178
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: '[object Object]addChildAt: The index 1 supplied is out of bounds 0' in or related to this line: 'game.addChildAt(tube, 1); // Add tube behind the character' Line Number: 176
User prompt
tube supposed to be behind of the character, make it little bit faster velocity of the tube should be same as enemy
User prompt
character is behind the ube fix it and make tube slower
User prompt
spawn the tube right of the screen and make it move to left fast
User prompt
move character and enemy 6 pixel up
User prompt
move character and enemy 4 pixel up
User prompt
fix character y location after first jump
/**** * Classes ****/ // Define a class for coins 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.update = function () { self.x -= self.velocity; }; }); // Define a class for enemies 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for flying enemies 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.update = function () { self.x -= self.speed; if (self.x < -50) { self.destroy(); } }; }); // Define a class for the player character 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.update = function () { if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Gravity if (self.y >= 2732 / 2 - 3) { // Use the initial player.y value self.y = 2732 / 2 - 3; // Land at the same initial position self.isJumping = false; self.velocityY = 0; } } }; self.jump = function () { if (!self.isJumping) { self.isJumping = true; self.velocityY = -self.jumpHeight; } }; }); // ScrollingBackground: orijinal ve mirrored arka plan var ScrollingBackground = Container.expand(function () { var self = Container.call(this); // Orijinal arka plan self.bg1 = LK.getAsset('background', { anchorX: 0, anchorY: 0 }); self.bg1.x = 0; self.bg1.y = 0; self.addChild(self.bg1); // Mirrored arka plan (flipX) 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); // Arka plan kayma hızı 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; } }; }); // Define a class for the weapon 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; // Yok etme kontrolü 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, // Mantıksal genişlik height: 2732, // Mantıksal yükseklik backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Function to spawn tube_1 every 20 seconds function spawnTube() { var tube = LK.getAsset('tup_1', { anchorX: 0.5, anchorY: 0.5 }); tube.x = 2048 / 2 + 200; // Move 600 pixels right from center x position tube.y = 2732 / 2 - 120; // Move 5 pixels down from previous position tube.zIndex = 5; // Lower zIndex for tubes game.addChild(tube); // Set a timeout to spawn the next tube LK.setTimeout(spawnTube, 5000); } // Start the tube spawning process spawnTube(); var centerText = new Text2('0', { size: 200, fill: 0xFF0000, // Kırmızı, net görünür anchorX: 0.5, anchorY: 0.5 }); centerText.x = 2048 / 2; centerText.y = 2732 / 2; game.addChild(centerText); // Coin'lerden toplanan puanı takip etmek için değişken (artışı kaldırdık) var coinCounter = 0; // Global diziler ve değişkenler var flyinEnemies = []; var coins = []; // 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; // Düşmanlar var enemies = []; var enemySpawnInterval = 50; var enemySpawnCounter = 0; // Skor metni arka planı 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; // Skor metni (GUI katmanında, ekranın üstünde) 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; // Uçan düşmanları periyodik olarak oluştur function spawnFlyinEnemy() { var delay = Math.random() * 2000 + 2000; // 2000-4000 ms LK.setTimeout(function () { var flyinEnemy = new FlyinEnemy(); flyinEnemy.x = 2048; flyinEnemy.y = 455; // Move enemy 5 pixels down flyinEnemy.zIndex = 10; // Higher zIndex for flying enemies 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(); // Add tube movement - place this inside your game.update function for (var t = 0; t < game.children.length; t++) { var child = game.children[t]; if (child.asset && child.asset.name === 'tup_1') { child.x -= 5; // Move at same speed as enemies // Remove tubes that go off-screen if (child.x < -50) { child.destroy(); } // Sort children by zIndex game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); } } // Düşman spawn işlemleri enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var canSpawn = true; for (var i = 0; i < enemies.length; i++) { if (enemies[i].x > 1800) { canSpawn = false; break; } } if (canSpawn) { // Check for tube collision before spawning enemy 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; // enemy.x + half enemy width var enemyLeft = 2048 - 75; // enemy.x - half enemy width var tubeRight = child.x + 125; // tube.x + half tube width var tubeLeft = child.x - 125; // tube.x - half tube width if (!(enemyLeft > tubeRight || enemyRight < tubeLeft)) { tubeCollision = true; break; } } } if (!tubeCollision) { var enemy = new Enemy(); enemy.x = 2048; enemy.y = 2732 / 2 - 7; enemy.zIndex = 10; // Higher zIndex for enemies enemy.zIndex = 10; // Higher zIndex for enemies enemies.push(enemy); game.addChild(enemy); } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } enemySpawnCounter = 0; enemySpawnInterval = Math.floor(Math.random() * 100) + 30; } // Normal düşmanların update + çarpışma for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); // Oyuncu ile çarpışma if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Oyuncu, düşmanı geçince skor güncellemesi // Weapon çarpışması: coin üretimi for (var k = game.children.length - 1; k >= 0; k--) { var child = game.children[k]; if (child instanceof Weapon && child.intersects(enemies[j])) { // Düşmandan coin oluşturuluyor var coin = new Coin(); coin.x = enemies[j].x; coin.y = enemies[j].y; coin.velocity = 5; // Coin update fonksiyonu coin update kısmında yapılacak game.addChild(coin); coins.push(coin); // Particle efekti 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; } } } // Flying enemy update + çarpışma for (var n = flyinEnemies.length - 1; n >= 0; n--) { flyinEnemies[n].update(); if (player.intersects(flyinEnemies[n])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Weapon çarpışması 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 update + çarpışma (Sadece coin temasında sayıyı değiştirmeden coin yok edilecek) for (var m = coins.length - 1; m >= 0; m--) { var coin = coins[m]; // Coin’in sol tarafa doğru hareketi (doğrudan güncelleme) coin.x -= coin.velocity; // Eğer coin ekran dışına çıktıysa (dokunulmadan) yok ol if (coin.x < -100) { coin.destroy(); coins.splice(m, 1); } // Eğer coin oyuncu ile temas ediyorsa: coin toplanır ve sayacı artırır else if (player.intersects(coin)) { coinCounter++; centerText.setText(coinCounter.toString()); scoreText.setText(coinCounter.toString()); if (coinCounter > 9 && !scoreText.movedLeft) { scoreText.x -= 20; scoreText.movedLeft = true; } coin.destroy(); coins.splice(m, 1); } } }; // 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; // Calculate the angle in radians between the weapon direction and the downward direction var angle = Math.acos(weapon.directionY / Math.sqrt(weapon.directionX * weapon.directionX + weapon.directionY * weapon.directionY)); // Convert the angle to degrees var angleInDegrees = angle * (180 / Math.PI); // Check if the angle is within 30 degrees of directly downward if (angleInDegrees <= 30) { weapon.speed *= 1.3; // Increase speed by 30% when shooting within 30 degrees downwards } game.addChild(weapon); LK.setTimeout(function () { weapon.destroy(); }, 9000); game.lastWeaponTime = Date.now(); } } player.jump(); }; // Önemli: Oyunu çalıştırmayı unutmayın LK.stage.addChild(game);
===================================================================
--- original.js
+++ change.js
@@ -173,9 +173,9 @@
var scrollingBackground = new ScrollingBackground();
game.addChild(scrollingBackground);
var player = game.addChild(new Player());
player.x = 2048 / 2 - 200;
-player.y = 2732 / 2 - 3;
+player.y = 2732 / 2 - 7;
// Düşmanlar
var enemies = [];
var enemySpawnInterval = 50;
var enemySpawnCounter = 0;
@@ -257,9 +257,9 @@
}
if (!tubeCollision) {
var enemy = new Enemy();
enemy.x = 2048;
- enemy.y = 2732 / 2 - 3;
+ enemy.y = 2732 / 2 - 7;
enemy.zIndex = 10; // Higher zIndex for enemies
enemy.zIndex = 10; // Higher zIndex for enemies
enemies.push(enemy);
game.addChild(enemy);
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