User prompt
Meyvelerin kesilme animasyonları olsun.
User prompt
Meyve kesince puan artmıyor.
User prompt
Meyveler her 2 saniyede bir çıksın
User prompt
Meyveler her 3 saniyede bir çıksın. Bombalar ise her 5 saniyede bir çıksın.
User prompt
Meyvelerin boyutları baya büyüt.
User prompt
Meyveler daha fazla fırlasın ama ekranın sağ ve solundan geçemesinler
User prompt
Meyveler geri düşünce x artmasın sadece bombaya dokunduğumuzda x artsın.
User prompt
Meyve çıkma olasılığını düşür.
User prompt
Meyveler çok azıcık daha fırlasın
User prompt
Meyveler daha az fırlasın
User prompt
Meyvelerin çıkma süresini azalat. Meyveler teker teker çıksın.
User prompt
Hepsinin asetini assets kısmına ekls
User prompt
Meyveleri baya fırlat
User prompt
Meyveler daha yükseğe çıksın ama daha yavaş olsunlar.
User prompt
Meyveler daha yavaş çıksın
User prompt
Meyveler ekranın sağ ve solu çok hızlı bir şekilde gidiyor bunu düzelt.
Code edit (1 edits merged)
Please save this source code
User prompt
Fruit Ninja Slice
Initial prompt
Fruit Ninja
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // Bomb class var Bomb = Container.expand(function () { var self = Container.call(this); // Bomb asset: black circle with red border var assetId = 'bomb'; var bombGfx = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); // Add a red border by overlaying a slightly larger ellipse var borderId = 'bomb_border'; var borderGfx = self.attachAsset(borderId, { anchorX: 0.5, anchorY: 0.5, alpha: 0.3 }); // Physics self.vx = 0; self.vy = 0; self.gravity = 0.35 + Math.random() * 0.1; self.sliced = false; self.slice = function () { if (self.sliced) return; self.sliced = true; // Animate: flash and fade out tween(self, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 250, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); }; self.update = function () { if (self.sliced) return; self.x += self.vx; self.y += self.vy; self.vy += self.gravity; // Prevent from leaving left/right screen edges if (self.x < 0 + self.width * 0.5) { self.x = self.width * 0.5; self.vx = -self.vx * 0.55; } if (self.x > 2048 - self.width * 0.5) { self.x = 2048 - self.width * 0.5; self.vx = -self.vx * 0.55; } }; return self; }); // Fruit class var Fruit = Container.expand(function () { var self = Container.call(this); // Fruit types: apple, banana, orange, watermelon, etc. // Each type has a color and shape // We'll use 'ellipse' for round fruits, 'box' for banana // We'll randomize type on creation var types = [{ id: 'apple', color: 0xff2d2d, shape: 'ellipse', width: 320, height: 320, points: 1 }, { id: 'orange', color: 0xffa500, shape: 'ellipse', width: 300, height: 300, points: 1 }, { id: 'banana', color: 0xfff700, shape: 'box', width: 420, height: 160, points: 2 }, { id: 'watermelon', color: 0x2ecc40, shape: 'ellipse', width: 420, height: 420, points: 3 }, { id: 'kiwi', color: 0x8ee53f, shape: 'ellipse', width: 270, height: 270, points: 2 }]; var type = types[Math.floor(Math.random() * types.length)]; // Asset id is unique per type var assetId = 'fruit_' + type.id; // Initialize asset if not already var fruitGfx = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); // Physics self.vx = 0; self.vy = 0; self.gravity = 0.35 + Math.random() * 0.1; self.sliced = false; self.points = type.points; // For arc motion, we set vx, vy on spawn // Slicing animation self.slice = function () { if (self.sliced) return; self.sliced = true; // Animate: scale up and fade out tween(self, { scaleX: 1.4, scaleY: 1.4, alpha: 0 }, { duration: 350, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); }; // Update per frame self.update = function () { if (self.sliced) return; self.x += self.vx; self.y += self.vy; self.vy += self.gravity; // Prevent from leaving left/right screen edges if (self.x < 0 + self.width * 0.5) { self.x = self.width * 0.5; self.vx = -self.vx * 0.55; // bounce back with some energy loss } if (self.x > 2048 - self.width * 0.5) { self.x = 2048 - self.width * 0.5; self.vx = -self.vx * 0.55; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ // Game variables var fruits = []; var bombs = []; var fruitSpawnTimer = 0; var bombSpawnTimer = 0; var fruitSpawnInterval = 120; // 2 seconds at 60fps var bombSpawnInterval = 300; // 5 seconds at 60fps var score = 0; var highScore = storage.highScore || 0; var missed = 0; var maxMissed = 3; var isGameOver = false; // Score display var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // High score display (smaller, top right) var highScoreTxt = new Text2('Best: ' + highScore, { size: 60, fill: "#fff" }); highScoreTxt.anchor.set(1, 0); LK.gui.topRight.addChild(highScoreTxt); // Missed fruits display (bottom left, as X icons) var missTxt = new Text2('', { size: 90, fill: 0xFF4444 }); missTxt.anchor.set(0, 1); LK.gui.bottomLeft.addChild(missTxt); // Helper: update score function updateScore(val) { score = val; scoreTxt.setText(score); if (score > highScore) { highScore = score; storage.highScore = highScore; highScoreTxt.setText('Best: ' + highScore); } } // Helper: update missed display function updateMissed() { var s = ''; for (var i = 0; i < missed; i++) s += '✗ '; missTxt.setText(s); } // (spawning is now handled by fruit/bomb timers in game.update) // Slicing logic var swipePath = []; var swipeMaxLength = 12; // Number of points to keep in swipe trail var swipeRadius = 90; // How close swipe must be to slice // Draw swipe trail (for visual feedback) var swipeTrail = []; function drawSwipeTrail() { // Remove old for (var i = 0; i < swipeTrail.length; i++) { swipeTrail[i].destroy(); } swipeTrail = []; // Draw new for (var i = 1; i < swipePath.length; i++) { var p1 = swipePath[i - 1]; var p2 = swipePath[i]; // Draw a short white ellipse between points var dx = p2.x - p1.x, dy = p2.y - p1.y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < 10) continue; var angle = Math.atan2(dy, dx); var id = 'swipe_' + i; var seg = LK.getAsset(id, { anchorX: 0, anchorY: 0.5, x: p1.x, y: p1.y, rotation: angle, alpha: 0.22 }); game.addChild(seg); swipeTrail.push(seg); } } // Handle swipe start game.down = function (x, y, obj) { if (isGameOver) return; swipePath = [{ x: x, y: y }]; drawSwipeTrail(); }; // Handle swipe move game.move = function (x, y, obj) { if (isGameOver) return; swipePath.push({ x: x, y: y }); if (swipePath.length > swipeMaxLength) swipePath.shift(); drawSwipeTrail(); // For each segment in swipe, check for intersection with fruits/bombs for (var i = 1; i < swipePath.length; i++) { var p1 = swipePath[i - 1], p2 = swipePath[i]; // Fruits for (var f = fruits.length - 1; f >= 0; f--) { var fruit = fruits[f]; if (fruit.sliced) continue; // If fruit already off screen, skip if (fruit.y > 2732 + 120) continue; // Check if swipe segment is close to fruit center var cx = fruit.x, cy = fruit.y; var dist = pointToSegmentDistance(cx, cy, p1.x, p1.y, p2.x, p2.y); if (dist < swipeRadius) { fruit.slice(); updateScore(score + fruit.points); // Increase score by fruit's point value fruits.splice(f, 1); // Flash effect LK.effects.flashObject(fruit, 0xffffff, 120); } } // Bombs for (var b = bombs.length - 1; b >= 0; b--) { var bomb = bombs[b]; if (bomb.sliced) continue; if (bomb.y > 2732 + 120) continue; var cx = bomb.x, cy = bomb.y; var dist = pointToSegmentDistance(cx, cy, p1.x, p1.y, p2.x, p2.y); if (dist < swipeRadius) { bomb.slice(); bombs.splice(b, 1); // Increase score by 1 when bomb is sliced updateScore(score + 1); // Flash screen red, then game over LK.effects.flashScreen(0xff2222, 800); isGameOver = true; LK.setTimeout(function () { LK.showGameOver(); }, 600); return; } } } }; // Handle swipe end game.up = function (x, y, obj) { swipePath = []; drawSwipeTrail(); }; // Helper: distance from point to segment function pointToSegmentDistance(px, py, x1, y1, x2, y2) { var dx = x2 - x1, dy = y2 - y1; if (dx === 0 && dy === 0) { dx = px - x1; dy = py - y1; return Math.sqrt(dx * dx + dy * dy); } var t = ((px - x1) * dx + (py - y1) * dy) / (dx * dx + dy * dy); t = Math.max(0, Math.min(1, t)); var lx = x1 + t * dx, ly = y1 + t * dy; dx = px - lx; dy = py - ly; return Math.sqrt(dx * dx + dy * dy); } // Main game update game.update = function () { if (isGameOver) return; // Spawn logic fruitSpawnTimer++; bombSpawnTimer++; if (fruitSpawnTimer >= fruitSpawnInterval) { // Spawn a fruit only var obj = new Fruit(); var x = 200 + Math.random() * (2048 - 400); var y = 2732 + 60; var angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI / 2; var speed = 17 + Math.random() * 5.5 + score * 0.055; var vx = Math.cos(angle) * speed * (Math.random() * 0.19 + 0.19); var vy = -Math.abs(Math.sin(angle) * speed) * 1.32; obj.x = x; obj.y = y; obj.vx = vx; obj.vy = vy; obj.scaleX = obj.scaleY = 1; obj.alpha = 1; fruits.push(obj); game.addChild(obj); fruitSpawnTimer = 0; } if (bombSpawnTimer >= bombSpawnInterval) { // Spawn a bomb only var obj = new Bomb(); var x = 200 + Math.random() * (2048 - 400); var y = 2732 + 60; var angle = -Math.PI / 2 + (Math.random() - 0.5) * Math.PI / 2; var speed = 17 + Math.random() * 5.5 + score * 0.055; var vx = Math.cos(angle) * speed * (Math.random() * 0.19 + 0.19); var vy = -Math.abs(Math.sin(angle) * speed) * 1.32; obj.x = x; obj.y = y; obj.vx = vx; obj.vy = vy; obj.scaleX = obj.scaleY = 1; obj.alpha = 1; bombs.push(obj); game.addChild(obj); bombSpawnTimer = 0; } // Update fruits for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; fruit.update(); // Remove if off screen if (!fruit.sliced && fruit.y > 2732 + 120) { fruit.destroy(); fruits.splice(i, 1); missed++; updateMissed(); // Flash screen if missed LK.effects.flashScreen(0x2222ff, 200); if (missed >= maxMissed) { isGameOver = true; LK.setTimeout(function () { LK.showGameOver(); }, 500); } // Do NOT increase score here; only bomb slice increases score now } } // Update bombs for (var i = bombs.length - 1; i >= 0; i--) { var bomb = bombs[i]; bomb.update(); if (bomb.y > 2732 + 120) { bomb.destroy(); bombs.splice(i, 1); } } // Fade out swipe trail for (var i = 0; i < swipeTrail.length; i++) { swipeTrail[i].alpha *= 0.85; if (swipeTrail[i].alpha < 0.05) { swipeTrail[i].destroy(); swipeTrail.splice(i, 1); i--; } } }; // Reset game state on new game game.on('reset', function () { // Remove all fruits and bombs for (var i = 0; i < fruits.length; i++) fruits[i].destroy(); for (var i = 0; i < bombs.length; i++) bombs[i].destroy(); fruits = []; bombs = []; fruitSpawnTimer = 0; bombSpawnTimer = 0; score = 0; missed = 0; isGameOver = false; updateScore(0); updateMissed(); swipePath = []; drawSwipeTrail(); highScore = storage.highScore || 0; highScoreTxt.setText('Best: ' + highScore); }); // Initial state updateScore(0); updateMissed(); // Fruit assets // Bomb asset: black circle // Bomb border: red, slightly larger, semi-transparent
===================================================================
--- original.js
+++ change.js
@@ -283,9 +283,9 @@
cy = fruit.y;
var dist = pointToSegmentDistance(cx, cy, p1.x, p1.y, p2.x, p2.y);
if (dist < swipeRadius) {
fruit.slice();
- // Do NOT increase score for fruit slice
+ updateScore(score + fruit.points); // Increase score by fruit's point value
fruits.splice(f, 1);
// Flash effect
LK.effects.flashObject(fruit, 0xffffff, 120);
}