User prompt
Make it so the music menu pops up when you start the game
User prompt
Still don’t work
User prompt
Still didn’t work
User prompt
Didn’t work
User prompt
Please fix the bug: 'undefined is not an object (evaluating 'musicTracks[currentMusicIndex]')' in or related to this line: 'LK.playMusic(musicTracks[currentMusicIndex]);' Line Number: 1064
User prompt
Make the music and sounds not need a tap to be activated just make them start automatically
User prompt
Make spawning the fruits activate the sounds
User prompt
Didn’t work
User prompt
Make the music only start once
User prompt
Make the fruits hitting the floor activate the song and an sounds instead of clicking
User prompt
Make any click or drag activate the sounds and music
User prompt
Make the rainbow mutation give x5 multiplye
User prompt
Move the music button to the right a little bit
User prompt
Move the music button a little to the right
User prompt
Make all the text in the music section black forever
User prompt
It doesn’t work
User prompt
Make it so the song selected is green
User prompt
Add a music menu so you can choose between 5 different songs ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Make the colors switch more smoothly ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Add a rare rainbow mutation that multiplies the score a fruit gives when merged by 3
User prompt
Make the death line disabled while the fruit rain is active
User prompt
Disable the death line while the fruit rain is active
User prompt
Give the fruits a tint of green when the fruit mover is used ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the fruits color get saturated if you use the fruit mover ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Script error.' in or related to this line: 'tween(fruits[i], {' Line Number: 818 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Fruit = Container.expand(function (type) {
var self = Container.call(this);
self.type = type;
self.velocityX = 0;
self.velocityY = 0;
self.angularVelocity = 0;
self.gravity = 1.2;
self.bounceX = 0.2;
self.bounceY = 0.1;
self.friction = 0.995;
self.rotationFriction = 0.85;
self.merged = false;
self.lastMergeCheck = false;
// Rainbow mutation - 5% chance for any fruit to be rainbow
self.isRainbow = Math.random() < 0.05;
var fruitAssets = ['cherry', 'strawberry', 'grape', 'orange', 'apple', 'pear', 'peach', 'pineapple', 'melon', 'watermelon', 'lemon', 'coconut', 'dragon', 'kiwi', 'mango', 'papaya', 'durian'];
var fruitSizes = [120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 520, 560, 600, 640, 580, 620, 660];
var fruitScores = [1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153];
self.assetName = fruitAssets[type];
self.size = fruitSizes[type];
self.scoreValue = fruitScores[type];
var fruitGraphics = self.attachAsset(self.assetName, {
anchorX: 0.5,
anchorY: 0.5
});
// Apply rainbow effect if this fruit is rainbow
if (self.isRainbow) {
self.rainbowTintIndex = 0;
self.rainbowColors = [0xff0000, 0xff8000, 0xffff00, 0x00ff00, 0x0080ff, 0x8000ff];
fruitGraphics.tint = self.rainbowColors[0];
}
self.getRadius = function () {
return self.size / 2;
};
self.update = function () {
if (typeof fruitsFrozen !== "undefined" && fruitsFrozen) {
return;
}
if (self.merged) {
return;
}
// Apply gravity
self.velocityY += self.gravity;
// Apply velocity
self.x += self.velocityX;
self.y += self.velocityY;
// Calculate current speed
var currentSpeed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
var speedThreshold = 3.0; // Only rotate when moving fast enough
// Always apply rotation
self.rotation += self.angularVelocity;
// Apply friction
self.velocityX *= self.friction;
self.velocityY *= self.friction;
self.angularVelocity *= self.rotationFriction;
// Additional stability check - if fruit is moving very slowly, gradually bring it to rest
var totalSpeed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
if (totalSpeed < 1.0 && totalSpeed > 0) {
var stabilityDamping = 0.8;
self.velocityX *= stabilityDamping;
self.velocityY *= stabilityDamping;
}
// Check if fruit is in cramped conditions
var nearbyFruits = 0;
if (typeof fruits !== "undefined") {
for (var k = 0; k < fruits.length; k++) {
if (fruits[k] !== self) {
var dist = Math.sqrt((self.x - fruits[k].x) * (self.x - fruits[k].x) + (self.y - fruits[k].y) * (self.y - fruits[k].y));
if (dist < self.getRadius() + fruits[k].getRadius() + 30) {
nearbyFruits++;
}
}
}
}
// Apply stronger rotational damping in cramped conditions
if (nearbyFruits >= 3) {
self.angularVelocity *= 0.6; // Much stronger damping when cramped
}
// Cap maximum rotation speed - lower limit for cramped conditions
var maxAngularVelocity = nearbyFruits >= 3 ? 0.05 : 0.1; // Reduced max rotation
if (self.angularVelocity > maxAngularVelocity) {
self.angularVelocity = maxAngularVelocity;
} else if (self.angularVelocity < -maxAngularVelocity) {
self.angularVelocity = -maxAngularVelocity;
}
// Rainbow color cycling for rainbow fruits
if (self.isRainbow && LK.ticks % 30 === 0) {
self.rainbowTintIndex = (self.rainbowTintIndex + 1) % self.rainbowColors.length;
var fruitGraphics = self.children[0];
if (fruitGraphics) {
tween(fruitGraphics, {
tint: self.rainbowColors[self.rainbowTintIndex]
}, {
duration: 500,
easing: tween.easeInOut
});
}
}
// Prevent very small velocities that can cause sticking - increased threshold
if (Math.abs(self.velocityX) < 0.5) {
self.velocityX = 0;
}
if (Math.abs(self.velocityY) < 0.5) {
self.velocityY = 0;
}
// Higher threshold for stopping rotation in cramped conditions
var rotationStopThreshold = nearbyFruits >= 3 ? 0.02 : 0.005;
if (Math.abs(self.angularVelocity) < rotationStopThreshold) {
self.angularVelocity = 0;
// Bounce rotation back to neutral position when angular velocity stops
if (Math.abs(self.rotation) > 0.1) {
tween(self, {
rotation: 0
}, {
duration: nearbyFruits >= 3 ? 400 : 600,
// Faster correction when cramped
easing: tween.bounceOut
});
}
}
var radius = self.getRadius();
var containerLeft = containerX - containerWidth / 2;
var containerRight = containerX + containerWidth / 2;
var containerBottom = containerY + containerHeight / 2;
// Collision with container walls
if (self.x - radius < containerLeft) {
self.x = containerLeft + radius;
self.velocityX = -self.velocityX * self.bounceX;
// Add rotational effect from wall collision only if movement is significant
if (Math.abs(self.velocityY) > 2.0) {
self.angularVelocity += self.velocityY * 0.01;
}
}
if (self.x + radius > containerRight) {
self.x = containerRight - radius;
self.velocityX = -self.velocityX * self.bounceX;
// Add rotational effect from wall collision only if movement is significant
if (Math.abs(self.velocityY) > 2.0) {
self.angularVelocity -= self.velocityY * 0.01;
}
}
// Collision with container bottom
if (self.y + radius > containerBottom) {
self.y = containerBottom - radius;
self.velocityY = -self.velocityY * self.bounceY;
// Add rotational effect from ground collision only if movement is significant
if (Math.abs(self.velocityX) > 2.0) {
self.angularVelocity += self.velocityX * 0.02;
}
if (Math.abs(self.velocityY) < 1) {
self.velocityY = 0;
}
// After ground collision, check speed threshold
var currentSpeed = Math.sqrt(self.velocityX * self.velocityX + self.velocityY * self.velocityY);
var speedThreshold = 3.0;
if (currentSpeed < speedThreshold) {
// Stop movement if below speed threshold after hitting ground
self.velocityX = 0;
self.velocityY = 0;
self.angularVelocity = 0;
// Bounce rotation back to neutral position
if (Math.abs(self.rotation) > 0.1) {
tween(self, {
rotation: 0
}, {
duration: 800,
easing: tween.elasticOut
});
}
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
// No backgroundColor, handled by asset
});
/****
* Game Code
****/
// Attach blue background asset, ensure it's at the back
// Blue background asset (full screen)
var blueBg = game.attachAsset('blueBg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
});
game.addChildAt(blueBg, 0); // Add as the bottom-most child
// Game state
var gameState = 'playing';
var fruits = [];
var currentFruit = null;
var nextFruitType = 0;
var gameRunning = true;
var dropLine = 400;
var gameOverLine = 300;
var isDragging = false;
var previewFruit = null;
// Freeze fruits when evolution menu is open
var fruitsFrozen = false;
// Track which fruits have been discovered by the player
var discoveredFruits = storage.discoveredFruits || [];
// Initialize array if not in storage
if (discoveredFruits.length === 0) {
for (var i = 0; i < 17; i++) {
discoveredFruits[i] = false;
}
}
// Container dimensions and position
var containerWidth = 1900;
var containerHeight = 2200;
var containerX = 2048 / 2;
var containerY = 1366;
// Create container
var container = game.attachAsset('container', {
anchorX: 0.5,
anchorY: 0.5,
x: containerX,
y: containerY
});
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Merge counter (reset to 0 every game start)
var totalMerges = 0;
var mergeCounterTxt = new Text2('Merges: ' + totalMerges, {
size: 60,
fill: 0x000000
});
mergeCounterTxt.anchor.set(0.5, 0.5);
mergeCounterTxt.x = 2048 / 2;
mergeCounterTxt.y = 2732 / 2;
game.addChild(mergeCounterTxt);
// Load discovered fruits from storage, but ensure first 5 are always available
for (var i = 0; i < discoveredFruits.length; i++) {
if (i < 5) {
discoveredFruits[i] = true; // First 5 are always available to drop
} else if (storage.discoveredFruits && storage.discoveredFruits[i]) {
discoveredFruits[i] = true; // Keep unlocked fruits from storage
}
}
// Save to storage
storage.discoveredFruits = discoveredFruits;
// Next fruit preview
var nextFruitPreview = null;
var nextFruitLabel = new Text2('Next:', {
size: 60,
fill: 0x000000
});
nextFruitLabel.anchor.set(1, 0.5);
nextFruitLabel.x = 1580;
nextFruitLabel.y = 120;
game.addChild(nextFruitLabel);
// Drop line indicator
var dropLineIndicator = LK.getAsset('container', {
width: containerWidth,
height: 4,
anchorX: 0.5,
anchorY: 0.5
});
dropLineIndicator.x = containerX;
dropLineIndicator.y = dropLine;
dropLineIndicator.tint = 0x0000FF;
game.addChild(dropLineIndicator);
// Helper functions
function getRandomFruitType() {
return Math.floor(Math.random() * 5); // Only first 5 fruit types can be dropped
}
function createNextFruit() {
nextFruitType = getRandomFruitType();
if (nextFruitPreview) {
// Stop any existing tweens before destroying
tween.stop(nextFruitPreview);
nextFruitPreview.destroy();
}
var fruitAssets = ['cherry', 'strawberry', 'grape', 'orange', 'apple'];
var fruitSizes = [120, 160, 200, 240, 280];
nextFruitPreview = LK.getAsset(fruitAssets[nextFruitType], {
anchorX: 0.5,
anchorY: 0.5
});
nextFruitPreview.x = 1700;
nextFruitPreview.y = 120;
game.addChild(nextFruitPreview);
// Position the label based on fruit size to ensure it's always visible
var fruitRadius = fruitSizes[nextFruitType] / 2;
nextFruitLabel.x = nextFruitPreview.x - fruitRadius - 20; // 20px padding from fruit edge
// Add bobbing animation
var originalY = nextFruitPreview.y;
function bobUp() {
tween(nextFruitPreview, {
y: originalY - 15
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: bobDown
});
}
function bobDown() {
tween(nextFruitPreview, {
y: originalY + 15
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: bobUp
});
}
bobUp();
}
function dropFruit(x) {
if (!gameRunning || currentFruit) {
return;
}
currentFruit = new Fruit(nextFruitType);
currentFruit.x = Math.max(containerX - containerWidth / 2 + currentFruit.getRadius(), Math.min(x, containerX + containerWidth / 2 - currentFruit.getRadius()));
currentFruit.y = dropLine + currentFruit.getRadius() + 60; // Spawn lower below the line with more padding
// Mark this fruit as discovered
var newlyDiscovered = !discoveredFruits[nextFruitType];
discoveredFruits[nextFruitType] = true;
// Save to storage
storage.discoveredFruits = discoveredFruits;
if (newlyDiscovered) {
// Show notification for unlocking new fruit
var evoFruitNames = ['Cherry', 'Strawberry', 'Grape', 'Orange', 'Apple', 'Pear', 'Peach', 'Pineapple', 'Melon', 'Watermelon', 'Lemon', 'Coconut', 'Dragonfruit', 'Kiwi', 'Mango', 'Papaya', 'Durian'];
var unlockedName = evoFruitNames[nextFruitType];
var notification = new Text2("You've unlocked " + unlockedName + "!", {
size: 90,
fill: 0x222222
});
notification.anchor.set(0.5, 0.5);
notification.x = 2048 / 2;
notification.y = 900;
notification.alpha = 0.0;
game.addChild(notification);
// Fade in, hold, then fade out
tween(notification, {
alpha: 1
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.setTimeout(function () {
tween(notification, {
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
notification.destroy();
}
});
}, 1200);
}
});
}
// Add small random initial rotation
currentFruit.angularVelocity = (Math.random() - 0.5) * 0.05;
fruits.push(currentFruit);
game.addChild(currentFruit);
// Music and drop sound now start on tap/hold instead of drop
// Reset current fruit after a delay
LK.setTimeout(function () {
currentFruit = null;
}, 100);
createNextFruit();
}
function createPreviewFruit(x) {
if (previewFruit) {
previewFruit.destroy();
}
var fruitAssets = ['cherry', 'strawberry', 'grape', 'orange', 'apple', 'pear', 'peach', 'pineapple', 'melon', 'watermelon', 'lemon', 'coconut', 'dragon', 'kiwi', 'mango', 'papaya', 'durian'];
previewFruit = LK.getAsset(fruitAssets[nextFruitType], {
anchorX: 0.5,
anchorY: 0.5
});
previewFruit.alpha = 0.7; // Make it semi-transparent
previewFruit.x = x;
previewFruit.y = dropLine;
game.addChild(previewFruit);
}
function updatePreviewFruit(x) {
if (!previewFruit) {
return;
}
var fruitSizes = [120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 520, 560, 600, 640, 580, 620, 660];
var radius = fruitSizes[nextFruitType] / 2;
previewFruit.x = Math.max(containerX - containerWidth / 2 + radius, Math.min(x, containerX + containerWidth / 2 - radius));
}
function destroyPreviewFruit() {
if (previewFruit) {
previewFruit.destroy();
previewFruit = null;
}
}
function checkCollision(fruit1, fruit2) {
var dx = fruit1.x - fruit2.x;
var dy = fruit1.y - fruit2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDistance = fruit1.getRadius() + fruit2.getRadius();
return distance < minDistance;
}
function resolveFruitCollision(fruit1, fruit2) {
var dx = fruit1.x - fruit2.x;
var dy = fruit1.y - fruit2.y;
var distance = Math.sqrt(dx * dx + dy * dy);
var minDistance = fruit1.getRadius() + fruit2.getRadius();
if (distance < minDistance && distance > 0) {
var overlap = minDistance - distance;
// Reduced separation force to prevent oscillation
var separationForce = 0.6;
var separationX = dx / distance * overlap * separationForce;
var separationY = dy / distance * overlap * separationForce;
fruit1.x += separationX;
fruit1.y += separationY;
fruit2.x -= separationX;
fruit2.y -= separationY;
// Apply strong damping when fruits are very close to prevent vibration
var dampingFactor = Math.max(0.1, Math.min(1.0, distance / minDistance));
fruit1.velocityX *= dampingFactor;
fruit1.velocityY *= dampingFactor;
fruit2.velocityX *= dampingFactor;
fruit2.velocityY *= dampingFactor;
// Realistic elastic collision response
var relativeVelX = fruit1.velocityX - fruit2.velocityX;
var relativeVelY = fruit1.velocityY - fruit2.velocityY;
var normalVelX = dx / distance;
var normalVelY = dy / distance;
var separatingVel = relativeVelX * normalVelX + relativeVelY * normalVelY;
// Only resolve if objects are moving toward each other with sufficient velocity
if (separatingVel < -0.5) {
var restitution = 0.05; // Reduced bounciness factor
var impulse = -(1 + restitution) * separatingVel * 0.5; // Reduced impulse strength
var impulseX = impulse * normalVelX;
var impulseY = impulse * normalVelY;
fruit1.velocityX += impulseX;
fruit1.velocityY += impulseY;
fruit2.velocityX -= impulseX;
fruit2.velocityY -= impulseY;
// Add rotational effects from collision only if movement is significant and not in cramped conditions
var movementThreshold = 5.0; // Increased threshold to prevent micro-rotation
var totalImpulse = Math.abs(impulseX) + Math.abs(impulseY);
// Check if fruits are in cramped conditions by counting nearby fruits
var nearbyCount1 = 0;
var nearbyCount2 = 0;
for (var k = 0; k < fruits.length; k++) {
if (fruits[k] !== fruit1 && fruits[k] !== fruit2) {
var dist1 = Math.sqrt((fruit1.x - fruits[k].x) * (fruit1.x - fruits[k].x) + (fruit1.y - fruits[k].y) * (fruit1.y - fruits[k].y));
var dist2 = Math.sqrt((fruit2.x - fruits[k].x) * (fruit2.x - fruits[k].x) + (fruit2.y - fruits[k].y) * (fruit2.y - fruits[k].y));
if (dist1 < fruit1.getRadius() + fruits[k].getRadius() + 50) nearbyCount1++;
if (dist2 < fruit2.getRadius() + fruits[k].getRadius() + 50) nearbyCount2++;
}
}
// Only apply rotation if not cramped and movement is significant
if (totalImpulse > movementThreshold && nearbyCount1 < 3 && nearbyCount2 < 3) {
var rotationFactor = 0.008; // Reduced rotation factor
fruit1.angularVelocity += (impulseX + impulseY) * rotationFactor;
fruit2.angularVelocity -= (impulseX + impulseY) * rotationFactor;
}
}
}
}
function mergeFruits(fruit1, fruit2) {
if (fruit1.type !== fruit2.type || fruit1.merged || fruit2.merged) {
return false;
}
if (fruit1.type >= 16) {
return false;
} // Can't merge durian (highest fruit)
// Mark the new fruit type as discovered
var newlyDiscovered = !discoveredFruits[fruit1.type + 1];
discoveredFruits[fruit1.type + 1] = true;
// Save to storage
storage.discoveredFruits = discoveredFruits;
if (newlyDiscovered) {
// Show notification for unlocking new fruit
var evoFruitNames = ['Cherry', 'Strawberry', 'Grape', 'Orange', 'Apple', 'Pear', 'Peach', 'Pineapple', 'Melon', 'Watermelon', 'Lemon', 'Coconut', 'Dragonfruit', 'Kiwi', 'Mango', 'Papaya', 'Durian'];
var unlockedName = evoFruitNames[fruit1.type + 1];
var notification = new Text2("You've unlocked " + unlockedName + "!", {
size: 90,
fill: 0x222222
});
notification.anchor.set(0.5, 0.5);
notification.x = 2048 / 2;
notification.y = 900;
notification.alpha = 0.0;
game.addChild(notification);
// Fade in, hold, then fade out
tween(notification, {
alpha: 1
}, {
duration: 300,
easing: tween.easeIn,
onFinish: function onFinish() {
LK.setTimeout(function () {
tween(notification, {
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
notification.destroy();
}
});
}, 1200);
}
});
}
// Create new fruit
var newFruit = new Fruit(fruit1.type + 1);
newFruit.x = (fruit1.x + fruit2.x) / 2;
newFruit.y = (fruit1.y + fruit2.y) / 2;
// Calculate score with rainbow multiplier
var scoreToAdd = newFruit.scoreValue;
if (fruit1.isRainbow || fruit2.isRainbow) {
scoreToAdd *= 5;
// Show rainbow score notification
var rainbowScoreText = new Text2('RAINBOW x5!', {
size: 80,
fill: 0xff00ff
});
rainbowScoreText.anchor.set(0.5, 0.5);
rainbowScoreText.x = newFruit.x;
rainbowScoreText.y = newFruit.y - 100;
rainbowScoreText.alpha = 0;
game.addChild(rainbowScoreText);
// Animate rainbow score text
tween(rainbowScoreText, {
alpha: 1,
y: rainbowScoreText.y - 50
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(rainbowScoreText, {
alpha: 0,
y: rainbowScoreText.y - 50
}, {
duration: 500,
easing: tween.easeIn,
onFinish: function onFinish() {
rainbowScoreText.destroy();
}
});
}
});
}
// Add score
LK.setScore(LK.getScore() + scoreToAdd);
scoreTxt.setText('Score: ' + LK.getScore());
// Update merge counter
totalMerges++;
mergeCounterTxt.setText('Merges: ' + totalMerges);
storage.totalMerges = totalMerges;
// Mark old fruits as merged
fruit1.merged = true;
fruit2.merged = true;
// Remove old fruits
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i] === fruit1 || fruits[i] === fruit2) {
fruits[i].destroy();
fruits.splice(i, 1);
}
}
// Add new fruit
fruits.push(newFruit);
game.addChild(newFruit);
LK.getSound('merge').play();
// Flash effect
tween(newFruit, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(newFruit, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
return true;
}
function performAutoMerge() {
var foundMerge = true;
// Keep merging until no more merges are possible
while (foundMerge) {
foundMerge = false;
// Check all fruit pairs for possible merges
for (var i = 0; i < fruits.length && !foundMerge; i++) {
for (var j = i + 1; j < fruits.length && !foundMerge; j++) {
var fruit1 = fruits[i];
var fruit2 = fruits[j];
// Skip if either fruit is already merged or different types
if (fruit1.merged || fruit2.merged || fruit1.type !== fruit2.type) {
continue;
}
// Skip if already at maximum fruit type (durian)
if (fruit1.type >= 16) {
continue;
}
// Auto merge merges ANY two fruits of the same type regardless of distance
// Perform the merge immediately
if (mergeFruits(fruit1, fruit2)) {
foundMerge = true;
break;
}
}
}
}
}
function checkGameOver() {
for (var i = 0; i < fruits.length; i++) {
var fruit = fruits[i];
if (fruit.y - fruit.getRadius() < gameOverLine) {
return true;
}
}
return false;
}
// Fruit Mover button (leftmost)
var fruitMoverButton = new Text2('FRUIT MOVER!', {
size: 60,
fill: 0x000000
});
fruitMoverButton.anchor.set(0.5, 0.5);
// Place at far left
fruitMoverButton.x = 200;
fruitMoverButton.y = 2732 - 150;
game.addChild(fruitMoverButton);
// Cost text under fruit mover button
var fruitMoverCostText = new Text2('Cost: 125', {
size: 40,
fill: 0x000000
});
fruitMoverCostText.anchor.set(0.5, 0);
// Position just below the fruit mover button
fruitMoverCostText.x = fruitMoverButton.x;
fruitMoverCostText.y = fruitMoverButton.y + 60;
game.addChild(fruitMoverCostText);
// Randomize fruit button (second from left)
var randomizeButton = new Text2('RANDOMIZE!', {
size: 60,
fill: 0x000000
});
randomizeButton.anchor.set(0.5, 0.5);
// Place second from left
randomizeButton.x = 600;
randomizeButton.y = 2732 - 150;
game.addChild(randomizeButton);
// Cost text under randomize button
var randomizeCostText = new Text2('Cost: 300', {
size: 40,
fill: 0x000000
});
randomizeCostText.anchor.set(0.5, 0);
// Position just below the randomize button
randomizeCostText.x = randomizeButton.x;
randomizeCostText.y = randomizeButton.y + 60;
game.addChild(randomizeCostText);
// Shake button (center)
var shakeButton = new Text2('SHAKE!', {
size: 60,
fill: 0x000000
});
shakeButton.anchor.set(0.5, 0.5);
// Place at center
shakeButton.x = 2048 / 2;
shakeButton.y = 2732 - 150;
game.addChild(shakeButton);
// Cost text under shake button
var shakeCostText = new Text2('Cost: 450', {
size: 40,
fill: 0x000000
});
shakeCostText.anchor.set(0.5, 0);
// Position just below the shake button
shakeCostText.x = shakeButton.x;
shakeCostText.y = shakeButton.y + 60;
game.addChild(shakeCostText);
// Auto merge button (second from right)
var autoMergeButton = new Text2('AUTO MERGE!', {
size: 60,
fill: 0x000000
});
autoMergeButton.anchor.set(0.5, 0.5);
// Place second from right
autoMergeButton.x = 1448;
autoMergeButton.y = 2732 - 150;
game.addChild(autoMergeButton);
// Cost text under auto merge button
var autoMergeCostText = new Text2('Cost: 800', {
size: 40,
fill: 0x000000
});
autoMergeCostText.anchor.set(0.5, 0);
// Position just below the auto merge button
autoMergeCostText.x = autoMergeButton.x;
autoMergeCostText.y = autoMergeButton.y + 60;
game.addChild(autoMergeCostText);
// Fruit Rain button (rightmost)
var fruitRainButton = new Text2('FRUIT RAIN!', {
size: 60,
fill: 0x000000
});
fruitRainButton.anchor.set(0.5, 0.5);
// Place at far right
fruitRainButton.x = 1848;
fruitRainButton.y = 2732 - 150;
game.addChild(fruitRainButton);
// Cost text under fruit rain button
var fruitRainCostText = new Text2('Cost: 1000', {
size: 40,
fill: 0x000000
});
fruitRainCostText.anchor.set(0.5, 0);
// Position just below the fruit rain button
fruitRainCostText.x = fruitRainButton.x;
fruitRainCostText.y = fruitRainButton.y + 60;
game.addChild(fruitRainCostText);
// Add auto merge button click handler
autoMergeButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (LK.getScore() >= 800 && fruits.length > 1) {
// Deduct score
LK.setScore(LK.getScore() - 800);
scoreTxt.setText('Score: ' + LK.getScore());
// Perform auto merge
performAutoMerge();
}
};
// Add randomize button click handler
randomizeButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (LK.getScore() >= 300 && fruits.length > 1) {
// Deduct score
LK.setScore(LK.getScore() - 300);
scoreTxt.setText('Score: ' + LK.getScore());
// Store all current fruit positions
var positions = [];
for (var i = 0; i < fruits.length; i++) {
positions.push({
x: fruits[i].x,
y: fruits[i].y
});
}
// Shuffle the positions array
for (var i = positions.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = positions[i];
positions[i] = positions[j];
positions[j] = temp;
}
// Apply shuffled positions to fruits
for (var i = 0; i < fruits.length; i++) {
fruits[i].x = positions[i].x;
fruits[i].y = positions[i].y;
// Reset velocities to prevent physics issues
fruits[i].velocityX = 0;
fruits[i].velocityY = 0;
fruits[i].angularVelocity = 0;
}
}
};
// Add fruit rain button click handler
fruitRainButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (LK.getScore() >= 1000) {
// Deduct score
LK.setScore(LK.getScore() - 1000);
scoreTxt.setText('Score: ' + LK.getScore());
// Create fruit rain effect for 3 seconds
var rainDuration = 3000;
var rainStartTime = LK.ticks;
fruitRainActive = true;
// Create fruits every 100ms (0.1 seconds) during the rain
var rainInterval = LK.setInterval(function () {
if (LK.ticks - rainStartTime >= rainDuration / (1000 / 60)) {
// 3 seconds have passed
LK.clearInterval(rainInterval);
fruitRainActive = false;
return;
}
// Create a random lesser fruit (types 0-4: cherry, strawberry, grape, orange, apple)
var randomType = Math.floor(Math.random() * 5);
var rainFruit = new Fruit(randomType);
// Random X position within container bounds
var fruitRadius = rainFruit.getRadius();
var containerLeft = containerX - containerWidth / 2;
var containerRight = containerX + containerWidth / 2;
var randomX = containerLeft + fruitRadius + Math.random() * (containerRight - containerLeft - 2 * fruitRadius);
// Start from above the container
var containerTop = containerY - containerHeight / 2;
rainFruit.x = randomX;
rainFruit.y = containerTop - 200 - Math.random() * 300; // Start higher with some randomness
// Add slight random horizontal velocity for more natural effect
rainFruit.velocityX = (Math.random() - 0.5) * 2;
rainFruit.velocityY = Math.random() * 2 + 1; // Small downward velocity
rainFruit.angularVelocity = (Math.random() - 0.5) * 0.1;
// Mark as discovered
discoveredFruits[randomType] = true;
storage.discoveredFruits = discoveredFruits;
fruits.push(rainFruit);
game.addChild(rainFruit);
}, 100); // Create fruit every 100ms
}
};
// Global variables for fruit mover mode
var fruitMoverActive = false;
var fruitMoverSelectedFruit = null;
// Global variable for fruit rain mode
var fruitRainActive = false;
// Add fruit mover button click handler
fruitMoverButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (LK.getScore() >= 125 && fruits.length > 0) {
// Deduct score
LK.setScore(LK.getScore() - 125);
scoreTxt.setText('Score: ' + LK.getScore());
// Activate fruit mover mode
fruitMoverActive = true;
fruitMoverSelectedFruit = null;
// Make all fruits green when fruit mover is used
for (var i = 0; i < fruits.length; i++) {
tween(fruits[i], {
tint: 0x00ff00
}, {
duration: 300,
easing: tween.easeOut
});
}
}
};
// Add shake button click handler
shakeButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (LK.getScore() >= 450) {
// Deduct score
LK.setScore(LK.getScore() - 450);
scoreTxt.setText('Score: ' + LK.getScore());
// Move all fruits to random positions within container bounds
for (var i = 0; i < fruits.length; i++) {
var fruit = fruits[i];
var radius = fruit.getRadius();
var containerLeft = containerX - containerWidth / 2;
var containerRight = containerX + containerWidth / 2;
var containerTop = containerY - containerHeight / 2;
var containerBottom = containerY + containerHeight / 2;
// Calculate valid random position within container bounds
var randomX = containerLeft + radius + Math.random() * (containerRight - containerLeft - 2 * radius);
var randomY = containerTop + radius + Math.random() * (containerBottom - containerTop - 2 * radius);
// Animate fruit to new position with tween
tween(fruit, {
x: randomX,
y: randomY
}, {
duration: 500 + Math.random() * 500,
// Random duration between 500-1000ms
easing: tween.easeOut
});
// Reset velocities to prevent physics issues
fruit.velocityX = 0;
fruit.velocityY = 0;
fruit.angularVelocity = 0;
}
}
};
// Do not spawn a fruit at start; only spawn on click/hold
createNextFruit();
// --- Evolution Button and Menu ---
// Evolution button
var evolutionButton = new Text2('EVOLUTION', {
size: 60,
fill: 0x000000
});
evolutionButton.anchor.set(0.5, 0);
// Place directly under the score display, using LK.gui for vertical stacking
evolutionButton.y = scoreTxt.height + 20;
LK.gui.top.addChild(evolutionButton);
// Evolution menu container (hidden by default)
var evolutionMenu = new Container();
evolutionMenu.visible = false;
// Add evolution menu to the front (highest z-index)
game.addChild(evolutionMenu);
// Semi-transparent background for menu
var menuBg = LK.getAsset('container', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
width: 1400,
height: 1400
});
menuBg.alpha = 0.92;
menuBg.tint = 0xeeeeee;
evolutionMenu.addChild(menuBg);
// Title
var evolutionTitle = new Text2('Fruit Evolution', {
size: 90,
fill: 0x222222,
stroke: 0xffffff,
strokeThickness: 4
});
evolutionTitle.anchor.set(0.5, 0);
evolutionTitle.x = 2048 / 2;
evolutionTitle.y = 2732 / 2 - 650;
evolutionMenu.addChild(evolutionTitle);
// Fruit evolution data
var evoFruitAssets = ['cherry', 'strawberry', 'grape', 'orange', 'apple', 'pear', 'peach', 'pineapple', 'melon', 'watermelon', 'lemon', 'coconut', 'dragon', 'kiwi', 'mango', 'papaya', 'durian'];
var evoFruitNames = ['Cherry', 'Strawberry', 'Grape', 'Orange', 'Apple', 'Pear', 'Peach', 'Pineapple', 'Melon', 'Watermelon', 'Lemon', 'Coconut', 'Dragonfruit', 'Kiwi', 'Mango', 'Papaya', 'Durian'];
var evoFruitSizes = [120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 520, 560, 600, 640, 580, 620, 660];
// Draw fruits in a circle
var centerX = 2048 / 2;
var centerY = 2732 / 2 + 80;
var radius = 500;
for (var i = 0; i < evoFruitAssets.length; i++) {
var angle = Math.PI * 2 / evoFruitAssets.length * i - Math.PI / 2;
var fruitAsset = LK.getAsset(evoFruitAssets[i], {
anchorX: 0.5,
anchorY: 0.5
});
// Make all fruits the same size as the strawberry (160x160)
var strawberrySize = 160;
var fruitRadius = strawberrySize / 2;
fruitAsset.width = strawberrySize;
fruitAsset.height = strawberrySize;
fruitAsset.x = centerX + Math.cos(angle) * radius;
fruitAsset.y = centerY + Math.sin(angle) * radius;
// Black out and hide text for undiscovered fruits
if (!discoveredFruits[i]) {
fruitAsset.tint = 0x222222;
fruitAsset.alpha = 0.7;
}
evolutionMenu.addChild(fruitAsset);
// Fruit name label
var nameLabel = new Text2(discoveredFruits[i] ? evoFruitNames[i] : '', {
size: 38,
fill: 0x333333,
stroke: 0xffffff,
strokeThickness: 3
});
nameLabel.anchor.set(0.5, 1);
nameLabel.x = fruitAsset.x;
nameLabel.y = fruitAsset.y - fruitRadius - 10;
evolutionMenu.addChild(nameLabel);
// Draw arrow to next fruit (except last)
if (i < evoFruitAssets.length - 1) {
var nextAngle = Math.PI * 2 / evoFruitAssets.length * (i + 1) - Math.PI / 2;
var arrowX1 = fruitAsset.x + Math.cos(angle) * (fruitRadius + 20);
var arrowY1 = fruitAsset.y + Math.sin(angle) * (fruitRadius + 20);
var arrowX2 = centerX + Math.cos(nextAngle) * (radius - 40);
var arrowY2 = centerY + Math.sin(nextAngle) * (radius - 40);
// Use a small fruit as an arrow "dot"
var arrowDot = LK.getAsset('nextFruit', {
anchorX: 0.5,
anchorY: 0.5,
x: (arrowX1 + arrowX2) / 2,
y: (arrowY1 + arrowY2) / 2,
width: 32,
height: 32
});
arrowDot.tint = 0xaaaaaa;
evolutionMenu.addChild(arrowDot);
}
}
// Show menu on button press
evolutionButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
// If menu is open, close it
if (evolutionMenu.visible) {
evolutionMenu.visible = false;
gameRunning = true;
fruitsFrozen = false;
return;
}
// Otherwise, update and open the menu
var childIdx = 0;
for (var i = 0; i < evoFruitAssets.length; i++) {
// Fruit asset is first, label is second, then arrow dot (if not last)
var fruitAsset = evolutionMenu.children[childIdx + 2]; // skip bg and title
var nameLabel = evolutionMenu.children[childIdx + 3];
if (!discoveredFruits[i]) {
fruitAsset.tint = 0x222222;
fruitAsset.alpha = 0.7;
nameLabel.setText('');
} else {
fruitAsset.tint = 0xffffff;
fruitAsset.alpha = 1.0;
nameLabel.setText(evoFruitNames[i]);
// Text2 stroke properties are set directly, not through style object
nameLabel.stroke = 0xffffff;
nameLabel.strokeThickness = 3;
}
childIdx += 2;
if (i < evoFruitAssets.length - 1) childIdx++; // skip arrow dot
}
evolutionMenu.visible = true;
// Move evolution menu to front to ensure it's on top of all game elements
game.removeChild(evolutionMenu);
game.addChild(evolutionMenu);
// Optionally, darken background or disable gameplay while menu is open
gameRunning = false;
fruitsFrozen = true;
};
// Music will start when first fruit is dropped
var musicStarted = false;
// Music selection system
var musicTracks = ['music1', 'music2', 'music3', 'music4', 'music5'];
var musicNames = ['Classic Melody', 'Upbeat Bounce', 'Chill Vibes', 'Epic Adventure', 'Peaceful Garden'];
var currentMusicIndex = storage.selectedMusic || 0;
var musicMenuVisible = false;
// Music menu button
var musicMenuButton = new Text2('MUSIC', {
size: 60,
fill: 0x000000
});
musicMenuButton.anchor.set(0.5, 0);
musicMenuButton.x = evolutionButton.x + 300;
musicMenuButton.y = evolutionButton.y;
LK.gui.top.addChild(musicMenuButton);
// Music menu container
var musicMenu = new Container();
musicMenu.visible = false;
game.addChild(musicMenu);
// Music menu background
var musicMenuBg = LK.getAsset('container', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
width: 1000,
height: 800
});
musicMenuBg.alpha = 0.95;
musicMenuBg.tint = 0xdddddd;
musicMenu.addChild(musicMenuBg);
// Music menu title
var musicMenuTitle = new Text2('Select Music Track', {
size: 80,
fill: 0x222222,
stroke: 0xffffff,
strokeThickness: 3
});
musicMenuTitle.anchor.set(0.5, 0);
musicMenuTitle.x = 2048 / 2;
musicMenuTitle.y = 2732 / 2 - 300;
musicMenu.addChild(musicMenuTitle);
// Create music selection buttons
var musicButtons = [];
for (var i = 0; i < musicTracks.length; i++) {
var musicButton = new Text2(musicNames[i], {
size: 60,
fill: 0x000000
});
musicButton.anchor.set(0.5, 0.5);
musicButton.x = 2048 / 2;
musicButton.y = 2732 / 2 - 150 + i * 100;
musicButton.musicIndex = i;
// Add click handler for each music button using closure to capture index
(function (index) {
musicButton.down = function (x, y, obj) {
// Update current music selection
currentMusicIndex = index;
storage.selectedMusic = currentMusicIndex;
// Stop current music and play selected track
LK.stopMusic();
LK.playMusic(musicTracks[currentMusicIndex]);
// Close menu
musicMenu.visible = false;
musicMenuVisible = false;
gameRunning = true;
fruitsFrozen = false;
};
})(i);
musicButtons.push(musicButton);
musicMenu.addChild(musicButton);
}
// Music menu button click handler
musicMenuButton.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (musicMenuVisible) {
musicMenu.visible = false;
musicMenuVisible = false;
gameRunning = true;
fruitsFrozen = false;
} else {
musicMenu.visible = true;
musicMenuVisible = true;
// Move music menu to front
game.removeChild(musicMenu);
game.addChild(musicMenu);
gameRunning = false;
fruitsFrozen = true;
}
};
// Event handlers
game.down = function (x, y, obj) {
// Start background music on any click/drag if not already playing
if (!musicStarted) {
LK.playMusic(musicTracks[currentMusicIndex]);
musicStarted = true;
}
// Play drop sound on any interaction
LK.getSound('drop').play();
if (!gameRunning || currentFruit) {
return;
}
// Handle fruit mover mode
if (fruitMoverActive) {
var _loop = function _loop() {
fruit = fruits[i];
dx = x - fruit.x;
dy = y - fruit.y;
distance = Math.sqrt(dx * dx + dy * dy);
if (distance <= fruit.getRadius()) {
var bobUp = function bobUp() {
tween(nextFruitPreview, {
y: originalY - 15
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: bobDown
});
};
var bobDown = function bobDown() {
tween(nextFruitPreview, {
y: originalY + 15
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: bobUp
});
};
// Fruit clicked - delete it and set as next fruit
fruitMoverSelectedFruit = fruit;
nextFruitType = fruit.type;
// Remove fruit from game
for (j = fruits.length - 1; j >= 0; j--) {
if (fruits[j] === fruit) {
fruits[j].destroy();
fruits.splice(j, 1);
break;
}
}
// Update next fruit preview to show the deleted fruit type
if (nextFruitPreview) {
// Stop any existing tweens before destroying
tween.stop(nextFruitPreview);
nextFruitPreview.destroy();
}
fruitAssets = ['cherry', 'strawberry', 'grape', 'orange', 'apple', 'pear', 'peach', 'pineapple', 'melon', 'watermelon', 'lemon', 'coconut', 'dragon', 'kiwi', 'mango', 'papaya', 'durian'];
fruitSizes = [120, 160, 200, 240, 280, 320, 360, 400, 440, 480, 520, 560, 600, 640, 580, 620, 660];
nextFruitPreview = LK.getAsset(fruitAssets[nextFruitType], {
anchorX: 0.5,
anchorY: 0.5
});
nextFruitPreview.x = 1700;
nextFruitPreview.y = 120;
game.addChild(nextFruitPreview);
// Position the label based on fruit size to ensure it's always visible
fruitRadius = fruitSizes[nextFruitType] / 2;
nextFruitLabel.x = nextFruitPreview.x - fruitRadius - 20; // 20px padding from fruit edge
// Add bobbing animation
originalY = nextFruitPreview.y;
bobUp();
// Reset all fruits to normal tint
for (k = 0; k < fruits.length; k++) {
tween(fruits[k], {
tint: 0xffffff
}, {
duration: 300,
easing: tween.easeOut
});
}
// Deactivate fruit mover mode
fruitMoverActive = false;
fruitMoverSelectedFruit = null;
return {
v: void 0
};
}
},
fruit,
dx,
dy,
distance,
j,
fruitAssets,
fruitSizes,
fruitRadius,
originalY,
k,
_ret;
// Check if click is on a fruit
for (var i = 0; i < fruits.length; i++) {
_ret = _loop();
if (_ret) return _ret.v;
}
// If no fruit was clicked, cancel fruit mover mode
fruitMoverActive = false;
for (var m = 0; m < fruits.length; m++) {
tween(fruits[m], {
tint: 0xffffff
}, {
duration: 300,
easing: tween.easeOut
});
}
return;
}
// Only allow spawning if the press is inside the container bounds
var radius = 0;
if (x >= containerX - containerWidth / 2 + radius && x <= containerX + containerWidth / 2 - radius && y >= containerY - containerHeight / 2 + radius && y <= containerY + containerHeight / 2 - radius) {
isDragging = true;
createPreviewFruit(x);
}
};
game.move = function (x, y, obj) {
if (!gameRunning || !isDragging) {
return;
}
updatePreviewFruit(x);
};
game.up = function (x, y, obj) {
if (!gameRunning || !isDragging) {
return;
}
isDragging = false;
var dropX = previewFruit ? previewFruit.x : x;
destroyPreviewFruit();
dropFruit(dropX);
};
// Main game loop
game.update = function () {
if (!gameRunning) {
return;
}
// Update all fruits
if (!fruitsFrozen) {
for (var i = 0; i < fruits.length; i++) {
fruits[i].update();
}
}
// Check collisions and merges
for (var i = 0; i < fruits.length; i++) {
for (var j = i + 1; j < fruits.length; j++) {
var fruit1 = fruits[i];
var fruit2 = fruits[j];
if (fruit1.merged || fruit2.merged) {
continue;
}
if (checkCollision(fruit1, fruit2)) {
// Always apply physics first to prevent sticking
resolveFruitCollision(fruit1, fruit2);
// Then check for merge
var currentMerging = fruit1.type === fruit2.type;
if (!fruit1.lastMergeCheck && currentMerging) {
if (mergeFruits(fruit1, fruit2)) {
break; // Break out of inner loop as fruits array changed
}
}
fruit1.lastMergeCheck = currentMerging;
fruit2.lastMergeCheck = currentMerging;
} else {
fruit1.lastMergeCheck = false;
fruit2.lastMergeCheck = false;
}
}
}
// Check game over condition (disabled during fruit rain)
if (!fruitRainActive && checkGameOver() && LK.ticks % 60 === 0) {
// Check every second
gameRunning = false;
LK.showGameOver();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -151,15 +151,8 @@
// Collision with container bottom
if (self.y + radius > containerBottom) {
self.y = containerBottom - radius;
self.velocityY = -self.velocityY * self.bounceY;
- // Start background music when fruit hits floor if not already playing
- if (typeof musicStarted !== "undefined" && !musicStarted) {
- LK.playMusic(musicTracks[currentMusicIndex]);
- musicStarted = true;
- }
- // Play drop sound when fruit hits floor
- LK.getSound('drop').play();
// Add rotational effect from ground collision only if movement is significant
if (Math.abs(self.velocityX) > 2.0) {
self.angularVelocity += self.velocityX * 0.02;
}
@@ -198,10 +191,10 @@
/****
* Game Code
****/
-// Blue background asset (full screen)
// Attach blue background asset, ensure it's at the back
+// Blue background asset (full screen)
var blueBg = game.attachAsset('blueBg', {
anchorX: 0,
anchorY: 0,
x: 0,
@@ -750,8 +743,15 @@
fruitRainCostText.y = fruitRainButton.y + 60;
game.addChild(fruitRainCostText);
// Add auto merge button click handler
autoMergeButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (LK.getScore() >= 800 && fruits.length > 1) {
// Deduct score
LK.setScore(LK.getScore() - 800);
scoreTxt.setText('Score: ' + LK.getScore());
@@ -760,8 +760,15 @@
}
};
// Add randomize button click handler
randomizeButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (LK.getScore() >= 300 && fruits.length > 1) {
// Deduct score
LK.setScore(LK.getScore() - 300);
scoreTxt.setText('Score: ' + LK.getScore());
@@ -792,8 +799,15 @@
}
};
// Add fruit rain button click handler
fruitRainButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (LK.getScore() >= 1000) {
// Deduct score
LK.setScore(LK.getScore() - 1000);
scoreTxt.setText('Score: ' + LK.getScore());
@@ -839,8 +853,15 @@
// Global variable for fruit rain mode
var fruitRainActive = false;
// Add fruit mover button click handler
fruitMoverButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (LK.getScore() >= 125 && fruits.length > 0) {
// Deduct score
LK.setScore(LK.getScore() - 125);
scoreTxt.setText('Score: ' + LK.getScore());
@@ -859,8 +880,15 @@
}
};
// Add shake button click handler
shakeButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (LK.getScore() >= 450) {
// Deduct score
LK.setScore(LK.getScore() - 450);
scoreTxt.setText('Score: ' + LK.getScore());
@@ -990,8 +1018,15 @@
}
}
// Show menu on button press
evolutionButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
// If menu is open, close it
if (evolutionMenu.visible) {
evolutionMenu.visible = false;
gameRunning = true;
@@ -1026,9 +1061,9 @@
// Optionally, darken background or disable gameplay while menu is open
gameRunning = false;
fruitsFrozen = true;
};
-// Music will start when first fruit is dropped - only once
+// Music will start when first fruit is dropped
var musicStarted = false;
// Music selection system
var musicTracks = ['music1', 'music2', 'music3', 'music4', 'music5'];
var musicNames = ['Classic Melody', 'Upbeat Bounce', 'Chill Vibes', 'Epic Adventure', 'Peaceful Garden'];
@@ -1101,8 +1136,15 @@
musicMenu.addChild(musicButton);
}
// Music menu button click handler
musicMenuButton.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (musicMenuVisible) {
musicMenu.visible = false;
musicMenuVisible = false;
gameRunning = true;
@@ -1118,8 +1160,15 @@
}
};
// Event handlers
game.down = function (x, y, obj) {
+ // Start background music on any click/drag if not already playing
+ if (!musicStarted) {
+ LK.playMusic(musicTracks[currentMusicIndex]);
+ musicStarted = true;
+ }
+ // Play drop sound on any interaction
+ LK.getSound('drop').play();
if (!gameRunning || currentFruit) {
return;
}
// Handle fruit mover mode
Apple with cute face. In-Game asset. 2d. High contrast. No shadows
Cherry with cute face. In-Game asset. 2d. High contrast. No shadows
Greyish blue square. In-Game asset. 2d. High contrast. No shadows
Grapes with a cute face. In-Game asset. 2d. High contrast. No shadows
Circle water melon with cute face. In-Game asset. 2d. High contrast. No shadows
Circle cantaloupe with cute face. In-Game asset. 2d. High contrast. No shadows
Pear with cute face. In-Game asset. 2d. High contrast. No shadows
Strawberry with cute face. In-Game asset. 2d. High contrast. No shadows
Peach with cute face. In-Game asset. 2d. High contrast. No shadows
Pineapple with cute face. In-Game asset. 2d. High contrast. No shadows
Dragon fruit with cute face. In-Game asset. 2d. High contrast. No shadows
Lemon with cute face. In-Game asset. 2d. High contrast. No shadows
Coconut with cute face. In-Game asset. 2d. High contrast. No shadows
Kiwi with cute face. In-Game asset. 2d. High contrast. No shadows
Durian with cute face. In-Game asset. 2d. High contrast. No shadows
Mango with cute face. In-Game asset. 2d. High contrast. No shadows
Papaya with cute face. In-Game asset. 2d. High contrast. No shadows
Arrow pointing down. In-Game asset. 2d. High contrast. No shadows
Shine. In-Game asset. 2d. High contrast. No shadows
Purple galaxy. In-Game asset. 2d. High contrast. No shadows
Blueberry with cute face. In-Game asset. 2d. High contrast. No shadows
Open pomegranate with cute face. In-Game asset. 2d. High contrast. No shadows
A cut in half avocado with cute face. In-Game asset. 2d. High contrast. No shadows
Cranberry’s with cute face. In-Game asset. 2d. High contrast. No shadows