/**** * Classes ****/ // Define the Player class var Player = Container.expand(function () { var self = Container.call(this); var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1); self.velocityY = 0; self.velocityX = 0; self.isOnGround = false; self.jump = function () { self.velocityY = -15 * gameSpeedMultiplier; // Jump force with speed multiplier }; self.update = function () { self.x += self.velocityX; // Prevent player from going beyond the right side of the screen if (self.x > game.width - playerGraphics.width) { self.x = game.width - playerGraphics.width; } // Prevent player from going beyond the left side of the screen if (self.x < 0) { self.x = 0; } self.y += self.velocityY; // Prevent player from going above the top of the screen if (self.y < 0) { self.y = 0; self.velocityY = 0; } self.velocityY += 0.5 * gameSpeedMultiplier; // Gravity with speed multiplier // Check for ground and set game over if player is at the bottom of the screen if (self.y > game.height - playerGraphics.height) { // Flash screen grey for 1 second (1000ms) to show game over LK.effects.flashScreen(0x808080, 1000); LK.showGameOver(); } }; }); // Define the Platform class var Platform = Container.expand(function () { var self = Container.call(this); var platformGraphics = self.createAsset('platform', 'Platform', 0.5, 1); self.speed = (Math.random() * 3 + 1) * 2; // Random speed between 2 and 8, doubled from original self.rockingAngle = 0; // Starting angle for rocking motion self.rockingSpeed = Math.random() * 0.1 + 0.05; // Random rocking speed between 0.05 and 0.15 self.update = function () { self.y += self.speed * gameSpeedMultiplier; // Move platform down at its own speed with multiplier self.rockingAngle += self.rockingSpeed; // Update rocking angle self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle }; self.setInitialPosition = function (x, y) { self.x = x; self.y = y; }; }); // Define the MovingPlatform class var MovingPlatform = Container.expand(function () { var self = Container.call(this); var movingPlatformGraphics = self.createAsset('moving_platform', 'Moving Platform', 0.5, 1); self.speed = (Math.random() * 2 + 1) * 2; // Random speed between 2 and 6 self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction self.setInitialPosition = function (x, y) { self.x = x; self.y = y; }; self.update = function () { self.x += self.direction * gameSpeedMultiplier; self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set self.rockingAngle += self.rockingSpeed; // Update rocking angle self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle // Change direction if it hits the edges of the screen if (self.x > game.width - movingPlatformGraphics.width || self.x < 0) { self.direction *= -1; } }; }); // Define the FastMovingPlatform class var FastMovingPlatform = Container.expand(function () { var self = Container.call(this); var fastMovingPlatformGraphics = self.createAsset('fast_moving_platform', 'Fast Moving Platform', 0.5, 1); self.speed = (Math.random() * 2 + 3) * 2; // Random speed between 6 and 10 self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction self.setInitialPosition = function (x, y) { self.x = x; self.y = y; }; self.update = function () { self.x += self.direction * self.speed * gameSpeedMultiplier; self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set self.rockingAngle += self.rockingSpeed; // Update rocking angle self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle // Change direction if it hits the edges of the screen if (self.x > game.width - fastMovingPlatformGraphics.width || self.x < 0) { self.direction *= -1; } }; }); // Define the BouncingPlatform class var BouncingPlatform = Container.expand(function () { var self = Container.call(this); var bouncingPlatformGraphics = self.createAsset('bouncing_platform', 'Bouncing Platform', 0.5, 1); self.speed = (Math.random() * 2 + 4) * 2; // Random speed between 8 and 12 self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction self.bounceHeight = Math.random() * 100 + 50; // Random bounce height between 50 and 150 self.bounceSpeed = Math.random() * 0.5 + 0.5; // Random bounce speed between 0.5 and 1 self.setInitialPosition = function (x, y) { self.x = x; self.y = y; self.originalY = y; }; self.update = function () { self.x += self.direction * self.speed * gameSpeedMultiplier; self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set self.rockingAngle += self.rockingSpeed; // Update rocking angle self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle // Bounce up and down over time self.y = self.originalY + Math.sin(Date.now() * self.bounceSpeed) * self.bounceHeight; // Change direction if it hits the edges of the screen if (self.x > game.width - bouncingPlatformGraphics.width || self.x < 0) { self.direction *= -1; } }; }); // Define the UltraFastMovingPlatform class var UltraFastMovingPlatform = Container.expand(function () { var self = Container.call(this); var ultraFastMovingPlatformGraphics = self.createAsset('ultra_fast_moving_platform', 'Ultra Fast Moving Platform', 0.5, 1); self.speed = (Math.random() * 2 + 5) * 2; // Random speed between 10 and 14 self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction self.setInitialPosition = function (x, y) { self.x = x; self.y = y; }; self.update = function () { self.x += self.direction * self.speed * gameSpeedMultiplier; self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set self.rockingAngle += self.rockingSpeed; // Update rocking angle self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle // Change direction if it hits the edges of the screen if (self.x > game.width - ultraFastMovingPlatformGraphics.width || self.x < 0) { self.direction *= -1; } }; }); /**** * Initialize Game ****/ // Store the start time of the game var game = new LK.Game({ backgroundColor: 0x000000 // Init game with black background }); /**** * Game Code ****/ var startTime = Date.now(); // Initialize the point counter var pointCounterTxt = new Text2('0', { size: 75, fill: "#ffffff" }); pointCounterTxt.anchor.set(1, 0); LK.gui.topRight.addChild(pointCounterTxt); // Attach pointCounterTxt to the top right of the screen. var startTime = Date.now(); // Store the start time of the game var timeCounterTxt = new Text2('0', { size: 75, fill: "#ffffff" }); timeCounterTxt.anchor.set(0, 0); LK.gui.topLeft.addChild(timeCounterTxt); // Attach timeCounterTxt to the top left of the screen. // Initialize important asset arrays var platforms = []; var player; // Initialize game speed multiplier var gameSpeedMultiplier = 1; // Create the player player = game.addChild(new Player()); player.x = game.width / 2; player.y = game.height / 2; // Create initial platforms var initialPlatformY = game.height - 300; for (var i = 0; i < 7; i++) { var platform; var platformType = Math.random(); if (platformType < 0.25) { platform = new MovingPlatform(); } else if (platformType < 0.5) { platform = new Platform(); } else if (platformType < 0.65) { platform = new FastMovingPlatform(); } else if (platformType < 0.85) { platform = new BouncingPlatform(); } else { platform = new UltraFastMovingPlatform(); } var randomX = Math.random() * (game.width - platform.width) + platform.width / 2; platform.setInitialPosition(randomX, initialPlatformY - i * 300); platforms.push(platform); game.addChild(platform); } // Event listener for touch events on the game area game.on('down', function (obj) { var touchPosition = obj.event.getLocalPosition(game); if (touchPosition.x < game.width / 2) { player.velocityX = -10; } else { player.velocityX = 10; } player.jump(); }); game.on('up', function (obj) { player.velocityX = 0; }); // Main game update loop LK.on('tick', function () { player.update(); // Update platforms for (var i = 0; i < platforms.length; i++) { var platform = platforms[i]; platform.y += platform.speed; // Move platforms down at their own speed if (platform instanceof MovingPlatform) { platform.update(); // Update moving platforms } // Recycle platforms if (platform.y > game.height) { var randomX = Math.random() * (game.width - platform.width) + platform.width / 2; platform.x = randomX; platform.y = -50; } // Check for collision with player using the player's next position to predict collision var playerNextY = player.y + player.velocityY; if (player.intersects(platform) && player.velocityY > 0 && playerNextY + player.height > platform.y && player.y < platform.y) { player.isOnGround = true; player.velocityY = 0; player.y = platform.y - player.height; // Award points if the platform is a FastMovingPlatform or UltraFastMovingPlatform and update the score counter if (platform instanceof MovingPlatform || platform instanceof FastMovingPlatform || platform instanceof UltraFastMovingPlatform) { var pointsAwarded = platform instanceof UltraFastMovingPlatform ? 50 : 10; var previousScore = LK.getScore(); LK.setScore(previousScore + pointsAwarded); pointCounterTxt.setText(LK.getScore().toString()); // Increase game speed multiplier every 100 points if (Math.floor(previousScore / 100) < Math.floor(LK.getScore() / 100)) { gameSpeedMultiplier += 0.1; } // Add a blue visual effect when colliding with these platforms LK.effects.flashObject(player, 0x0000ff, 500); } } } // Update the time counter var currentTime = Date.now(); var elapsedTime = ((currentTime - startTime) / 1000).toFixed(1); // Elapsed time in seconds with one decimal place timeCounterTxt.setText(elapsedTime + 's'); // Check for game over condition if (player.y < -player.height) { // Flash screen grey for 1 second (1000ms) to show game over LK.effects.flashScreen(0x808080, 1000); LK.showGameOver(); } });
/****
* Classes
****/
// Define the Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.createAsset('player', 'Player character', 0.5, 1);
self.velocityY = 0;
self.velocityX = 0;
self.isOnGround = false;
self.jump = function () {
self.velocityY = -15 * gameSpeedMultiplier; // Jump force with speed multiplier
};
self.update = function () {
self.x += self.velocityX;
// Prevent player from going beyond the right side of the screen
if (self.x > game.width - playerGraphics.width) {
self.x = game.width - playerGraphics.width;
}
// Prevent player from going beyond the left side of the screen
if (self.x < 0) {
self.x = 0;
}
self.y += self.velocityY;
// Prevent player from going above the top of the screen
if (self.y < 0) {
self.y = 0;
self.velocityY = 0;
}
self.velocityY += 0.5 * gameSpeedMultiplier; // Gravity with speed multiplier
// Check for ground and set game over if player is at the bottom of the screen
if (self.y > game.height - playerGraphics.height) {
// Flash screen grey for 1 second (1000ms) to show game over
LK.effects.flashScreen(0x808080, 1000);
LK.showGameOver();
}
};
});
// Define the Platform class
var Platform = Container.expand(function () {
var self = Container.call(this);
var platformGraphics = self.createAsset('platform', 'Platform', 0.5, 1);
self.speed = (Math.random() * 3 + 1) * 2; // Random speed between 2 and 8, doubled from original
self.rockingAngle = 0; // Starting angle for rocking motion
self.rockingSpeed = Math.random() * 0.1 + 0.05; // Random rocking speed between 0.05 and 0.15
self.update = function () {
self.y += self.speed * gameSpeedMultiplier; // Move platform down at its own speed with multiplier
self.rockingAngle += self.rockingSpeed; // Update rocking angle
self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle
};
self.setInitialPosition = function (x, y) {
self.x = x;
self.y = y;
};
});
// Define the MovingPlatform class
var MovingPlatform = Container.expand(function () {
var self = Container.call(this);
var movingPlatformGraphics = self.createAsset('moving_platform', 'Moving Platform', 0.5, 1);
self.speed = (Math.random() * 2 + 1) * 2; // Random speed between 2 and 6
self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction
self.setInitialPosition = function (x, y) {
self.x = x;
self.y = y;
};
self.update = function () {
self.x += self.direction * gameSpeedMultiplier;
self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set
self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set
self.rockingAngle += self.rockingSpeed; // Update rocking angle
self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle
// Change direction if it hits the edges of the screen
if (self.x > game.width - movingPlatformGraphics.width || self.x < 0) {
self.direction *= -1;
}
};
});
// Define the FastMovingPlatform class
var FastMovingPlatform = Container.expand(function () {
var self = Container.call(this);
var fastMovingPlatformGraphics = self.createAsset('fast_moving_platform', 'Fast Moving Platform', 0.5, 1);
self.speed = (Math.random() * 2 + 3) * 2; // Random speed between 6 and 10
self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction
self.setInitialPosition = function (x, y) {
self.x = x;
self.y = y;
};
self.update = function () {
self.x += self.direction * self.speed * gameSpeedMultiplier;
self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set
self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set
self.rockingAngle += self.rockingSpeed; // Update rocking angle
self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle
// Change direction if it hits the edges of the screen
if (self.x > game.width - fastMovingPlatformGraphics.width || self.x < 0) {
self.direction *= -1;
}
};
});
// Define the BouncingPlatform class
var BouncingPlatform = Container.expand(function () {
var self = Container.call(this);
var bouncingPlatformGraphics = self.createAsset('bouncing_platform', 'Bouncing Platform', 0.5, 1);
self.speed = (Math.random() * 2 + 4) * 2; // Random speed between 8 and 12
self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction
self.bounceHeight = Math.random() * 100 + 50; // Random bounce height between 50 and 150
self.bounceSpeed = Math.random() * 0.5 + 0.5; // Random bounce speed between 0.5 and 1
self.setInitialPosition = function (x, y) {
self.x = x;
self.y = y;
self.originalY = y;
};
self.update = function () {
self.x += self.direction * self.speed * gameSpeedMultiplier;
self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set
self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set
self.rockingAngle += self.rockingSpeed; // Update rocking angle
self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle
// Bounce up and down over time
self.y = self.originalY + Math.sin(Date.now() * self.bounceSpeed) * self.bounceHeight;
// Change direction if it hits the edges of the screen
if (self.x > game.width - bouncingPlatformGraphics.width || self.x < 0) {
self.direction *= -1;
}
};
});
// Define the UltraFastMovingPlatform class
var UltraFastMovingPlatform = Container.expand(function () {
var self = Container.call(this);
var ultraFastMovingPlatformGraphics = self.createAsset('ultra_fast_moving_platform', 'Ultra Fast Moving Platform', 0.5, 1);
self.speed = (Math.random() * 2 + 5) * 2; // Random speed between 10 and 14
self.direction = Math.random() > 0.5 ? 1 : -1; // Randomly choose initial direction
self.setInitialPosition = function (x, y) {
self.x = x;
self.y = y;
};
self.update = function () {
self.x += self.direction * self.speed * gameSpeedMultiplier;
self.rockingAngle = self.rockingAngle || 0; // Initialize rocking angle if not set
self.rockingSpeed = self.rockingSpeed || Math.random() * 0.1 + 0.05; // Initialize rocking speed if not set
self.rockingAngle += self.rockingSpeed; // Update rocking angle
self.rotation = Math.sin(self.rockingAngle) * 0.1; // Apply rocking motion based on angle
// Change direction if it hits the edges of the screen
if (self.x > game.width - ultraFastMovingPlatformGraphics.width || self.x < 0) {
self.direction *= -1;
}
};
});
/****
* Initialize Game
****/
// Store the start time of the game
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
var startTime = Date.now();
// Initialize the point counter
var pointCounterTxt = new Text2('0', {
size: 75,
fill: "#ffffff"
});
pointCounterTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(pointCounterTxt); // Attach pointCounterTxt to the top right of the screen.
var startTime = Date.now(); // Store the start time of the game
var timeCounterTxt = new Text2('0', {
size: 75,
fill: "#ffffff"
});
timeCounterTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(timeCounterTxt); // Attach timeCounterTxt to the top left of the screen.
// Initialize important asset arrays
var platforms = [];
var player;
// Initialize game speed multiplier
var gameSpeedMultiplier = 1;
// Create the player
player = game.addChild(new Player());
player.x = game.width / 2;
player.y = game.height / 2;
// Create initial platforms
var initialPlatformY = game.height - 300;
for (var i = 0; i < 7; i++) {
var platform;
var platformType = Math.random();
if (platformType < 0.25) {
platform = new MovingPlatform();
} else if (platformType < 0.5) {
platform = new Platform();
} else if (platformType < 0.65) {
platform = new FastMovingPlatform();
} else if (platformType < 0.85) {
platform = new BouncingPlatform();
} else {
platform = new UltraFastMovingPlatform();
}
var randomX = Math.random() * (game.width - platform.width) + platform.width / 2;
platform.setInitialPosition(randomX, initialPlatformY - i * 300);
platforms.push(platform);
game.addChild(platform);
}
// Event listener for touch events on the game area
game.on('down', function (obj) {
var touchPosition = obj.event.getLocalPosition(game);
if (touchPosition.x < game.width / 2) {
player.velocityX = -10;
} else {
player.velocityX = 10;
}
player.jump();
});
game.on('up', function (obj) {
player.velocityX = 0;
});
// Main game update loop
LK.on('tick', function () {
player.update();
// Update platforms
for (var i = 0; i < platforms.length; i++) {
var platform = platforms[i];
platform.y += platform.speed; // Move platforms down at their own speed
if (platform instanceof MovingPlatform) {
platform.update(); // Update moving platforms
}
// Recycle platforms
if (platform.y > game.height) {
var randomX = Math.random() * (game.width - platform.width) + platform.width / 2;
platform.x = randomX;
platform.y = -50;
}
// Check for collision with player using the player's next position to predict collision
var playerNextY = player.y + player.velocityY;
if (player.intersects(platform) && player.velocityY > 0 && playerNextY + player.height > platform.y && player.y < platform.y) {
player.isOnGround = true;
player.velocityY = 0;
player.y = platform.y - player.height;
// Award points if the platform is a FastMovingPlatform or UltraFastMovingPlatform and update the score counter
if (platform instanceof MovingPlatform || platform instanceof FastMovingPlatform || platform instanceof UltraFastMovingPlatform) {
var pointsAwarded = platform instanceof UltraFastMovingPlatform ? 50 : 10;
var previousScore = LK.getScore();
LK.setScore(previousScore + pointsAwarded);
pointCounterTxt.setText(LK.getScore().toString());
// Increase game speed multiplier every 100 points
if (Math.floor(previousScore / 100) < Math.floor(LK.getScore() / 100)) {
gameSpeedMultiplier += 0.1;
}
// Add a blue visual effect when colliding with these platforms
LK.effects.flashObject(player, 0x0000ff, 500);
}
}
}
// Update the time counter
var currentTime = Date.now();
var elapsedTime = ((currentTime - startTime) / 1000).toFixed(1); // Elapsed time in seconds with one decimal place
timeCounterTxt.setText(elapsedTime + 's');
// Check for game over condition
if (player.y < -player.height) {
// Flash screen grey for 1 second (1000ms) to show game over
LK.effects.flashScreen(0x808080, 1000);
LK.showGameOver();
}
});
small black umbrella. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
white umbrella. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
erase
water drop with anime style eyes. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.