User prompt
Make it 5 points per second
User prompt
Make that you lose 1 point per second when you swipe ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
It’s not working
User prompt
Make a 5 Second Timeout to the swipe feature when it’s used 5 seconds ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make that you can slice the Boxes with the Swipe feature
User prompt
Make it if you swipe you have a trail
User prompt
Make that if you swipe you get a bonus
User prompt
Add a Swipe mechanic
User prompt
Add a cube variant that destroys all cubes in it horizontal line
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'comboText.style.fill = 0xFFCC00; // Yellow for medium combo' Line Number: 108
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'comboText.setFill(0xFFCC00); // Yellow for medium combo' Line Number: 108
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'comboText.style.fill = 0xFFCC00; // Yellow for medium combo' Line Number: 108
User prompt
Make a Combo System
User prompt
Make the Background green when the score hits 300 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the green slighter
User prompt
Make the background fade into green the closer you get to winning ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Initial prompt
Make the score black
/**** * 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(); }; // Method to handle swipe interactions self.checkSwipe = function (startX, startY, endX, endY) { if (!self.active) { return false; } // Calculate swipe line intersection with box var boxRadius = self.boxGraphics.width / 2; // Simple check for line-circle intersection // Calculate the nearest point on the line to the circle center var dx = endX - startX; var dy = endY - startY; var len = Math.sqrt(dx * dx + dy * dy); // Normalize direction vector if (len > 0) { dx /= len; dy /= len; } // Vector from line start to circle center var cx = self.x - startX; var cy = self.y - startY; // Project circle center onto line var projLen = cx * dx + cy * dy; // Closest point on line to circle center var closestX, closestY; if (projLen < 0) { // Closest point is line start closestX = startX; closestY = startY; } else if (projLen > len) { // Closest point is line end closestX = endX; closestY = endY; } else { // Closest point is on the line closestX = startX + projLen * dx; closestY = startY + projLen * dy; } // Check if the closest point is within the circle var distX = self.x - closestX; var distY = self.y - closestY; var distance = Math.sqrt(distX * distX + distY * distY); if (distance <= boxRadius) { self.tap(); return true; } return false; }; 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; // Swipe variables var swipeStartX = 0; var swipeStartY = 0; var isSwipeActive = false; var swipeMinDistance = 100; // Minimum distance to register as a swipe // Initialize UI var scoreTxt = new Text2('0', { size: 80, fill: 0x000000 }); 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 or swipe 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; } } } }; // Handle both tapping and swipe start game.down = function (x, y) { // Start tracking potential swipe swipeStartX = x; swipeStartY = y; isSwipeActive = true; // Check if any box was hit (for tap) 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); } }; // Handle swipe end game.up = function (x, y) { if (!isSwipeActive) { return; } // Calculate swipe distance var dx = x - swipeStartX; var dy = y - swipeStartY; var distance = Math.sqrt(dx * dx + dy * dy); // Check if this was a valid swipe (minimum distance) if (distance >= swipeMinDistance) { // Process the swipe through all boxes var hitAnyBox = false; for (var i = boxes.length - 1; i >= 0; i--) { if (boxes[i].checkSwipe(swipeStartX, swipeStartY, x, y)) { hitAnyBox = true; } } // Visual feedback for swipe if (hitAnyBox) { // Add swipe line visual effect var lineEffect = new Container(); game.addChild(lineEffect); // Draw swipe line with multiple dots for trail effect var steps = Math.min(20, Math.floor(distance / 20)); var dotSize = 20; for (var s = 0; s < steps; s++) { var dotPercent = s / (steps - 1); var dotX = swipeStartX + dx * dotPercent; var dotY = swipeStartY + dy * dotPercent; // Create dot var dot = LK.getAsset('regularBox', { anchorX: 0.5, anchorY: 0.5, width: dotSize, height: dotSize, alpha: 0.5 * (1 - dotPercent) // Fade out towards the end }); dot.x = dotX; dot.y = dotY; lineEffect.addChild(dot); } // Animate and remove the effect tween(lineEffect, { alpha: 0 }, { duration: 300, easing: tween.linear, onFinish: function onFinish() { lineEffect.destroy(); } }); } } // Reset swipe tracking isSwipeActive = false; }; // Add move handler to track active swipes game.move = function (x, y) { // For very long swipes, we can process while still moving if (isSwipeActive) { var dx = x - swipeStartX; var dy = y - swipeStartY; var distance = Math.sqrt(dx * dx + dy * dy); // For very long swipes, check boxes during the swipe if (distance >= swipeMinDistance * 2) { for (var i = boxes.length - 1; i >= 0; i--) { boxes[i].checkSwipe(swipeStartX, swipeStartY, x, y); } // Update swipe start position to current swipeStartX = x; swipeStartY = y; } } }; // Game clean-up function game.cleanup = function () { if (spawnTimer) { LK.clearInterval(spawnTimer); } if (difficultyTimer) { LK.clearInterval(difficultyTimer); } LK.stopMusic(); };
===================================================================
--- original.js
+++ change.js
@@ -33,17 +33,8 @@
anchorY: 0.5
});
self.points = 5;
self.speed = 9;
- } else if (self.type === 'lineClear') {
- self.boxGraphics = self.attachAsset('specialBox', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.boxGraphics.tint = 0x9b59b6; // Purple tint
- self.points = 2;
- self.speed = 6;
- self.isLineClearer = true;
}
// Add a small rotation to make it visually interesting
self.rotationSpeed = (Math.random() - 0.5) * 0.02;
self.update = function () {
@@ -70,91 +61,37 @@
if (!self.active) {
return;
}
self.active = false;
- // Handle line-clearing box
- if (self.isLineClearer) {
- LK.getSound('lineClear').play();
- // Find all boxes in the same horizontal line (within a small y-tolerance)
- var yPosition = self.y;
- var tolerance = 30; // Tolerance for y-position matching
- var boxesInLine = [];
- var totalPoints = self.points; // Start with the points from this box
- // Find boxes in the same line
- boxes.forEach(function (otherBox) {
- if (otherBox !== self && otherBox.active && Math.abs(otherBox.y - yPosition) < tolerance) {
- boxesInLine.push(otherBox);
- totalPoints += otherBox.points;
- otherBox.active = false;
- // Create explosion effect for each box in line
- tween(otherBox, {
- alpha: 0,
- scaleX: 1.5,
- scaleY: 1.5
- }, {
- duration: 300,
- easing: tween.linear,
- onFinish: function onFinish() {
- otherBox.destroy();
- }
- });
- }
- });
- // Show total points cleared
- var pointText = new Text2('+' + totalPoints, {
- size: 70,
- fill: 0x9b59b6
- });
- pointText.anchor.set(0.5, 0.5);
- pointText.x = self.x;
- pointText.y = self.y;
- game.addChild(pointText);
- // Animate the text
- tween(pointText, {
- y: pointText.y - 80,
- alpha: 0
- }, {
- duration: 1200,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- pointText.destroy();
- }
- });
- // Update score with total points
- LK.setScore(LK.getScore() + totalPoints);
- updateScoreDisplay();
+ // Play appropriate sound
+ if (self.type === 'regular') {
+ LK.getSound('tap').play();
} else {
- // Regular box behavior
- // 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 remove it
- tween(pointText, {
- y: pointText.y - 80,
- alpha: 0
- }, {
- duration: 800,
- easing: tween.easeOut,
- onFinish: function onFinish() {
- pointText.destroy();
- }
- });
+ 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,
@@ -174,8 +111,55 @@
// Event handler for tapping on boxes
self.down = function () {
self.tap();
};
+ // Method to handle swipe interactions
+ self.checkSwipe = function (startX, startY, endX, endY) {
+ if (!self.active) {
+ return false;
+ }
+ // Calculate swipe line intersection with box
+ var boxRadius = self.boxGraphics.width / 2;
+ // Simple check for line-circle intersection
+ // Calculate the nearest point on the line to the circle center
+ var dx = endX - startX;
+ var dy = endY - startY;
+ var len = Math.sqrt(dx * dx + dy * dy);
+ // Normalize direction vector
+ if (len > 0) {
+ dx /= len;
+ dy /= len;
+ }
+ // Vector from line start to circle center
+ var cx = self.x - startX;
+ var cy = self.y - startY;
+ // Project circle center onto line
+ var projLen = cx * dx + cy * dy;
+ // Closest point on line to circle center
+ var closestX, closestY;
+ if (projLen < 0) {
+ // Closest point is line start
+ closestX = startX;
+ closestY = startY;
+ } else if (projLen > len) {
+ // Closest point is line end
+ closestX = endX;
+ closestY = endY;
+ } else {
+ // Closest point is on the line
+ closestX = startX + projLen * dx;
+ closestY = startY + projLen * dy;
+ }
+ // Check if the closest point is within the circle
+ var distX = self.x - closestX;
+ var distY = self.y - closestY;
+ var distance = Math.sqrt(distX * distX + distY * distY);
+ if (distance <= boxRadius) {
+ self.tap();
+ return true;
+ }
+ return false;
+ };
return self;
});
/****
@@ -198,8 +182,13 @@
var winScore = 300; // Score needed to win
var difficultyIncreaseInterval = 10000; // Increase difficulty every 10 seconds
var difficultyTimer = null;
var gameStarted = false;
+// Swipe variables
+var swipeStartX = 0;
+var swipeStartY = 0;
+var isSwipeActive = false;
+var swipeMinDistance = 100; // Minimum distance to register as a swipe
// Initialize UI
var scoreTxt = new Text2('0', {
size: 80,
fill: 0x000000
@@ -213,9 +202,9 @@
missedBoxesTxt.anchor.set(0, 0);
missedBoxesTxt.x = 150;
missedBoxesTxt.y = 50;
LK.gui.topRight.addChild(missedBoxesTxt);
-var instructionsTxt = new Text2('Tap the falling boxes!', {
+var instructionsTxt = new Text2('Tap or swipe the falling boxes!', {
size: 60,
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 0.5);
@@ -241,16 +230,14 @@
// Function to spawn a box
function spawnBox() {
var boxType;
var random = Math.random();
- if (random < 0.65) {
+ if (random < 0.7) {
boxType = 'regular';
- } else if (random < 0.85) {
+ } else if (random < 0.9) {
boxType = 'bonus';
- } else if (random < 0.95) {
- boxType = 'special';
} else {
- boxType = 'lineClear';
+ boxType = 'special';
}
var box = new Box(boxType);
box.x = Math.random() * (2048 - 100) + 50; // Random x position
box.y = -100; // Start above the screen
@@ -316,11 +303,15 @@
}
}
}
};
-// Allow tapping anywhere on the screen to tap a box
+// Handle both tapping and swipe start
game.down = function (x, y) {
- // Check if any box was hit
+ // Start tracking potential swipe
+ swipeStartX = x;
+ swipeStartY = y;
+ isSwipeActive = true;
+ // Check if any box was hit (for tap)
var hitBox = false;
for (var i = boxes.length - 1; i >= 0; i--) {
var box = boxes[i];
// Calculate distance from tap to box center
@@ -338,8 +329,83 @@
if (!hitBox && boxes.length > 0) {
LK.effects.flashScreen(0x3498db, 100);
}
};
+// Handle swipe end
+game.up = function (x, y) {
+ if (!isSwipeActive) {
+ return;
+ }
+ // Calculate swipe distance
+ var dx = x - swipeStartX;
+ var dy = y - swipeStartY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // Check if this was a valid swipe (minimum distance)
+ if (distance >= swipeMinDistance) {
+ // Process the swipe through all boxes
+ var hitAnyBox = false;
+ for (var i = boxes.length - 1; i >= 0; i--) {
+ if (boxes[i].checkSwipe(swipeStartX, swipeStartY, x, y)) {
+ hitAnyBox = true;
+ }
+ }
+ // Visual feedback for swipe
+ if (hitAnyBox) {
+ // Add swipe line visual effect
+ var lineEffect = new Container();
+ game.addChild(lineEffect);
+ // Draw swipe line with multiple dots for trail effect
+ var steps = Math.min(20, Math.floor(distance / 20));
+ var dotSize = 20;
+ for (var s = 0; s < steps; s++) {
+ var dotPercent = s / (steps - 1);
+ var dotX = swipeStartX + dx * dotPercent;
+ var dotY = swipeStartY + dy * dotPercent;
+ // Create dot
+ var dot = LK.getAsset('regularBox', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ width: dotSize,
+ height: dotSize,
+ alpha: 0.5 * (1 - dotPercent) // Fade out towards the end
+ });
+ dot.x = dotX;
+ dot.y = dotY;
+ lineEffect.addChild(dot);
+ }
+ // Animate and remove the effect
+ tween(lineEffect, {
+ alpha: 0
+ }, {
+ duration: 300,
+ easing: tween.linear,
+ onFinish: function onFinish() {
+ lineEffect.destroy();
+ }
+ });
+ }
+ }
+ // Reset swipe tracking
+ isSwipeActive = false;
+};
+// Add move handler to track active swipes
+game.move = function (x, y) {
+ // For very long swipes, we can process while still moving
+ if (isSwipeActive) {
+ var dx = x - swipeStartX;
+ var dy = y - swipeStartY;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // For very long swipes, check boxes during the swipe
+ if (distance >= swipeMinDistance * 2) {
+ for (var i = boxes.length - 1; i >= 0; i--) {
+ boxes[i].checkSwipe(swipeStartX, swipeStartY, x, y);
+ }
+ // Update swipe start position to current
+ swipeStartX = x;
+ swipeStartY = y;
+ }
+ }
+};
// Game clean-up function
game.cleanup = function () {
if (spawnTimer) {
LK.clearInterval(spawnTimer);