/****
* 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: 0.5
});
self.speed = 8;
self.lastY = 0;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Add landscape background
var landscape = LK.getAsset('landscape', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(landscape);
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
var blocks = [];
var blockSpawnTimer = 0;
var blockSpawnDelay = 60;
var gameSpeed = 1;
var survivalTime = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
// Convert touch position to game coordinates and move player
dragNode.x = x;
// Keep player within screen bounds
if (dragNode.x < 40) {
dragNode.x = 40;
}
if (dragNode.x > 2048 - 40) {
dragNode.x = 2048 - 40;
}
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Start relaxing background music
LK.playMusic('relaxingMusic');
game.update = function () {
survivalTime++;
// Update score based on survival time
var currentScore = Math.floor(survivalTime / 10);
LK.setScore(currentScore);
scoreTxt.setText(LK.getScore());
// Increase difficulty over time
if (survivalTime % 300 === 0) {
gameSpeed += 0.2;
blockSpawnDelay = Math.max(20, blockSpawnDelay - 3);
}
// Spawn blocks
blockSpawnTimer++;
if (blockSpawnTimer >= blockSpawnDelay) {
blockSpawnTimer = 0;
var newBlock = new Block();
newBlock.x = Math.random() * (2048 - 120) + 60;
newBlock.y = -50;
newBlock.speed = 8 * gameSpeed;
newBlock.lastY = newBlock.y;
blocks.push(newBlock);
game.addChild(newBlock);
}
// Update and check blocks
for (var i = blocks.length - 1; i >= 0; i--) {
var block = blocks[i];
// Check if block went off screen
if (block.lastY <= 2732 + 50 && block.y > 2732 + 50) {
block.destroy();
blocks.splice(i, 1);
continue;
}
// Check collision with player
if (block.intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
block.lastY = block.y;
}
}; /****
* 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: 0.5
});
self.speed = 8;
self.lastY = 0;
self.update = function () {
self.y += self.speed;
};
return self;
});
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x222222
});
/****
* Game Code
****/
// Add landscape background
var landscape = LK.getAsset('landscape', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.addChild(landscape);
var player = game.addChild(new Player());
player.x = 2048 / 2;
player.y = 2732 - 150;
var blocks = [];
var blockSpawnTimer = 0;
var blockSpawnDelay = 60;
var gameSpeed = 1;
var survivalTime = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
// Convert touch position to game coordinates and move player
dragNode.x = x;
// Keep player within screen bounds
if (dragNode.x < 40) {
dragNode.x = 40;
}
if (dragNode.x > 2048 - 40) {
dragNode.x = 2048 - 40;
}
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = player;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
// Start relaxing background music
LK.playMusic('relaxingMusic');
game.update = function () {
survivalTime++;
// Update score based on survival time
var currentScore = Math.floor(survivalTime / 10);
LK.setScore(currentScore);
scoreTxt.setText(LK.getScore());
// Increase difficulty over time
if (survivalTime % 300 === 0) {
gameSpeed += 0.2;
blockSpawnDelay = Math.max(20, blockSpawnDelay - 3);
}
// Spawn blocks
blockSpawnTimer++;
if (blockSpawnTimer >= blockSpawnDelay) {
blockSpawnTimer = 0;
var newBlock = new Block();
newBlock.x = Math.random() * (2048 - 120) + 60;
newBlock.y = -50;
newBlock.speed = 8 * gameSpeed;
newBlock.lastY = newBlock.y;
blocks.push(newBlock);
game.addChild(newBlock);
}
// Update and check blocks
for (var i = blocks.length - 1; i >= 0; i--) {
var block = blocks[i];
// Check if block went off screen
if (block.lastY <= 2732 + 50 && block.y > 2732 + 50) {
block.destroy();
blocks.splice(i, 1);
continue;
}
// Check collision with player
if (block.intersects(player)) {
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
block.lastY = block.y;
}
};