/**** * Classes ****/ //<Assets used in the game will automatically appear here> // Platform class var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('platform', { anchorX: 0.5, anchorY: 0.5 }); self.direction = Math.random() < 0.5 ? -1 : 1; // Randomly assign a direction to each platform self.update = function () { // Platforms move horizontally self.x += 5 * self.direction; // If platform goes off the edge of the screen, it reappears on the opposite side if (self.x > 2048) { self.x = -100; } else if (self.x < -100) { self.x = 2048; } }; }); // Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.attachAsset('player', { anchorX: 0.5, anchorY: 0.5 }); var earGraphics = self.attachAsset('Ear', { anchorX: 0.5, anchorY: 1 }); earGraphics.y = -playerGraphics.height / 2; earGraphics.x = 35; var ear2Graphics = self.attachAsset('Ear2', { anchorX: 0.5, anchorY: 1 }); ear2Graphics.y = -playerGraphics.height / 2; ear2Graphics.x = earGraphics.x - earGraphics.width; self.vy = 0; // Vertical velocity self.jump = function () { self.vy = -20; // Jump velocity }; self.update = function () { self.y += self.vy; self.vy += 1; // Gravity if (self.y > 2732) { // Player fell off the screen LK.showGameOver(); } // Add physics to the ear asset earGraphics.rotation += 0.1; // Rotate the ear asset if (earGraphics.rotation > 0.5) { earGraphics.rotation = -0.5; // Reset the rotation when it reaches a certain point } // Add physics to the ear2 asset ear2Graphics.rotation += 0.1; // Rotate the ear2 asset if (ear2Graphics.rotation > 0.5) { ear2Graphics.rotation = -0.5; // Reset the rotation when it reaches a certain point } }; }); // StartingPlatform class var StartingPlatform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.attachAsset('StartPlatform', { anchorX: 0.5, anchorY: 0.5 }); self.disappear = function () { self.destroy(); }; }); /**** * Initialize Game ****/ var game = new LK.Game(); /**** * Game Code ****/ var bg = game.attachAsset('BG', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); // Initialize arrays and variables var platforms = []; var player; var score = 0; var scoreTxt; var jumpLimit = 100; // Player starts with 100 jumps // Create initial platforms function createInitialPlatforms() { for (var i = 0; i < 10; i++) { var platform; if (i === 0) { platform = new StartingPlatform(); } else { platform = new Platform(); } platform.x = Math.random() * 2048; platform.y = 2732 - i * 100; platforms.push(platform); game.addChild(platform); } } // Create player function createPlayer() { player = new Player(); player.x = 1024; // Center horizontally player.y = 2000; // Start near the bottom game.addChild(player); } // Create score text function createScoreText() { scoreTxt = new Text2('0', { size: 86, fill: "#000000", font: "bold 86px Arial" }); scoreTxt.anchor.set(1, 1); LK.gui.bottomRight.addChild(scoreTxt); } // Create jump limit bar function createJumpLimitBar() { jumpLimitBar = LK.getAsset('jumpLimitBar', { width: 50, height: jumpLimit * 10, color: 0x00ff00, shape: 'box', anchorX: 0, anchorY: 0 }); jumpLimitBar.x = 0; jumpLimitBar.y = 0; LK.gui.left.addChild(jumpLimitBar); game.addChild(jumpLimitBar); } // Initialize game elements createInitialPlatforms(); createPlayer(); createScoreText(); createJumpLimitBar(); // Add moon asset to top center of screen var moon = game.attachAsset('Moon', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 200 }); // Add sparkle asset to top center of screen and set its initial alpha to 0 var sparkle = game.attachAsset('Sparkle', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 200, alpha: 0 }); // Handle player jump on touch game.down = function (x, y, obj) { if (jumpLimit > 0) { player.jump(); if (platforms[0] instanceof StartingPlatform) { platforms[0].disappear(); platforms.shift(); } // Play jump sound when player jumps LK.getSound('Jump').play(); jumpLimit -= 13; // Increase the rate at which the jump limit bar depletes jumpLimitBar.height = jumpLimit * 20; // Reflect the jump limit increase in the jump limit bar jumpLimitBar.y = 2732 - jumpLimitBar.height; } else { jumpLimit += 0.5; // Restore the jump limit bar jumpLimitBar.height = jumpLimit * 20; jumpLimitBar.y = 2732 - jumpLimitBar.height; } }; // Update game every tick game.update = function () { player.update(); for (var i = 0; i < platforms.length; i++) { if (player.intersects(platforms[i])) { if (player.vy > 0) { // Player is moving downwards player.vy = -10; // Knockback effect } else { player.jump(); score++; scoreTxt.setText(score); } } } // Check if player hits the top of the screen or the moon if (player.y <= 0 || player.intersects(moon)) { score++; scoreTxt.setText(score); sparkle.alpha = 1; sparkle.rotation += 0.05; var fadeOutTimer = LK.setInterval(function () { sparkle.alpha -= 0.02; sparkle.rotation += 0.1; if (sparkle.alpha <= 0) { LK.clearInterval(fadeOutTimer); } }, 10); // Play chime sound when player hits the moon LK.getSound('Chime').play(); } for (var i = platforms.length - 1; i >= 0; i--) { if (platforms[i].y > 2732) { platforms[i].destroy(); platforms.splice(i, 1); var newPlatform = new Platform(); newPlatform.x = Math.random() * 2048; newPlatform.y = (moon.y + moon.height + newPlatform.height) * 0.75; // Start platform just below the moon and limit to the middle of the screen platforms.push(newPlatform); game.addChild(newPlatform); } } // Restore the jump limit bar gradually over time if (jumpLimit < 100) { jumpLimit += 0.5; jumpLimitBar.height = jumpLimit * 20; jumpLimitBar.y = 2732 - jumpLimitBar.height; } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Platform class
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('platform', {
anchorX: 0.5,
anchorY: 0.5
});
self.direction = Math.random() < 0.5 ? -1 : 1; // Randomly assign a direction to each platform
self.update = function () {
// Platforms move horizontally
self.x += 5 * self.direction;
// If platform goes off the edge of the screen, it reappears on the opposite side
if (self.x > 2048) {
self.x = -100;
} else if (self.x < -100) {
self.x = 2048;
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
var earGraphics = self.attachAsset('Ear', {
anchorX: 0.5,
anchorY: 1
});
earGraphics.y = -playerGraphics.height / 2;
earGraphics.x = 35;
var ear2Graphics = self.attachAsset('Ear2', {
anchorX: 0.5,
anchorY: 1
});
ear2Graphics.y = -playerGraphics.height / 2;
ear2Graphics.x = earGraphics.x - earGraphics.width;
self.vy = 0; // Vertical velocity
self.jump = function () {
self.vy = -20; // Jump velocity
};
self.update = function () {
self.y += self.vy;
self.vy += 1; // Gravity
if (self.y > 2732) {
// Player fell off the screen
LK.showGameOver();
}
// Add physics to the ear asset
earGraphics.rotation += 0.1; // Rotate the ear asset
if (earGraphics.rotation > 0.5) {
earGraphics.rotation = -0.5; // Reset the rotation when it reaches a certain point
}
// Add physics to the ear2 asset
ear2Graphics.rotation += 0.1; // Rotate the ear2 asset
if (ear2Graphics.rotation > 0.5) {
ear2Graphics.rotation = -0.5; // Reset the rotation when it reaches a certain point
}
};
});
// StartingPlatform class
var StartingPlatform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.attachAsset('StartPlatform', {
anchorX: 0.5,
anchorY: 0.5
});
self.disappear = function () {
self.destroy();
};
});
/****
* Initialize Game
****/
var game = new LK.Game();
/****
* Game Code
****/
var bg = game.attachAsset('BG', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
// Initialize arrays and variables
var platforms = [];
var player;
var score = 0;
var scoreTxt;
var jumpLimit = 100; // Player starts with 100 jumps
// Create initial platforms
function createInitialPlatforms() {
for (var i = 0; i < 10; i++) {
var platform;
if (i === 0) {
platform = new StartingPlatform();
} else {
platform = new Platform();
}
platform.x = Math.random() * 2048;
platform.y = 2732 - i * 100;
platforms.push(platform);
game.addChild(platform);
}
}
// Create player
function createPlayer() {
player = new Player();
player.x = 1024; // Center horizontally
player.y = 2000; // Start near the bottom
game.addChild(player);
}
// Create score text
function createScoreText() {
scoreTxt = new Text2('0', {
size: 86,
fill: "#000000",
font: "bold 86px Arial"
});
scoreTxt.anchor.set(1, 1);
LK.gui.bottomRight.addChild(scoreTxt);
}
// Create jump limit bar
function createJumpLimitBar() {
jumpLimitBar = LK.getAsset('jumpLimitBar', {
width: 50,
height: jumpLimit * 10,
color: 0x00ff00,
shape: 'box',
anchorX: 0,
anchorY: 0
});
jumpLimitBar.x = 0;
jumpLimitBar.y = 0;
LK.gui.left.addChild(jumpLimitBar);
game.addChild(jumpLimitBar);
}
// Initialize game elements
createInitialPlatforms();
createPlayer();
createScoreText();
createJumpLimitBar();
// Add moon asset to top center of screen
var moon = game.attachAsset('Moon', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 200
});
// Add sparkle asset to top center of screen and set its initial alpha to 0
var sparkle = game.attachAsset('Sparkle', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 200,
alpha: 0
});
// Handle player jump on touch
game.down = function (x, y, obj) {
if (jumpLimit > 0) {
player.jump();
if (platforms[0] instanceof StartingPlatform) {
platforms[0].disappear();
platforms.shift();
}
// Play jump sound when player jumps
LK.getSound('Jump').play();
jumpLimit -= 13; // Increase the rate at which the jump limit bar depletes
jumpLimitBar.height = jumpLimit * 20; // Reflect the jump limit increase in the jump limit bar
jumpLimitBar.y = 2732 - jumpLimitBar.height;
} else {
jumpLimit += 0.5; // Restore the jump limit bar
jumpLimitBar.height = jumpLimit * 20;
jumpLimitBar.y = 2732 - jumpLimitBar.height;
}
};
// Update game every tick
game.update = function () {
player.update();
for (var i = 0; i < platforms.length; i++) {
if (player.intersects(platforms[i])) {
if (player.vy > 0) {
// Player is moving downwards
player.vy = -10; // Knockback effect
} else {
player.jump();
score++;
scoreTxt.setText(score);
}
}
}
// Check if player hits the top of the screen or the moon
if (player.y <= 0 || player.intersects(moon)) {
score++;
scoreTxt.setText(score);
sparkle.alpha = 1;
sparkle.rotation += 0.05;
var fadeOutTimer = LK.setInterval(function () {
sparkle.alpha -= 0.02;
sparkle.rotation += 0.1;
if (sparkle.alpha <= 0) {
LK.clearInterval(fadeOutTimer);
}
}, 10);
// Play chime sound when player hits the moon
LK.getSound('Chime').play();
}
for (var i = platforms.length - 1; i >= 0; i--) {
if (platforms[i].y > 2732) {
platforms[i].destroy();
platforms.splice(i, 1);
var newPlatform = new Platform();
newPlatform.x = Math.random() * 2048;
newPlatform.y = (moon.y + moon.height + newPlatform.height) * 0.75; // Start platform just below the moon and limit to the middle of the screen
platforms.push(newPlatform);
game.addChild(newPlatform);
}
}
// Restore the jump limit bar gradually over time
if (jumpLimit < 100) {
jumpLimit += 0.5;
jumpLimitBar.height = jumpLimit * 20;
jumpLimitBar.y = 2732 - jumpLimitBar.height;
}
};
A pixel art moon, crescent, pale yellow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Rabbit and moon themed start button. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
In game comic sparkles, a circle ring of stars and sparkles ✨ pixel art, pale yellow, action lines. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.