User prompt
Layer1 yavaşca sağdan sola doğru hareket etsin
Code edit (1 edits merged)
Please save this source code
User prompt
Arkaplanı 30 birim yukarı kaydır
User prompt
Karakterimiz powerup özelliğinde opaklığı azamalasın
User prompt
Karakterimiz powerup özelliğinde opaklığı azalmasın
User prompt
Layer4 katmanını layer1 katmanının üstüne koy
User prompt
Layer1 tesmini tüm ekrana sığdır
User prompt
Move Layer1 visuals 180 units downward
User prompt
Layer1 görselini 80 birim aşağıya kaydır
User prompt
Arkaplan sağdan sola doğru hareket etsin ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Katmanları arkplanın arkasına koy
User prompt
Arkaplanı katmanların önüne getir
User prompt
Layer2 görselini 120 birim yukarı kaydır
User prompt
Layer2 görselini 200 birim yukarı kaydır
User prompt
Layer3 görselini 400 birim yukarı kaydır
User prompt
Layer3 görselini 80 birim yukarı kaydır
User prompt
Layer3 ü layer 2 nin üstüne koy
User prompt
Layer2 yi layer1 ün üstüne koy
User prompt
Arka plan soldan sağa doğru hareket eder
User prompt
Layer 1 hareketsiz durur
User prompt
Arkplanın önüne layer1 katmanı ekle
User prompt
Layer1 görselini arkpalan yap
User prompt
Arkaplanın tamamını layer 1 ile kapla
User prompt
Arkaplan görselini sırasıyla katmanlar halinde layer12, layer11, layer10, layer9, layer8, layer7, layer6, layer5, layer4, layer3, layer2, layer1 şeklinde yerleştir
User prompt
Tam tersi sırayla yerleştir
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Define a class for the down button var DownButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('downButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed if (player.y + 100 <= 2732) { player.y += 100; // Check if player is intersecting with NewEnemy for (var i = 0; i < enemies.length; i++) { if (enemies[i] instanceof NewEnemy && player.intersects(enemies[i])) { LK.setScore(LK.getScore() + 10); // Increase score by 10 scoreTxt.setText(LK.getScore()); // Update the score text display break; // Exit loop after finding the first intersecting NewEnemy } } } }; }); // 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 = Math.random() * 2 + 1; // Random speed between 1 and 3 self.update = function () { self.x -= self.speed; // Move from right to left self.y += Math.sin(self.x / 150) * 15; // Further reduce vertical oscillation amplitude for (var k = walls.length - 1; k >= 0; k--) { if (self.intersects(walls[k])) { // If enemy intersects with a wall, adjust its position to prevent passing through if (self.x > walls[k].x) { self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2; } else { self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2; } } } if (self.y < 0) { self.y = 0; // Prevent moving above the top of the scene } if (self.x < -50) { self.destroy(); } }; }); var Kaplu = Container.expand(function () { var self = Container.call(this); // Store frame asset ids var kapluFrames = ['Kaplu1', 'Kaplu2', 'Kaplu3']; var currentFrame = 0; // Attach all frames, but only show the first one var kapluGraphicsArr = []; for (var i = 0; i < kapluFrames.length; i++) { var g = self.attachAsset(kapluFrames[i], { anchorX: 0.5, anchorY: 0.5 }); g.visible = i === 0; kapluGraphicsArr.push(g); } var kapluGraphics = kapluGraphicsArr[0]; // Animation timing var frameInterval = 120; // ms per frame (~8 FPS) var lastFrameTime = Date.now(); self.update = function () { self.x -= 5; // Move 'kaplu' from right to left faster // Animate frames var now = Date.now(); if (now - lastFrameTime >= frameInterval) { // Hide current frame kapluGraphicsArr[currentFrame].visible = false; // Advance frame currentFrame = (currentFrame + 1) % kapluFrames.length; // Show new frame kapluGraphicsArr[currentFrame].visible = true; kapluGraphics = kapluGraphicsArr[currentFrame]; lastFrameTime = now; } for (var k = walls.length - 1; k >= 0; k--) { if (self.intersects(walls[k])) { // If 'kaplu' intersects with a wall, adjust its position to prevent passing through if (self.x > walls[k].x) { self.x = walls[k].x + walls[k].width / 2 + kapluGraphics.width / 2; } else { self.x = walls[k].x - walls[k].width / 2 - kapluGraphics.width / 2; } } } if (self.x < -kapluGraphics.width / 2) { self.destroy(); // Remove 'kaplu' when it goes off-screen } }; }); // Define a class for the left button var LeftButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('leftButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed character.speedX = -moveSpeed; character.removeChild(character.children[0]); // Remove current player image character.attachAsset('leftImage', { // Change character image to 'leftImage' anchorX: 0.5, anchorY: 0.5 }); }; self.up = function (x, y, obj) { character.speedX = 0; character.removeChild(character.children[0]); // Remove current leftImage character.attachAsset('player', { // Revert character image to original anchorX: 0.5, anchorY: 0.5 }); }; }); var LifeIcon = Container.expand(function () { var self = Container.call(this); var lifeIconGraphics = self.attachAsset('lifeIcon', { anchorX: 0.5, anchorY: 0.5 }); self.updatePosition = function (index) { self.x = 50 + index * 60; // Position each icon with a gap self.y = 50; // Position at the top-left corner }; }); var MenuSystem = Container.expand(function () { var self = Container.call(this); // Background overlay for menu var menuBg = LK.getAsset('dusman', { anchorX: 0.5, anchorY: 0.5, width: 2948, height: 3932 }); menuBg.alpha = 0.8; menuBg.tint = 0x000000; self.addChild(menuBg); // Create menu title var menuTitle = new Text2('Game Menu', { size: 100, fill: 0xFFFFFF }); menuTitle.anchor.set(0.5, 0); menuTitle.x = 2048 / 3; menuTitle.y = 400; self.addChild(menuTitle); // Sound button var soundBtn = new Text2('Sound: ON', { size: 50, fill: 0xFFFFFF }); soundBtn.anchor.set(0.5, 0.5); soundBtn.x = 2048 / 3; soundBtn.y = 700; self.addChild(soundBtn); // Button for game rules var rulesBtn = new Text2('Game Rules', { size: 50, fill: 0xFFFFFF }); rulesBtn.anchor.set(0.5, 0.5); rulesBtn.x = 2048 / 3; rulesBtn.y = 850; self.addChild(rulesBtn); // Market button var marketBtn = new Text2('Market', { size: 50, fill: 0xFFFFFF }); marketBtn.anchor.set(0.5, 0.5); marketBtn.x = 2048 / 3; marketBtn.y = 1000; self.addChild(marketBtn); // Back to game button var backBtn = new Text2('Back to Game', { size: 50, fill: 0xFFFFFF }); backBtn.anchor.set(0.5, 0.5); backBtn.x = 2048 / 3; backBtn.y = 1150; self.addChild(backBtn); // Creator button var creatorBtn = new Text2('Creator', { size: 50, fill: 0xFFFFFF }); creatorBtn.anchor.set(0.5, 0.5); creatorBtn.x = 2048 / 3; creatorBtn.y = 1400; self.addChild(creatorBtn); // Creator modal var creatorModal = new Container(); creatorModal.visible = false; self.addChild(creatorModal); // Creator modal background var creatorModalBg = LK.getAsset('dusman', { anchorX: 0.5, anchorY: 0.5, width: 1600, height: 800 }); creatorModalBg.tint = 0x333333; creatorModalBg.x = 2048 / 3; creatorModalBg.y = 2732 / 2; creatorModal.addChild(creatorModalBg); // Creator name var creatorName = new Text2('Akif Uraz Aydın', { size: 100, fill: 0xFFFFFF }); creatorName.anchor.set(0.5, 0); creatorName.x = 2048 / 3; creatorName.y = 2732 / 2 - 100; creatorModal.addChild(creatorName); // Close button for creator modal var closeCreatorBtn = new Text2('Close', { size: 50, fill: 0xFFFFFF }); closeCreatorBtn.anchor.set(0.5, 0.5); closeCreatorBtn.x = 2048 / 3; closeCreatorBtn.y = 2732 / 2 + 200; creatorModal.addChild(closeCreatorBtn); // Market modal var marketModal = new Container(); marketModal.visible = false; self.addChild(marketModal); // Market modal background var marketModalBg = LK.getAsset('dusman', { anchorX: 0.5, anchorY: 0.5, width: 1600, height: 1600 // Increased height to accommodate power-up option }); marketModalBg.tint = 0x333333; marketModalBg.x = 2048 / 3; marketModalBg.y = 2732 / 2; marketModal.addChild(marketModalBg); // Market title var marketTitle = new Text2('Market', { size: 180, fill: 0xFFFFFF }); marketTitle.anchor.set(0.5, 0); marketTitle.x = 2048 / 3; marketTitle.y = 700; // Moved up to make room for new items marketModal.addChild(marketTitle); // Life icon in market var marketLifeIcon = LK.getAsset('lifeIcon', { anchorX: 0.5, anchorY: 0.5 }); marketLifeIcon.x = 2048 / 3 - 200; marketLifeIcon.y = 950; // Adjusted position marketLifeIcon.scale.set(2); marketModal.addChild(marketLifeIcon); // Life description var lifeDescription = new Text2('Extra Life\nCost: 100 Score', { size: 60, fill: 0xFFFFFF }); lifeDescription.anchor.set(0, 0.5); lifeDescription.x = 2048 / 3 - 100; lifeDescription.y = 950; // Adjusted position marketModal.addChild(lifeDescription); // Buy life button var buyLifeBtn = new Text2('Buy', { size: 80, fill: 0x00FF00 }); buyLifeBtn.anchor.set(0.5, 0.5); buyLifeBtn.x = 2048 / 3; buyLifeBtn.y = 1050; // Adjusted position // Set initial interactive state based on score buyLifeBtn.interactive = LK.getScore() >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; // Visual indicator for disabled state marketModal.addChild(buyLifeBtn); // Power-up section // Power-up icon in market var marketPowerUpIcon = LK.getAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); marketPowerUpIcon.x = 2048 / 3 - 200; marketPowerUpIcon.y = 1250; // Position below life option marketPowerUpIcon.scale.set(0.8); marketModal.addChild(marketPowerUpIcon); // Power-up description var powerUpDescription = new Text2('Power Up Box\nCost: 100 Score', { size: 60, fill: 0xFFFFFF }); powerUpDescription.anchor.set(0, 0.5); powerUpDescription.x = 2048 / 3 - 100; powerUpDescription.y = 1250; marketModal.addChild(powerUpDescription); // Buy power-up button var buyPowerUpBtn = new Text2('Buy', { size: 80, fill: 0x00FF00 }); buyPowerUpBtn.anchor.set(0.5, 0.5); buyPowerUpBtn.x = 2048 / 3; buyPowerUpBtn.y = 1350; // Set initial interactive state based on score buyPowerUpBtn.interactive = LK.getScore() >= 100; buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5; marketModal.addChild(buyPowerUpBtn); // Status message for purchases var statusMessage = new Text2('', { size: 50, fill: 0xFFFFFF }); statusMessage.anchor.set(0.5, 0.5); statusMessage.x = 2048 / 3; statusMessage.y = 1500; //{2p} // Adjusted position marketModal.addChild(statusMessage); // Close button for market modal var closeMarketBtn = new Text2('Close', { size: 100, fill: 0xFFFFFF }); closeMarketBtn.anchor.set(0.5, 0.5); closeMarketBtn.x = 2048 / 3; closeMarketBtn.y = 1700; // Adjusted position marketModal.addChild(closeMarketBtn); // Button handlers creatorBtn.interactive = true; creatorBtn.buttonMode = true; creatorBtn.down = function () { creatorModal.visible = true; marketModal.visible = false; }; closeCreatorBtn.interactive = true; closeCreatorBtn.buttonMode = true; closeCreatorBtn.down = function () { creatorModal.visible = false; }; // Market button handlers marketBtn.interactive = true; marketBtn.buttonMode = true; marketBtn.down = function () { marketModal.visible = true; creatorModal.visible = false; statusMessage.setText(''); // Update buy buttons state based on current score var currentScore = LK.getScore(); buyLifeBtn.interactive = currentScore >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; buyPowerUpBtn.interactive = currentScore >= 100; buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5; }; // Buy life button handler buyLifeBtn.buttonMode = true; buyLifeBtn.down = function () { var currentScore = LK.getScore(); if (currentScore >= 100) { // Deduct score LK.setScore(currentScore - 100); scoreTxt.setText(LK.getScore()); // Add life playerHealth.lives++; // Create new life icon var lifeIcon = new LifeIcon(); lifeIcon.updatePosition(playerHealth.lives - 1); LK.gui.topLeft.addChild(lifeIcon); lifeIcons.push(lifeIcon); // Show success message statusMessage.setText('Successfully purchased 1 life!'); // Use the constructor to create a new Text2 with updated fill color var successStyle = { size: 50, fill: 0x00FF00 }; marketModal.removeChild(statusMessage); statusMessage = new Text2('Successfully purchased 1 life!', successStyle); statusMessage.anchor.set(0.5, 0.5); statusMessage.x = 2048 / 3; statusMessage.y = 1500; //{2P} // Adjusted position marketModal.addChild(statusMessage); // Play purchase sound LK.getSound('Moneyses').play(); // Update button states after purchase var updatedScore = LK.getScore(); buyLifeBtn.interactive = updatedScore >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; buyPowerUpBtn.interactive = updatedScore >= 100; buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5; } else { // Show error message // Use the constructor to create a new Text2 with updated fill color var errorStyle = { size: 50, fill: 0xFF0000 }; marketModal.removeChild(statusMessage); statusMessage = new Text2('Not enough score! Need 100.', errorStyle); statusMessage.anchor.set(0.5, 0.5); statusMessage.x = 2048 / 3; statusMessage.y = 1500; //{30} // Adjusted position marketModal.addChild(statusMessage); // Play error sound LK.getSound('Damage').play(); } }; // Buy power-up button handler buyPowerUpBtn.buttonMode = true; buyPowerUpBtn.down = function () { var currentScore = LK.getScore(); if (currentScore >= 100) { // Deduct score LK.setScore(currentScore - 100); scoreTxt.setText(LK.getScore()); // Spawn a power-up at the player's position spawnPowerUpAtPlayer(); // Show success message var successStyle = { size: 50, fill: 0x00FF00 }; marketModal.removeChild(statusMessage); statusMessage = new Text2('Successfully purchased Power-Up!', successStyle); statusMessage.anchor.set(0.5, 0.5); statusMessage.x = 2048 / 3; statusMessage.y = 1500; marketModal.addChild(statusMessage); // Play purchase sound LK.getSound('Moneyses').play(); // Update button states after purchase var updatedScore = LK.getScore(); buyLifeBtn.interactive = updatedScore >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; buyPowerUpBtn.interactive = updatedScore >= 100; buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5; } else { // Show error message var errorStyle = { size: 50, fill: 0xFF0000 }; marketModal.removeChild(statusMessage); statusMessage = new Text2('Not enough score! Need 100.', errorStyle); statusMessage.anchor.set(0.5, 0.5); statusMessage.x = 2048 / 3; statusMessage.y = 1500; marketModal.addChild(statusMessage); // Play error sound LK.getSound('Damage').play(); } }; closeMarketBtn.interactive = true; closeMarketBtn.buttonMode = true; closeMarketBtn.down = function () { marketModal.visible = false; }; // Rules modal var rulesModal = new Container(); this.children.forEach(function (child) { if (child === rulesModal) { child.visible = false; } }); self.addChild(rulesModal); // Rules modal background var modalBg = LK.getAsset('dusman', { anchorX: 0.5, anchorY: 0.5, width: 1600, height: 1800 }); modalBg.tint = 0x333333; modalBg.x = 2048 / 3; modalBg.y = 2732 / 2; rulesModal.addChild(modalBg); // Rules title var rulesTitle = new Text2('Game Rules', { size: 180, fill: 0xFFFFFF }); rulesTitle.anchor.set(0.5, 0); rulesTitle.x = 2048 / 3; rulesTitle.y = 500; rulesModal.addChild(rulesTitle); // Rules content var rulesContent = new Text2('- Killing the monster bees (+2)\n' + '- Collecting the money (+1)\n' + '- Getting caught by the turtle (-1 life)\n' + '- Touching the wires on the left (game over)\n' + '- Visit the market to buy extra lives for 100 score\n' + '- Buy power-ups in the market for special abilities\n' + '- PowerUp prevents turtle spawns for 30 seconds\n' + '- Money Rain occurs every 30 seconds for 10 seconds', { size: 60, fill: 0xFFFFFF }); rulesContent.anchor.set(0.5, 0); rulesContent.x = 2048 / 3; rulesContent.y = 750; rulesModal.addChild(rulesContent); // Close button for rules modal var closeBtn = new Text2('Close', { size: 150, fill: 0xFFFFFF }); closeBtn.anchor.set(0.5, 0.5); closeBtn.x = 2048 / 3; closeBtn.y = 1800; rulesModal.addChild(closeBtn); // State tracking self.isOpen = false; self.isSoundOn = true; // Button handlers soundBtn.interactive = true; soundBtn.buttonMode = true; soundBtn.down = function () { self.isSoundOn = !self.isSoundOn; soundBtn.setText(self.isSoundOn ? 'Sound: ON' : 'Sound: OFF'); // Toggle game music if (self.isSoundOn) { LK.playMusic('gameMusic', { volume: 0.4 }); } else { LK.stopMusic(); } }; rulesBtn.interactive = true; rulesBtn.buttonMode = true; rulesBtn.down = function () { rulesModal.visible = true; marketModal.visible = false; }; closeBtn.interactive = true; closeBtn.buttonMode = true; closeBtn.down = function () { rulesModal.visible = false; }; backBtn.interactive = true; backBtn.buttonMode = true; backBtn.down = function () { self.toggle(); }; // Toggle menu visibility self.toggle = function () { self.isOpen = !self.isOpen; self.visible = self.isOpen; // Pause/unpause game functionality if (self.isOpen) { // Pause game when menu is open if (typeof pauseGame === 'function') { pauseGame(); } } else { // Resume game when menu is closed if (typeof resumeGame === 'function') { resumeGame(); } // Hide all modals when closing menu if (rulesModal) { rulesModal.visible = false; } if (marketModal) { marketModal.visible = false; } if (creatorModal) { creatorModal.visible = false; } } }; // Initialize as hidden self.visible = false; return self; }); var Money = Container.expand(function () { var self = Container.call(this); var moneyGraphics = self.attachAsset('money', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 3 + 2; // Random speed between 2 and 5 self.update = function () { self.y += self.speed; self.x += Math.sin(self.y / 100) * 20; // Increased sine wave amplitude moneyGraphics.rotation += 0.05; // Rotate the money if (self.y > 2732) { self.destroy(); } }; }); // Define a class for managing periodic money rain var MoneyRain = Container.expand(function () { var self = Container.call(this); // Time between money rain events in milliseconds (60 seconds) self.rainInterval = 60000; // Duration of each money rain in milliseconds (10 seconds) self.rainDuration = 10000; // Track if rain is active self.isRaining = false; // Track the interval ID for spawning money during rain self.moneySpawnInterval = null; // Function to start money rain self.startRain = function () { if (isGamePaused || self.isRaining) { return; } self.isRaining = true; // Create animated Money Rain text var moneyRainText = new MoneyRainText(); game.addChild(moneyRainText); moneyRainText.show(self.rainDuration); // Create update interval for the animated text var textUpdateInterval = LK.setInterval(function () { if (isGamePaused) { return; } moneyRainText.update(); }, 16); // Update at 60fps // Spawn money at regular intervals during the rain duration self.moneySpawnInterval = LK.setInterval(function () { if (isGamePaused) { return; } // Reduced number of money to spawn each time var moneyCount = Math.floor(Math.random() * 2) + 1; // 1-2 money objects for (var i = 0; i < moneyCount; i++) { var money = new Money(); money.x = Math.random() * 2048; // Random horizontal position money.y = -50; // Start above the screen game.addChild(money); } }, 500); // Spawn every 0.5 seconds during rain // Stop rain after duration LK.setTimeout(function () { if (self.moneySpawnInterval !== null) { LK.clearInterval(self.moneySpawnInterval); self.moneySpawnInterval = null; } if (textUpdateInterval !== null) { LK.clearInterval(textUpdateInterval); } self.isRaining = false; }, self.rainDuration); }; // Initialize rain cycle self.initialize = function () { // Start first rain after 60 seconds LK.setTimeout(function () { self.startRain(); // Set up recurring rain cycle LK.setInterval(function () { if (!isGamePaused) { self.startRain(); } }, self.rainInterval); }, 60000); // Delay the first rain by 60 seconds - no money will spawn before this }; return self; }); var MoneyRainText = Container.expand(function () { var self = Container.call(this); // Create the "Money Rain" text var rainText = new Text2('Money Rain', { size: 250, fill: 0xFFD700 // Gold color }); // Set anchor to center rainText.anchor.set(0.5, 0.5); // Add text to container self.addChild(rainText); // Initialize with horizontal motion parameters self.speed = 5; self.direction = 1; // 1 = right, -1 = left self.amplitude = 30; self.frequency = 0.05; self.oscillationOffset = 0; // Update position each frame self.update = function () { // Move horizontally self.x += self.speed * self.direction; // Bounce when reaching screen edges if (self.x > 1800) { self.direction = -1; } else if (self.x < 200) { self.direction = 1; } // Add sine wave motion for vertical movement self.oscillationOffset += self.frequency; self.y = self.baseY + Math.sin(self.oscillationOffset) * self.amplitude; }; // Show the text with animation self.show = function (duration) { // Position at center initially self.x = 2048 / 2; self.y = 400; self.baseY = self.y; self.oscillationOffset = 0; // Add scaling effect self.scale.set(0); tween(self.scale, { x: 1, y: 1 }, { duration: 500, easing: tween.elasticOut }); // Set auto-removal timer LK.setTimeout(function () { // Scale down and remove tween(self.scale, { x: 0, y: 0 }, { duration: 500, easing: tween.easeInBack, onFinish: function onFinish() { self.destroy(); } }); }, duration); }; return self; }); var NewEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3 self.update = function () { self.x -= self.speed; // Move from right to left self.y += Math.sin(self.x / 150) * 15; // Vertical oscillation for (var k = walls.length - 1; k >= 0; k--) { if (self.intersects(walls[k])) { // If NewEnemy intersects with a wall, adjust its position to prevent passing through if (self.x > walls[k].x) { self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2; } else { self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2; } } } if (self.y < 0) { self.y = 0; // Prevent moving above the top of the scene } if (self.x < -50) { self.destroy(); } }; }); //<Assets used in the game will automatically appear here> // 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 = 15; self.isJumping = false; self.velocityY = 0; self.update = function () { // Check if the player is outside the scene boundaries if (self.isJumping) { if (self.lastY > self.y) { LK.getSound('Fly').play(); // Play 'Fly' sound when moving upwards } self.lastY = self.y; // Update lastY to current y position self.y -= self.velocityY; self.velocityY -= gravity; if (self.velocityY <= 0 && self.y < 1366) { self.x += 7; // Move right by 7 units at peak } if (self.y >= 1366) { self.y = 1366; self.isJumping = false; self.velocityY = 0; } // Prevent player from being pushed when touching the top of a wall for (var k = walls.length - 1; k >= 0; k--) { if (self.intersects(walls[k])) { if (self.y < walls[k].y - walls[k].height / 2) { self.y = walls[k].y - walls[k].height / 2; self.velocityY = 0; self.isJumping = false; } } } } // Check if the player touches the left edge of the screen if (self.x <= 0) { LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene LK.showGameOver(); // End the game if the player touches the wires on the left } self.x += self.speedX; if (self.x > 2048 - playerGraphics.width / 2) { self.x = 2048 - playerGraphics.width / 2; // Prevent moving outside the right edge } // Removed vertical oscillation when the player is not jumping and not moving horizontally if (self.isJumping) { self.y -= self.velocityY; self.velocityY -= gravity; if (self.y >= 1366) { self.y = 1366; self.isJumping = false; self.velocityY = 0; } // Check if the player touches the top edge of the screen if (self.y <= 0) { LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene LK.showGameOver(); // End the game if the player touches the top edge } } }; self.jump = function () { if (!self.isJumping && self.y > 0) { self.isJumping = true; self.velocityY = 20; // Set initial jump velocity self.speedX = 0; // Reset horizontal speed } }; }); var PlayerHealth = Container.expand(function () { var self = Container.call(this); self.lives = 5; // Default initial lives self.initialize = function (initialLives) { self.lives = initialLives || 5; }; self.decreaseLife = function () { self.lives--; if (self.lives <= 0) { LK.showGameOver(); // End the game if no lives are left } }; self.getLives = function () { return self.lives; }; return self; }); // Define a class for the right button var RightButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('rightButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed character.speedX = moveSpeed; character.removeChild(character.children[0]); // Remove current player image character.attachAsset('rightImage', { anchorX: 0.5, anchorY: 0.5 }); // Change character image to 'rightImage' character.y += 100; // Move character down by 100px }; self.up = function (x, y, obj) { character.speedX = 0; character.removeChild(character.children[0]); // Remove current rightImage character.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Revert character image to original }; }); // ScrollingBackground class removed as we're using layered background instead // Define a class for the sine wave enemy var SineWaveEnemy = Container.expand(function () { var self = Container.call(this); var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 3; // Constant speed self.amplitude = 50; // Amplitude of the sine wave self.frequency = 100; // Frequency of the sine wave self.update = function () { self.x -= self.speed; self.y += Math.sin(self.x / self.frequency) * self.amplitude; for (var k = walls.length - 1; k >= 0; k--) { if (self.intersects(walls[k])) { // If SineWaveEnemy intersects with a wall, adjust its position to prevent passing through if (self.x > walls[k].x) { self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2; } else { self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2; } } } if (self.x < -50) { self.destroy(); } }; }); // Define a class for the up button var UpButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('upButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed player.jump(); }; }); var Wall = Container.expand(function () { var self = Container.call(this); var wallGraphics = self.attachAsset('wall', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; // Speed at which the wall moves from right to left self.update = function () { self.x -= self.speed; if (self.x < -wallGraphics.width) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ // No title, no description // Always backgroundColor is black backgroundColor: 0x000000 }); /**** * Game Code ****/ function spawnFlowers() { // This function is kept empty but not removed to maintain compatibility // Money only spawns during Money Rain events } // Define a class for managing player health // Initialize player health with 5 lives //Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property. //Storage library which should be used for persistent game data function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) { return t; } var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) { return i; } throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var playerHealth = new PlayerHealth(); playerHealth.initialize(5); // Create and display life icons var lifeIcons = []; for (var i = 0; i < playerHealth.getLives(); i++) { var lifeIcon = new LifeIcon(); lifeIcon.updatePosition(i); LK.gui.topLeft.addChild(lifeIcon); lifeIcons.push(lifeIcon); } // Store original decrease life function var originalDecreaseLife = playerHealth.decreaseLife; // Override the decrease life function playerHealth.decreaseLife = function () { // Call the original function originalDecreaseLife.call(playerHealth); // Remove a life icon if (lifeIcons.length > 0) { var iconToRemove = lifeIcons.pop(); iconToRemove.destroy(); } }; LK.setInterval(createKaplu, 5000); // Spawn 'kaplu' every 5 seconds var walls = []; function spawnWall() { if (isGamePaused) { return; } if (!powerUpActive) { var wall = new Wall(); wall.x = 2048 + wall.width / 2; // Start from the right edge of the screen wall.y = Math.random() * (2732 / 2 - wall.height) + wall.height / 2; // Random vertical position above the center game.addChild(wall); walls.push(wall); } } LK.setInterval(spawnWall, 10000); // Set interval to spawn walls every 10 seconds // Function to create sine wave enemies function createSineWaveEnemy() { if (isGamePaused) { return; } var enemy = new SineWaveEnemy(); enemy.x = 2048; // Start from the right edge of the screen enemy.y = Math.random() * 2732; // Random vertical position game.addChild(enemy); enemies.push(enemy); } // Set interval to spawn sine wave enemies LK.setInterval(createSineWaveEnemy, 5000); // Spawn every 5 seconds // MoneyRain now starts automatically every 60 seconds from MoneyRain.initialize() // Function to create enemies with different types and behaviors function createEnemy() { if (isGamePaused) { return; } var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "enemy"; var enemy; enemy = new Enemy(); enemy.x = 2048; // Start from the right edge of the screen enemy.y = Math.random() * (2732 - enemy.height) + enemy.height / 2; // Random vertical position within screen bounds game.addChild(enemy); enemies.push(enemy); } // Set intervals to spawn enemies LK.setInterval(function () { createEnemy("enemy"); // Normal enemy every 4 seconds }, 4000); // Function to spawn money on the screen function spawnMoney() { if (isGamePaused) { return; } // Number of money to spawn var moneyCount = LK.getScore() > 200 ? Math.floor(Math.random() * 1) + 1 : Math.floor(Math.random() * 3) + 2; for (var i = 0; i < moneyCount; i++) { // Create a new money object var money = new Money(); // Set random initial position money.x = Math.random() * 2048; // Random horizontal position money.y = -50; // Start above the screen // Add money to the game scene game.addChild(money); } } // Money spawning is only managed by MoneyRain system // No regular money spawning in the game // Create layers for background var backgroundLayers = []; // Order of layers from back to front (reversed) var layerOrder = ['Layer12', 'Layer11', 'Lauer10', 'Layer9', 'Layer8', 'Layer7', 'Layer6', 'Layer5', 'Layer4', 'Layer3', 'Layer2', 'Layer1']; // Add each layer for (var i = 0; i < layerOrder.length; i++) { var layer = LK.getAsset(layerOrder[i], { anchorX: 0.5, anchorY: 0.5 }); layer.x = 2048 / 2; layer.y = 2732 / 2; layer.scale.set(20); // Scale to fill the screen game.addChild(layer); backgroundLayers.push(layer); } // Variable to track game over state var gameOver = false; // Play background music when the game starts LK.playMusic('gameMusic', { volume: 0.8, loop: true }); // Variable to track power-up states var powerUpActive = false; var powerUpCooldown = false; // Function to spawn a super power-up function spawnSuperPowerUp() { if (powerUpActive || powerUpCooldown) { return; } // Create a new power-up asset var powerUp = LK.getAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); // Random x position within the scene width var x = Math.random() * (2048 - 50); powerUp.x = x; powerUp.y = -60; // Start above the screen // Add power-up to the game scene game.addChild(powerUp); // Move the power-up downwards var fall = LK.setInterval(function () { powerUp.y += 4; powerUp.x += Math.sin(powerUp.y / 100) * 10; // Sine wave pattern // Remove power-up if it goes off-screen if (powerUp.y > 2732) { LK.clearInterval(fall); powerUp.destroy(); } // Check for collision with player if (player.intersects(powerUp)) { LK.clearInterval(fall); powerUp.destroy(); activateSuperPower(); } }, 16); } // Function to activate the super power function activateSuperPower() { if (powerUpActive) { return; } powerUpActive = true; // Create and show power-up status indicator var powerUpIndicator = new Text2('PowerUp Active!', { size: 80, fill: 0x00FF00 }); powerUpIndicator.anchor.set(0.5, 0.5); powerUpIndicator.x = 2048 / 2; powerUpIndicator.y = 2732 / 2; LK.gui.center.addChild(powerUpIndicator); // Add pulsing effect to power-up indicator var _pulseIndicator = function pulseIndicator() { tween(powerUpIndicator.scale, { x: 1.2, y: 1.2 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(powerUpIndicator.scale, { x: 1, y: 1 }, { duration: 800, easing: tween.easeInOut, onFinish: _pulseIndicator }); } }); }; _pulseIndicator(); // Add glowing effect to player tween(player, { alpha: 0.7 }, { duration: 500, easing: tween.easeInOut, yoyo: true, loop: true }); // Power-Up does not affect money spawn rate // since money only spawns during Money Rain events powerUpCooldown = true; // Scale up the player player.scale.set(4); // Show countdown timer var remainingTime = 30; var countdownTimer = new Text2(remainingTime + 's', { size: 60, fill: 0xFFFFFF }); countdownTimer.anchor.set(0.5, 0); countdownTimer.x = 2048 / 2; countdownTimer.y = 230; LK.gui.top.addChild(countdownTimer); // Update timer every second var timerInterval = LK.setInterval(function () { remainingTime--; // When time is 10 or less, recreate the text with red color if (remainingTime <= 10) { // Remove the old timer LK.gui.top.removeChild(countdownTimer); // Create a new timer with red color countdownTimer = new Text2(remainingTime + 's', { size: 60, fill: 0xFF0000 // Red color for urgent countdown }); countdownTimer.anchor.set(0.5, 0); countdownTimer.x = 2048 / 2; countdownTimer.y = 230; LK.gui.top.addChild(countdownTimer); } else { // Just update the text for normal countdown countdownTimer.setText(remainingTime + 's'); } }, 1000); // Revert player scale after 30 seconds LK.setTimeout(function () { player.scale.set(1); powerUpActive = false; LK.gui.top.removeChild(powerUpIndicator); LK.gui.top.removeChild(countdownTimer); LK.clearInterval(timerInterval); player.alpha = 1; // Reset player alpha // Remove any tweens on the player tween.stop(player); // Cooldown before another power-up can spawn LK.setTimeout(function () { powerUpCooldown = false; }, 60000); // Set to 1 minute if player collects the power-up }, 30000); } // Attempt to spawn a power-up every 40 seconds, ensuring only one is active at a time if (!powerUpActive && !powerUpCooldown) { LK.setTimeout(spawnSuperPowerUp, 40000); } // Array to hold spikes var spikes = []; // Function to create spikes function createSpikes() { var spikeHeight = 100; // Height of each spike var spikeWidth = 30; // Width of each spike var gap = 50; // Gap between spikes // Create fixed spikes on the left edge of the scene for (var y = 0; y < 2732; y += spikeHeight + gap) { var spike = LK.getAsset('spike', { anchorX: 0.5, anchorY: 0.5 }); // Spike starting position (fixed to the left edge) var startX = -spikeWidth; // Left edge var startY = y; // Arranged with gap between them spike.x = startX; spike.y = startY; // Add spikes to the game scene game.addChild(spike); // Add spike object to the array spikes.push(spike); } } // Create spikes (only run once) createSpikes(); // Create and initialize money rain system var moneyRain = new MoneyRain(); moneyRain.initialize(); // Create and initialize the score text display var scoreTxt = new Text2('0', { size: 150, // Reduced size by 25% from 200 fill: 0x000000 // Black color for the score text }); // Set the initial score text to zero scoreTxt.setText(LK.getScore()); // Center the score text horizontally at the top of the screen scoreTxt.anchor.set(0.5, 0); // Anchor at the center of the top edge // Add the score text to the GUI overlay at a slightly left position from the top-right var newVisual = LK.getAsset('newVisual', { anchorX: 0.5, anchorY: 0.5 }); newVisual.x -= 100; // Move the new visual 100 pixels to the left newVisual.y += 100; // Move the new visual 100 pixels downwards scoreTxt.x = newVisual.x - 180; // Position score text 180 pixels to the left of the new visual scoreTxt.y = newVisual.y + 90 - 170; LK.gui.topRight.addChild(scoreTxt); LK.gui.topRight.addChild(newVisual); // Display Best Score in the center of the scene // Always show the highest score achieved, update if current score is higher // Create a menu button in the center of the screen when game starts var menuButton = LK.getAsset('menuButtonShape', { anchorX: 0.5, anchorY: 0.5, width: 200, height: 200 }); menuButton.scale.set(3); // Set scale to 3 for 3x size menuButton.tint = 0x3f51b5; // Nice blue color menuButton.x = 2048 / 2; // Center horizontally menuButton.y = 2732 / 2 + 1300; // Move 1300 units down from center menuButton.visible = true; // Ensure menu button is visible when game starts menuButton.alpha = 1; // Make sure button is fully opaque menuButton.interactive = true; menuButton.buttonMode = true; // Removed menu label from menu button // Create the menu system and add it to the GUI layer var menuSystem = new MenuSystem(); LK.gui.addChild(menuSystem); // Don't show menu automatically when game starts menuSystem.isOpen = false; menuSystem.visible = false; // Game is not paused initially isGamePaused = false; // Add the menu button directly to the main game scene for full visibility game.addChild(menuButton); // Add animation effects for menu button menuButton.down = function () { // Scale down button when clicked tween(menuButton.scale, { x: 2.7, y: 2.7 }, { duration: 100, easing: tween.easeOut }); // Toggle menu system menuSystem.toggle(); // Update button appearance based on menu state menuButton.tint = menuSystem.isOpen ? 0x888888 : 0x444444; }; menuButton.up = function () { // Scale back to normal when released tween(menuButton.scale, { x: 3, y: 3 }, { duration: 100, easing: tween.easeOut }); }; // Add enhanced pulse animation to menu button to make it more visible function pulseMenuButton() { // Make sure menuButton is visible before animating menuButton.visible = true; // Ensure menu button is centered 1300 units below center menuButton.x = 2048 / 2; menuButton.y = 2732 / 2 + 1300; tween(menuButton.scale, { x: 3.6, y: 3.6 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(menuButton.scale, { x: 3, y: 3 }, { duration: 800, easing: tween.easeInOut, onFinish: pulseMenuButton }); } }); // Also animate the button's alpha for a flashy effect tween(menuButton, { alpha: 0.8 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(menuButton, { alpha: 1 }, { duration: 800, easing: tween.easeInOut }); } }); } // Start pulse animation immediately pulseMenuButton(); // Ensure menu button is on top of all other elements if (game.children.indexOf(menuButton) !== -1) { game.removeChild(menuButton); game.addChild(menuButton); } // Set initial button state with a nice blue color menuButton.tint = 0x3f51b5; // Blue color for visibility // Get best score from storage with proper default var bestScore = storage.bestScore !== undefined ? storage.bestScore : 0; var bestScoreTxt = new Text2('Best Score: ' + bestScore, { size: 121.5, // 135'in %10 küçüğü fill: 0x000000 }); bestScoreTxt.anchor.set(0.5, 0.5); bestScoreTxt.x = 2048 / 2; bestScoreTxt.y = 2732 / 2 + 920; // 30 units higher game.addChild(bestScoreTxt); // Update best score if current score exceeds it, and always show the highest function updateBestScoreDisplay() { var currentScore = LK.getScore(); var storedBest = storage.bestScore !== undefined ? storage.bestScore : 0; if (currentScore > storedBest) { storage.bestScore = currentScore; bestScoreTxt.setText('Best Score: ' + currentScore); } else { bestScoreTxt.setText('Best Score: ' + storedBest); } } var moveSpeed = 5; // Speed for character movement var gravity = 0.8; // Decrease gravity for a lighter effect var windSpeed = 2; // Reduce wind speed for horizontal movement // Initialize player at the center of the screen var player = game.addChild(new Player()); var character = player; // Define character as a reference to player player.x = 1024; player.y = 1366; player.speedX = 0; // Prevent movement on spawn player.speedY = 0; // Prevent movement on spawn player.isJumping = false; player.velocityY = 0; // Initialize up button var upButton = game.addChild(new UpButton()); upButton.x = 2048 / 2 - 500; // Middle point's x coordinate minus button width upButton.y = 2732 / 2 + 600; // Middle point's y coordinate plus button height plus additional 100 pixels // Add scaling effect to the up button when pressed and released upButton.down = function () { upButton.scale.set(0.9); // Scale down by 10% }; upButton.up = function () { upButton.scale.set(1); // Reset to original size }; upButton.move = function () { upButton.scale.set(1); // Reset to original size if mouse leaves }; // Initialize left button var leftButton = game.addChild(new LeftButton()); leftButton.x = 300; // Move slightly more to the right leftButton.y = 2732 - 250; // Move slightly more upwards // Initialize right button var rightButton = game.addChild(new RightButton()); rightButton.x = 2048 - 300; // Move slightly more to the left rightButton.y = 2732 - 250; // Move slightly more upwards // Initialize down button var downButton = game.addChild(new DownButton()); downButton.x = 2048 - 500 - 50; // Right edge minus button width and margin downButton.y = 2732 - 500 - 250; // Move the down button slightly more upwards // Initialize enemies var enemies = []; var enemySpawnInterval = 160; // Initial slower spawn rate for the first 30 seconds var enemySpawnIncreaseInterval = 40000; // Increase spawn rate every 40 seconds var enemySpawnCounter = 0; // Variables to track button presses var isPressingUp = false; var isPressingDown = false; // Event listeners for button presses upButton.down = function () { isPressingUp = true; character.removeChild(character.children[0]); // Remove current player image character.attachAsset('playerup', { anchorX: 0.5, anchorY: 0.5 }); // Change character image to 'up' }; upButton.up = function () { isPressingUp = false; character.removeChild(character.children[0]); // Remove current playerup image character.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Revert character image to original }; downButton.down = function () { isPressingDown = true; character.removeChild(character.children[0]); // Remove current player image character.attachAsset('player_down', { anchorX: 0.5, anchorY: 0.5 }); // Change character image to 'dow' character.y += 50; // Move character down by 50px character.x += 160; // Move character right by 160px }; downButton.up = function () { isPressingDown = false; character.removeChild(character.children[0]); // Remove current player_down image character.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Revert character image to original character.y -= 50; // Move character back to original position }; // Update player movement based on button presses function updatePlayerMovement() { if (isPressingUp) { player.velocityY = -20; // Increase upward speed player.x += 8; // Move right by 8 units } // Removed upward movement when the down button is pressed player.y += player.velocityY; if (!isPressingUp && !isPressingDown) { player.velocityY += gravity; } if (player.y > 1366) { player.y = 1366; player.velocityY = 0; } if (player.y < 0) { player.y = 0; player.velocityY = 0; } } // Set interval for updating player movement LK.setInterval(updatePlayerMovement, 16); // Set interval to increase enemy spawn rate LK.setInterval(function () { if (enemySpawnInterval > 20) { // Ensure a minimum spawn interval enemySpawnInterval -= 10; // Decrease interval to increase spawn rate } }, enemySpawnIncreaseInterval); // Set interval for updating player movement LK.setInterval(function () { player.update(); }, 16); // Game state tracking var isGamePaused = false; // Function to pause the game function pauseGame() { isGamePaused = true; // Optional: Stop or pause background music // LK.stopMusic(); } // Function to resume the game function resumeGame() { isGamePaused = false; // Optional: Resume background music if it was playing if (menuSystem.isSoundOn) { LK.playMusic('gameMusic', { volume: 0.4 }); } } // Update menu system toggle to pause/resume game menuSystem.toggle = function () { this.isOpen = !this.isOpen; this.visible = this.isOpen; // Ensure menu button is always visible menuButton.visible = true; if (this.isOpen) { // When menu opens, move the menu button to top right tween(menuButton, { x: 2048 - 150, y: 150, scaleX: 3, scaleY: 3 }, { duration: 300, easing: tween.easeOut }); pauseGame(); } else { // Always keep button centered 1300 units below center when menu is closed tween(menuButton, { x: 2048 / 2, y: 2732 / 2 + 1300, scaleX: 3, scaleY: 3 }, { duration: 300, easing: tween.easeOut }); resumeGame(); // Find rulesModal in children and hide it this.children.forEach(function (child) { if (child.children && child.children[0] && child.children[0].tint === 0x333333) { child.visible = false; } }); } }; // Handle game updates game.update = function () { // Skip updates if game is paused if (isGamePaused) { return; } player.update(); // Update all background layers for (var k = walls.length - 1; k >= 0; k--) { walls[k].update(); if (player.intersects(walls[k])) { // Allow player to approach walls without collision if (player.x > walls[k].x) { if (player.x < walls[k].x + walls[k].width / 2 + player.width / 2 - 10) { player.x = walls[k].x + walls[k].width / 2 + player.width / 2 - 10; } } else { if (player.x > walls[k].x - walls[k].width / 2 - player.width / 2 + 10) { player.x = walls[k].x - walls[k].width / 2 - player.width / 2 + 10; } } // Do not trigger game over when intersecting with walls } } for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Money) { var money = game.children[i]; money.update(); if (player.intersects(money)) { money.destroy(); // Remove money from the scene LK.setScore(LK.getScore() + 1); // Increase score by 1 for collecting money scoreTxt.setText(LK.getScore()); // Update the score text display updateBestScoreDisplay(); // Update best score if needed // Update buy button state if market is visible if (menuSystem.isOpen && menuSystem.children[4] && menuSystem.children[4].visible) { buyLifeBtn.interactive = LK.getScore() >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; } LK.getSound('Moneyses').play(); // Play 'Moneyses' sound when player intersects with money } } } // Check if the player is completely out of the scene if (player.x < -player.width || player.x > 2048 + player.width || player.y < -player.height || player.y > 2732 + player.height) { LK.showGameOver(); // End the game if the player is completely out of bounds } player.x -= windSpeed; // Apply wind effect to move player left // Spawn enemies enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval * 6 && !powerUpActive) { if (LK.ticks >= 1800) { // 30 seconds * 60 FPS enemySpawnInterval = 80; // Increase spawn rate after 30 seconds } if (enemySpawnCounter % 2 === 0) { // Introduce a delay between spawns return; } // Increase interval to reduce new enemy spawn rate var enemy = new Enemy(); enemy.x = 2048; // Spawn from the right edge of the screen enemy.y = Math.random() * (2732 / 2) + 100; // Random y position slightly lower from the top half of the screen enemies.push(enemy); game.addChild(enemy); enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.getSound('Kick').play(); // Play 'Kick' sound when player intersects with an enemy // Show 'kan' image at the collision point for 1 second var kanVisual = LK.getAsset('kan', { anchorX: 0.5, anchorY: 0.5 }); kanVisual.x = enemies[j].x; kanVisual.y = enemies[j].y; game.addChild(kanVisual); // Remove enemy from scene and array enemies[j].destroy(); enemies.splice(j, 1); // Ensure player is above kan visual game.addChild(player); // Remove 'kan' visual after 1 second LK.setTimeout(function () { kanVisual.destroy(); }, 1000); if (enemies[j] instanceof NewEnemy) { LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene if (LK.ticks >= 3600) { // 60 seconds * 60 FPS LK.setScore(LK.getScore() - 10); // Decrease score by 10 after 60 seconds } else { LK.setScore(LK.getScore() - 3); // Decrease score by 3 for newEnemy } if (LK.getScore() < 0) { LK.getSound('End').play(); // Play 'End' sound LK.showGameOver(); // End the game if the score goes below zero } } else { LK.setScore(LK.getScore() + 2); // Increase score by 2 for killing monster bees } scoreTxt.setText(LK.getScore()); // Update the score text display updateBestScoreDisplay(); // Update best score if needed // Update buy buttons state if market is visible if (menuSystem.isOpen && menuSystem.children[4] && menuSystem.children[4].visible) { var currentScore = LK.getScore(); buyLifeBtn.interactive = currentScore >= 100; buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; buyPowerUpBtn.interactive = currentScore >= 100; buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5; } if (LK.getScore() % 20 === 0) { enemySpawnInterval = Math.max(20, enemySpawnInterval - 10); // Increase spawn rate by decreasing interval } if (LK.getScore() % 100 === 0 && LK.getScore() !== 0) { LK.effects.flashScreen(0x00ff00, 1000); // Flash green light across the entire scene } if (LK.getScore() >= 40) { enemySpawnInterval = Math.max(10, enemySpawnInterval - 5); // Further increase spawn rate when score is 40 or more } } } for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Kaplu) { var kaplu = game.children[i]; kaplu.update(); if (player.intersects(kaplu)) { LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene LK.setScore(LK.getScore() - 5); // Decrease score by 5 scoreTxt.setText(LK.getScore()); // Update the score text display updateBestScoreDisplay(); // Update best score if needed playerHealth.decreaseLife(); // Decrease player health by 1 for getting caught by the turtle LK.getSound('Damage').play(); // Play 'Damage' sound when player intersects with 'kaplu' kaplu.destroy(); // Remove 'kaplu' from the scene } } } }; // Handle player movement with touch game.down = function (x, y, obj) { if (y < 1366) { // Check if the touch is in the upper half player.x = x; player.y = y; } }; game.move = function (x, y, obj) { if (y < 1366) { // Check if the touch is in the upper half player.x = x; player.y = y; } }; function createKaplu() { if (isGamePaused) { return; } if (!powerUpActive) { var kaplu = new Kaplu(); kaplu.x = 2048 + kaplu.width / 2; // Start from the right edge of the screen kaplu.y = Math.random() * (2732 / 2 - kaplu.height) + kaplu.height / 2; // Random vertical position above the center game.addChild(kaplu); } } // Function to spawn a power-up at player's position function spawnPowerUpAtPlayer() { // Create a new power-up asset var powerUp = LK.getAsset('powerUp', { anchorX: 0.5, anchorY: 0.5 }); // Position at player location with slight offset powerUp.x = player.x; powerUp.y = player.y - 100; // Position above the player // Add power-up to the game scene game.addChild(powerUp); // Add rotating animation var rotationTween = tween(powerUp, { rotation: Math.PI * 2 // Full rotation (360 degrees) }, { duration: 2000, easing: tween.easeInOut, loop: true }); // Add pulsing effect var _pulseAnimation = function pulseAnimation() { tween(powerUp.scale, { x: 1.2, y: 1.2 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { tween(powerUp.scale, { x: 1, y: 1 }, { duration: 800, easing: tween.easeInOut, onFinish: _pulseAnimation }); } }); }; _pulseAnimation(); // Make it automatically activate after 5 seconds if not collected LK.setTimeout(function () { if (powerUp.parent) { // Check if power-up still exists powerUp.destroy(); activateSuperPower(); // Activate the power-up } }, 5000); // Add collision detection for faster collection var collisionInterval = LK.setInterval(function () { if (powerUp.parent && player.intersects(powerUp)) { powerUp.destroy(); LK.clearInterval(collisionInterval); activateSuperPower(); // Activate the power-up when collected } }, 16); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
// Define a class for the down button
var DownButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('downButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed
if (player.y + 100 <= 2732) {
player.y += 100;
// Check if player is intersecting with NewEnemy
for (var i = 0; i < enemies.length; i++) {
if (enemies[i] instanceof NewEnemy && player.intersects(enemies[i])) {
LK.setScore(LK.getScore() + 10); // Increase score by 10
scoreTxt.setText(LK.getScore()); // Update the score text display
break; // Exit loop after finding the first intersecting NewEnemy
}
}
}
};
});
// 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 = Math.random() * 2 + 1; // Random speed between 1 and 3
self.update = function () {
self.x -= self.speed; // Move from right to left
self.y += Math.sin(self.x / 150) * 15; // Further reduce vertical oscillation amplitude
for (var k = walls.length - 1; k >= 0; k--) {
if (self.intersects(walls[k])) {
// If enemy intersects with a wall, adjust its position to prevent passing through
if (self.x > walls[k].x) {
self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2;
} else {
self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2;
}
}
}
if (self.y < 0) {
self.y = 0; // Prevent moving above the top of the scene
}
if (self.x < -50) {
self.destroy();
}
};
});
var Kaplu = Container.expand(function () {
var self = Container.call(this);
// Store frame asset ids
var kapluFrames = ['Kaplu1', 'Kaplu2', 'Kaplu3'];
var currentFrame = 0;
// Attach all frames, but only show the first one
var kapluGraphicsArr = [];
for (var i = 0; i < kapluFrames.length; i++) {
var g = self.attachAsset(kapluFrames[i], {
anchorX: 0.5,
anchorY: 0.5
});
g.visible = i === 0;
kapluGraphicsArr.push(g);
}
var kapluGraphics = kapluGraphicsArr[0];
// Animation timing
var frameInterval = 120; // ms per frame (~8 FPS)
var lastFrameTime = Date.now();
self.update = function () {
self.x -= 5; // Move 'kaplu' from right to left faster
// Animate frames
var now = Date.now();
if (now - lastFrameTime >= frameInterval) {
// Hide current frame
kapluGraphicsArr[currentFrame].visible = false;
// Advance frame
currentFrame = (currentFrame + 1) % kapluFrames.length;
// Show new frame
kapluGraphicsArr[currentFrame].visible = true;
kapluGraphics = kapluGraphicsArr[currentFrame];
lastFrameTime = now;
}
for (var k = walls.length - 1; k >= 0; k--) {
if (self.intersects(walls[k])) {
// If 'kaplu' intersects with a wall, adjust its position to prevent passing through
if (self.x > walls[k].x) {
self.x = walls[k].x + walls[k].width / 2 + kapluGraphics.width / 2;
} else {
self.x = walls[k].x - walls[k].width / 2 - kapluGraphics.width / 2;
}
}
}
if (self.x < -kapluGraphics.width / 2) {
self.destroy(); // Remove 'kaplu' when it goes off-screen
}
};
});
// Define a class for the left button
var LeftButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('leftButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed
character.speedX = -moveSpeed;
character.removeChild(character.children[0]); // Remove current player image
character.attachAsset('leftImage', {
// Change character image to 'leftImage'
anchorX: 0.5,
anchorY: 0.5
});
};
self.up = function (x, y, obj) {
character.speedX = 0;
character.removeChild(character.children[0]); // Remove current leftImage
character.attachAsset('player', {
// Revert character image to original
anchorX: 0.5,
anchorY: 0.5
});
};
});
var LifeIcon = Container.expand(function () {
var self = Container.call(this);
var lifeIconGraphics = self.attachAsset('lifeIcon', {
anchorX: 0.5,
anchorY: 0.5
});
self.updatePosition = function (index) {
self.x = 50 + index * 60; // Position each icon with a gap
self.y = 50; // Position at the top-left corner
};
});
var MenuSystem = Container.expand(function () {
var self = Container.call(this);
// Background overlay for menu
var menuBg = LK.getAsset('dusman', {
anchorX: 0.5,
anchorY: 0.5,
width: 2948,
height: 3932
});
menuBg.alpha = 0.8;
menuBg.tint = 0x000000;
self.addChild(menuBg);
// Create menu title
var menuTitle = new Text2('Game Menu', {
size: 100,
fill: 0xFFFFFF
});
menuTitle.anchor.set(0.5, 0);
menuTitle.x = 2048 / 3;
menuTitle.y = 400;
self.addChild(menuTitle);
// Sound button
var soundBtn = new Text2('Sound: ON', {
size: 50,
fill: 0xFFFFFF
});
soundBtn.anchor.set(0.5, 0.5);
soundBtn.x = 2048 / 3;
soundBtn.y = 700;
self.addChild(soundBtn);
// Button for game rules
var rulesBtn = new Text2('Game Rules', {
size: 50,
fill: 0xFFFFFF
});
rulesBtn.anchor.set(0.5, 0.5);
rulesBtn.x = 2048 / 3;
rulesBtn.y = 850;
self.addChild(rulesBtn);
// Market button
var marketBtn = new Text2('Market', {
size: 50,
fill: 0xFFFFFF
});
marketBtn.anchor.set(0.5, 0.5);
marketBtn.x = 2048 / 3;
marketBtn.y = 1000;
self.addChild(marketBtn);
// Back to game button
var backBtn = new Text2('Back to Game', {
size: 50,
fill: 0xFFFFFF
});
backBtn.anchor.set(0.5, 0.5);
backBtn.x = 2048 / 3;
backBtn.y = 1150;
self.addChild(backBtn);
// Creator button
var creatorBtn = new Text2('Creator', {
size: 50,
fill: 0xFFFFFF
});
creatorBtn.anchor.set(0.5, 0.5);
creatorBtn.x = 2048 / 3;
creatorBtn.y = 1400;
self.addChild(creatorBtn);
// Creator modal
var creatorModal = new Container();
creatorModal.visible = false;
self.addChild(creatorModal);
// Creator modal background
var creatorModalBg = LK.getAsset('dusman', {
anchorX: 0.5,
anchorY: 0.5,
width: 1600,
height: 800
});
creatorModalBg.tint = 0x333333;
creatorModalBg.x = 2048 / 3;
creatorModalBg.y = 2732 / 2;
creatorModal.addChild(creatorModalBg);
// Creator name
var creatorName = new Text2('Akif Uraz Aydın', {
size: 100,
fill: 0xFFFFFF
});
creatorName.anchor.set(0.5, 0);
creatorName.x = 2048 / 3;
creatorName.y = 2732 / 2 - 100;
creatorModal.addChild(creatorName);
// Close button for creator modal
var closeCreatorBtn = new Text2('Close', {
size: 50,
fill: 0xFFFFFF
});
closeCreatorBtn.anchor.set(0.5, 0.5);
closeCreatorBtn.x = 2048 / 3;
closeCreatorBtn.y = 2732 / 2 + 200;
creatorModal.addChild(closeCreatorBtn);
// Market modal
var marketModal = new Container();
marketModal.visible = false;
self.addChild(marketModal);
// Market modal background
var marketModalBg = LK.getAsset('dusman', {
anchorX: 0.5,
anchorY: 0.5,
width: 1600,
height: 1600 // Increased height to accommodate power-up option
});
marketModalBg.tint = 0x333333;
marketModalBg.x = 2048 / 3;
marketModalBg.y = 2732 / 2;
marketModal.addChild(marketModalBg);
// Market title
var marketTitle = new Text2('Market', {
size: 180,
fill: 0xFFFFFF
});
marketTitle.anchor.set(0.5, 0);
marketTitle.x = 2048 / 3;
marketTitle.y = 700; // Moved up to make room for new items
marketModal.addChild(marketTitle);
// Life icon in market
var marketLifeIcon = LK.getAsset('lifeIcon', {
anchorX: 0.5,
anchorY: 0.5
});
marketLifeIcon.x = 2048 / 3 - 200;
marketLifeIcon.y = 950; // Adjusted position
marketLifeIcon.scale.set(2);
marketModal.addChild(marketLifeIcon);
// Life description
var lifeDescription = new Text2('Extra Life\nCost: 100 Score', {
size: 60,
fill: 0xFFFFFF
});
lifeDescription.anchor.set(0, 0.5);
lifeDescription.x = 2048 / 3 - 100;
lifeDescription.y = 950; // Adjusted position
marketModal.addChild(lifeDescription);
// Buy life button
var buyLifeBtn = new Text2('Buy', {
size: 80,
fill: 0x00FF00
});
buyLifeBtn.anchor.set(0.5, 0.5);
buyLifeBtn.x = 2048 / 3;
buyLifeBtn.y = 1050; // Adjusted position
// Set initial interactive state based on score
buyLifeBtn.interactive = LK.getScore() >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5; // Visual indicator for disabled state
marketModal.addChild(buyLifeBtn);
// Power-up section
// Power-up icon in market
var marketPowerUpIcon = LK.getAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
marketPowerUpIcon.x = 2048 / 3 - 200;
marketPowerUpIcon.y = 1250; // Position below life option
marketPowerUpIcon.scale.set(0.8);
marketModal.addChild(marketPowerUpIcon);
// Power-up description
var powerUpDescription = new Text2('Power Up Box\nCost: 100 Score', {
size: 60,
fill: 0xFFFFFF
});
powerUpDescription.anchor.set(0, 0.5);
powerUpDescription.x = 2048 / 3 - 100;
powerUpDescription.y = 1250;
marketModal.addChild(powerUpDescription);
// Buy power-up button
var buyPowerUpBtn = new Text2('Buy', {
size: 80,
fill: 0x00FF00
});
buyPowerUpBtn.anchor.set(0.5, 0.5);
buyPowerUpBtn.x = 2048 / 3;
buyPowerUpBtn.y = 1350;
// Set initial interactive state based on score
buyPowerUpBtn.interactive = LK.getScore() >= 100;
buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5;
marketModal.addChild(buyPowerUpBtn);
// Status message for purchases
var statusMessage = new Text2('', {
size: 50,
fill: 0xFFFFFF
});
statusMessage.anchor.set(0.5, 0.5);
statusMessage.x = 2048 / 3;
statusMessage.y = 1500; //{2p} // Adjusted position
marketModal.addChild(statusMessage);
// Close button for market modal
var closeMarketBtn = new Text2('Close', {
size: 100,
fill: 0xFFFFFF
});
closeMarketBtn.anchor.set(0.5, 0.5);
closeMarketBtn.x = 2048 / 3;
closeMarketBtn.y = 1700; // Adjusted position
marketModal.addChild(closeMarketBtn);
// Button handlers
creatorBtn.interactive = true;
creatorBtn.buttonMode = true;
creatorBtn.down = function () {
creatorModal.visible = true;
marketModal.visible = false;
};
closeCreatorBtn.interactive = true;
closeCreatorBtn.buttonMode = true;
closeCreatorBtn.down = function () {
creatorModal.visible = false;
};
// Market button handlers
marketBtn.interactive = true;
marketBtn.buttonMode = true;
marketBtn.down = function () {
marketModal.visible = true;
creatorModal.visible = false;
statusMessage.setText('');
// Update buy buttons state based on current score
var currentScore = LK.getScore();
buyLifeBtn.interactive = currentScore >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5;
buyPowerUpBtn.interactive = currentScore >= 100;
buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5;
};
// Buy life button handler
buyLifeBtn.buttonMode = true;
buyLifeBtn.down = function () {
var currentScore = LK.getScore();
if (currentScore >= 100) {
// Deduct score
LK.setScore(currentScore - 100);
scoreTxt.setText(LK.getScore());
// Add life
playerHealth.lives++;
// Create new life icon
var lifeIcon = new LifeIcon();
lifeIcon.updatePosition(playerHealth.lives - 1);
LK.gui.topLeft.addChild(lifeIcon);
lifeIcons.push(lifeIcon);
// Show success message
statusMessage.setText('Successfully purchased 1 life!');
// Use the constructor to create a new Text2 with updated fill color
var successStyle = {
size: 50,
fill: 0x00FF00
};
marketModal.removeChild(statusMessage);
statusMessage = new Text2('Successfully purchased 1 life!', successStyle);
statusMessage.anchor.set(0.5, 0.5);
statusMessage.x = 2048 / 3;
statusMessage.y = 1500; //{2P} // Adjusted position
marketModal.addChild(statusMessage);
// Play purchase sound
LK.getSound('Moneyses').play();
// Update button states after purchase
var updatedScore = LK.getScore();
buyLifeBtn.interactive = updatedScore >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5;
buyPowerUpBtn.interactive = updatedScore >= 100;
buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5;
} else {
// Show error message
// Use the constructor to create a new Text2 with updated fill color
var errorStyle = {
size: 50,
fill: 0xFF0000
};
marketModal.removeChild(statusMessage);
statusMessage = new Text2('Not enough score! Need 100.', errorStyle);
statusMessage.anchor.set(0.5, 0.5);
statusMessage.x = 2048 / 3;
statusMessage.y = 1500; //{30} // Adjusted position
marketModal.addChild(statusMessage);
// Play error sound
LK.getSound('Damage').play();
}
};
// Buy power-up button handler
buyPowerUpBtn.buttonMode = true;
buyPowerUpBtn.down = function () {
var currentScore = LK.getScore();
if (currentScore >= 100) {
// Deduct score
LK.setScore(currentScore - 100);
scoreTxt.setText(LK.getScore());
// Spawn a power-up at the player's position
spawnPowerUpAtPlayer();
// Show success message
var successStyle = {
size: 50,
fill: 0x00FF00
};
marketModal.removeChild(statusMessage);
statusMessage = new Text2('Successfully purchased Power-Up!', successStyle);
statusMessage.anchor.set(0.5, 0.5);
statusMessage.x = 2048 / 3;
statusMessage.y = 1500;
marketModal.addChild(statusMessage);
// Play purchase sound
LK.getSound('Moneyses').play();
// Update button states after purchase
var updatedScore = LK.getScore();
buyLifeBtn.interactive = updatedScore >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5;
buyPowerUpBtn.interactive = updatedScore >= 100;
buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5;
} else {
// Show error message
var errorStyle = {
size: 50,
fill: 0xFF0000
};
marketModal.removeChild(statusMessage);
statusMessage = new Text2('Not enough score! Need 100.', errorStyle);
statusMessage.anchor.set(0.5, 0.5);
statusMessage.x = 2048 / 3;
statusMessage.y = 1500;
marketModal.addChild(statusMessage);
// Play error sound
LK.getSound('Damage').play();
}
};
closeMarketBtn.interactive = true;
closeMarketBtn.buttonMode = true;
closeMarketBtn.down = function () {
marketModal.visible = false;
};
// Rules modal
var rulesModal = new Container();
this.children.forEach(function (child) {
if (child === rulesModal) {
child.visible = false;
}
});
self.addChild(rulesModal);
// Rules modal background
var modalBg = LK.getAsset('dusman', {
anchorX: 0.5,
anchorY: 0.5,
width: 1600,
height: 1800
});
modalBg.tint = 0x333333;
modalBg.x = 2048 / 3;
modalBg.y = 2732 / 2;
rulesModal.addChild(modalBg);
// Rules title
var rulesTitle = new Text2('Game Rules', {
size: 180,
fill: 0xFFFFFF
});
rulesTitle.anchor.set(0.5, 0);
rulesTitle.x = 2048 / 3;
rulesTitle.y = 500;
rulesModal.addChild(rulesTitle);
// Rules content
var rulesContent = new Text2('- Killing the monster bees (+2)\n' + '- Collecting the money (+1)\n' + '- Getting caught by the turtle (-1 life)\n' + '- Touching the wires on the left (game over)\n' + '- Visit the market to buy extra lives for 100 score\n' + '- Buy power-ups in the market for special abilities\n' + '- PowerUp prevents turtle spawns for 30 seconds\n' + '- Money Rain occurs every 30 seconds for 10 seconds', {
size: 60,
fill: 0xFFFFFF
});
rulesContent.anchor.set(0.5, 0);
rulesContent.x = 2048 / 3;
rulesContent.y = 750;
rulesModal.addChild(rulesContent);
// Close button for rules modal
var closeBtn = new Text2('Close', {
size: 150,
fill: 0xFFFFFF
});
closeBtn.anchor.set(0.5, 0.5);
closeBtn.x = 2048 / 3;
closeBtn.y = 1800;
rulesModal.addChild(closeBtn);
// State tracking
self.isOpen = false;
self.isSoundOn = true;
// Button handlers
soundBtn.interactive = true;
soundBtn.buttonMode = true;
soundBtn.down = function () {
self.isSoundOn = !self.isSoundOn;
soundBtn.setText(self.isSoundOn ? 'Sound: ON' : 'Sound: OFF');
// Toggle game music
if (self.isSoundOn) {
LK.playMusic('gameMusic', {
volume: 0.4
});
} else {
LK.stopMusic();
}
};
rulesBtn.interactive = true;
rulesBtn.buttonMode = true;
rulesBtn.down = function () {
rulesModal.visible = true;
marketModal.visible = false;
};
closeBtn.interactive = true;
closeBtn.buttonMode = true;
closeBtn.down = function () {
rulesModal.visible = false;
};
backBtn.interactive = true;
backBtn.buttonMode = true;
backBtn.down = function () {
self.toggle();
};
// Toggle menu visibility
self.toggle = function () {
self.isOpen = !self.isOpen;
self.visible = self.isOpen;
// Pause/unpause game functionality
if (self.isOpen) {
// Pause game when menu is open
if (typeof pauseGame === 'function') {
pauseGame();
}
} else {
// Resume game when menu is closed
if (typeof resumeGame === 'function') {
resumeGame();
}
// Hide all modals when closing menu
if (rulesModal) {
rulesModal.visible = false;
}
if (marketModal) {
marketModal.visible = false;
}
if (creatorModal) {
creatorModal.visible = false;
}
}
};
// Initialize as hidden
self.visible = false;
return self;
});
var Money = Container.expand(function () {
var self = Container.call(this);
var moneyGraphics = self.attachAsset('money', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 2; // Random speed between 2 and 5
self.update = function () {
self.y += self.speed;
self.x += Math.sin(self.y / 100) * 20; // Increased sine wave amplitude
moneyGraphics.rotation += 0.05; // Rotate the money
if (self.y > 2732) {
self.destroy();
}
};
});
// Define a class for managing periodic money rain
var MoneyRain = Container.expand(function () {
var self = Container.call(this);
// Time between money rain events in milliseconds (60 seconds)
self.rainInterval = 60000;
// Duration of each money rain in milliseconds (10 seconds)
self.rainDuration = 10000;
// Track if rain is active
self.isRaining = false;
// Track the interval ID for spawning money during rain
self.moneySpawnInterval = null;
// Function to start money rain
self.startRain = function () {
if (isGamePaused || self.isRaining) {
return;
}
self.isRaining = true;
// Create animated Money Rain text
var moneyRainText = new MoneyRainText();
game.addChild(moneyRainText);
moneyRainText.show(self.rainDuration);
// Create update interval for the animated text
var textUpdateInterval = LK.setInterval(function () {
if (isGamePaused) {
return;
}
moneyRainText.update();
}, 16); // Update at 60fps
// Spawn money at regular intervals during the rain duration
self.moneySpawnInterval = LK.setInterval(function () {
if (isGamePaused) {
return;
}
// Reduced number of money to spawn each time
var moneyCount = Math.floor(Math.random() * 2) + 1; // 1-2 money objects
for (var i = 0; i < moneyCount; i++) {
var money = new Money();
money.x = Math.random() * 2048; // Random horizontal position
money.y = -50; // Start above the screen
game.addChild(money);
}
}, 500); // Spawn every 0.5 seconds during rain
// Stop rain after duration
LK.setTimeout(function () {
if (self.moneySpawnInterval !== null) {
LK.clearInterval(self.moneySpawnInterval);
self.moneySpawnInterval = null;
}
if (textUpdateInterval !== null) {
LK.clearInterval(textUpdateInterval);
}
self.isRaining = false;
}, self.rainDuration);
};
// Initialize rain cycle
self.initialize = function () {
// Start first rain after 60 seconds
LK.setTimeout(function () {
self.startRain();
// Set up recurring rain cycle
LK.setInterval(function () {
if (!isGamePaused) {
self.startRain();
}
}, self.rainInterval);
}, 60000); // Delay the first rain by 60 seconds - no money will spawn before this
};
return self;
});
var MoneyRainText = Container.expand(function () {
var self = Container.call(this);
// Create the "Money Rain" text
var rainText = new Text2('Money Rain', {
size: 250,
fill: 0xFFD700 // Gold color
});
// Set anchor to center
rainText.anchor.set(0.5, 0.5);
// Add text to container
self.addChild(rainText);
// Initialize with horizontal motion parameters
self.speed = 5;
self.direction = 1; // 1 = right, -1 = left
self.amplitude = 30;
self.frequency = 0.05;
self.oscillationOffset = 0;
// Update position each frame
self.update = function () {
// Move horizontally
self.x += self.speed * self.direction;
// Bounce when reaching screen edges
if (self.x > 1800) {
self.direction = -1;
} else if (self.x < 200) {
self.direction = 1;
}
// Add sine wave motion for vertical movement
self.oscillationOffset += self.frequency;
self.y = self.baseY + Math.sin(self.oscillationOffset) * self.amplitude;
};
// Show the text with animation
self.show = function (duration) {
// Position at center initially
self.x = 2048 / 2;
self.y = 400;
self.baseY = self.y;
self.oscillationOffset = 0;
// Add scaling effect
self.scale.set(0);
tween(self.scale, {
x: 1,
y: 1
}, {
duration: 500,
easing: tween.elasticOut
});
// Set auto-removal timer
LK.setTimeout(function () {
// Scale down and remove
tween(self.scale, {
x: 0,
y: 0
}, {
duration: 500,
easing: tween.easeInBack,
onFinish: function onFinish() {
self.destroy();
}
});
}, duration);
};
return self;
});
var NewEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3
self.update = function () {
self.x -= self.speed; // Move from right to left
self.y += Math.sin(self.x / 150) * 15; // Vertical oscillation
for (var k = walls.length - 1; k >= 0; k--) {
if (self.intersects(walls[k])) {
// If NewEnemy intersects with a wall, adjust its position to prevent passing through
if (self.x > walls[k].x) {
self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2;
} else {
self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2;
}
}
}
if (self.y < 0) {
self.y = 0; // Prevent moving above the top of the scene
}
if (self.x < -50) {
self.destroy();
}
};
});
//<Assets used in the game will automatically appear here>
// 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 = 15;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
// Check if the player is outside the scene boundaries
if (self.isJumping) {
if (self.lastY > self.y) {
LK.getSound('Fly').play(); // Play 'Fly' sound when moving upwards
}
self.lastY = self.y; // Update lastY to current y position
self.y -= self.velocityY;
self.velocityY -= gravity;
if (self.velocityY <= 0 && self.y < 1366) {
self.x += 7; // Move right by 7 units at peak
}
if (self.y >= 1366) {
self.y = 1366;
self.isJumping = false;
self.velocityY = 0;
}
// Prevent player from being pushed when touching the top of a wall
for (var k = walls.length - 1; k >= 0; k--) {
if (self.intersects(walls[k])) {
if (self.y < walls[k].y - walls[k].height / 2) {
self.y = walls[k].y - walls[k].height / 2;
self.velocityY = 0;
self.isJumping = false;
}
}
}
}
// Check if the player touches the left edge of the screen
if (self.x <= 0) {
LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene
LK.showGameOver(); // End the game if the player touches the wires on the left
}
self.x += self.speedX;
if (self.x > 2048 - playerGraphics.width / 2) {
self.x = 2048 - playerGraphics.width / 2; // Prevent moving outside the right edge
}
// Removed vertical oscillation when the player is not jumping and not moving horizontally
if (self.isJumping) {
self.y -= self.velocityY;
self.velocityY -= gravity;
if (self.y >= 1366) {
self.y = 1366;
self.isJumping = false;
self.velocityY = 0;
}
// Check if the player touches the top edge of the screen
if (self.y <= 0) {
LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene
LK.showGameOver(); // End the game if the player touches the top edge
}
}
};
self.jump = function () {
if (!self.isJumping && self.y > 0) {
self.isJumping = true;
self.velocityY = 20; // Set initial jump velocity
self.speedX = 0; // Reset horizontal speed
}
};
});
var PlayerHealth = Container.expand(function () {
var self = Container.call(this);
self.lives = 5; // Default initial lives
self.initialize = function (initialLives) {
self.lives = initialLives || 5;
};
self.decreaseLife = function () {
self.lives--;
if (self.lives <= 0) {
LK.showGameOver(); // End the game if no lives are left
}
};
self.getLives = function () {
return self.lives;
};
return self;
});
// Define a class for the right button
var RightButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('rightButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed
character.speedX = moveSpeed;
character.removeChild(character.children[0]); // Remove current player image
character.attachAsset('rightImage', {
anchorX: 0.5,
anchorY: 0.5
}); // Change character image to 'rightImage'
character.y += 100; // Move character down by 100px
};
self.up = function (x, y, obj) {
character.speedX = 0;
character.removeChild(character.children[0]); // Remove current rightImage
character.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
}); // Revert character image to original
};
});
// ScrollingBackground class removed as we're using layered background instead
// Define a class for the sine wave enemy
var SineWaveEnemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3; // Constant speed
self.amplitude = 50; // Amplitude of the sine wave
self.frequency = 100; // Frequency of the sine wave
self.update = function () {
self.x -= self.speed;
self.y += Math.sin(self.x / self.frequency) * self.amplitude;
for (var k = walls.length - 1; k >= 0; k--) {
if (self.intersects(walls[k])) {
// If SineWaveEnemy intersects with a wall, adjust its position to prevent passing through
if (self.x > walls[k].x) {
self.x = walls[k].x + walls[k].width / 2 + enemyGraphics.width / 2;
} else {
self.x = walls[k].x - walls[k].width / 2 - enemyGraphics.width / 2;
}
}
}
if (self.x < -50) {
self.destroy();
}
};
});
// Define a class for the up button
var UpButton = Container.expand(function () {
var self = Container.call(this);
var buttonGraphics = self.attachAsset('upButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
LK.getSound('Kok').play(); // Play 'Kok' sound when button is pressed
player.jump();
};
});
var Wall = Container.expand(function () {
var self = Container.call(this);
var wallGraphics = self.attachAsset('wall', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5; // Speed at which the wall moves from right to left
self.update = function () {
self.x -= self.speed;
if (self.x < -wallGraphics.width) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
// No title, no description
// Always backgroundColor is black
backgroundColor: 0x000000
});
/****
* Game Code
****/
function spawnFlowers() {
// This function is kept empty but not removed to maintain compatibility
// Money only spawns during Money Rain events
}
// Define a class for managing player health
// Initialize player health with 5 lives
//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
//Storage library which should be used for persistent game data
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _classCallCheck(a, n) {
if (!(a instanceof n)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(e, r) {
for (var t = 0; t < r.length; t++) {
var o = r[t];
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
}
}
function _createClass(e, r, t) {
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
writable: !1
}), e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var playerHealth = new PlayerHealth();
playerHealth.initialize(5);
// Create and display life icons
var lifeIcons = [];
for (var i = 0; i < playerHealth.getLives(); i++) {
var lifeIcon = new LifeIcon();
lifeIcon.updatePosition(i);
LK.gui.topLeft.addChild(lifeIcon);
lifeIcons.push(lifeIcon);
}
// Store original decrease life function
var originalDecreaseLife = playerHealth.decreaseLife;
// Override the decrease life function
playerHealth.decreaseLife = function () {
// Call the original function
originalDecreaseLife.call(playerHealth);
// Remove a life icon
if (lifeIcons.length > 0) {
var iconToRemove = lifeIcons.pop();
iconToRemove.destroy();
}
};
LK.setInterval(createKaplu, 5000); // Spawn 'kaplu' every 5 seconds
var walls = [];
function spawnWall() {
if (isGamePaused) {
return;
}
if (!powerUpActive) {
var wall = new Wall();
wall.x = 2048 + wall.width / 2; // Start from the right edge of the screen
wall.y = Math.random() * (2732 / 2 - wall.height) + wall.height / 2; // Random vertical position above the center
game.addChild(wall);
walls.push(wall);
}
}
LK.setInterval(spawnWall, 10000); // Set interval to spawn walls every 10 seconds
// Function to create sine wave enemies
function createSineWaveEnemy() {
if (isGamePaused) {
return;
}
var enemy = new SineWaveEnemy();
enemy.x = 2048; // Start from the right edge of the screen
enemy.y = Math.random() * 2732; // Random vertical position
game.addChild(enemy);
enemies.push(enemy);
}
// Set interval to spawn sine wave enemies
LK.setInterval(createSineWaveEnemy, 5000); // Spawn every 5 seconds
// MoneyRain now starts automatically every 60 seconds from MoneyRain.initialize()
// Function to create enemies with different types and behaviors
function createEnemy() {
if (isGamePaused) {
return;
}
var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "enemy";
var enemy;
enemy = new Enemy();
enemy.x = 2048; // Start from the right edge of the screen
enemy.y = Math.random() * (2732 - enemy.height) + enemy.height / 2; // Random vertical position within screen bounds
game.addChild(enemy);
enemies.push(enemy);
}
// Set intervals to spawn enemies
LK.setInterval(function () {
createEnemy("enemy"); // Normal enemy every 4 seconds
}, 4000);
// Function to spawn money on the screen
function spawnMoney() {
if (isGamePaused) {
return;
}
// Number of money to spawn
var moneyCount = LK.getScore() > 200 ? Math.floor(Math.random() * 1) + 1 : Math.floor(Math.random() * 3) + 2;
for (var i = 0; i < moneyCount; i++) {
// Create a new money object
var money = new Money();
// Set random initial position
money.x = Math.random() * 2048; // Random horizontal position
money.y = -50; // Start above the screen
// Add money to the game scene
game.addChild(money);
}
}
// Money spawning is only managed by MoneyRain system
// No regular money spawning in the game
// Create layers for background
var backgroundLayers = [];
// Order of layers from back to front (reversed)
var layerOrder = ['Layer12', 'Layer11', 'Lauer10', 'Layer9', 'Layer8', 'Layer7', 'Layer6', 'Layer5', 'Layer4', 'Layer3', 'Layer2', 'Layer1'];
// Add each layer
for (var i = 0; i < layerOrder.length; i++) {
var layer = LK.getAsset(layerOrder[i], {
anchorX: 0.5,
anchorY: 0.5
});
layer.x = 2048 / 2;
layer.y = 2732 / 2;
layer.scale.set(20); // Scale to fill the screen
game.addChild(layer);
backgroundLayers.push(layer);
}
// Variable to track game over state
var gameOver = false;
// Play background music when the game starts
LK.playMusic('gameMusic', {
volume: 0.8,
loop: true
});
// Variable to track power-up states
var powerUpActive = false;
var powerUpCooldown = false;
// Function to spawn a super power-up
function spawnSuperPowerUp() {
if (powerUpActive || powerUpCooldown) {
return;
}
// Create a new power-up asset
var powerUp = LK.getAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
// Random x position within the scene width
var x = Math.random() * (2048 - 50);
powerUp.x = x;
powerUp.y = -60; // Start above the screen
// Add power-up to the game scene
game.addChild(powerUp);
// Move the power-up downwards
var fall = LK.setInterval(function () {
powerUp.y += 4;
powerUp.x += Math.sin(powerUp.y / 100) * 10; // Sine wave pattern
// Remove power-up if it goes off-screen
if (powerUp.y > 2732) {
LK.clearInterval(fall);
powerUp.destroy();
}
// Check for collision with player
if (player.intersects(powerUp)) {
LK.clearInterval(fall);
powerUp.destroy();
activateSuperPower();
}
}, 16);
}
// Function to activate the super power
function activateSuperPower() {
if (powerUpActive) {
return;
}
powerUpActive = true;
// Create and show power-up status indicator
var powerUpIndicator = new Text2('PowerUp Active!', {
size: 80,
fill: 0x00FF00
});
powerUpIndicator.anchor.set(0.5, 0.5);
powerUpIndicator.x = 2048 / 2;
powerUpIndicator.y = 2732 / 2;
LK.gui.center.addChild(powerUpIndicator);
// Add pulsing effect to power-up indicator
var _pulseIndicator = function pulseIndicator() {
tween(powerUpIndicator.scale, {
x: 1.2,
y: 1.2
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(powerUpIndicator.scale, {
x: 1,
y: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _pulseIndicator
});
}
});
};
_pulseIndicator();
// Add glowing effect to player
tween(player, {
alpha: 0.7
}, {
duration: 500,
easing: tween.easeInOut,
yoyo: true,
loop: true
});
// Power-Up does not affect money spawn rate
// since money only spawns during Money Rain events
powerUpCooldown = true;
// Scale up the player
player.scale.set(4);
// Show countdown timer
var remainingTime = 30;
var countdownTimer = new Text2(remainingTime + 's', {
size: 60,
fill: 0xFFFFFF
});
countdownTimer.anchor.set(0.5, 0);
countdownTimer.x = 2048 / 2;
countdownTimer.y = 230;
LK.gui.top.addChild(countdownTimer);
// Update timer every second
var timerInterval = LK.setInterval(function () {
remainingTime--;
// When time is 10 or less, recreate the text with red color
if (remainingTime <= 10) {
// Remove the old timer
LK.gui.top.removeChild(countdownTimer);
// Create a new timer with red color
countdownTimer = new Text2(remainingTime + 's', {
size: 60,
fill: 0xFF0000 // Red color for urgent countdown
});
countdownTimer.anchor.set(0.5, 0);
countdownTimer.x = 2048 / 2;
countdownTimer.y = 230;
LK.gui.top.addChild(countdownTimer);
} else {
// Just update the text for normal countdown
countdownTimer.setText(remainingTime + 's');
}
}, 1000);
// Revert player scale after 30 seconds
LK.setTimeout(function () {
player.scale.set(1);
powerUpActive = false;
LK.gui.top.removeChild(powerUpIndicator);
LK.gui.top.removeChild(countdownTimer);
LK.clearInterval(timerInterval);
player.alpha = 1; // Reset player alpha
// Remove any tweens on the player
tween.stop(player);
// Cooldown before another power-up can spawn
LK.setTimeout(function () {
powerUpCooldown = false;
}, 60000); // Set to 1 minute if player collects the power-up
}, 30000);
}
// Attempt to spawn a power-up every 40 seconds, ensuring only one is active at a time
if (!powerUpActive && !powerUpCooldown) {
LK.setTimeout(spawnSuperPowerUp, 40000);
}
// Array to hold spikes
var spikes = [];
// Function to create spikes
function createSpikes() {
var spikeHeight = 100; // Height of each spike
var spikeWidth = 30; // Width of each spike
var gap = 50; // Gap between spikes
// Create fixed spikes on the left edge of the scene
for (var y = 0; y < 2732; y += spikeHeight + gap) {
var spike = LK.getAsset('spike', {
anchorX: 0.5,
anchorY: 0.5
});
// Spike starting position (fixed to the left edge)
var startX = -spikeWidth; // Left edge
var startY = y; // Arranged with gap between them
spike.x = startX;
spike.y = startY;
// Add spikes to the game scene
game.addChild(spike);
// Add spike object to the array
spikes.push(spike);
}
}
// Create spikes (only run once)
createSpikes();
// Create and initialize money rain system
var moneyRain = new MoneyRain();
moneyRain.initialize();
// Create and initialize the score text display
var scoreTxt = new Text2('0', {
size: 150,
// Reduced size by 25% from 200
fill: 0x000000 // Black color for the score text
});
// Set the initial score text to zero
scoreTxt.setText(LK.getScore());
// Center the score text horizontally at the top of the screen
scoreTxt.anchor.set(0.5, 0); // Anchor at the center of the top edge
// Add the score text to the GUI overlay at a slightly left position from the top-right
var newVisual = LK.getAsset('newVisual', {
anchorX: 0.5,
anchorY: 0.5
});
newVisual.x -= 100; // Move the new visual 100 pixels to the left
newVisual.y += 100; // Move the new visual 100 pixels downwards
scoreTxt.x = newVisual.x - 180; // Position score text 180 pixels to the left of the new visual
scoreTxt.y = newVisual.y + 90 - 170;
LK.gui.topRight.addChild(scoreTxt);
LK.gui.topRight.addChild(newVisual);
// Display Best Score in the center of the scene
// Always show the highest score achieved, update if current score is higher
// Create a menu button in the center of the screen when game starts
var menuButton = LK.getAsset('menuButtonShape', {
anchorX: 0.5,
anchorY: 0.5,
width: 200,
height: 200
});
menuButton.scale.set(3); // Set scale to 3 for 3x size
menuButton.tint = 0x3f51b5; // Nice blue color
menuButton.x = 2048 / 2; // Center horizontally
menuButton.y = 2732 / 2 + 1300; // Move 1300 units down from center
menuButton.visible = true; // Ensure menu button is visible when game starts
menuButton.alpha = 1; // Make sure button is fully opaque
menuButton.interactive = true;
menuButton.buttonMode = true;
// Removed menu label from menu button
// Create the menu system and add it to the GUI layer
var menuSystem = new MenuSystem();
LK.gui.addChild(menuSystem);
// Don't show menu automatically when game starts
menuSystem.isOpen = false;
menuSystem.visible = false;
// Game is not paused initially
isGamePaused = false;
// Add the menu button directly to the main game scene for full visibility
game.addChild(menuButton);
// Add animation effects for menu button
menuButton.down = function () {
// Scale down button when clicked
tween(menuButton.scale, {
x: 2.7,
y: 2.7
}, {
duration: 100,
easing: tween.easeOut
});
// Toggle menu system
menuSystem.toggle();
// Update button appearance based on menu state
menuButton.tint = menuSystem.isOpen ? 0x888888 : 0x444444;
};
menuButton.up = function () {
// Scale back to normal when released
tween(menuButton.scale, {
x: 3,
y: 3
}, {
duration: 100,
easing: tween.easeOut
});
};
// Add enhanced pulse animation to menu button to make it more visible
function pulseMenuButton() {
// Make sure menuButton is visible before animating
menuButton.visible = true;
// Ensure menu button is centered 1300 units below center
menuButton.x = 2048 / 2;
menuButton.y = 2732 / 2 + 1300;
tween(menuButton.scale, {
x: 3.6,
y: 3.6
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(menuButton.scale, {
x: 3,
y: 3
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: pulseMenuButton
});
}
});
// Also animate the button's alpha for a flashy effect
tween(menuButton, {
alpha: 0.8
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(menuButton, {
alpha: 1
}, {
duration: 800,
easing: tween.easeInOut
});
}
});
}
// Start pulse animation immediately
pulseMenuButton();
// Ensure menu button is on top of all other elements
if (game.children.indexOf(menuButton) !== -1) {
game.removeChild(menuButton);
game.addChild(menuButton);
}
// Set initial button state with a nice blue color
menuButton.tint = 0x3f51b5; // Blue color for visibility
// Get best score from storage with proper default
var bestScore = storage.bestScore !== undefined ? storage.bestScore : 0;
var bestScoreTxt = new Text2('Best Score: ' + bestScore, {
size: 121.5,
// 135'in %10 küçüğü
fill: 0x000000
});
bestScoreTxt.anchor.set(0.5, 0.5);
bestScoreTxt.x = 2048 / 2;
bestScoreTxt.y = 2732 / 2 + 920; // 30 units higher
game.addChild(bestScoreTxt);
// Update best score if current score exceeds it, and always show the highest
function updateBestScoreDisplay() {
var currentScore = LK.getScore();
var storedBest = storage.bestScore !== undefined ? storage.bestScore : 0;
if (currentScore > storedBest) {
storage.bestScore = currentScore;
bestScoreTxt.setText('Best Score: ' + currentScore);
} else {
bestScoreTxt.setText('Best Score: ' + storedBest);
}
}
var moveSpeed = 5; // Speed for character movement
var gravity = 0.8; // Decrease gravity for a lighter effect
var windSpeed = 2; // Reduce wind speed for horizontal movement
// Initialize player at the center of the screen
var player = game.addChild(new Player());
var character = player; // Define character as a reference to player
player.x = 1024;
player.y = 1366;
player.speedX = 0; // Prevent movement on spawn
player.speedY = 0; // Prevent movement on spawn
player.isJumping = false;
player.velocityY = 0;
// Initialize up button
var upButton = game.addChild(new UpButton());
upButton.x = 2048 / 2 - 500; // Middle point's x coordinate minus button width
upButton.y = 2732 / 2 + 600; // Middle point's y coordinate plus button height plus additional 100 pixels
// Add scaling effect to the up button when pressed and released
upButton.down = function () {
upButton.scale.set(0.9); // Scale down by 10%
};
upButton.up = function () {
upButton.scale.set(1); // Reset to original size
};
upButton.move = function () {
upButton.scale.set(1); // Reset to original size if mouse leaves
};
// Initialize left button
var leftButton = game.addChild(new LeftButton());
leftButton.x = 300; // Move slightly more to the right
leftButton.y = 2732 - 250; // Move slightly more upwards
// Initialize right button
var rightButton = game.addChild(new RightButton());
rightButton.x = 2048 - 300; // Move slightly more to the left
rightButton.y = 2732 - 250; // Move slightly more upwards
// Initialize down button
var downButton = game.addChild(new DownButton());
downButton.x = 2048 - 500 - 50; // Right edge minus button width and margin
downButton.y = 2732 - 500 - 250; // Move the down button slightly more upwards
// Initialize enemies
var enemies = [];
var enemySpawnInterval = 160; // Initial slower spawn rate for the first 30 seconds
var enemySpawnIncreaseInterval = 40000; // Increase spawn rate every 40 seconds
var enemySpawnCounter = 0;
// Variables to track button presses
var isPressingUp = false;
var isPressingDown = false;
// Event listeners for button presses
upButton.down = function () {
isPressingUp = true;
character.removeChild(character.children[0]); // Remove current player image
character.attachAsset('playerup', {
anchorX: 0.5,
anchorY: 0.5
}); // Change character image to 'up'
};
upButton.up = function () {
isPressingUp = false;
character.removeChild(character.children[0]); // Remove current playerup image
character.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
}); // Revert character image to original
};
downButton.down = function () {
isPressingDown = true;
character.removeChild(character.children[0]); // Remove current player image
character.attachAsset('player_down', {
anchorX: 0.5,
anchorY: 0.5
}); // Change character image to 'dow'
character.y += 50; // Move character down by 50px
character.x += 160; // Move character right by 160px
};
downButton.up = function () {
isPressingDown = false;
character.removeChild(character.children[0]); // Remove current player_down image
character.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
}); // Revert character image to original
character.y -= 50; // Move character back to original position
};
// Update player movement based on button presses
function updatePlayerMovement() {
if (isPressingUp) {
player.velocityY = -20; // Increase upward speed
player.x += 8; // Move right by 8 units
}
// Removed upward movement when the down button is pressed
player.y += player.velocityY;
if (!isPressingUp && !isPressingDown) {
player.velocityY += gravity;
}
if (player.y > 1366) {
player.y = 1366;
player.velocityY = 0;
}
if (player.y < 0) {
player.y = 0;
player.velocityY = 0;
}
}
// Set interval for updating player movement
LK.setInterval(updatePlayerMovement, 16);
// Set interval to increase enemy spawn rate
LK.setInterval(function () {
if (enemySpawnInterval > 20) {
// Ensure a minimum spawn interval
enemySpawnInterval -= 10; // Decrease interval to increase spawn rate
}
}, enemySpawnIncreaseInterval);
// Set interval for updating player movement
LK.setInterval(function () {
player.update();
}, 16);
// Game state tracking
var isGamePaused = false;
// Function to pause the game
function pauseGame() {
isGamePaused = true;
// Optional: Stop or pause background music
// LK.stopMusic();
}
// Function to resume the game
function resumeGame() {
isGamePaused = false;
// Optional: Resume background music if it was playing
if (menuSystem.isSoundOn) {
LK.playMusic('gameMusic', {
volume: 0.4
});
}
}
// Update menu system toggle to pause/resume game
menuSystem.toggle = function () {
this.isOpen = !this.isOpen;
this.visible = this.isOpen;
// Ensure menu button is always visible
menuButton.visible = true;
if (this.isOpen) {
// When menu opens, move the menu button to top right
tween(menuButton, {
x: 2048 - 150,
y: 150,
scaleX: 3,
scaleY: 3
}, {
duration: 300,
easing: tween.easeOut
});
pauseGame();
} else {
// Always keep button centered 1300 units below center when menu is closed
tween(menuButton, {
x: 2048 / 2,
y: 2732 / 2 + 1300,
scaleX: 3,
scaleY: 3
}, {
duration: 300,
easing: tween.easeOut
});
resumeGame();
// Find rulesModal in children and hide it
this.children.forEach(function (child) {
if (child.children && child.children[0] && child.children[0].tint === 0x333333) {
child.visible = false;
}
});
}
};
// Handle game updates
game.update = function () {
// Skip updates if game is paused
if (isGamePaused) {
return;
}
player.update();
// Update all background layers
for (var k = walls.length - 1; k >= 0; k--) {
walls[k].update();
if (player.intersects(walls[k])) {
// Allow player to approach walls without collision
if (player.x > walls[k].x) {
if (player.x < walls[k].x + walls[k].width / 2 + player.width / 2 - 10) {
player.x = walls[k].x + walls[k].width / 2 + player.width / 2 - 10;
}
} else {
if (player.x > walls[k].x - walls[k].width / 2 - player.width / 2 + 10) {
player.x = walls[k].x - walls[k].width / 2 - player.width / 2 + 10;
}
}
// Do not trigger game over when intersecting with walls
}
}
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Money) {
var money = game.children[i];
money.update();
if (player.intersects(money)) {
money.destroy(); // Remove money from the scene
LK.setScore(LK.getScore() + 1); // Increase score by 1 for collecting money
scoreTxt.setText(LK.getScore()); // Update the score text display
updateBestScoreDisplay(); // Update best score if needed
// Update buy button state if market is visible
if (menuSystem.isOpen && menuSystem.children[4] && menuSystem.children[4].visible) {
buyLifeBtn.interactive = LK.getScore() >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5;
}
LK.getSound('Moneyses').play(); // Play 'Moneyses' sound when player intersects with money
}
}
}
// Check if the player is completely out of the scene
if (player.x < -player.width || player.x > 2048 + player.width || player.y < -player.height || player.y > 2732 + player.height) {
LK.showGameOver(); // End the game if the player is completely out of bounds
}
player.x -= windSpeed; // Apply wind effect to move player left
// Spawn enemies
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval * 6 && !powerUpActive) {
if (LK.ticks >= 1800) {
// 30 seconds * 60 FPS
enemySpawnInterval = 80; // Increase spawn rate after 30 seconds
}
if (enemySpawnCounter % 2 === 0) {
// Introduce a delay between spawns
return;
}
// Increase interval to reduce new enemy spawn rate
var enemy = new Enemy();
enemy.x = 2048; // Spawn from the right edge of the screen
enemy.y = Math.random() * (2732 / 2) + 100; // Random y position slightly lower from the top half of the screen
enemies.push(enemy);
game.addChild(enemy);
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
LK.getSound('Kick').play(); // Play 'Kick' sound when player intersects with an enemy
// Show 'kan' image at the collision point for 1 second
var kanVisual = LK.getAsset('kan', {
anchorX: 0.5,
anchorY: 0.5
});
kanVisual.x = enemies[j].x;
kanVisual.y = enemies[j].y;
game.addChild(kanVisual);
// Remove enemy from scene and array
enemies[j].destroy();
enemies.splice(j, 1);
// Ensure player is above kan visual
game.addChild(player);
// Remove 'kan' visual after 1 second
LK.setTimeout(function () {
kanVisual.destroy();
}, 1000);
if (enemies[j] instanceof NewEnemy) {
LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene
if (LK.ticks >= 3600) {
// 60 seconds * 60 FPS
LK.setScore(LK.getScore() - 10); // Decrease score by 10 after 60 seconds
} else {
LK.setScore(LK.getScore() - 3); // Decrease score by 3 for newEnemy
}
if (LK.getScore() < 0) {
LK.getSound('End').play(); // Play 'End' sound
LK.showGameOver(); // End the game if the score goes below zero
}
} else {
LK.setScore(LK.getScore() + 2); // Increase score by 2 for killing monster bees
}
scoreTxt.setText(LK.getScore()); // Update the score text display
updateBestScoreDisplay(); // Update best score if needed
// Update buy buttons state if market is visible
if (menuSystem.isOpen && menuSystem.children[4] && menuSystem.children[4].visible) {
var currentScore = LK.getScore();
buyLifeBtn.interactive = currentScore >= 100;
buyLifeBtn.alpha = buyLifeBtn.interactive ? 1.0 : 0.5;
buyPowerUpBtn.interactive = currentScore >= 100;
buyPowerUpBtn.alpha = buyPowerUpBtn.interactive ? 1.0 : 0.5;
}
if (LK.getScore() % 20 === 0) {
enemySpawnInterval = Math.max(20, enemySpawnInterval - 10); // Increase spawn rate by decreasing interval
}
if (LK.getScore() % 100 === 0 && LK.getScore() !== 0) {
LK.effects.flashScreen(0x00ff00, 1000); // Flash green light across the entire scene
}
if (LK.getScore() >= 40) {
enemySpawnInterval = Math.max(10, enemySpawnInterval - 5); // Further increase spawn rate when score is 40 or more
}
}
}
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Kaplu) {
var kaplu = game.children[i];
kaplu.update();
if (player.intersects(kaplu)) {
LK.effects.flashScreen(0xff0000, 1000); // Flash red light across the entire scene
LK.setScore(LK.getScore() - 5); // Decrease score by 5
scoreTxt.setText(LK.getScore()); // Update the score text display
updateBestScoreDisplay(); // Update best score if needed
playerHealth.decreaseLife(); // Decrease player health by 1 for getting caught by the turtle
LK.getSound('Damage').play(); // Play 'Damage' sound when player intersects with 'kaplu'
kaplu.destroy(); // Remove 'kaplu' from the scene
}
}
}
};
// Handle player movement with touch
game.down = function (x, y, obj) {
if (y < 1366) {
// Check if the touch is in the upper half
player.x = x;
player.y = y;
}
};
game.move = function (x, y, obj) {
if (y < 1366) {
// Check if the touch is in the upper half
player.x = x;
player.y = y;
}
};
function createKaplu() {
if (isGamePaused) {
return;
}
if (!powerUpActive) {
var kaplu = new Kaplu();
kaplu.x = 2048 + kaplu.width / 2; // Start from the right edge of the screen
kaplu.y = Math.random() * (2732 / 2 - kaplu.height) + kaplu.height / 2; // Random vertical position above the center
game.addChild(kaplu);
}
}
// Function to spawn a power-up at player's position
function spawnPowerUpAtPlayer() {
// Create a new power-up asset
var powerUp = LK.getAsset('powerUp', {
anchorX: 0.5,
anchorY: 0.5
});
// Position at player location with slight offset
powerUp.x = player.x;
powerUp.y = player.y - 100; // Position above the player
// Add power-up to the game scene
game.addChild(powerUp);
// Add rotating animation
var rotationTween = tween(powerUp, {
rotation: Math.PI * 2 // Full rotation (360 degrees)
}, {
duration: 2000,
easing: tween.easeInOut,
loop: true
});
// Add pulsing effect
var _pulseAnimation = function pulseAnimation() {
tween(powerUp.scale, {
x: 1.2,
y: 1.2
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(powerUp.scale, {
x: 1,
y: 1
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: _pulseAnimation
});
}
});
};
_pulseAnimation();
// Make it automatically activate after 5 seconds if not collected
LK.setTimeout(function () {
if (powerUp.parent) {
// Check if power-up still exists
powerUp.destroy();
activateSuperPower(); // Activate the power-up
}
}, 5000);
// Add collision detection for faster collection
var collisionInterval = LK.setInterval(function () {
if (powerUp.parent && player.intersects(powerUp)) {
powerUp.destroy();
LK.clearInterval(collisionInterval);
activateSuperPower(); // Activate the power-up when collected
}
}, 16);
}