/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.83,
scaleY: 0.83
});
self.speed = 8;
self.passed = false;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
self.getHitbox = function () {
return {
x: self.x - 60,
y: self.y - 120,
width: 160,
height: 240
};
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.95,
scaleY: 0.95
});
self.speed = 1000;
self.jumpHeight = 30;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7;
if (self.y >= 2732 / 2) {
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
LK.playMusic('jumpmusic', {
loop: false
});
}
};
self.getHitbox = function () {
return {
x: self.x - 75,
y: self.y - 150,
width: 150,
height: 300
};
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Background
// Import tween plugin for smooth animations
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
// Create a duplicate background for seamless scrolling
var background2 = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 + background.width,
y: 2732 / 2
}));
// Background scrolling animation is now disabled
function scrollBackground() {
// Background remains static - no scrolling animation
}
// Not starting the scrolling animation anymore
// Player
var player = game.addChild(new Player());
player.x = 2048 / 2 - 100;
player.y = 2732 / 2;
// Enemy array
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Score Text
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreText);
// Center the score text horizontally, anchor point set at the middle of its top edge.
scoreText.anchor.set(0.5, 0);
scoreText.x = LK.gui.top.width / 2;
scoreText.y = 40;
// Collision function
function checkCollision(rect1, rect2) {
return rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.y + rect1.height > rect2.y;
}
// Spawn Enemy
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2;
enemy.passed = false;
enemies.push(enemy);
game.addChild(enemy);
}
// Game loop
game.update = function () {
player.update();
// Enemy spawn
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
spawnEnemy();
enemySpawnInterval = Math.floor(Math.random() * 100) + 50;
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
// Collision detection
if (checkCollision(player.getHitbox(), enemies[j].getHitbox())) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Leaderboard will be shown automatically by LK after game over
// Music will be restarted by LK after game reset
}
// Score increment
else if (enemies[j].x < player.x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
}
// Remove offscreen enemy
if (enemies[j].x < -50) {
enemies[j].destroy();
enemies.splice(j, 1);
}
}
// Speed increase
if (LK.ticks % 300 == 0) {
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed += 1;
}
}
};
// Tap to jump
game.down = function (x, y, obj) {
player.jump();
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Enemy class
var Enemy = Container.expand(function () {
var self = Container.call(this);
var enemyGraphics = self.attachAsset('enemy', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.83,
scaleY: 0.83
});
self.speed = 8;
self.passed = false;
self.update = function () {
self.x -= self.speed;
if (self.x < -50) {
self.destroy();
}
};
self.getHitbox = function () {
return {
x: self.x - 60,
y: self.y - 120,
width: 160,
height: 240
};
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.95,
scaleY: 0.95
});
self.speed = 1000;
self.jumpHeight = 30;
self.isJumping = false;
self.velocityY = 0;
self.update = function () {
if (self.isJumping) {
self.y += self.velocityY;
self.velocityY += 0.7;
if (self.y >= 2732 / 2) {
self.y = 2732 / 2;
self.isJumping = false;
self.velocityY = 0;
}
}
};
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.velocityY = -self.jumpHeight;
LK.playMusic('jumpmusic', {
loop: false
});
}
};
self.getHitbox = function () {
return {
x: self.x - 75,
y: self.y - 150,
width: 150,
height: 300
};
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
// Background
// Import tween plugin for smooth animations
var background = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
}));
// Create a duplicate background for seamless scrolling
var background2 = game.addChild(LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2 + background.width,
y: 2732 / 2
}));
// Background scrolling animation is now disabled
function scrollBackground() {
// Background remains static - no scrolling animation
}
// Not starting the scrolling animation anymore
// Player
var player = game.addChild(new Player());
player.x = 2048 / 2 - 100;
player.y = 2732 / 2;
// Enemy array
var enemies = [];
var enemySpawnInterval = 100;
var enemySpawnCounter = 0;
// Score Text
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
LK.gui.top.addChild(scoreText);
// Center the score text horizontally, anchor point set at the middle of its top edge.
scoreText.anchor.set(0.5, 0);
scoreText.x = LK.gui.top.width / 2;
scoreText.y = 40;
// Collision function
function checkCollision(rect1, rect2) {
return rect1.x < rect2.x + rect2.width && rect1.x + rect1.width > rect2.x && rect1.y < rect2.y + rect2.height && rect1.y + rect1.height > rect2.y;
}
// Spawn Enemy
function spawnEnemy() {
var enemy = new Enemy();
enemy.x = 2048;
enemy.y = 2732 / 2;
enemy.passed = false;
enemies.push(enemy);
game.addChild(enemy);
}
// Game loop
game.update = function () {
player.update();
// Enemy spawn
enemySpawnCounter++;
if (enemySpawnCounter >= enemySpawnInterval) {
spawnEnemy();
enemySpawnInterval = Math.floor(Math.random() * 100) + 50;
enemySpawnCounter = 0;
}
// Update enemies
for (var j = enemies.length - 1; j >= 0; j--) {
enemies[j].update();
// Collision detection
if (checkCollision(player.getHitbox(), enemies[j].getHitbox())) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
// Leaderboard will be shown automatically by LK after game over
// Music will be restarted by LK after game reset
}
// Score increment
else if (enemies[j].x < player.x && !enemies[j].passed) {
enemies[j].passed = true;
LK.setScore(LK.getScore() + 1);
scoreText.setText(LK.getScore());
}
// Remove offscreen enemy
if (enemies[j].x < -50) {
enemies[j].destroy();
enemies.splice(j, 1);
}
}
// Speed increase
if (LK.ticks % 300 == 0) {
for (var i = 0; i < enemies.length; i++) {
enemies[i].speed += 1;
}
}
};
// Tap to jump
game.down = function (x, y, obj) {
player.jump();
};