/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -1.5;
self.initialX = 0;
self.update = function () {
self.x += self.speed;
// Reset cloud position when it goes off screen
if (self.x < cameraX - 200) {
self.x = cameraX + 2248 + Math.random() * 500;
self.y = 500 + Math.random() * 800;
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.bobOffset = 0;
self.initialY = 0;
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.setScore(LK.getScore() + 50);
LK.getSound('coin_collect').play();
tween(self, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
self.update = function () {
if (!self.collected) {
// Bobbing animation
self.bobOffset += 0.1;
self.y = self.initialY + Math.sin(self.bobOffset) * 10;
coinGraphics.rotation += 0.05;
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = -2;
self.direction = -1;
self.isDefeated = false;
self.defeat = function () {
if (!self.isDefeated) {
self.isDefeated = true;
LK.setScore(LK.getScore() + 100);
LK.getSound('enemy_defeat').play();
tween(self, {
scaleY: 0.2,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
self.update = function () {
if (!self.isDefeated) {
self.x += self.speed * self.direction;
// Simple AI - turn around at edges or walls
if (self.x < cameraX - 200 || self.x > cameraX + 2248) {
self.direction *= -1;
}
}
};
return self;
});
var Flag = Container.expand(function () {
var self = Container.call(this);
var flagGraphics = self.attachAsset('flag', {
anchorX: 0.5,
anchorY: 1.0
});
self.reached = false;
self.reach = function () {
if (!self.reached) {
self.reached = true;
LK.setScore(LK.getScore() + 1000);
LK.effects.flashScreen(0x00ff00, 1000);
// Check if this is the final level
if (currentLevel >= maxLevels) {
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
} else {
// Advance to next level
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.isGrounded = false;
self.isJumping = false;
self.jumpPower = -40; // Increased jump power for longer distance
self.highJumpPower = -60; // Increased high jump power for longer distance
self.gravity = 1.2;
self.speed = 4;
self.lives = 3;
self.isInvulnerable = false;
self.invulnerabilityTime = 0;
self.tapCount = 0;
self.lastTapTime = 0;
self.doubleTapWindow = 300; // 300ms window for double tap
self.jump = function () {
if (self.isGrounded && !self.isJumping) {
var currentTime = Date.now();
// Check if this is a double tap
if (currentTime - self.lastTapTime < self.doubleTapWindow) {
// Double tap - high jump
self.velocityY = self.highJumpPower;
self.tapCount = 0;
} else {
// Single tap - normal jump
self.velocityY = self.jumpPower;
self.tapCount = 1;
}
self.lastTapTime = currentTime;
self.isJumping = true;
self.isGrounded = false;
LK.getSound('jump').play();
}
};
self.takeDamage = function () {
if (!self.isInvulnerable) {
self.lives--;
self.isInvulnerable = true;
self.invulnerabilityTime = 120; // 2 seconds at 60fps
LK.effects.flashObject(self, 0xff0000, 500);
if (self.lives <= 0) {
LK.showGameOver();
}
}
};
self.update = function () {
// Handle invulnerability timer
if (self.isInvulnerable) {
self.invulnerabilityTime--;
if (self.invulnerabilityTime <= 0) {
self.isInvulnerable = false;
}
}
// Apply gravity
self.velocityY += self.gravity;
// Move player
self.x += self.speed;
self.y += self.velocityY;
// Ground collision (basic ground level)
if (self.y >= groundLevel) {
self.y = groundLevel;
self.velocityY = 0;
self.isGrounded = true;
self.isJumping = false;
}
// Platform collision
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.intersects(platform)) {
var playerBottom = self.y;
var playerTop = self.y - 80; // Player height is 80
var playerLeft = self.x - 40; // Player width is 80, so half is 40
var playerRight = self.x + 40;
var platformTop = platform.y - platform.height / 2;
var platformBottom = platform.y + platform.height / 2;
var platformLeft = platform.x - platform.width / 2;
var platformRight = platform.x + platform.width / 2;
// Landing on top of platform
if (self.velocityY > 0 && playerBottom > platformTop - 20 && playerBottom < platformTop + 20) {
self.y = platformTop;
self.velocityY = 0;
self.isGrounded = true;
self.isJumping = false;
}
// Hitting platform from below
else if (self.velocityY < 0 && playerTop < platformBottom + 20 && playerTop > platformBottom - 20) {
self.y = platformBottom + 80; // Push player down
self.velocityY = 0;
}
// Hitting platform from left side
else if (playerRight > platformLeft && playerLeft < platformLeft && self.x < platform.x) {
self.x = platformLeft - 40; // Push player to the left
}
// Hitting platform from right side
else if (playerLeft < platformRight && playerRight > platformRight && self.x > platform.x) {
self.x = platformRight + 40; // Push player to the right
}
}
}
// Death by falling
if (self.y > 2732 + 100) {
self.takeDamage();
self.x = cameraX + 100;
self.y = groundLevel - 200;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var player;
var enemies = [];
var coins = [];
var platforms = [];
var clouds = [];
var flag;
var cameraX = 0;
var groundLevel = 2600;
var levelWidth = 8000;
var currentLevel = 1;
var maxLevels = 11;
// UI elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesText.anchor.set(1, 0);
LK.gui.topRight.addChild(livesText);
var levelText = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
// Create ground platforms
for (var i = 0; i < levelWidth / 200; i++) {
var groundPiece = LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 1.0
});
groundPiece.x = i * 200 + 100;
groundPiece.y = groundLevel + 30;
game.addChild(groundPiece);
}
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = groundLevel;
// Create platforms - fill entire first section with platforms
var platformPositions = [];
var startX = 600;
var endX = 7800;
var platformSpacing = 380; // Slightly increased spacing between platforms
var yVariation = 50; // Vertical position variation
var baseY = 2200;
// Generate platforms throughout the entire first section
for (var x = startX; x <= endX; x += platformSpacing) {
platformPositions.push({
x: x + (Math.random() - 0.5) * 60,
// Small random horizontal offset
y: baseY + (Math.random() - 0.5) * yVariation // Small random vertical offset
});
}
for (var i = 0; i < platformPositions.length; i++) {
var platform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
platform.x = platformPositions[i].x;
platform.y = platformPositions[i].y;
platforms.push(platform);
game.addChild(platform);
}
// Create enemies
var enemyPositions = [{
x: 1000,
y: groundLevel
}, {
x: 1600,
y: groundLevel
}, {
x: 2200,
y: groundLevel
}, {
x: 2800,
y: groundLevel
}, {
x: 3400,
y: groundLevel
}, {
x: 4000,
y: groundLevel
}, {
x: 4600,
y: groundLevel
}, {
x: 5200,
y: groundLevel
}, {
x: 5800,
y: groundLevel
}];
for (var i = 0; i < enemyPositions.length; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = enemyPositions[i].x;
enemy.y = enemyPositions[i].y;
enemies.push(enemy);
}
// Create coins
var coinPositions = [{
x: 900,
y: 2100
}, {
x: 1500,
y: 2050
}, {
x: 2100,
y: 2080
}, {
x: 2700,
y: 2120
}, {
x: 3300,
y: 2060
}, {
x: 3900,
y: 2100
}, {
x: 4500,
y: 2070
}, {
x: 5100,
y: 2110
}, {
x: 5700,
y: 2090
}, {
x: 6300,
y: 2080
}, {
x: 6900,
y: 2100
}, {
x: 7500,
y: 2150
}, {
x: 1200,
y: 2120
}, {
x: 1800,
y: 2050
}, {
x: 2400,
y: 2180
}, {
x: 3000,
y: 2090
}, {
x: 3600,
y: 2160
}, {
x: 4200,
y: 2120
}, {
x: 4800,
y: 2180
}, {
x: 5400,
y: 2050
}, {
x: 6000,
y: 2140
}, {
x: 6600,
y: 2110
}, {
x: 7200,
y: 2170
}];
for (var i = 0; i < coinPositions.length; i++) {
var coin = game.addChild(new Coin());
coin.x = coinPositions[i].x;
coin.y = coinPositions[i].y;
coin.initialY = coin.y;
coins.push(coin);
}
// Create flag at the end
flag = game.addChild(new Flag());
flag.x = levelWidth - 200;
flag.y = groundLevel;
// Create moving clouds
for (var i = 0; i < 8; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = Math.random() * levelWidth;
cloud.y = 300 + Math.random() * 1000;
cloud.initialX = cloud.x;
clouds.push(cloud);
// Add random tween movement for more dynamic clouds
tween(cloud, {
y: cloud.y + (Math.random() - 0.5) * 200
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeInOut,
onFinish: function () {
// Start a new random movement
tween(this, {
y: this.y + (Math.random() - 0.5) * 300
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeInOut
});
}.bind(cloud)
});
}
// Touch controls
game.down = function (x, y, obj) {
player.jump();
};
// Camera following
function updateCamera() {
// Camera follows player with some offset
var targetCameraX = player.x - 300;
// Clamp camera to level bounds
targetCameraX = Math.max(0, Math.min(targetCameraX, levelWidth - 2048));
// Smooth camera movement
cameraX += (targetCameraX - cameraX) * 0.1;
// Apply camera offset to all game objects
game.x = -cameraX;
}
// Game update loop
game.update = function () {
// Update camera
updateCamera();
// Update UI
scoreText.setText('Score: ' + LK.getScore());
livesText.setText('Lives: ' + player.lives);
levelText.setText('Level: ' + currentLevel);
// Check player-enemy collisions
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (!enemy.isDefeated && player.intersects(enemy) && !player.isInvulnerable) {
// Check if player is actually falling onto enemy (not standing on platform above)
var playerOnPlatform = false;
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
var playerBottom = player.y;
var platformTop = platform.y - platform.height / 2;
// Check if player is standing on a platform and enemy is below
if (Math.abs(playerBottom - platformTop) < 50 && Math.abs(player.x - platform.x) < platform.width / 2 && enemy.y > platform.y) {
playerOnPlatform = true;
break;
}
}
// Check if player is jumping on enemy (and not on platform above)
if (player.velocityY > 0 && player.y < enemy.y - 20 && !playerOnPlatform) {
// Player stomps enemy
enemy.defeat();
enemies.splice(i, 1);
player.velocityY = -15; // Small bounce
} else {
// Player takes damage
player.takeDamage();
}
}
}
// Check player-coin collisions
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.collected && player.intersects(coin)) {
coin.collect();
coins.splice(i, 1);
}
}
// Check player-flag collision
if (!flag.reached && player.intersects(flag)) {
flag.reach();
}
};
// Function to advance to next level
function nextLevel() {
currentLevel++;
if (currentLevel > maxLevels) {
LK.showYouWin();
return;
}
// Clear current level objects
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
}
enemies = [];
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].destroy();
}
coins = [];
for (var i = platforms.length - 1; i >= 0; i--) {
platforms[i].destroy();
}
platforms = [];
for (var i = clouds.length - 1; i >= 0; i--) {
clouds[i].destroy();
}
clouds = [];
flag.destroy();
// Generate new level with increased difficulty
generateLevel();
// Reset player position
player.x = 200;
player.y = groundLevel;
player.velocityY = 0;
cameraX = 0;
}
// Function to generate level based on current level
function generateLevel() {
var difficultyMultiplier = currentLevel * 0.3;
// Increase platforms for first section, reduce for others
var platformCount;
if (currentLevel === 1) {
platformCount = 30; // Increased platform count for first section
} else {
platformCount = Math.min((15 + currentLevel * 2) / 2, 12); // Half the platforms for remaining sections
}
var enemyCount = Math.min(10 + currentLevel, 20);
var coinCount = Math.min(15 + currentLevel * 2, 30);
// Create platforms with spacing that's at most half the jump distance
for (var i = 0; i < platformCount; i++) {
var platform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
// Reduce spacing between platforms to ensure maximum gap is half of jump distance
platform.x = 900 + i * (levelWidth - 1800) / platformCount * 1.1 + (Math.random() - 0.5) * 100;
platform.y = 2200 - Math.random() * 100 - currentLevel * 10;
platforms.push(platform);
game.addChild(platform);
}
// Add extra platforms in between to fill sections
var extraPlatformMultiplier = currentLevel === 1 ? 0.6 : 0.3; // Reduce extra platforms for later levels
for (var i = 0; i < Math.floor(platformCount * extraPlatformMultiplier); i++) {
var extraPlatform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
extraPlatform.x = 1200 + i * (levelWidth - 2400) / Math.floor(platformCount * extraPlatformMultiplier) * 1.0 + (Math.random() - 0.5) * 150;
extraPlatform.y = 2150 - Math.random() * 120 - currentLevel * 8;
platforms.push(extraPlatform);
game.addChild(extraPlatform);
}
// Create enemies with increasing count
for (var i = 0; i < enemyCount; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = 800 + i * (levelWidth - 1600) / enemyCount + (Math.random() - 0.5) * 200;
enemy.y = groundLevel;
enemy.speed = -2 - difficultyMultiplier;
enemies.push(enemy);
}
// Create coins
for (var i = 0; i < coinCount; i++) {
var coin = game.addChild(new Coin());
// Spread coins with larger gaps to match platform distribution
coin.x = 800 + i * (levelWidth - 1600) / coinCount * 1.4 + (Math.random() - 0.5) * 600;
coin.y = 2100 - Math.random() * 150;
coin.initialY = coin.y;
coins.push(coin);
}
// Add extra coins scattered throughout sections
for (var i = 0; i < Math.floor(coinCount * 0.5); i++) {
var extraCoin = game.addChild(new Coin());
extraCoin.x = 1000 + i * (levelWidth - 2000) / Math.floor(coinCount * 0.5) * 1.3 + (Math.random() - 0.5) * 700;
extraCoin.y = 2050 - Math.random() * 180;
extraCoin.initialY = extraCoin.y;
coins.push(extraCoin);
}
// Create moving clouds
var cloudCount = 6 + Math.floor(currentLevel / 2);
for (var i = 0; i < cloudCount; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = Math.random() * levelWidth;
cloud.y = 300 + Math.random() * 1000;
cloud.initialX = cloud.x;
clouds.push(cloud);
// Add random tween movement
tween(cloud, {
y: cloud.y + (Math.random() - 0.5) * 250
}, {
duration: 2500 + Math.random() * 2000,
easing: tween.easeInOut,
onFinish: function () {
tween(this, {
y: this.y + (Math.random() - 0.5) * 300
}, {
duration: 2500 + Math.random() * 2000,
easing: tween.easeInOut
});
}.bind(cloud)
});
}
// Create flag at the end
flag = game.addChild(new Flag());
flag.x = levelWidth - 200;
flag.y = groundLevel;
flag.reached = false;
}
// Start background music
LK.playMusic('background_music');
; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Cloud = Container.expand(function () {
var self = Container.call(this);
var cloudGraphics = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -1.5;
self.initialX = 0;
self.update = function () {
self.x += self.speed;
// Reset cloud position when it goes off screen
if (self.x < cameraX - 200) {
self.x = cameraX + 2248 + Math.random() * 500;
self.y = 500 + Math.random() * 800;
}
};
return self;
});
var Coin = Container.expand(function () {
var self = Container.call(this);
var coinGraphics = self.attachAsset('coin', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.bobOffset = 0;
self.initialY = 0;
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.setScore(LK.getScore() + 50);
LK.getSound('coin_collect').play();
tween(self, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
self.update = function () {
if (!self.collected) {
// Bobbing animation
self.bobOffset += 0.1;
self.y = self.initialY + Math.sin(self.bobOffset) * 10;
coinGraphics.rotation += 0.05;
}
};
return self;
});
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = -2;
self.direction = -1;
self.isDefeated = false;
self.defeat = function () {
if (!self.isDefeated) {
self.isDefeated = true;
LK.setScore(LK.getScore() + 100);
LK.getSound('enemy_defeat').play();
tween(self, {
scaleY: 0.2,
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
}
};
self.update = function () {
if (!self.isDefeated) {
self.x += self.speed * self.direction;
// Simple AI - turn around at edges or walls
if (self.x < cameraX - 200 || self.x > cameraX + 2248) {
self.direction *= -1;
}
}
};
return self;
});
var Flag = Container.expand(function () {
var self = Container.call(this);
var flagGraphics = self.attachAsset('flag', {
anchorX: 0.5,
anchorY: 1.0
});
self.reached = false;
self.reach = function () {
if (!self.reached) {
self.reached = true;
LK.setScore(LK.getScore() + 1000);
LK.effects.flashScreen(0x00ff00, 1000);
// Check if this is the final level
if (currentLevel >= maxLevels) {
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
} else {
// Advance to next level
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.isGrounded = false;
self.isJumping = false;
self.jumpPower = -40; // Increased jump power for longer distance
self.highJumpPower = -60; // Increased high jump power for longer distance
self.gravity = 1.2;
self.speed = 4;
self.lives = 3;
self.isInvulnerable = false;
self.invulnerabilityTime = 0;
self.tapCount = 0;
self.lastTapTime = 0;
self.doubleTapWindow = 300; // 300ms window for double tap
self.jump = function () {
if (self.isGrounded && !self.isJumping) {
var currentTime = Date.now();
// Check if this is a double tap
if (currentTime - self.lastTapTime < self.doubleTapWindow) {
// Double tap - high jump
self.velocityY = self.highJumpPower;
self.tapCount = 0;
} else {
// Single tap - normal jump
self.velocityY = self.jumpPower;
self.tapCount = 1;
}
self.lastTapTime = currentTime;
self.isJumping = true;
self.isGrounded = false;
LK.getSound('jump').play();
}
};
self.takeDamage = function () {
if (!self.isInvulnerable) {
self.lives--;
self.isInvulnerable = true;
self.invulnerabilityTime = 120; // 2 seconds at 60fps
LK.effects.flashObject(self, 0xff0000, 500);
if (self.lives <= 0) {
LK.showGameOver();
}
}
};
self.update = function () {
// Handle invulnerability timer
if (self.isInvulnerable) {
self.invulnerabilityTime--;
if (self.invulnerabilityTime <= 0) {
self.isInvulnerable = false;
}
}
// Apply gravity
self.velocityY += self.gravity;
// Move player
self.x += self.speed;
self.y += self.velocityY;
// Ground collision (basic ground level)
if (self.y >= groundLevel) {
self.y = groundLevel;
self.velocityY = 0;
self.isGrounded = true;
self.isJumping = false;
}
// Platform collision
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
if (self.intersects(platform)) {
var playerBottom = self.y;
var playerTop = self.y - 80; // Player height is 80
var playerLeft = self.x - 40; // Player width is 80, so half is 40
var playerRight = self.x + 40;
var platformTop = platform.y - platform.height / 2;
var platformBottom = platform.y + platform.height / 2;
var platformLeft = platform.x - platform.width / 2;
var platformRight = platform.x + platform.width / 2;
// Landing on top of platform
if (self.velocityY > 0 && playerBottom > platformTop - 20 && playerBottom < platformTop + 20) {
self.y = platformTop;
self.velocityY = 0;
self.isGrounded = true;
self.isJumping = false;
}
// Hitting platform from below
else if (self.velocityY < 0 && playerTop < platformBottom + 20 && playerTop > platformBottom - 20) {
self.y = platformBottom + 80; // Push player down
self.velocityY = 0;
}
// Hitting platform from left side
else if (playerRight > platformLeft && playerLeft < platformLeft && self.x < platform.x) {
self.x = platformLeft - 40; // Push player to the left
}
// Hitting platform from right side
else if (playerLeft < platformRight && playerRight > platformRight && self.x > platform.x) {
self.x = platformRight + 40; // Push player to the right
}
}
}
// Death by falling
if (self.y > 2732 + 100) {
self.takeDamage();
self.x = cameraX + 100;
self.y = groundLevel - 200;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var player;
var enemies = [];
var coins = [];
var platforms = [];
var clouds = [];
var flag;
var cameraX = 0;
var groundLevel = 2600;
var levelWidth = 8000;
var currentLevel = 1;
var maxLevels = 11;
// UI elements
var scoreText = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreText.anchor.set(0, 0);
LK.gui.topLeft.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesText.anchor.set(1, 0);
LK.gui.topRight.addChild(livesText);
var levelText = new Text2('Level: 1', {
size: 60,
fill: 0xFFFFFF
});
levelText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelText);
// Create ground platforms
for (var i = 0; i < levelWidth / 200; i++) {
var groundPiece = LK.getAsset('ground', {
anchorX: 0.5,
anchorY: 1.0
});
groundPiece.x = i * 200 + 100;
groundPiece.y = groundLevel + 30;
game.addChild(groundPiece);
}
// Create player
player = game.addChild(new Player());
player.x = 200;
player.y = groundLevel;
// Create platforms - fill entire first section with platforms
var platformPositions = [];
var startX = 600;
var endX = 7800;
var platformSpacing = 380; // Slightly increased spacing between platforms
var yVariation = 50; // Vertical position variation
var baseY = 2200;
// Generate platforms throughout the entire first section
for (var x = startX; x <= endX; x += platformSpacing) {
platformPositions.push({
x: x + (Math.random() - 0.5) * 60,
// Small random horizontal offset
y: baseY + (Math.random() - 0.5) * yVariation // Small random vertical offset
});
}
for (var i = 0; i < platformPositions.length; i++) {
var platform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
platform.x = platformPositions[i].x;
platform.y = platformPositions[i].y;
platforms.push(platform);
game.addChild(platform);
}
// Create enemies
var enemyPositions = [{
x: 1000,
y: groundLevel
}, {
x: 1600,
y: groundLevel
}, {
x: 2200,
y: groundLevel
}, {
x: 2800,
y: groundLevel
}, {
x: 3400,
y: groundLevel
}, {
x: 4000,
y: groundLevel
}, {
x: 4600,
y: groundLevel
}, {
x: 5200,
y: groundLevel
}, {
x: 5800,
y: groundLevel
}];
for (var i = 0; i < enemyPositions.length; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = enemyPositions[i].x;
enemy.y = enemyPositions[i].y;
enemies.push(enemy);
}
// Create coins
var coinPositions = [{
x: 900,
y: 2100
}, {
x: 1500,
y: 2050
}, {
x: 2100,
y: 2080
}, {
x: 2700,
y: 2120
}, {
x: 3300,
y: 2060
}, {
x: 3900,
y: 2100
}, {
x: 4500,
y: 2070
}, {
x: 5100,
y: 2110
}, {
x: 5700,
y: 2090
}, {
x: 6300,
y: 2080
}, {
x: 6900,
y: 2100
}, {
x: 7500,
y: 2150
}, {
x: 1200,
y: 2120
}, {
x: 1800,
y: 2050
}, {
x: 2400,
y: 2180
}, {
x: 3000,
y: 2090
}, {
x: 3600,
y: 2160
}, {
x: 4200,
y: 2120
}, {
x: 4800,
y: 2180
}, {
x: 5400,
y: 2050
}, {
x: 6000,
y: 2140
}, {
x: 6600,
y: 2110
}, {
x: 7200,
y: 2170
}];
for (var i = 0; i < coinPositions.length; i++) {
var coin = game.addChild(new Coin());
coin.x = coinPositions[i].x;
coin.y = coinPositions[i].y;
coin.initialY = coin.y;
coins.push(coin);
}
// Create flag at the end
flag = game.addChild(new Flag());
flag.x = levelWidth - 200;
flag.y = groundLevel;
// Create moving clouds
for (var i = 0; i < 8; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = Math.random() * levelWidth;
cloud.y = 300 + Math.random() * 1000;
cloud.initialX = cloud.x;
clouds.push(cloud);
// Add random tween movement for more dynamic clouds
tween(cloud, {
y: cloud.y + (Math.random() - 0.5) * 200
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeInOut,
onFinish: function () {
// Start a new random movement
tween(this, {
y: this.y + (Math.random() - 0.5) * 300
}, {
duration: 3000 + Math.random() * 2000,
easing: tween.easeInOut
});
}.bind(cloud)
});
}
// Touch controls
game.down = function (x, y, obj) {
player.jump();
};
// Camera following
function updateCamera() {
// Camera follows player with some offset
var targetCameraX = player.x - 300;
// Clamp camera to level bounds
targetCameraX = Math.max(0, Math.min(targetCameraX, levelWidth - 2048));
// Smooth camera movement
cameraX += (targetCameraX - cameraX) * 0.1;
// Apply camera offset to all game objects
game.x = -cameraX;
}
// Game update loop
game.update = function () {
// Update camera
updateCamera();
// Update UI
scoreText.setText('Score: ' + LK.getScore());
livesText.setText('Lives: ' + player.lives);
levelText.setText('Level: ' + currentLevel);
// Check player-enemy collisions
for (var i = enemies.length - 1; i >= 0; i--) {
var enemy = enemies[i];
if (!enemy.isDefeated && player.intersects(enemy) && !player.isInvulnerable) {
// Check if player is actually falling onto enemy (not standing on platform above)
var playerOnPlatform = false;
for (var j = 0; j < platforms.length; j++) {
var platform = platforms[j];
var playerBottom = player.y;
var platformTop = platform.y - platform.height / 2;
// Check if player is standing on a platform and enemy is below
if (Math.abs(playerBottom - platformTop) < 50 && Math.abs(player.x - platform.x) < platform.width / 2 && enemy.y > platform.y) {
playerOnPlatform = true;
break;
}
}
// Check if player is jumping on enemy (and not on platform above)
if (player.velocityY > 0 && player.y < enemy.y - 20 && !playerOnPlatform) {
// Player stomps enemy
enemy.defeat();
enemies.splice(i, 1);
player.velocityY = -15; // Small bounce
} else {
// Player takes damage
player.takeDamage();
}
}
}
// Check player-coin collisions
for (var i = coins.length - 1; i >= 0; i--) {
var coin = coins[i];
if (!coin.collected && player.intersects(coin)) {
coin.collect();
coins.splice(i, 1);
}
}
// Check player-flag collision
if (!flag.reached && player.intersects(flag)) {
flag.reach();
}
};
// Function to advance to next level
function nextLevel() {
currentLevel++;
if (currentLevel > maxLevels) {
LK.showYouWin();
return;
}
// Clear current level objects
for (var i = enemies.length - 1; i >= 0; i--) {
enemies[i].destroy();
}
enemies = [];
for (var i = coins.length - 1; i >= 0; i--) {
coins[i].destroy();
}
coins = [];
for (var i = platforms.length - 1; i >= 0; i--) {
platforms[i].destroy();
}
platforms = [];
for (var i = clouds.length - 1; i >= 0; i--) {
clouds[i].destroy();
}
clouds = [];
flag.destroy();
// Generate new level with increased difficulty
generateLevel();
// Reset player position
player.x = 200;
player.y = groundLevel;
player.velocityY = 0;
cameraX = 0;
}
// Function to generate level based on current level
function generateLevel() {
var difficultyMultiplier = currentLevel * 0.3;
// Increase platforms for first section, reduce for others
var platformCount;
if (currentLevel === 1) {
platformCount = 30; // Increased platform count for first section
} else {
platformCount = Math.min((15 + currentLevel * 2) / 2, 12); // Half the platforms for remaining sections
}
var enemyCount = Math.min(10 + currentLevel, 20);
var coinCount = Math.min(15 + currentLevel * 2, 30);
// Create platforms with spacing that's at most half the jump distance
for (var i = 0; i < platformCount; i++) {
var platform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
// Reduce spacing between platforms to ensure maximum gap is half of jump distance
platform.x = 900 + i * (levelWidth - 1800) / platformCount * 1.1 + (Math.random() - 0.5) * 100;
platform.y = 2200 - Math.random() * 100 - currentLevel * 10;
platforms.push(platform);
game.addChild(platform);
}
// Add extra platforms in between to fill sections
var extraPlatformMultiplier = currentLevel === 1 ? 0.6 : 0.3; // Reduce extra platforms for later levels
for (var i = 0; i < Math.floor(platformCount * extraPlatformMultiplier); i++) {
var extraPlatform = LK.getAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
extraPlatform.x = 1200 + i * (levelWidth - 2400) / Math.floor(platformCount * extraPlatformMultiplier) * 1.0 + (Math.random() - 0.5) * 150;
extraPlatform.y = 2150 - Math.random() * 120 - currentLevel * 8;
platforms.push(extraPlatform);
game.addChild(extraPlatform);
}
// Create enemies with increasing count
for (var i = 0; i < enemyCount; i++) {
var enemy = game.addChild(new Enemy());
enemy.x = 800 + i * (levelWidth - 1600) / enemyCount + (Math.random() - 0.5) * 200;
enemy.y = groundLevel;
enemy.speed = -2 - difficultyMultiplier;
enemies.push(enemy);
}
// Create coins
for (var i = 0; i < coinCount; i++) {
var coin = game.addChild(new Coin());
// Spread coins with larger gaps to match platform distribution
coin.x = 800 + i * (levelWidth - 1600) / coinCount * 1.4 + (Math.random() - 0.5) * 600;
coin.y = 2100 - Math.random() * 150;
coin.initialY = coin.y;
coins.push(coin);
}
// Add extra coins scattered throughout sections
for (var i = 0; i < Math.floor(coinCount * 0.5); i++) {
var extraCoin = game.addChild(new Coin());
extraCoin.x = 1000 + i * (levelWidth - 2000) / Math.floor(coinCount * 0.5) * 1.3 + (Math.random() - 0.5) * 700;
extraCoin.y = 2050 - Math.random() * 180;
extraCoin.initialY = extraCoin.y;
coins.push(extraCoin);
}
// Create moving clouds
var cloudCount = 6 + Math.floor(currentLevel / 2);
for (var i = 0; i < cloudCount; i++) {
var cloud = game.addChild(new Cloud());
cloud.x = Math.random() * levelWidth;
cloud.y = 300 + Math.random() * 1000;
cloud.initialX = cloud.x;
clouds.push(cloud);
// Add random tween movement
tween(cloud, {
y: cloud.y + (Math.random() - 0.5) * 250
}, {
duration: 2500 + Math.random() * 2000,
easing: tween.easeInOut,
onFinish: function () {
tween(this, {
y: this.y + (Math.random() - 0.5) * 300
}, {
duration: 2500 + Math.random() * 2000,
easing: tween.easeInOut
});
}.bind(cloud)
});
}
// Create flag at the end
flag = game.addChild(new Flag());
flag.x = levelWidth - 200;
flag.y = groundLevel;
flag.reached = false;
}
// Start background music
LK.playMusic('background_music');
;
Fullscreen modern App Store landscape banner, 16:9, high definition, for a game titled "Super Mario Adventure" and with the description "Classic side-scrolling platformer where you jump over obstacles, collect coins, and defeat enemies to reach the goal flag.". No text on banner!
düşman. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
çimenli zemin. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
coın. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
oyun geçiş kapısı. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat