/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Block = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = -8;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Cursor = Container.expand(function () {
var self = Container.call(this);
var cursorGraphics = self.attachAsset('cursor', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -14;
self.highJumpPower = -18; // Higher jump for longer press
self.isOnGround = true;
self.groundY = 2632; // Ground level - cursor height
self.jump = function (isHighJump) {
if (self.isOnGround) {
if (isHighJump) {
self.velocityY = self.highJumpPower;
} else {
self.velocityY = self.jumpPower;
}
self.isOnGround = false;
LK.getSound('jump').play();
}
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Check ground collision
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isOnGround = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Difficulty levels - adjusted jump powers to clear blocks with small margin
var difficultyLevels = {
LOW: {
gameSpeed: 6,
spawnInterval: 120,
minSpawnInterval: 60,
jumpPower: -15,
highJumpPower: -20,
gravity: 0.6,
name: "LOW"
},
MEDIUM: {
gameSpeed: 8,
spawnInterval: 90,
minSpawnInterval: 40,
jumpPower: -14,
highJumpPower: -18,
gravity: 0.8,
name: "MEDIUM"
},
HARD: {
gameSpeed: 12,
spawnInterval: 60,
minSpawnInterval: 25,
jumpPower: -13,
highJumpPower: -17,
gravity: 1.0,
name: "HARD"
},
IMPOSSIBLE: {
gameSpeed: 16,
spawnInterval: 40,
minSpawnInterval: 15,
jumpPower: -12,
highJumpPower: -16,
gravity: 1.2,
name: "IMPOSSIBLE"
}
};
var currentDifficulty = difficultyLevels.MEDIUM;
var gameSpeed = currentDifficulty.gameSpeed;
var spawnTimer = 0;
var spawnInterval = currentDifficulty.spawnInterval;
var minSpawnInterval = currentDifficulty.minSpawnInterval;
var speedIncreaseTimer = 0;
var difficultyChangeTimer = 0;
var difficultyOrder = ['LOW', 'MEDIUM', 'HARD', 'IMPOSSIBLE'];
var currentDifficultyIndex = 1;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2632
}));
// Create cursor
var cursor = game.addChild(new Cursor());
cursor.x = 300;
cursor.y = cursor.groundY;
// Apply difficulty settings to cursor with very fast jump
function applyDifficultyToCursor() {
// Set very fast jump power - much faster than original
cursor.jumpPower = -25; // Very fast jump power
cursor.highJumpPower = -30; // Very fast high jump power
cursor.gravity = currentDifficulty.gravity;
}
applyDifficultyToCursor();
// Arrays to track game objects
var blocks = [];
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create difficulty level display
var levelTxt = new Text2('LEVEL: MEDIUM', {
size: 60,
fill: 0xFFFF00
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 120;
LK.gui.top.addChild(levelTxt);
// Create block counter display
var blockCountTxt = new Text2('BLOCKS: 0', {
size: 60,
fill: 0x00FF00
});
blockCountTxt.anchor.set(0.5, 0);
blockCountTxt.y = 200;
LK.gui.top.addChild(blockCountTxt);
// Block counter variable
var blocksCount = 0;
// Game variables
var distance = 0;
var tapStartTime = 0;
var isTapping = false;
var highJumpThreshold = 200; // ms for high jump
function spawnBlock() {
var block = new Block();
block.x = 2200; // Spawn off-screen right
block.y = 2632; // On ground level
blocks.push(block);
game.addChild(block);
}
function updateDifficulty() {
// Progress through difficulty levels every 10 seconds
difficultyChangeTimer++;
if (difficultyChangeTimer >= 600) {
// 10 seconds at 60fps
if (currentDifficultyIndex < difficultyOrder.length - 1) {
currentDifficultyIndex++;
currentDifficulty = difficultyLevels[difficultyOrder[currentDifficultyIndex]];
// Update game parameters
gameSpeed = currentDifficulty.gameSpeed;
spawnInterval = currentDifficulty.spawnInterval;
minSpawnInterval = currentDifficulty.minSpawnInterval;
// Update cursor properties
applyDifficultyToCursor();
// Update level display
levelTxt.setText('LEVEL: ' + currentDifficulty.name);
// Flash screen to indicate level change
LK.effects.flashScreen(0x00ff00, 300);
}
difficultyChangeTimer = 0;
}
// Fine-tune difficulty within current level
speedIncreaseTimer++;
if (speedIncreaseTimer >= 300) {
// Every 5 seconds at 60fps
gameSpeed += 0.3;
if (spawnInterval > minSpawnInterval) {
spawnInterval -= 1;
}
speedIncreaseTimer = 0;
}
}
// Touch controls
game.down = function (x, y, obj) {
tapStartTime = Date.now();
isTapping = true;
// Jump immediately on tap down
cursor.jump(false); // Use normal jump power for instant response
};
game.up = function (x, y, obj) {
if (isTapping) {
isTapping = false;
}
};
game.update = function () {
// Update distance and score
distance += gameSpeed;
LK.setScore(Math.floor(distance / 10));
scoreTxt.setText(LK.getScore());
// Update difficulty
updateDifficulty();
// Spawn blocks
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnBlock();
spawnTimer = 0;
}
// Update blocks and check collisions
for (var i = blocks.length - 1; i >= 0; i--) {
var block = blocks[i];
block.speed = -gameSpeed;
// Remove blocks that are off-screen
if (block.x < -200) {
// Increment block counter when block passes off-screen (successfully avoided)
blocksCount++;
blockCountTxt.setText('BLOCKS: ' + blocksCount);
block.destroy();
blocks.splice(i, 1);
continue;
}
// Check collision with cursor
if (cursor.intersects(block)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Block = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 1.0
});
self.speed = -8;
self.update = function () {
self.x += self.speed;
};
return self;
});
var Cursor = Container.expand(function () {
var self = Container.call(this);
var cursorGraphics = self.attachAsset('cursor', {
anchorX: 0.5,
anchorY: 1.0
});
self.velocityY = 0;
self.gravity = 0.8;
self.jumpPower = -14;
self.highJumpPower = -18; // Higher jump for longer press
self.isOnGround = true;
self.groundY = 2632; // Ground level - cursor height
self.jump = function (isHighJump) {
if (self.isOnGround) {
if (isHighJump) {
self.velocityY = self.highJumpPower;
} else {
self.velocityY = self.jumpPower;
}
self.isOnGround = false;
LK.getSound('jump').play();
}
};
self.update = function () {
// Apply gravity
self.velocityY += self.gravity;
self.y += self.velocityY;
// Check ground collision
if (self.y >= self.groundY) {
self.y = self.groundY;
self.velocityY = 0;
self.isOnGround = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Difficulty levels - adjusted jump powers to clear blocks with small margin
var difficultyLevels = {
LOW: {
gameSpeed: 6,
spawnInterval: 120,
minSpawnInterval: 60,
jumpPower: -15,
highJumpPower: -20,
gravity: 0.6,
name: "LOW"
},
MEDIUM: {
gameSpeed: 8,
spawnInterval: 90,
minSpawnInterval: 40,
jumpPower: -14,
highJumpPower: -18,
gravity: 0.8,
name: "MEDIUM"
},
HARD: {
gameSpeed: 12,
spawnInterval: 60,
minSpawnInterval: 25,
jumpPower: -13,
highJumpPower: -17,
gravity: 1.0,
name: "HARD"
},
IMPOSSIBLE: {
gameSpeed: 16,
spawnInterval: 40,
minSpawnInterval: 15,
jumpPower: -12,
highJumpPower: -16,
gravity: 1.2,
name: "IMPOSSIBLE"
}
};
var currentDifficulty = difficultyLevels.MEDIUM;
var gameSpeed = currentDifficulty.gameSpeed;
var spawnTimer = 0;
var spawnInterval = currentDifficulty.spawnInterval;
var minSpawnInterval = currentDifficulty.minSpawnInterval;
var speedIncreaseTimer = 0;
var difficultyChangeTimer = 0;
var difficultyOrder = ['LOW', 'MEDIUM', 'HARD', 'IMPOSSIBLE'];
var currentDifficultyIndex = 1;
// Create ground
var ground = game.addChild(LK.getAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 2632
}));
// Create cursor
var cursor = game.addChild(new Cursor());
cursor.x = 300;
cursor.y = cursor.groundY;
// Apply difficulty settings to cursor with very fast jump
function applyDifficultyToCursor() {
// Set very fast jump power - much faster than original
cursor.jumpPower = -25; // Very fast jump power
cursor.highJumpPower = -30; // Very fast high jump power
cursor.gravity = currentDifficulty.gravity;
}
applyDifficultyToCursor();
// Arrays to track game objects
var blocks = [];
// Create score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Create difficulty level display
var levelTxt = new Text2('LEVEL: MEDIUM', {
size: 60,
fill: 0xFFFF00
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 120;
LK.gui.top.addChild(levelTxt);
// Create block counter display
var blockCountTxt = new Text2('BLOCKS: 0', {
size: 60,
fill: 0x00FF00
});
blockCountTxt.anchor.set(0.5, 0);
blockCountTxt.y = 200;
LK.gui.top.addChild(blockCountTxt);
// Block counter variable
var blocksCount = 0;
// Game variables
var distance = 0;
var tapStartTime = 0;
var isTapping = false;
var highJumpThreshold = 200; // ms for high jump
function spawnBlock() {
var block = new Block();
block.x = 2200; // Spawn off-screen right
block.y = 2632; // On ground level
blocks.push(block);
game.addChild(block);
}
function updateDifficulty() {
// Progress through difficulty levels every 10 seconds
difficultyChangeTimer++;
if (difficultyChangeTimer >= 600) {
// 10 seconds at 60fps
if (currentDifficultyIndex < difficultyOrder.length - 1) {
currentDifficultyIndex++;
currentDifficulty = difficultyLevels[difficultyOrder[currentDifficultyIndex]];
// Update game parameters
gameSpeed = currentDifficulty.gameSpeed;
spawnInterval = currentDifficulty.spawnInterval;
minSpawnInterval = currentDifficulty.minSpawnInterval;
// Update cursor properties
applyDifficultyToCursor();
// Update level display
levelTxt.setText('LEVEL: ' + currentDifficulty.name);
// Flash screen to indicate level change
LK.effects.flashScreen(0x00ff00, 300);
}
difficultyChangeTimer = 0;
}
// Fine-tune difficulty within current level
speedIncreaseTimer++;
if (speedIncreaseTimer >= 300) {
// Every 5 seconds at 60fps
gameSpeed += 0.3;
if (spawnInterval > minSpawnInterval) {
spawnInterval -= 1;
}
speedIncreaseTimer = 0;
}
}
// Touch controls
game.down = function (x, y, obj) {
tapStartTime = Date.now();
isTapping = true;
// Jump immediately on tap down
cursor.jump(false); // Use normal jump power for instant response
};
game.up = function (x, y, obj) {
if (isTapping) {
isTapping = false;
}
};
game.update = function () {
// Update distance and score
distance += gameSpeed;
LK.setScore(Math.floor(distance / 10));
scoreTxt.setText(LK.getScore());
// Update difficulty
updateDifficulty();
// Spawn blocks
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnBlock();
spawnTimer = 0;
}
// Update blocks and check collisions
for (var i = blocks.length - 1; i >= 0; i--) {
var block = blocks[i];
block.speed = -gameSpeed;
// Remove blocks that are off-screen
if (block.x < -200) {
// Increment block counter when block passes off-screen (successfully avoided)
blocksCount++;
blockCountTxt.setText('BLOCKS: ' + blocksCount);
block.destroy();
blocks.splice(i, 1);
continue;
}
// Check collision with cursor
if (cursor.intersects(block)) {
LK.getSound('hit').play();
LK.effects.flashScreen(0xff0000, 500);
LK.showGameOver();
return;
}
}
};