User prompt
sliced fruit water melon should fall down immediately after slicing
User prompt
check sliced fruits falling down or not
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'y')' in or related to this line: 'slicedFruit1.y += slicedFruit1.velocityY;' Line Number: 208
User prompt
Please fix the bug: 'ReferenceError: slicedFruit1 is not defined' in or related to this line: 'slicedFruit1.y += slicedFruit1.velocityY;' Line Number: 207
User prompt
make sure its working Enable gravity on sliced fruit objects to make them fall naturally after slicing ✅ Update sliced fruit objects to apply gravity in their update method
User prompt
How do I enable gravity on sliced fruit objects? I'm using a component-based approach and need the pieces to fall naturally after slicing."
User prompt
Ensure juice splash is triggered immediately upon slicing.
User prompt
Make sliced fruits fall immediately after slicing
User prompt
make sure that sliced fruits are falling immediately after slicing
User prompt
Add soft lighting effect to the background animation
User prompt
Add background animation to the game soft lighting effects
User prompt
Add background animations
User prompt
Improve sound effects for slicing, juice splashes, and bombs exploding
User prompt
add bomb explosion effects
User prompt
Check juice splash effects match the fruit type (e.g., red splash for watermelon, orange for oranges).
User prompt
add juice splash effects
User prompt
make sure that sliced fruits correctly displayed and positioned after slicing.
User prompt
add sliced fruit assets
Code edit (1 edits merged)
Please save this source code
User prompt
need to add backgroung image
User prompt
change code and remove errors
Code edit (1 edits merged)
Please save this source code
User prompt
Fruit Master
User prompt
Title: Fruit Master Description: Unleash your inner ninja in Fruit Slash Master! Slice through flying fruits with precision and speed while avoiding deadly bombs. Master exciting power-ups like Freeze Mode, Frenzy Mode, and Double Score to boost your skills. Compete for high scores, unlock unique blades, and experience the ultimate fruit-slashing challenge. Are you ready to become the ultimate Fruit Ninja? 🍉⚡🔪
User prompt
start fresh
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1", { highScore: 0 }); /**** * Classes ****/ var FruitItem = Container.expand(function () { var self = Container.call(this); var type = 'fruit-watermelon'; var fruitGraphic = null; self.isBomb = false; self.isPowerup = false; self.powerupType = ''; self.sliced = false; self.velocityX = 0; self.velocityY = 0; self.gravity = 0.25; self.rotationSpeed = 0; self.init = function (fruitType, startX, startY, velX, velY) { type = fruitType; self.isBomb = fruitType === 'bomb'; self.isPowerup = fruitType.indexOf('powerup') !== -1; if (self.isPowerup) { self.powerupType = fruitType.split('-')[1]; } fruitGraphic = self.attachAsset(fruitType, { anchorX: 0.5, anchorY: 0.5 }); self.x = startX; self.y = startY; self.velocityX = velX; self.velocityY = velY; self.lastX = startX; // Initialize lastX for tracking changes on X self.lastY = startY; // Initialize lastY for tracking changes on Y self.rotationSpeed = (Math.random() - 0.5) * 0.05; return self; }; var slicedFruit1, slicedFruit2; // Declare slicedFruit1 and slicedFruit2 self.slice = function () { if (self.sliced) { return false; } self.sliced = true; if (self.isBomb) { // Bomb blast tween effect var bombBlast = LK.getAsset('bomb-blast', { anchorX: 0.5, anchorY: 0.5, x: self.x, y: self.y, alpha: 1.0 }); game.addChild(bombBlast); tween(bombBlast, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { bombBlast.destroy(); } }); // Bomb visual effect tween(fruitGraphic, { alpha: 0.5, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, easing: tween.easeOut }); // Add bomb explosion effect var explosion = LK.getAsset('juice-splash', { anchorX: 0.5, anchorY: 0.5, x: self.x, y: self.y, alpha: 0.8, tint: 0xff0000 // Red explosion }); game.addChild(explosion); tween(explosion, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { explosion.destroy(); } }); LK.getSound('bomb').play(); return true; } else if (self.isPowerup) { // Powerup visual effect tween(fruitGraphic, { alpha: 0.7, scaleX: 0.7, scaleY: 0.7 }, { duration: 300, easing: tween.easeOut }); LK.getSound('powerup').play(); return true; } else { // Regular fruit slicing effect tween(fruitGraphic, { alpha: 0.7, scaleX: 0.7, scaleY: 0.7 }, { duration: 300, easing: tween.easeOut }); // Add juice splash effect var splashColor = 0xff0000; // Default to red switch (type) { case 'combo-fruit': splashColor = 0x8A2BE2; // BlueViolet break; //{15.1} case 'fruit-watermelon': splashColor = 0xff0000; // Red break; case 'fruit-orange': splashColor = 0xffa500; // Orange break; case 'fruit-apple': splashColor = 0x00ff00; // Green break; case 'fruit-banana': splashColor = 0xffff00; // Yellow break; case 'fruit-strawberry': splashColor = 0xff69b4; // Pink break; case 'fruit-pineapple': splashColor = 0xffd700; // Gold break; case 'fruit-papaya': splashColor = 0xff4500; // OrangeRed break; case 'fruit-lemon': splashColor = 0xfff44f; // LemonChiffon break; } var juiceSplash = LK.getAsset('juice-splash', { anchorX: 0.5, anchorY: 0.5, x: self.x, y: self.y, alpha: 0.8, tint: splashColor }); game.addChild(juiceSplash); tween(juiceSplash, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { juiceSplash.destroy(); } }); // Split the fruit in two (visual effect) var halfScale = fruitGraphic.scaleX * 0.7; // Create sliced fruit assets slicedFruit1 = LK.getAsset('sliced-' + type, { anchorX: 0.5, anchorY: 0.5, x: self.x - 20, y: self.y, rotation: fruitGraphic.rotation }); slicedFruit2 = LK.getAsset('sliced-' + type, { anchorX: 0.5, anchorY: 0.5, x: self.x + 20, y: self.y, rotation: fruitGraphic.rotation }); // Add sliced fruits to the game game.addChild(slicedFruit1); game.addChild(slicedFruit2); // Apply velocity to sliced fruits slicedFruit1.velocityX = self.velocityX - 2; slicedFruit2.velocityX = self.velocityX + 2; slicedFruit1.velocityY = self.velocityY + 20; // Further increase Y velocity for immediate fall slicedFruit2.velocityY = self.velocityY + 20; // Further increase Y velocity for immediate fall slicedFruit1.gravity = self.gravity; // Apply gravity to the first sliced fruit slicedFruit2.gravity = self.gravity; // Apply gravity to the second sliced fruit // Remove the original fruit graphic fruitGraphic.destroy(); // Now separate the halves self.velocityX = self.velocityX * 0.5; self.rotationSpeed = self.rotationSpeed * 2; LK.getSound('slice').play(); return true; } }; self.update = function () { if (!gameActive) { return; } // Apply physics self.velocityY += self.gravity * (gameState.freezeMode ? 0.3 : 1); self.x += self.velocityX * (gameState.freezeMode ? 0.3 : 1); self.y += self.velocityY * (gameState.freezeMode ? 0.3 : 1); // Apply gravity to sliced fruits if (self.sliced) { self.velocityY += self.gravity; if (slicedFruit1 && slicedFruit2) { slicedFruit1.velocityY += slicedFruit1.gravity; slicedFruit2.velocityY += slicedFruit2.gravity; slicedFruit1.y += slicedFruit1.velocityY; slicedFruit2.y += slicedFruit2.velocityY; } } // Prevent fruits from getting too close to the side boundaries if (self.x < 100 && self.velocityX < 0) { self.velocityX = Math.abs(self.velocityX); // Move right if too close to the left } else if (self.x > 1948 && self.velocityX > 0) { self.velocityX = -Math.abs(self.velocityX); // Move left if too close to the right } self.lastX = self.x; // Update lastX after applying physics self.lastY = self.y; // Update lastY after applying physics // Apply rotation fruitGraphic.rotation += self.rotationSpeed * (gameState.freezeMode ? 0.3 : 1); // Check if fruit is out of bounds if (self.y > 2732 + fruitGraphic.height) { // Check if we missed a fruit (not a bomb) if (!self.sliced && !self.isBomb && !self.isPowerup) { gameState.lives--; updateLivesDisplay(); if (gameState.lives <= 0) { endGame(); } } self.destroy(); var index = fruits.indexOf(self); if (index !== -1) { fruits.splice(index, 1); } } }; return self; }); var Slash = Container.expand(function () { var self = Container.call(this); var slashGraphic = self.attachAsset('slash', { anchorX: 0.5, anchorY: 0.5, alpha: 1.0, tint: 0x00ff00 // Initial green tint }); self.startPoint = { x: 0, y: 0 }; self.endPoint = { x: 0, y: 0 }; self.setup = function (startX, startY, endX, endY) { self.startPoint.x = startX; self.startPoint.y = startY; self.endPoint.x = endX; self.endPoint.y = endY; // Calculate position (midpoint) self.x = (startX + endX) / 2; self.y = (startY + endY) / 2; // Calculate angle var angle = Math.atan2(endY - startY, endX - startX); slashGraphic.rotation = angle; // Calculate length var length = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2)); slashGraphic.width = length; // Adjust color intensity based on speed var speed = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2)); var intensity = Math.min(1, speed / 100); slashGraphic.tint = 0x00ff00 + Math.floor(intensity * 0xff0000); // Vary between green and red return self; }; self.fadeOut = function () { tween(slashGraphic, { alpha: 0 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ //{0.2} //{0.1} // Sliced watermelon asset // Sliced strawberry asset // Sliced orange asset // Sliced banana asset // Sliced apple asset //{0.1} var background = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChild(background); // Add soft lighting effect to the background var lightingEffect = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2, alpha: 0.3, // Soft lighting effect tint: 0xffffe0 // Light yellow tint for soft lighting }); game.addChild(lightingEffect); tween(lightingEffect, { alpha: 0.5 }, { duration: 2000, yoyo: true, repeat: Infinity, easing: tween.easeInOutSine }); // Game state var gameActive = false; var gameState = { score: 0, lives: 3, combo: 0, comboTimer: 0, freezeMode: false, freezeTimer: 0, frenzyMode: false, frenzyTimer: 0, doubleScoreMode: false, doubleScoreTimer: 0, spawnRate: 60, // Frames between fruit spawns spawnCounter: 0, difficulty: 1 }; // Game arrays var fruits = []; var slashes = []; // Create UI elements var scoreText = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreText.anchor.set(0.5, 0); LK.gui.top.addChild(scoreText); var livesText = new Text2('Lives: 3', { size: 60, fill: 0xFFFFFF }); livesText.anchor.set(0, 0); livesText.x = 50; livesText.y = 50; LK.gui.topRight.addChild(livesText); var comboText = new Text2('', { size: 70, fill: 0xF39C12, fontWeight: 'bold' // Make text bold }); comboText.anchor.set(0.5, 0.5); comboText.alpha = 0; LK.gui.center.addChild(comboText); // Add tween effect to comboText tween(comboText, { alpha: 1, scaleX: 1.2, scaleY: 1.2 }, { duration: 500, easing: tween.easeInOut, onFinish: function onFinish() { tween(comboText, { alpha: 0, scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.easeInOut }); } }); var powerupText = new Text2('', { size: 60, fill: 0x3498DB }); powerupText.anchor.set(0.5, 1); powerupText.alpha = 0; LK.gui.bottom.addChild(powerupText); // Track swipe var swipeStart = { x: 0, y: 0 }; var isSwipe = false; var lastMouseX = 0; var lastMouseY = 0; // Handlers for touch/mouse events game.down = function (x, y, obj) { if (!gameActive) { return; } swipeStart.x = x; swipeStart.y = y; isSwipe = true; lastMouseX = x; lastMouseY = y; }; game.move = function (x, y, obj) { if (!isSwipe || !gameActive) { if (!gameActive) { // Start game on first swipe startGame(); } return; } // Create slash effect if moved enough distance var dist = Math.sqrt(Math.pow(x - lastMouseX, 2) + Math.pow(y - lastMouseY, 2)); if (dist > 30) { var slash = new Slash().setup(lastMouseX, lastMouseY, x, y); game.addChild(slash); slashes.push(slash); // Check for fruit collisions checkSlashCollisions(lastMouseX, lastMouseY, x, y); slash.fadeOut(); lastMouseX = x; lastMouseY = y; } }; game.up = function (x, y, obj) { isSwipe = false; }; // Helper functions function startGame() { // Reset game state gameState.score = 0; gameState.lives = 3; gameState.combo = 0; gameState.comboTimer = 0; gameState.freezeMode = false; gameState.freezeTimer = 0; gameState.frenzyMode = false; gameState.frenzyTimer = 0; gameState.doubleScoreMode = false; gameState.doubleScoreTimer = 0; gameState.spawnRate = 60; gameState.spawnCounter = 0; gameState.difficulty = 1; // Clear any existing fruits for (var i = fruits.length - 1; i >= 0; i--) { fruits[i].destroy(); } fruits = []; // Clear any existing slashes for (var i = slashes.length - 1; i >= 0; i--) { slashes[i].destroy(); } slashes = []; // Reset UI scoreText.setText("0"); updateLivesDisplay(); // Remove the 'swipe-to-slice' asset swipeToSliceAsset.destroy(); // Start the game gameActive = true; // Play music LK.playMusic('gameMusic'); } function endGame() { gameActive = false; // Check high score if (gameState.score > storage.highScore) { storage.highScore = gameState.score; } // Show game over LK.showGameOver(); // Stop music LK.stopMusic(); } function updateLivesDisplay() { livesText.setText("Lives: " + gameState.lives); } function checkSlashCollisions(startX, startY, endX, endY) { var sliced = false; var slashLine = { x1: startX, y1: startY, x2: endX, y2: endY }; for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; if (fruit.sliced) { continue; } // Simple line-circle intersection for collision detection if (lineCircleIntersect(slashLine, { x: fruit.x, y: fruit.y, r: fruit.width / 2 })) { var result = fruit.slice(); if (result) { sliced = true; if (fruit.isBomb) { // Hit a bomb endGame(); // Trigger game over immediately // Reset combo gameState.combo = 0; comboText.alpha = 0; } else if (fruit.isPowerup) { // Activate powerup activatePowerup(fruit.powerupType); } else { // Regular fruit updateScore(10); // Update combo gameState.combo++; gameState.comboTimer = 120; // 2 seconds at 60fps if (gameState.combo >= 3) { comboText.setText("COMBO x" + gameState.combo + "!"); comboText.alpha = 1; // Add bonus points for combo updateScore(gameState.combo * 5); } } } } } return sliced; } function lineCircleIntersect(line, circle) { // Distance formula for point-line segment distance var dx = line.x2 - line.x1; var dy = line.y2 - line.y1; var len = Math.sqrt(dx * dx + dy * dy); // Normalize direction vector dx /= len; dy /= len; // Vector from line start to circle center var cx = circle.x - line.x1; var cy = circle.y - line.y1; // Project circle center onto line var projLen = cx * dx + cy * dy; // Calculate closest point on line to circle center var closestX, closestY; // Handle cases where circle center projection is outside line segment if (projLen < 0) { closestX = line.x1; closestY = line.y1; } else if (projLen > len) { closestX = line.x2; closestY = line.y2; } else { closestX = line.x1 + projLen * dx; closestY = line.y1 + projLen * dy; } // Calculate distance from closest point to circle center var distance = Math.sqrt(Math.pow(circle.x - closestX, 2) + Math.pow(circle.y - closestY, 2)); // Check if distance is less than circle radius return distance <= circle.r; } function updateScore(points) { // Apply double score if active if (gameState.doubleScoreMode) { points *= 2; } gameState.score += points; // Check if score is a multiple of 100 if (gameState.score % 100 === 0) { // Add two bombs as a special effect spawnSpecificFruit('bomb'); spawnSpecificFruit('bomb'); } scoreText.setText(gameState.score); // Update game score LK.setScore(gameState.score); } function activatePowerup(type) { // Duration in frames (60fps) var duration = 300; // 5 seconds switch (type) { case 'freeze': gameState.freezeMode = true; gameState.freezeTimer = duration; showPowerupMessage("FREEZE MODE!"); break; case 'frenzy': gameState.frenzyMode = true; gameState.frenzyTimer = duration; showPowerupMessage("FRUIT FRENZY!"); break; case 'double': gameState.doubleScoreMode = true; gameState.doubleScoreTimer = duration; showPowerupMessage("DOUBLE SCORE!"); break; } } function showPowerupMessage(message) { powerupText.setText(message); powerupText.alpha = 1; tween(powerupText, { alpha: 0 }, { duration: 2000 }); } function spawnFruit() { // Determine if we should spawn a fruit based on spawn rate if (gameState.spawnCounter <= 0) { // Reset counter gameState.spawnCounter = gameState.frenzyMode ? Math.floor(gameState.spawnRate / 3) : gameState.spawnRate; // Determine how many fruits to spawn var fruitCount = 1; if (gameState.difficulty >= 2) { fruitCount++; } if (gameState.difficulty >= 4) { fruitCount++; } if (gameState.frenzyMode) { fruitCount += 2; } // Spawn multiple fruits for (var i = 0; i < fruitCount; i++) { spawnSingleFruit(); } // Possibly spawn a bomb (higher chance with higher difficulty) if (Math.random() < 0.1 * gameState.difficulty && !gameState.frenzyMode) { spawnSpecificFruit('bomb'); } // Possibly spawn a powerup (lower chance) if (Math.random() < 0.03) { var powerupTypes = ['powerup-freeze', 'powerup-frenzy', 'powerup-double']; var randomPowerup = powerupTypes[Math.floor(Math.random() * powerupTypes.length)]; spawnSpecificFruit(randomPowerup); } } else { gameState.spawnCounter--; } } function spawnSingleFruit() { var fruitTypes = ['fruit-watermelon', 'fruit-orange', 'fruit-apple', 'fruit-banana', 'fruit-strawberry', 'fruit-pineapple', 'fruit-papaya', 'fruit-lemon', 'combo-fruit']; var randomFruit = fruitTypes[Math.floor(Math.random() * fruitTypes.length)]; spawnSpecificFruit(randomFruit); } function spawnSpecificFruit(fruitType) { // Determine spawn position and velocity var startX = Math.random() * 2048; var startY = 2732 + 100; // Start below screen // Determine velocity var velocityX = (Math.random() - 0.5) * 10; // -5 to 5 var velocityY = -20 - Math.random() * 5; // -20 to -25 (upward) // Create fruit and add to game var fruit = new FruitItem().init(fruitType, startX, startY, velocityX, velocityY); game.addChild(fruit); fruits.push(fruit); } // Main game update game.update = function () { if (!gameActive) { return; } // Update all fruits for (var i = fruits.length - 1; i >= 0; i--) { fruits[i].update(); } // Handle spawning of new fruits spawnFruit(); // Update combo timer if (gameState.comboTimer > 0) { gameState.comboTimer--; if (gameState.comboTimer <= 0) { gameState.combo = 0; comboText.alpha = 0; } } // Update powerup timers if (gameState.freezeTimer > 0) { gameState.freezeTimer--; if (gameState.freezeTimer <= 0) { gameState.freezeMode = false; } } if (gameState.frenzyTimer > 0) { gameState.frenzyTimer--; if (gameState.frenzyTimer <= 0) { gameState.frenzyMode = false; } } if (gameState.doubleScoreTimer > 0) { gameState.doubleScoreTimer--; if (gameState.doubleScoreTimer <= 0) { gameState.doubleScoreMode = false; } } // Increase difficulty over time if (LK.ticks % 1800 === 0) { // Every 30 seconds gameState.difficulty += 0.5; gameState.spawnRate = Math.max(30, gameState.spawnRate - 5); } }; // Start with instructions var swipeToSliceAsset = LK.getAsset('swipe-to-slice', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 // Moved further downwards }); game.addChild(swipeToSliceAsset);
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1", {
highScore: 0
});
/****
* Classes
****/
var FruitItem = Container.expand(function () {
var self = Container.call(this);
var type = 'fruit-watermelon';
var fruitGraphic = null;
self.isBomb = false;
self.isPowerup = false;
self.powerupType = '';
self.sliced = false;
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.25;
self.rotationSpeed = 0;
self.init = function (fruitType, startX, startY, velX, velY) {
type = fruitType;
self.isBomb = fruitType === 'bomb';
self.isPowerup = fruitType.indexOf('powerup') !== -1;
if (self.isPowerup) {
self.powerupType = fruitType.split('-')[1];
}
fruitGraphic = self.attachAsset(fruitType, {
anchorX: 0.5,
anchorY: 0.5
});
self.x = startX;
self.y = startY;
self.velocityX = velX;
self.velocityY = velY;
self.lastX = startX; // Initialize lastX for tracking changes on X
self.lastY = startY; // Initialize lastY for tracking changes on Y
self.rotationSpeed = (Math.random() - 0.5) * 0.05;
return self;
};
var slicedFruit1, slicedFruit2; // Declare slicedFruit1 and slicedFruit2
self.slice = function () {
if (self.sliced) {
return false;
}
self.sliced = true;
if (self.isBomb) {
// Bomb blast tween effect
var bombBlast = LK.getAsset('bomb-blast', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
alpha: 1.0
});
game.addChild(bombBlast);
tween(bombBlast, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
bombBlast.destroy();
}
});
// Bomb visual effect
tween(fruitGraphic, {
alpha: 0.5,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 300,
easing: tween.easeOut
});
// Add bomb explosion effect
var explosion = LK.getAsset('juice-splash', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
alpha: 0.8,
tint: 0xff0000 // Red explosion
});
game.addChild(explosion);
tween(explosion, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
explosion.destroy();
}
});
LK.getSound('bomb').play();
return true;
} else if (self.isPowerup) {
// Powerup visual effect
tween(fruitGraphic, {
alpha: 0.7,
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 300,
easing: tween.easeOut
});
LK.getSound('powerup').play();
return true;
} else {
// Regular fruit slicing effect
tween(fruitGraphic, {
alpha: 0.7,
scaleX: 0.7,
scaleY: 0.7
}, {
duration: 300,
easing: tween.easeOut
});
// Add juice splash effect
var splashColor = 0xff0000; // Default to red
switch (type) {
case 'combo-fruit':
splashColor = 0x8A2BE2; // BlueViolet
break;
//{15.1}
case 'fruit-watermelon':
splashColor = 0xff0000; // Red
break;
case 'fruit-orange':
splashColor = 0xffa500; // Orange
break;
case 'fruit-apple':
splashColor = 0x00ff00; // Green
break;
case 'fruit-banana':
splashColor = 0xffff00; // Yellow
break;
case 'fruit-strawberry':
splashColor = 0xff69b4; // Pink
break;
case 'fruit-pineapple':
splashColor = 0xffd700; // Gold
break;
case 'fruit-papaya':
splashColor = 0xff4500; // OrangeRed
break;
case 'fruit-lemon':
splashColor = 0xfff44f; // LemonChiffon
break;
}
var juiceSplash = LK.getAsset('juice-splash', {
anchorX: 0.5,
anchorY: 0.5,
x: self.x,
y: self.y,
alpha: 0.8,
tint: splashColor
});
game.addChild(juiceSplash);
tween(juiceSplash, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
juiceSplash.destroy();
}
});
// Split the fruit in two (visual effect)
var halfScale = fruitGraphic.scaleX * 0.7;
// Create sliced fruit assets
slicedFruit1 = LK.getAsset('sliced-' + type, {
anchorX: 0.5,
anchorY: 0.5,
x: self.x - 20,
y: self.y,
rotation: fruitGraphic.rotation
});
slicedFruit2 = LK.getAsset('sliced-' + type, {
anchorX: 0.5,
anchorY: 0.5,
x: self.x + 20,
y: self.y,
rotation: fruitGraphic.rotation
});
// Add sliced fruits to the game
game.addChild(slicedFruit1);
game.addChild(slicedFruit2);
// Apply velocity to sliced fruits
slicedFruit1.velocityX = self.velocityX - 2;
slicedFruit2.velocityX = self.velocityX + 2;
slicedFruit1.velocityY = self.velocityY + 20; // Further increase Y velocity for immediate fall
slicedFruit2.velocityY = self.velocityY + 20; // Further increase Y velocity for immediate fall
slicedFruit1.gravity = self.gravity; // Apply gravity to the first sliced fruit
slicedFruit2.gravity = self.gravity; // Apply gravity to the second sliced fruit
// Remove the original fruit graphic
fruitGraphic.destroy();
// Now separate the halves
self.velocityX = self.velocityX * 0.5;
self.rotationSpeed = self.rotationSpeed * 2;
LK.getSound('slice').play();
return true;
}
};
self.update = function () {
if (!gameActive) {
return;
}
// Apply physics
self.velocityY += self.gravity * (gameState.freezeMode ? 0.3 : 1);
self.x += self.velocityX * (gameState.freezeMode ? 0.3 : 1);
self.y += self.velocityY * (gameState.freezeMode ? 0.3 : 1);
// Apply gravity to sliced fruits
if (self.sliced) {
self.velocityY += self.gravity;
if (slicedFruit1 && slicedFruit2) {
slicedFruit1.velocityY += slicedFruit1.gravity;
slicedFruit2.velocityY += slicedFruit2.gravity;
slicedFruit1.y += slicedFruit1.velocityY;
slicedFruit2.y += slicedFruit2.velocityY;
}
}
// Prevent fruits from getting too close to the side boundaries
if (self.x < 100 && self.velocityX < 0) {
self.velocityX = Math.abs(self.velocityX); // Move right if too close to the left
} else if (self.x > 1948 && self.velocityX > 0) {
self.velocityX = -Math.abs(self.velocityX); // Move left if too close to the right
}
self.lastX = self.x; // Update lastX after applying physics
self.lastY = self.y; // Update lastY after applying physics
// Apply rotation
fruitGraphic.rotation += self.rotationSpeed * (gameState.freezeMode ? 0.3 : 1);
// Check if fruit is out of bounds
if (self.y > 2732 + fruitGraphic.height) {
// Check if we missed a fruit (not a bomb)
if (!self.sliced && !self.isBomb && !self.isPowerup) {
gameState.lives--;
updateLivesDisplay();
if (gameState.lives <= 0) {
endGame();
}
}
self.destroy();
var index = fruits.indexOf(self);
if (index !== -1) {
fruits.splice(index, 1);
}
}
};
return self;
});
var Slash = Container.expand(function () {
var self = Container.call(this);
var slashGraphic = self.attachAsset('slash', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1.0,
tint: 0x00ff00 // Initial green tint
});
self.startPoint = {
x: 0,
y: 0
};
self.endPoint = {
x: 0,
y: 0
};
self.setup = function (startX, startY, endX, endY) {
self.startPoint.x = startX;
self.startPoint.y = startY;
self.endPoint.x = endX;
self.endPoint.y = endY;
// Calculate position (midpoint)
self.x = (startX + endX) / 2;
self.y = (startY + endY) / 2;
// Calculate angle
var angle = Math.atan2(endY - startY, endX - startX);
slashGraphic.rotation = angle;
// Calculate length
var length = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
slashGraphic.width = length;
// Adjust color intensity based on speed
var speed = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
var intensity = Math.min(1, speed / 100);
slashGraphic.tint = 0x00ff00 + Math.floor(intensity * 0xff0000); // Vary between green and red
return self;
};
self.fadeOut = function () {
tween(slashGraphic, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000
});
/****
* Game Code
****/
//{0.2}
//{0.1}
// Sliced watermelon asset
// Sliced strawberry asset
// Sliced orange asset
// Sliced banana asset
// Sliced apple asset
//{0.1}
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(background);
// Add soft lighting effect to the background
var lightingEffect = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2,
alpha: 0.3,
// Soft lighting effect
tint: 0xffffe0 // Light yellow tint for soft lighting
});
game.addChild(lightingEffect);
tween(lightingEffect, {
alpha: 0.5
}, {
duration: 2000,
yoyo: true,
repeat: Infinity,
easing: tween.easeInOutSine
});
// Game state
var gameActive = false;
var gameState = {
score: 0,
lives: 3,
combo: 0,
comboTimer: 0,
freezeMode: false,
freezeTimer: 0,
frenzyMode: false,
frenzyTimer: 0,
doubleScoreMode: false,
doubleScoreTimer: 0,
spawnRate: 60,
// Frames between fruit spawns
spawnCounter: 0,
difficulty: 1
};
// Game arrays
var fruits = [];
var slashes = [];
// Create UI elements
var scoreText = new Text2('0', {
size: 100,
fill: 0xFFFFFF
});
scoreText.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreText);
var livesText = new Text2('Lives: 3', {
size: 60,
fill: 0xFFFFFF
});
livesText.anchor.set(0, 0);
livesText.x = 50;
livesText.y = 50;
LK.gui.topRight.addChild(livesText);
var comboText = new Text2('', {
size: 70,
fill: 0xF39C12,
fontWeight: 'bold' // Make text bold
});
comboText.anchor.set(0.5, 0.5);
comboText.alpha = 0;
LK.gui.center.addChild(comboText);
// Add tween effect to comboText
tween(comboText, {
alpha: 1,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(comboText, {
alpha: 0,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
var powerupText = new Text2('', {
size: 60,
fill: 0x3498DB
});
powerupText.anchor.set(0.5, 1);
powerupText.alpha = 0;
LK.gui.bottom.addChild(powerupText);
// Track swipe
var swipeStart = {
x: 0,
y: 0
};
var isSwipe = false;
var lastMouseX = 0;
var lastMouseY = 0;
// Handlers for touch/mouse events
game.down = function (x, y, obj) {
if (!gameActive) {
return;
}
swipeStart.x = x;
swipeStart.y = y;
isSwipe = true;
lastMouseX = x;
lastMouseY = y;
};
game.move = function (x, y, obj) {
if (!isSwipe || !gameActive) {
if (!gameActive) {
// Start game on first swipe
startGame();
}
return;
}
// Create slash effect if moved enough distance
var dist = Math.sqrt(Math.pow(x - lastMouseX, 2) + Math.pow(y - lastMouseY, 2));
if (dist > 30) {
var slash = new Slash().setup(lastMouseX, lastMouseY, x, y);
game.addChild(slash);
slashes.push(slash);
// Check for fruit collisions
checkSlashCollisions(lastMouseX, lastMouseY, x, y);
slash.fadeOut();
lastMouseX = x;
lastMouseY = y;
}
};
game.up = function (x, y, obj) {
isSwipe = false;
};
// Helper functions
function startGame() {
// Reset game state
gameState.score = 0;
gameState.lives = 3;
gameState.combo = 0;
gameState.comboTimer = 0;
gameState.freezeMode = false;
gameState.freezeTimer = 0;
gameState.frenzyMode = false;
gameState.frenzyTimer = 0;
gameState.doubleScoreMode = false;
gameState.doubleScoreTimer = 0;
gameState.spawnRate = 60;
gameState.spawnCounter = 0;
gameState.difficulty = 1;
// Clear any existing fruits
for (var i = fruits.length - 1; i >= 0; i--) {
fruits[i].destroy();
}
fruits = [];
// Clear any existing slashes
for (var i = slashes.length - 1; i >= 0; i--) {
slashes[i].destroy();
}
slashes = [];
// Reset UI
scoreText.setText("0");
updateLivesDisplay();
// Remove the 'swipe-to-slice' asset
swipeToSliceAsset.destroy();
// Start the game
gameActive = true;
// Play music
LK.playMusic('gameMusic');
}
function endGame() {
gameActive = false;
// Check high score
if (gameState.score > storage.highScore) {
storage.highScore = gameState.score;
}
// Show game over
LK.showGameOver();
// Stop music
LK.stopMusic();
}
function updateLivesDisplay() {
livesText.setText("Lives: " + gameState.lives);
}
function checkSlashCollisions(startX, startY, endX, endY) {
var sliced = false;
var slashLine = {
x1: startX,
y1: startY,
x2: endX,
y2: endY
};
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
if (fruit.sliced) {
continue;
}
// Simple line-circle intersection for collision detection
if (lineCircleIntersect(slashLine, {
x: fruit.x,
y: fruit.y,
r: fruit.width / 2
})) {
var result = fruit.slice();
if (result) {
sliced = true;
if (fruit.isBomb) {
// Hit a bomb
endGame(); // Trigger game over immediately
// Reset combo
gameState.combo = 0;
comboText.alpha = 0;
} else if (fruit.isPowerup) {
// Activate powerup
activatePowerup(fruit.powerupType);
} else {
// Regular fruit
updateScore(10);
// Update combo
gameState.combo++;
gameState.comboTimer = 120; // 2 seconds at 60fps
if (gameState.combo >= 3) {
comboText.setText("COMBO x" + gameState.combo + "!");
comboText.alpha = 1;
// Add bonus points for combo
updateScore(gameState.combo * 5);
}
}
}
}
}
return sliced;
}
function lineCircleIntersect(line, circle) {
// Distance formula for point-line segment distance
var dx = line.x2 - line.x1;
var dy = line.y2 - line.y1;
var len = Math.sqrt(dx * dx + dy * dy);
// Normalize direction vector
dx /= len;
dy /= len;
// Vector from line start to circle center
var cx = circle.x - line.x1;
var cy = circle.y - line.y1;
// Project circle center onto line
var projLen = cx * dx + cy * dy;
// Calculate closest point on line to circle center
var closestX, closestY;
// Handle cases where circle center projection is outside line segment
if (projLen < 0) {
closestX = line.x1;
closestY = line.y1;
} else if (projLen > len) {
closestX = line.x2;
closestY = line.y2;
} else {
closestX = line.x1 + projLen * dx;
closestY = line.y1 + projLen * dy;
}
// Calculate distance from closest point to circle center
var distance = Math.sqrt(Math.pow(circle.x - closestX, 2) + Math.pow(circle.y - closestY, 2));
// Check if distance is less than circle radius
return distance <= circle.r;
}
function updateScore(points) {
// Apply double score if active
if (gameState.doubleScoreMode) {
points *= 2;
}
gameState.score += points;
// Check if score is a multiple of 100
if (gameState.score % 100 === 0) {
// Add two bombs as a special effect
spawnSpecificFruit('bomb');
spawnSpecificFruit('bomb');
}
scoreText.setText(gameState.score);
// Update game score
LK.setScore(gameState.score);
}
function activatePowerup(type) {
// Duration in frames (60fps)
var duration = 300; // 5 seconds
switch (type) {
case 'freeze':
gameState.freezeMode = true;
gameState.freezeTimer = duration;
showPowerupMessage("FREEZE MODE!");
break;
case 'frenzy':
gameState.frenzyMode = true;
gameState.frenzyTimer = duration;
showPowerupMessage("FRUIT FRENZY!");
break;
case 'double':
gameState.doubleScoreMode = true;
gameState.doubleScoreTimer = duration;
showPowerupMessage("DOUBLE SCORE!");
break;
}
}
function showPowerupMessage(message) {
powerupText.setText(message);
powerupText.alpha = 1;
tween(powerupText, {
alpha: 0
}, {
duration: 2000
});
}
function spawnFruit() {
// Determine if we should spawn a fruit based on spawn rate
if (gameState.spawnCounter <= 0) {
// Reset counter
gameState.spawnCounter = gameState.frenzyMode ? Math.floor(gameState.spawnRate / 3) : gameState.spawnRate;
// Determine how many fruits to spawn
var fruitCount = 1;
if (gameState.difficulty >= 2) {
fruitCount++;
}
if (gameState.difficulty >= 4) {
fruitCount++;
}
if (gameState.frenzyMode) {
fruitCount += 2;
}
// Spawn multiple fruits
for (var i = 0; i < fruitCount; i++) {
spawnSingleFruit();
}
// Possibly spawn a bomb (higher chance with higher difficulty)
if (Math.random() < 0.1 * gameState.difficulty && !gameState.frenzyMode) {
spawnSpecificFruit('bomb');
}
// Possibly spawn a powerup (lower chance)
if (Math.random() < 0.03) {
var powerupTypes = ['powerup-freeze', 'powerup-frenzy', 'powerup-double'];
var randomPowerup = powerupTypes[Math.floor(Math.random() * powerupTypes.length)];
spawnSpecificFruit(randomPowerup);
}
} else {
gameState.spawnCounter--;
}
}
function spawnSingleFruit() {
var fruitTypes = ['fruit-watermelon', 'fruit-orange', 'fruit-apple', 'fruit-banana', 'fruit-strawberry', 'fruit-pineapple', 'fruit-papaya', 'fruit-lemon', 'combo-fruit'];
var randomFruit = fruitTypes[Math.floor(Math.random() * fruitTypes.length)];
spawnSpecificFruit(randomFruit);
}
function spawnSpecificFruit(fruitType) {
// Determine spawn position and velocity
var startX = Math.random() * 2048;
var startY = 2732 + 100; // Start below screen
// Determine velocity
var velocityX = (Math.random() - 0.5) * 10; // -5 to 5
var velocityY = -20 - Math.random() * 5; // -20 to -25 (upward)
// Create fruit and add to game
var fruit = new FruitItem().init(fruitType, startX, startY, velocityX, velocityY);
game.addChild(fruit);
fruits.push(fruit);
}
// Main game update
game.update = function () {
if (!gameActive) {
return;
}
// Update all fruits
for (var i = fruits.length - 1; i >= 0; i--) {
fruits[i].update();
}
// Handle spawning of new fruits
spawnFruit();
// Update combo timer
if (gameState.comboTimer > 0) {
gameState.comboTimer--;
if (gameState.comboTimer <= 0) {
gameState.combo = 0;
comboText.alpha = 0;
}
}
// Update powerup timers
if (gameState.freezeTimer > 0) {
gameState.freezeTimer--;
if (gameState.freezeTimer <= 0) {
gameState.freezeMode = false;
}
}
if (gameState.frenzyTimer > 0) {
gameState.frenzyTimer--;
if (gameState.frenzyTimer <= 0) {
gameState.frenzyMode = false;
}
}
if (gameState.doubleScoreTimer > 0) {
gameState.doubleScoreTimer--;
if (gameState.doubleScoreTimer <= 0) {
gameState.doubleScoreMode = false;
}
}
// Increase difficulty over time
if (LK.ticks % 1800 === 0) {
// Every 30 seconds
gameState.difficulty += 0.5;
gameState.spawnRate = Math.max(30, gameState.spawnRate - 5);
}
};
// Start with instructions
var swipeToSliceAsset = LK.getAsset('swipe-to-slice', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
y: 2732 / 2 // Moved further downwards
});
game.addChild(swipeToSliceAsset);
apple fruit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
banana. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
watermelon images. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
orange. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
strawberry fruit. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
sliced watermelon fruit into two left side one and rightside one. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
orange fruit double cut. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
apple fruit is cut into two halves with a slight separation to match the style of Fruit Ninja. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
firing Bomb Asset firing on top of the bomb thread: Approximately 512x512 pixels. Consistent with fruit sizes to maintain visual coherence.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
game icon for a video game called fruit slash, show an fruits cutting with sword symbols in the fore ground show the name of the game "Swipe to Slice "big in the center with the fruits underneath. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
lemon fruit cartoon style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
fruit pine apple. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
any three combo fruits some distance from each one. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows