/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Banana = Container.expand(function () { var self = Container.call(this); var bananaGraphics = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.sliced = false; self.update = function () { if (!self.sliced) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Boundary collision - bounce off left and right edges if (self.x <= 120 && self.velocityX < 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 120; // Keep within bounds } if (self.x >= 1928 && self.velocityX > 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 1928; // Keep within bounds } // Rotate banana as it moves bananaGraphics.rotation += 0.03; } }; return self; }); var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.sliced = false; self.update = function () { if (!self.sliced) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Boundary collision - bounce off left and right edges if (self.x <= 120 && self.velocityX < 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 120; // Keep within bounds } if (self.x >= 1928 && self.velocityX > 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 1928; // Keep within bounds } } }; return self; }); var Fruit = Container.expand(function () { var self = Container.call(this); var fruitGraphics = self.attachAsset('fruit', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.sliced = false; self.update = function () { if (!self.sliced) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Boundary collision - bounce off left and right edges if (self.x <= 120 && self.velocityX < 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 120; // Keep within bounds } if (self.x >= 1928 && self.velocityX > 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 1928; // Keep within bounds } // Rotate fruit as it moves fruitGraphics.rotation += 0.05; } }; return self; }); var KnifeTrail = Container.expand(function () { var self = Container.call(this); var trailGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.life = 60; self.maxLife = 60; // Knife trail appearance - much larger and more prominent self.scaleX = 8.0; self.scaleY = 1.5; trailGraphics.tint = 0xffffff; // Bright white for maximum visibility // Animate knife trail - starts bright and fades slowly with glow tween(self, { scaleX: 0.5, scaleY: 0.1, alpha: 0 }, { duration: 600, easing: tween.easeOut }); // Add secondary glow effect tween(trailGraphics, { tint: 0x00ffff }, { duration: 300, easing: tween.easeInOut }); self.update = function () { self.life--; if (self.life <= 0) { self.destroy(); } }; return self; }); var MainMenu = Container.expand(function () { var self = Container.call(this); // Create menu background with image var menuBg = self.attachAsset('menu_bg', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Add white transparent background for how to play section var howToPlayBg = self.attachAsset('how_to_play_bg', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 750, alpha: 0.8 }); // Add how to play title var howToPlayTitle = new Text2('NASIL OYNANIR', { size: 100, fill: 0xFFFFFF, font: "'Arial Black','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 8 }); howToPlayTitle.anchor.set(0.5, 0.5); howToPlayTitle.x = 1024; howToPlayTitle.y = 500; self.addChild(howToPlayTitle); // Add instruction text 1 var instruction1 = new Text2('🍎 Meyveleri kesmek için parmağınızı sürükleyin', { size: 60, fill: 0xFFFFFF, font: "'Arial','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 4 }); instruction1.anchor.set(0.5, 0.5); instruction1.x = 1024; instruction1.y = 650; self.addChild(instruction1); // Add instruction text 2 var instruction2 = new Text2('🍌 Farklı meyveler farklı puanlar verir', { size: 60, fill: 0xFFFFFF, font: "'Arial','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 4 }); instruction2.anchor.set(0.5, 0.5); instruction2.x = 1024; instruction2.y = 750; self.addChild(instruction2); // Add instruction text 3 var instruction3 = new Text2('🍓 Kombolar daha fazla puan kazandırır', { size: 60, fill: 0xFFFFFF, font: "'Arial','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 4 }); instruction3.anchor.set(0.5, 0.5); instruction3.x = 1024; instruction3.y = 850; self.addChild(instruction3); // Add warning text var warningText = new Text2('💣 DİKKAT: Bombalara dokunmayın!', { size: 70, fill: 0xFF3333, font: "'Arial Black','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 6 }); warningText.anchor.set(0.5, 0.5); warningText.x = 1024; warningText.y = 980; self.addChild(warningText); // Add play button background image var playButtonBg = self.attachAsset('play_button', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1300 }); var playText = new Text2('OYNA', { size: 120, fill: 0x000000, font: "'Arial Black','GillSans-Bold',Impact,Tahoma", stroke: 0x000000, strokeThickness: 12 }); playText.anchor.set(0.5, 0.5); playText.x = 1024; playText.y = 1300; self.addChild(playText); // Play button interaction playText.down = function (x, y, obj) { LK.getSound('touch_sound').play(); startGame(); }; return self; }); var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = (Math.random() - 0.5) * 24; self.velocityY = (Math.random() - 0.5) * 24; self.life = 180; self.maxLife = 180; // Start with random scale and animate self.scaleX = 0.4 + Math.random() * 1.5; self.scaleY = 0.4 + Math.random() * 1.5; // Animate scale down over time with rotation tween(self, { scaleX: 0.03, scaleY: 0.03, rotation: Math.PI * 4 }, { duration: 4000, easing: tween.easeOut }); self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.life--; self.alpha = self.life / self.maxLife; self.velocityY += 0.4; // Add slight scale pulsing effect var pulseFactor = 0.8 + 0.4 * Math.sin(LK.ticks * 0.1); particleGraphics.scaleX = self.scaleX * pulseFactor; particleGraphics.scaleY = self.scaleY * pulseFactor; if (self.life <= 0) { self.destroy(); } }; return self; }); var Strawberry = Container.expand(function () { var self = Container.call(this); var strawberryGraphics = self.attachAsset('strawberry', { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = 0; self.velocityY = 0; self.gravity = 0.3; self.sliced = false; self.update = function () { if (!self.sliced) { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Boundary collision - bounce off left and right edges if (self.x <= 120 && self.velocityX < 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 120; // Keep within bounds } if (self.x >= 1928 && self.velocityX > 0) { self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity self.x = 1928; // Keep within bounds } // Rotate strawberry as it moves strawberryGraphics.rotation += 0.04; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game state variables var gameState = 'menu'; // 'menu' or 'playing' var mainMenu = null; var gameBackground = null; // Game arrays and variables var fruits = []; var bananas = []; var strawberries = []; var bombs = []; var particles = []; var knifeTrails = []; var sliceTrail = []; var isSlicing = false; var lastSliceX = 0; var lastSliceY = 0; var comboCount = 0; var spawnRate = 120; var gameSpeed = 1; // Initialize main menu function initMainMenu() { mainMenu = new MainMenu(); game.addChild(mainMenu); // Start playing background music LK.playMusic('menu_music'); } // Start the actual game function startGame() { gameState = 'playing'; // Stop menu music LK.stopMusic(); // Remove main menu if (mainMenu) { mainMenu.destroy(); mainMenu = null; } // Add game background gameBackground = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0, width: 2048, height: 2732 }); // Reset game variables LK.setScore(0); gameSpeed = 1; spawnRate = 120; comboCount = 0; } // Initialize main menu at start initMainMenu(); // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Combo display var comboTxt = new Text2('', { size: 60, fill: 0xFFFF00 }); comboTxt.anchor.set(0.5, 0); comboTxt.y = 100; LK.gui.top.addChild(comboTxt); function spawnFruit() { // Spawn multiple fruits (2-4 fruits at once) var fruitCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 fruits for (var j = 0; j < fruitCount; j++) { var fruit = new Fruit(); fruit.x = Math.random() * 1600 + 224; fruit.y = 2732 + 100; // Random trajectory upward with higher velocity fruit.velocityX = (Math.random() - 0.5) * 8; fruit.velocityY = -22 - Math.random() * 16; // Start small and scale up with tween animation fruit.scaleX = 0.3; fruit.scaleY = 0.3; tween(fruit, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, easing: tween.easeOut }); fruits.push(fruit); game.addChild(fruit); } } function spawnBanana() { // Spawn multiple bananas (2-4 bananas at once) var bananaCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 bananas for (var j = 0; j < bananaCount; j++) { var banana = new Banana(); banana.x = Math.random() * 1600 + 224; banana.y = 2732 + 100; banana.velocityX = (Math.random() - 0.5) * 7; banana.velocityY = -21 - Math.random() * 15; // Start small and scale up with tween animation banana.scaleX = 0.3; banana.scaleY = 0.3; tween(banana, { scaleX: 1.1, scaleY: 1.1 }, { duration: 350, easing: tween.easeOut }); bananas.push(banana); game.addChild(banana); } } function spawnStrawberry() { // Spawn multiple strawberries (2-4 strawberries at once) var strawberryCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 strawberries for (var j = 0; j < strawberryCount; j++) { var strawberry = new Strawberry(); strawberry.x = Math.random() * 1600 + 224; strawberry.y = 2732 + 100; strawberry.velocityX = (Math.random() - 0.5) * 6; strawberry.velocityY = -20 - Math.random() * 14; // Start small and scale up with tween animation strawberry.scaleX = 0.3; strawberry.scaleY = 0.3; tween(strawberry, { scaleX: 1.0, scaleY: 1.0 }, { duration: 320, easing: tween.easeOut }); strawberries.push(strawberry); game.addChild(strawberry); } } function spawnBomb() { var bomb = new Bomb(); bomb.x = Math.random() * 1600 + 224; bomb.y = 2732 + 100; bomb.velocityX = (Math.random() - 0.5) * 6; bomb.velocityY = -24 - Math.random() * 16; // Start small and scale up with tween animation bomb.scaleX = 0.3; bomb.scaleY = 0.3; tween(bomb, { scaleX: 1, scaleY: 1 }, { duration: 400, easing: tween.bounceOut }); bombs.push(bomb); game.addChild(bomb); } function createParticles(x, y, color) { for (var i = 0; i < 40; i++) { var particle = new Particle(); particle.x = x + (Math.random() - 0.5) * 120; particle.y = y + (Math.random() - 0.5) * 120; var particleGraphics = particle.children[0]; // Create color variations with more vibrant colors var colors = [color, 0xffffff, 0xffff00, 0xff6600, 0xff0066]; var selectedColor = colors[Math.floor(Math.random() * colors.length)]; particleGraphics.tint = selectedColor; particleGraphics.alpha = 0.9 + Math.random() * 0.1; // Add color transition animation tween(particleGraphics, { tint: 0x000000, alpha: 0 }, { duration: 3600, easing: tween.easeInOut }); particles.push(particle); game.addChild(particle); } } function checkSliceCollision(x1, y1, x2, y2, target) { var dx = target.x - x1; var dy = target.y - y1; var lineX = x2 - x1; var lineY = y2 - y1; var lineLength = Math.sqrt(lineX * lineX + lineY * lineY); if (lineLength === 0) return false; var dot = (dx * lineX + dy * lineY) / (lineLength * lineLength); dot = Math.max(0, Math.min(1, dot)); var closestX = x1 + dot * lineX; var closestY = y1 + dot * lineY; var distance = Math.sqrt((target.x - closestX) * (target.x - closestX) + (target.y - closestY) * (target.y - closestY)); return distance < 120; // Hit radius } game.down = function (x, y, obj) { if (gameState !== 'playing') return; isSlicing = true; lastSliceX = x; lastSliceY = y; sliceTrail = [{ x: x, y: y }]; comboCount = 0; // Play touch sound when user starts slicing LK.getSound('touch_sound').play(); }; game.move = function (x, y, obj) { if (gameState !== 'playing') return; if (isSlicing) { // Create knife trails more frequently for denser effect var distance = Math.sqrt((x - lastSliceX) * (x - lastSliceX) + (y - lastSliceY) * (y - lastSliceY)); if (distance > 8) { var knifeTrail = new KnifeTrail(); knifeTrail.x = x; knifeTrail.y = y; // Rotate knife trail to match movement direction var angle = Math.atan2(y - lastSliceY, x - lastSliceX); knifeTrail.rotation = angle; knifeTrails.push(knifeTrail); game.addChild(knifeTrail); } // Add to slice trail sliceTrail.push({ x: x, y: y }); if (sliceTrail.length > 10) { sliceTrail.shift(); } // Check slice collision with fruits for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; if (!fruit.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, fruit)) { fruit.sliced = true; comboCount++; var baseScore = 10; var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0; LK.setScore(LK.getScore() + baseScore + comboBonus); // Create particles var fruitColor = fruit.children[0].tint; createParticles(fruit.x, fruit.y, fruitColor); // Play fruit cutting sound LK.getSound('fruit_cut_sound').play(); // Play particle animation sound LK.getSound('particle_sound').play(); // Remove fruit fruit.destroy(); fruits.splice(i, 1); } } // Check slice collision with bananas for (var i = bananas.length - 1; i >= 0; i--) { var banana = bananas[i]; if (!banana.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, banana)) { banana.sliced = true; comboCount++; var baseScore = 15; // Bananas worth more points var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0; LK.setScore(LK.getScore() + baseScore + comboBonus); // Create particles with yellow tint for bananas createParticles(banana.x, banana.y, 0xffff00); // Play fruit cutting sound LK.getSound('fruit_cut_sound').play(); // Play particle animation sound LK.getSound('particle_sound').play(); // Remove banana banana.destroy(); bananas.splice(i, 1); } } // Check slice collision with strawberries for (var i = strawberries.length - 1; i >= 0; i--) { var strawberry = strawberries[i]; if (!strawberry.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, strawberry)) { strawberry.sliced = true; comboCount++; var baseScore = 12; // Strawberries worth medium points var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0; LK.setScore(LK.getScore() + baseScore + comboBonus); // Create particles with red tint for strawberries createParticles(strawberry.x, strawberry.y, 0xff3366); // Play fruit cutting sound LK.getSound('fruit_cut_sound').play(); // Play particle animation sound LK.getSound('particle_sound').play(); // Remove strawberry strawberry.destroy(); strawberries.splice(i, 1); } } // Check slice collision with bombs for (var i = bombs.length - 1; i >= 0; i--) { var bomb = bombs[i]; if (!bomb.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, bomb)) { bomb.sliced = true; // Game over LK.getSound('bomb_sound').play(); LK.effects.flashScreen(0xff0000, 1000); LK.showGameOver(); return; } } lastSliceX = x; lastSliceY = y; } }; game.up = function (x, y, obj) { if (gameState !== 'playing') return; isSlicing = false; sliceTrail = []; if (comboCount > 1) { comboTxt.setText('COMBO x' + comboCount + '!'); tween(comboTxt, { alpha: 0 }, { duration: 2000, onFinish: function onFinish() { comboTxt.setText(''); comboTxt.alpha = 1; } }); } comboCount = 0; }; game.update = function () { if (gameState !== 'playing') return; // Update score display scoreTxt.setText('Score: ' + LK.getScore()); // Increase difficulty over time if (LK.ticks % 600 === 0) { gameSpeed += 0.1; spawnRate = Math.max(60, spawnRate - 5); } // Check if all fruits and bombs have fallen (are off-screen at bottom) var allFallen = true; for (var i = 0; i < fruits.length; i++) { if (fruits[i].y < 2732 + 200) { allFallen = false; break; } } if (allFallen) { for (var i = 0; i < bananas.length; i++) { if (bananas[i].y < 2732 + 200) { allFallen = false; break; } } } if (allFallen) { for (var i = 0; i < strawberries.length; i++) { if (strawberries[i].y < 2732 + 200) { allFallen = false; break; } } } if (allFallen) { for (var i = 0; i < bombs.length; i++) { if (bombs[i].y < 2732 + 200) { allFallen = false; break; } } } // Only spawn new fruits if all previous ones have fallen if (allFallen && LK.ticks % Math.floor(spawnRate / gameSpeed) === 0) { var randomValue = Math.random(); if (randomValue < 0.33) { spawnBanana(); // 33% chance to spawn banana } else if (randomValue < 0.66) { spawnStrawberry(); // 33% chance to spawn strawberry } else { spawnFruit(); // 33% chance to spawn fruit } } // Only spawn new bombs if all fruits and bombs have fallen if (allFallen && LK.ticks % Math.floor(300 / gameSpeed) === 0 && Math.random() < 0.3) { spawnBomb(); } // Clean up off-screen fruits for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; if (fruit.y > 2732 + 200 || fruit.x < -200 || fruit.x > 2248) { fruit.destroy(); fruits.splice(i, 1); } } // Clean up off-screen bananas for (var i = bananas.length - 1; i >= 0; i--) { var banana = bananas[i]; if (banana.y > 2732 + 200 || banana.x < -200 || banana.x > 2248) { banana.destroy(); bananas.splice(i, 1); } } // Clean up off-screen strawberries for (var i = strawberries.length - 1; i >= 0; i--) { var strawberry = strawberries[i]; if (strawberry.y > 2732 + 200 || strawberry.x < -200 || strawberry.x > 2248) { strawberry.destroy(); strawberries.splice(i, 1); } } // Clean up off-screen bombs for (var i = bombs.length - 1; i >= 0; i--) { var bomb = bombs[i]; if (bomb.y > 2732 + 200 || bomb.x < -200 || bomb.x > 2248) { bomb.destroy(); bombs.splice(i, 1); } } // Clean up dead particles for (var i = particles.length - 1; i >= 0; i--) { var particle = particles[i]; if (particle.life <= 0) { particles.splice(i, 1); } } // Clean up dead knife trails for (var i = knifeTrails.length - 1; i >= 0; i--) { var knifeTrail = knifeTrails[i]; if (knifeTrail.life <= 0) { knifeTrails.splice(i, 1); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Banana = Container.expand(function () {
var self = Container.call(this);
var bananaGraphics = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.3;
self.sliced = false;
self.update = function () {
if (!self.sliced) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Boundary collision - bounce off left and right edges
if (self.x <= 120 && self.velocityX < 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 120; // Keep within bounds
}
if (self.x >= 1928 && self.velocityX > 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 1928; // Keep within bounds
}
// Rotate banana as it moves
bananaGraphics.rotation += 0.03;
}
};
return self;
});
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.3;
self.sliced = false;
self.update = function () {
if (!self.sliced) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Boundary collision - bounce off left and right edges
if (self.x <= 120 && self.velocityX < 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 120; // Keep within bounds
}
if (self.x >= 1928 && self.velocityX > 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 1928; // Keep within bounds
}
}
};
return self;
});
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.3;
self.sliced = false;
self.update = function () {
if (!self.sliced) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Boundary collision - bounce off left and right edges
if (self.x <= 120 && self.velocityX < 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 120; // Keep within bounds
}
if (self.x >= 1928 && self.velocityX > 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 1928; // Keep within bounds
}
// Rotate fruit as it moves
fruitGraphics.rotation += 0.05;
}
};
return self;
});
var KnifeTrail = Container.expand(function () {
var self = Container.call(this);
var trailGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.life = 60;
self.maxLife = 60;
// Knife trail appearance - much larger and more prominent
self.scaleX = 8.0;
self.scaleY = 1.5;
trailGraphics.tint = 0xffffff; // Bright white for maximum visibility
// Animate knife trail - starts bright and fades slowly with glow
tween(self, {
scaleX: 0.5,
scaleY: 0.1,
alpha: 0
}, {
duration: 600,
easing: tween.easeOut
});
// Add secondary glow effect
tween(trailGraphics, {
tint: 0x00ffff
}, {
duration: 300,
easing: tween.easeInOut
});
self.update = function () {
self.life--;
if (self.life <= 0) {
self.destroy();
}
};
return self;
});
var MainMenu = Container.expand(function () {
var self = Container.call(this);
// Create menu background with image
var menuBg = self.attachAsset('menu_bg', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Add white transparent background for how to play section
var howToPlayBg = self.attachAsset('how_to_play_bg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 750,
alpha: 0.8
});
// Add how to play title
var howToPlayTitle = new Text2('NASIL OYNANIR', {
size: 100,
fill: 0xFFFFFF,
font: "'Arial Black','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 8
});
howToPlayTitle.anchor.set(0.5, 0.5);
howToPlayTitle.x = 1024;
howToPlayTitle.y = 500;
self.addChild(howToPlayTitle);
// Add instruction text 1
var instruction1 = new Text2('🍎 Meyveleri kesmek için parmağınızı sürükleyin', {
size: 60,
fill: 0xFFFFFF,
font: "'Arial','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 4
});
instruction1.anchor.set(0.5, 0.5);
instruction1.x = 1024;
instruction1.y = 650;
self.addChild(instruction1);
// Add instruction text 2
var instruction2 = new Text2('🍌 Farklı meyveler farklı puanlar verir', {
size: 60,
fill: 0xFFFFFF,
font: "'Arial','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 4
});
instruction2.anchor.set(0.5, 0.5);
instruction2.x = 1024;
instruction2.y = 750;
self.addChild(instruction2);
// Add instruction text 3
var instruction3 = new Text2('🍓 Kombolar daha fazla puan kazandırır', {
size: 60,
fill: 0xFFFFFF,
font: "'Arial','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 4
});
instruction3.anchor.set(0.5, 0.5);
instruction3.x = 1024;
instruction3.y = 850;
self.addChild(instruction3);
// Add warning text
var warningText = new Text2('💣 DİKKAT: Bombalara dokunmayın!', {
size: 70,
fill: 0xFF3333,
font: "'Arial Black','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 6
});
warningText.anchor.set(0.5, 0.5);
warningText.x = 1024;
warningText.y = 980;
self.addChild(warningText);
// Add play button background image
var playButtonBg = self.attachAsset('play_button', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1300
});
var playText = new Text2('OYNA', {
size: 120,
fill: 0x000000,
font: "'Arial Black','GillSans-Bold',Impact,Tahoma",
stroke: 0x000000,
strokeThickness: 12
});
playText.anchor.set(0.5, 0.5);
playText.x = 1024;
playText.y = 1300;
self.addChild(playText);
// Play button interaction
playText.down = function (x, y, obj) {
LK.getSound('touch_sound').play();
startGame();
};
return self;
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = (Math.random() - 0.5) * 24;
self.velocityY = (Math.random() - 0.5) * 24;
self.life = 180;
self.maxLife = 180;
// Start with random scale and animate
self.scaleX = 0.4 + Math.random() * 1.5;
self.scaleY = 0.4 + Math.random() * 1.5;
// Animate scale down over time with rotation
tween(self, {
scaleX: 0.03,
scaleY: 0.03,
rotation: Math.PI * 4
}, {
duration: 4000,
easing: tween.easeOut
});
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.life--;
self.alpha = self.life / self.maxLife;
self.velocityY += 0.4;
// Add slight scale pulsing effect
var pulseFactor = 0.8 + 0.4 * Math.sin(LK.ticks * 0.1);
particleGraphics.scaleX = self.scaleX * pulseFactor;
particleGraphics.scaleY = self.scaleY * pulseFactor;
if (self.life <= 0) {
self.destroy();
}
};
return self;
});
var Strawberry = Container.expand(function () {
var self = Container.call(this);
var strawberryGraphics = self.attachAsset('strawberry', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocityX = 0;
self.velocityY = 0;
self.gravity = 0.3;
self.sliced = false;
self.update = function () {
if (!self.sliced) {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
// Boundary collision - bounce off left and right edges
if (self.x <= 120 && self.velocityX < 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 120; // Keep within bounds
}
if (self.x >= 1928 && self.velocityX > 0) {
self.velocityX = -self.velocityX * 0.8; // Reverse and dampen velocity
self.x = 1928; // Keep within bounds
}
// Rotate strawberry as it moves
strawberryGraphics.rotation += 0.04;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game state variables
var gameState = 'menu'; // 'menu' or 'playing'
var mainMenu = null;
var gameBackground = null;
// Game arrays and variables
var fruits = [];
var bananas = [];
var strawberries = [];
var bombs = [];
var particles = [];
var knifeTrails = [];
var sliceTrail = [];
var isSlicing = false;
var lastSliceX = 0;
var lastSliceY = 0;
var comboCount = 0;
var spawnRate = 120;
var gameSpeed = 1;
// Initialize main menu
function initMainMenu() {
mainMenu = new MainMenu();
game.addChild(mainMenu);
// Start playing background music
LK.playMusic('menu_music');
}
// Start the actual game
function startGame() {
gameState = 'playing';
// Stop menu music
LK.stopMusic();
// Remove main menu
if (mainMenu) {
mainMenu.destroy();
mainMenu = null;
}
// Add game background
gameBackground = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0,
width: 2048,
height: 2732
});
// Reset game variables
LK.setScore(0);
gameSpeed = 1;
spawnRate = 120;
comboCount = 0;
}
// Initialize main menu at start
initMainMenu();
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Combo display
var comboTxt = new Text2('', {
size: 60,
fill: 0xFFFF00
});
comboTxt.anchor.set(0.5, 0);
comboTxt.y = 100;
LK.gui.top.addChild(comboTxt);
function spawnFruit() {
// Spawn multiple fruits (2-4 fruits at once)
var fruitCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 fruits
for (var j = 0; j < fruitCount; j++) {
var fruit = new Fruit();
fruit.x = Math.random() * 1600 + 224;
fruit.y = 2732 + 100;
// Random trajectory upward with higher velocity
fruit.velocityX = (Math.random() - 0.5) * 8;
fruit.velocityY = -22 - Math.random() * 16;
// Start small and scale up with tween animation
fruit.scaleX = 0.3;
fruit.scaleY = 0.3;
tween(fruit, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
fruits.push(fruit);
game.addChild(fruit);
}
}
function spawnBanana() {
// Spawn multiple bananas (2-4 bananas at once)
var bananaCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 bananas
for (var j = 0; j < bananaCount; j++) {
var banana = new Banana();
banana.x = Math.random() * 1600 + 224;
banana.y = 2732 + 100;
banana.velocityX = (Math.random() - 0.5) * 7;
banana.velocityY = -21 - Math.random() * 15;
// Start small and scale up with tween animation
banana.scaleX = 0.3;
banana.scaleY = 0.3;
tween(banana, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 350,
easing: tween.easeOut
});
bananas.push(banana);
game.addChild(banana);
}
}
function spawnStrawberry() {
// Spawn multiple strawberries (2-4 strawberries at once)
var strawberryCount = 2 + Math.floor(Math.random() * 3); // Random between 2-4 strawberries
for (var j = 0; j < strawberryCount; j++) {
var strawberry = new Strawberry();
strawberry.x = Math.random() * 1600 + 224;
strawberry.y = 2732 + 100;
strawberry.velocityX = (Math.random() - 0.5) * 6;
strawberry.velocityY = -20 - Math.random() * 14;
// Start small and scale up with tween animation
strawberry.scaleX = 0.3;
strawberry.scaleY = 0.3;
tween(strawberry, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 320,
easing: tween.easeOut
});
strawberries.push(strawberry);
game.addChild(strawberry);
}
}
function spawnBomb() {
var bomb = new Bomb();
bomb.x = Math.random() * 1600 + 224;
bomb.y = 2732 + 100;
bomb.velocityX = (Math.random() - 0.5) * 6;
bomb.velocityY = -24 - Math.random() * 16;
// Start small and scale up with tween animation
bomb.scaleX = 0.3;
bomb.scaleY = 0.3;
tween(bomb, {
scaleX: 1,
scaleY: 1
}, {
duration: 400,
easing: tween.bounceOut
});
bombs.push(bomb);
game.addChild(bomb);
}
function createParticles(x, y, color) {
for (var i = 0; i < 40; i++) {
var particle = new Particle();
particle.x = x + (Math.random() - 0.5) * 120;
particle.y = y + (Math.random() - 0.5) * 120;
var particleGraphics = particle.children[0];
// Create color variations with more vibrant colors
var colors = [color, 0xffffff, 0xffff00, 0xff6600, 0xff0066];
var selectedColor = colors[Math.floor(Math.random() * colors.length)];
particleGraphics.tint = selectedColor;
particleGraphics.alpha = 0.9 + Math.random() * 0.1;
// Add color transition animation
tween(particleGraphics, {
tint: 0x000000,
alpha: 0
}, {
duration: 3600,
easing: tween.easeInOut
});
particles.push(particle);
game.addChild(particle);
}
}
function checkSliceCollision(x1, y1, x2, y2, target) {
var dx = target.x - x1;
var dy = target.y - y1;
var lineX = x2 - x1;
var lineY = y2 - y1;
var lineLength = Math.sqrt(lineX * lineX + lineY * lineY);
if (lineLength === 0) return false;
var dot = (dx * lineX + dy * lineY) / (lineLength * lineLength);
dot = Math.max(0, Math.min(1, dot));
var closestX = x1 + dot * lineX;
var closestY = y1 + dot * lineY;
var distance = Math.sqrt((target.x - closestX) * (target.x - closestX) + (target.y - closestY) * (target.y - closestY));
return distance < 120; // Hit radius
}
game.down = function (x, y, obj) {
if (gameState !== 'playing') return;
isSlicing = true;
lastSliceX = x;
lastSliceY = y;
sliceTrail = [{
x: x,
y: y
}];
comboCount = 0;
// Play touch sound when user starts slicing
LK.getSound('touch_sound').play();
};
game.move = function (x, y, obj) {
if (gameState !== 'playing') return;
if (isSlicing) {
// Create knife trails more frequently for denser effect
var distance = Math.sqrt((x - lastSliceX) * (x - lastSliceX) + (y - lastSliceY) * (y - lastSliceY));
if (distance > 8) {
var knifeTrail = new KnifeTrail();
knifeTrail.x = x;
knifeTrail.y = y;
// Rotate knife trail to match movement direction
var angle = Math.atan2(y - lastSliceY, x - lastSliceX);
knifeTrail.rotation = angle;
knifeTrails.push(knifeTrail);
game.addChild(knifeTrail);
}
// Add to slice trail
sliceTrail.push({
x: x,
y: y
});
if (sliceTrail.length > 10) {
sliceTrail.shift();
}
// Check slice collision with fruits
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
if (!fruit.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, fruit)) {
fruit.sliced = true;
comboCount++;
var baseScore = 10;
var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0;
LK.setScore(LK.getScore() + baseScore + comboBonus);
// Create particles
var fruitColor = fruit.children[0].tint;
createParticles(fruit.x, fruit.y, fruitColor);
// Play fruit cutting sound
LK.getSound('fruit_cut_sound').play();
// Play particle animation sound
LK.getSound('particle_sound').play();
// Remove fruit
fruit.destroy();
fruits.splice(i, 1);
}
}
// Check slice collision with bananas
for (var i = bananas.length - 1; i >= 0; i--) {
var banana = bananas[i];
if (!banana.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, banana)) {
banana.sliced = true;
comboCount++;
var baseScore = 15; // Bananas worth more points
var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0;
LK.setScore(LK.getScore() + baseScore + comboBonus);
// Create particles with yellow tint for bananas
createParticles(banana.x, banana.y, 0xffff00);
// Play fruit cutting sound
LK.getSound('fruit_cut_sound').play();
// Play particle animation sound
LK.getSound('particle_sound').play();
// Remove banana
banana.destroy();
bananas.splice(i, 1);
}
}
// Check slice collision with strawberries
for (var i = strawberries.length - 1; i >= 0; i--) {
var strawberry = strawberries[i];
if (!strawberry.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, strawberry)) {
strawberry.sliced = true;
comboCount++;
var baseScore = 12; // Strawberries worth medium points
var comboBonus = comboCount > 1 ? (comboCount - 1) * 5 : 0;
LK.setScore(LK.getScore() + baseScore + comboBonus);
// Create particles with red tint for strawberries
createParticles(strawberry.x, strawberry.y, 0xff3366);
// Play fruit cutting sound
LK.getSound('fruit_cut_sound').play();
// Play particle animation sound
LK.getSound('particle_sound').play();
// Remove strawberry
strawberry.destroy();
strawberries.splice(i, 1);
}
}
// Check slice collision with bombs
for (var i = bombs.length - 1; i >= 0; i--) {
var bomb = bombs[i];
if (!bomb.sliced && checkSliceCollision(lastSliceX, lastSliceY, x, y, bomb)) {
bomb.sliced = true;
// Game over
LK.getSound('bomb_sound').play();
LK.effects.flashScreen(0xff0000, 1000);
LK.showGameOver();
return;
}
}
lastSliceX = x;
lastSliceY = y;
}
};
game.up = function (x, y, obj) {
if (gameState !== 'playing') return;
isSlicing = false;
sliceTrail = [];
if (comboCount > 1) {
comboTxt.setText('COMBO x' + comboCount + '!');
tween(comboTxt, {
alpha: 0
}, {
duration: 2000,
onFinish: function onFinish() {
comboTxt.setText('');
comboTxt.alpha = 1;
}
});
}
comboCount = 0;
};
game.update = function () {
if (gameState !== 'playing') return;
// Update score display
scoreTxt.setText('Score: ' + LK.getScore());
// Increase difficulty over time
if (LK.ticks % 600 === 0) {
gameSpeed += 0.1;
spawnRate = Math.max(60, spawnRate - 5);
}
// Check if all fruits and bombs have fallen (are off-screen at bottom)
var allFallen = true;
for (var i = 0; i < fruits.length; i++) {
if (fruits[i].y < 2732 + 200) {
allFallen = false;
break;
}
}
if (allFallen) {
for (var i = 0; i < bananas.length; i++) {
if (bananas[i].y < 2732 + 200) {
allFallen = false;
break;
}
}
}
if (allFallen) {
for (var i = 0; i < strawberries.length; i++) {
if (strawberries[i].y < 2732 + 200) {
allFallen = false;
break;
}
}
}
if (allFallen) {
for (var i = 0; i < bombs.length; i++) {
if (bombs[i].y < 2732 + 200) {
allFallen = false;
break;
}
}
}
// Only spawn new fruits if all previous ones have fallen
if (allFallen && LK.ticks % Math.floor(spawnRate / gameSpeed) === 0) {
var randomValue = Math.random();
if (randomValue < 0.33) {
spawnBanana(); // 33% chance to spawn banana
} else if (randomValue < 0.66) {
spawnStrawberry(); // 33% chance to spawn strawberry
} else {
spawnFruit(); // 33% chance to spawn fruit
}
}
// Only spawn new bombs if all fruits and bombs have fallen
if (allFallen && LK.ticks % Math.floor(300 / gameSpeed) === 0 && Math.random() < 0.3) {
spawnBomb();
}
// Clean up off-screen fruits
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
if (fruit.y > 2732 + 200 || fruit.x < -200 || fruit.x > 2248) {
fruit.destroy();
fruits.splice(i, 1);
}
}
// Clean up off-screen bananas
for (var i = bananas.length - 1; i >= 0; i--) {
var banana = bananas[i];
if (banana.y > 2732 + 200 || banana.x < -200 || banana.x > 2248) {
banana.destroy();
bananas.splice(i, 1);
}
}
// Clean up off-screen strawberries
for (var i = strawberries.length - 1; i >= 0; i--) {
var strawberry = strawberries[i];
if (strawberry.y > 2732 + 200 || strawberry.x < -200 || strawberry.x > 2248) {
strawberry.destroy();
strawberries.splice(i, 1);
}
}
// Clean up off-screen bombs
for (var i = bombs.length - 1; i >= 0; i--) {
var bomb = bombs[i];
if (bomb.y > 2732 + 200 || bomb.x < -200 || bomb.x > 2248) {
bomb.destroy();
bombs.splice(i, 1);
}
}
// Clean up dead particles
for (var i = particles.length - 1; i >= 0; i--) {
var particle = particles[i];
if (particle.life <= 0) {
particles.splice(i, 1);
}
}
// Clean up dead knife trails
for (var i = knifeTrails.length - 1; i >= 0; i--) {
var knifeTrail = knifeTrails[i];
if (knifeTrail.life <= 0) {
knifeTrails.splice(i, 1);
}
}
};
Fruit ninja arkaplan. In-Game asset. 2d. High contrast. No shadows
Meyve kesme animasyonu için arkaplan. In-Game asset. 2d. High contrast. No shadows
Muz meyvesi. In-Game asset. 2d. High contrast. No shadows
Çilek. In-Game asset. 2d. High contrast. No shadows
Çilek şeklinde bomba. In-Game asset. 2d. High contrast. No shadows