/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var BonusStar = Container.expand(function () { var self = Container.call(this); // Bonus graphics var bonusGraphics = self.attachAsset('bonusStar', { anchorX: 0.5, anchorY: 0.5 }); // Bonus properties self.speed = 0; // Set in game code self.collected = false; // Animation effect self.startPulsing = function () { var _pulse = function pulse() { if (!self.collected) { tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.easeInOut, onFinish: _pulse }); } }); } }; _pulse(); }; // Update method called every frame self.update = function () { // Move bonus from right to left self.x -= self.speed; // Rotate slowly self.rotation += 0.01; }; // Collect animation self.collect = function () { if (!self.collected) { self.collected = true; LK.getSound('bonus').play(); // Scale up and fade out tween(self, { scaleX: 2, scaleY: 2, alpha: 0 }, { duration: 300, easing: tween.easeOut }); } }; return self; }); var Obstacle = Container.expand(function () { var self = Container.call(this); // Obstacle graphics var obstacleGraphics = self.attachAsset('obstacle', { anchorX: 0.5, anchorY: 1.0 // Bottom center anchor }); // Obstacle properties self.speed = 0; // Set in game code self.passed = false; // Update method called every frame self.update = function () { // Move obstacle from right to left self.x -= self.speed; }; return self; }); var Player = Container.expand(function () { var self = Container.call(this); // Player graphics var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); // Player properties self.isJumping = false; self.isDead = false; self.jumpHeight = 300; self.jumpDuration = 600; self.groundY = 0; // Set in game code // Handle player jump self.jump = function () { if (!self.isJumping && !self.isDead) { self.isJumping = true; // Play jump sound LK.getSound('jump').play(); // Jump animation tween(self, { y: self.groundY - self.jumpHeight }, { duration: self.jumpDuration / 2, easing: tween.easeOut, onFinish: function onFinish() { // Fall animation tween(self, { y: self.groundY }, { duration: self.jumpDuration / 2, easing: tween.easeIn, onFinish: function onFinish() { self.isJumping = false; } }); } }); } }; // Die animation self.die = function () { if (!self.isDead) { self.isDead = true; LK.getSound('hit').play(); // Flash red LK.effects.flashObject(self, 0xff0000, 500); // Rotate and fall animation tween(self, { rotation: Math.PI, y: self.groundY + 100 }, { duration: 800, easing: tween.easeIn }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Sky blue background }); /**** * Game Code ****/ // Game constants var GROUND_Y = 2500; var GAME_DURATION = 300000; // 5 minutes in milliseconds var INITIAL_OBSTACLE_INTERVAL = 2000; // Initial interval between obstacles var MIN_OBSTACLE_INTERVAL = 800; // Min interval between obstacles var DIFFICULTY_INCREASE_INTERVAL = 10000; // Increase difficulty every 10 seconds var BASE_OBSTACLE_SPEED = 10; var BONUS_SPAWN_CHANCE = 0.25; // 25% chance to spawn a bonus with each obstacle // Game variables var player; var obstacles = []; var bonusItems = []; var ground; var ceiling; var score = 0; var gameTime = 0; var lastObstacleTime = 0; var obstacleInterval = INITIAL_OBSTACLE_INTERVAL; var isGameOver = false; var gameStartTime; // UI elements var scoreTxt; var timerTxt; var highScoreTxt; // Initialize the game function initGame() { // Reset variables obstacles = []; bonusItems = []; score = 0; gameTime = 0; lastObstacleTime = 0; obstacleInterval = INITIAL_OBSTACLE_INTERVAL; isGameOver = false; gameStartTime = Date.now(); // Create ground ground = game.addChild(LK.getAsset('ground', { anchorX: 0, anchorY: 0 })); ground.x = 0; ground.y = GROUND_Y; // Create ceiling ceiling = game.addChild(LK.getAsset('ceiling', { anchorX: 0, anchorY: 0 })); ceiling.x = 0; ceiling.y = 0; // Create player player = new Player(); player.x = 400; player.y = GROUND_Y; player.groundY = GROUND_Y; game.addChild(player); // Initialize UI createUI(); // Play background music LK.playMusic('bgMusic', { fade: { start: 0, end: 0.3, duration: 1000 } }); } // Create UI elements function createUI() { // Score text scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(scoreTxt); scoreTxt.x = -scoreTxt.width - 30; scoreTxt.y = 30; // Timer text timerTxt = new Text2('Time: 5:00', { size: 80, fill: 0xFFFFFF }); timerTxt.anchor.set(0.5, 0); LK.gui.top.addChild(timerTxt); timerTxt.y = 30; // High score text highScoreTxt = new Text2('High Score: ' + storage.highScore, { size: 50, fill: 0xFFFFFF }); highScoreTxt.anchor.set(0, 0); LK.gui.topRight.addChild(highScoreTxt); highScoreTxt.x = -highScoreTxt.width - 30; highScoreTxt.y = scoreTxt.y + scoreTxt.height + 10; } // Update score function updateScore(points) { score += points; scoreTxt.setText('Score: ' + score); // Update high score if needed if (score > storage.highScore) { storage.highScore = score; highScoreTxt.setText('High Score: ' + storage.highScore); } // Update LK score (for game over screen) LK.setScore(score); } // Format time as MM:SS function formatTime(milliseconds) { var totalSeconds = Math.max(0, Math.floor((GAME_DURATION - milliseconds) / 1000)); var minutes = Math.floor(totalSeconds / 60); var seconds = totalSeconds % 60; return minutes + ':' + (seconds < 10 ? '0' : '') + seconds; } // Create a new obstacle function createObstacle() { var obstacle = new Obstacle(); obstacle.x = 2048 + obstacle.width; obstacle.y = GROUND_Y; obstacle.speed = BASE_OBSTACLE_SPEED + gameTime / DIFFICULTY_INCREASE_INTERVAL; game.addChild(obstacle); obstacles.push(obstacle); // Sometimes create a bonus star if (Math.random() < BONUS_SPAWN_CHANCE) { createBonusStar(obstacle.x); } return obstacle; } // Create a bonus star function createBonusStar(xPos) { var bonus = new BonusStar(); bonus.x = xPos; // Position either above obstacle or at a random height bonus.y = GROUND_Y - Math.random() * 400 - 100; bonus.speed = BASE_OBSTACLE_SPEED + gameTime / DIFFICULTY_INCREASE_INTERVAL; bonus.startPulsing(); game.addChild(bonus); bonusItems.push(bonus); return bonus; } // Check if two game objects collide function checkCollision(obj1, obj2) { return obj1.intersects(obj2); } // Handle game over function gameOver() { if (!isGameOver) { isGameOver = true; player.die(); // Stop background music with fade LK.stopMusic({ fade: { start: 0.3, end: 0, duration: 800 } }); // Show game over screen after a short delay LK.setTimeout(function () { LK.showGameOver(); }, 1500); } } // Event handlers game.down = function (x, y, obj) { player.jump(); }; // Main game update function game.update = function () { // Update game time var currentTime = Date.now(); gameTime = currentTime - gameStartTime; // Check if game time is up if (gameTime >= GAME_DURATION && !isGameOver) { // Player survived the full duration updateScore(1000); // Bonus for completing the full time gameOver(); return; } // Update timer display timerTxt.setText('Time: ' + formatTime(gameTime)); // Increase difficulty over time if (gameTime % DIFFICULTY_INCREASE_INTERVAL < 16) { obstacleInterval = Math.max(MIN_OBSTACLE_INTERVAL, INITIAL_OBSTACLE_INTERVAL - gameTime / DIFFICULTY_INCREASE_INTERVAL * 100); } // Spawn obstacles if (currentTime - lastObstacleTime > obstacleInterval && !isGameOver) { createObstacle(); lastObstacleTime = currentTime; } // Update obstacles for (var i = obstacles.length - 1; i >= 0; i--) { var obstacle = obstacles[i]; obstacle.update(); // Check if obstacle is off-screen if (obstacle.x < -obstacle.width) { obstacle.destroy(); obstacles.splice(i, 1); continue; } // Check for collision with player if (!isGameOver && !obstacle.passed && checkCollision(player, obstacle)) { gameOver(); } // Check if player passed the obstacle if (!obstacle.passed && obstacle.x < player.x - player.width) { obstacle.passed = true; updateScore(10); } } // Update bonus items for (var j = bonusItems.length - 1; j >= 0; j--) { var bonus = bonusItems[j]; bonus.update(); // Check if bonus is off-screen if (bonus.x < -bonus.width) { bonus.destroy(); bonusItems.splice(j, 1); continue; } // Check if player collected the bonus if (!bonus.collected && checkCollision(player, bonus)) { bonus.collect(); updateScore(50); // Remove from array after animation completes LK.setTimeout(function () { var index = bonusItems.indexOf(bonus); if (index > -1) { bonus.destroy(); bonusItems.splice(index, 1); } }, 300); } } }; // Initialize the game initGame();
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var BonusStar = Container.expand(function () {
var self = Container.call(this);
// Bonus graphics
var bonusGraphics = self.attachAsset('bonusStar', {
anchorX: 0.5,
anchorY: 0.5
});
// Bonus properties
self.speed = 0; // Set in game code
self.collected = false;
// Animation effect
self.startPulsing = function () {
var _pulse = function pulse() {
if (!self.collected) {
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: _pulse
});
}
});
}
};
_pulse();
};
// Update method called every frame
self.update = function () {
// Move bonus from right to left
self.x -= self.speed;
// Rotate slowly
self.rotation += 0.01;
};
// Collect animation
self.collect = function () {
if (!self.collected) {
self.collected = true;
LK.getSound('bonus').play();
// Scale up and fade out
tween(self, {
scaleX: 2,
scaleY: 2,
alpha: 0
}, {
duration: 300,
easing: tween.easeOut
});
}
};
return self;
});
var Obstacle = Container.expand(function () {
var self = Container.call(this);
// Obstacle graphics
var obstacleGraphics = self.attachAsset('obstacle', {
anchorX: 0.5,
anchorY: 1.0 // Bottom center anchor
});
// Obstacle properties
self.speed = 0; // Set in game code
self.passed = false;
// Update method called every frame
self.update = function () {
// Move obstacle from right to left
self.x -= self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
// Player graphics
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
// Player properties
self.isJumping = false;
self.isDead = false;
self.jumpHeight = 300;
self.jumpDuration = 600;
self.groundY = 0; // Set in game code
// Handle player jump
self.jump = function () {
if (!self.isJumping && !self.isDead) {
self.isJumping = true;
// Play jump sound
LK.getSound('jump').play();
// Jump animation
tween(self, {
y: self.groundY - self.jumpHeight
}, {
duration: self.jumpDuration / 2,
easing: tween.easeOut,
onFinish: function onFinish() {
// Fall animation
tween(self, {
y: self.groundY
}, {
duration: self.jumpDuration / 2,
easing: tween.easeIn,
onFinish: function onFinish() {
self.isJumping = false;
}
});
}
});
}
};
// Die animation
self.die = function () {
if (!self.isDead) {
self.isDead = true;
LK.getSound('hit').play();
// Flash red
LK.effects.flashObject(self, 0xff0000, 500);
// Rotate and fall animation
tween(self, {
rotation: Math.PI,
y: self.groundY + 100
}, {
duration: 800,
easing: tween.easeIn
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Sky blue background
});
/****
* Game Code
****/
// Game constants
var GROUND_Y = 2500;
var GAME_DURATION = 300000; // 5 minutes in milliseconds
var INITIAL_OBSTACLE_INTERVAL = 2000; // Initial interval between obstacles
var MIN_OBSTACLE_INTERVAL = 800; // Min interval between obstacles
var DIFFICULTY_INCREASE_INTERVAL = 10000; // Increase difficulty every 10 seconds
var BASE_OBSTACLE_SPEED = 10;
var BONUS_SPAWN_CHANCE = 0.25; // 25% chance to spawn a bonus with each obstacle
// Game variables
var player;
var obstacles = [];
var bonusItems = [];
var ground;
var ceiling;
var score = 0;
var gameTime = 0;
var lastObstacleTime = 0;
var obstacleInterval = INITIAL_OBSTACLE_INTERVAL;
var isGameOver = false;
var gameStartTime;
// UI elements
var scoreTxt;
var timerTxt;
var highScoreTxt;
// Initialize the game
function initGame() {
// Reset variables
obstacles = [];
bonusItems = [];
score = 0;
gameTime = 0;
lastObstacleTime = 0;
obstacleInterval = INITIAL_OBSTACLE_INTERVAL;
isGameOver = false;
gameStartTime = Date.now();
// Create ground
ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0
}));
ground.x = 0;
ground.y = GROUND_Y;
// Create ceiling
ceiling = game.addChild(LK.getAsset('ceiling', {
anchorX: 0,
anchorY: 0
}));
ceiling.x = 0;
ceiling.y = 0;
// Create player
player = new Player();
player.x = 400;
player.y = GROUND_Y;
player.groundY = GROUND_Y;
game.addChild(player);
// Initialize UI
createUI();
// Play background music
LK.playMusic('bgMusic', {
fade: {
start: 0,
end: 0.3,
duration: 1000
}
});
}
// Create UI elements
function createUI() {
// Score text
scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(scoreTxt);
scoreTxt.x = -scoreTxt.width - 30;
scoreTxt.y = 30;
// Timer text
timerTxt = new Text2('Time: 5:00', {
size: 80,
fill: 0xFFFFFF
});
timerTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(timerTxt);
timerTxt.y = 30;
// High score text
highScoreTxt = new Text2('High Score: ' + storage.highScore, {
size: 50,
fill: 0xFFFFFF
});
highScoreTxt.anchor.set(0, 0);
LK.gui.topRight.addChild(highScoreTxt);
highScoreTxt.x = -highScoreTxt.width - 30;
highScoreTxt.y = scoreTxt.y + scoreTxt.height + 10;
}
// Update score
function updateScore(points) {
score += points;
scoreTxt.setText('Score: ' + score);
// Update high score if needed
if (score > storage.highScore) {
storage.highScore = score;
highScoreTxt.setText('High Score: ' + storage.highScore);
}
// Update LK score (for game over screen)
LK.setScore(score);
}
// Format time as MM:SS
function formatTime(milliseconds) {
var totalSeconds = Math.max(0, Math.floor((GAME_DURATION - milliseconds) / 1000));
var minutes = Math.floor(totalSeconds / 60);
var seconds = totalSeconds % 60;
return minutes + ':' + (seconds < 10 ? '0' : '') + seconds;
}
// Create a new obstacle
function createObstacle() {
var obstacle = new Obstacle();
obstacle.x = 2048 + obstacle.width;
obstacle.y = GROUND_Y;
obstacle.speed = BASE_OBSTACLE_SPEED + gameTime / DIFFICULTY_INCREASE_INTERVAL;
game.addChild(obstacle);
obstacles.push(obstacle);
// Sometimes create a bonus star
if (Math.random() < BONUS_SPAWN_CHANCE) {
createBonusStar(obstacle.x);
}
return obstacle;
}
// Create a bonus star
function createBonusStar(xPos) {
var bonus = new BonusStar();
bonus.x = xPos;
// Position either above obstacle or at a random height
bonus.y = GROUND_Y - Math.random() * 400 - 100;
bonus.speed = BASE_OBSTACLE_SPEED + gameTime / DIFFICULTY_INCREASE_INTERVAL;
bonus.startPulsing();
game.addChild(bonus);
bonusItems.push(bonus);
return bonus;
}
// Check if two game objects collide
function checkCollision(obj1, obj2) {
return obj1.intersects(obj2);
}
// Handle game over
function gameOver() {
if (!isGameOver) {
isGameOver = true;
player.die();
// Stop background music with fade
LK.stopMusic({
fade: {
start: 0.3,
end: 0,
duration: 800
}
});
// Show game over screen after a short delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1500);
}
}
// Event handlers
game.down = function (x, y, obj) {
player.jump();
};
// Main game update function
game.update = function () {
// Update game time
var currentTime = Date.now();
gameTime = currentTime - gameStartTime;
// Check if game time is up
if (gameTime >= GAME_DURATION && !isGameOver) {
// Player survived the full duration
updateScore(1000); // Bonus for completing the full time
gameOver();
return;
}
// Update timer display
timerTxt.setText('Time: ' + formatTime(gameTime));
// Increase difficulty over time
if (gameTime % DIFFICULTY_INCREASE_INTERVAL < 16) {
obstacleInterval = Math.max(MIN_OBSTACLE_INTERVAL, INITIAL_OBSTACLE_INTERVAL - gameTime / DIFFICULTY_INCREASE_INTERVAL * 100);
}
// Spawn obstacles
if (currentTime - lastObstacleTime > obstacleInterval && !isGameOver) {
createObstacle();
lastObstacleTime = currentTime;
}
// Update obstacles
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.update();
// Check if obstacle is off-screen
if (obstacle.x < -obstacle.width) {
obstacle.destroy();
obstacles.splice(i, 1);
continue;
}
// Check for collision with player
if (!isGameOver && !obstacle.passed && checkCollision(player, obstacle)) {
gameOver();
}
// Check if player passed the obstacle
if (!obstacle.passed && obstacle.x < player.x - player.width) {
obstacle.passed = true;
updateScore(10);
}
}
// Update bonus items
for (var j = bonusItems.length - 1; j >= 0; j--) {
var bonus = bonusItems[j];
bonus.update();
// Check if bonus is off-screen
if (bonus.x < -bonus.width) {
bonus.destroy();
bonusItems.splice(j, 1);
continue;
}
// Check if player collected the bonus
if (!bonus.collected && checkCollision(player, bonus)) {
bonus.collect();
updateScore(50);
// Remove from array after animation completes
LK.setTimeout(function () {
var index = bonusItems.indexOf(bonus);
if (index > -1) {
bonus.destroy();
bonusItems.splice(index, 1);
}
}, 300);
}
}
};
// Initialize the game
initGame();
A single spiky rotating obstacle designed in pixel art style. Dark red color with glowing orange edges to create urgency. The obstacle is circular with sharp edges, slightly animated to spin or pulse. Made to look dangerous but simple, ideal for a fast-paced jump-and-dodge arcade game. Transparent background.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A small, glowing golden star collectible in pixel art style. Shiny with a subtle sparkle effect, floating slightly above the ground. Simple and bright, easy to spot during fast gameplay. Designed to reward players for precision jumping. Transparent background.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows