/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FallingPiece = Container.expand(function (pieceWidth, x, y) {
var self = Container.call(this);
self.fallSpeed = 5;
self.rotationSpeed = 0.1;
var pieceGraphics = self.attachAsset('fallingPiece', {
anchorX: 0.5,
anchorY: 0.5,
width: pieceWidth
});
self.x = x;
self.y = y;
self.update = function () {
self.y += self.fallSpeed;
self.rotation += self.rotationSpeed;
self.fallSpeed += 0.2; // Gravity acceleration
};
return self;
});
var MovingBlock = Container.expand(function (blockWidth) {
var self = Container.call(this);
self.blockWidth = blockWidth || 450;
self.speed = 3;
self.direction = 1;
var blockGraphics = self.attachAsset('movingBlock', {
anchorX: 0.5,
anchorY: 0.5,
width: self.blockWidth
});
self.update = function () {
self.x += self.speed * self.direction;
// Bounce at screen edges
if (self.x <= self.blockWidth / 2) {
self.x = self.blockWidth / 2;
self.direction = 1;
} else if (self.x >= 2048 - self.blockWidth / 2) {
self.x = 2048 - self.blockWidth / 2;
self.direction = -1;
}
};
return self;
});
var TowerBlock = Container.expand(function (blockWidth, x, y) {
var self = Container.call(this);
self.blockWidth = blockWidth;
var blockGraphics = self.attachAsset('towerBlock', {
anchorX: 0.5,
anchorY: 0.5,
width: self.blockWidth
});
self.x = x;
self.y = y;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var towerBlocks = [];
var fallingPieces = [];
var currentMovingBlock = null;
var gameHeight = 2732;
var gameWidth = 2048;
var blockHeight = 100;
var baseY = gameHeight - 400;
var currentBlockWidth = 450;
var towerHeight = 0;
var gameActive = false;
var gameStarted = false;
var menuScreen = null;
var startButton = null;
var titleText = null;
var startText = null;
// UI Elements
var scoreTxt = new Text2('Height: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var widthTxt = new Text2('Width: 450px', {
size: 60,
fill: 0xFFFFFF
});
widthTxt.anchor.set(0.5, 0);
widthTxt.y = 100;
LK.gui.top.addChild(widthTxt);
// Create first moving block
function createNewMovingBlock() {
if (currentMovingBlock) {
currentMovingBlock.destroy();
}
currentMovingBlock = new MovingBlock(currentBlockWidth);
currentMovingBlock.x = gameWidth / 2;
currentMovingBlock.y = 100;
game.addChild(currentMovingBlock);
}
// Add background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create the base block (after background so it renders on top)
var baseBlock = new TowerBlock(450, gameWidth / 2, baseY);
game.addChild(baseBlock);
towerBlocks.push(baseBlock);
// Create menu screen
function createMenuScreen() {
menuScreen = game.attachAsset('menuBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: gameWidth / 2,
y: gameHeight / 2,
alpha: 0.9
});
startButton = game.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
x: gameWidth / 2,
y: gameHeight / 2
});
titleText = new Text2('TOWER DROP', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = gameWidth / 2;
titleText.y = gameHeight / 2 - 200;
game.addChild(titleText);
startText = new Text2('TAP TO START', {
size: 60,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = gameWidth / 2;
startText.y = gameHeight / 2;
game.addChild(startText);
}
// Initialize menu
createMenuScreen();
// Start menu music only when in menu
if (!gameStarted) {
LK.playMusic('menumusic');
}
// Handle block drop
function dropBlock() {
if (!gameActive || !currentMovingBlock) {
return;
}
var droppedX = currentMovingBlock.x;
var droppedWidth = currentMovingBlock.blockWidth;
// Get the top block of the tower
var topBlock = towerBlocks[towerBlocks.length - 1];
var topBlockX = topBlock.x;
var topBlockWidth = topBlock.blockWidth;
// Calculate overlap
var leftEdgeDropped = droppedX - droppedWidth / 2;
var rightEdgeDropped = droppedX + droppedWidth / 2;
var leftEdgeTop = topBlockX - topBlockWidth / 2;
var rightEdgeTop = topBlockX + topBlockWidth / 2;
var overlapLeft = Math.max(leftEdgeDropped, leftEdgeTop);
var overlapRight = Math.min(rightEdgeDropped, rightEdgeTop);
var overlapWidth = overlapRight - overlapLeft;
if (overlapWidth <= 0) {
// Complete miss - game over
gameActive = false;
LK.showGameOver();
return;
}
// Drop sound will play when block lands after animation
// Calculate new block position and width
var newBlockX = (overlapLeft + overlapRight) / 2;
var newBlockY = topBlock.y - blockHeight;
// Create falling pieces for the parts that don't overlap
if (leftEdgeDropped < overlapLeft) {
// Left piece falls
var leftPieceWidth = overlapLeft - leftEdgeDropped;
var leftPieceX = leftEdgeDropped + leftPieceWidth / 2;
var leftPiece = new FallingPiece(leftPieceWidth, leftPieceX, newBlockY);
game.addChild(leftPiece);
fallingPieces.push(leftPiece);
LK.getSound('break').play();
}
if (rightEdgeDropped > overlapRight) {
// Right piece falls
var rightPieceWidth = rightEdgeDropped - overlapRight;
var rightPieceX = overlapRight + rightPieceWidth / 2;
var rightPiece = new FallingPiece(rightPieceWidth, rightPieceX, newBlockY);
game.addChild(rightPiece);
fallingPieces.push(rightPiece);
LK.getSound('break').play();
}
// Create new tower block with the overlapping portion at moving block position first
var newTowerBlock = new TowerBlock(overlapWidth, newBlockX, currentMovingBlock.y);
game.addChild(newTowerBlock);
towerBlocks.push(newTowerBlock);
// Animate the block falling down to its final position
tween(newTowerBlock, {
y: newBlockY
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Play drop sound when block lands
LK.getSound('drop').play();
}
});
// Update game state
currentBlockWidth = overlapWidth;
towerHeight++;
// Update UI
scoreTxt.setText('Height: ' + towerHeight);
widthTxt.setText('Width: ' + Math.round(currentBlockWidth) + 'px');
// Check if block is too small to continue
if (currentBlockWidth < 50) {
gameActive = false;
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
// Create next moving block
LK.setTimeout(function () {
createNewMovingBlock();
}, 500);
// Remove current moving block
currentMovingBlock.destroy();
currentMovingBlock = null;
// Increase game difficulty slightly
if (currentMovingBlock) {
currentMovingBlock.speed = Math.min(currentMovingBlock.speed + 0.1, 8);
}
}
// Game tap handler
game.down = function (x, y, obj) {
if (!gameStarted) {
// Start the game
gameStarted = true;
gameActive = true;
// Remove menu elements
if (menuScreen) {
menuScreen.destroy();
menuScreen = null;
}
if (startButton) {
startButton.destroy();
startButton = null;
}
if (titleText) {
titleText.destroy();
titleText = null;
}
if (startText) {
startText.destroy();
startText = null;
}
// Create first moving block
createNewMovingBlock();
// Smooth transition from menu music to game music
// Stop menu music and start game music with fade in
LK.stopMusic();
LK.setTimeout(function () {
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 1,
duration: 1000
}
});
}, 100);
} else if (gameActive) {
dropBlock();
}
};
// Main game loop
game.update = function () {
if (!gameStarted || !gameActive) {
return;
}
// Clean up falling pieces that are off screen
for (var i = fallingPieces.length - 1; i >= 0; i--) {
var piece = fallingPieces[i];
if (piece.y > gameHeight + 200) {
piece.destroy();
fallingPieces.splice(i, 1);
}
}
// Update score based on tower height
LK.setScore(towerHeight * 10 + Math.round(currentBlockWidth / 10));
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FallingPiece = Container.expand(function (pieceWidth, x, y) {
var self = Container.call(this);
self.fallSpeed = 5;
self.rotationSpeed = 0.1;
var pieceGraphics = self.attachAsset('fallingPiece', {
anchorX: 0.5,
anchorY: 0.5,
width: pieceWidth
});
self.x = x;
self.y = y;
self.update = function () {
self.y += self.fallSpeed;
self.rotation += self.rotationSpeed;
self.fallSpeed += 0.2; // Gravity acceleration
};
return self;
});
var MovingBlock = Container.expand(function (blockWidth) {
var self = Container.call(this);
self.blockWidth = blockWidth || 450;
self.speed = 3;
self.direction = 1;
var blockGraphics = self.attachAsset('movingBlock', {
anchorX: 0.5,
anchorY: 0.5,
width: self.blockWidth
});
self.update = function () {
self.x += self.speed * self.direction;
// Bounce at screen edges
if (self.x <= self.blockWidth / 2) {
self.x = self.blockWidth / 2;
self.direction = 1;
} else if (self.x >= 2048 - self.blockWidth / 2) {
self.x = 2048 - self.blockWidth / 2;
self.direction = -1;
}
};
return self;
});
var TowerBlock = Container.expand(function (blockWidth, x, y) {
var self = Container.call(this);
self.blockWidth = blockWidth;
var blockGraphics = self.attachAsset('towerBlock', {
anchorX: 0.5,
anchorY: 0.5,
width: self.blockWidth
});
self.x = x;
self.y = y;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2C3E50
});
/****
* Game Code
****/
var towerBlocks = [];
var fallingPieces = [];
var currentMovingBlock = null;
var gameHeight = 2732;
var gameWidth = 2048;
var blockHeight = 100;
var baseY = gameHeight - 400;
var currentBlockWidth = 450;
var towerHeight = 0;
var gameActive = false;
var gameStarted = false;
var menuScreen = null;
var startButton = null;
var titleText = null;
var startText = null;
// UI Elements
var scoreTxt = new Text2('Height: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var widthTxt = new Text2('Width: 450px', {
size: 60,
fill: 0xFFFFFF
});
widthTxt.anchor.set(0.5, 0);
widthTxt.y = 100;
LK.gui.top.addChild(widthTxt);
// Create first moving block
function createNewMovingBlock() {
if (currentMovingBlock) {
currentMovingBlock.destroy();
}
currentMovingBlock = new MovingBlock(currentBlockWidth);
currentMovingBlock.x = gameWidth / 2;
currentMovingBlock.y = 100;
game.addChild(currentMovingBlock);
}
// Add background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create the base block (after background so it renders on top)
var baseBlock = new TowerBlock(450, gameWidth / 2, baseY);
game.addChild(baseBlock);
towerBlocks.push(baseBlock);
// Create menu screen
function createMenuScreen() {
menuScreen = game.attachAsset('menuBackground', {
anchorX: 0.5,
anchorY: 0.5,
x: gameWidth / 2,
y: gameHeight / 2,
alpha: 0.9
});
startButton = game.attachAsset('startButton', {
anchorX: 0.5,
anchorY: 0.5,
x: gameWidth / 2,
y: gameHeight / 2
});
titleText = new Text2('TOWER DROP', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = gameWidth / 2;
titleText.y = gameHeight / 2 - 200;
game.addChild(titleText);
startText = new Text2('TAP TO START', {
size: 60,
fill: 0xFFFFFF
});
startText.anchor.set(0.5, 0.5);
startText.x = gameWidth / 2;
startText.y = gameHeight / 2;
game.addChild(startText);
}
// Initialize menu
createMenuScreen();
// Start menu music only when in menu
if (!gameStarted) {
LK.playMusic('menumusic');
}
// Handle block drop
function dropBlock() {
if (!gameActive || !currentMovingBlock) {
return;
}
var droppedX = currentMovingBlock.x;
var droppedWidth = currentMovingBlock.blockWidth;
// Get the top block of the tower
var topBlock = towerBlocks[towerBlocks.length - 1];
var topBlockX = topBlock.x;
var topBlockWidth = topBlock.blockWidth;
// Calculate overlap
var leftEdgeDropped = droppedX - droppedWidth / 2;
var rightEdgeDropped = droppedX + droppedWidth / 2;
var leftEdgeTop = topBlockX - topBlockWidth / 2;
var rightEdgeTop = topBlockX + topBlockWidth / 2;
var overlapLeft = Math.max(leftEdgeDropped, leftEdgeTop);
var overlapRight = Math.min(rightEdgeDropped, rightEdgeTop);
var overlapWidth = overlapRight - overlapLeft;
if (overlapWidth <= 0) {
// Complete miss - game over
gameActive = false;
LK.showGameOver();
return;
}
// Drop sound will play when block lands after animation
// Calculate new block position and width
var newBlockX = (overlapLeft + overlapRight) / 2;
var newBlockY = topBlock.y - blockHeight;
// Create falling pieces for the parts that don't overlap
if (leftEdgeDropped < overlapLeft) {
// Left piece falls
var leftPieceWidth = overlapLeft - leftEdgeDropped;
var leftPieceX = leftEdgeDropped + leftPieceWidth / 2;
var leftPiece = new FallingPiece(leftPieceWidth, leftPieceX, newBlockY);
game.addChild(leftPiece);
fallingPieces.push(leftPiece);
LK.getSound('break').play();
}
if (rightEdgeDropped > overlapRight) {
// Right piece falls
var rightPieceWidth = rightEdgeDropped - overlapRight;
var rightPieceX = overlapRight + rightPieceWidth / 2;
var rightPiece = new FallingPiece(rightPieceWidth, rightPieceX, newBlockY);
game.addChild(rightPiece);
fallingPieces.push(rightPiece);
LK.getSound('break').play();
}
// Create new tower block with the overlapping portion at moving block position first
var newTowerBlock = new TowerBlock(overlapWidth, newBlockX, currentMovingBlock.y);
game.addChild(newTowerBlock);
towerBlocks.push(newTowerBlock);
// Animate the block falling down to its final position
tween(newTowerBlock, {
y: newBlockY
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
// Play drop sound when block lands
LK.getSound('drop').play();
}
});
// Update game state
currentBlockWidth = overlapWidth;
towerHeight++;
// Update UI
scoreTxt.setText('Height: ' + towerHeight);
widthTxt.setText('Width: ' + Math.round(currentBlockWidth) + 'px');
// Check if block is too small to continue
if (currentBlockWidth < 50) {
gameActive = false;
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
// Create next moving block
LK.setTimeout(function () {
createNewMovingBlock();
}, 500);
// Remove current moving block
currentMovingBlock.destroy();
currentMovingBlock = null;
// Increase game difficulty slightly
if (currentMovingBlock) {
currentMovingBlock.speed = Math.min(currentMovingBlock.speed + 0.1, 8);
}
}
// Game tap handler
game.down = function (x, y, obj) {
if (!gameStarted) {
// Start the game
gameStarted = true;
gameActive = true;
// Remove menu elements
if (menuScreen) {
menuScreen.destroy();
menuScreen = null;
}
if (startButton) {
startButton.destroy();
startButton = null;
}
if (titleText) {
titleText.destroy();
titleText = null;
}
if (startText) {
startText.destroy();
startText = null;
}
// Create first moving block
createNewMovingBlock();
// Smooth transition from menu music to game music
// Stop menu music and start game music with fade in
LK.stopMusic();
LK.setTimeout(function () {
LK.playMusic('bgmusic', {
fade: {
start: 0,
end: 1,
duration: 1000
}
});
}, 100);
} else if (gameActive) {
dropBlock();
}
};
// Main game loop
game.update = function () {
if (!gameStarted || !gameActive) {
return;
}
// Clean up falling pieces that are off screen
for (var i = fallingPieces.length - 1; i >= 0; i--) {
var piece = fallingPieces[i];
if (piece.y > gameHeight + 200) {
piece.destroy();
fallingPieces.splice(i, 1);
}
}
// Update score based on tower height
LK.setScore(towerHeight * 10 + Math.round(currentBlockWidth / 10));
};
bloque rectangular de ladrillos de castillo. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
ladrillos rotos . No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
ladrillos. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
boton de inicio ovalado sin texto. In-Game asset. 2d. High contrast. No shadows
con cielo y menos altas