User prompt
when each level is completed assign the campsite to collide with player which adds another oxygen bar to the player
User prompt
make each level is accessible to play and fix the problem which is occurring after completing level 1
User prompt
**Level 1**: Reach an altitude of 5000 meters. 2. **Level 2**: Reach an altitude of 10000 meters (5000 meters for Level 1 + 5000 meters for Level 2). 3. **Level 3**: Reach an altitude of 15000 meters (10000 meters for Level 2 + 5000 meters for Level 3). 4. **Level 4**: Reach an altitude of 20000 meters (15000 meters for Level 3 + 5000 meters for Level 4). 5. **Level 5**: Reach an altitude of 25000 meters (20000 meters for Level 4 + 5000 meters for Level 5). fix the altitude after level 1 that is resetting the altitude meter count and repair the game flow properly on each level
User prompt
spawn everything that player need to complete the game up to 25000 meters
User prompt
reset the oxygen bar to full when a level is completed
User prompt
reduce the oxygen reduction count at all levels
User prompt
reduce the oxygen reduction count
User prompt
fix the above problem for all the 5 levels of the entire game
User prompt
fix the above problem
User prompt
reduce the oxygen reduction count
User prompt
to pass a single level, the player must guide the climber to ascend 5000 meters so loop the game for every 5000 meters with oxygen spawn , obstacle spawn and path spawn
User prompt
make the game in the loop as the player goes on upwards on the screen
User prompt
at every 2000 meters assign the campsite as a save point if the player gets game over restart the game from that camp site
User prompt
make the game move vertically upwards
User prompt
make the player move upwards based on holding left mouse button dragging around
Code edit (1 edits merged)
Please save this source code
User prompt
fix the player logic which continously falling down and causing game over
Code edit (1 edits merged)
Please save this source code
User prompt
Peak Climber: Summit Challenge
User prompt
Please continue polishing my design document.
Initial prompt
make a mountain trekking game
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0, gearCollected: 0, gearUpgrades: { oxygenEfficiency: 0, climbingSpeed: 0, weatherResistance: 0 } }); /**** * Classes ****/ var Campsite = Container.expand(function () { var self = Container.call(this); var campsiteGraphics = self.attachAsset('campsite', { anchorX: 0.5, anchorY: 0.5 }); self.width = campsiteGraphics.width; self.height = campsiteGraphics.height; self.active = true; return self; }); var Climber = Container.expand(function () { var self = Container.call(this); var climberGraphics = self.attachAsset('climber', { anchorX: 2, anchorY: 2 }); self.width = climberGraphics.width; self.height = climberGraphics.height; self.vx = 0; self.vy = 0; self.speed = 14 + storage.gearUpgrades.climbingSpeed * 2; self.jumpPower = -25; self.gravity = 0; self.onGround = false; self.climbing = false; self.targetX = null; self.targetY = null; self.movingToTarget = false; self.lastX = 0; self.lastY = 0; self.update = function () { // Create smoke effect behind the player if (LK.ticks % 10 === 0) { // Emit smoke every 10 ticks var smoke = LK.getAsset('smoke', { anchorX: 1.5, anchorY: 2.2, x: self.x - self.width / 4, y: self.y + self.height / 2 }); game.addChild(smoke); tween(smoke, { alpha: 0 }, { duration: 1000, onFinish: function onFinish() { smoke.destroy(); } }); } self.lastX = self.x; self.lastY = self.y; if (self.movingToTarget && self.targetX !== null) { var dx = self.targetX - self.x; var dy = self.targetY - self.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance > self.speed) { var angle = Math.atan2(dy, dx); self.vx = Math.cos(angle) * self.speed; self.vy = Math.sin(angle) * self.speed; } else { self.x = self.targetX; self.y = self.targetY; self.vx = 0; // Stop horizontal movement self.vy = 0; // Stop vertical movement self.movingToTarget = false; self.targetX = null; self.targetY = null; } } // Remove gravity effect to ensure constant upward movement self.x += self.vx; self.y += self.vy; // Allow vertical movement based on velocity // Constrain to screen bounds if (self.x < self.width / 2) { self.x = self.width / 2; self.vx = 0; } else if (self.x > 2048 - self.width / 2) { self.x = 2048 - self.width / 2; self.vx = 0; } }; self.jump = function () { if (self.onGround) { self.vy = self.jumpPower; self.onGround = false; LK.getSound('jump').play(); // Add visual effect for jump LK.effects.flashObject(self, 0x00ff00, 300); } }; self.moveToPosition = function (x, y) { self.targetX = x; self.targetY = y; self.movingToTarget = true; self.climbing = true; }; return self; }); var ClimbingPath = Container.expand(function (pathType) { var self = Container.call(this); // Different path types: 'normal', 'narrow', 'slippery' self.pathType = pathType || 'normal'; var pathWidth = 300; var pathColor = 0xDDDDDD; if (self.pathType === 'narrow') { pathWidth = 150; pathColor = 0xBBBBBB; } else if (self.pathType === 'slippery') { pathWidth = 250; pathColor = 0xADD8E6; } var pathGraphics = self.attachAsset('path', { anchorX: 0.5, anchorY: 0.5, width: pathWidth, height: 100, tint: pathColor }); self.width = pathGraphics.width; self.height = pathGraphics.height; return self; }); var Collectable = Container.expand(function (collectableType) { var self = Container.call(this); self.collectableType = collectableType || 'oxygen'; var assetId, value; if (self.collectableType === 'oxygen') { assetId = 'oxygen'; value = 20 + Math.floor(Math.random() * 10); } else if (self.collectableType === 'gear') { assetId = 'gear'; value = 1; } var collectableGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.width = collectableGraphics.width; self.height = collectableGraphics.height; self.value = value; self.active = true; self.update = function () { // Simple hover animation collectableGraphics.y = Math.sin(LK.ticks / 20) * 5; }; return self; }); var Hazard = Container.expand(function (hazardType) { var self = Container.call(this); self.hazardType = hazardType || 'rock'; var assetId, size, speed; if (self.hazardType === 'rock') { assetId = 'rock'; size = 100; speed = 5 + Math.random() * 3; } else if (self.hazardType === 'snowball') { assetId = 'snowball'; size = 90; speed = 7 + Math.random() * 4; } var hazardGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.width = hazardGraphics.width; self.height = hazardGraphics.height; self.vy = speed; self.active = true; self.update = function () { if (self.hazardType !== 'gap') { self.y += self.vy; } // Remove when out of screen if (self.y > 2732 + self.height) { self.active = false; } }; return self; }); var HealthBar = Container.expand(function () { var self = Container.call(this); var barBackground = self.attachAsset('oxygenBarBg', { anchorX: 0, anchorY: 0.5 }); var bar = self.attachAsset('oxygenBar', { anchorX: 0, anchorY: 0.5, x: 5, y: 0 }); var healthText = new Text2('HEALTH', { size: 30, fill: 0xFFFFFF }); healthText.anchor.set(0.5, 0.5); healthText.x = 200; healthText.y = 0; self.addChild(healthText); self.maxWidth = bar.width; self.updateBar = function (percentage) { percentage = Math.max(0, Math.min(100, percentage)); bar.width = self.maxWidth * (percentage / 100); if (percentage > 60) { bar.tint = 0x00FF00; // Green } else if (percentage > 30) { bar.tint = 0xFFFF00; // Yellow } else { bar.tint = 0xFF0000; // Red } }; return self; }); var MainMenu = Container.expand(function () { var self = Container.call(this); var background = self.attachAsset('mainMenuBackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); // Create a title text var titleText = new Text2('JetPack Adventure', { size: 100, fill: 0xFFFFFF, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" // Custom font }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 800; self.addChild(titleText); // Create a start button var startButton = new Text2('Start Game', { size: 80, fill: 0x00FF00, font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" // Custom font }); startButton.anchor.set(0.5, 0.5); startButton.x = 2048 / 2; startButton.y = 1400; self.addChild(startButton); // Add interaction to start button startButton.interactive = true; startButton.buttonMode = true; startButton.down = function () { self.visible = false; setupGame(); }; return self; }); var Mountain = Container.expand(function () { var self = Container.call(this); var mountainGraphics = self.attachAsset('mountain', { anchorX: 0.5, anchorY: 0 }); self.width = mountainGraphics.width; self.height = mountainGraphics.height; return self; }); var OxygenBar = Container.expand(function () { var self = Container.call(this); var barBackground = self.attachAsset('oxygenBarBg', { anchorX: 0, anchorY: 0.5 }); var bar = self.attachAsset('oxygenBar', { anchorX: 0, anchorY: 0.5, x: 5, y: 0 }); var oxygenText = new Text2('OXYGEN', { size: 30, fill: 0xFFFFFF }); oxygenText.anchor.set(0.5, 0.5); oxygenText.x = 200; oxygenText.y = 0; self.addChild(oxygenText); self.maxWidth = bar.width; self.updateBar = function (percentage) { // Clamp percentage between 0 and 100 percentage = Math.max(0, Math.min(100, percentage)); bar.width = self.maxWidth * (percentage / 100); // Change color based on oxygen level if (percentage > 60) { bar.tint = 0x00BFFF; // Blue } else if (percentage > 30) { bar.tint = 0xFFAA00; // Orange } else { bar.tint = 0xFF0000; // Red } }; return self; }); var WindEffect = Container.expand(function () { var self = Container.call(this); var windGraphics = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 2048, y: Math.random() * 2732 / 2 }); self.vx = 1 + Math.random(); // Random horizontal speed self.update = function () { windGraphics.x += self.vx; if (windGraphics.x > 2048 + windGraphics.width) { windGraphics.x = -windGraphics.width; // Reset position to the left } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Always black }); /**** * Game Code ****/ function createBackgroundForLevel(level) { // Define different backgrounds for each level var backgroundAssetId; switch (level) { case 1: backgroundAssetId = 'backgroundLevel1'; break; case 2: backgroundAssetId = 'backgroundLevel2'; break; case 3: backgroundAssetId = 'backgroundLevel3'; break; case 4: backgroundAssetId = 'backgroundLevel4'; break; case 5: backgroundAssetId = 'backgroundLevel5'; break; } // Create and position the background var background1 = LK.getAsset(backgroundAssetId, { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); var background2 = LK.getAsset(backgroundAssetId, { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: -2732 / 2 }); game.addChild(background1); game.addChild(background2); background1.zIndex = -1; // Ensure background is behind other elements background2.zIndex = -1; background1.update = function () { background1.y += scrollSpeed; if (background1.y > 2732 + 2732 / 2) { background1.y = -2732 / 2; } }; background2.update = function () { background2.y += scrollSpeed; if (background2.y > 2732 + 2732 / 2) { background2.y = -2732 / 2; } }; } function adjustGameDynamics() { // Increase scroll speed with altitude scrollSpeed = 3 + Math.floor(altitude / 1000); // Adjust hazard spawn rate based on altitude if (altitude > 2000) { pathGap = 200; } else if (altitude > 4000) { pathGap = 180; } // Modify oxygen usage rate based on altitude if (altitude > 3000) { oxygenUseRate = 0.15 - storage.gearUpgrades.oxygenEfficiency * 0.01; } else if (altitude > 5000) { oxygenUseRate = 0.2 - storage.gearUpgrades.oxygenEfficiency * 0.01; } } // Game state var gameActive = false; var score = 0; var altitude = 0; var oxygen = 100; var maxOxygen = 100; var health = 100; var oxygenUseRate = 0.1 - storage.gearUpgrades.oxygenEfficiency * 0.01; var weatherEffect = 0; var weatherResistance = storage.gearUpgrades.weatherResistance; var level = 1; var levelHeight = 5000; // Screen scroll var scrollSpeed = 3; var camera = { y: 0 }; // Game elements var climber; var paths = []; var hazards = []; var collectables = []; var campsites = []; var mountains = []; var nextPathY = 2600; // Start position for first path var pathGap = 220; // Gap between consecutive paths // UI elements var scoreText; var altitudeText; var levelText; var oxygenBar; var healthBar; // Define healthBar in the global scope // Setup game function setupGame() { gameActive = true; // Start background music setupUI(); // Create and spawn background for each level when played createBackgroundForLevel(level); // Add dynamic clouds to the background function createClouds() { var cloud = LK.getAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 2048, y: Math.random() * 2732 / 2 }); game.addChild(cloud); cloud.vx = 0.5 + Math.random(); // Random horizontal speed cloud.update = function () { cloud.x += cloud.vx; if (cloud.x > 2048 + cloud.width) { cloud.x = -cloud.width; // Reset position to the left } }; return cloud; } // Create multiple clouds for (var i = 0; i < 5; i++) { var cloud = createClouds(); game.addChild(cloud); } // Add wind effects for (var i = 0; i < 3; i++) { var wind = new WindEffect(); game.addChild(wind); } // Create mountains createMountains(); // Continuously spawn mountains every 5 seconds function spawnMountain() { var newMountain = new Mountain(); newMountain.x = 2048 / 2; newMountain.y = camera.y - 500; // Position above the current view mountains.push(newMountain); game.addChild(newMountain); } LK.setInterval(spawnMountain, 5000); // Schedule the mountain spawn every 5 seconds spawnMountain(); // Start the mountain spawning process immediately // Create initial paths for (var i = 0; i < 15; i++) { createPathAt(nextPathY); nextPathY -= pathGap; } // Create climber climber = new Climber(); climber.x = 2048 / 2; climber.y = 2400; game.addChild(climber); // Ensure climber is initialized before calling update if (climber) { climber.update(); } // Start background music LK.playMusic('bgMusic', { fade: { start: 0, end: 0.3, duration: 1000 } }); } function setupUI() { // Score text scoreText = new Text2('SCORE: 0', { size: 50, fill: 0xFFFFFF }); scoreText.anchor.set(1, 0); LK.gui.topRight.addChild(scoreText); // Altitude text altitudeText = new Text2('ALTITUDE: 0 M', { size: 50, fill: 0xFFFFFF }); altitudeText.anchor.set(0.5, 0); LK.gui.top.addChild(altitudeText); // Level text levelText = new Text2('LEVEL: 1', { size: 50, fill: 0xFFFFFF }); levelText.anchor.set(0, 0); LK.gui.topLeft.addChild(levelText); levelText.x = 120; // Offset from the top left corner to avoid UI elements // Oxygen bar oxygenBar = new OxygenBar(); oxygenBar.x = 200; oxygenBar.y = 100; LK.gui.top.addChild(oxygenBar); // Health bar healthBar = new HealthBar(); healthBar.x = 200; healthBar.y = 150; LK.gui.top.addChild(healthBar); } function createMountains() { // Create two mountains for parallax effect var mountain1 = new Mountain(); mountain1.x = 2048 / 2; mountain1.y = 2200; mountains.push(mountain1); game.addChild(mountain1); var mountain2 = new Mountain(); mountain2.x = 2048 / 2; mountain2.y = 700; mountains.push(mountain2); game.addChild(mountain2); } function createPathAt(yPosition) { // Random path properties var pathX = Math.random() * (2048 - 400) + 200; var pathType = 'normal'; var pathTypeRoll = Math.random(); if (pathTypeRoll > 0.7) { pathType = 'narrow'; } else if (pathTypeRoll > 0.5) { pathType = 'slippery'; } // Create the path var path = new ClimbingPath(pathType); path.x = pathX; path.y = yPosition; paths.push(path); game.addChild(path); // Chance to add collectable if (Math.random() > 0.6) { var collectableType = Math.random() > 0.7 ? 'gear' : 'oxygen'; var collectable = new Collectable(collectableType); collectable.x = pathX + (Math.random() * 200 - 100); collectable.y = yPosition - 80; collectables.push(collectable); game.addChild(collectable); } // Lower chance to add campsite if (Math.random() > 0.9) { var campsite = new Campsite(); campsite.x = pathX; campsite.y = yPosition - 80; campsites.push(campsite); game.addChild(campsite); } // Chance to add hazard if (Math.random() > 0.7) { var hazardType; var hazardRoll = Math.random(); if (hazardRoll > 0.5) { hazardType = 'snowball'; } else if (hazardRoll > 0.3) { hazardType = 'rock'; } else { // Flying hazards are positioned above var hazard = new Hazard(hazardType); hazard.x = Math.random() * 2048; hazard.y = yPosition - 500 - Math.random() * 500; hazards.push(hazard); game.addChild(hazard); } } return path; } function updateGame() { if (!gameActive) { return; } // Update oxygen level updateOxygen(); // Adjust game dynamics based on altitude adjustGameDynamics(); // Update climber and check collisions updateClimber(); // Update paths and scroll updatePathsAndScroll(); // Update hazards updateHazards(); // Update collectables updateCollectables(); // Update campsites updateCampsites(); // Update UI updateUI(); // Update clouds for (var i = 0; i < game.children.length; i++) { var child = game.children[i]; if (child.update) { child.update(); } } // Check for game over conditions checkGameOver(); // Check for level complete checkLevelComplete(); } function updateOxygen() { // Consume oxygen oxygen -= oxygenUseRate * 0.5 * (1 + weatherEffect); // Reduce oxygen consumption rate // Apply weather effects if (altitude > level * 1000) { weatherEffect = Math.min(1, (altitude - level * 1000) / 1000); // Reduce weather effect based on weather resistance upgrade weatherEffect *= 1 - weatherResistance * 0.1; } // Update oxygen bar if (oxygenBar) { oxygenBar.updateBar(oxygen); } } function updateClimber() { // Update climber position if (climber) { climber.update(); } // Check if climber is on any path if (climber) { climber.onGround = false; } for (var i = 0; i < paths.length; i++) { var path = paths[i]; if (climber && path && climber.intersects(path) && climber.lastY + climber.height / 2 <= path.y - path.height / 2 + 20 && climber.vy >= 0) { climber.y = path.y - path.height / 2 - climber.height / 2 + 5; climber.vy = 0; climber.onGround = true; climber.climbing = false; // If on slippery path, add slide effect if (path.pathType === 'slippery' && !climber.movingToTarget) { climber.vx = Math.random() > 0.5 ? 1 : -1; } break; } } // Reduce health when player goes fast if (climber && Math.abs(climber.vx) > climber.speed * 0.8) { health -= 0.2; // Increase health reduction rate based on speed healthBar.updateBar(health); } // Reduce health slowly when player goes down if (climber && climber.vy > 0) { health -= 0.1; // Increase health reduction rate based on downward movement healthBar.updateBar(health); } } function updatePathsAndScroll() { // Scroll the screen when climber is higher if (climber && climber.y < 2732 / 3) { var scrollAmount = 2732 / 3 - climber.y; camera.y += scrollAmount; climber.y += scrollAmount; // Move all game elements for (var i = 0; i < paths.length; i++) { paths[i].y += scrollAmount; } for (var i = 0; i < hazards.length; i++) { hazards[i].y += scrollAmount; } for (var i = 0; i < collectables.length; i++) { collectables[i].y += scrollAmount; } for (var i = 0; i < campsites.length; i++) { campsites[i].y += scrollAmount; } for (var i = 0; i < mountains.length; i++) { mountains[i].y += scrollAmount * 0.5; // Parallax effect } // Increase altitude altitude += scrollAmount; // Create new paths as needed while (nextPathY > camera.y - 2732 / 2) { createPathAt(nextPathY); nextPathY -= pathGap + Math.random() * 50; } } else { // Always scroll the game elements upwards var scrollAmount = scrollSpeed; camera.y += scrollAmount; for (var i = 0; i < paths.length; i++) { paths[i].y += scrollAmount; } for (var i = 0; i < hazards.length; i++) { hazards[i].y += scrollAmount; } for (var i = 0; i < collectables.length; i++) { collectables[i].y += scrollAmount; } for (var i = 0; i < campsites.length; i++) { campsites[i].y += scrollAmount; } for (var i = 0; i < mountains.length; i++) { mountains[i].y += scrollAmount * 0.5; // Parallax effect } altitude += scrollAmount; while (nextPathY > camera.y - 2732 / 2 && altitude < 25000) { createPathAt(nextPathY); nextPathY -= pathGap + Math.random() * 50; } } // Remove paths that are off-screen for (var i = paths.length - 1; i >= 0; i--) { if (paths[i].y > camera.y + 2732 + 200) { paths[i].destroy(); paths.splice(i, 1); } } } function updateHazards() { for (var i = hazards.length - 1; i >= 0; i--) { var hazard = hazards[i]; hazard.update(); // Check for collision with climber if (hazard && hazard.active && climber && climber.intersects(hazard)) { handleHazardCollision(hazard); } // Remove inactive hazards if (!hazard.active || hazard.y > camera.y + 2732 + 200) { hazard.destroy(); hazards.splice(i, 1); } } } function handleHazardCollision(hazard) { LK.getSound('danger').play(); if (hazard.hazardType === 'rock' || hazard.hazardType === 'snowball') { // Visual feedback if (climber) { LK.effects.flashObject(climber, 0xff0000, 500); } // Add visual effect for hazard LK.effects.flashObject(hazard, 0xff0000, 500); // Knockback effect climber.vy = 5; climber.vx = climber.x < hazard.x ? -8 : 8; // Make hazard inactive hazard.active = false; } } function updateCollectables() { for (var i = collectables.length - 1; i >= 0; i--) { var collectable = collectables[i]; collectable.update(); // Check for collision with climber if (collectable && collectable.active && climber && climber.intersects(collectable)) { handleCollectableCollision(collectable); // Remove collected item collectable.destroy(); collectables.splice(i, 1); } else if (collectable.y > camera.y + 2732 + 200) { // Remove off-screen collectables collectable.destroy(); collectables.splice(i, 1); } } } function handleCollectableCollision(collectable) { LK.getSound('collect').play(); if (collectable.collectableType === 'oxygen') { // Refill oxygen oxygen = Math.min(maxOxygen, oxygen + collectable.value); // Visual feedback LK.effects.flashObject(collectable, 0x00BFFF, 300); } else if (collectable.collectableType === 'gear') { storage.gearCollected += collectable.value; // Apply gear upgrade effect storage.gearUpgrades.climbingSpeed += 0.1; // Increase climbing speed storage.gearUpgrades.oxygenEfficiency += 0.05; // Increase oxygen efficiency storage.gearUpgrades.weatherResistance += 0.02; // Increase weather resistance // Add to score score += 10; // Visual feedback LK.effects.flashObject(collectable, 0xFFD700, 300); // Add visual effect for climber if (climber) { LK.effects.flashObject(climber, 0xFFD700, 300); } } } function updateCampsites() { for (var i = campsites.length - 1; i >= 0; i--) { var campsite = campsites[i]; // Check for collision with climber if (campsite && campsite.active && climber && climber.intersects(campsite)) { handleCampsiteCollision(campsite); } // Remove off-screen campsites if (campsite.y > camera.y + 2732 + 200) { campsite.destroy(); campsites.splice(i, 1); } } } function handleCampsiteCollision(campsite) { // Rest at campsite to replenish oxygen if (climber.onGround && campsite.active) { LK.getSound('rest').play(); // Replenish oxygen oxygen = Math.min(maxOxygen, oxygen + 0.5); // Visual feedback if (LK.ticks % 20 === 0) { LK.effects.flashObject(campsite, 0x4CBB17, 300); // Add visual effect for resting LK.effects.flashObject(climber, 0x4CBB17, 300); } // Increase score for time spent at campsite if (LK.ticks % 60 === 0) { score += 1; } // Save game state when resting at the end level campsite if (campsite.y < 100) { // Assuming y < 100 indicates it's the end level campsite storage.highScore = Math.max(storage.highScore, Math.floor(score)); storage.gearCollected = storage.gearCollected; storage.gearUpgrades = storage.gearUpgrades; } } } function updateUI() { // Update score text if (scoreText) { scoreText.setText('SCORE: ' + Math.floor(score)); } // Update altitude text if (altitudeText) { altitudeText.setText('ALTITUDE: ' + Math.floor(altitude) + ' M'); } // Update level text if (levelText) { levelText.setText('LEVEL: ' + level); } } function checkGameOver() { // Game over if oxygen depletes if (oxygen <= 0) { gameActive = false; oxygen = Math.max(0, oxygen); LK.effects.flashScreen(0xff0000, 1000); LK.setTimeout(function () { LK.showGameOver(); }, 1000); } // Game over if fallen off screen if (climber && climber.y > camera.y + 2732 + climber.height) { gameActive = false; LK.effects.flashScreen(0xff0000, 1000); LK.setTimeout(function () { LK.showGameOver(); }, 1000); } } function checkLevelComplete() { // Advance to next level when reaching required height if (altitude >= level * levelHeight) { level++; // Increase difficulty pathGap += 20; oxygenUseRate += 0.05; // Bonus score score += level * 100; // Flash screen for feedback LK.effects.flashScreen(0x00ff00, 500); // Add visual effect for climber if (climber) { LK.effects.flashObject(climber, 0x00ff00, 500); } // Reset altitude for next level altitude = 0; // Reset paths, hazards, and collectables for new level paths = []; hazards = []; collectables = []; campsites = []; nextPathY = 2600; // Reset start position for first path // Spawn a campsite at the end of the level var endCampsite = new Campsite(); endCampsite.x = 2048 / 2; endCampsite.y = nextPathY - 100; // Position slightly above the last path campsites.push(endCampsite); game.addChild(endCampsite); // Create initial paths for new level for (var i = 0; i < 15; i++) { createPathAt(nextPathY); nextPathY -= pathGap; } // If reached final level (5), show win screen if (level > 5) { LK.setTimeout(function () { // Update high score if (score > storage.highScore) { storage.highScore = Math.floor(score); } LK.showYouWin(); }, 1000); } } } // Interaction handlers game.down = function (x, y, obj) { if (!gameActive) { return; } // Convert click to game coordinates var position = game.toLocal({ x: x, y: y }); // When clicking/tapping, move towards that point if within reasonable range if (climber) { var dx = position.x - climber.x; var dy = position.y - climber.y; var distance = Math.sqrt(dx * dx + dy * dy); // Ensure climber is initialized before calling moveToPosition if (climber && typeof climber.moveToPosition === 'function') { climber.moveToPosition(position.x, position.y); } if (climber && typeof climber.speed !== 'undefined') { climber.vx = dx > 0 ? climber.speed : -climber.speed; // Set horizontal speed based on touch position climber.vy = -scrollSpeed; // Set vertical speed to move upwards } else { console.error("Climber is not initialized or speed is undefined."); return; // Exit the function if climber is not properly initialized } } if (climber) { var dy = position.y - climber.y; } var distance = Math.sqrt(dx * dx + dy * dy); // Move towards the target position if (climber && typeof climber.moveToPosition === 'function') { climber.moveToPosition(position.x, position.y); } climber.vx = dx > 0 ? climber.speed : -climber.speed; // Set horizontal speed based on touch position climber.vy = -scrollSpeed; // Set vertical speed to move upwards }; game.up = function (x, y, obj) { // Not needed for this game }; game.move = function (x, y, obj) { // Not needed for this game }; // Main game loop game.update = function () { if (gameActive) { updateGame(); } // Update score based on altitude if (gameActive && LK.ticks % 30 === 0) { score += 0.1 * level; } }; // Initialize and display the main menu var mainMenu = new MainMenu(); game.addChild(mainMenu); // Set game score LK.setScore(Math.floor(score));
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0,
gearCollected: 0,
gearUpgrades: {
oxygenEfficiency: 0,
climbingSpeed: 0,
weatherResistance: 0
}
});
/****
* Classes
****/
var Campsite = Container.expand(function () {
var self = Container.call(this);
var campsiteGraphics = self.attachAsset('campsite', {
anchorX: 0.5,
anchorY: 0.5
});
self.width = campsiteGraphics.width;
self.height = campsiteGraphics.height;
self.active = true;
return self;
});
var Climber = Container.expand(function () {
var self = Container.call(this);
var climberGraphics = self.attachAsset('climber', {
anchorX: 2,
anchorY: 2
});
self.width = climberGraphics.width;
self.height = climberGraphics.height;
self.vx = 0;
self.vy = 0;
self.speed = 14 + storage.gearUpgrades.climbingSpeed * 2;
self.jumpPower = -25;
self.gravity = 0;
self.onGround = false;
self.climbing = false;
self.targetX = null;
self.targetY = null;
self.movingToTarget = false;
self.lastX = 0;
self.lastY = 0;
self.update = function () {
// Create smoke effect behind the player
if (LK.ticks % 10 === 0) {
// Emit smoke every 10 ticks
var smoke = LK.getAsset('smoke', {
anchorX: 1.5,
anchorY: 2.2,
x: self.x - self.width / 4,
y: self.y + self.height / 2
});
game.addChild(smoke);
tween(smoke, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
smoke.destroy();
}
});
}
self.lastX = self.x;
self.lastY = self.y;
if (self.movingToTarget && self.targetX !== null) {
var dx = self.targetX - self.x;
var dy = self.targetY - self.y;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance > self.speed) {
var angle = Math.atan2(dy, dx);
self.vx = Math.cos(angle) * self.speed;
self.vy = Math.sin(angle) * self.speed;
} else {
self.x = self.targetX;
self.y = self.targetY;
self.vx = 0; // Stop horizontal movement
self.vy = 0; // Stop vertical movement
self.movingToTarget = false;
self.targetX = null;
self.targetY = null;
}
}
// Remove gravity effect to ensure constant upward movement
self.x += self.vx;
self.y += self.vy; // Allow vertical movement based on velocity
// Constrain to screen bounds
if (self.x < self.width / 2) {
self.x = self.width / 2;
self.vx = 0;
} else if (self.x > 2048 - self.width / 2) {
self.x = 2048 - self.width / 2;
self.vx = 0;
}
};
self.jump = function () {
if (self.onGround) {
self.vy = self.jumpPower;
self.onGround = false;
LK.getSound('jump').play();
// Add visual effect for jump
LK.effects.flashObject(self, 0x00ff00, 300);
}
};
self.moveToPosition = function (x, y) {
self.targetX = x;
self.targetY = y;
self.movingToTarget = true;
self.climbing = true;
};
return self;
});
var ClimbingPath = Container.expand(function (pathType) {
var self = Container.call(this);
// Different path types: 'normal', 'narrow', 'slippery'
self.pathType = pathType || 'normal';
var pathWidth = 300;
var pathColor = 0xDDDDDD;
if (self.pathType === 'narrow') {
pathWidth = 150;
pathColor = 0xBBBBBB;
} else if (self.pathType === 'slippery') {
pathWidth = 250;
pathColor = 0xADD8E6;
}
var pathGraphics = self.attachAsset('path', {
anchorX: 0.5,
anchorY: 0.5,
width: pathWidth,
height: 100,
tint: pathColor
});
self.width = pathGraphics.width;
self.height = pathGraphics.height;
return self;
});
var Collectable = Container.expand(function (collectableType) {
var self = Container.call(this);
self.collectableType = collectableType || 'oxygen';
var assetId, value;
if (self.collectableType === 'oxygen') {
assetId = 'oxygen';
value = 20 + Math.floor(Math.random() * 10);
} else if (self.collectableType === 'gear') {
assetId = 'gear';
value = 1;
}
var collectableGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.width = collectableGraphics.width;
self.height = collectableGraphics.height;
self.value = value;
self.active = true;
self.update = function () {
// Simple hover animation
collectableGraphics.y = Math.sin(LK.ticks / 20) * 5;
};
return self;
});
var Hazard = Container.expand(function (hazardType) {
var self = Container.call(this);
self.hazardType = hazardType || 'rock';
var assetId, size, speed;
if (self.hazardType === 'rock') {
assetId = 'rock';
size = 100;
speed = 5 + Math.random() * 3;
} else if (self.hazardType === 'snowball') {
assetId = 'snowball';
size = 90;
speed = 7 + Math.random() * 4;
}
var hazardGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.width = hazardGraphics.width;
self.height = hazardGraphics.height;
self.vy = speed;
self.active = true;
self.update = function () {
if (self.hazardType !== 'gap') {
self.y += self.vy;
}
// Remove when out of screen
if (self.y > 2732 + self.height) {
self.active = false;
}
};
return self;
});
var HealthBar = Container.expand(function () {
var self = Container.call(this);
var barBackground = self.attachAsset('oxygenBarBg', {
anchorX: 0,
anchorY: 0.5
});
var bar = self.attachAsset('oxygenBar', {
anchorX: 0,
anchorY: 0.5,
x: 5,
y: 0
});
var healthText = new Text2('HEALTH', {
size: 30,
fill: 0xFFFFFF
});
healthText.anchor.set(0.5, 0.5);
healthText.x = 200;
healthText.y = 0;
self.addChild(healthText);
self.maxWidth = bar.width;
self.updateBar = function (percentage) {
percentage = Math.max(0, Math.min(100, percentage));
bar.width = self.maxWidth * (percentage / 100);
if (percentage > 60) {
bar.tint = 0x00FF00; // Green
} else if (percentage > 30) {
bar.tint = 0xFFFF00; // Yellow
} else {
bar.tint = 0xFF0000; // Red
}
};
return self;
});
var MainMenu = Container.expand(function () {
var self = Container.call(this);
var background = self.attachAsset('mainMenuBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Create a title text
var titleText = new Text2('JetPack Adventure', {
size: 100,
fill: 0xFFFFFF,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" // Custom font
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 800;
self.addChild(titleText);
// Create a start button
var startButton = new Text2('Start Game', {
size: 80,
fill: 0x00FF00,
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma" // Custom font
});
startButton.anchor.set(0.5, 0.5);
startButton.x = 2048 / 2;
startButton.y = 1400;
self.addChild(startButton);
// Add interaction to start button
startButton.interactive = true;
startButton.buttonMode = true;
startButton.down = function () {
self.visible = false;
setupGame();
};
return self;
});
var Mountain = Container.expand(function () {
var self = Container.call(this);
var mountainGraphics = self.attachAsset('mountain', {
anchorX: 0.5,
anchorY: 0
});
self.width = mountainGraphics.width;
self.height = mountainGraphics.height;
return self;
});
var OxygenBar = Container.expand(function () {
var self = Container.call(this);
var barBackground = self.attachAsset('oxygenBarBg', {
anchorX: 0,
anchorY: 0.5
});
var bar = self.attachAsset('oxygenBar', {
anchorX: 0,
anchorY: 0.5,
x: 5,
y: 0
});
var oxygenText = new Text2('OXYGEN', {
size: 30,
fill: 0xFFFFFF
});
oxygenText.anchor.set(0.5, 0.5);
oxygenText.x = 200;
oxygenText.y = 0;
self.addChild(oxygenText);
self.maxWidth = bar.width;
self.updateBar = function (percentage) {
// Clamp percentage between 0 and 100
percentage = Math.max(0, Math.min(100, percentage));
bar.width = self.maxWidth * (percentage / 100);
// Change color based on oxygen level
if (percentage > 60) {
bar.tint = 0x00BFFF; // Blue
} else if (percentage > 30) {
bar.tint = 0xFFAA00; // Orange
} else {
bar.tint = 0xFF0000; // Red
}
};
return self;
});
var WindEffect = Container.expand(function () {
var self = Container.call(this);
var windGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732 / 2
});
self.vx = 1 + Math.random(); // Random horizontal speed
self.update = function () {
windGraphics.x += self.vx;
if (windGraphics.x > 2048 + windGraphics.width) {
windGraphics.x = -windGraphics.width; // Reset position to the left
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Always black
});
/****
* Game Code
****/
function createBackgroundForLevel(level) {
// Define different backgrounds for each level
var backgroundAssetId;
switch (level) {
case 1:
backgroundAssetId = 'backgroundLevel1';
break;
case 2:
backgroundAssetId = 'backgroundLevel2';
break;
case 3:
backgroundAssetId = 'backgroundLevel3';
break;
case 4:
backgroundAssetId = 'backgroundLevel4';
break;
case 5:
backgroundAssetId = 'backgroundLevel5';
break;
}
// Create and position the background
var background1 = LK.getAsset(backgroundAssetId, {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
var background2 = LK.getAsset(backgroundAssetId, {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: -2732 / 2
});
game.addChild(background1);
game.addChild(background2);
background1.zIndex = -1; // Ensure background is behind other elements
background2.zIndex = -1;
background1.update = function () {
background1.y += scrollSpeed;
if (background1.y > 2732 + 2732 / 2) {
background1.y = -2732 / 2;
}
};
background2.update = function () {
background2.y += scrollSpeed;
if (background2.y > 2732 + 2732 / 2) {
background2.y = -2732 / 2;
}
};
}
function adjustGameDynamics() {
// Increase scroll speed with altitude
scrollSpeed = 3 + Math.floor(altitude / 1000);
// Adjust hazard spawn rate based on altitude
if (altitude > 2000) {
pathGap = 200;
} else if (altitude > 4000) {
pathGap = 180;
}
// Modify oxygen usage rate based on altitude
if (altitude > 3000) {
oxygenUseRate = 0.15 - storage.gearUpgrades.oxygenEfficiency * 0.01;
} else if (altitude > 5000) {
oxygenUseRate = 0.2 - storage.gearUpgrades.oxygenEfficiency * 0.01;
}
}
// Game state
var gameActive = false;
var score = 0;
var altitude = 0;
var oxygen = 100;
var maxOxygen = 100;
var health = 100;
var oxygenUseRate = 0.1 - storage.gearUpgrades.oxygenEfficiency * 0.01;
var weatherEffect = 0;
var weatherResistance = storage.gearUpgrades.weatherResistance;
var level = 1;
var levelHeight = 5000;
// Screen scroll
var scrollSpeed = 3;
var camera = {
y: 0
};
// Game elements
var climber;
var paths = [];
var hazards = [];
var collectables = [];
var campsites = [];
var mountains = [];
var nextPathY = 2600; // Start position for first path
var pathGap = 220; // Gap between consecutive paths
// UI elements
var scoreText;
var altitudeText;
var levelText;
var oxygenBar;
var healthBar; // Define healthBar in the global scope
// Setup game
function setupGame() {
gameActive = true;
// Start background music
setupUI();
// Create and spawn background for each level when played
createBackgroundForLevel(level);
// Add dynamic clouds to the background
function createClouds() {
var cloud = LK.getAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732 / 2
});
game.addChild(cloud);
cloud.vx = 0.5 + Math.random(); // Random horizontal speed
cloud.update = function () {
cloud.x += cloud.vx;
if (cloud.x > 2048 + cloud.width) {
cloud.x = -cloud.width; // Reset position to the left
}
};
return cloud;
}
// Create multiple clouds
for (var i = 0; i < 5; i++) {
var cloud = createClouds();
game.addChild(cloud);
}
// Add wind effects
for (var i = 0; i < 3; i++) {
var wind = new WindEffect();
game.addChild(wind);
}
// Create mountains
createMountains();
// Continuously spawn mountains every 5 seconds
function spawnMountain() {
var newMountain = new Mountain();
newMountain.x = 2048 / 2;
newMountain.y = camera.y - 500; // Position above the current view
mountains.push(newMountain);
game.addChild(newMountain);
}
LK.setInterval(spawnMountain, 5000); // Schedule the mountain spawn every 5 seconds
spawnMountain(); // Start the mountain spawning process immediately
// Create initial paths
for (var i = 0; i < 15; i++) {
createPathAt(nextPathY);
nextPathY -= pathGap;
}
// Create climber
climber = new Climber();
climber.x = 2048 / 2;
climber.y = 2400;
game.addChild(climber);
// Ensure climber is initialized before calling update
if (climber) {
climber.update();
}
// Start background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});
}
function setupUI() {
// Score text
scoreText = new Text2('SCORE: 0', {
size: 50,
fill: 0xFFFFFF
});
scoreText.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreText);
// Altitude text
altitudeText = new Text2('ALTITUDE: 0 M', {
size: 50,
fill: 0xFFFFFF
});
altitudeText.anchor.set(0.5, 0);
LK.gui.top.addChild(altitudeText);
// Level text
levelText = new Text2('LEVEL: 1', {
size: 50,
fill: 0xFFFFFF
});
levelText.anchor.set(0, 0);
LK.gui.topLeft.addChild(levelText);
levelText.x = 120; // Offset from the top left corner to avoid UI elements
// Oxygen bar
oxygenBar = new OxygenBar();
oxygenBar.x = 200;
oxygenBar.y = 100;
LK.gui.top.addChild(oxygenBar);
// Health bar
healthBar = new HealthBar();
healthBar.x = 200;
healthBar.y = 150;
LK.gui.top.addChild(healthBar);
}
function createMountains() {
// Create two mountains for parallax effect
var mountain1 = new Mountain();
mountain1.x = 2048 / 2;
mountain1.y = 2200;
mountains.push(mountain1);
game.addChild(mountain1);
var mountain2 = new Mountain();
mountain2.x = 2048 / 2;
mountain2.y = 700;
mountains.push(mountain2);
game.addChild(mountain2);
}
function createPathAt(yPosition) {
// Random path properties
var pathX = Math.random() * (2048 - 400) + 200;
var pathType = 'normal';
var pathTypeRoll = Math.random();
if (pathTypeRoll > 0.7) {
pathType = 'narrow';
} else if (pathTypeRoll > 0.5) {
pathType = 'slippery';
}
// Create the path
var path = new ClimbingPath(pathType);
path.x = pathX;
path.y = yPosition;
paths.push(path);
game.addChild(path);
// Chance to add collectable
if (Math.random() > 0.6) {
var collectableType = Math.random() > 0.7 ? 'gear' : 'oxygen';
var collectable = new Collectable(collectableType);
collectable.x = pathX + (Math.random() * 200 - 100);
collectable.y = yPosition - 80;
collectables.push(collectable);
game.addChild(collectable);
}
// Lower chance to add campsite
if (Math.random() > 0.9) {
var campsite = new Campsite();
campsite.x = pathX;
campsite.y = yPosition - 80;
campsites.push(campsite);
game.addChild(campsite);
}
// Chance to add hazard
if (Math.random() > 0.7) {
var hazardType;
var hazardRoll = Math.random();
if (hazardRoll > 0.5) {
hazardType = 'snowball';
} else if (hazardRoll > 0.3) {
hazardType = 'rock';
} else {
// Flying hazards are positioned above
var hazard = new Hazard(hazardType);
hazard.x = Math.random() * 2048;
hazard.y = yPosition - 500 - Math.random() * 500;
hazards.push(hazard);
game.addChild(hazard);
}
}
return path;
}
function updateGame() {
if (!gameActive) {
return;
}
// Update oxygen level
updateOxygen();
// Adjust game dynamics based on altitude
adjustGameDynamics();
// Update climber and check collisions
updateClimber();
// Update paths and scroll
updatePathsAndScroll();
// Update hazards
updateHazards();
// Update collectables
updateCollectables();
// Update campsites
updateCampsites();
// Update UI
updateUI();
// Update clouds
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child.update) {
child.update();
}
}
// Check for game over conditions
checkGameOver();
// Check for level complete
checkLevelComplete();
}
function updateOxygen() {
// Consume oxygen
oxygen -= oxygenUseRate * 0.5 * (1 + weatherEffect); // Reduce oxygen consumption rate
// Apply weather effects
if (altitude > level * 1000) {
weatherEffect = Math.min(1, (altitude - level * 1000) / 1000);
// Reduce weather effect based on weather resistance upgrade
weatherEffect *= 1 - weatherResistance * 0.1;
}
// Update oxygen bar
if (oxygenBar) {
oxygenBar.updateBar(oxygen);
}
}
function updateClimber() {
// Update climber position
if (climber) {
climber.update();
}
// Check if climber is on any path
if (climber) {
climber.onGround = false;
}
for (var i = 0; i < paths.length; i++) {
var path = paths[i];
if (climber && path && climber.intersects(path) && climber.lastY + climber.height / 2 <= path.y - path.height / 2 + 20 && climber.vy >= 0) {
climber.y = path.y - path.height / 2 - climber.height / 2 + 5;
climber.vy = 0;
climber.onGround = true;
climber.climbing = false;
// If on slippery path, add slide effect
if (path.pathType === 'slippery' && !climber.movingToTarget) {
climber.vx = Math.random() > 0.5 ? 1 : -1;
}
break;
}
}
// Reduce health when player goes fast
if (climber && Math.abs(climber.vx) > climber.speed * 0.8) {
health -= 0.2; // Increase health reduction rate based on speed
healthBar.updateBar(health);
}
// Reduce health slowly when player goes down
if (climber && climber.vy > 0) {
health -= 0.1; // Increase health reduction rate based on downward movement
healthBar.updateBar(health);
}
}
function updatePathsAndScroll() {
// Scroll the screen when climber is higher
if (climber && climber.y < 2732 / 3) {
var scrollAmount = 2732 / 3 - climber.y;
camera.y += scrollAmount;
climber.y += scrollAmount;
// Move all game elements
for (var i = 0; i < paths.length; i++) {
paths[i].y += scrollAmount;
}
for (var i = 0; i < hazards.length; i++) {
hazards[i].y += scrollAmount;
}
for (var i = 0; i < collectables.length; i++) {
collectables[i].y += scrollAmount;
}
for (var i = 0; i < campsites.length; i++) {
campsites[i].y += scrollAmount;
}
for (var i = 0; i < mountains.length; i++) {
mountains[i].y += scrollAmount * 0.5; // Parallax effect
}
// Increase altitude
altitude += scrollAmount;
// Create new paths as needed
while (nextPathY > camera.y - 2732 / 2) {
createPathAt(nextPathY);
nextPathY -= pathGap + Math.random() * 50;
}
} else {
// Always scroll the game elements upwards
var scrollAmount = scrollSpeed;
camera.y += scrollAmount;
for (var i = 0; i < paths.length; i++) {
paths[i].y += scrollAmount;
}
for (var i = 0; i < hazards.length; i++) {
hazards[i].y += scrollAmount;
}
for (var i = 0; i < collectables.length; i++) {
collectables[i].y += scrollAmount;
}
for (var i = 0; i < campsites.length; i++) {
campsites[i].y += scrollAmount;
}
for (var i = 0; i < mountains.length; i++) {
mountains[i].y += scrollAmount * 0.5; // Parallax effect
}
altitude += scrollAmount;
while (nextPathY > camera.y - 2732 / 2 && altitude < 25000) {
createPathAt(nextPathY);
nextPathY -= pathGap + Math.random() * 50;
}
}
// Remove paths that are off-screen
for (var i = paths.length - 1; i >= 0; i--) {
if (paths[i].y > camera.y + 2732 + 200) {
paths[i].destroy();
paths.splice(i, 1);
}
}
}
function updateHazards() {
for (var i = hazards.length - 1; i >= 0; i--) {
var hazard = hazards[i];
hazard.update();
// Check for collision with climber
if (hazard && hazard.active && climber && climber.intersects(hazard)) {
handleHazardCollision(hazard);
}
// Remove inactive hazards
if (!hazard.active || hazard.y > camera.y + 2732 + 200) {
hazard.destroy();
hazards.splice(i, 1);
}
}
}
function handleHazardCollision(hazard) {
LK.getSound('danger').play();
if (hazard.hazardType === 'rock' || hazard.hazardType === 'snowball') {
// Visual feedback
if (climber) {
LK.effects.flashObject(climber, 0xff0000, 500);
}
// Add visual effect for hazard
LK.effects.flashObject(hazard, 0xff0000, 500);
// Knockback effect
climber.vy = 5;
climber.vx = climber.x < hazard.x ? -8 : 8;
// Make hazard inactive
hazard.active = false;
}
}
function updateCollectables() {
for (var i = collectables.length - 1; i >= 0; i--) {
var collectable = collectables[i];
collectable.update();
// Check for collision with climber
if (collectable && collectable.active && climber && climber.intersects(collectable)) {
handleCollectableCollision(collectable);
// Remove collected item
collectable.destroy();
collectables.splice(i, 1);
} else if (collectable.y > camera.y + 2732 + 200) {
// Remove off-screen collectables
collectable.destroy();
collectables.splice(i, 1);
}
}
}
function handleCollectableCollision(collectable) {
LK.getSound('collect').play();
if (collectable.collectableType === 'oxygen') {
// Refill oxygen
oxygen = Math.min(maxOxygen, oxygen + collectable.value);
// Visual feedback
LK.effects.flashObject(collectable, 0x00BFFF, 300);
} else if (collectable.collectableType === 'gear') {
storage.gearCollected += collectable.value;
// Apply gear upgrade effect
storage.gearUpgrades.climbingSpeed += 0.1; // Increase climbing speed
storage.gearUpgrades.oxygenEfficiency += 0.05; // Increase oxygen efficiency
storage.gearUpgrades.weatherResistance += 0.02; // Increase weather resistance
// Add to score
score += 10;
// Visual feedback
LK.effects.flashObject(collectable, 0xFFD700, 300);
// Add visual effect for climber
if (climber) {
LK.effects.flashObject(climber, 0xFFD700, 300);
}
}
}
function updateCampsites() {
for (var i = campsites.length - 1; i >= 0; i--) {
var campsite = campsites[i];
// Check for collision with climber
if (campsite && campsite.active && climber && climber.intersects(campsite)) {
handleCampsiteCollision(campsite);
}
// Remove off-screen campsites
if (campsite.y > camera.y + 2732 + 200) {
campsite.destroy();
campsites.splice(i, 1);
}
}
}
function handleCampsiteCollision(campsite) {
// Rest at campsite to replenish oxygen
if (climber.onGround && campsite.active) {
LK.getSound('rest').play();
// Replenish oxygen
oxygen = Math.min(maxOxygen, oxygen + 0.5);
// Visual feedback
if (LK.ticks % 20 === 0) {
LK.effects.flashObject(campsite, 0x4CBB17, 300);
// Add visual effect for resting
LK.effects.flashObject(climber, 0x4CBB17, 300);
}
// Increase score for time spent at campsite
if (LK.ticks % 60 === 0) {
score += 1;
}
// Save game state when resting at the end level campsite
if (campsite.y < 100) {
// Assuming y < 100 indicates it's the end level campsite
storage.highScore = Math.max(storage.highScore, Math.floor(score));
storage.gearCollected = storage.gearCollected;
storage.gearUpgrades = storage.gearUpgrades;
}
}
}
function updateUI() {
// Update score text
if (scoreText) {
scoreText.setText('SCORE: ' + Math.floor(score));
}
// Update altitude text
if (altitudeText) {
altitudeText.setText('ALTITUDE: ' + Math.floor(altitude) + ' M');
}
// Update level text
if (levelText) {
levelText.setText('LEVEL: ' + level);
}
}
function checkGameOver() {
// Game over if oxygen depletes
if (oxygen <= 0) {
gameActive = false;
oxygen = Math.max(0, oxygen);
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Game over if fallen off screen
if (climber && climber.y > camera.y + 2732 + climber.height) {
gameActive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
}
function checkLevelComplete() {
// Advance to next level when reaching required height
if (altitude >= level * levelHeight) {
level++;
// Increase difficulty
pathGap += 20;
oxygenUseRate += 0.05;
// Bonus score
score += level * 100;
// Flash screen for feedback
LK.effects.flashScreen(0x00ff00, 500);
// Add visual effect for climber
if (climber) {
LK.effects.flashObject(climber, 0x00ff00, 500);
}
// Reset altitude for next level
altitude = 0;
// Reset paths, hazards, and collectables for new level
paths = [];
hazards = [];
collectables = [];
campsites = [];
nextPathY = 2600; // Reset start position for first path
// Spawn a campsite at the end of the level
var endCampsite = new Campsite();
endCampsite.x = 2048 / 2;
endCampsite.y = nextPathY - 100; // Position slightly above the last path
campsites.push(endCampsite);
game.addChild(endCampsite);
// Create initial paths for new level
for (var i = 0; i < 15; i++) {
createPathAt(nextPathY);
nextPathY -= pathGap;
}
// If reached final level (5), show win screen
if (level > 5) {
LK.setTimeout(function () {
// Update high score
if (score > storage.highScore) {
storage.highScore = Math.floor(score);
}
LK.showYouWin();
}, 1000);
}
}
}
// Interaction handlers
game.down = function (x, y, obj) {
if (!gameActive) {
return;
}
// Convert click to game coordinates
var position = game.toLocal({
x: x,
y: y
});
// When clicking/tapping, move towards that point if within reasonable range
if (climber) {
var dx = position.x - climber.x;
var dy = position.y - climber.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// Ensure climber is initialized before calling moveToPosition
if (climber && typeof climber.moveToPosition === 'function') {
climber.moveToPosition(position.x, position.y);
}
if (climber && typeof climber.speed !== 'undefined') {
climber.vx = dx > 0 ? climber.speed : -climber.speed; // Set horizontal speed based on touch position
climber.vy = -scrollSpeed; // Set vertical speed to move upwards
} else {
console.error("Climber is not initialized or speed is undefined.");
return; // Exit the function if climber is not properly initialized
}
}
if (climber) {
var dy = position.y - climber.y;
}
var distance = Math.sqrt(dx * dx + dy * dy);
// Move towards the target position
if (climber && typeof climber.moveToPosition === 'function') {
climber.moveToPosition(position.x, position.y);
}
climber.vx = dx > 0 ? climber.speed : -climber.speed; // Set horizontal speed based on touch position
climber.vy = -scrollSpeed; // Set vertical speed to move upwards
};
game.up = function (x, y, obj) {
// Not needed for this game
};
game.move = function (x, y, obj) {
// Not needed for this game
};
// Main game loop
game.update = function () {
if (gameActive) {
updateGame();
}
// Update score based on altitude
if (gameActive && LK.ticks % 30 === 0) {
score += 0.1 * level;
}
};
// Initialize and display the main menu
var mainMenu = new MainMenu();
game.addChild(mainMenu);
// Set game score
LK.setScore(Math.floor(score));
mountain ledge Single Game Texture. In-Game asset. High contrast. No shadows
mountain boulder. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
bunch clouds. Single Game Texture. In-Game asset. Blank background. High contrast.
diffrent kinds of mountains. Single Game Texture. In-Game asset. High contrast
sand mountain. Single Game Texture. In-Game asset. Blank background. High contrast
snowy mountains. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
asgard. Single Game Texture. In-Game asset. Blank background. High contrast
oxygen cylinder with O2 symbol Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
single cloud. Single Game Texture. In-Game asset. Blank background. High contrast
snow ball. Single Game Texture. In-Game asset. 2d. Blank background. High contrast
camptent Single Game Texture. In-Game asset. 2d. Blank background. High contrast.
single climbing gear. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
mixed infinite cloud background Single Game Texture. In-Game asset. 2d. Blank background. High contrast
Fly Through Endless JetPack Adventure,Soaring Through the Sky Single Game Texture. In-Game asset. 2d. . High contrast.