User prompt
Please fix the bug: 'ReferenceError: backgroundScrollSpeed is not defined' in or related to this line: 'child.x -= backgroundScrollSpeed;' Line Number: 877
Code edit (1 edits merged)
Please save this source code
User prompt
below is one way to fix the error. The error indicates that when the code calls js Kopyala Düzenle character.jump(); the variable character hasn’t been defined in that scope. To fix this, declare the variable globally before it’s used. For example, add this at the top of your script (before any functions that reference it): js Kopyala Düzenle var character; Then, later in your initialization code, assign it: js Kopyala Düzenle character = game.addChild(new Character()); This ensures that when you call character.jump(); (for example in the game.down event), the variable is defined and accessible. Make sure that this global declaration is placed before any functions (like in game.down) that call character.jump().
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: recordsButton is not defined' in or related to this line: 'recordsButton.visible = checkEllipseHover(recordsButton, localX, localY);' Line Number: 639
User prompt
Please fix the bug: 'Uncaught ReferenceError: creditsButton is not defined' in or related to this line: 'creditsButton.visible = checkEllipseHover(creditsButton, localX, localY);' Line Number: 630
User prompt
Please fix the bug: 'Uncaught ReferenceError: volumeButton is not defined' in or related to this line: 'volumeButton.visible = checkEllipseHover(volumeButton, localX, localY);' Line Number: 621
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'addChild')' in or related to this line: 'menuContainer.addChild(playButton);' Line Number: 296
User prompt
Please fix the bug: 'Uncaught ReferenceError: playButton is not defined' in or related to this line: 'playButton.visible = checkEllipseHover(playButton, localX, localY);' Line Number: 612
User prompt
Please fix the bug: 'Uncaught ReferenceError: menuContainer is not defined' in or related to this line: 'var localX = x - menuContainer.x;' Line Number: 609
User prompt
Please fix the bug: 'ReferenceError: menuOpen is not defined' in or related to this line: 'if (!gameOver && !menuOpen && gameStarted) {' Line Number: 713
User prompt
Please fix the bug: 'ReferenceError: gameOver is not defined' in or related to this line: 'if (!gameOver && !menuOpen && gameStarted) {' Line Number: 712
User prompt
Please fix the bug: 'ReferenceError: background is not defined' in or related to this line: 'if (child === background || child === bg2) {' Line Number: 694
User prompt
Please fix the bug: 'groundY is not defined' in or related to this line: 'background3DContainer.y = groundY + 300;' Line Number: 314
User prompt
Please fix the bug: 'centerX is not defined' in or related to this line: 'var underscoreAsset = LK.getAsset('_', {' Line Number: 276
Code edit (1 edits merged)
Please save this source code
User prompt
Place background3DContainer and bgEffect3DContainer 1600 pixels down
User prompt
Gravity works for these assets background3DContainer and bgEffect3DContainer, if only character is moving
User prompt
make character bounded assets unbounded
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of null (reading 'jump')' in or related to this line: 'character.jump();' Line Number: 814
User prompt
Please fix the bug: 'ReferenceError: background is not defined' in or related to this line: 'if (child === background || child === bg2) {' Line Number: 823
User prompt
Please fix the bug: 'character is not defined' in or related to this line: 'background3DContainer.y = (character ? character.y : centerY()) + 500;' Line Number: 433
Code edit (1 edits merged)
Please save this source code
User prompt
Aşağıdaki örnekte, karakter bağlı arka planların (background3DContainer ve bgEffect3DContainer) sadece oyun başladıktan sonra (gameStarted true olduğunda) güncellenmesi için bir koşul ekledim. Böylece, menüdeyken bu dinamik güncelleme yapılmayacak ve arka planlar yerinde kalacak: js Kopyala Düzenle // Oyun döngüsü update fonksiyonunda: game.update = function () { // Karakter bağlı arka planları sadece oyun başladığında güncelle if (gameStarted && !menuOpen && character) { // Her iki arka plan için dinamik y offset'i güncelle background3DContainer.velocityY += background3DContainer.gravity; background3DContainer.offsetY += background3DContainer.velocityY; background3DContainer.y = character.y + 500 + background3DContainer.offsetY; // 500px aşağıda bgEffect3DContainer.velocityY += bgEffect3DContainer.gravity; bgEffect3DContainer.offsetY += bgEffect3DContainer.velocityY; bgEffect3DContainer.y = character.y + 500 + bgEffect3DContainer.offsetY; } else if (character) { // Menüdayken arka planların y konumunu sadece karakterin y'sine göre 500px sabit olarak ayarla background3DContainer.y = character.y + 500; bgEffect3DContainer.y = character.y + 500; } // Diğer güncellemeler... game.children.forEach(function (child) { if (child.update) { child.update(); } // Statik arka planların (background, bg2) hareketi if (child === background || child === bg2) { if (!gameOver && !menuOpen && gameStarted) { child.x -= 7.2; } if (child.x < -2807.2 / 2) { child.x += 2807.2 * 2; } } // Diğer hareket güncellemeleri... }); game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); }; Ayrıca, karakterin jump fonksiyonunda, arka planlara atanan zıplama etkisinin de sadece oyun başladıktan sonra aktif olmasını sağlayabilirsiniz: js Kopyala Düzenle self.jump = function () { if (!gameOver && gameStarted) { self.velocityY = self.jumpStrength; // Karakter için zıplama LK.getSound('wingeffect').play(); // Arka planlar için ters yönde zıplama, sadece oyun başladığında: background3DContainer.velocityY = -self.jumpStrength; bgEffect3DContainer.velocityY = -self.jumpStrength; } }; Bu değişikliklerle, menüdeyken arka planlar sabit kalacak, oyun başladığında ise karaktere bağlı olarak 500px aşağıda konumlanıp, karakterin zıplama hareketine zıt yönde tepki verecekler.
User prompt
Step 1. Initialize Background Dynamics Right after you create the backgrounds (for example, right after creating and positioning background3DContainer and bgEffect3DContainer), add custom properties for the jump effect: js Kopyala Düzenle // Initialize background dynamics: background3DContainer.offsetY = 0; background3DContainer.velocityY = 0; background3DContainer.gravity = -0.3; // gravity opposite to character's bgEffect3DContainer.offsetY = 0; bgEffect3DContainer.velocityY = 0; bgEffect3DContainer.gravity = -0.3; Step 2. Update the Y Position in the Game Loop In the game’s update loop, update the offset for each container and set its y position relative to the character. Replace or update the current code that sets the y positions with something like this: js Kopyala Düzenle if (character) { // Update background offsets using their own velocity and gravity. background3DContainer.velocityY += background3DContainer.gravity; background3DContainer.offsetY += background3DContainer.velocityY; background3DContainer.y = character.y + 500 + background3DContainer.offsetY; // 500px down bgEffect3DContainer.velocityY += bgEffect3DContainer.gravity; bgEffect3DContainer.offsetY += bgEffect3DContainer.velocityY; bgEffect3DContainer.y = character.y + 500 + bgEffect3DContainer.offsetY; } Step 3. Trigger the Opposite Jump on the Backgrounds When the character jumps, in addition to setting the character’s velocity, set the backgrounds’ velocities so they “jump” in the opposite direction. For example, modify the character’s jump function as follows: js Kopyala Düzenle self.jump = function () { if (!gameOver && gameStarted) { self.velocityY = self.jumpStrength; // typically -12 for the character LK.getSound('wingeffect').play(); // Make the character-bound backgrounds jump in the opposite direction: background3DContainer.velocityY = -self.jumpStrength; // becomes +12 bgEffect3DContainer.velocityY = -self.jumpStrength; } }; Summary Y Offset: We now set each background’s y position to be the character’s y plus 500px plus a dynamic offset. Dynamic Offset: Each container has its own velocityY and gravity (set to –0.3) so that they “float” in the opposite direction. Opposite Jump: When the character jumps (with a negative velocity), the backgrounds receive a positive velocity (the negative of the jump strength).
/**** * Classes ****/ // Character: Dokunulduğunda zıplar. var Character = Container.expand(function () { var self = Container.call(this); self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5 }); self.zIndex = 4; self.velocityY = 0; // Karakterin kendi gravity ve jump strength değeri self.gravity = 0.3; self.jumpStrength = -12; self.width = 350; self.height = 300; self.update = function () { if (gameStarted && !gameOver) { self.velocityY += self.gravity; self.y += self.velocityY; if (self.y > groundY - 100) { self.y = groundY - 100; self.velocityY = 0; if (!self.intersects(underscoreAsset) && !self.preventDeath) { gameOver = true; endGame(); } } var characterLeft = self.x - self.width / 2; var characterRight = self.x + self.width / 2; var characterTop = self.y - self.height / 2; var characterBottom = self.y + self.height / 2; if (characterLeft + self.width / 2 < 0 || characterRight - self.width / 2 > screenRight || characterTop + self.height / 2 < 0 || characterBottom - self.height / 2 > groundY) { gameOver = true; endGame(); } game.children.forEach(function (child) { if (child instanceof Tube) { var tubeLeft = child.x - child.bottomTube.width / 2; var tubeRight = child.x + child.bottomTube.width / 2; var safeGapLowerEdge = child.y - child.bottomTube.height; var safeGapUpperEdge = -gapOffset + child.topTube.height; if (self.x + self.width / 2 > tubeLeft && self.x - self.width / 2 < tubeRight) { if (self.y < safeGapUpperEdge || self.y > safeGapLowerEdge) { if (!self.intersects(underscoreAsset) && !self.preventDeath) { gameOver = true; endGame(); } else { return; } } } } else if (child instanceof Tree) { var treeLeft = child.x - child.bottomTree.width / 2; var treeRight = child.x + child.bottomTree.width / 2; var safeGapLowerEdge = child.y - child.bottomTree.height; var safeGapUpperEdge = -gapOffset + child.topTree.height; if (self.x + self.width / 2 > treeLeft && self.x - self.width / 2 < treeRight) { if (self.y < safeGapUpperEdge || self.y > safeGapLowerEdge) { if (!self.intersects(underscoreAsset) && !self.preventTreeDeath) { gameOver = true; endGame(); } } } } }); } }; self.jump = function () { if (!gameOver && gameStarted) { self.velocityY = self.jumpStrength; LK.getSound('wingeffect').play(); // Artık backgroundlar karakterle tamamen senkron (başka velocity uygulanmıyor) } }; return self; }); // GameOverText class var GameOverText = Container.expand(function () { var self = Container.call(this); self.text = new Text2("GAME OVER", { fontFamily: "Arial", fontSize: 2250, fill: 0xFF0000, align: "center", fontWeight: "bold" }); self.text.anchorX = 0.5; self.text.anchorY = 0.5; self.addChild(self.text); self.zIndex = 100; return self; }); // Tree class: Üst ve alt ağaç oluşturma var Tree = Container.expand(function () { var self = Container.call(this); var bottomUnit = Math.floor(Math.random() * 8) + 1; var topUnit = 9 - bottomUnit; var unitSize = groundY / totalUnits; var bottomHeight = bottomUnit * unitSize; var topHeight = topUnit * unitSize; self.y = groundY; self.bottomTree = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, width: 300, height: bottomHeight, flipY: false }); self.topTree = self.attachAsset('tree', { anchorX: 0.5, anchorY: 0.5, width: 300, height: topHeight, flipY: false }); self.topTree.rotation = Math.PI; self.topTree.y = -groundY - gapOffset + topHeight / 2; self.zIndex = 1; self.x = 2048 + 800; self.velocityX = -3.6; self.spawned = false; self.prevX = self.x; self.update = function () { if (gameStarted && !gameOver) { self.x += self.velocityX; if (!self.spawned && self.prevX > treeSpawnThreshold && self.x <= treeSpawnThreshold) { self.spawned = true; var newTube = new Tube(); newTube.x = 2048 + 800; game.addChild(newTube); lastSpawner = newTube; } self.prevX = self.x; if (!self.passed && character.x > self.x + self.bottomTree.width / 2) { self.passed = true; updateScore(); } } }; return self; }); // Tube class: Üst ve alt boru oluşturma var Tube = Container.expand(function () { var self = Container.call(this); var bottomUnit = Math.floor(Math.random() * 8) + 1; var topUnit = 9 - bottomUnit; var unitSize = groundY / totalUnits; var bottomHeight = bottomUnit * unitSize; var topHeight = topUnit * unitSize; self.y = groundY; self.bottomTube = self.attachAsset('tube', { anchorX: 0.5, anchorY: 1, width: 300, height: bottomHeight, flipY: false }); self.topTube = self.attachAsset('tube', { anchorX: 0.5, anchorY: 0.5, width: 300, height: topHeight, flipY: false }); self.topTube.rotation = Math.PI; self.topTube.y = -groundY - gapOffset + topHeight / 2; self.zIndex = 1; self.x = 2048 + 800; self.velocityX = -3.6; self.spawned = false; self.prevX = self.x; self.update = function () { if (gameStarted && !gameOver) { self.x += self.velocityX; if (self.velocityX === 0) { background.velocityX = 0; bg2.velocityX = 0; } if (!self.spawned && self.prevX > tubeSpawnThreshold && self.x <= tubeSpawnThreshold) { self.spawned = true; var newTree = new Tree(); newTree.x = 2048 + 800; game.addChild(newTree); lastSpawner = newTree; } self.prevX = self.x; if (!self.passed && character.x > self.x + self.bottomTube.width / 2) { self.passed = true; updateScore(); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // Define background and bg2 variables var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: centerX(), y: centerY() }); var bg2 = LK.getAsset('bg2', { anchorX: 0.5, anchorY: 0.5, x: centerX() + backgroundWidth, y: centerY() }); game.addChild(background); game.addChild(bg2); /**** * Global Variables & Helper Functions ****/ var backgroundWidth = 2807; var backgroundScrollSpeed = 3.6; var musicSequence = ['m_1', 'M_2', 'M_3']; var musicCycle = 0; function playNextMusic() { musicCycle++; if (musicCycle === 1) { LK.stopMusic(); LK.playMusic(musicSequence[1]); } else if (musicCycle === 2) { LK.stopMusic(); LK.playMusic(musicSequence[2]); } else if (musicCycle === 3) { LK.stopMusic(); } else { musicCycle = 0; LK.stopMusic(); LK.playMusic(musicSequence[0]); } } LK.playMusic(musicSequence[0]); // Define character variable var character = game.addChild(new Character()); character.x = centerX(); character.y = groundY / 2; // Bu öğeler karakterin y'sine sabit +500 offset ile bağlanacak // Karakter passCounter 0 ile başlarken, backgroundların puanı başlangıçta 5 ve 10 var passCounter = 0; var bgScore1 = 5; var bgScore2 = 5; // Puanları gösteren metin nesneleri: var counterText = new Text2('0', { size: 124.2, fill: 0xFFFFFF }); counterText.anchor.set(0, 0); counterText.x = 1315; counterText.y = 15; LK.gui.topLeft.addChild(counterText); var bgScoreText1 = new Text2('BG1: ' + bgScore1, { size: 100, fill: 0xFFFFFF }); bgScoreText1.anchor.set(0, 0); bgScoreText1.x = 1315; bgScoreText1.y = 50; LK.gui.topLeft.addChild(bgScoreText1); var bgScoreText2 = new Text2('BG2: ' + bgScore2, { size: 100, fill: 0xFFFFFF }); bgScoreText2.anchor.set(0, 0); bgScoreText2.x = 1315; bgScoreText2.y = 100; LK.gui.topLeft.addChild(bgScoreText2); var groundY = 2732; var menuOpen = true; var volumeOn = true; var records = []; var gapOffset = 400; var gameStarted = false; var gameOver = false; var gameWait = false; var screenRight = 2048; var totalUnits = 10; var tubeSpawnThreshold = centerX() + (screenRight - centerX()) / 2; var treeSpawnThreshold = centerX() + 3 * (screenRight - centerX()) / 4; var lastSpawner = null; var gameOverText = null; var lastScore = 0; var underscoreTouchCount = 0; var flipped = false; function centerX() { return 2048 / 2; } function centerY() { return groundY / 2; } /**** * Menu Setup ****/ var menuContainer = new Container(); menuContainer.zIndex = 200; var menuBackground = LK.getAsset('menu_background', { anchorX: 0.5, anchorY: 0.5, x: centerX(), y: centerY() + 625 }); menuBackground.zIndex = 1000; menuContainer.addChild(menuBackground); var menuBackgroundPart = LK.getAsset('menu_background_part', { anchorX: 0.5, anchorY: 0.19, x: centerX() - 1030, y: centerY() - 2866 }); menuBackgroundPart.zIndex = menuBackground.zIndex + 1; menuBackground.addChild(menuBackgroundPart); var playButton = LK.getAsset('button_play', { anchorX: 0.5, anchorY: 0.5, x: centerX() - 20, y: centerY() + 205 }); playButton.visible = false; menuContainer.addChild(playButton); var playLabel = new Text2("PLAY", { fontFamily: "Arial", fontSize: 630.25 * 1.1 * 1.08 * 1.5, fill: 0xffffff }); playLabel.anchorX = 0.5; playLabel.anchorY = 0.5; playLabel.x = playButton.x - 45; playLabel.y = playButton.y - -25; playLabel.visible = true; playLabel.zIndex = 1000; menuContainer.addChild(playLabel); var volumeButton = LK.getAsset('button_volume', { anchorX: 0.5, anchorY: 0.5, x: centerX() - 28, y: centerY() + 320 }); volumeButton.visible = false; menuContainer.addChild(volumeButton); var volumeLabel = new Text2("VOLUME", { fontFamily: "Arial", fontSize: 63.25 * 1.1 * 1.05 * 1.05 * 1.05 * 1.5, fill: 0xffffff }); volumeLabel.anchorX = 0.5; volumeLabel.anchorY = 0.5; volumeLabel.x = volumeButton.x - 58; volumeLabel.y = volumeButton.y + 30; volumeLabel.visible = true; volumeLabel.zIndex = 1000; menuContainer.addChild(volumeLabel); var creditsButton = LK.getAsset('button_credits', { anchorX: 0.5, anchorY: 0.5, x: centerX() - 30, y: centerY() + 429 }); creditsButton.visible = false; menuContainer.addChild(creditsButton); var creditsLabel = new Text2("CREDITS", { fontFamily: "Arial", fontSize: 630.25 * 1.05 * 1.05 * 1.05 * 1.5, fill: 0xffffff }); creditsLabel.anchorX = 0.5; creditsLabel.anchorY = 0.5; creditsLabel.x = creditsButton.x - 60; creditsLabel.y = creditsButton.y + 28; creditsLabel.visible = true; creditsLabel.zIndex = 1000; menuContainer.addChild(creditsLabel); var recordsButton = LK.getAsset('button_records', { anchorX: 0.5, anchorY: 0.5, x: centerX() - 30, y: centerY() + 540 }); recordsButton.visible = false; menuContainer.addChild(recordsButton); var recordsLabel = new Text2("RECORDS", { fontFamily: "Arial", fontSize: 150.25 * 1.05 * 1.05 * 1.03 * 1.05 * 1.5, fill: 0xffffff }); recordsLabel.anchorX = 0.5; recordsLabel.anchorY = 0.5; recordsLabel.x = recordsButton.x - 67; recordsLabel.y = recordsButton.y + 28; recordsLabel.visible = true; recordsLabel.zIndex = 1000; menuContainer.addChild(recordsLabel); menuContainer.y += 100; game.addChild(menuContainer); /**** * Create and add character-bound 3d backgrounds ****/ // Bu öğeler karakterin y'sine sabit +500 offset ile bağlanacak var background3D = LK.getAsset('3dlikebackground', { anchorX: 0.5, anchorY: 0.5 }); var background3DContainer = new Container(); background3DContainer.addChild(background3D); // Başlangıçta, karakter varsa onun y'sine göre 500px aşağı; yoksa centerY()+500 background3DContainer.x = centerX(); background3DContainer.y = (character ? character.y : centerY()) + 500; background3DContainer.zIndex = 0.5; game.addChild(background3DContainer); var bgEffect3D = LK.getAsset('3dbgeffect', { anchorX: 0.5, anchorY: 0.5 }); var bgEffect3DContainer = new Container(); bgEffect3DContainer.addChild(bgEffect3D); // background3DContainer'ın hemen sağında; aynı y offset bgEffect3DContainer.x = background3DContainer.x + backgroundWidth; bgEffect3DContainer.y = (character ? character.y : centerY()) + 500; bgEffect3DContainer.zIndex = 0.5; game.addChild(bgEffect3DContainer); /**** * Underscore asset ****/ var underscoreAsset = LK.getAsset('_', { anchorX: 0.5, anchorY: 0.5, x: centerX() + 1000, y: centerY() }); underscoreAsset.zIndex = 15000; game.addChild(underscoreAsset); underscoreAsset.on('down', function () { underscoreTouchCount++; if (underscoreTouchCount >= 5) { character.preventDeath = true; character.preventTreeDeath = true; } }); game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); /**** * Helper Functions: Credits, Volume & Records ****/ function createCommonCloseElements(modalWidth, modalHeight) { var closeLabel = LK.getAsset('justX', { anchorX: 0.5, anchorY: 0.5, zIndex: 100000, x: -9, y: 6 }); var radius = 50; var closeButton = LK.getAsset('button_close', { anchorX: 0.5, anchorY: 0.5, width: radius * 2.3 * 1.2, height: radius * 2.3 * 1.2 }); closeButton.zIndex = 10000; closeButton.x = 0; closeButton.y = 0; closeButton.addChild(closeLabel); return closeButton; } function showCredits() { menuOpen = false; var creditsContainer = new Container(); creditsContainer.zIndex = 300; var modalWidth = 1500, modalHeight = 2200; var bg = LK.getAsset('second_menu', { anchorX: 0.5, anchorY: 0.5, width: modalWidth, height: modalHeight, color: 0x000000 }); bg.x = centerX(); bg.y = centerY(); creditsContainer.addChild(bg); var creditsText = new Text2("Game by\nMustafa Talha ŞEN", { fontFamily: "Arial", fontSize: 5000 * 1.03, fill: 0xffffff, align: "center" }); creditsText.anchorX = 0.5; creditsText.anchorY = 0.5; creditsText.x = centerX() - 359; creditsText.y = centerY() - 800 + 40; creditsText.scale.set(3, 3); creditsContainer.addChild(creditsText); game.addChild(creditsContainer); var closeButton = createCommonCloseElements(modalWidth, modalHeight); closeButton.x = bg.x + modalWidth / 2 - closeButton.width / 2 - 185; closeButton.y = bg.y - modalHeight / 2 + closeButton.height / 2 + 230; creditsContainer.addChild(closeButton); closeButton.on('down', function () { game.removeChild(creditsContainer); menuOpen = true; menuContainer.visible = true; }); } function showVolume() { menuOpen = false; var volumeContainer = new Container(); volumeContainer.zIndex = 300; var modalWidth = 1500, modalHeight = 2200; var bg = LK.getAsset('second_menu', { anchorX: 0.5, anchorY: 0.5, width: modalWidth, height: modalHeight, color: 0x000000 }); bg.x = centerX(); bg.y = centerY(); volumeContainer.addChild(bg); var currentMusicName = new Text2("Next Music", { fontFamily: "Arial", fontSize: 5000 * 1.103, fill: 0xffffff, align: "center" }); currentMusicName.anchorX = 0.5; currentMusicName.anchorY = 0.5; currentMusicName.x = centerX() - 250; currentMusicName.y = centerY() - 650 + 40 - 300 + 100; currentMusicName.scale.set(3, 3); volumeContainer.addChild(currentMusicName); var musicButton = LK.getAsset('Musicbutton', { anchorX: 0.5, anchorY: 0.5, x: centerX() - 280 + 250, y: centerY() - 350 + 40 - 150 }); musicButton.on('down', function () { playNextMusic(); }); volumeContainer.addChild(musicButton); game.addChild(volumeContainer); var closeButton = createCommonCloseElements(modalWidth, modalHeight); closeButton.x = bg.x + modalWidth / 2 - closeButton.width / 2 - 185; closeButton.y = bg.y - modalHeight / 2 + closeButton.height / 2 + 230; volumeContainer.addChild(closeButton); closeButton.on('down', function () { game.removeChild(volumeContainer); menuOpen = true; menuContainer.visible = true; }); } function showRecords() { menuOpen = false; var recordsContainer = new Container(); recordsContainer.zIndex = 300; var modalWidth = 1500, modalHeight = 2200; var bg = LK.getAsset('second_menu', { anchorX: 0.5, anchorY: 0.5, width: modalWidth, height: modalHeight, color: 0x000000 }); bg.x = centerX(); bg.y = centerY(); recordsContainer.addChild(bg); var recordsTextStr = "Top Scores:\n"; for (var i = 0; i < records.length; i++) { recordsTextStr += i + 1 + ". " + records[i].score + " (Attempt " + records[i].attempt + ")\n"; } if (records.length === 0) { recordsTextStr += "No records yet."; } recordsTextStr += "\nAttempts: " + records.length; recordsTextStr += "\nLast Score: " + lastScore; var recordsText = new Text2(recordsTextStr, { fontFamily: "Arial", fontSize: 5000 * 1.103, fill: 0xffffff, align: "center" }); recordsText.anchorX = 0.5; recordsText.anchorY = 0.5; recordsText.x = centerX() - 280; recordsText.y = centerY() - 850 + 40; recordsText.scale.set(3, 3); recordsContainer.addChild(recordsText); game.addChild(recordsContainer); var closeButton = createCommonCloseElements(modalWidth, modalHeight); closeButton.x = bg.x + modalWidth / 2 - closeButton.width / 2 - 185; closeButton.y = bg.y - modalHeight / 2 + closeButton.height / 2 + 230; recordsContainer.addChild(closeButton); closeButton.on('down', function () { game.removeChild(recordsContainer); menuOpen = true; menuContainer.visible = true; }); } /**** * End Game & Reset Functions ****/ function endGame() { LK.effects.flashScreen(0xFF0000, 500); LK.getSound('deatheffect').play(); character.velocityY = character.jumpStrength; character.update = function () { if (gameOver) { character.velocityY += character.gravity; character.y += character.velocityY; if (character.y > groundY + character.height) { character.y = groundY + character.height; character.velocityY = 0; } } }; game.children.forEach(function (child) { if (child.velocityX) { child.velocityX = 0; } }); game.touchDisabled = true; lastScore = passCounter; records.push({ score: passCounter, attempt: records.length + 1 }); records.sort(function (a, b) { return b.score - a.score; }); if (records.length > 5) { records = records.slice(0, 5); } LK.setTimeout(function () { game.touchDisabled = false; menuOpen = true; menuContainer.visible = true; var startY = groundY + 100; var endY = centerY() - 1270; var animationDuration = 16.5 * 5 / 1.5; var startTime = Date.now(); function animateMenu() { var currentTime = Date.now(); var elapsedTime = currentTime - startTime; var progress = Math.min(elapsedTime / animationDuration, 1); menuContainer.y = startY + (endY - startY) * progress; if (progress < 1) { LK.setTimeout(animateMenu, 16); } } animateMenu(); }, 1700); LK.setTimeout(function () { resetGame(); }, 1750); } function resetGame() { if (gameOverText) { game.removeChild(gameOverText); gameOverText = null; } unflipWorld(); var objectsToRemove = []; game.children.forEach(function (child) { if (child instanceof Tree || child instanceof Tube) { objectsToRemove.push(child); } }); objectsToRemove.forEach(function (obj) { game.removeChild(obj); }); game.removeChild(character); character = game.addChild(new Character()); character.x = centerX(); character.y = groundY / 2; background.x = centerX(); bg2.x = centerX() + 2807.2; background.velocityX = -3.6; bg2.velocityX = -3.6; bg2.scale.x = 1; gameStarted = false; gameOver = false; character.preventDeath = false; underscoreAsset.preventDeath = false; lastSpawner = null; passCounter = 0; bgScore1 = 5; bgScore2 = 5; underscoreTouchCount = 0; counterText.setText(passCounter); bgScoreText1.setText('BG1: ' + bgScore1); bgScoreText2.setText('BG2: ' + bgScore2); } /**** * Eliptik hit testi için yardımcı fonksiyon ****/ function checkEllipseHover(button, lx, ly) { var scaleFactorX = 1; var scaleFactorY = 0.53; var offsetY = 40; var dx = lx - button.x; var dy = ly - (button.y + offsetY); var rx = button.width / 2 * scaleFactorX; var ry = button.height / 2 * scaleFactorY; return dx * dx / (rx * rx) + dy * dy / (ry * ry) <= 1; } /**** * Fare hareketinde hover kontrolü ****/ game.move = function (x, y, obj) { if (!menuOpen) { return; } var localX = x - menuContainer.x; var localY = y - menuContainer.y; playButton.visible = checkEllipseHover(playButton, localX, localY); volumeButton.visible = checkEllipseHover(volumeButton, localX, localY); creditsButton.visible = checkEllipseHover(creditsButton, localX, localY); recordsButton.visible = checkEllipseHover(recordsButton, localX, localY); }; /**** * Touch Event ****/ game.down = function (x, y, obj) { if (menuOpen) { var localX = x - menuContainer.x; var localY = y - menuContainer.y; if (checkEllipseHover(playButton, localX, localY)) { var _animateMenu = function animateMenu() { var currentTime = Date.now(); var elapsedTime = currentTime - startTime; var progress = Math.min(elapsedTime / animationDuration, 1); menuContainer.y = startY + (endY - startY) * progress; if (progress < 1) { LK.setTimeout(_animateMenu, 1); } else { menuOpen = false; menuContainer.visible = false; gameWait = true; } }; var animationDuration = 16.5 * 5 * 2 / 1.5; var startTime = Date.now(); var startY = menuContainer.y; var endY = centerY() + 100; _animateMenu(); return; } else if (checkEllipseHover(volumeButton, localX, localY)) { showVolume(); } else if (checkEllipseHover(creditsButton, localX, localY)) { showCredits(); } else if (checkEllipseHover(recordsButton, localX, localY)) { showRecords(); } return; } else if (gameOver) { if (!game.touchDisabled) { menuOpen = true; menuContainer.visible = true; resetGame(); } } else { if (gameWait) { gameWait = false; gameStarted = true; var initialTube = new Tube(); game.addChild(initialTube); lastSpawner = initialTube; character.jump(); } else { character.jump(); character.rotation = 0.1; LK.setTimeout(function () { character.rotation = 0; }, 200); } } }; /**** * Game Loop ****/ game.update = function () { // Arka planların (background3DContainer ve bgEffect3DContainer) y konumu, karakterin y'sine sabit 500px offset eklenerek ayarlanıyor if (character) { background3DContainer.y = character.y + 500; bgEffect3DContainer.y = character.y + 500; } game.children.forEach(function (child) { if (child.update) { child.update(); } // Statik arka planların (background, bg2) hareketi: if (child === background || child === bg2) { if (!gameOver && !menuOpen && gameStarted) { child.x -= 7.2; } if (child.x < -2807.2 / 2) { child.x += 2807.2 * 2; } } // Karakter bağlı arka planların (background3DContainer ve bgEffect3DContainer) yatay kaydırması: if (child === background3DContainer || child === bgEffect3DContainer) { if (!gameOver && !menuOpen && gameStarted) { child.x -= backgroundScrollSpeed; } if (child.x < -2807.2 / 2) { child.x += 2807.2 * 2; } } }); game.children.sort(function (a, b) { return (a.zIndex || 0) - (b.zIndex || 0); }); }; // Puan güncelleme fonksiyonu: Karakterin passCounter'ı artarken, backgroundların puanları da function updateScore() { passCounter++; counterText.setText(passCounter); // Backgroundların puanları; karakterin puanına göre +5 ve +10 olarak ayarlanıyor bgScore1 = passCounter + 5; bgScore2 = passCounter + 10; bgScoreText1.setText('BG1: ' + bgScore1); bgScoreText2.setText('BG2: ' + bgScore2); if (passCounter % 5 === 0) { if (!flipped) { flipWorld(); } else { unflipWorld(); } } } function getCurrentMusicName() { return musicSequence[currentMusicIndex]; } /**** * Flip World Functions (ekran ters çevirme) ****/ function flipWorld() { if (flipped) { return; } flipped = true; character.gravity = 0; character.jumpStrength = 0; zoomEffect(); LK.setTimeout(function () { character.gravity = 0.3; character.jumpStrength = -12; }, 300); background.scale.y *= -1; bg2.scale.y *= -1; sky.scale.y *= -1; groundAsset.scale.y *= -1; ground2Asset.scale.y *= -1; // Karakter bağlı arka planların da ters ölçeklenmesi: background3DContainer.scale.y *= -1; bgEffect3DContainer.scale.y *= -1; } function unflipWorld() { if (!flipped) { return; } flipped = false; character.gravity = 0; character.jumpStrength = 0; zoomEffect(); LK.setTimeout(function () { character.gravity = 0.3; character.jumpStrength = -12; }, 300); background.scale.y *= -1; bg2.scale.y *= -1; sky.scale.y *= -1; groundAsset.scale.y *= -1; ground2Asset.scale.y *= -1; background3DContainer.scale.y *= -1; bgEffect3DContainer.scale.y *= -1; } function zoomEffect() { var originalScale = character.scale.x; character.scale.set(originalScale * 1.2); LK.setTimeout(function () { character.scale.set(originalScale); }, 300); }
===================================================================
--- original.js
+++ change.js
@@ -245,9 +245,11 @@
}
}
LK.playMusic(musicSequence[0]);
// Define character variable
-var character = null;
+var character = game.addChild(new Character());
+character.x = centerX();
+character.y = groundY / 2;
// Bu öğeler karakterin y'sine sabit +500 offset ile bağlanacak
// Karakter passCounter 0 ile başlarken, backgroundların puanı başlangıçta 5 ve 10
var passCounter = 0;
var bgScore1 = 5;
green theme forest by green tones to the sky , not to much detail just simple tree shadows trees has no details just shadowed green and shadowless places, beautiful view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
hyper realistic nature too reallistic proffational blue sky white clouds yellow sun an over realistic mountain view with full of trees and sun and clouds view a forest of a mountain challangeing mountain road. No background.cool background. view background. No shadows. 2d. In-Game asset. flat