/**** * Classes ****/ // Bomb class representing the bombs to be avoided var Bomb = Container.expand(function () { var self = Container.call(this); var bombGraphics = self.attachAsset('bomb', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); self.speed = Math.random() * 15 + 30; // Set the minimum and maximum height that the bombs will reach self.direction = Math.random() * Math.PI * 2; // Random direction for each bomb // Update function to move the bomb self.update = function () { self.speed -= 0.4; // Decrease speed to simulate gravity self.y -= self.speed; // Make the bomb rise by decreasing its y-coordinate self.rotation += 0.1; // Add rotation to create a rising animation // Check if the bomb is out of bounds if (self.y < 0) { self.destroy(); } }; // Add containsPoint method to check if a point is inside the bomb self.containsPoint = function (point) { var dx = point.x - self.x; var dy = point.y - self.y; return dx * dx + dy * dy <= bombGraphics.width * 1.5 * (bombGraphics.width * 1.5) / 4; }; }); // Fruit class representing the fruits to be sliced var Fruit = Container.expand(function () { var self = Container.call(this); var fruitGraphics = self.attachAsset('fruit' + Math.ceil(Math.random() * 3), { anchorX: 0.5, anchorY: 0.5, scaleX: (Math.random() * 0.5 + 1) * 1.5, scaleY: (Math.random() * 0.5 + 1) * 1.5 }); self.speed = Math.random() * 15 + 30; // Set the minimum and maximum height that the fruits will reach self.direction = Math.random() * Math.PI * 2; // Random direction for each fruit // Update function to move the fruit self.update = function () { self.speed -= 0.4; // Decrease speed to simulate gravity self.y -= self.speed; // Make the fruit rise by decreasing its y-coordinate self.rotation += 0.1; // Add rotation to create a rising animation // Check if the fruit is out of bounds if (self.y < 0) { self.destroy(); } }; // Add containsPoint method to check if a point is inside the fruit self.containsPoint = function (point) { var dx = point.x - self.x; var dy = point.y - self.y; return dx * dx + dy * dy <= fruitGraphics.width * 1.5 * (fruitGraphics.width * 1.5) / 4; }; }); //<Assets used in the game will automatically appear here> // Class for the game canvas var GameCanvas = Container.expand(function () { var self = Container.call(this); var canvasGraphics = self.attachAsset('canvas', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); self.x = 2048 / 2; self.y = 2732 / 2; }); // Class for the game score var GameScore = Container.expand(function () { var self = Container.call(this); var scoreGraphics = self.attachAsset('scoreTxt', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); self.x = 2048 / 2; self.y = 2732 / 2; self.setText = function (score) { scoreGraphics.text = score.toString(); }; }); // Class for the half fruit pieces var HalfFruit = Container.expand(function () { var self = Container.call(this); var halfFruitGraphics = self.attachAsset('slicedFruit1', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.25, scaleY: 1.25 }); self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction // Update function to move the fruit piece self.update = function () { self.speed -= 0.2; // Decrease speed to simulate gravity self.y += self.speed; // Make the piece fall by increasing its y-coordinate self.rotation += 0.1; // Add rotation to create a falling animation // Check if the piece is out of bounds if (self.y > 2732) { self.destroy(); } }; }); var HalfFruit2 = Container.expand(function () { var self = Container.call(this); var halfFruitGraphics = self.attachAsset('slicedFruit2', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.25, scaleY: 1.25 }); self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction // Update function to move the fruit piece self.update = function () { self.speed -= 0.2; // Decrease speed to simulate gravity self.y += self.speed; // Make the piece fall by increasing its y-coordinate self.rotation += 0.1; // Add rotation to create a falling animation // Check if the piece is out of bounds if (self.y > 2732) { self.destroy(); } }; }); var HalfFruit3 = Container.expand(function () { var self = Container.call(this); var halfFruitGraphics = self.attachAsset('slicedFruit3', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.25, scaleY: 1.25 }); self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction // Update function to move the fruit piece self.update = function () { self.speed -= 0.2; // Decrease speed to simulate gravity self.y += self.speed; // Make the piece fall by increasing its y-coordinate self.rotation += 0.1; // Add rotation to create a falling animation // Check if the piece is out of bounds if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB // Light blue background to simulate sky }); /**** * Game Code ****/ // Function to display animated 'Fruit Juice' text function displayAnimatedText() { var text = new Text2('', { // Initialize with empty string to avoid undefined error size: 200, fill: 0xFF4500 }); text.text = ''; // Initialize text.text to an empty string to avoid undefined error text.anchor.set(0.5, 0.5); text.x = 2048 / 2; text.y = 2732 / 2; game.addChild(text); var charIndex = 0; var revealInterval = LK.setInterval(function () { if (charIndex < text.text.length) { text.text = text.text.substring(0, charIndex + 1); charIndex++; } else { LK.clearInterval(revealInterval); // Remove the text after a delay LK.setTimeout(function () { text.destroy(); }, 2000); } }, 200); } // Call the function to display the text when the game starts displayAnimatedText(); // Play background music continuously LK.playMusic('huzur'); // Function to spawn a new bomb /****const canvas = document.getElementById('gameCanvas'); const ctx = canvas.getContext('2d'); canvas.width = 800; canvas.height = 600; let score = 0; let time = 60; let fruits = []; let gameInterval; let timeInterval; const fruitImages = { apple: 'https://example.com/apple.png', // Replace with actual image URLs banana: 'https://example.com/banana.png', strawberry: 'https://example.com/strawberry.png', pineapple: 'https://example.com/pineapple.png', bomb: 'https://example.com/bomb.png' }; class Fruit { constructor(x, y, type) { this.x = x; this.y = y; this.type = type; this.width = 50; this.height = 50; this.speed = Math.random() * 3 + 2; // Random speed } draw() { const img = new Image(); img.src = fruitImages[this.type]; img.onload = () => { ctx.drawImage(img, this.x, this.y, this.width, this.height); }; } update() { this.y -= this.speed; if (this.y < 0) { fruits.splice(fruits.indexOf(this), 1); } } } function spawnFruit() { const types = Object.keys(fruitImages); const type = types[Math.floor(Math.random() * types.length)]; const x = Math.random() * (canvas.width - 50); const fruit = new Fruit(x, canvas.height, type); fruits.push(fruit); } function draw() { ctx.clearRect(0, 0, canvas.width, canvas.height); fruits.forEach(fruit => { fruit.update(); fruit.draw(); }); document.getElementById('score').innerText = `Score: ${score}`; document.getElementById('time').innerText = `Time: ${time}`; } function startGame() { gameInterval = setInterval(() => { draw(); spawnFruit(); }, 1000 / 60); // 60 FPS timeInterval = setInterval(() => { time--; if (time <= 0) { endGame(); } }, 1000); } function endGame() { clearInterval(gameInterval); clearInterval(timeInterval); document.getElementById('final-score').innerText = score; document.getElementById('game-over').classList.remove('hidden'); } function restartGame() { score = 0; time = 60; fruits = []; document.getElementById('game-over').classList.add('hidden'); startGame(); } canvas.addEventListener('click', (event) => { const rect = canvas.getBoundingClientRect(); const mouseX = event.clientX - rect.left; const mouseY = event.clientY - rect.top; fruits.forEach((fruit, index) => { if (mouseX > fruit.x && mouseX < fruit.x + fruit.width && mouseY > fruit.y && mouseY < fruit.y + fruit.height) { if (fruit.type === 'bomb') { endGame(); } else { score += 10; // Adjust score based on fruit type fruits.splice(index, 1); // Remove sliced fruit } } }); }); document.getElementById('restart-button').addEventListener('click', restartGame); // Start the game on load startGame(); * Assets ****/ function spawnBomb() { var newBomb = new Bomb(); newBomb.x = Math.random() * 2048; newBomb.y = Math.random() * 100 + 2732; // Start from the bottom of the screen game.addChild(newBomb); } // Initialize variables var dragNode = null; // Initialize dragNode in the global scope var fruits = []; var score = 0; var gameCanvas = game.addChild(new GameCanvas()); var gameScore = game.addChild(new GameScore()); var scoreTxt = new Text2('0', { size: 150, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Add 'Glaud' text in the top right corner var glaudTxt = new Text2('Glaud', { size: 60, fill: 0xFF8C00 // Orange color }); glaudTxt.anchor.set(1, 0); // Anchor to top right LK.gui.topRight.addChild(glaudTxt); // Function to spawn a new fruit function spawnFruit() { var newFruit = new Fruit(); newFruit.x = Math.random() * 2048; newFruit.y = Math.random() * 100 + 2732; // Start from the bottom of the screen fruits.push(newFruit); game.addChild(newFruit); } // Function to handle slicing function sliceFruit(x, y) { for (var i = fruits.length - 1; i >= 0; i--) { if (fruits[i].containsPoint({ x: x, y: y })) { // Create two half fruit pieces when a fruit is sliced var halfFruit1 = new HalfFruit(); var halfFruit2 = new HalfFruit(); halfFruit1.x = fruits[i].x; halfFruit1.y = fruits[i].y; halfFruit1.direction = Math.random() * Math.PI; // Random direction for each piece game.addChild(halfFruit1); halfFruit2.x = fruits[i].x; halfFruit2.y = fruits[i].y; halfFruit2.direction = Math.random() * Math.PI; // Random direction for each piece game.addChild(halfFruit2); // Add juice splash effect var juiceSplash = LK.getAsset('swordTrail', { anchorX: 0.5, anchorY: 0.5, x: fruits[i].x, y: fruits[i].y }); game.addChild(juiceSplash); var splashFadeDuration = 300; var splashFadeStep = 1 / (splashFadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame var splashFadeInterval = LK.setInterval(function () { juiceSplash.alpha -= splashFadeStep; if (juiceSplash.alpha <= 0) { juiceSplash.destroy(); LK.clearInterval(splashFadeInterval); } }, 16.67); // Add sliced fruit visual effect var slicedFruitVisual = LK.getAsset('slicedFruit' + Math.ceil(Math.random() * 3), { anchorX: 0.5, anchorY: 0.5, x: fruits[i].x, y: fruits[i].y }); game.addChild(slicedFruitVisual); var visualFadeDuration = 500; var visualFadeStep = 1 / (visualFadeDuration / 16.67); var visualFadeInterval = LK.setInterval(function () { slicedFruitVisual.alpha -= visualFadeStep; if (slicedFruitVisual.alpha <= 0) { slicedFruitVisual.destroy(); LK.clearInterval(visualFadeInterval); } }, 16.67); // Play slicing sound LK.getSound('kesme').play(); // Store fruit position before destroying var fruitX = fruits[i].x; var fruitY = fruits[i].y; fruits[i].destroy(); fruits.splice(i, 1); score += 10; scoreTxt.setText(score.toString()); gameScore.setText(score); // Display points gained var pointsGained = new Text2('+10', { size: 100, fill: 0x00FF00 }); pointsGained.anchor.set(0.5, 0.5); pointsGained.x = fruitX + 20; pointsGained.y = fruitY + 20; game.addChild(pointsGained); // Add sparkle effect around points gained var sparkle = LK.getAsset('swordTrail', { anchorX: 0.5, anchorY: 0.5, x: fruitX, y: fruitY }); game.addChild(sparkle); var sparkleFadeDuration = 500; var sparkleFadeStep = 1 / (sparkleFadeDuration / 16.67); var sparkleFadeInterval = LK.setInterval(function () { sparkle.alpha -= sparkleFadeStep; if (sparkle.alpha <= 0) { sparkle.destroy(); LK.clearInterval(sparkleFadeInterval); } }, 16.67); // Fade out effect for points gained var pointsFadeDuration = 1000; var pointsFadeStep = 1 / (pointsFadeDuration / 16.67); var pointsFadeInterval = LK.setInterval(function () { pointsGained.alpha -= pointsFadeStep; if (pointsGained.alpha <= 0) { pointsGained.destroy(); LK.clearInterval(pointsFadeInterval); } }, 16.67); } } } // Set up game events game.down = function (x, y, obj) { dragNode = { x: x, y: y }; // Start tracking the drag // Create sword trail effect var swordTrail = LK.getAsset('swordTrail', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); game.addChild(swordTrail); // Custom fade out effect for sword trail var fadeDuration = 500; var fadeStep = 1 / (fadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame var fadeInterval = LK.setInterval(function () { swordTrail.alpha -= fadeStep; if (swordTrail.alpha <= 0) { swordTrail.destroy(); LK.clearInterval(fadeInterval); } }, 16.67); // Add sparkle effect on mouse click var sparkle = LK.getAsset('swordTrail', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); game.addChild(sparkle); var sparkleFadeDuration = 300; var sparkleFadeStep = 1 / (sparkleFadeDuration / 16.67); var sparkleFadeInterval = LK.setInterval(function () { sparkle.alpha -= sparkleFadeStep; if (sparkle.alpha <= 0) { sparkle.destroy(); LK.clearInterval(sparkleFadeInterval); } }, 16.67); }; // Update function called every tick game.move = function (x, y, obj) { if (dragNode) { // Create sword trail effect var swordTrail = LK.getAsset('swordTrail', { anchorX: 0.5, anchorY: 0.5, x: x, y: y }); game.addChild(swordTrail); // Custom fade out effect for sword trail var fadeDuration = 500; var fadeStep = 1 / (fadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame var fadeInterval = LK.setInterval(function () { swordTrail.alpha -= fadeStep; if (swordTrail.alpha <= 0) { swordTrail.destroy(); LK.clearInterval(fadeInterval); } }, 16.67); // Calculate the distance moved var dx = x - dragNode.x; var dy = y - dragNode.y; var distance = Math.sqrt(dx * dx + dy * dy); // If the distance is significant, consider it a slice if (distance > 10) { sliceFruit(x, y); dragNode = { x: x, y: y }; // Update the drag position } } }; game.up = function (x, y, obj) { dragNode = null; // Stop tracking the drag }; game.update = function () { // Update all fruits for (var i = fruits.length - 1; i >= 0; i--) { fruits[i].update(); } // Spawn a new fruit every 60 ticks if (LK.ticks % 60 === 0) { spawnFruit(); } // Update the game score scoreTxt.setText(score.toString()); gameScore.setText(score); // Check for bomb interactions for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof Bomb && game.children[i].containsPoint({ x: obj.event.x, y: obj.event.y })) { // Trigger negative effect, e.g., losing points score -= 20; scoreTxt.setText(score); game.children[i].destroy(); } } // Update the half fruit pieces for (var i = game.children.length - 1; i >= 0; i--) { if (game.children[i] instanceof HalfFruit || game.children[i] instanceof HalfFruit2 || game.children[i] instanceof HalfFruit3) { game.children[i].update(); } } };
/****
* Classes
****/
// Bomb class representing the bombs to be avoided
var Bomb = Container.expand(function () {
var self = Container.call(this);
var bombGraphics = self.attachAsset('bomb', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
self.speed = Math.random() * 15 + 30; // Set the minimum and maximum height that the bombs will reach
self.direction = Math.random() * Math.PI * 2; // Random direction for each bomb
// Update function to move the bomb
self.update = function () {
self.speed -= 0.4; // Decrease speed to simulate gravity
self.y -= self.speed; // Make the bomb rise by decreasing its y-coordinate
self.rotation += 0.1; // Add rotation to create a rising animation
// Check if the bomb is out of bounds
if (self.y < 0) {
self.destroy();
}
};
// Add containsPoint method to check if a point is inside the bomb
self.containsPoint = function (point) {
var dx = point.x - self.x;
var dy = point.y - self.y;
return dx * dx + dy * dy <= bombGraphics.width * 1.5 * (bombGraphics.width * 1.5) / 4;
};
});
// Fruit class representing the fruits to be sliced
var Fruit = Container.expand(function () {
var self = Container.call(this);
var fruitGraphics = self.attachAsset('fruit' + Math.ceil(Math.random() * 3), {
anchorX: 0.5,
anchorY: 0.5,
scaleX: (Math.random() * 0.5 + 1) * 1.5,
scaleY: (Math.random() * 0.5 + 1) * 1.5
});
self.speed = Math.random() * 15 + 30; // Set the minimum and maximum height that the fruits will reach
self.direction = Math.random() * Math.PI * 2; // Random direction for each fruit
// Update function to move the fruit
self.update = function () {
self.speed -= 0.4; // Decrease speed to simulate gravity
self.y -= self.speed; // Make the fruit rise by decreasing its y-coordinate
self.rotation += 0.1; // Add rotation to create a rising animation
// Check if the fruit is out of bounds
if (self.y < 0) {
self.destroy();
}
};
// Add containsPoint method to check if a point is inside the fruit
self.containsPoint = function (point) {
var dx = point.x - self.x;
var dy = point.y - self.y;
return dx * dx + dy * dy <= fruitGraphics.width * 1.5 * (fruitGraphics.width * 1.5) / 4;
};
});
//<Assets used in the game will automatically appear here>
// Class for the game canvas
var GameCanvas = Container.expand(function () {
var self = Container.call(this);
var canvasGraphics = self.attachAsset('canvas', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
self.x = 2048 / 2;
self.y = 2732 / 2;
});
// Class for the game score
var GameScore = Container.expand(function () {
var self = Container.call(this);
var scoreGraphics = self.attachAsset('scoreTxt', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1,
scaleY: 1
});
self.x = 2048 / 2;
self.y = 2732 / 2;
self.setText = function (score) {
scoreGraphics.text = score.toString();
};
});
// Class for the half fruit pieces
var HalfFruit = Container.expand(function () {
var self = Container.call(this);
var halfFruitGraphics = self.attachAsset('slicedFruit1', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.25,
scaleY: 1.25
});
self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces
self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction
// Update function to move the fruit piece
self.update = function () {
self.speed -= 0.2; // Decrease speed to simulate gravity
self.y += self.speed; // Make the piece fall by increasing its y-coordinate
self.rotation += 0.1; // Add rotation to create a falling animation
// Check if the piece is out of bounds
if (self.y > 2732) {
self.destroy();
}
};
});
var HalfFruit2 = Container.expand(function () {
var self = Container.call(this);
var halfFruitGraphics = self.attachAsset('slicedFruit2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.25,
scaleY: 1.25
});
self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces
self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction
// Update function to move the fruit piece
self.update = function () {
self.speed -= 0.2; // Decrease speed to simulate gravity
self.y += self.speed; // Make the piece fall by increasing its y-coordinate
self.rotation += 0.1; // Add rotation to create a falling animation
// Check if the piece is out of bounds
if (self.y > 2732) {
self.destroy();
}
};
});
var HalfFruit3 = Container.expand(function () {
var self = Container.call(this);
var halfFruitGraphics = self.attachAsset('slicedFruit3', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.25,
scaleY: 1.25
});
self.speed = Math.random() * 3 + 5; // Set the speed of the falling pieces
self.direction = Math.random() * Math.PI + Math.PI; // Random direction for each piece in the opposite direction
// Update function to move the fruit piece
self.update = function () {
self.speed -= 0.2; // Decrease speed to simulate gravity
self.y += self.speed; // Make the piece fall by increasing its y-coordinate
self.rotation += 0.1; // Add rotation to create a falling animation
// Check if the piece is out of bounds
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background to simulate sky
});
/****
* Game Code
****/
// Function to display animated 'Fruit Juice' text
function displayAnimatedText() {
var text = new Text2('', {
// Initialize with empty string to avoid undefined error
size: 200,
fill: 0xFF4500
});
text.text = ''; // Initialize text.text to an empty string to avoid undefined error
text.anchor.set(0.5, 0.5);
text.x = 2048 / 2;
text.y = 2732 / 2;
game.addChild(text);
var charIndex = 0;
var revealInterval = LK.setInterval(function () {
if (charIndex < text.text.length) {
text.text = text.text.substring(0, charIndex + 1);
charIndex++;
} else {
LK.clearInterval(revealInterval);
// Remove the text after a delay
LK.setTimeout(function () {
text.destroy();
}, 2000);
}
}, 200);
}
// Call the function to display the text when the game starts
displayAnimatedText();
// Play background music continuously
LK.playMusic('huzur');
// Function to spawn a new bomb
/****const canvas = document.getElementById('gameCanvas');
const ctx = canvas.getContext('2d');
canvas.width = 800;
canvas.height = 600;
let score = 0;
let time = 60;
let fruits = [];
let gameInterval;
let timeInterval;
const fruitImages = {
apple: 'https://example.com/apple.png', // Replace with actual image URLs
banana: 'https://example.com/banana.png',
strawberry: 'https://example.com/strawberry.png',
pineapple: 'https://example.com/pineapple.png',
bomb: 'https://example.com/bomb.png'
};
class Fruit {
constructor(x, y, type) {
this.x = x;
this.y = y;
this.type = type;
this.width = 50;
this.height = 50;
this.speed = Math.random() * 3 + 2; // Random speed
}
draw() {
const img = new Image();
img.src = fruitImages[this.type];
img.onload = () => {
ctx.drawImage(img, this.x, this.y, this.width, this.height);
};
}
update() {
this.y -= this.speed;
if (this.y < 0) {
fruits.splice(fruits.indexOf(this), 1);
}
}
}
function spawnFruit() {
const types = Object.keys(fruitImages);
const type = types[Math.floor(Math.random() * types.length)];
const x = Math.random() * (canvas.width - 50);
const fruit = new Fruit(x, canvas.height, type);
fruits.push(fruit);
}
function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
fruits.forEach(fruit => {
fruit.update();
fruit.draw();
});
document.getElementById('score').innerText = `Score: ${score}`;
document.getElementById('time').innerText = `Time: ${time}`;
}
function startGame() {
gameInterval = setInterval(() => {
draw();
spawnFruit();
}, 1000 / 60); // 60 FPS
timeInterval = setInterval(() => {
time--;
if (time <= 0) {
endGame();
}
}, 1000);
}
function endGame() {
clearInterval(gameInterval);
clearInterval(timeInterval);
document.getElementById('final-score').innerText = score;
document.getElementById('game-over').classList.remove('hidden');
}
function restartGame() {
score = 0;
time = 60;
fruits = [];
document.getElementById('game-over').classList.add('hidden');
startGame();
}
canvas.addEventListener('click', (event) => {
const rect = canvas.getBoundingClientRect();
const mouseX = event.clientX - rect.left;
const mouseY = event.clientY - rect.top;
fruits.forEach((fruit, index) => {
if (mouseX > fruit.x && mouseX < fruit.x + fruit.width &&
mouseY > fruit.y && mouseY < fruit.y + fruit.height) {
if (fruit.type === 'bomb') {
endGame();
} else {
score += 10; // Adjust score based on fruit type
fruits.splice(index, 1); // Remove sliced fruit
}
}
});
});
document.getElementById('restart-button').addEventListener('click', restartGame);
// Start the game on load
startGame();
* Assets
****/
function spawnBomb() {
var newBomb = new Bomb();
newBomb.x = Math.random() * 2048;
newBomb.y = Math.random() * 100 + 2732; // Start from the bottom of the screen
game.addChild(newBomb);
}
// Initialize variables
var dragNode = null; // Initialize dragNode in the global scope
var fruits = [];
var score = 0;
var gameCanvas = game.addChild(new GameCanvas());
var gameScore = game.addChild(new GameScore());
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add 'Glaud' text in the top right corner
var glaudTxt = new Text2('Glaud', {
size: 60,
fill: 0xFF8C00 // Orange color
});
glaudTxt.anchor.set(1, 0); // Anchor to top right
LK.gui.topRight.addChild(glaudTxt);
// Function to spawn a new fruit
function spawnFruit() {
var newFruit = new Fruit();
newFruit.x = Math.random() * 2048;
newFruit.y = Math.random() * 100 + 2732; // Start from the bottom of the screen
fruits.push(newFruit);
game.addChild(newFruit);
}
// Function to handle slicing
function sliceFruit(x, y) {
for (var i = fruits.length - 1; i >= 0; i--) {
if (fruits[i].containsPoint({
x: x,
y: y
})) {
// Create two half fruit pieces when a fruit is sliced
var halfFruit1 = new HalfFruit();
var halfFruit2 = new HalfFruit();
halfFruit1.x = fruits[i].x;
halfFruit1.y = fruits[i].y;
halfFruit1.direction = Math.random() * Math.PI; // Random direction for each piece
game.addChild(halfFruit1);
halfFruit2.x = fruits[i].x;
halfFruit2.y = fruits[i].y;
halfFruit2.direction = Math.random() * Math.PI; // Random direction for each piece
game.addChild(halfFruit2);
// Add juice splash effect
var juiceSplash = LK.getAsset('swordTrail', {
anchorX: 0.5,
anchorY: 0.5,
x: fruits[i].x,
y: fruits[i].y
});
game.addChild(juiceSplash);
var splashFadeDuration = 300;
var splashFadeStep = 1 / (splashFadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame
var splashFadeInterval = LK.setInterval(function () {
juiceSplash.alpha -= splashFadeStep;
if (juiceSplash.alpha <= 0) {
juiceSplash.destroy();
LK.clearInterval(splashFadeInterval);
}
}, 16.67);
// Add sliced fruit visual effect
var slicedFruitVisual = LK.getAsset('slicedFruit' + Math.ceil(Math.random() * 3), {
anchorX: 0.5,
anchorY: 0.5,
x: fruits[i].x,
y: fruits[i].y
});
game.addChild(slicedFruitVisual);
var visualFadeDuration = 500;
var visualFadeStep = 1 / (visualFadeDuration / 16.67);
var visualFadeInterval = LK.setInterval(function () {
slicedFruitVisual.alpha -= visualFadeStep;
if (slicedFruitVisual.alpha <= 0) {
slicedFruitVisual.destroy();
LK.clearInterval(visualFadeInterval);
}
}, 16.67);
// Play slicing sound
LK.getSound('kesme').play();
// Store fruit position before destroying
var fruitX = fruits[i].x;
var fruitY = fruits[i].y;
fruits[i].destroy();
fruits.splice(i, 1);
score += 10;
scoreTxt.setText(score.toString());
gameScore.setText(score);
// Display points gained
var pointsGained = new Text2('+10', {
size: 100,
fill: 0x00FF00
});
pointsGained.anchor.set(0.5, 0.5);
pointsGained.x = fruitX + 20;
pointsGained.y = fruitY + 20;
game.addChild(pointsGained);
// Add sparkle effect around points gained
var sparkle = LK.getAsset('swordTrail', {
anchorX: 0.5,
anchorY: 0.5,
x: fruitX,
y: fruitY
});
game.addChild(sparkle);
var sparkleFadeDuration = 500;
var sparkleFadeStep = 1 / (sparkleFadeDuration / 16.67);
var sparkleFadeInterval = LK.setInterval(function () {
sparkle.alpha -= sparkleFadeStep;
if (sparkle.alpha <= 0) {
sparkle.destroy();
LK.clearInterval(sparkleFadeInterval);
}
}, 16.67);
// Fade out effect for points gained
var pointsFadeDuration = 1000;
var pointsFadeStep = 1 / (pointsFadeDuration / 16.67);
var pointsFadeInterval = LK.setInterval(function () {
pointsGained.alpha -= pointsFadeStep;
if (pointsGained.alpha <= 0) {
pointsGained.destroy();
LK.clearInterval(pointsFadeInterval);
}
}, 16.67);
}
}
}
// Set up game events
game.down = function (x, y, obj) {
dragNode = {
x: x,
y: y
}; // Start tracking the drag
// Create sword trail effect
var swordTrail = LK.getAsset('swordTrail', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
});
game.addChild(swordTrail);
// Custom fade out effect for sword trail
var fadeDuration = 500;
var fadeStep = 1 / (fadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame
var fadeInterval = LK.setInterval(function () {
swordTrail.alpha -= fadeStep;
if (swordTrail.alpha <= 0) {
swordTrail.destroy();
LK.clearInterval(fadeInterval);
}
}, 16.67);
// Add sparkle effect on mouse click
var sparkle = LK.getAsset('swordTrail', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
});
game.addChild(sparkle);
var sparkleFadeDuration = 300;
var sparkleFadeStep = 1 / (sparkleFadeDuration / 16.67);
var sparkleFadeInterval = LK.setInterval(function () {
sparkle.alpha -= sparkleFadeStep;
if (sparkle.alpha <= 0) {
sparkle.destroy();
LK.clearInterval(sparkleFadeInterval);
}
}, 16.67);
};
// Update function called every tick
game.move = function (x, y, obj) {
if (dragNode) {
// Create sword trail effect
var swordTrail = LK.getAsset('swordTrail', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y
});
game.addChild(swordTrail);
// Custom fade out effect for sword trail
var fadeDuration = 500;
var fadeStep = 1 / (fadeDuration / 16.67); // Assuming 60 FPS, 16.67ms per frame
var fadeInterval = LK.setInterval(function () {
swordTrail.alpha -= fadeStep;
if (swordTrail.alpha <= 0) {
swordTrail.destroy();
LK.clearInterval(fadeInterval);
}
}, 16.67);
// Calculate the distance moved
var dx = x - dragNode.x;
var dy = y - dragNode.y;
var distance = Math.sqrt(dx * dx + dy * dy);
// If the distance is significant, consider it a slice
if (distance > 10) {
sliceFruit(x, y);
dragNode = {
x: x,
y: y
}; // Update the drag position
}
}
};
game.up = function (x, y, obj) {
dragNode = null; // Stop tracking the drag
};
game.update = function () {
// Update all fruits
for (var i = fruits.length - 1; i >= 0; i--) {
fruits[i].update();
}
// Spawn a new fruit every 60 ticks
if (LK.ticks % 60 === 0) {
spawnFruit();
}
// Update the game score
scoreTxt.setText(score.toString());
gameScore.setText(score);
// Check for bomb interactions
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof Bomb && game.children[i].containsPoint({
x: obj.event.x,
y: obj.event.y
})) {
// Trigger negative effect, e.g., losing points
score -= 20;
scoreTxt.setText(score);
game.children[i].destroy();
}
}
// Update the half fruit pieces
for (var i = game.children.length - 1; i >= 0; i--) {
if (game.children[i] instanceof HalfFruit || game.children[i] instanceof HalfFruit2 || game.children[i] instanceof HalfFruit3) {
game.children[i].update();
}
}
};
animation orange. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
animation banana transparent back. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
bomba. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
çilek. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
açık kahve rengi tahta çizikli. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
diagonal white line. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
2d meyve suyu patlaması. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.