User prompt
the fruits want to be faster ↪💡 Consider importing and using the following plugins: @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Fruit Slash Frenzy
Initial prompt
I want a game where you want to cut the fruits that game is infinite. When you lose you want to restart the game. When your score is 30 you have a double score when your score is 10000 you win
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Fruit = Container.expand(function (fruitType) { var self = Container.call(this); var fruitGraphics = self.attachAsset(fruitType, { anchorX: 0.5, anchorY: 0.5 }); self.fruitType = fruitType; self.fallSpeed = Math.random() * 4 + 4; // Random speed between 4-8 self.rotationSpeed = (Math.random() - 0.5) * 0.1; // Random rotation self.isSliced = false; self.lastY = undefined; self.update = function () { if (!self.isSliced) { self.y += self.fallSpeed; self.rotation += self.rotationSpeed; // Gradually increase speed as fruit falls if (self.y > 500 && self.y < 501) { tween(self, { fallSpeed: self.fallSpeed * 1.5 }, { duration: 1000 }); } } }; self.slice = function () { if (self.isSliced) return; self.isSliced = true; // Create slice effect LK.effects.flashObject(self, 0xffffff, 300); // Animate fruit disappearing tween(self, { alpha: 0, scaleX: 1.5, scaleY: 1.5 }, { duration: 300, onFinish: function onFinish() { if (self.parent) { self.destroy(); } } }); // Play slice sound LK.getSound('slice').play(); // Award points var points = doubleScore ? 2 : 1; LK.setScore(LK.getScore() + points); // Check for milestones if (LK.getScore() >= 30 && !doubleScore) { doubleScore = true; LK.effects.flashScreen(0x00ff00, 500); } if (LK.getScore() >= 10000) { LK.showYouWin(); } }; return self; }); var SlashEffect = Container.expand(function () { var self = Container.call(this); var slashGraphics = self.attachAsset('slashEffect', { anchorX: 0.5, anchorY: 0.5 }); slashGraphics.alpha = 0.8; // Animate slash effect tween(self, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 200, onFinish: function onFinish() { if (self.parent) { self.destroy(); } } }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Game variables var fruits = []; var fruitTypes = ['apple', 'orange', 'banana', 'grape']; var spawnTimer = 0; var spawnRate = 60; // Start spawning every 60 ticks (1 second) var doubleScore = false; var isSlashing = false; var slashStartX = 0; var slashStartY = 0; // UI Elements var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0, 0); scoreTxt.x = 120; scoreTxt.y = 50; game.addChild(scoreTxt); var multiplierTxt = new Text2('', { size: 60, fill: 0xFFFF00 }); multiplierTxt.anchor.set(0.5, 0); multiplierTxt.x = 1024; multiplierTxt.y = 50; game.addChild(multiplierTxt); // Spawn fruit function function spawnFruit() { var fruitType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)]; var fruit = new Fruit(fruitType); fruit.x = Math.random() * (2048 - 200) + 100; // Keep fruits within screen bounds fruit.y = -100; fruit.lastY = fruit.y; fruits.push(fruit); game.addChild(fruit); } // Check if point is on fruit function checkFruitHit(x, y) { for (var i = 0; i < fruits.length; i++) { var fruit = fruits[i]; if (!fruit.isSliced) { var dx = x - fruit.x; var dy = y - fruit.y; var distance = Math.sqrt(dx * dx + dy * dy); if (distance < 80) { // Hit radius fruit.slice(); // Create slash effect var slash = new SlashEffect(); slash.x = x; slash.y = y; slash.rotation = Math.random() * Math.PI * 2; game.addChild(slash); return true; } } } return false; } // Game input handlers game.down = function (x, y, obj) { isSlashing = true; slashStartX = x; slashStartY = y; checkFruitHit(x, y); }; game.move = function (x, y, obj) { if (isSlashing) { checkFruitHit(x, y); } }; game.up = function (x, y, obj) { isSlashing = false; }; // Main game update loop game.update = function () { // Update score display scoreTxt.setText('Score: ' + LK.getScore()); // Update multiplier display if (doubleScore) { multiplierTxt.setText('2X SCORE!'); } else { multiplierTxt.setText(''); } // Spawn fruits spawnTimer++; if (spawnTimer >= spawnRate) { spawnFruit(); spawnTimer = 0; // Gradually increase difficulty if (spawnRate > 20) { spawnRate -= 1; } } // Update fruits and check for missed fruits for (var i = fruits.length - 1; i >= 0; i--) { var fruit = fruits[i]; if (fruit.lastY === undefined) fruit.lastY = fruit.y; // Check if fruit went off screen (missed) if (fruit.lastY <= 2732 && fruit.y > 2732 && !fruit.isSliced) { // Game over - missed a fruit LK.effects.flashScreen(0xff0000, 1000); LK.getSound('miss').play(); LK.showGameOver(); return; } // Remove fruits that are off screen and already sliced or way below screen if (fruit.y > 2832 || fruit.isSliced && fruit.alpha <= 0) { if (fruit.parent) { fruit.destroy(); } fruits.splice(i, 1); continue; } fruit.lastY = fruit.y; } };
===================================================================
--- original.js
+++ change.js
@@ -12,16 +12,24 @@
anchorX: 0.5,
anchorY: 0.5
});
self.fruitType = fruitType;
- self.fallSpeed = Math.random() * 3 + 2; // Random speed between 2-5
+ self.fallSpeed = Math.random() * 4 + 4; // Random speed between 4-8
self.rotationSpeed = (Math.random() - 0.5) * 0.1; // Random rotation
self.isSliced = false;
self.lastY = undefined;
self.update = function () {
if (!self.isSliced) {
self.y += self.fallSpeed;
self.rotation += self.rotationSpeed;
+ // Gradually increase speed as fruit falls
+ if (self.y > 500 && self.y < 501) {
+ tween(self, {
+ fallSpeed: self.fallSpeed * 1.5
+ }, {
+ duration: 1000
+ });
+ }
}
};
self.slice = function () {
if (self.isSliced) return;
@@ -93,9 +101,9 @@
// Game variables
var fruits = [];
var fruitTypes = ['apple', 'orange', 'banana', 'grape'];
var spawnTimer = 0;
-var spawnRate = 90; // Start spawning every 90 ticks (1.5 seconds)
+var spawnRate = 60; // Start spawning every 60 ticks (1 second)
var doubleScore = false;
var isSlashing = false;
var slashStartX = 0;
var slashStartY = 0;
@@ -179,10 +187,10 @@
if (spawnTimer >= spawnRate) {
spawnFruit();
spawnTimer = 0;
// Gradually increase difficulty
- if (spawnRate > 30) {
- spawnRate -= 0.5;
+ if (spawnRate > 20) {
+ spawnRate -= 1;
}
}
// Update fruits and check for missed fruits
for (var i = fruits.length - 1; i >= 0; i--) {