Code edit (1 edits merged)
Please save this source code
User prompt
Update with: if (availablePlatforms.length > 0) { var platform = availablePlatforms[Math.floor(Math.random() * availablePlatforms.length)]; enemy.y = platform.y - 250; // Change to: enemy.y = platform.y - ENEMY_PLATFORM_OFFSET; enemy.currentPlatform = platform; } else { enemy.y = 2732 / 1.5; // Ground level }
User prompt
Update with: if (Math.abs(self.y - (platform.y - ENEMY_PLATFORM_OFFSET)) < 5) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - ENEMY_PLATFORM_OFFSET; // Changed from 250 self.isOnGround = true; self.velocityY = 0; return true; } }
Code edit (1 edits merged)
Please save this source code
User prompt
Update with: // In the game update function, replace the simple intersection check: if (player.intersects(enemies[j])) { // With a more precise hitbox check: var playerBounds = player.getBounds(); var enemyBounds = enemies[j].getBounds(); if (playerBounds.left < enemyBounds.right && playerBounds.right > enemyBounds.left && playerBounds.top < enemyBounds.bottom && playerBounds.bottom > enemyBounds.top) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } }
User prompt
Update player class with: // Add bounding box properties self.hitboxWidth = 100; // Smaller than the 600px animation frames self.hitboxHeight = 150; // Adjusted for player height // Add method to get actual collision bounds self.getBounds = function() { return { left: self.x - self.hitboxWidth/2, right: self.x + self.hitboxWidth/2, top: self.y - self.hitboxHeight/2, bottom: self.y + self.hitboxHeight/2 }; };
User prompt
Update enemy class with: // Add bounding box properties self.hitboxWidth = 80; // Smaller than the 150px sprite width self.hitboxHeight = 120; // Adjusted for goblin height // Update collision check method self.getBounds = function() { return { left: self.x - self.hitboxWidth/2, right: self.x + self.hitboxWidth/2, top: self.y - self.hitboxHeight/2, bottom: self.y + self.hitboxHeight/2 }; };
Code edit (4 edits merged)
Please save this source code
User prompt
Update with: if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy('goblin'); // or 'basic' for original enemy enemy.x = 2048; // Randomly choose a platform to spawn on var availablePlatforms = platforms.filter(p => p.x > 2048 - 100 && p.x < 2048 + 100); if (availablePlatforms.length > 0) { var platform = availablePlatforms[Math.floor(Math.random() * availablePlatforms.length)]; enemy.y = platform.y - 250; enemy.currentPlatform = platform; } else { enemy.y = 2732 / 1.5; // Ground level } enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; }
User prompt
Update with: var Enemy = Container.expand(function (type) { var self = Container.call(this); // Enemy properties self.type = type || 'basic'; self.speed = 5; self.isOnGround = true; self.velocityY = 0; self.currentPlatform = null; self.groundY = 2732 / 1.5; // Same as player ground Y // Animation properties for goblin self.runAnimation = []; self.runFrame = 0; self.animationSpeed = 0.08; self.animationCounter = 0; self.sprites = []; // Initialize based on enemy type if (self.type === 'goblin') { // Setup goblin animations self.runAnimation = ['goblinrun1', 'goblinrun2', 'goblinrun3', 'goblinrun4', 'goblinrun5', 'goblinrun6', 'goblinrun7', 'goblinrun8']; // Pre-attach all animation frames for (var i = 0; i < self.runAnimation.length; i++) { var sprite = self.attachAsset(self.runAnimation[i], { anchorX: 0.5, anchorY: 0.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } } else { // Basic enemy (original version) var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); } self.checkPlatformCollision = function() { var onAnyPlatform = false; var platformHalfWidth = 500; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; if (self.x >= leftEdge && self.x <= rightEdge) { if (Math.abs(self.y - (platform.y - 250)) < 5) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; self.isOnGround = true; self.velocityY = 0; return true; } } } return false; }; self.update = function () { // Move left self.x -= self.speed; // Handle platform-based movement if (self.currentPlatform) { var platformHalfWidth = 500; var stillOnPlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth; if (!stillOnPlatform) { self.isOnGround = false; self.currentPlatform = null; self.velocityY = 0.1; } } // Apply gravity if not on ground if (!self.isOnGround) { self.velocityY += 0.7; self.y += self.velocityY; // Check for platform collision while falling if (!self.checkPlatformCollision()) { // Check for ground collision if (self.y >= self.groundY) { self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; } } } // Handle animations for goblin if (self.type === 'goblin') { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Update animation self.animationCounter += self.animationSpeed; if (self.animationCounter >= 1) { self.animationCounter = 0; self.runFrame = (self.runFrame + 1) % self.runAnimation.length; } // Show current frame self.sprites[self.runFrame].alpha = 1; } // Destroy if off screen if (self.x < -50 || self.y > 2732) { self.destroy(); } }; });
Code edit (1 edits merged)
Please save this source code
User prompt
Update with: self.groundY = 2732 * 0.9; // Move ground much lower to allow falling from all platforms
User prompt
Update with: if (!foundAnotherPlatform) { self.isOnGround = false; self.currentPlatform = null; // Start falling with initial velocity - ALWAYS apply gravity regardless of height self.velocityY = 0.1; }
User prompt
Update as needed with: self.update = function() { // [Previous code remains unchanged] // IMPORTANT: Clear platform status at the beginning of each frame var wasOnPlatform = self.isOnGround && self.currentPlatform !== null; var onAnyPlatform = false; self.currentPlatform = null; // Check for ALL platform collisions from scratch every frame for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var platformHalfWidth = 500; // Consistent half-width // Check if player is directly above this platform if (self.x >= platform.x - platformHalfWidth && self.x <= platform.x + platformHalfWidth) { // If we're at the right height and not jumping up if (Math.abs(self.y - (platform.y - 250)) < 10 && self.velocityY >= 0) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; // Snap to platform self.isOnGround = true; self.velocityY = 0; self.isJumping = false; break; } } } // If we were on a platform but now aren't on any platform, start falling if (wasOnPlatform && !onAnyPlatform && !self.isJumping) { self.isOnGround = false; self.velocityY = 0.1; // Begin falling console.log("Falling off platform"); // Debug output } // Apply gravity if not on a platform and not actively jumping if (!self.isOnGround) { self.velocityY += 0.7; self.y += self.velocityY; // Ground collision check comes AFTER falling movement if (self.y >= self.groundY) { self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; self.currentPlatform = null; // Important: clear platform reference } }
User prompt
Update with: // Add this to the appropriate place in the update function // Ground collision check comes AFTER falling movement if (self.y >= self.groundY) { self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; self.currentPlatform = null; // Clear platform reference when on ground }
User prompt
Update with: if (self.currentPlatform) { // Use the constant platformWidth value var platformHalfWidth = 500; // half of platform width (1000/2) var stillOnPlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth; if (!stillOnPlatform) { var foundAnotherPlatform = false; for (var i = 0; i < platforms.length; i++) { var otherPlatform = platforms[i]; if (otherPlatform === self.currentPlatform) continue; var otherHalfWidth = 500; // Use correct half width if (self.x > otherPlatform.x - otherHalfWidth && self.x < otherPlatform.x + otherHalfWidth) { // We found another platform directly below player self.currentPlatform = otherPlatform; foundAnotherPlatform = true; break; } } // Only fall if we didn't find another platform if (!foundAnotherPlatform) { self.isOnGround = false; self.currentPlatform = null; // Start falling self.velocityY = 0.1; // CRITICAL FIX: Make sure player can fall below the ground if they're on a high platform if (self.y < self.groundY) { // Only apply gravity if above ground self.velocityY = 0.1; } } } }
User prompt
Update with: if (self.currentPlatform) { // FIXED: Use the correct platform width constant var platformHalfWidth = 500; // half of platform width (1000/2) var stillOnPlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth;
User prompt
Update as needed with: self.update = function() { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPORTANT: Platform collision check - runs EVERY frame var onAnyPlatform = false; var platformHalfWidth = 500; // First, check platform collisions for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; // Check if player is within horizontal bounds of platform if (self.x >= leftEdge && self.x <= rightEdge) { // If we're at platform height and not jumping if (Math.abs(self.y - (platform.y - 250)) < 5 && !self.isJumping) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; self.isOnGround = true; self.velocityY = 0; break; } } } // Handle falling state if (!onAnyPlatform && !self.isJumping) { self.isOnGround = false; self.currentPlatform = null; // Apply gravity if (self.velocityY === 0) { self.velocityY = 0.1; } self.velocityY += 0.7; self.y += self.velocityY; // Ground collision check comes AFTER falling movement if (self.y >= self.groundY) { self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; } }
Code edit (1 edits merged)
Please save this source code
User prompt
Update with: self.update = function() { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPORTANT: Platform collision check - runs EVERY frame var onAnyPlatform = false; var platformHalfWidth = 500; // half of platform width (1000/2) var closestPlatformBelow = null; var closestPlatformDistance = Infinity; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; // Check if player is within horizontal bounds of platform if (self.x >= leftEdge && self.x <= rightEdge) { // Calculate vertical distance to platform (platform.y - 250 is the standing height) var platformTopY = platform.y - 250; var distanceToPlatform = platformTopY - self.y; // Only consider platforms below or at the player's feet if (distanceToPlatform >= -5 && distanceToPlatform < closestPlatformDistance) { closestPlatformBelow = platform; closestPlatformDistance = distanceToPlatform; } } } // Now handle the closest valid platform (if any) if (closestPlatformBelow && closestPlatformDistance < 5 && !self.isJumping) { onAnyPlatform = true; self.currentPlatform = closestPlatformBelow; self.y = closestPlatformBelow.y - 250; // Snap to exact platform height self.isOnGround = true; self.velocityY = 0; } // If not on any platform and not at ground level, start falling if (!onAnyPlatform && !self.isJumping) { if (self.y < self.groundY) { self.isOnGround = false; self.currentPlatform = null; // Start falling if (self.velocityY === 0) { self.velocityY = 0.1; // Initial fall velocity } self.velocityY += 0.7; // Apply gravity self.y += self.velocityY; } else if (self.y >= self.groundY) { // Landing on ground self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; } }
User prompt
Update as needed with: self.update = function() { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPORTANT: Platform collision check - runs EVERY frame var onAnyPlatform = false; var platformHalfWidth = 500; // half of platform width (1000/2) for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; // Check if player is within horizontal bounds of platform if (self.x >= leftEdge && self.x <= rightEdge) { // If we're at platform height and not jumping if (Math.abs(self.y - (platform.y - 250)) < 5 && !self.isJumping) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; // Snap to exact platform height self.isOnGround = true; self.velocityY = 0; break; } } } // If not on any platform and not at ground level, start falling if (!onAnyPlatform && !self.isJumping) { if (self.y < self.groundY) { self.isOnGround = false; self.currentPlatform = null; // Start falling if (self.velocityY === 0) { self.velocityY = 0.1; // Initial fall velocity } self.velocityY += 0.7; // Apply gravity self.y += self.velocityY; } else if (self.y >= self.groundY) { // Landing on ground self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; } }
User prompt
Update as needed with: self.update = function () { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPORTANT: Platform fall detection - must happen EVERY FRAME // Only check for falling if we're not already in the air if (self.isOnGround || self.currentPlatform) { var stillOnPlatform = false; // Explicitly check every platform's current position for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; // Calculate exact platform boundaries var leftEdge = platform.x - (platform.width / 2); var rightEdge = platform.x + (platform.width / 2); // Log positions for debugging (remove in final version) // console.log("Player x:", self.x, "Platform:", i, "left:", leftEdge, "right:", rightEdge); // Check if player's center is within platform horizontal bounds if (self.x >= leftEdge && self.x <= rightEdge) { stillOnPlatform = true; self.currentPlatform = platform; break; } } // If not above any platform and not at ground level, start falling if (!stillOnPlatform) { if (self.y < self.groundY) { // Player is above ground level but not on platform - fall self.isOnGround = false; self.currentPlatform = null; self.velocityY = 0.1; // Start falling with small initial velocity } else if (self.y >= self.groundY) { // Player is at ground level self.isOnGround = true; self.currentPlatform = null; } } } // Apply gravity if not on ground and not actively jumping if (!self.isOnGround && !self.isJumping) { self.velocityY += 0.7; self.y += self.velocityY; // Show falling animation (using jump3) var jumpOffset = self.runAnimation.length; self.sprites[jumpOffset + 2].alpha = 1; // jump3 // Check for platform collisions while falling self.checkPlatformCollision(); } // Check if player has fallen off the bottom of the screen if (self.y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // The rest of the update function remains the same... // Handle jumping physics and animation if (self.isJumping) { // Jumping code remains unchanged } else if (self.isOnGround) { // Running animation code remains unchanged self.animationCounter += self.animationSpeed; if (self.animationCounter >= 1) { self.animationCounter = 0; // Update to next frame self.runFrame = (self.runFrame + 1) % self.runAnimation.length; } // Show current run frame self.sprites[self.runFrame].alpha = 1; } };
User prompt
Update with: self.update = function () { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPROVED PLATFORM DETECTION: Always check if player should fall if (self.isOnGround && !self.isJumping) { // Start with assumption that player isn't above any platform var foundPlatform = false; // Check all platforms to see if player is above any of them for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var platformHalfWidth = platform.width / 2; if (self.x > platform.x - platformHalfWidth && self.x < platform.x + platformHalfWidth) { // Player is above this platform foundPlatform = true; self.currentPlatform = platform; break; } } // If not above any platform and not at ground level, start falling if (!foundPlatform && self.y < self.groundY) { self.isOnGround = false; self.currentPlatform = null; // Start falling self.velocityY = 0.1; } } // Apply gravity if not on a platform and not actively jumping if (!self.isOnGround && !self.isJumping) { self.velocityY += 0.7; self.y += self.velocityY; // Show falling animation (using jump3) var jumpOffset = self.runAnimation.length; self.sprites[jumpOffset + 2].alpha = 1; // jump3 // Check for platform collisions while falling self.checkPlatformCollision(); }
User prompt
Update with: self.update = function () { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // NEW CODE: Always check if the player is above a platform when on ground if (self.isOnGround && !self.isJumping) { var isAbovePlatform = false; // If we have a current platform, check if we're still above it if (self.currentPlatform) { var platformHalfWidth = self.currentPlatform.width / 2; isAbovePlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth; // If not above current platform, check all other platforms if (!isAbovePlatform) { for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; if (platform === self.currentPlatform) continue; var halfWidth = platform.width / 2; if (self.x > platform.x - halfWidth && self.x < platform.x + halfWidth) { self.currentPlatform = platform; isAbovePlatform = true; break; } } } } else { // No current platform but we're on ground - check all platforms for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var halfWidth = platform.width / 2; if (self.x > platform.x - halfWidth && self.x < platform.x + halfWidth) { self.currentPlatform = platform; isAbovePlatform = true; break; } } } // If not above any platform and not on the original ground level, start falling if (!isAbovePlatform && self.y < self.groundY) { self.isOnGround = false; self.currentPlatform = null; self.velocityY = 0.1; // Start falling } }
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ var Enemy = Container.expand(function (type) { var self = Container.call(this); // Enemy properties self.type = type || 'basic'; self.speed = 5; self.isOnGround = true; self.velocityY = 0; self.currentPlatform = null; self.groundY = 2732 / 1.5; // Same as player ground Y // Animation properties for goblin self.runAnimation = []; self.runFrame = 0; self.animationSpeed = 0.08; self.animationCounter = 0; self.sprites = []; // Initialize based on enemy type if (self.type === 'goblin') { // Setup goblin animations self.runAnimation = ['goblinrun1', 'goblinrun2', 'goblinrun3', 'goblinrun4', 'goblinrun5', 'goblinrun6', 'goblinrun7', 'goblinrun8']; // Pre-attach all animation frames for (var i = 0; i < self.runAnimation.length; i++) { var sprite = self.attachAsset(self.runAnimation[i], { anchorX: 0.5, anchorY: 0.5 }); sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } } else { // Basic enemy (original version) var enemyGraphics = self.attachAsset('enemy', { anchorX: 0.5, anchorY: 0.5 }); } self.checkPlatformCollision = function () { var onAnyPlatform = false; var platformHalfWidth = 500; for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; if (self.x >= leftEdge && self.x <= rightEdge) { if (Math.abs(self.y - (platform.y - 250)) < 5) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; self.isOnGround = true; self.velocityY = 0; return true; } } } return false; }; self.update = function () { // Move left self.x -= self.speed; // Handle platform-based movement if (self.currentPlatform) { var platformHalfWidth = 500; var stillOnPlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth; if (!stillOnPlatform) { self.isOnGround = false; self.currentPlatform = null; self.velocityY = 0.1; } } // Apply gravity if not on ground if (!self.isOnGround) { self.velocityY += 0.7; self.y += self.velocityY; // Check for platform collision while falling if (!self.checkPlatformCollision()) { // Check for ground collision if (self.y >= self.groundY) { self.y = self.groundY; self.isOnGround = true; self.velocityY = 0; } } } // Handle animations for goblin if (self.type === 'goblin') { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // Update animation self.animationCounter += self.animationSpeed; if (self.animationCounter >= 1) { self.animationCounter = 0; self.runFrame = (self.runFrame + 1) % self.runAnimation.length; } // Show current frame self.sprites[self.runFrame].alpha = 1; } // Destroy if off screen if (self.x < -50 || self.y > 2732) { self.destroy(); } }; }); var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.speed = 5; self.passed = false; self.update = function () { self.x -= self.speed; if (self.x < -500) { // Increased value to ensure platforms are fully off-screen self.destroy(); } }; }); //<Assets used in the game will automatically appear here> var Player = Container.expand(function () { var self = Container.call(this); // Animation properties self.runAnimation = ['playerrun1', 'playerrun2', 'playerrun3', 'playerrun4', 'playerrun5', 'playerrun6']; self.jumpAnimation = ['playerjump1', 'playerjump2', 'playerjump3']; self.runFrame = 0; self.animationSpeed = 0.08; self.animationCounter = 0; self.sprites = []; self.groundY = 2732 * 0.9; // Move ground much lower to allow falling from all platforms // Platform collision properties self.isOnGround = true; self.currentPlatform = null; // Pre-attach all animation frames but make only the first one visible // First add run animation sprites for (var i = 0; i < self.runAnimation.length; i++) { var sprite = self.attachAsset(self.runAnimation[i], { anchorX: 0.5, anchorY: 0.5 }); // Set all frames except the first to be invisible sprite.alpha = i === 0 ? 1 : 0; self.sprites.push(sprite); } // Then add jump animation sprites for (var i = 0; i < self.jumpAnimation.length; i++) { var sprite = self.attachAsset(self.jumpAnimation[i], { anchorX: 0.5, anchorY: 0.5 }); // Set all jump frames to invisible initially sprite.alpha = 0; self.sprites.push(sprite); } // Movement properties self.speed = 5; self.jumpHeight = 40; // Keeping the original jump height self.isJumping = false; self.velocityY = 0; self.jumpState = "none"; // Added to track jump animation phases self.jumpStartTime = 0; self.update = function () { // Hide all sprites first for (var i = 0; i < self.sprites.length; i++) { self.sprites[i].alpha = 0; } // IMPORTANT: Platform collision check - runs EVERY frame var onAnyPlatform = false; var platformHalfWidth = 500; // half of platform width (1000/2) // First, check platform collisions for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var leftEdge = platform.x - platformHalfWidth; var rightEdge = platform.x + platformHalfWidth; // Check if player is within horizontal bounds of platform if (self.x >= leftEdge && self.x <= rightEdge) { // If we're at platform height and not jumping if (Math.abs(self.y - (platform.y - 250)) < 5 && !self.isJumping) { onAnyPlatform = true; self.currentPlatform = platform; self.y = platform.y - 250; self.isOnGround = true; self.velocityY = 0; break; } } } // Handle falling state if (!onAnyPlatform && !self.isJumping) { self.isOnGround = false; self.currentPlatform = null; // Apply gravity if (self.velocityY === 0) { self.velocityY = 0.1; } self.velocityY += 0.1; self.y += self.velocityY; // Ground collision check comes AFTER falling movement if (self.y >= self.groundY) { // Reached the bottom of the screen - game over LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } } // Apply gravity if not on a platform and not actively jumping if (!self.isOnGround && !self.isJumping) { self.velocityY += 0.7; self.y += self.velocityY; // Show falling animation (using jump3) var jumpOffset = self.runAnimation.length; self.sprites[jumpOffset + 2].alpha = 1; // jump3 // Check for platform collisions while falling self.checkPlatformCollision(); } // Check if player has fallen off the bottom of the screen if (self.y > 2732) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } // Handle jumping physics and animation if (self.isJumping) { self.y += self.velocityY; self.velocityY += 0.7; // Get jump frame index offset var jumpOffset = self.runAnimation.length; // Determine jump animation based on velocity and time var currentTime = Date.now(); if (currentTime - self.jumpStartTime < 100) { // Brief initial jump1 phase (first 100ms) self.sprites[jumpOffset + 0].alpha = 1; // jump1 } else if (self.velocityY < 0) { // Going up - show jump2 self.sprites[jumpOffset + 1].alpha = 1; // jump2 } else if (self.velocityY > 0) { // Going down - show jump3 self.sprites[jumpOffset + 2].alpha = 1; // jump3 // Check for landing on platforms while falling during a jump self.checkPlatformCollision(); } // End jump if hitting the original ground (for backward compatibility) if (self.y >= self.groundY && !self.currentPlatform) { self.y = self.groundY; self.isJumping = false; self.velocityY = 0; self.jumpState = "none"; self.isOnGround = true; } } else if (self.isOnGround) { // Run animation when on a platform or ground self.animationCounter += self.animationSpeed; if (self.animationCounter >= 1) { self.animationCounter = 0; // Update to next frame self.runFrame = (self.runFrame + 1) % self.runAnimation.length; } // Show current run frame self.sprites[self.runFrame].alpha = 1; } // If on a platform, check if we're still above it if (self.currentPlatform) { // Use the constant platformWidth value var platformHalfWidth = platformWidth / 2; // Use platformWidth constant var stillOnPlatform = self.x > self.currentPlatform.x - platformHalfWidth && self.x < self.currentPlatform.x + platformHalfWidth; if (!stillOnPlatform) { var foundAnotherPlatform = false; for (var i = 0; i < platforms.length; i++) { var otherPlatform = platforms[i]; if (otherPlatform === self.currentPlatform) { continue; } var otherHalfWidth = platformWidth / 2; // Use platformWidth constant if (self.x > otherPlatform.x - otherHalfWidth && self.x < otherPlatform.x + otherHalfWidth) { // We found another platform directly below player self.currentPlatform = otherPlatform; foundAnotherPlatform = true; break; } } // Only fall if we didn't find another platform if (!foundAnotherPlatform) { self.isOnGround = false; self.currentPlatform = null; // Start falling with initial velocity - ALWAYS apply gravity regardless of height self.velocityY = 0.1; } } } }; self.jump = function () { if (self.isOnGround) { self.isJumping = true; self.isOnGround = false; self.velocityY = -self.jumpHeight; self.jumpState = "start"; self.jumpStartTime = Date.now(); self.currentPlatform = null; } else if (self.isJumping && self.velocityY < 10) { // Allow for a small double-jump to reach higher platforms // Only if not falling too fast self.velocityY = -self.jumpHeight * 0.7; self.jumpStartTime = Date.now(); } }; self.checkPlatformCollision = function () { for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; var platformHalfWidth = platform.width / 2; // The offset should match exactly how the player aligns with the lower platform initially var playerPlatformOffset = 250; // This is the exact offset between player.y and lowPlatformHeight // Check if player is above the platform and falling if (self.velocityY > 0 && // Must be falling down self.y < platform.y - playerPlatformOffset && self.y + self.velocityY >= platform.y - playerPlatformOffset && self.x > platform.x - platformHalfWidth && self.x < platform.x + platformHalfWidth) { // Land on the platform with the exact same positioning as on the low platform self.y = platform.y - playerPlatformOffset; self.velocityY = 0; self.isJumping = false; self.isOnGround = true; self.currentPlatform = platform; return; } } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // Black background }); /**** * Game Code ****/ var GAME_WIDTH = 2048; var platforms = []; var platformWidth = 1000; // Define platform width based on asset size var platformSpawnInterval = 60; var platformSpawnCounter = 0; var platformOverlap = 50; var platformSpeed = 5; // Define platform speed globally var platformSpawnInterval = 190; // = (1000 - 50) / 5 = 190 // Define the two fixed platform heights var lowPlatformHeight = 2732 / 1.5 + 250; // Regular height (player.y + 250) var highPlatformHeight = lowPlatformHeight - 600; // High platform (600 pixels higher) var minPlatformsInSequence = 5; // Minimum platforms in a sequence var maxPlatformsInSequence = 10; // Maximum platforms in a sequence var platformsUntilNextChange = 5; // Initial longer ground sequence var currentPlatformHeight = lowPlatformHeight; var lastPlatformHeight = lowPlatformHeight; // Simple toggle for alternating platform heights var useHighPlatform = false; var platformGap = 200; // Gap between platforms var lastPlatformX = 0; // Track the last platform position //<Assets used in the game will automatically appear here> var background = game.addChild(LK.getAsset('background', { anchorX: 0, anchorY: 0, alpha: 0 })); background.x = 0; background.y = 0; // Initialize player var player = game.addChild(new Player()); player.x = 2048 / 4.5; player.y = 2732 / 1.5; // Initialize enemies var enemies = []; var enemySpawnInterval = 100; var enemySpawnCounter = 0; // Create a new Text2 object to display the score var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); // Add the score text to the game GUI at the top center of the screen LK.gui.top.addChild(scoreText); scoreText.x = 2048 / 2; scoreText.y = 0; // Initialize the game with starting platforms function initializeGame() { // Create initial platforms at the low level for (var i = 0; i < 5; i++) { var platform = new Platform(); if (i === 0) { // First platform centered on player platform.x = player.x; } else { // Position with slight overlap platform.x = lastPlatformX + platformWidth - platformOverlap; } platform.y = lowPlatformHeight; platforms.push(platform); game.addChild(platform); lastPlatformX = platform.x; } lastPlatformHeight = lowPlatformHeight; player.isOnGround = true; player.currentPlatform = platforms[0]; } initializeGame(); // Handle game updates game.update = function () { player.update(); // Check if we need to spawn a new sequence of platforms var lastPlatform = platforms[platforms.length - 1]; if (lastPlatform && lastPlatform.x < GAME_WIDTH + 500) { // Spawn further off-screen to prevent pop-in // Time to spawn a new sequence if (platformsUntilNextChange <= 0) { // Switch height currentPlatformHeight = currentPlatformHeight === lowPlatformHeight ? highPlatformHeight : lowPlatformHeight; // Generate new random sequence length platformsUntilNextChange = Math.floor(Math.random() * (maxPlatformsInSequence - minPlatformsInSequence + 1)) + minPlatformsInSequence; // Make ground sequences longer if (currentPlatformHeight === lowPlatformHeight) { platformsUntilNextChange += 5; } } // Spawn a single platform in the sequence var platform = new Platform(); platform.x = lastPlatform.x + (platformWidth - platformOverlap); platform.y = currentPlatformHeight; platforms.push(platform); game.addChild(platform); // Decrement the counter for each platform added platformsUntilNextChange--; } // Update platforms for (var i = platforms.length - 1; i >= 0; i--) { platforms[i].update(); // Remove platforms that are destroyed if (platforms[i].destroyed) { platforms.splice(i, 1); } } // Enemy handling (keep your existing enemy code) enemySpawnCounter++; if (enemySpawnCounter >= enemySpawnInterval) { var enemy = new Enemy('goblin'); // or 'basic' for original enemy enemy.x = 2048; // Randomly choose a platform to spawn on var availablePlatforms = platforms.filter(function (p) { return p.x > 2048 - 100 && p.x < 2048 + 100; }); if (availablePlatforms.length > 0) { var platform = availablePlatforms[Math.floor(Math.random() * availablePlatforms.length)]; enemy.y = platform.y - 250; enemy.currentPlatform = platform; } else { enemy.y = 2732 / 1.5; // Ground level } enemies.push(enemy); game.addChild(enemy); enemySpawnInterval = Math.floor(Math.random() * 150) + 50; enemySpawnCounter = 0; } // Update enemies for (var j = enemies.length - 1; j >= 0; j--) { enemies[j].update(); if (player.intersects(enemies[j])) { LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); } else if (player.x > enemies[j].x && !enemies[j].passed) { enemies[j].passed = true; LK.setScore(LK.getScore() + 1); scoreText.setText(LK.getScore()); } } }; // Handle player jump game.down = function (x, y, obj) { player.jump(); };
===================================================================
--- original.js
+++ change.js
@@ -439,9 +439,9 @@
platforms.splice(i, 1);
}
}
// Enemy handling (keep your existing enemy code)
- //enemySpawnCounter++;
+ enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
var enemy = new Enemy('goblin'); // or 'basic' for original enemy
enemy.x = 2048;
// Randomly choose a platform to spawn on
2D Single Monster. In-Game asset. 2d. Blank background. High contrast. No shadows..
A gold coin. 8 bit pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
Dark and moody dungeon background. Infinite repeatable texture. 8 bit pixel art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A ruby. Pixel art.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A wooden arrow with white feathers and a steel arrow head. Horizontal. Pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
backgroundmusic1
Music
playerjump
Sound effect
swordslash
Sound effect
jarbreak
Sound effect
enemyhit
Sound effect
eyeballhit
Sound effect
coincollect
Sound effect
woodbreak
Sound effect
coinbounce
Sound effect
potion
Sound effect
playerouch
Sound effect
bowfiring
Sound effect
arrowfire
Sound effect
arrowpickup
Sound effect
gameover
Sound effect