/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ var Box = Container.expand(function (type) { var self = Container.call(this); self.type = type || 'regular'; self.speed = 5; self.points = 1; self.active = true; // Different box configurations based on type if (self.type === 'regular') { self.boxGraphics = self.attachAsset('regularBox', { anchorX: 0.5, anchorY: 0.5 }); self.points = 1; } else if (self.type === 'bonus') { self.boxGraphics = self.attachAsset('bonusBox', { anchorX: 0.5, anchorY: 0.5 }); self.points = 3; self.speed = 7; } else if (self.type === 'special') { self.boxGraphics = self.attachAsset('specialBox', { anchorX: 0.5, anchorY: 0.5 }); self.points = 5; self.speed = 9; } // Add a small rotation to make it visually interesting self.rotationSpeed = (Math.random() - 0.5) * 0.02; self.update = function () { if (!self.active) { return; } self.y += self.speed; self.boxGraphics.rotation += self.rotationSpeed; // Check if box moved out of screen if (self.y > 2732 + self.boxGraphics.height) { self.active = false; missedBoxes++; // Check if the player has missed too many boxes if (missedBoxes >= maxMissedBoxes) { LK.effects.flashScreen(0xff0000, 500); LK.getSound('gameOverSound').play(); LK.setTimeout(function () { LK.showGameOver(); }, 500); } } }; self.tap = function () { if (!self.active) { return; } self.active = false; // Play appropriate sound if (self.type === 'regular') { LK.getSound('tap').play(); } else { LK.getSound('bonus').play(); } // Update score LK.setScore(LK.getScore() + self.points); updateScoreDisplay(); // Show score increase effect var pointText = new Text2('+' + self.points, { size: 50, fill: 0xFFFFFF }); pointText.anchor.set(0.5, 0.5); pointText.x = self.x; pointText.y = self.y; game.addChild(pointText); // Animate the text and then remove it tween(pointText, { y: pointText.y - 80, alpha: 0 }, { duration: 800, easing: tween.easeOut, onFinish: function onFinish() { pointText.destroy(); } }); // Animate the box explosion tween(self, { alpha: 0, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { self.destroy(); } }); // Check if player reached target score if (LK.getScore() >= winScore) { LK.showYouWin(); } }; // Event handler for tapping on boxes self.down = function () { self.tap(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF }); /**** * Game Code ****/ // Game variables var boxes = []; var spawnInterval = 1000; // Initial spawn interval in ms var minSpawnInterval = 300; // Minimum spawn interval var spawnTimer = null; var missedBoxes = 0; var maxMissedBoxes = 10; // Game over after 10 missed boxes var winScore = 300; // Score needed to win var difficultyIncreaseInterval = 10000; // Increase difficulty every 10 seconds var difficultyTimer = null; var gameStarted = false; // Initialize UI var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var missedBoxesTxt = new Text2('Missed: 0/' + maxMissedBoxes, { size: 50, fill: 0xFFFFFF }); missedBoxesTxt.anchor.set(0, 0); missedBoxesTxt.x = 150; missedBoxesTxt.y = 50; LK.gui.topRight.addChild(missedBoxesTxt); var instructionsTxt = new Text2('Tap the falling boxes!', { size: 60, fill: 0xFFFFFF }); instructionsTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(instructionsTxt); // Hide instructions after a delay LK.setTimeout(function () { tween(instructionsTxt, { alpha: 0 }, { duration: 1000, easing: tween.linear, onFinish: function onFinish() { instructionsTxt.destroy(); } }); startGame(); }, 2000); // Function to update score display function updateScoreDisplay() { scoreTxt.setText(LK.getScore()); missedBoxesTxt.setText('Missed: ' + missedBoxes + '/' + maxMissedBoxes); } // Function to spawn a box function spawnBox() { var boxType; var random = Math.random(); if (random < 0.7) { boxType = 'regular'; } else if (random < 0.9) { boxType = 'bonus'; } else { boxType = 'special'; } var box = new Box(boxType); box.x = Math.random() * (2048 - 100) + 50; // Random x position box.y = -100; // Start above the screen // Add some variety to the path box.xSpeed = (Math.random() - 0.5) * 3; boxes.push(box); game.addChild(box); } // Function to start the game function startGame() { if (gameStarted) { return; } gameStarted = true; // Reset variables boxes.forEach(function (box) { box.destroy(); }); boxes = []; missedBoxes = 0; LK.setScore(0); updateScoreDisplay(); // Start spawning boxes spawnTimer = LK.setInterval(function () { spawnBox(); }, spawnInterval); // Increase difficulty over time difficultyTimer = LK.setInterval(function () { if (spawnInterval > minSpawnInterval) { spawnInterval = Math.max(minSpawnInterval, spawnInterval - 100); // Clear and restart spawn timer with new interval LK.clearInterval(spawnTimer); spawnTimer = LK.setInterval(function () { spawnBox(); }, spawnInterval); } }, difficultyIncreaseInterval); // Play background music LK.playMusic('gameMusic', { fade: { start: 0, end: 0.5, duration: 1000 } }); } // Update function called every frame game.update = function () { // Process all active boxes for (var i = boxes.length - 1; i >= 0; i--) { var box = boxes[i]; // Remove inactive boxes from the array if (!box.active) { boxes.splice(i, 1); continue; } // Add some horizontal movement to make it more interesting if (box.xSpeed) { box.x += box.xSpeed; // Bounce off the edges if (box.x < 50 || box.x > 2048 - 50) { box.xSpeed *= -1; } } } }; // Allow tapping anywhere on the screen to tap a box game.down = function (x, y) { // Check if any box was hit var hitBox = false; for (var i = boxes.length - 1; i >= 0; i--) { var box = boxes[i]; // Calculate distance from tap to box center var dx = x - box.x; var dy = y - box.y; var distance = Math.sqrt(dx * dx + dy * dy); // If tap is within the box, trigger a tap if (distance < box.boxGraphics.width / 2 && box.active) { box.tap(); hitBox = true; break; // Only tap one box at a time } } // Flash screen very subtly when missing a box if (!hitBox && boxes.length > 0) { LK.effects.flashScreen(0x3498db, 100); } }; // Game clean-up function game.cleanup = function () { if (spawnTimer) { LK.clearInterval(spawnTimer); } if (difficultyTimer) { LK.clearInterval(difficultyTimer); } LK.stopMusic(); };
===================================================================
--- original.js
+++ change.js
@@ -118,9 +118,9 @@
/****
* Initialize Game
****/
var game = new LK.Game({
- backgroundColor: 0x202a3b
+ backgroundColor: 0xFFFFFF
});
/****
* Game Code