/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
var centerZone = self.attachAsset('platformCenter', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.width = 400;
self.centerZoneWidth = 120;
self.isPerfectLanding = function (playerX) {
var platformCenterX = self.x;
var distance = Math.abs(playerX - platformCenterX);
return distance <= self.centerZoneWidth / 2;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.isJumping = false;
self.jumpForce = -35;
self.gravity = 1.2;
self.moveSpeed = 8;
self.baseJumpForce = -35;
self.jump = function (multiplier) {
if (multiplier === undefined) multiplier = 1;
self.velocityY = self.baseJumpForce * multiplier;
self.isJumping = true;
LK.getSound('jump').play();
};
self.update = function () {
// Apply horizontal movement
self.x += self.velocityX;
// Apply gravity and vertical movement
self.velocityY += self.gravity;
self.y += self.velocityY;
// Horizontal drag
self.velocityX *= 0.85;
// Keep player within screen bounds horizontally
if (self.x < 60) {
self.x = 60;
self.velocityX = 0;
} else if (self.x > 1988) {
self.x = 1988;
self.velocityX = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var player = game.addChild(new Player());
var platforms = [];
var camera = {
y: 0
};
var combo = 0;
var maxCombo = 0;
var platformSpacing = 300;
var nextPlatformY = -platformSpacing;
var difficultyLevel = 0;
var gameHeight = 2732;
var lastPlatformLanded = null;
var gameStarted = false;
// UI Elements
var scoreText = new Text2('Height: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var comboText = new Text2('', {
size: 50,
fill: 0xFFD700
});
comboText.anchor.set(0.5, 0);
comboText.y = 80;
LK.gui.top.addChild(comboText);
// Initialize player position
player.x = 1024;
player.y = gameHeight - 200;
// Create initial platforms
function createPlatform(y) {
var platform = new Platform();
// Progressive difficulty: platforms get smaller and more spread out
var minScale = Math.max(0.4, 1 - difficultyLevel * 0.1); // Minimum 40% scale
var maxScale = Math.max(0.7, 1 - difficultyLevel * 0.05); // Maximum scale decreases slower
var scale = minScale + Math.random() * (maxScale - minScale);
platform.scaleX = scale;
platform.width = 400 * scale; // Update logical width for collision
platform.centerZoneWidth = 120 * scale; // Scale center zone accordingly
// Increase horizontal spread as difficulty increases
var spreadFactor = 1 + difficultyLevel * 0.3;
var minX = 400 / spreadFactor;
var maxX = (2048 - 400) * spreadFactor;
maxX = Math.min(maxX, 1648); // Don't exceed screen bounds
minX = Math.max(minX, 400);
platform.x = Math.random() * (maxX - minX) + minX;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
}
// Create permanently wide starting ground platform
var startingPlatform = new Platform();
startingPlatform.x = 1024; // Center of screen
startingPlatform.y = gameHeight - 100;
// Make the starting platform span almost full screen width
startingPlatform.scaleX = 5; // Make it 5 times wider (2000px wide)
startingPlatform.width = 2000; // Update logical width for collision detection
startingPlatform.centerZoneWidth = 600; // Make center zone proportionally larger
platforms.push(startingPlatform);
game.addChild(startingPlatform);
// Create initial platforms above
for (var i = 1; i <= 8; i++) {
createPlatform(gameHeight - 100 - platformSpacing * i);
}
// Function to create special bonus platforms occasionally
function maybeCreateBonusPlatform(y) {
// 15% chance for bonus platform after certain height
if (Math.abs(y) > 2000 && Math.random() < 0.15) {
var bonusPlatform = new Platform();
bonusPlatform.x = Math.random() * (2048 - 600) + 300;
bonusPlatform.y = y - 150; // Place between regular platforms
bonusPlatform.scaleX = 0.6;
bonusPlatform.scaleY = 1.2; // Taller for visual distinction
bonusPlatform.width = 400 * 0.6;
bonusPlatform.centerZoneWidth = 300; // Larger perfect zone
bonusPlatform.tint = 0xFFD700; // Golden color
bonusPlatform.isBonusPlatform = true;
platforms.push(bonusPlatform);
game.addChild(bonusPlatform);
}
}
function updateCamera() {
var targetY = Math.max(0, player.y - gameHeight * 0.7);
camera.y += (targetY - camera.y) * 0.1;
game.y = -camera.y;
}
function generateNewPlatforms() {
while (nextPlatformY > camera.y - gameHeight) {
createPlatform(nextPlatformY);
maybeCreateBonusPlatform(nextPlatformY);
// Progressive difficulty: spacing increases and becomes more variable as player climbs higher
difficultyLevel = Math.floor(Math.abs(nextPlatformY) / 3000); // Difficulty increases every 3000 units
var baseSpacing = platformSpacing + difficultyLevel * 20; // Platforms get further apart
var variability = 100 + difficultyLevel * 30; // More random spacing variation
nextPlatformY -= baseSpacing + Math.random() * variability - variability / 2;
}
}
function removeOldPlatforms() {
for (var i = platforms.length - 1; i >= 0; i--) {
var platform = platforms[i];
if (platform.y > camera.y + gameHeight + 500) {
platform.destroy();
platforms.splice(i, 1);
}
}
}
function checkPlatformCollisions() {
if (player.velocityY <= 0) return;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
// Check if player is falling and intersects with platform
if (player.intersects(platform) && player.y < platform.y + 30 && player.y > platform.y - 60) {
// Landing on platform
player.y = platform.y - 60;
player.velocityY = 0;
player.isJumping = false;
// Check for perfect landing
if (platform.isPerfectLanding(player.x) && platform !== lastPlatformLanded) {
combo++;
maxCombo = Math.max(maxCombo, combo);
LK.getSound('perfectLanding').play();
// Bonus points for special platforms
if (platform.isBonusPlatform) {
LK.setScore(LK.getScore() + 1000 + combo * 200); // Large bonus for golden platforms
comboText.setText('BONUS! Combo: ' + combo + 'x');
} else {
// Regular perfect landing bonus
LK.setScore(LK.getScore() + 50 + combo * 25);
}
// Visual feedback for perfect landing
tween(platform, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
tween(platform, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
// Update combo display
comboText.setText('Combo: ' + combo + 'x');
if (combo > 1) {
tween(comboText, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150
});
tween(comboText, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
} else if (platform !== lastPlatformLanded) {
// Break combo on non-perfect landing
if (combo > 0) {
combo = 0;
comboText.setText('');
LK.getSound('comboBreak').play();
}
}
lastPlatformLanded = platform;
return true;
}
}
return false;
}
function handleInput(x, y) {
// Start game with first input if not started yet
if (!gameStarted && !player.isJumping) {
gameStarted = true;
player.jump();
}
var centerX = 1024;
var inputForce = 15;
if (x < centerX) {
player.velocityX = -inputForce;
} else {
player.velocityX = inputForce;
}
}
game.down = function (x, y, obj) {
handleInput(x, y);
};
game.move = function (x, y, obj) {
handleInput(x, y);
};
game.update = function () {
// Check platform collisions first to handle landings
var landedOnPlatform = checkPlatformCollisions();
// Continuous jumping: jump immediately after landing on any platform
if (gameStarted && landedOnPlatform && !player.isJumping) {
var jumpMultiplier = 1 + combo * 0.3;
player.jump(jumpMultiplier);
}
// Update camera
updateCamera();
// Generate new platforms
generateNewPlatforms();
// Remove old platforms
removeOldPlatforms();
// Update score based on height with higher multipliers for longer gameplay
var height = Math.max(0, Math.floor((gameHeight - player.y) / 2)); // Increased height scoring
var comboBonus = maxCombo * 500; // Increased combo bonus significantly
var perfectLandingBonus = combo > 0 ? combo * 50 : 0; // Additional bonus for current combo
LK.setScore(height + comboBonus + perfectLandingBonus);
scoreText.setText('Height: ' + height + ' | Score: ' + LK.getScore());
// Check game over
if (player.y > camera.y + gameHeight + 200) {
LK.showGameOver();
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
var centerZone = self.attachAsset('platformCenter', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.width = 400;
self.centerZoneWidth = 120;
self.isPerfectLanding = function (playerX) {
var platformCenterX = self.x;
var distance = Math.abs(playerX - platformCenterX);
return distance <= self.centerZoneWidth / 2;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.isJumping = false;
self.jumpForce = -35;
self.gravity = 1.2;
self.moveSpeed = 8;
self.baseJumpForce = -35;
self.jump = function (multiplier) {
if (multiplier === undefined) multiplier = 1;
self.velocityY = self.baseJumpForce * multiplier;
self.isJumping = true;
LK.getSound('jump').play();
};
self.update = function () {
// Apply horizontal movement
self.x += self.velocityX;
// Apply gravity and vertical movement
self.velocityY += self.gravity;
self.y += self.velocityY;
// Horizontal drag
self.velocityX *= 0.85;
// Keep player within screen bounds horizontally
if (self.x < 60) {
self.x = 60;
self.velocityX = 0;
} else if (self.x > 1988) {
self.x = 1988;
self.velocityX = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var player = game.addChild(new Player());
var platforms = [];
var camera = {
y: 0
};
var combo = 0;
var maxCombo = 0;
var platformSpacing = 300;
var nextPlatformY = -platformSpacing;
var difficultyLevel = 0;
var gameHeight = 2732;
var lastPlatformLanded = null;
var gameStarted = false;
// UI Elements
var scoreText = new Text2('Height: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var comboText = new Text2('', {
size: 50,
fill: 0xFFD700
});
comboText.anchor.set(0.5, 0);
comboText.y = 80;
LK.gui.top.addChild(comboText);
// Initialize player position
player.x = 1024;
player.y = gameHeight - 200;
// Create initial platforms
function createPlatform(y) {
var platform = new Platform();
// Progressive difficulty: platforms get smaller and more spread out
var minScale = Math.max(0.4, 1 - difficultyLevel * 0.1); // Minimum 40% scale
var maxScale = Math.max(0.7, 1 - difficultyLevel * 0.05); // Maximum scale decreases slower
var scale = minScale + Math.random() * (maxScale - minScale);
platform.scaleX = scale;
platform.width = 400 * scale; // Update logical width for collision
platform.centerZoneWidth = 120 * scale; // Scale center zone accordingly
// Increase horizontal spread as difficulty increases
var spreadFactor = 1 + difficultyLevel * 0.3;
var minX = 400 / spreadFactor;
var maxX = (2048 - 400) * spreadFactor;
maxX = Math.min(maxX, 1648); // Don't exceed screen bounds
minX = Math.max(minX, 400);
platform.x = Math.random() * (maxX - minX) + minX;
platform.y = y;
platforms.push(platform);
game.addChild(platform);
}
// Create permanently wide starting ground platform
var startingPlatform = new Platform();
startingPlatform.x = 1024; // Center of screen
startingPlatform.y = gameHeight - 100;
// Make the starting platform span almost full screen width
startingPlatform.scaleX = 5; // Make it 5 times wider (2000px wide)
startingPlatform.width = 2000; // Update logical width for collision detection
startingPlatform.centerZoneWidth = 600; // Make center zone proportionally larger
platforms.push(startingPlatform);
game.addChild(startingPlatform);
// Create initial platforms above
for (var i = 1; i <= 8; i++) {
createPlatform(gameHeight - 100 - platformSpacing * i);
}
// Function to create special bonus platforms occasionally
function maybeCreateBonusPlatform(y) {
// 15% chance for bonus platform after certain height
if (Math.abs(y) > 2000 && Math.random() < 0.15) {
var bonusPlatform = new Platform();
bonusPlatform.x = Math.random() * (2048 - 600) + 300;
bonusPlatform.y = y - 150; // Place between regular platforms
bonusPlatform.scaleX = 0.6;
bonusPlatform.scaleY = 1.2; // Taller for visual distinction
bonusPlatform.width = 400 * 0.6;
bonusPlatform.centerZoneWidth = 300; // Larger perfect zone
bonusPlatform.tint = 0xFFD700; // Golden color
bonusPlatform.isBonusPlatform = true;
platforms.push(bonusPlatform);
game.addChild(bonusPlatform);
}
}
function updateCamera() {
var targetY = Math.max(0, player.y - gameHeight * 0.7);
camera.y += (targetY - camera.y) * 0.1;
game.y = -camera.y;
}
function generateNewPlatforms() {
while (nextPlatformY > camera.y - gameHeight) {
createPlatform(nextPlatformY);
maybeCreateBonusPlatform(nextPlatformY);
// Progressive difficulty: spacing increases and becomes more variable as player climbs higher
difficultyLevel = Math.floor(Math.abs(nextPlatformY) / 3000); // Difficulty increases every 3000 units
var baseSpacing = platformSpacing + difficultyLevel * 20; // Platforms get further apart
var variability = 100 + difficultyLevel * 30; // More random spacing variation
nextPlatformY -= baseSpacing + Math.random() * variability - variability / 2;
}
}
function removeOldPlatforms() {
for (var i = platforms.length - 1; i >= 0; i--) {
var platform = platforms[i];
if (platform.y > camera.y + gameHeight + 500) {
platform.destroy();
platforms.splice(i, 1);
}
}
}
function checkPlatformCollisions() {
if (player.velocityY <= 0) return;
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
// Check if player is falling and intersects with platform
if (player.intersects(platform) && player.y < platform.y + 30 && player.y > platform.y - 60) {
// Landing on platform
player.y = platform.y - 60;
player.velocityY = 0;
player.isJumping = false;
// Check for perfect landing
if (platform.isPerfectLanding(player.x) && platform !== lastPlatformLanded) {
combo++;
maxCombo = Math.max(maxCombo, combo);
LK.getSound('perfectLanding').play();
// Bonus points for special platforms
if (platform.isBonusPlatform) {
LK.setScore(LK.getScore() + 1000 + combo * 200); // Large bonus for golden platforms
comboText.setText('BONUS! Combo: ' + combo + 'x');
} else {
// Regular perfect landing bonus
LK.setScore(LK.getScore() + 50 + combo * 25);
}
// Visual feedback for perfect landing
tween(platform, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut
});
tween(platform, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
// Update combo display
comboText.setText('Combo: ' + combo + 'x');
if (combo > 1) {
tween(comboText, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150
});
tween(comboText, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
} else if (platform !== lastPlatformLanded) {
// Break combo on non-perfect landing
if (combo > 0) {
combo = 0;
comboText.setText('');
LK.getSound('comboBreak').play();
}
}
lastPlatformLanded = platform;
return true;
}
}
return false;
}
function handleInput(x, y) {
// Start game with first input if not started yet
if (!gameStarted && !player.isJumping) {
gameStarted = true;
player.jump();
}
var centerX = 1024;
var inputForce = 15;
if (x < centerX) {
player.velocityX = -inputForce;
} else {
player.velocityX = inputForce;
}
}
game.down = function (x, y, obj) {
handleInput(x, y);
};
game.move = function (x, y, obj) {
handleInput(x, y);
};
game.update = function () {
// Check platform collisions first to handle landings
var landedOnPlatform = checkPlatformCollisions();
// Continuous jumping: jump immediately after landing on any platform
if (gameStarted && landedOnPlatform && !player.isJumping) {
var jumpMultiplier = 1 + combo * 0.3;
player.jump(jumpMultiplier);
}
// Update camera
updateCamera();
// Generate new platforms
generateNewPlatforms();
// Remove old platforms
removeOldPlatforms();
// Update score based on height with higher multipliers for longer gameplay
var height = Math.max(0, Math.floor((gameHeight - player.y) / 2)); // Increased height scoring
var comboBonus = maxCombo * 500; // Increased combo bonus significantly
var perfectLandingBonus = combo > 0 ? combo * 50 : 0; // Additional bonus for current combo
LK.setScore(height + comboBonus + perfectLandingBonus);
scoreText.setText('Height: ' + height + ' | Score: ' + LK.getScore());
// Check game over
if (player.y > camera.y + gameHeight + 200) {
LK.showGameOver();
}
};