User prompt
start should go up and down all the height of the screen
User prompt
when mario is invincibel because of start, add a tween to make it flash fast, and anything that will look cool ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
mvoe upgrades lowe and make it yellow. Alsoanimate the OG Mario title a little bit ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
remove sub title from OG mario
User prompt
use background3 for main menu backgorund
User prompt
Rename Mario Game to OG Mario
User prompt
use background 1 for main menu background image
User prompt
Improve homepgae elements diatributio
User prompt
Star should also move forward and have a way bigger oscilation ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Coins should not increase and dcrease size either
User prompt
Coins should not move up and down
User prompt
Combo message should appear smaller and in the position qhere enemy was killed
User prompt
wen start effect is up, make player blink fast
User prompt
combo message is repetaed, should only appear once
User prompt
add effect of pick up coins like pick up star ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
starts can not spawn again when star powerup is active
User prompt
when in start mode feels like player kills the enemies many times, it should only kill them once. also they should add up for combo points. also make sure comobo points are added to the score
User prompt
add tween to start make its movememnt wider, and also a little increase and decrease its size
User prompt
when star effect is on, make sure also enemies and everything is increase in speed, not only player and backgroud
User prompt
when star is picked up play starman2 and pause music bg, when effect is over go back to normal theme.
User prompt
star oscilation shouldbe smoother and wider ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
star should not rotate on its axis, instead it should have a wider up and down oscilation
User prompt
use star assset for star powerup
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'speedText.style.fill = 0xFCE29F; // Return to normal color' Line Number: 1090
User prompt
Randomly spawn a start. If player pick up start he will become invincible and kill enemies just by touching them. this will last 10 seconds. Also speed will be duplicated during those 10 seconds
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { coins: 0 }); /**** * Classes ****/ var Background = Container.expand(function () { var self = Container.call(this); var backgrounds = ['background1', 'background2', 'background3']; var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)]; var backgroundGraphics = self.attachAsset(randomBackground, { anchorX: 0, anchorY: 0 }); self.sprites = [backgroundGraphics]; // Store sprites for access self.speed = 3; self.update = function () { if (!game.playerDead) { // Increase speed over time, up to a reasonable maximum self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3); // Double speed during star power if (starPowerActive) { self.speed *= 2; } self.x -= self.speed; } if (self.x <= -2048) { self.x = 2048; } }; }); var Background2 = Container.expand(function () { var self = Container.call(this); var backgrounds = ['background1', 'background2', 'background3']; var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)]; var backgroundGraphics = self.attachAsset(randomBackground, { anchorX: 0, anchorY: 0 }); self.sprites = [backgroundGraphics]; // Store sprites for access self.speed = 3; self.update = function () { if (!game.playerDead) { // Increase speed over time, up to a reasonable maximum self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3); // Double speed during star power if (starPowerActive) { self.speed *= 2; } self.x -= self.speed; } if (self.x <= -2048) { self.x = 2048; } }; }); var Coin = Container.expand(function () { var self = Container.call(this); var coinGraphics = self.attachAsset('coin', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); self.speed = 3; self.collected = false; self.y = 2732 - 600; // Position coins higher than the ground self.update = function () { if (!game.playerDead) { // Increase speed over time, up to a reasonable maximum self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3); self.x -= self.speed; } if (self.x < -100) { self.destroy(); } }; }); // ComboDisplay handles showing combo text on screen var ComboDisplay = Container.expand(function () { var self = Container.call(this); var comboText = new Text2('', { size: 100, fill: 0xFFD700, // Gold color for combo text font: "'Press Start 2P', monospace" }); comboText.anchor.set(0.5, 0.5); self.addChild(comboText); self.showCombo = function (comboCount, points) { comboText.setText('COMBO x' + comboCount + '!\n+' + points + ' POINTS!'); comboText.alpha = 1; // Animate the combo text with a scale effect comboText.scale.x = 1.5; comboText.scale.y = 1.5; tween(comboText, { alpha: 0, scaleX: 1, scaleY: 1, y: comboText.y - 100 // Move up as it fades }, { duration: 1000, easing: tween.easeOut }); }; return self; }); var Enemy = Container.expand(function () { var self = Container.call(this); self.runFrames = ['turtle1', 'turtle2']; self.sprites = []; // Pre-attach all sprites for (var i = 0; i < self.runFrames.length; i++) { var sprite = self.attachAsset(self.runFrames[i], { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } self.speed = 6 + Math.random() * 2; self.passed = false; self.isJumping = false; self.velocityY = 0; self.groundY = 2732 - 400; // 400 pixels from bottom self.y = self.groundY; // Set initial position to ground level self.runFrameIndex = 0; self.runFrameCounter = 0; self.runFrameDelay = 15; self.showFrame = function (index) { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Show the appropriate sprite self.sprites[index].alpha = 1; }; self.update = function () { self.x -= self.speed + Math.floor(LK.ticks / 300) * 0.2; // Increase speed over time faster if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.5; // Gravity effect if (self.y > 2732) { self.destroy(); } } else { self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; self.showFrame(self.runFrameIndex); self.runFrameCounter = 0; } } if (self.x < -100) { self.destroy(); } }; }); var FlyKoopa = Container.expand(function () { var self = Container.call(this); self.runFrames = ['flykoopa1', 'flykoopa2']; self.sprites = []; // Pre-attach all sprites for (var i = 0; i < self.runFrames.length; i++) { var sprite = self.attachAsset(self.runFrames[i], { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } self.speed = 4 + Math.random() * 2; self.runFrameIndex = 0; self.runFrameCounter = 0; self.runFrameDelay = 15; self.isJumping = false; self.velocityY = 0; self.showFrame = function (index) { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Show the appropriate sprite self.sprites[index].alpha = 1; }; self.update = function () { // Increase speed over time, up to a reasonable maximum self.speed = 4 + Math.random() * 2 + Math.min(6, Math.floor(LK.ticks / 300) * 0.3); self.x -= self.speed; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.5; // Gravity effect if (self.y > 2732) { self.destroy(); } } else { self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; self.showFrame(self.runFrameIndex); self.runFrameCounter = 0; } } if (self.x < -100) { self.destroy(); } }; }); var Goomba = Container.expand(function () { var self = Container.call(this); self.runFrames = ['goomba1', 'goomba2']; self.sprites = []; // Pre-attach all sprites for (var i = 0; i < self.runFrames.length; i++) { var sprite = self.attachAsset(self.runFrames[i], { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } self.speed = 4 + Math.random() * 2; self.passed = false; self.isJumping = false; self.velocityY = 0; self.groundY = 2732 - 400; // 400 pixels from bottom self.y = self.groundY; // Set initial position to ground level self.runFrameIndex = 0; self.runFrameCounter = 0; self.runFrameDelay = 15; self.showFrame = function (index) { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Show the appropriate sprite self.sprites[index].alpha = 1; }; self.update = function () { // Increase speed over time, up to a reasonable maximum self.speed = 4 + Math.random() * 2 + Math.min(6, Math.floor(LK.ticks / 300) * 0.3); self.x -= self.speed; if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.5; // Gravity effect if (self.y > 2732) { self.destroy(); } } else { self.runFrameCounter++; if (self.runFrameCounter >= self.runFrameDelay) { self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length; self.showFrame(self.runFrameIndex); self.runFrameCounter = 0; } } if (self.x < -100) { self.destroy(); } }; }); var MainMenu = Container.expand(function () { var self = Container.call(this); // Title text var titleText = new Text2('MARIO GAME', { size: 150, fill: 0xE75A10, //{3t} // NES Mario brick-red color font: "'Press Start 2P', monospace" }); titleText.anchor.set(0.5, 0.5); titleText.x = 2048 / 2; titleText.y = 2732 / 3; self.addChild(titleText); // Subtitle text var subtitleText = new Text2('Jump, run, and collect coins!', { size: 80, fill: 0xFCE29F, //{3z} // NES light tan/cream color font: "'Press Start 2P', monospace" }); subtitleText.anchor.set(0.5, 0.5); subtitleText.x = 2048 / 2; subtitleText.y = 2732 / 3 + 200; self.addChild(subtitleText); // Play button var playButton = new Text2('TAP TO START', { size: 100, fill: 0xFCA817, // NES Mario gold coin color font: "'Press Start 2P', monospace" }); playButton.anchor.set(0.5, 0.5); playButton.x = 2048 / 2; playButton.y = 2732 / 2 + 200; self.addChild(playButton); // Upgrade button var upgradeButton = new Text2('UPGRADES', { size: 80, fill: 0x4AC5FF, // NES Mario sky blue color font: "'Press Start 2P', monospace" }); upgradeButton.anchor.set(0.5, 0.5); upgradeButton.x = 2048 / 2; upgradeButton.y = 2732 / 2 + 350; self.addChild(upgradeButton); // Make the play button "pulse" for attention self.animationCounter = 0; self.update = function () { self.animationCounter += 0.05; playButton.scale.x = 1 + Math.sin(self.animationCounter) * 0.1; playButton.scale.y = 1 + Math.sin(self.animationCounter) * 0.1; }; // Handle button clicks self.down = function (x, y, obj) { // Check if upgrade button was clicked if (x > upgradeButton.x - 200 && x < upgradeButton.x + 200 && y > upgradeButton.y - 50 && y < upgradeButton.y + 50) { if (self.onUpgradeClick) { self.onUpgradeClick(); } return true; // Prevent propagation } // Default behavior - start game if (self.onPlayClick) { self.onPlayClick(); } }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); self.runAnimation = ['player_run1', 'player_run2', 'player_run3']; self.jumpAnimation = ['player_jump']; self.currentState = 'running'; self.sprites = []; self.runFrame = 0; self.jumpFrame = 0; self.animationCounter = 0; self.animationSpeed = 0.1; // Pre-attach all sprites for (var i = 0; i < self.runAnimation.length; i++) { var sprite = self.attachAsset(self.runAnimation[i], { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } for (var j = 0; j < self.jumpAnimation.length; j++) { var jumpSprite = self.attachAsset(self.jumpAnimation[j], { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); jumpSprite.alpha = 0; self.sprites.push(jumpSprite); } self.speed = 5; // Base speed, will increase in update function self.jumpHeight = 25; self.isJumping = false; self.canDoubleJump = false; // Track if double jump is available self.hasDoubleJumped = false; // Track if double jump was used self.isDashing = false; // Track if player is currently dashing self.isInvincible = false; // Track if player is invincible self.dashCooldown = false; // Dash cooldown self.swipeStartX = null; // Track swipe start position self.swipeStartY = null; self.velocityY = 0; self.groundY = 2732 - 400; // 400 pixels from bottom self.y = self.groundY; // Set initial position to ground level self.runFrameDelay = 10; self.showFrame = function (frameType, index) { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Show the appropriate sprite based on state and frame index if (frameType === 'run') { self.sprites[index].alpha = 1; } else if (frameType === 'jump') { self.sprites[self.runAnimation.length + index].alpha = 1; } }; self.dash = function () { // Only dash if the upgrade is purchased and not on cooldown if (storage.dashPurchased && !self.dashCooldown && !self.isDashing) { self.isDashing = true; self.isInvincible = true; // Create a distinct visual effect for dash - cyan trail and blue flash LK.effects.flashObject(self, 0x00FFFF, 500); // Cyan flash for dash // Store original position to create trail effect var startX = self.x; // Move player forward quickly self.x += 300; // Create "speed lines" effect for (var i = 0; i < 5; i++) { var trailEffect = LK.getAsset('player_jump', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5 - i * 0.2, scaleY: 1.5 - i * 0.2, x: startX + i * 60, y: self.y, alpha: 0.7 - i * 0.1 }); trailEffect.tint = 0x00FFFF; // Cyan trail game.addChild(trailEffect); // Fade out and remove the trail effect var trailIndex = i; LK.setTimeout(function () { if (trailEffect && trailEffect.parent) { trailEffect.parent.removeChild(trailEffect); } }, 100 + trailIndex * 50); } // Set invincibility LK.setTimeout(function () { self.isInvincible = false; self.isDashing = false; }, 500); // Set cooldown self.dashCooldown = true; LK.setTimeout(function () { self.dashCooldown = false; }, 2000); // 2 second cooldown } }; self.checkSwipe = function (endX, endY) { if (self.swipeStartX === null || self.swipeStartY === null) { return; } var deltaX = endX - self.swipeStartX; var deltaY = endY - self.swipeStartY; // Only consider horizontal swipes with minimal vertical movement if (Math.abs(deltaX) > 100 && Math.abs(deltaY) < 50 && deltaX > 0) { self.dash(); } // Reset swipe tracking self.swipeStartX = null; self.swipeStartY = null; }; self.down = function (x, y, obj) { self.swipeStartX = x; self.swipeStartY = y; }; self.up = function (x, y, obj) { self.checkSwipe(x, y); }; self.move = function (x, y, obj) { // Optional: For more responsive swipe detection // If pointer moves far enough horizontally, trigger dash if (self.swipeStartX !== null && Math.abs(x - self.swipeStartX) > 150) { self.checkSwipe(x, y); } }; self.update = function () { // Update player speed based on game progress and background speed // Use background speed as base for player speed scaling if available var speedMultiplier = 1; if (game.background && game.background.speed) { speedMultiplier = game.background.speed / 3; } self.speed = 5 + Math.min(5, Math.floor(LK.ticks / 300) * 0.3 * speedMultiplier); if (self.isJumping) { self.y += self.velocityY; // Scale gravity based on game speed - faster speed = faster falling var gravityMultiplier = speedMultiplier > 1 ? speedMultiplier * 0.8 : 1; self.velocityY += 0.3 * gravityMultiplier; // Show jump sprite self.showFrame('jump', 0); if (self.y >= self.groundY - 30) { if (self.y < 0) { // Prevent jump from exceeding the top of the screen self.y = 0; self.velocityY = 0; } if (!self.isDead) { self.y = self.groundY - 30; self.isJumping = false; self.hasDoubleJumped = false; // Reset double jump when landing self.velocityY = 0; self.currentState = 'running'; // Reset combo when landing if (comboActive) { comboActive = false; // If we had a combo going, display the final combo if (comboCount > 1) { if (!comboDisplayObj) { comboDisplayObj = game.addChild(new ComboDisplay()); comboDisplayObj.x = 2048 / 2; comboDisplayObj.y = 2732 / 2 - 300; } var comboPoints = comboCount * 50 * 2; // Double points for combos comboDisplayObj.showCombo(comboCount, comboPoints); } comboCount = 0; } } } } else { // Running animation self.animationCounter += self.animationSpeed; if (self.animationCounter >= 1) { self.animationCounter = 0; self.runFrame = (self.runFrame + 1) % self.runAnimation.length; self.showFrame('run', self.runFrame); } } }; self.jump = function () { // Get speed multiplier based on background speed var speedMultiplier = 1; if (game.background && game.background.speed) { speedMultiplier = game.background.speed / 3; } // Increase jump height slightly with game speed to help player clear obstacles var jumpHeightMultiplier = Math.min(1.3, 1 + (speedMultiplier - 1) * 0.3); // Regular jump when not jumping if (!self.isJumping) { self.isJumping = true; LK.getSound('jump').play(); self.velocityY = -self.jumpHeight * jumpHeightMultiplier; self.currentState = 'jumping'; self.showFrame('jump', 0); } // Double jump when already jumping and upgrade purchased else if (self.isJumping && storage.doubleJumpPurchased && !self.hasDoubleJumped) { LK.getSound('jump').play(); self.velocityY = -self.jumpHeight * 0.8 * jumpHeightMultiplier; // Slightly lower second jump self.hasDoubleJumped = true; // No flash effect for double jump to make it distinct from dash } }; }); var Star = Container.expand(function () { var self = Container.call(this); // Create star shape with yellow color var starGraphics = self.attachAsset('gauge_fill', { anchorX: 0.5, anchorY: 0.5, scaleX: 0.3, scaleY: 0.3 }); // Set star color to bright yellow starGraphics.tint = 0xFFFF00; self.speed = 3; self.collected = false; self.y = 2732 - 600; // Position stars higher than the ground // Add animation self.animationCounter = 0; self.update = function () { if (!game.playerDead) { // Increase speed over time, matching background speed self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3); self.x -= self.speed; // Bobbing animation self.animationCounter += 0.1; self.y += Math.sin(self.animationCounter) * 2; // Pulsing scale animation self.scale.x = 1 + Math.sin(self.animationCounter * 0.5) * 0.1; self.scale.y = 1 + Math.sin(self.animationCounter * 0.5) * 0.1; } if (self.x < -100) { self.destroy(); } }; return self; }); var UpgradeMenu = Container.expand(function () { var self = Container.call(this); // Background panel var panel = self.attachAsset('gauge_background', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.1, scaleY: 5 }); panel.alpha = 0.8; // Title var titleText = new Text2('UPGRADES', { size: 100, fill: 0xE75A10, //{5b} // NES Mario brick-red color font: "'Press Start 2P', monospace" }); titleText.anchor.set(0.5, 0.5); titleText.x = 0; titleText.y = -400; self.addChild(titleText); // Coin display var coinDisplay = new Text2('Coins: ' + (storage.coins || 0), { size: 70, fill: 0xFCA817, //{5h} // NES Mario gold coin color font: "'Press Start 2P', monospace" }); coinDisplay.anchor.set(0.5, 0.5); coinDisplay.x = 0; coinDisplay.y = -300; self.addChild(coinDisplay); // Double Jump upgrade button var doubleJumpButton = new Text2('Double Jump: ' + (storage.doubleJumpPurchased ? 'PURCHASED' : '5 COINS'), { size: 70, fill: storage.doubleJumpPurchased ? 0x00FF00 : 0xFFFFFF, font: "'Press Start 2P', monospace" }); doubleJumpButton.anchor.set(0.5, 0.5); doubleJumpButton.x = 0; doubleJumpButton.y = -100; self.addChild(doubleJumpButton); // Dash upgrade button var dashButton = new Text2('Dash: ' + (storage.dashPurchased ? 'PURCHASED' : '8 COINS'), { size: 70, fill: storage.dashPurchased ? 0x00FF00 : 0xFFFFFF, font: "'Press Start 2P', monospace" }); dashButton.anchor.set(0.5, 0.5); dashButton.x = 0; dashButton.y = 0; self.addChild(dashButton); // Close button var closeButton = new Text2('BACK TO MENU', { size: 70, fill: 0xE75A10, //{5t} // NES Mario brick-red color font: "'Press Start 2P', monospace" }); closeButton.anchor.set(0.5, 0.5); closeButton.x = 0; closeButton.y = 400; self.addChild(closeButton); // Update coin display self.updateCoinDisplay = function () { coinDisplay.setText('Coins: ' + (storage.coins || 0)); doubleJumpButton.setText('Double Jump: ' + (storage.doubleJumpPurchased ? 'PURCHASED' : '5 COINS'), { size: 70, fill: storage.doubleJumpPurchased ? 0x20D060 : 0xFCE29F, //{5x} // NES green for purchased, light cream for not font: "'Press Start 2P', monospace" }); dashButton.setText('Dash: ' + (storage.dashPurchased ? 'PURCHASED' : '8 COINS'), { size: 70, fill: storage.dashPurchased ? 0x20D060 : 0xFCE29F, //{5B} // NES green for purchased, light cream for not font: "'Press Start 2P', monospace" }); }; // Handle purchase self.purchaseDoubleJump = function () { if (!storage.doubleJumpPurchased && (storage.coins || 0) >= 5) { storage.coins -= 5; storage.doubleJumpPurchased = true; self.updateCoinDisplay(); } }; // Handle dash purchase self.purchaseDash = function () { if (!storage.dashPurchased && (storage.coins || 0) >= 8) { storage.coins -= 8; storage.dashPurchased = true; self.updateCoinDisplay(); } }; // Handle button presses self.down = function (x, y, obj) { // Direct comparison without conversion as x,y are already in local coordinates // Check if double jump button was pressed if (Math.abs(x - doubleJumpButton.x) < 400 && Math.abs(y - doubleJumpButton.y) < 50) { self.purchaseDoubleJump(); } // Check if dash button was pressed if (Math.abs(x - dashButton.x) < 400 && Math.abs(y - dashButton.y) < 50) { self.purchaseDash(); } // Check if close button was pressed if (Math.abs(x - closeButton.x) < 300 && Math.abs(y - closeButton.y) < 50) { if (self.onClose) { self.onClose(); } } }; return self; }); /**** * Initialize Game ****/ // Helper function to adjust music playback rate as LK.setMusicPlaybackRate is not available /**** *-Seperator- ****/ var game = new LK.Game({ backgroundColor: 0x5C94FC // NES Mario sky blue background color }); /**** * Game Code ****/ // Helper function to adjust music playback rate as LK.setMusicPlaybackRate is not available // Game state variables function setMusicPlaybackRate(rate) { // Check if music is playing before trying to adjust it // Use the sound API instead of the non-existent LK.getMusic function var music = LK.getSound('theme'); if (music) { // Set the playback rate if available on the audio element if (music.playbackRate !== undefined) { music.playbackRate = rate; } } } var gameStarted = false; var showingUpgradeMenu = false; var mainMenu; var upgradeMenu; var background; var background2; var player; var enemies = []; var enemySpawnInterval = 80; var enemySpawnCounter = 0; var coinObjects = []; // Renamed from 'coins' to avoid conflict with coin counter var coinSpawnInterval = Math.max(40, 150 - Math.floor(LK.ticks / 300) * 2); // Decrease interval faster, minimum 40 var coinSpawnCounter = 0; var stars = []; // Array to store star power-ups var starSpawnInterval = 500; // Spawn stars less frequently than coins var starSpawnCounter = 0; var starPowerActive = false; // Track if star power is active var starPowerDuration = 10 * 60; // 10 seconds at 60fps var starPowerTimer = 0; // Timer for star power // Combo system variables var comboCount = 0; var comboActive = false; var comboDisplayObj = null; // Score system var score = 0; var coins = storage.coins || 0; // Get persistent coin count var scoreText = new Text2('Score: 0', { size: 60, fill: 0xFCE29F, //{67} // NES light tan/cream color font: "'Press Start 2P', monospace" }); // Add a speed indicator to show the increasing difficulty var speedText = new Text2('Speed: 1x', { size: 40, fill: 0xFCE29F, //{6a} // NES light tan/cream color font: "'Press Start 2P', monospace" }); speedText.anchor.set(1, 0); speedText.x = -50; speedText.y = 180; // Position below coin count LK.gui.topRight.addChild(speedText); speedText.alpha = 0; // Hide initially scoreText.anchor.set(1, 0); scoreText.x = -50; scoreText.y = 50; LK.gui.topRight.addChild(scoreText); // Coin count display var coinText = new Text2('Coins: ' + coins, { size: 50, fill: 0xFCA817, //{6d} // NES Mario gold coin color // Gold color for coins font: "'Press Start 2P', monospace" }); coinText.anchor.set(1, 0); coinText.x = -50; coinText.y = 120; // Position below score LK.gui.topRight.addChild(coinText); // Combo indicator for HUD var comboText = new Text2('Combo: 0', { size: 50, fill: 0xFFD700, // Gold color for combo text font: "'Press Start 2P', monospace" }); comboText.anchor.set(1, 0); comboText.x = -50; comboText.y = 240; // Position below coin count LK.gui.topRight.addChild(comboText); comboText.alpha = 0; // Hide combo count initially scoreText.alpha = 0; // Hide score initially coinText.alpha = 0; // Hide coin count initially // Initialize upgrades in storage if needed if (storage.doubleJumpPurchased === undefined) { storage.doubleJumpPurchased = false; } if (storage.dashPurchased === undefined) { storage.dashPurchased = false; } // Show main menu first mainMenu = game.addChild(new MainMenu()); mainMenu.onUpgradeClick = function () { showingUpgradeMenu = true; mainMenu.visible = false; // Create upgrade menu upgradeMenu = game.addChild(new UpgradeMenu()); upgradeMenu.x = 2048 / 2; upgradeMenu.y = 2732 / 2; upgradeMenu.updateCoinDisplay(); upgradeMenu.onClose = function () { showingUpgradeMenu = false; upgradeMenu.destroy(); upgradeMenu = null; mainMenu.visible = true; // Update coin display on main menu coinText.setText('Coins: ' + (storage.coins || 0)); }; }; mainMenu.onPlayClick = function () { // Start the game gameStarted = true; mainMenu.destroy(); mainMenu = null; // Initialize game elements - handled in game.down }; game.update = function () { // Handle menu states if (!gameStarted) { if (showingUpgradeMenu) { // When in upgrade menu, no need to update main menu return; } // When in menu mode, just update the menu if (mainMenu) { mainMenu.update(); } return; } // Game hasn't been initialized yet - start it if (!background) { // Initialize game elements LK.playMusic('theme'); // Create background background = game.addChild(new Background()); background.x = 0; background.y = 0; background2 = game.addChild(new Background2()); background2.x = 2048; background2.y = 0; // Store a reference to the background in the game object for access from other objects game.background = background; // Create player player = game.addChild(new Player()); player.x = 2048 / 4; player.y = player.groundY - 30; // Show score, coin count and speed scoreText.alpha = 1; coinText.alpha = 1; speedText.alpha = 1; } // Game play update logic background.update(); background2.update(); player.update(); enemySpawnCounter++; coinSpawnCounter++; starSpawnCounter++; // Handle star power-up timer if (starPowerActive) { starPowerTimer--; if (starPowerTimer <= 0) { starPowerActive = false; player.isInvincible = false; // Return background tint to normal background.sprites[0].tint = 0xFFFFFF; background2.sprites[0].tint = 0xFFFFFF; } } if (coinSpawnCounter >= coinSpawnInterval) { var coin = new Coin(); coin.x = 2048 + Math.random() * 200; // Set a reasonable height range for coins (not too low, not too high) coin.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800))); coinObjects.push(coin); game.addChild(coin); coinSpawnCounter = 0; } // Spawn star power-ups occasionally if (starSpawnCounter >= starSpawnInterval) { var star = new Star(); star.x = 2048 + Math.random() * 200; // Set a reasonable height range for stars (not too low, not too high) star.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800))); stars.push(star); game.addChild(star); starSpawnCounter = 0; starSpawnInterval = Math.floor(Math.random() * 300) + 300; // Random interval between 300-600 ticks } if (enemySpawnCounter >= enemySpawnInterval) { var enemyType = Math.random() < 0.33 ? 'Enemy' : Math.random() < 0.5 ? 'Goomba' : 'FlyKoopa'; var enemy; if (enemyType === 'Enemy') { enemy = new Enemy(); } else if (enemyType === 'Goomba') { enemy = new Goomba(); } else { enemy = new FlyKoopa(); // Ensure FlyKoopas spawn in the middle to upper part of the screen, not too low enemy.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800))); } enemy.x = 2048 + Math.random() * 200; if (enemyType === 'FlyKoopa') { // Height for FlyKoopa is already set earlier, no need to set it again } else { enemy.y = enemy.groundY; // Use groundY for initial position } enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.max(15, Math.floor(Math.random() * 100) + 60 - Math.floor(LK.ticks / 300) * 2); // Decrease interval faster, minimum 15 enemySpawnCounter = 0; } for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { if (starPowerActive) { // Star power is active - instantly defeat enemy with special effect enemies[j].velocityY = -15; // Stronger pop up effect for star power enemies[j].isJumping = true; enemies[j].canHarmPlayer = false; LK.getSound('stomp').play(); // Create a sparkle effect LK.effects.flashObject(enemies[j], 0xFFFF00, 300); // Add points with star power bonus var starEnemyPoints = 100; score += starEnemyPoints; scoreText.setText('Score: ' + score); LK.setScore(score); } else if (!player.isDead && player.isJumping && player.velocityY > 0 && player.y < enemies[j].y) { // Player is falling and lands on enemy enemies[j].velocityY = -10; // Pop up effect for enemy player.velocityY = -15; // Bounce Mario upwards LK.getSound('stomp').play(); // Play stomp sound // Handle combo tracking - activate combo mode if not already active if (!comboActive) { comboActive = true; comboCount = 0; } // Increment combo count comboCount++; // Calculate score with combo bonus var enemyPoints = 50; if (comboCount > 1) { // Apply combo multiplier - each enemy in combo is worth more enemyPoints = 50 * comboCount; } score += enemyPoints; // Display flash text for combo count if more than 1 if (comboCount > 1) { if (!comboDisplayObj) { comboDisplayObj = game.addChild(new ComboDisplay()); comboDisplayObj.x = 2048 / 2; comboDisplayObj.y = 2732 / 2 - 300; } comboDisplayObj.showCombo(comboCount, enemyPoints); } scoreText.setText('Score: ' + score); LK.setScore(score); enemies[j].isJumping = true; enemies[j].canHarmPlayer = false; // Enemy can no longer harm player } else if (enemies[j].canHarmPlayer !== false && !player.isInvincible) { if (!player.isDead && enemies[j].canHarmPlayer !== false) { LK.getSound('dead').play(); // Play dead sound player.isDead = true; game.playerDead = true; player.velocityY = -10; // Pop up effect similar to enemy player.isJumping = true; LK.setTimeout(function () { // Save final score before game over LK.setScore(score); LK.showGameOver(); }, 3000); // Delay game over by 3 seconds } } } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; } if (enemies[j].x < -100) { enemies.splice(j, 1); } } for (var k = coinObjects.length - 1; k >= 0; k--) { coinObjects[k].update(); if (player.intersects(coinObjects[k])) { if (!coinObjects[k].collected) { coinObjects[k].collected = true; LK.getSound('Coin').play(); // Play coin sound // Increase score when collecting coins score += 10; // Separate coin counter coins++; // Update storage for persistence storage.coins = coins; // Update displays scoreText.setText('Score: ' + score); coinText.setText('Coins: ' + coins); LK.setScore(score); coinObjects[k].destroy(); coinObjects.splice(k, 1); } } } // Update and check star power-ups for (var s = stars.length - 1; s >= 0; s--) { stars[s].update(); if (player.intersects(stars[s])) { if (!stars[s].collected) { stars[s].collected = true; // Play coin sound for now (could use a special star sound) LK.getSound('Coin').play(); // Activate star power starPowerActive = true; starPowerTimer = starPowerDuration; player.isInvincible = true; // Visual effects for star power LK.effects.flashObject(player, 0xFFFF00, 500); // Yellow flash // Change background tint for star power effect if (background.sprites && background.sprites.length > 0) { background.sprites[0].tint = 0xFFFFAA; // Slight yellow tint } if (background2.sprites && background2.sprites.length > 0) { background2.sprites[0].tint = 0xFFFFAA; // Slight yellow tint } // Add extra points for star score += 100; scoreText.setText('Score: ' + score); LK.setScore(score); // Remove the star stars[s].destroy(); stars.splice(s, 1); } } else if (stars[s].x < -100) { stars[s].destroy(); stars.splice(s, 1); } } // Update speed display and music speed if (background && !game.playerDead) { var speedMultiplier = (background.speed / 3).toFixed(1); // Show star power status in speed text if active if (starPowerActive) { var starTimeLeft = Math.ceil(starPowerTimer / 60); speedText.setText('STAR POWER: ' + starTimeLeft + 's'); speedText.style.fill = 0xFFFF00; // Yellow for star power } else { speedText.setText('Speed: ' + speedMultiplier + 'x'); speedText.style.fill = 0xFCE29F; // Return to normal color } // Update combo text in HUD comboText.setText('Combo: ' + comboCount); comboText.alpha = gameStarted ? 1 : 0; // Adjust music playback rate based on game speed var musicPlaybackRate = Math.min(1.5, 0.8 + background.speed / 3 * 0.2); // Increase music speed during star power if (starPowerActive) { musicPlaybackRate = Math.min(2.0, musicPlaybackRate * 1.2); } setMusicPlaybackRate(musicPlaybackRate); } }; game.down = function (x, y, obj) { if (showingUpgradeMenu) { // Let the upgrade menu handle this event return; } if (!gameStarted) { // Let the main menu handle this event return; } else { // Pass event to player to track swipes player.down(x, y, obj); // In-game tap makes player jump player.jump(); } }; game.up = function (x, y, obj) { if (showingUpgradeMenu || !gameStarted) { return; } // Pass touch up event to player for swipe detection if (player) { player.up(x, y, obj); } }; game.move = function (x, y, obj) { if (showingUpgradeMenu || !gameStarted) { return; } // Pass touch move event to player for swipe detection if (player) { player.move(x, y, obj); } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
coins: 0
});
/****
* Classes
****/
var Background = Container.expand(function () {
var self = Container.call(this);
var backgrounds = ['background1', 'background2', 'background3'];
var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
var backgroundGraphics = self.attachAsset(randomBackground, {
anchorX: 0,
anchorY: 0
});
self.sprites = [backgroundGraphics]; // Store sprites for access
self.speed = 3;
self.update = function () {
if (!game.playerDead) {
// Increase speed over time, up to a reasonable maximum
self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3);
// Double speed during star power
if (starPowerActive) {
self.speed *= 2;
}
self.x -= self.speed;
}
if (self.x <= -2048) {
self.x = 2048;
}
};
});
var Background2 = Container.expand(function () {
var self = Container.call(this);
var backgrounds = ['background1', 'background2', 'background3'];
var randomBackground = backgrounds[Math.floor(Math.random() * backgrounds.length)];
var backgroundGraphics = self.attachAsset(randomBackground, {
anchorX: 0,
anchorY: 0
});
self.sprites = [backgroundGraphics]; // Store sprites for access
self.speed = 3;
self.update = function () {
if (!game.playerDead) {
// Increase speed over time, up to a reasonable maximum
self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3);
// Double speed during star power
if (starPowerActive) {
self.speed *= 2;
}
self.x -= self.speed;
}
if (self.x <= -2048) {
self.x = 2048;
}
};
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
self.speed = 3;
self.collected = false;
self.y = 2732 - 600; // Position coins higher than the ground
self.update = function () {
if (!game.playerDead) {
// Increase speed over time, up to a reasonable maximum
self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3);
self.x -= self.speed;
}
if (self.x < -100) {
self.destroy();
}
};
});
// ComboDisplay handles showing combo text on screen
var ComboDisplay = Container.expand(function () {
var self = Container.call(this);
var comboText = new Text2('', {
size: 100,
fill: 0xFFD700,
// Gold color for combo text
font: "'Press Start 2P', monospace"
});
comboText.anchor.set(0.5, 0.5);
self.addChild(comboText);
self.showCombo = function (comboCount, points) {
comboText.setText('COMBO x' + comboCount + '!\n+' + points + ' POINTS!');
comboText.alpha = 1;
// Animate the combo text with a scale effect
comboText.scale.x = 1.5;
comboText.scale.y = 1.5;
tween(comboText, {
alpha: 0,
scaleX: 1,
scaleY: 1,
y: comboText.y - 100 // Move up as it fades
}, {
duration: 1000,
easing: tween.easeOut
});
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
self.runFrames = ['turtle1', 'turtle2'];
self.sprites = [];
// Pre-attach all sprites
for (var i = 0; i < self.runFrames.length; i++) {
var sprite = self.attachAsset(self.runFrames[i], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
sprite.alpha = i === 0 ? 1 : 0;
self.sprites.push(sprite);
}
self.speed = 6 + Math.random() * 2;
self.passed = false;
self.isJumping = false;
self.velocityY = 0;
self.groundY = 2732 - 400; // 400 pixels from bottom
self.y = self.groundY; // Set initial position to ground level
self.runFrameIndex = 0;
self.runFrameCounter = 0;
self.runFrameDelay = 15;
self.showFrame = function (index) {
// Hide all sprites first
for (var i = 0; i < self.sprites.length; i++) {
self.sprites[i].alpha = 0;
}
// Show the appropriate sprite
self.sprites[index].alpha = 1;
};
self.update = function () {
self.x -= self.speed + Math.floor(LK.ticks / 300) * 0.2; // Increase speed over time faster
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.5; // Gravity effect
if (self.y > 2732) {
self.destroy();
}
} else {
self.runFrameCounter++;
if (self.runFrameCounter >= self.runFrameDelay) {
self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length;
self.showFrame(self.runFrameIndex);
self.runFrameCounter = 0;
}
}
if (self.x < -100) {
self.destroy();
}
};
});
var FlyKoopa = Container.expand(function () {
var self = Container.call(this);
self.runFrames = ['flykoopa1', 'flykoopa2'];
self.sprites = [];
// Pre-attach all sprites
for (var i = 0; i < self.runFrames.length; i++) {
var sprite = self.attachAsset(self.runFrames[i], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
sprite.alpha = i === 0 ? 1 : 0;
self.sprites.push(sprite);
}
self.speed = 4 + Math.random() * 2;
self.runFrameIndex = 0;
self.runFrameCounter = 0;
self.runFrameDelay = 15;
self.isJumping = false;
self.velocityY = 0;
self.showFrame = function (index) {
// Hide all sprites first
for (var i = 0; i < self.sprites.length; i++) {
self.sprites[i].alpha = 0;
}
// Show the appropriate sprite
self.sprites[index].alpha = 1;
};
self.update = function () {
// Increase speed over time, up to a reasonable maximum
self.speed = 4 + Math.random() * 2 + Math.min(6, Math.floor(LK.ticks / 300) * 0.3);
self.x -= self.speed;
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.5; // Gravity effect
if (self.y > 2732) {
self.destroy();
}
} else {
self.runFrameCounter++;
if (self.runFrameCounter >= self.runFrameDelay) {
self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length;
self.showFrame(self.runFrameIndex);
self.runFrameCounter = 0;
}
}
if (self.x < -100) {
self.destroy();
}
};
});
var Goomba = Container.expand(function () {
var self = Container.call(this);
self.runFrames = ['goomba1', 'goomba2'];
self.sprites = [];
// Pre-attach all sprites
for (var i = 0; i < self.runFrames.length; i++) {
var sprite = self.attachAsset(self.runFrames[i], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
sprite.alpha = i === 0 ? 1 : 0;
self.sprites.push(sprite);
}
self.speed = 4 + Math.random() * 2;
self.passed = false;
self.isJumping = false;
self.velocityY = 0;
self.groundY = 2732 - 400; // 400 pixels from bottom
self.y = self.groundY; // Set initial position to ground level
self.runFrameIndex = 0;
self.runFrameCounter = 0;
self.runFrameDelay = 15;
self.showFrame = function (index) {
// Hide all sprites first
for (var i = 0; i < self.sprites.length; i++) {
self.sprites[i].alpha = 0;
}
// Show the appropriate sprite
self.sprites[index].alpha = 1;
};
self.update = function () {
// Increase speed over time, up to a reasonable maximum
self.speed = 4 + Math.random() * 2 + Math.min(6, Math.floor(LK.ticks / 300) * 0.3);
self.x -= self.speed;
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.5; // Gravity effect
if (self.y > 2732) {
self.destroy();
}
} else {
self.runFrameCounter++;
if (self.runFrameCounter >= self.runFrameDelay) {
self.runFrameIndex = (self.runFrameIndex + 1) % self.runFrames.length;
self.showFrame(self.runFrameIndex);
self.runFrameCounter = 0;
}
}
if (self.x < -100) {
self.destroy();
}
};
});
var MainMenu = Container.expand(function () {
var self = Container.call(this);
// Title text
var titleText = new Text2('MARIO GAME', {
size: 150,
fill: 0xE75A10,
//{3t} // NES Mario brick-red color
font: "'Press Start 2P', monospace"
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 2048 / 2;
titleText.y = 2732 / 3;
self.addChild(titleText);
// Subtitle text
var subtitleText = new Text2('Jump, run, and collect coins!', {
size: 80,
fill: 0xFCE29F,
//{3z} // NES light tan/cream color
font: "'Press Start 2P', monospace"
});
subtitleText.anchor.set(0.5, 0.5);
subtitleText.x = 2048 / 2;
subtitleText.y = 2732 / 3 + 200;
self.addChild(subtitleText);
// Play button
var playButton = new Text2('TAP TO START', {
size: 100,
fill: 0xFCA817,
// NES Mario gold coin color
font: "'Press Start 2P', monospace"
});
playButton.anchor.set(0.5, 0.5);
playButton.x = 2048 / 2;
playButton.y = 2732 / 2 + 200;
self.addChild(playButton);
// Upgrade button
var upgradeButton = new Text2('UPGRADES', {
size: 80,
fill: 0x4AC5FF,
// NES Mario sky blue color
font: "'Press Start 2P', monospace"
});
upgradeButton.anchor.set(0.5, 0.5);
upgradeButton.x = 2048 / 2;
upgradeButton.y = 2732 / 2 + 350;
self.addChild(upgradeButton);
// Make the play button "pulse" for attention
self.animationCounter = 0;
self.update = function () {
self.animationCounter += 0.05;
playButton.scale.x = 1 + Math.sin(self.animationCounter) * 0.1;
playButton.scale.y = 1 + Math.sin(self.animationCounter) * 0.1;
};
// Handle button clicks
self.down = function (x, y, obj) {
// Check if upgrade button was clicked
if (x > upgradeButton.x - 200 && x < upgradeButton.x + 200 && y > upgradeButton.y - 50 && y < upgradeButton.y + 50) {
if (self.onUpgradeClick) {
self.onUpgradeClick();
}
return true; // Prevent propagation
}
// Default behavior - start game
if (self.onPlayClick) {
self.onPlayClick();
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
self.runAnimation = ['player_run1', 'player_run2', 'player_run3'];
self.jumpAnimation = ['player_jump'];
self.currentState = 'running';
self.sprites = [];
self.runFrame = 0;
self.jumpFrame = 0;
self.animationCounter = 0;
self.animationSpeed = 0.1;
// Pre-attach all sprites
for (var i = 0; i < self.runAnimation.length; i++) {
var sprite = self.attachAsset(self.runAnimation[i], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
sprite.alpha = i === 0 ? 1 : 0;
self.sprites.push(sprite);
}
for (var j = 0; j < self.jumpAnimation.length; j++) {
var jumpSprite = self.attachAsset(self.jumpAnimation[j], {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5,
scaleY: 1.5
});
jumpSprite.alpha = 0;
self.sprites.push(jumpSprite);
}
self.speed = 5; // Base speed, will increase in update function
self.jumpHeight = 25;
self.isJumping = false;
self.canDoubleJump = false; // Track if double jump is available
self.hasDoubleJumped = false; // Track if double jump was used
self.isDashing = false; // Track if player is currently dashing
self.isInvincible = false; // Track if player is invincible
self.dashCooldown = false; // Dash cooldown
self.swipeStartX = null; // Track swipe start position
self.swipeStartY = null;
self.velocityY = 0;
self.groundY = 2732 - 400; // 400 pixels from bottom
self.y = self.groundY; // Set initial position to ground level
self.runFrameDelay = 10;
self.showFrame = function (frameType, index) {
// Hide all sprites first
for (var i = 0; i < self.sprites.length; i++) {
self.sprites[i].alpha = 0;
}
// Show the appropriate sprite based on state and frame index
if (frameType === 'run') {
self.sprites[index].alpha = 1;
} else if (frameType === 'jump') {
self.sprites[self.runAnimation.length + index].alpha = 1;
}
};
self.dash = function () {
// Only dash if the upgrade is purchased and not on cooldown
if (storage.dashPurchased && !self.dashCooldown && !self.isDashing) {
self.isDashing = true;
self.isInvincible = true;
// Create a distinct visual effect for dash - cyan trail and blue flash
LK.effects.flashObject(self, 0x00FFFF, 500); // Cyan flash for dash
// Store original position to create trail effect
var startX = self.x;
// Move player forward quickly
self.x += 300;
// Create "speed lines" effect
for (var i = 0; i < 5; i++) {
var trailEffect = LK.getAsset('player_jump', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.5 - i * 0.2,
scaleY: 1.5 - i * 0.2,
x: startX + i * 60,
y: self.y,
alpha: 0.7 - i * 0.1
});
trailEffect.tint = 0x00FFFF; // Cyan trail
game.addChild(trailEffect);
// Fade out and remove the trail effect
var trailIndex = i;
LK.setTimeout(function () {
if (trailEffect && trailEffect.parent) {
trailEffect.parent.removeChild(trailEffect);
}
}, 100 + trailIndex * 50);
}
// Set invincibility
LK.setTimeout(function () {
self.isInvincible = false;
self.isDashing = false;
}, 500);
// Set cooldown
self.dashCooldown = true;
LK.setTimeout(function () {
self.dashCooldown = false;
}, 2000); // 2 second cooldown
}
};
self.checkSwipe = function (endX, endY) {
if (self.swipeStartX === null || self.swipeStartY === null) {
return;
}
var deltaX = endX - self.swipeStartX;
var deltaY = endY - self.swipeStartY;
// Only consider horizontal swipes with minimal vertical movement
if (Math.abs(deltaX) > 100 && Math.abs(deltaY) < 50 && deltaX > 0) {
self.dash();
}
// Reset swipe tracking
self.swipeStartX = null;
self.swipeStartY = null;
};
self.down = function (x, y, obj) {
self.swipeStartX = x;
self.swipeStartY = y;
};
self.up = function (x, y, obj) {
self.checkSwipe(x, y);
};
self.move = function (x, y, obj) {
// Optional: For more responsive swipe detection
// If pointer moves far enough horizontally, trigger dash
if (self.swipeStartX !== null && Math.abs(x - self.swipeStartX) > 150) {
self.checkSwipe(x, y);
}
};
self.update = function () {
// Update player speed based on game progress and background speed
// Use background speed as base for player speed scaling if available
var speedMultiplier = 1;
if (game.background && game.background.speed) {
speedMultiplier = game.background.speed / 3;
}
self.speed = 5 + Math.min(5, Math.floor(LK.ticks / 300) * 0.3 * speedMultiplier);
if (self.isJumping) {
self.y += self.velocityY;
// Scale gravity based on game speed - faster speed = faster falling
var gravityMultiplier = speedMultiplier > 1 ? speedMultiplier * 0.8 : 1;
self.velocityY += 0.3 * gravityMultiplier;
// Show jump sprite
self.showFrame('jump', 0);
if (self.y >= self.groundY - 30) {
if (self.y < 0) {
// Prevent jump from exceeding the top of the screen
self.y = 0;
self.velocityY = 0;
}
if (!self.isDead) {
self.y = self.groundY - 30;
self.isJumping = false;
self.hasDoubleJumped = false; // Reset double jump when landing
self.velocityY = 0;
self.currentState = 'running';
// Reset combo when landing
if (comboActive) {
comboActive = false;
// If we had a combo going, display the final combo
if (comboCount > 1) {
if (!comboDisplayObj) {
comboDisplayObj = game.addChild(new ComboDisplay());
comboDisplayObj.x = 2048 / 2;
comboDisplayObj.y = 2732 / 2 - 300;
}
var comboPoints = comboCount * 50 * 2; // Double points for combos
comboDisplayObj.showCombo(comboCount, comboPoints);
}
comboCount = 0;
}
}
}
} else {
// Running animation
self.animationCounter += self.animationSpeed;
if (self.animationCounter >= 1) {
self.animationCounter = 0;
self.runFrame = (self.runFrame + 1) % self.runAnimation.length;
self.showFrame('run', self.runFrame);
}
}
};
self.jump = function () {
// Get speed multiplier based on background speed
var speedMultiplier = 1;
if (game.background && game.background.speed) {
speedMultiplier = game.background.speed / 3;
}
// Increase jump height slightly with game speed to help player clear obstacles
var jumpHeightMultiplier = Math.min(1.3, 1 + (speedMultiplier - 1) * 0.3);
// Regular jump when not jumping
if (!self.isJumping) {
self.isJumping = true;
LK.getSound('jump').play();
self.velocityY = -self.jumpHeight * jumpHeightMultiplier;
self.currentState = 'jumping';
self.showFrame('jump', 0);
}
// Double jump when already jumping and upgrade purchased
else if (self.isJumping && storage.doubleJumpPurchased && !self.hasDoubleJumped) {
LK.getSound('jump').play();
self.velocityY = -self.jumpHeight * 0.8 * jumpHeightMultiplier; // Slightly lower second jump
self.hasDoubleJumped = true;
// No flash effect for double jump to make it distinct from dash
}
};
});
var Star = Container.expand(function () {
var self = Container.call(this);
// Create star shape with yellow color
var starGraphics = self.attachAsset('gauge_fill', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
// Set star color to bright yellow
starGraphics.tint = 0xFFFF00;
self.speed = 3;
self.collected = false;
self.y = 2732 - 600; // Position stars higher than the ground
// Add animation
self.animationCounter = 0;
self.update = function () {
if (!game.playerDead) {
// Increase speed over time, matching background speed
self.speed = 3 + Math.min(8, Math.floor(LK.ticks / 300) * 0.3);
self.x -= self.speed;
// Bobbing animation
self.animationCounter += 0.1;
self.y += Math.sin(self.animationCounter) * 2;
// Pulsing scale animation
self.scale.x = 1 + Math.sin(self.animationCounter * 0.5) * 0.1;
self.scale.y = 1 + Math.sin(self.animationCounter * 0.5) * 0.1;
}
if (self.x < -100) {
self.destroy();
}
};
return self;
});
var UpgradeMenu = Container.expand(function () {
var self = Container.call(this);
// Background panel
var panel = self.attachAsset('gauge_background', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.1,
scaleY: 5
});
panel.alpha = 0.8;
// Title
var titleText = new Text2('UPGRADES', {
size: 100,
fill: 0xE75A10,
//{5b} // NES Mario brick-red color
font: "'Press Start 2P', monospace"
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 0;
titleText.y = -400;
self.addChild(titleText);
// Coin display
var coinDisplay = new Text2('Coins: ' + (storage.coins || 0), {
size: 70,
fill: 0xFCA817,
//{5h} // NES Mario gold coin color
font: "'Press Start 2P', monospace"
});
coinDisplay.anchor.set(0.5, 0.5);
coinDisplay.x = 0;
coinDisplay.y = -300;
self.addChild(coinDisplay);
// Double Jump upgrade button
var doubleJumpButton = new Text2('Double Jump: ' + (storage.doubleJumpPurchased ? 'PURCHASED' : '5 COINS'), {
size: 70,
fill: storage.doubleJumpPurchased ? 0x00FF00 : 0xFFFFFF,
font: "'Press Start 2P', monospace"
});
doubleJumpButton.anchor.set(0.5, 0.5);
doubleJumpButton.x = 0;
doubleJumpButton.y = -100;
self.addChild(doubleJumpButton);
// Dash upgrade button
var dashButton = new Text2('Dash: ' + (storage.dashPurchased ? 'PURCHASED' : '8 COINS'), {
size: 70,
fill: storage.dashPurchased ? 0x00FF00 : 0xFFFFFF,
font: "'Press Start 2P', monospace"
});
dashButton.anchor.set(0.5, 0.5);
dashButton.x = 0;
dashButton.y = 0;
self.addChild(dashButton);
// Close button
var closeButton = new Text2('BACK TO MENU', {
size: 70,
fill: 0xE75A10,
//{5t} // NES Mario brick-red color
font: "'Press Start 2P', monospace"
});
closeButton.anchor.set(0.5, 0.5);
closeButton.x = 0;
closeButton.y = 400;
self.addChild(closeButton);
// Update coin display
self.updateCoinDisplay = function () {
coinDisplay.setText('Coins: ' + (storage.coins || 0));
doubleJumpButton.setText('Double Jump: ' + (storage.doubleJumpPurchased ? 'PURCHASED' : '5 COINS'), {
size: 70,
fill: storage.doubleJumpPurchased ? 0x20D060 : 0xFCE29F,
//{5x} // NES green for purchased, light cream for not
font: "'Press Start 2P', monospace"
});
dashButton.setText('Dash: ' + (storage.dashPurchased ? 'PURCHASED' : '8 COINS'), {
size: 70,
fill: storage.dashPurchased ? 0x20D060 : 0xFCE29F,
//{5B} // NES green for purchased, light cream for not
font: "'Press Start 2P', monospace"
});
};
// Handle purchase
self.purchaseDoubleJump = function () {
if (!storage.doubleJumpPurchased && (storage.coins || 0) >= 5) {
storage.coins -= 5;
storage.doubleJumpPurchased = true;
self.updateCoinDisplay();
}
};
// Handle dash purchase
self.purchaseDash = function () {
if (!storage.dashPurchased && (storage.coins || 0) >= 8) {
storage.coins -= 8;
storage.dashPurchased = true;
self.updateCoinDisplay();
}
};
// Handle button presses
self.down = function (x, y, obj) {
// Direct comparison without conversion as x,y are already in local coordinates
// Check if double jump button was pressed
if (Math.abs(x - doubleJumpButton.x) < 400 && Math.abs(y - doubleJumpButton.y) < 50) {
self.purchaseDoubleJump();
}
// Check if dash button was pressed
if (Math.abs(x - dashButton.x) < 400 && Math.abs(y - dashButton.y) < 50) {
self.purchaseDash();
}
// Check if close button was pressed
if (Math.abs(x - closeButton.x) < 300 && Math.abs(y - closeButton.y) < 50) {
if (self.onClose) {
self.onClose();
}
}
};
return self;
});
/****
* Initialize Game
****/
// Helper function to adjust music playback rate as LK.setMusicPlaybackRate is not available
/****
*-Seperator-
****/
var game = new LK.Game({
backgroundColor: 0x5C94FC // NES Mario sky blue background color
});
/****
* Game Code
****/
// Helper function to adjust music playback rate as LK.setMusicPlaybackRate is not available
// Game state variables
function setMusicPlaybackRate(rate) {
// Check if music is playing before trying to adjust it
// Use the sound API instead of the non-existent LK.getMusic function
var music = LK.getSound('theme');
if (music) {
// Set the playback rate if available on the audio element
if (music.playbackRate !== undefined) {
music.playbackRate = rate;
}
}
}
var gameStarted = false;
var showingUpgradeMenu = false;
var mainMenu;
var upgradeMenu;
var background;
var background2;
var player;
var enemies = [];
var enemySpawnInterval = 80;
var enemySpawnCounter = 0;
var coinObjects = []; // Renamed from 'coins' to avoid conflict with coin counter
var coinSpawnInterval = Math.max(40, 150 - Math.floor(LK.ticks / 300) * 2); // Decrease interval faster, minimum 40
var coinSpawnCounter = 0;
var stars = []; // Array to store star power-ups
var starSpawnInterval = 500; // Spawn stars less frequently than coins
var starSpawnCounter = 0;
var starPowerActive = false; // Track if star power is active
var starPowerDuration = 10 * 60; // 10 seconds at 60fps
var starPowerTimer = 0; // Timer for star power
// Combo system variables
var comboCount = 0;
var comboActive = false;
var comboDisplayObj = null;
// Score system
var score = 0;
var coins = storage.coins || 0; // Get persistent coin count
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFCE29F,
//{67} // NES light tan/cream color
font: "'Press Start 2P', monospace"
});
// Add a speed indicator to show the increasing difficulty
var speedText = new Text2('Speed: 1x', {
size: 40,
fill: 0xFCE29F,
//{6a} // NES light tan/cream color
font: "'Press Start 2P', monospace"
});
speedText.anchor.set(1, 0);
speedText.x = -50;
speedText.y = 180; // Position below coin count
LK.gui.topRight.addChild(speedText);
speedText.alpha = 0; // Hide initially
scoreText.anchor.set(1, 0);
scoreText.x = -50;
scoreText.y = 50;
LK.gui.topRight.addChild(scoreText);
// Coin count display
var coinText = new Text2('Coins: ' + coins, {
size: 50,
fill: 0xFCA817,
//{6d} // NES Mario gold coin color
// Gold color for coins
font: "'Press Start 2P', monospace"
});
coinText.anchor.set(1, 0);
coinText.x = -50;
coinText.y = 120; // Position below score
LK.gui.topRight.addChild(coinText);
// Combo indicator for HUD
var comboText = new Text2('Combo: 0', {
size: 50,
fill: 0xFFD700,
// Gold color for combo text
font: "'Press Start 2P', monospace"
});
comboText.anchor.set(1, 0);
comboText.x = -50;
comboText.y = 240; // Position below coin count
LK.gui.topRight.addChild(comboText);
comboText.alpha = 0; // Hide combo count initially
scoreText.alpha = 0; // Hide score initially
coinText.alpha = 0; // Hide coin count initially
// Initialize upgrades in storage if needed
if (storage.doubleJumpPurchased === undefined) {
storage.doubleJumpPurchased = false;
}
if (storage.dashPurchased === undefined) {
storage.dashPurchased = false;
}
// Show main menu first
mainMenu = game.addChild(new MainMenu());
mainMenu.onUpgradeClick = function () {
showingUpgradeMenu = true;
mainMenu.visible = false;
// Create upgrade menu
upgradeMenu = game.addChild(new UpgradeMenu());
upgradeMenu.x = 2048 / 2;
upgradeMenu.y = 2732 / 2;
upgradeMenu.updateCoinDisplay();
upgradeMenu.onClose = function () {
showingUpgradeMenu = false;
upgradeMenu.destroy();
upgradeMenu = null;
mainMenu.visible = true;
// Update coin display on main menu
coinText.setText('Coins: ' + (storage.coins || 0));
};
};
mainMenu.onPlayClick = function () {
// Start the game
gameStarted = true;
mainMenu.destroy();
mainMenu = null;
// Initialize game elements - handled in game.down
};
game.update = function () {
// Handle menu states
if (!gameStarted) {
if (showingUpgradeMenu) {
// When in upgrade menu, no need to update main menu
return;
}
// When in menu mode, just update the menu
if (mainMenu) {
mainMenu.update();
}
return;
}
// Game hasn't been initialized yet - start it
if (!background) {
// Initialize game elements
LK.playMusic('theme');
// Create background
background = game.addChild(new Background());
background.x = 0;
background.y = 0;
background2 = game.addChild(new Background2());
background2.x = 2048;
background2.y = 0;
// Store a reference to the background in the game object for access from other objects
game.background = background;
// Create player
player = game.addChild(new Player());
player.x = 2048 / 4;
player.y = player.groundY - 30;
// Show score, coin count and speed
scoreText.alpha = 1;
coinText.alpha = 1;
speedText.alpha = 1;
}
// Game play update logic
background.update();
background2.update();
player.update();
enemySpawnCounter++;
coinSpawnCounter++;
starSpawnCounter++;
// Handle star power-up timer
if (starPowerActive) {
starPowerTimer--;
if (starPowerTimer <= 0) {
starPowerActive = false;
player.isInvincible = false;
// Return background tint to normal
background.sprites[0].tint = 0xFFFFFF;
background2.sprites[0].tint = 0xFFFFFF;
}
}
if (coinSpawnCounter >= coinSpawnInterval) {
var coin = new Coin();
coin.x = 2048 + Math.random() * 200;
// Set a reasonable height range for coins (not too low, not too high)
coin.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800)));
coinObjects.push(coin);
game.addChild(coin);
coinSpawnCounter = 0;
}
// Spawn star power-ups occasionally
if (starSpawnCounter >= starSpawnInterval) {
var star = new Star();
star.x = 2048 + Math.random() * 200;
// Set a reasonable height range for stars (not too low, not too high)
star.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800)));
stars.push(star);
game.addChild(star);
starSpawnCounter = 0;
starSpawnInterval = Math.floor(Math.random() * 300) + 300; // Random interval between 300-600 ticks
}
if (enemySpawnCounter >= enemySpawnInterval) {
var enemyType = Math.random() < 0.33 ? 'Enemy' : Math.random() < 0.5 ? 'Goomba' : 'FlyKoopa';
var enemy;
if (enemyType === 'Enemy') {
enemy = new Enemy();
} else if (enemyType === 'Goomba') {
enemy = new Goomba();
} else {
enemy = new FlyKoopa();
// Ensure FlyKoopas spawn in the middle to upper part of the screen, not too low
enemy.y = Math.max(300, Math.min(2732 - 600, Math.random() * (2732 - 800)));
}
enemy.x = 2048 + Math.random() * 200;
if (enemyType === 'FlyKoopa') {
// Height for FlyKoopa is already set earlier, no need to set it again
} else {
enemy.y = enemy.groundY; // Use groundY for initial position
}
enemies.push(enemy);
game.addChild(enemy);
enemySpawnInterval = Math.max(15, Math.floor(Math.random() * 100) + 60 - Math.floor(LK.ticks / 300) * 2); // Decrease interval faster, minimum 15
enemySpawnCounter = 0;
}
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
if (player.intersects(enemies[j])) {
if (starPowerActive) {
// Star power is active - instantly defeat enemy with special effect
enemies[j].velocityY = -15; // Stronger pop up effect for star power
enemies[j].isJumping = true;
enemies[j].canHarmPlayer = false;
LK.getSound('stomp').play();
// Create a sparkle effect
LK.effects.flashObject(enemies[j], 0xFFFF00, 300);
// Add points with star power bonus
var starEnemyPoints = 100;
score += starEnemyPoints;
scoreText.setText('Score: ' + score);
LK.setScore(score);
} else if (!player.isDead && player.isJumping && player.velocityY > 0 && player.y < enemies[j].y) {
// Player is falling and lands on enemy
enemies[j].velocityY = -10; // Pop up effect for enemy
player.velocityY = -15; // Bounce Mario upwards
LK.getSound('stomp').play(); // Play stomp sound
// Handle combo tracking - activate combo mode if not already active
if (!comboActive) {
comboActive = true;
comboCount = 0;
}
// Increment combo count
comboCount++;
// Calculate score with combo bonus
var enemyPoints = 50;
if (comboCount > 1) {
// Apply combo multiplier - each enemy in combo is worth more
enemyPoints = 50 * comboCount;
}
score += enemyPoints;
// Display flash text for combo count if more than 1
if (comboCount > 1) {
if (!comboDisplayObj) {
comboDisplayObj = game.addChild(new ComboDisplay());
comboDisplayObj.x = 2048 / 2;
comboDisplayObj.y = 2732 / 2 - 300;
}
comboDisplayObj.showCombo(comboCount, enemyPoints);
}
scoreText.setText('Score: ' + score);
LK.setScore(score);
enemies[j].isJumping = true;
enemies[j].canHarmPlayer = false; // Enemy can no longer harm player
} else if (enemies[j].canHarmPlayer !== false && !player.isInvincible) {
if (!player.isDead && enemies[j].canHarmPlayer !== false) {
LK.getSound('dead').play(); // Play dead sound
player.isDead = true;
game.playerDead = true;
player.velocityY = -10; // Pop up effect similar to enemy
player.isJumping = true;
LK.setTimeout(function () {
// Save final score before game over
LK.setScore(score);
LK.showGameOver();
}, 3000); // Delay game over by 3 seconds
}
}
} else if (player.x > enemies[j].x && !enemies[j].passed) {
enemies[j].passed = true;
}
if (enemies[j].x < -100) {
enemies.splice(j, 1);
}
}
for (var k = coinObjects.length - 1; k >= 0; k--) {
coinObjects[k].update();
if (player.intersects(coinObjects[k])) {
if (!coinObjects[k].collected) {
coinObjects[k].collected = true;
LK.getSound('Coin').play(); // Play coin sound
// Increase score when collecting coins
score += 10;
// Separate coin counter
coins++;
// Update storage for persistence
storage.coins = coins;
// Update displays
scoreText.setText('Score: ' + score);
coinText.setText('Coins: ' + coins);
LK.setScore(score);
coinObjects[k].destroy();
coinObjects.splice(k, 1);
}
}
}
// Update and check star power-ups
for (var s = stars.length - 1; s >= 0; s--) {
stars[s].update();
if (player.intersects(stars[s])) {
if (!stars[s].collected) {
stars[s].collected = true;
// Play coin sound for now (could use a special star sound)
LK.getSound('Coin').play();
// Activate star power
starPowerActive = true;
starPowerTimer = starPowerDuration;
player.isInvincible = true;
// Visual effects for star power
LK.effects.flashObject(player, 0xFFFF00, 500); // Yellow flash
// Change background tint for star power effect
if (background.sprites && background.sprites.length > 0) {
background.sprites[0].tint = 0xFFFFAA; // Slight yellow tint
}
if (background2.sprites && background2.sprites.length > 0) {
background2.sprites[0].tint = 0xFFFFAA; // Slight yellow tint
}
// Add extra points for star
score += 100;
scoreText.setText('Score: ' + score);
LK.setScore(score);
// Remove the star
stars[s].destroy();
stars.splice(s, 1);
}
} else if (stars[s].x < -100) {
stars[s].destroy();
stars.splice(s, 1);
}
}
// Update speed display and music speed
if (background && !game.playerDead) {
var speedMultiplier = (background.speed / 3).toFixed(1);
// Show star power status in speed text if active
if (starPowerActive) {
var starTimeLeft = Math.ceil(starPowerTimer / 60);
speedText.setText('STAR POWER: ' + starTimeLeft + 's');
speedText.style.fill = 0xFFFF00; // Yellow for star power
} else {
speedText.setText('Speed: ' + speedMultiplier + 'x');
speedText.style.fill = 0xFCE29F; // Return to normal color
}
// Update combo text in HUD
comboText.setText('Combo: ' + comboCount);
comboText.alpha = gameStarted ? 1 : 0;
// Adjust music playback rate based on game speed
var musicPlaybackRate = Math.min(1.5, 0.8 + background.speed / 3 * 0.2);
// Increase music speed during star power
if (starPowerActive) {
musicPlaybackRate = Math.min(2.0, musicPlaybackRate * 1.2);
}
setMusicPlaybackRate(musicPlaybackRate);
}
};
game.down = function (x, y, obj) {
if (showingUpgradeMenu) {
// Let the upgrade menu handle this event
return;
}
if (!gameStarted) {
// Let the main menu handle this event
return;
} else {
// Pass event to player to track swipes
player.down(x, y, obj);
// In-game tap makes player jump
player.jump();
}
};
game.up = function (x, y, obj) {
if (showingUpgradeMenu || !gameStarted) {
return;
}
// Pass touch up event to player for swipe detection
if (player) {
player.up(x, y, obj);
}
};
game.move = function (x, y, obj) {
if (showingUpgradeMenu || !gameStarted) {
return;
}
// Pass touch move event to player for swipe detection
if (player) {
player.move(x, y, obj);
}
};