/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Block = Container.expand(function (blockWidth, yPos, color) {
var self = Container.call(this);
self.blockWidth = blockWidth || 200;
self.yPosition = yPos || 0;
self.blockColor = color || 0x4A90E2;
// Create shadow first (appears behind)
var shadowGraphics = self.attachAsset('shadow', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3,
scaleX: self.blockWidth / 200,
tint: 0x000000
});
// Create main block
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: self.blockWidth / 200,
tint: self.blockColor
});
// Position elements for 3D effect
self.x = 1024;
self.y = self.yPosition;
// Shadow offset for 3D depth effect
shadowGraphics.x = 8;
shadowGraphics.y = 8;
blockGraphics.x = 0;
blockGraphics.y = 0;
return self;
});
var MovingBlock = Container.expand(function (blockWidth, yPos) {
var self = Container.call(this);
self.blockWidth = blockWidth || 200;
self.yPosition = yPos || 0;
self.speed = 3 + Math.floor(LK.getScore() / 5); // Increase speed every 5 points
self.direction = 1;
self.isActive = true;
// Create shadow
var shadowGraphics = self.attachAsset('movingShadow', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.3,
scaleX: self.blockWidth / 200
});
// Create moving block
var blockGraphics = self.attachAsset('movingBlock', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: self.blockWidth / 200,
tint: 0x5BA0F2
});
// Position for 3D effect
self.x = 1024;
self.y = self.yPosition;
shadowGraphics.x = 8;
shadowGraphics.y = 8;
blockGraphics.x = 0;
blockGraphics.y = 0;
self.update = function () {
if (!self.isActive) return;
self.x += self.speed * self.direction;
// Bounce off edges with padding for block width
var halfWidth = self.blockWidth * 0.5;
if (self.x <= halfWidth) {
self.x = halfWidth;
self.direction = 1;
} else if (self.x >= 2048 - halfWidth) {
self.x = 2048 - halfWidth;
self.direction = -1;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var blocks = [];
var movingBlock = null;
var gameActive = true;
var perfectStreak = 0;
var baseBlockWidth = 200;
var currentBlockWidth = baseBlockWidth;
// UI Elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var perfectTxt = new Text2('', {
size: 40,
fill: 0xFFD700
});
perfectTxt.anchor.set(0.5, 0);
perfectTxt.y = 100;
LK.gui.top.addChild(perfectTxt);
// Create first base block
function createBaseBlock() {
var baseBlock = new Block(baseBlockWidth, 2600, 0x2E7D32);
blocks.push(baseBlock);
game.addChild(baseBlock);
}
// Create new moving block
function createMovingBlock() {
if (movingBlock) {
movingBlock.destroy();
}
var yPos = 2600 - blocks.length * 65; // Stack height with 3D perspective
movingBlock = new MovingBlock(currentBlockWidth, yPos);
game.addChild(movingBlock);
}
// Calculate block overlap and trim
function calculateOverlap(movingX, lastBlockX, blockWidth) {
var leftEdgeMoving = movingX - blockWidth / 2;
var rightEdgeMoving = movingX + blockWidth / 2;
var leftEdgeLast = lastBlockX - blockWidth / 2;
var rightEdgeLast = lastBlockX + blockWidth / 2;
var overlapLeft = Math.max(leftEdgeMoving, leftEdgeLast);
var overlapRight = Math.min(rightEdgeMoving, rightEdgeLast);
if (overlapRight <= overlapLeft) {
return {
width: 0,
center: movingX,
perfect: false
};
}
var overlapWidth = overlapRight - overlapLeft;
var overlapCenter = (overlapLeft + overlapRight) / 2;
var perfect = Math.abs(movingX - lastBlockX) < 5; // Perfect if within 5 pixels
return {
width: overlapWidth,
center: overlapCenter,
perfect: perfect
};
}
// Place the moving block
function placeBlock() {
if (!gameActive || !movingBlock || !movingBlock.isActive) return;
movingBlock.isActive = false;
var lastBlock = blocks[blocks.length - 1];
var overlap = calculateOverlap(movingBlock.x, lastBlock.x, currentBlockWidth);
if (overlap.width <= 5) {
// Complete miss - game over
LK.getSound('miss').play();
gameActive = false;
LK.effects.flashScreen(0xff0000, 1000);
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
return;
}
if (overlap.perfect) {
// Perfect placement
perfectStreak++;
LK.setScore(LK.getScore() + 10 + perfectStreak); // Bonus for streak
LK.getSound('perfect').play();
perfectTxt.setText('PERFECT! +' + (10 + perfectStreak));
perfectTxt.alpha = 1;
tween(perfectTxt, {
alpha: 0
}, {
duration: 2000
});
// Flash effect for perfect
LK.effects.flashObject(movingBlock, 0xFFD700, 500);
} else {
// Imperfect placement - trim block
perfectStreak = 0;
currentBlockWidth = overlap.width;
LK.setScore(LK.getScore() + 1);
LK.getSound('place').play();
perfectTxt.setText('');
}
// Create new static block at overlap position
var blockColor = overlap.perfect ? 0x4CAF50 : 0x4A90E2;
var newBlock = new Block(currentBlockWidth, movingBlock.y, blockColor);
newBlock.x = overlap.center;
blocks.push(newBlock);
game.addChild(newBlock);
// Remove moving block
movingBlock.destroy();
movingBlock = null;
// Update score display
scoreTxt.setText(LK.getScore());
// Check win condition (very high tower)
if (blocks.length >= 50) {
gameActive = false;
LK.effects.flashScreen(0x00ff00, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 1000);
return;
}
// Camera follow effect - move all blocks down as tower grows
if (blocks.length > 8) {
for (var i = 0; i < blocks.length; i++) {
tween(blocks[i], {
y: blocks[i].y + 30
}, {
duration: 300,
easing: tween.easeOut
});
}
}
// Create next moving block after a short delay
LK.setTimeout(function () {
if (gameActive) {
createMovingBlock();
}
}, 500);
}
// Touch controls
game.down = function (x, y, obj) {
if (gameActive && movingBlock && movingBlock.isActive) {
placeBlock();
}
};
// Initialize game
createBaseBlock();
createMovingBlock();
// Update loop
game.update = function () {
// Camera shake effect when blocks get very small
if (currentBlockWidth < 50 && gameActive) {
game.x = (Math.random() - 0.5) * 2;
game.y = (Math.random() - 0.5) * 2;
} else {
game.x = 0;
game.y = 0;
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,247 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Block = Container.expand(function (blockWidth, yPos, color) {
+ var self = Container.call(this);
+ self.blockWidth = blockWidth || 200;
+ self.yPosition = yPos || 0;
+ self.blockColor = color || 0x4A90E2;
+ // Create shadow first (appears behind)
+ var shadowGraphics = self.attachAsset('shadow', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.3,
+ scaleX: self.blockWidth / 200,
+ tint: 0x000000
+ });
+ // Create main block
+ var blockGraphics = self.attachAsset('block', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: self.blockWidth / 200,
+ tint: self.blockColor
+ });
+ // Position elements for 3D effect
+ self.x = 1024;
+ self.y = self.yPosition;
+ // Shadow offset for 3D depth effect
+ shadowGraphics.x = 8;
+ shadowGraphics.y = 8;
+ blockGraphics.x = 0;
+ blockGraphics.y = 0;
+ return self;
+});
+var MovingBlock = Container.expand(function (blockWidth, yPos) {
+ var self = Container.call(this);
+ self.blockWidth = blockWidth || 200;
+ self.yPosition = yPos || 0;
+ self.speed = 3 + Math.floor(LK.getScore() / 5); // Increase speed every 5 points
+ self.direction = 1;
+ self.isActive = true;
+ // Create shadow
+ var shadowGraphics = self.attachAsset('movingShadow', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.3,
+ scaleX: self.blockWidth / 200
+ });
+ // Create moving block
+ var blockGraphics = self.attachAsset('movingBlock', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: self.blockWidth / 200,
+ tint: 0x5BA0F2
+ });
+ // Position for 3D effect
+ self.x = 1024;
+ self.y = self.yPosition;
+ shadowGraphics.x = 8;
+ shadowGraphics.y = 8;
+ blockGraphics.x = 0;
+ blockGraphics.y = 0;
+ self.update = function () {
+ if (!self.isActive) return;
+ self.x += self.speed * self.direction;
+ // Bounce off edges with padding for block width
+ var halfWidth = self.blockWidth * 0.5;
+ if (self.x <= halfWidth) {
+ self.x = halfWidth;
+ self.direction = 1;
+ } else if (self.x >= 2048 - halfWidth) {
+ self.x = 2048 - halfWidth;
+ self.direction = -1;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var blocks = [];
+var movingBlock = null;
+var gameActive = true;
+var perfectStreak = 0;
+var baseBlockWidth = 200;
+var currentBlockWidth = baseBlockWidth;
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var perfectTxt = new Text2('', {
+ size: 40,
+ fill: 0xFFD700
+});
+perfectTxt.anchor.set(0.5, 0);
+perfectTxt.y = 100;
+LK.gui.top.addChild(perfectTxt);
+// Create first base block
+function createBaseBlock() {
+ var baseBlock = new Block(baseBlockWidth, 2600, 0x2E7D32);
+ blocks.push(baseBlock);
+ game.addChild(baseBlock);
+}
+// Create new moving block
+function createMovingBlock() {
+ if (movingBlock) {
+ movingBlock.destroy();
+ }
+ var yPos = 2600 - blocks.length * 65; // Stack height with 3D perspective
+ movingBlock = new MovingBlock(currentBlockWidth, yPos);
+ game.addChild(movingBlock);
+}
+// Calculate block overlap and trim
+function calculateOverlap(movingX, lastBlockX, blockWidth) {
+ var leftEdgeMoving = movingX - blockWidth / 2;
+ var rightEdgeMoving = movingX + blockWidth / 2;
+ var leftEdgeLast = lastBlockX - blockWidth / 2;
+ var rightEdgeLast = lastBlockX + blockWidth / 2;
+ var overlapLeft = Math.max(leftEdgeMoving, leftEdgeLast);
+ var overlapRight = Math.min(rightEdgeMoving, rightEdgeLast);
+ if (overlapRight <= overlapLeft) {
+ return {
+ width: 0,
+ center: movingX,
+ perfect: false
+ };
+ }
+ var overlapWidth = overlapRight - overlapLeft;
+ var overlapCenter = (overlapLeft + overlapRight) / 2;
+ var perfect = Math.abs(movingX - lastBlockX) < 5; // Perfect if within 5 pixels
+ return {
+ width: overlapWidth,
+ center: overlapCenter,
+ perfect: perfect
+ };
+}
+// Place the moving block
+function placeBlock() {
+ if (!gameActive || !movingBlock || !movingBlock.isActive) return;
+ movingBlock.isActive = false;
+ var lastBlock = blocks[blocks.length - 1];
+ var overlap = calculateOverlap(movingBlock.x, lastBlock.x, currentBlockWidth);
+ if (overlap.width <= 5) {
+ // Complete miss - game over
+ LK.getSound('miss').play();
+ gameActive = false;
+ LK.effects.flashScreen(0xff0000, 1000);
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+ return;
+ }
+ if (overlap.perfect) {
+ // Perfect placement
+ perfectStreak++;
+ LK.setScore(LK.getScore() + 10 + perfectStreak); // Bonus for streak
+ LK.getSound('perfect').play();
+ perfectTxt.setText('PERFECT! +' + (10 + perfectStreak));
+ perfectTxt.alpha = 1;
+ tween(perfectTxt, {
+ alpha: 0
+ }, {
+ duration: 2000
+ });
+ // Flash effect for perfect
+ LK.effects.flashObject(movingBlock, 0xFFD700, 500);
+ } else {
+ // Imperfect placement - trim block
+ perfectStreak = 0;
+ currentBlockWidth = overlap.width;
+ LK.setScore(LK.getScore() + 1);
+ LK.getSound('place').play();
+ perfectTxt.setText('');
+ }
+ // Create new static block at overlap position
+ var blockColor = overlap.perfect ? 0x4CAF50 : 0x4A90E2;
+ var newBlock = new Block(currentBlockWidth, movingBlock.y, blockColor);
+ newBlock.x = overlap.center;
+ blocks.push(newBlock);
+ game.addChild(newBlock);
+ // Remove moving block
+ movingBlock.destroy();
+ movingBlock = null;
+ // Update score display
+ scoreTxt.setText(LK.getScore());
+ // Check win condition (very high tower)
+ if (blocks.length >= 50) {
+ gameActive = false;
+ LK.effects.flashScreen(0x00ff00, 1000);
+ LK.setTimeout(function () {
+ LK.showYouWin();
+ }, 1000);
+ return;
+ }
+ // Camera follow effect - move all blocks down as tower grows
+ if (blocks.length > 8) {
+ for (var i = 0; i < blocks.length; i++) {
+ tween(blocks[i], {
+ y: blocks[i].y + 30
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ }
+ }
+ // Create next moving block after a short delay
+ LK.setTimeout(function () {
+ if (gameActive) {
+ createMovingBlock();
+ }
+ }, 500);
+}
+// Touch controls
+game.down = function (x, y, obj) {
+ if (gameActive && movingBlock && movingBlock.isActive) {
+ placeBlock();
+ }
+};
+// Initialize game
+createBaseBlock();
+createMovingBlock();
+// Update loop
+game.update = function () {
+ // Camera shake effect when blocks get very small
+ if (currentBlockWidth < 50 && gameActive) {
+ game.x = (Math.random() - 0.5) * 2;
+ game.y = (Math.random() - 0.5) * 2;
+ } else {
+ game.x = 0;
+ game.y = 0;
+ }
+};
\ No newline at end of file