/****
* 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
});
// Random cloud properties
self.speed = Math.random() * 2 + 1; // Speed between 1-3
cloudGraphics.scaleX = Math.random() * 0.8 + 0.6; // Scale between 0.6-1.4
cloudGraphics.scaleY = Math.random() * 0.6 + 0.4; // Scale between 0.4-1.0
cloudGraphics.alpha = Math.random() * 0.4 + 0.6; // Alpha between 0.6-1.0
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Meteor = Container.expand(function () {
var self = Container.call(this);
var meteorGraphics = self.attachAsset('meteor', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.gravity = 0.8;
self.velocity = 0;
// Add warning indicator
self.warningTimer = 60; // 1 second warning
meteorGraphics.alpha = 0.7;
meteorGraphics.tint = 0xff6666;
self.update = function () {
if (self.warningTimer > 0) {
self.warningTimer--;
// Flash warning
meteorGraphics.alpha = 0.3 + 0.4 * Math.sin(self.warningTimer * 0.3);
} else {
// Start falling
self.velocity += self.gravity;
self.y += self.velocity;
meteorGraphics.alpha = 1.0;
meteorGraphics.tint = 0xffffff;
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleType = type || 'ground';
if (obstacleType === 'ground') {
var obstacleGraphics = self.attachAsset('groundObstacle', {
anchorX: 0.5,
anchorY: 1.0
});
self.height = 80;
} else {
var obstacleGraphics = self.attachAsset('airObstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.height = 40;
}
self.obstacleType = obstacleType;
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.isJumping = false;
self.isDucking = false;
self.jumpVelocity = 0;
self.gravity = 1.2;
self.jumpPower = -18;
self.normalHeight = 80;
self.duckHeight = 40;
self.groundY = 0;
// Running animation properties
self.runAnimationTime = 0;
self.runAnimationSpeed = 0.2;
self.runBobAmount = 3;
self.runTiltAmount = 0.1;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
}
};
self.startDuck = function () {
if (!self.isDucking && !self.isJumping) {
self.isDucking = true;
playerGraphics.height = self.duckHeight;
LK.getSound('duck').play();
}
};
self.stopDuck = function () {
if (self.isDucking) {
self.isDucking = false;
playerGraphics.height = self.normalHeight;
}
};
self.update = function () {
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
}
} else if (!self.isDucking) {
// Running animation when on ground and not ducking
self.runAnimationTime += self.runAnimationSpeed;
var bobOffset = Math.sin(self.runAnimationTime) * self.runBobAmount;
var tiltOffset = Math.sin(self.runAnimationTime * 2) * self.runTiltAmount;
playerGraphics.y = bobOffset;
playerGraphics.rotation = tiltOffset;
} else {
// Reset animation when ducking
playerGraphics.y = 0;
playerGraphics.rotation = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameSpeed = 8;
var speedIncrement = 0.01;
var maxSpeed = 20;
var groundY = 2732 - 200;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnDelay = 90;
var minSpawnDelay = 45;
var distance = 0;
var isGameRunning = true;
var isPressed = false;
var clouds = [];
var cloudSpawnTimer = 0;
var cloudSpawnDelay = 120;
var meteors = [];
var lastMeteorScore = 0;
var meteorInterval = 200;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: groundY + 20
}));
// Create player
var player = game.addChild(new Player());
player.x = 300;
player.y = groundY;
player.groundY = groundY;
// Create score display
var scoreText = new Text2('0', {
size: 100,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create distance display
var distanceText = new Text2('0m', {
size: 60,
fill: 0x333333
});
distanceText.anchor.set(1, 0);
distanceText.x = -20;
distanceText.y = 20;
LK.gui.topRight.addChild(distanceText);
function spawnObstacle() {
var obstacleType = Math.random() < 0.6 ? 'ground' : 'air';
var obstacle = new Obstacle(obstacleType);
obstacle.x = 2048 + 100;
if (obstacleType === 'ground') {
obstacle.y = groundY;
} else {
obstacle.y = groundY - 120;
}
obstacle.speed = gameSpeed;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnCloud() {
var cloud = new Cloud();
cloud.x = 2048 + 150;
cloud.y = Math.random() * 800 + 200; // Random height in upper portion of screen
clouds.push(cloud);
game.addChild(cloud);
}
function updateClouds() {
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
if (cloud.x < -200) {
cloud.destroy();
clouds.splice(i, 1);
}
}
}
function spawnMeteor() {
var meteor = new Meteor();
meteor.x = player.x + Math.random() * 400 - 200; // Random position around player
meteor.y = -100; // Start above screen
meteors.push(meteor);
game.addChild(meteor);
LK.getSound('meteor').play();
}
function updateMeteors() {
for (var i = meteors.length - 1; i >= 0; i--) {
var meteor = meteors[i];
if (meteor.y > 2732 + 100) {
meteor.destroy();
meteors.splice(i, 1);
}
}
}
function checkMeteorSpawn() {
var currentScore = LK.getScore();
if (currentScore >= lastMeteorScore + meteorInterval) {
spawnMeteor();
lastMeteorScore = currentScore;
}
}
// Spawn initial clouds
for (var i = 0; i < 5; i++) {
var initialCloud = new Cloud();
initialCloud.x = Math.random() * 2048;
initialCloud.y = Math.random() * 800 + 200;
clouds.push(initialCloud);
game.addChild(initialCloud);
}
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (player.intersects(obstacle)) {
LK.getSound('hit').play();
isGameRunning = false;
LK.showGameOver();
return;
}
}
// Check meteor collisions
for (var j = 0; j < meteors.length; j++) {
var meteor = meteors[j];
if (meteor.warningTimer <= 0 && player.intersects(meteor)) {
LK.getSound('hit').play();
isGameRunning = false;
LK.showGameOver();
return;
}
}
}
function updateObstacles() {
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = gameSpeed;
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
LK.setScore(LK.getScore() + 10);
}
}
}
function updateGameSpeed() {
if (gameSpeed < maxSpeed) {
gameSpeed += speedIncrement;
}
if (obstacleSpawnDelay > minSpawnDelay) {
obstacleSpawnDelay = Math.max(minSpawnDelay, 90 - distance / 100);
}
}
game.down = function (x, y, obj) {
if (isGameRunning) {
isPressed = true;
player.jump();
}
};
game.up = function (x, y, obj) {
isPressed = false;
if (isGameRunning) {
player.stopDuck();
}
};
game.update = function () {
if (!isGameRunning) return;
// Handle ducking
if (isPressed && !player.isJumping) {
player.startDuck();
} else if (!isPressed) {
player.stopDuck();
}
// Update distance and score
distance += gameSpeed * 0.1;
distanceText.setText(Math.floor(distance) + 'm');
scoreText.setText(LK.getScore());
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnDelay) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Spawn clouds
cloudSpawnTimer++;
if (cloudSpawnTimer >= cloudSpawnDelay) {
spawnCloud();
cloudSpawnTimer = 0;
}
// Update game elements
updateObstacles();
updateClouds();
updateMeteors();
updateGameSpeed();
checkMeteorSpawn();
checkCollisions();
}; /****
* 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
});
// Random cloud properties
self.speed = Math.random() * 2 + 1; // Speed between 1-3
cloudGraphics.scaleX = Math.random() * 0.8 + 0.6; // Scale between 0.6-1.4
cloudGraphics.scaleY = Math.random() * 0.6 + 0.4; // Scale between 0.4-1.0
cloudGraphics.alpha = Math.random() * 0.4 + 0.6; // Alpha between 0.6-1.0
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Meteor = Container.expand(function () {
var self = Container.call(this);
var meteorGraphics = self.attachAsset('meteor', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 12;
self.gravity = 0.8;
self.velocity = 0;
// Add warning indicator
self.warningTimer = 60; // 1 second warning
meteorGraphics.alpha = 0.7;
meteorGraphics.tint = 0xff6666;
self.update = function () {
if (self.warningTimer > 0) {
self.warningTimer--;
// Flash warning
meteorGraphics.alpha = 0.3 + 0.4 * Math.sin(self.warningTimer * 0.3);
} else {
// Start falling
self.velocity += self.gravity;
self.y += self.velocity;
meteorGraphics.alpha = 1.0;
meteorGraphics.tint = 0xffffff;
}
};
return self;
});
var Obstacle = Container.expand(function (type) {
var self = Container.call(this);
var obstacleType = type || 'ground';
if (obstacleType === 'ground') {
var obstacleGraphics = self.attachAsset('groundObstacle', {
anchorX: 0.5,
anchorY: 1.0
});
self.height = 80;
} else {
var obstacleGraphics = self.attachAsset('airObstacle', {
anchorX: 0.5,
anchorY: 0.5
});
self.height = 40;
}
self.obstacleType = obstacleType;
self.speed = gameSpeed;
self.update = function () {
self.x -= self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 1.0
});
self.isJumping = false;
self.isDucking = false;
self.jumpVelocity = 0;
self.gravity = 1.2;
self.jumpPower = -18;
self.normalHeight = 80;
self.duckHeight = 40;
self.groundY = 0;
// Running animation properties
self.runAnimationTime = 0;
self.runAnimationSpeed = 0.2;
self.runBobAmount = 3;
self.runTiltAmount = 0.1;
self.jump = function () {
if (!self.isJumping) {
self.isJumping = true;
self.jumpVelocity = self.jumpPower;
LK.getSound('jump').play();
}
};
self.startDuck = function () {
if (!self.isDucking && !self.isJumping) {
self.isDucking = true;
playerGraphics.height = self.duckHeight;
LK.getSound('duck').play();
}
};
self.stopDuck = function () {
if (self.isDucking) {
self.isDucking = false;
playerGraphics.height = self.normalHeight;
}
};
self.update = function () {
if (self.isJumping) {
self.jumpVelocity += self.gravity;
self.y += self.jumpVelocity;
if (self.y >= self.groundY) {
self.y = self.groundY;
self.isJumping = false;
self.jumpVelocity = 0;
}
} else if (!self.isDucking) {
// Running animation when on ground and not ducking
self.runAnimationTime += self.runAnimationSpeed;
var bobOffset = Math.sin(self.runAnimationTime) * self.runBobAmount;
var tiltOffset = Math.sin(self.runAnimationTime * 2) * self.runTiltAmount;
playerGraphics.y = bobOffset;
playerGraphics.rotation = tiltOffset;
} else {
// Reset animation when ducking
playerGraphics.y = 0;
playerGraphics.rotation = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var gameSpeed = 8;
var speedIncrement = 0.01;
var maxSpeed = 20;
var groundY = 2732 - 200;
var obstacles = [];
var obstacleSpawnTimer = 0;
var obstacleSpawnDelay = 90;
var minSpawnDelay = 45;
var distance = 0;
var isGameRunning = true;
var isPressed = false;
var clouds = [];
var cloudSpawnTimer = 0;
var cloudSpawnDelay = 120;
var meteors = [];
var lastMeteorScore = 0;
var meteorInterval = 200;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: groundY + 20
}));
// Create player
var player = game.addChild(new Player());
player.x = 300;
player.y = groundY;
player.groundY = groundY;
// Create score display
var scoreText = new Text2('0', {
size: 100,
fill: 0x000000
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
// Create distance display
var distanceText = new Text2('0m', {
size: 60,
fill: 0x333333
});
distanceText.anchor.set(1, 0);
distanceText.x = -20;
distanceText.y = 20;
LK.gui.topRight.addChild(distanceText);
function spawnObstacle() {
var obstacleType = Math.random() < 0.6 ? 'ground' : 'air';
var obstacle = new Obstacle(obstacleType);
obstacle.x = 2048 + 100;
if (obstacleType === 'ground') {
obstacle.y = groundY;
} else {
obstacle.y = groundY - 120;
}
obstacle.speed = gameSpeed;
obstacles.push(obstacle);
game.addChild(obstacle);
}
function spawnCloud() {
var cloud = new Cloud();
cloud.x = 2048 + 150;
cloud.y = Math.random() * 800 + 200; // Random height in upper portion of screen
clouds.push(cloud);
game.addChild(cloud);
}
function updateClouds() {
for (var i = clouds.length - 1; i >= 0; i--) {
var cloud = clouds[i];
if (cloud.x < -200) {
cloud.destroy();
clouds.splice(i, 1);
}
}
}
function spawnMeteor() {
var meteor = new Meteor();
meteor.x = player.x + Math.random() * 400 - 200; // Random position around player
meteor.y = -100; // Start above screen
meteors.push(meteor);
game.addChild(meteor);
LK.getSound('meteor').play();
}
function updateMeteors() {
for (var i = meteors.length - 1; i >= 0; i--) {
var meteor = meteors[i];
if (meteor.y > 2732 + 100) {
meteor.destroy();
meteors.splice(i, 1);
}
}
}
function checkMeteorSpawn() {
var currentScore = LK.getScore();
if (currentScore >= lastMeteorScore + meteorInterval) {
spawnMeteor();
lastMeteorScore = currentScore;
}
}
// Spawn initial clouds
for (var i = 0; i < 5; i++) {
var initialCloud = new Cloud();
initialCloud.x = Math.random() * 2048;
initialCloud.y = Math.random() * 800 + 200;
clouds.push(initialCloud);
game.addChild(initialCloud);
}
function checkCollisions() {
for (var i = 0; i < obstacles.length; i++) {
var obstacle = obstacles[i];
if (player.intersects(obstacle)) {
LK.getSound('hit').play();
isGameRunning = false;
LK.showGameOver();
return;
}
}
// Check meteor collisions
for (var j = 0; j < meteors.length; j++) {
var meteor = meteors[j];
if (meteor.warningTimer <= 0 && player.intersects(meteor)) {
LK.getSound('hit').play();
isGameRunning = false;
LK.showGameOver();
return;
}
}
}
function updateObstacles() {
for (var i = obstacles.length - 1; i >= 0; i--) {
var obstacle = obstacles[i];
obstacle.speed = gameSpeed;
if (obstacle.x < -100) {
obstacle.destroy();
obstacles.splice(i, 1);
LK.setScore(LK.getScore() + 10);
}
}
}
function updateGameSpeed() {
if (gameSpeed < maxSpeed) {
gameSpeed += speedIncrement;
}
if (obstacleSpawnDelay > minSpawnDelay) {
obstacleSpawnDelay = Math.max(minSpawnDelay, 90 - distance / 100);
}
}
game.down = function (x, y, obj) {
if (isGameRunning) {
isPressed = true;
player.jump();
}
};
game.up = function (x, y, obj) {
isPressed = false;
if (isGameRunning) {
player.stopDuck();
}
};
game.update = function () {
if (!isGameRunning) return;
// Handle ducking
if (isPressed && !player.isJumping) {
player.startDuck();
} else if (!isPressed) {
player.stopDuck();
}
// Update distance and score
distance += gameSpeed * 0.1;
distanceText.setText(Math.floor(distance) + 'm');
scoreText.setText(LK.getScore());
// Spawn obstacles
obstacleSpawnTimer++;
if (obstacleSpawnTimer >= obstacleSpawnDelay) {
spawnObstacle();
obstacleSpawnTimer = 0;
}
// Spawn clouds
cloudSpawnTimer++;
if (cloudSpawnTimer >= cloudSpawnDelay) {
spawnCloud();
cloudSpawnTimer = 0;
}
// Update game elements
updateObstacles();
updateClouds();
updateMeteors();
updateGameSpeed();
checkMeteorSpawn();
checkCollisions();
};
brick layer. In-Game asset. 2d. High contrast. No shadows
green road. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
pine tree. In-Game asset. 2d. High contrast. No shadows
running dinosour. In-Game asset. 2d. High contrast. No shadows
draw realistic cloud. In-Game asset. 2d. High contrast. No shadows
draw a falling meteor. In-Game asset. 2d. High contrast. No shadows