User prompt
Quitar lag
User prompt
Que el láser al colisionar con una fruta que de experiencia ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Quitar lag
User prompt
Al cortar fruta +2 monedas
User prompt
Pon un botón de volver al menú
User prompt
Pon una mejora que 2 láseres i ser más ancho
User prompt
Añadir tienda ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Añadir un menú de inicio
User prompt
Para acabar tienes que tener 25000
User prompt
Mejoras para el jugador ↪💡 Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1
User prompt
Mejoras de puntos
User prompt
Mejoras
Code edit (1 edits merged)
Please save this source code
User prompt
Smash Fruit Frenzy
Initial prompt
Shmas fruite
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Character = Container.expand(function () {
var self = Container.call(this);
var characterGraphics = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
return self;
});
var Fruit = Container.expand(function (type) {
var self = Container.call(this);
self.type = type || 'apple';
self.fallSpeed = 3;
self.points = 10;
var fruitGraphics = self.attachAsset(self.type, {
anchorX: 0.5,
anchorY: 0.5
});
// Set different points for different fruits
switch (self.type) {
case 'apple':
self.points = 10;
break;
case 'orange':
self.points = 15;
break;
case 'banana':
self.points = 20;
break;
case 'grape':
self.points = 25;
break;
case 'powerup':
self.points = 50;
self.fallSpeed = 2; // Slower fall speed
break;
}
self.update = function () {
self.y += self.fallSpeed;
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var character = game.addChild(new Character());
character.x = 2048 / 2;
character.y = 2732 - 200;
var fruits = [];
var fruitTypes = ['apple', 'orange', 'banana', 'grape'];
var powerupChance = 0.05; // 5% chance for power-up fruit
var spawnTimer = 0;
var spawnInterval = 90; // frames between fruit spawns
var gameSpeed = 1;
var comboCount = 0;
var comboTimer = 0;
var comboTimeout = 120; // frames before combo resets
var bonusPoints = 0;
var perfectHits = 0;
var timeBonus = 0;
var lastHitTime = 0;
// 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.x = 0;
comboTxt.y = 100;
LK.gui.top.addChild(comboTxt);
// Bonus points display
var bonusTxt = new Text2('Bonus: 0', {
size: 50,
fill: 0x00FF00
});
bonusTxt.anchor.set(0.5, 0);
bonusTxt.x = 0;
bonusTxt.y = 170;
LK.gui.top.addChild(bonusTxt);
// Drag controls
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x;
dragNode.y = y;
// Keep character within screen bounds
if (dragNode.x < 60) dragNode.x = 60;
if (dragNode.x > 2048 - 60) dragNode.x = 2048 - 60;
if (dragNode.y < 60) dragNode.y = 60;
if (dragNode.y > 2732 - 60) dragNode.y = 2732 - 60;
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
dragNode = character;
handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
dragNode = null;
};
function spawnFruit() {
var randomType;
// Chance for power-up fruit
if (Math.random() < powerupChance) {
randomType = 'powerup';
} else {
randomType = fruitTypes[Math.floor(Math.random() * fruitTypes.length)];
}
var fruit = new Fruit(randomType);
fruit.x = Math.random() * (2048 - 160) + 80;
fruit.y = -80;
fruit.fallSpeed = 3 + gameSpeed * 0.5;
fruit.lastY = fruit.y;
fruit.lastIntersecting = false;
// Add pulsing effect to power-up fruits
if (randomType === 'powerup') {
tween(fruit, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
repeat: -1,
yoyo: true
});
}
fruits.push(fruit);
game.addChild(fruit);
}
function createSmashEffect(x, y) {
// Create multiple small particles for smash effect
for (var i = 0; i < 6; i++) {
var particle = LK.getAsset('apple', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3
});
particle.x = x + (Math.random() - 0.5) * 60;
particle.y = y + (Math.random() - 0.5) * 60;
game.addChild(particle);
// Animate particles
tween(particle, {
x: particle.x + (Math.random() - 0.5) * 200,
y: particle.y + (Math.random() - 0.5) * 200,
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 800,
onFinish: function onFinish() {
particle.destroy();
}
});
}
}
game.update = function () {
// Spawn fruits
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnFruit();
spawnTimer = 0;
}
// Update fruits and check collisions
for (var i = fruits.length - 1; i >= 0; i--) {
var fruit = fruits[i];
// Check if fruit went off screen
if (fruit.lastY <= 2732 + 100 && fruit.y > 2732 + 100) {
fruit.destroy();
fruits.splice(i, 1);
continue;
}
// Check collision with character
var currentIntersecting = fruit.intersects(character);
if (!fruit.lastIntersecting && currentIntersecting) {
// Fruit smashed!
comboCount++;
comboTimer = 0;
var multiplier = Math.min(comboCount, 5); // Max 5x multiplier
var basePoints = fruit.points;
var points = basePoints * multiplier;
// Time bonus - award bonus points for quick successive hits
var currentTime = LK.ticks;
if (currentTime - lastHitTime < 30) {
// Within 0.5 seconds
timeBonus += 5;
points += timeBonus;
} else {
timeBonus = 0;
}
lastHitTime = currentTime;
// Perfect hit bonus - fruit hit near center of screen
var centerX = 2048 / 2;
var distanceFromCenter = Math.abs(fruit.x - centerX);
if (distanceFromCenter < 100) {
perfectHits++;
points += 10; // Perfect hit bonus
bonusPoints += 10;
}
// Power-up fruit special bonus
if (fruit.type === 'powerup') {
points += 25; // Extra bonus for power-up
bonusPoints += 25;
// Flash screen gold for power-up
LK.effects.flashScreen(0xFFD700, 200);
}
// Rare fruit bonus (grapes are worth more)
if (fruit.type === 'grape') {
points += 5;
bonusPoints += 5;
}
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
// Update combo display
if (comboCount > 1) {
comboTxt.setText('COMBO x' + multiplier + '!');
tween(comboTxt, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 200,
onFinish: function onFinish() {
tween(comboTxt, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
}
// Update bonus display
bonusTxt.setText('Bonus: ' + bonusPoints);
// Create floating point text for visual feedback
var pointText = new Text2('+' + points, {
size: 40,
fill: 0xFFFFFF
});
pointText.anchor.set(0.5, 0.5);
pointText.x = fruit.x;
pointText.y = fruit.y - 50;
game.addChild(pointText);
// Animate point text
tween(pointText, {
y: pointText.y - 100,
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
pointText.destroy();
}
});
// Create smash effect
createSmashEffect(fruit.x, fruit.y);
// Play smash sound
LK.getSound('smash').play();
// Visual feedback - flash screen and scale character
LK.effects.flashScreen(0xFFFFFF, 100);
tween(character, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
onFinish: function onFinish() {
tween(character, {
scaleX: 1,
scaleY: 1
}, {
duration: 150
});
}
});
// Score milestone bonuses
var currentScore = LK.getScore();
if (currentScore >= 100 && currentScore < 105) {
bonusPoints += 50;
LK.setScore(currentScore + 50);
scoreTxt.setText('Score: ' + LK.getScore());
}
if (currentScore >= 250 && currentScore < 255) {
bonusPoints += 100;
LK.setScore(currentScore + 100);
scoreTxt.setText('Score: ' + LK.getScore());
}
// Perfect hit streak bonus
if (perfectHits >= 5 && perfectHits % 5 === 0) {
var streakBonus = perfectHits * 2;
bonusPoints += streakBonus;
LK.setScore(currentScore + streakBonus);
scoreTxt.setText('Score: ' + LK.getScore());
}
// Check for win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
return;
}
fruit.destroy();
fruits.splice(i, 1);
continue;
}
// Update last known states
fruit.lastY = fruit.y;
fruit.lastIntersecting = currentIntersecting;
}
// Manage combo timer
comboTimer++;
if (comboTimer >= comboTimeout && comboCount > 0) {
comboCount = 0;
comboTxt.setText('');
}
// Increase game speed based on score
gameSpeed = 1 + LK.getScore() / 200;
// Decrease spawn interval as speed increases
spawnInterval = Math.max(30, 90 - LK.getScore() / 10);
// Add more fruit types as score increases
if (LK.getScore() >= 100 && fruitTypes.length < 4) {
// All fruit types are already available from start
}
};
// Start background music
LK.playMusic('bgmusic'); ===================================================================
--- original.js
+++ change.js
@@ -69,8 +69,12 @@
var gameSpeed = 1;
var comboCount = 0;
var comboTimer = 0;
var comboTimeout = 120; // frames before combo resets
+var bonusPoints = 0;
+var perfectHits = 0;
+var timeBonus = 0;
+var lastHitTime = 0;
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
@@ -85,8 +89,17 @@
comboTxt.anchor.set(0.5, 0);
comboTxt.x = 0;
comboTxt.y = 100;
LK.gui.top.addChild(comboTxt);
+// Bonus points display
+var bonusTxt = new Text2('Bonus: 0', {
+ size: 50,
+ fill: 0x00FF00
+});
+bonusTxt.anchor.set(0.5, 0);
+bonusTxt.x = 0;
+bonusTxt.y = 170;
+LK.gui.top.addChild(bonusTxt);
// Drag controls
var dragNode = null;
function handleMove(x, y, obj) {
if (dragNode) {
@@ -184,9 +197,40 @@
// Fruit smashed!
comboCount++;
comboTimer = 0;
var multiplier = Math.min(comboCount, 5); // Max 5x multiplier
- var points = fruit.points * multiplier;
+ var basePoints = fruit.points;
+ var points = basePoints * multiplier;
+ // Time bonus - award bonus points for quick successive hits
+ var currentTime = LK.ticks;
+ if (currentTime - lastHitTime < 30) {
+ // Within 0.5 seconds
+ timeBonus += 5;
+ points += timeBonus;
+ } else {
+ timeBonus = 0;
+ }
+ lastHitTime = currentTime;
+ // Perfect hit bonus - fruit hit near center of screen
+ var centerX = 2048 / 2;
+ var distanceFromCenter = Math.abs(fruit.x - centerX);
+ if (distanceFromCenter < 100) {
+ perfectHits++;
+ points += 10; // Perfect hit bonus
+ bonusPoints += 10;
+ }
+ // Power-up fruit special bonus
+ if (fruit.type === 'powerup') {
+ points += 25; // Extra bonus for power-up
+ bonusPoints += 25;
+ // Flash screen gold for power-up
+ LK.effects.flashScreen(0xFFD700, 200);
+ }
+ // Rare fruit bonus (grapes are worth more)
+ if (fruit.type === 'grape') {
+ points += 5;
+ bonusPoints += 5;
+ }
LK.setScore(LK.getScore() + points);
scoreTxt.setText('Score: ' + LK.getScore());
// Update combo display
if (comboCount > 1) {
@@ -205,8 +249,29 @@
});
}
});
}
+ // Update bonus display
+ bonusTxt.setText('Bonus: ' + bonusPoints);
+ // Create floating point text for visual feedback
+ var pointText = new Text2('+' + points, {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ pointText.anchor.set(0.5, 0.5);
+ pointText.x = fruit.x;
+ pointText.y = fruit.y - 50;
+ game.addChild(pointText);
+ // Animate point text
+ tween(pointText, {
+ y: pointText.y - 100,
+ alpha: 0
+ }, {
+ duration: 1000,
+ onFinish: function onFinish() {
+ pointText.destroy();
+ }
+ });
// Create smash effect
createSmashEffect(fruit.x, fruit.y);
// Play smash sound
LK.getSound('smash').play();
@@ -225,8 +290,27 @@
duration: 150
});
}
});
+ // Score milestone bonuses
+ var currentScore = LK.getScore();
+ if (currentScore >= 100 && currentScore < 105) {
+ bonusPoints += 50;
+ LK.setScore(currentScore + 50);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ }
+ if (currentScore >= 250 && currentScore < 255) {
+ bonusPoints += 100;
+ LK.setScore(currentScore + 100);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ }
+ // Perfect hit streak bonus
+ if (perfectHits >= 5 && perfectHits % 5 === 0) {
+ var streakBonus = perfectHits * 2;
+ bonusPoints += streakBonus;
+ LK.setScore(currentScore + streakBonus);
+ scoreTxt.setText('Score: ' + LK.getScore());
+ }
// Check for win condition
if (LK.getScore() >= 500) {
LK.showYouWin();
return;