/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Block = Container.expand(function () {
var self = Container.call(this);
self.blockWidth = 200;
self.blockHeight = 60;
var blockGraphics = self.attachAsset('block', {
anchorX: 0.5,
anchorY: 0.5
});
self.setWidth = function (newWidth) {
self.blockWidth = newWidth;
blockGraphics.width = newWidth;
};
self.getWidth = function () {
return self.blockWidth;
};
return self;
});
var FallingBlock = Container.expand(function () {
var self = Container.call(this);
self.blockWidth = 200;
self.blockHeight = 60;
self.speed = 200;
self.stopped = false;
var blockGraphics = self.attachAsset('fallingBlock', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
if (!self.stopped) {
self.y += self.speed * (1 / 60);
}
};
self.stop = function () {
self.stopped = true;
};
self.setWidth = function (newWidth) {
self.blockWidth = newWidth;
blockGraphics.width = newWidth;
};
self.getWidth = function () {
return self.blockWidth;
};
return self;
});
/****
* Initialize Game
****/
// Game variables
var game = new LK.Game({
backgroundColor: 0x1a1a2e
});
/****
* Game Code
****/
// Game variables
// Import tween plugin for animations
// Initialize game assets
var tower = [];
var currentFallingBlock = null;
var gameRunning = true;
var currentPlatformWidth = 200;
var dropSpeed = 200;
var perfectStreak = 0;
var lastDropTime = 0;
var dropInterval = 2000; // 2 seconds initially
// UI Elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
scoreTxt.y = 50;
var streakTxt = new Text2('', {
size: 40,
fill: 0xFFD700
});
streakTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(streakTxt);
streakTxt.y = 150;
// Create base platform
var basePlatform = game.addChild(new Block());
basePlatform.x = 1024;
basePlatform.y = 2400;
tower.push(basePlatform);
function spawnFallingBlock() {
if (!gameRunning || currentFallingBlock) return;
currentFallingBlock = game.addChild(new FallingBlock());
currentFallingBlock.setWidth(currentPlatformWidth);
// Random horizontal position
var minX = currentPlatformWidth / 2;
var maxX = 2048 - currentPlatformWidth / 2;
currentFallingBlock.x = Math.random() * (maxX - minX) + minX;
currentFallingBlock.y = -30;
// Increase speed based on tower height
var speedMultiplier = 1 + tower.length * 0.1;
currentFallingBlock.speed = dropSpeed * speedMultiplier;
}
function dropBlock() {
if (!currentFallingBlock || !gameRunning) return;
currentFallingBlock.stop();
var topBlock = tower[tower.length - 1];
var alignment = Math.abs(currentFallingBlock.x - topBlock.x);
var tolerance = 10; // Perfect drop tolerance
if (alignment > currentPlatformWidth / 2) {
// Complete miss - game over
gameOver();
return;
}
var newBlock = game.addChild(new Block());
var overlap = currentPlatformWidth - alignment;
var newWidth = Math.max(overlap, 20); // Minimum width of 20
// Position new block
if (currentFallingBlock.x < topBlock.x) {
newBlock.x = topBlock.x - (currentPlatformWidth - newWidth) / 2;
} else {
newBlock.x = topBlock.x + (currentPlatformWidth - newWidth) / 2;
}
newBlock.y = topBlock.y - 60;
newBlock.setWidth(newWidth);
// Check if it's a perfect drop
var isPerfect = alignment <= tolerance;
if (isPerfect) {
perfectStreak++;
LK.getSound('perfect').play();
// Flash block green for perfect drop
tween(newBlock, {
tint: 0x00FF00
}, {
duration: 200,
onFinish: function onFinish() {
tween(newBlock, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
// Bonus points for perfect drops
LK.setScore(LK.getScore() + 10 + perfectStreak * 5);
} else {
perfectStreak = 0;
currentPlatformWidth = newWidth;
LK.getSound('trim').play();
// Flash block red for trimmed drop
tween(newBlock, {
tint: 0xFF6666
}, {
duration: 200,
onFinish: function onFinish() {
tween(newBlock, {
tint: 0xFFFFFF
}, {
duration: 200
});
}
});
LK.setScore(LK.getScore() + 1);
}
LK.getSound('drop').play();
tower.push(newBlock);
// Remove falling block
currentFallingBlock.destroy();
currentFallingBlock = null;
// Update UI
scoreTxt.setText(LK.getScore());
if (perfectStreak > 0) {
streakTxt.setText('Perfect x' + perfectStreak);
} else {
streakTxt.setText('');
}
// Adjust camera to follow tower
var cameraY = Math.max(0, newBlock.y - 1366);
tween(game, {
y: -cameraY
}, {
duration: 500,
easing: tween.easeOut
});
// Increase difficulty
dropInterval = Math.max(800, dropInterval - 20); // Minimum 0.8 seconds
lastDropTime = LK.ticks;
}
function gameOver() {
gameRunning = false;
// Flash screen red
LK.effects.flashScreen(0xFF0000, 1000);
// Show game over after a brief delay
LK.setTimeout(function () {
LK.showGameOver();
}, 1000);
}
// Touch/click handler
game.down = function (x, y, obj) {
if (currentFallingBlock && !currentFallingBlock.stopped) {
dropBlock();
}
};
// Game update loop
game.update = function () {
// Spawn new falling block if needed
if (gameRunning && !currentFallingBlock && LK.ticks - lastDropTime > dropInterval) {
spawnFallingBlock();
}
// Check if falling block went off screen (should not happen in normal gameplay)
if (currentFallingBlock && currentFallingBlock.y > 2800) {
gameOver();
}
};
// Initialize game
lastDropTime = LK.ticks;
spawnFallingBlock(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,222 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Block = Container.expand(function () {
+ var self = Container.call(this);
+ self.blockWidth = 200;
+ self.blockHeight = 60;
+ var blockGraphics = self.attachAsset('block', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.setWidth = function (newWidth) {
+ self.blockWidth = newWidth;
+ blockGraphics.width = newWidth;
+ };
+ self.getWidth = function () {
+ return self.blockWidth;
+ };
+ return self;
+});
+var FallingBlock = Container.expand(function () {
+ var self = Container.call(this);
+ self.blockWidth = 200;
+ self.blockHeight = 60;
+ self.speed = 200;
+ self.stopped = false;
+ var blockGraphics = self.attachAsset('fallingBlock', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.update = function () {
+ if (!self.stopped) {
+ self.y += self.speed * (1 / 60);
+ }
+ };
+ self.stop = function () {
+ self.stopped = true;
+ };
+ self.setWidth = function (newWidth) {
+ self.blockWidth = newWidth;
+ blockGraphics.width = newWidth;
+ };
+ self.getWidth = function () {
+ return self.blockWidth;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
+// Game variables
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x1a1a2e
+});
+
+/****
+* Game Code
+****/
+// Game variables
+// Import tween plugin for animations
+// Initialize game assets
+var tower = [];
+var currentFallingBlock = null;
+var gameRunning = true;
+var currentPlatformWidth = 200;
+var dropSpeed = 200;
+var perfectStreak = 0;
+var lastDropTime = 0;
+var dropInterval = 2000; // 2 seconds initially
+// UI Elements
+var scoreTxt = new Text2('0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+scoreTxt.y = 50;
+var streakTxt = new Text2('', {
+ size: 40,
+ fill: 0xFFD700
+});
+streakTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(streakTxt);
+streakTxt.y = 150;
+// Create base platform
+var basePlatform = game.addChild(new Block());
+basePlatform.x = 1024;
+basePlatform.y = 2400;
+tower.push(basePlatform);
+function spawnFallingBlock() {
+ if (!gameRunning || currentFallingBlock) return;
+ currentFallingBlock = game.addChild(new FallingBlock());
+ currentFallingBlock.setWidth(currentPlatformWidth);
+ // Random horizontal position
+ var minX = currentPlatformWidth / 2;
+ var maxX = 2048 - currentPlatformWidth / 2;
+ currentFallingBlock.x = Math.random() * (maxX - minX) + minX;
+ currentFallingBlock.y = -30;
+ // Increase speed based on tower height
+ var speedMultiplier = 1 + tower.length * 0.1;
+ currentFallingBlock.speed = dropSpeed * speedMultiplier;
+}
+function dropBlock() {
+ if (!currentFallingBlock || !gameRunning) return;
+ currentFallingBlock.stop();
+ var topBlock = tower[tower.length - 1];
+ var alignment = Math.abs(currentFallingBlock.x - topBlock.x);
+ var tolerance = 10; // Perfect drop tolerance
+ if (alignment > currentPlatformWidth / 2) {
+ // Complete miss - game over
+ gameOver();
+ return;
+ }
+ var newBlock = game.addChild(new Block());
+ var overlap = currentPlatformWidth - alignment;
+ var newWidth = Math.max(overlap, 20); // Minimum width of 20
+ // Position new block
+ if (currentFallingBlock.x < topBlock.x) {
+ newBlock.x = topBlock.x - (currentPlatformWidth - newWidth) / 2;
+ } else {
+ newBlock.x = topBlock.x + (currentPlatformWidth - newWidth) / 2;
+ }
+ newBlock.y = topBlock.y - 60;
+ newBlock.setWidth(newWidth);
+ // Check if it's a perfect drop
+ var isPerfect = alignment <= tolerance;
+ if (isPerfect) {
+ perfectStreak++;
+ LK.getSound('perfect').play();
+ // Flash block green for perfect drop
+ tween(newBlock, {
+ tint: 0x00FF00
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(newBlock, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 200
+ });
+ }
+ });
+ // Bonus points for perfect drops
+ LK.setScore(LK.getScore() + 10 + perfectStreak * 5);
+ } else {
+ perfectStreak = 0;
+ currentPlatformWidth = newWidth;
+ LK.getSound('trim').play();
+ // Flash block red for trimmed drop
+ tween(newBlock, {
+ tint: 0xFF6666
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(newBlock, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 200
+ });
+ }
+ });
+ LK.setScore(LK.getScore() + 1);
+ }
+ LK.getSound('drop').play();
+ tower.push(newBlock);
+ // Remove falling block
+ currentFallingBlock.destroy();
+ currentFallingBlock = null;
+ // Update UI
+ scoreTxt.setText(LK.getScore());
+ if (perfectStreak > 0) {
+ streakTxt.setText('Perfect x' + perfectStreak);
+ } else {
+ streakTxt.setText('');
+ }
+ // Adjust camera to follow tower
+ var cameraY = Math.max(0, newBlock.y - 1366);
+ tween(game, {
+ y: -cameraY
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ // Increase difficulty
+ dropInterval = Math.max(800, dropInterval - 20); // Minimum 0.8 seconds
+ lastDropTime = LK.ticks;
+}
+function gameOver() {
+ gameRunning = false;
+ // Flash screen red
+ LK.effects.flashScreen(0xFF0000, 1000);
+ // Show game over after a brief delay
+ LK.setTimeout(function () {
+ LK.showGameOver();
+ }, 1000);
+}
+// Touch/click handler
+game.down = function (x, y, obj) {
+ if (currentFallingBlock && !currentFallingBlock.stopped) {
+ dropBlock();
+ }
+};
+// Game update loop
+game.update = function () {
+ // Spawn new falling block if needed
+ if (gameRunning && !currentFallingBlock && LK.ticks - lastDropTime > dropInterval) {
+ spawnFallingBlock();
+ }
+ // Check if falling block went off screen (should not happen in normal gameplay)
+ if (currentFallingBlock && currentFallingBlock.y > 2800) {
+ gameOver();
+ }
+};
+// Initialize game
+lastDropTime = LK.ticks;
+spawnFallingBlock();
\ No newline at end of file