/**** * Classes ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> // Class for TowerBlock var TowerBlock = Container.expand(function () { var self = Container.call(this); var blockGraphics = self.attachAsset('towerBlock', { anchorX: 0.5, anchorY: 0.5 }); self.swayDirection = 1; self.swaySpeed = 1; self.update = function () { self.x += self.swaySpeed * self.swayDirection; if (self.x > 2048 - blockGraphics.width / 2 || self.x < blockGraphics.width / 2) { self.swayDirection *= -1; } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background }); /**** * Game Code ****/ // Initialize variables var towerBlocks = []; var baseY = 2500; // Base row position var currentBlock = null; // Function to drop the current block function dropBlock() { if (currentBlock) { currentBlock.swaySpeed = 0; // Stop swaying towerBlocks.push(currentBlock); currentBlock = null; } } // Create a new block at the top of the screen function createNewBlock() { currentBlock = new TowerBlock(); currentBlock.x = 2048 / 2; currentBlock.y = 100; game.addChild(currentBlock); } // Handle screen tap to drop the block game.down = function (x, y, obj) { dropBlock(); createNewBlock(); }; // Initialize the first block createNewBlock(); // Update function for the game game.update = function () { if (currentBlock) { currentBlock.update(); } // Check for game over condition if (towerBlocks.length > 0 && towerBlocks[towerBlocks.length - 1].y <= baseY - 100) { LK.showGameOver(); } // Update positions of all blocks for (var i = 0; i < towerBlocks.length; i++) { towerBlocks[i].y += 5; // Move blocks down } };
/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for TowerBlock
var TowerBlock = Container.expand(function () {
var self = Container.call(this);
var blockGraphics = self.attachAsset('towerBlock', {
anchorX: 0.5,
anchorY: 0.5
});
self.swayDirection = 1;
self.swaySpeed = 1;
self.update = function () {
self.x += self.swaySpeed * self.swayDirection;
if (self.x > 2048 - blockGraphics.width / 2 || self.x < blockGraphics.width / 2) {
self.swayDirection *= -1;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
// Initialize variables
var towerBlocks = [];
var baseY = 2500; // Base row position
var currentBlock = null;
// Function to drop the current block
function dropBlock() {
if (currentBlock) {
currentBlock.swaySpeed = 0; // Stop swaying
towerBlocks.push(currentBlock);
currentBlock = null;
}
}
// Create a new block at the top of the screen
function createNewBlock() {
currentBlock = new TowerBlock();
currentBlock.x = 2048 / 2;
currentBlock.y = 100;
game.addChild(currentBlock);
}
// Handle screen tap to drop the block
game.down = function (x, y, obj) {
dropBlock();
createNewBlock();
};
// Initialize the first block
createNewBlock();
// Update function for the game
game.update = function () {
if (currentBlock) {
currentBlock.update();
}
// Check for game over condition
if (towerBlocks.length > 0 && towerBlocks[towerBlocks.length - 1].y <= baseY - 100) {
LK.showGameOver();
}
// Update positions of all blocks
for (var i = 0; i < towerBlocks.length; i++) {
towerBlocks[i].y += 5; // Move blocks down
}
};