User prompt
ahora que aparezcan de lan parte de abajo de la pantalla y que después caiga ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
haz que alla mas frutas y que spawnen y caigan mas rapido
Code edit (1 edits merged)
Please save this source code
User prompt
Pineapple Slice Master
Initial prompt
haz un juego donde tengas que cortar una piña
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Pineapple = Container.expand(function () {
var self = Container.call(this);
var pineappleGraphics = self.attachAsset('pineapple', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.sliced = false;
self.lastX = 0;
self.lastY = 0;
self.update = function () {
if (!self.sliced) {
self.lastX = self.x;
self.lastY = self.y;
self.x += self.speedX;
self.y += self.speedY;
}
};
return self;
});
var PineapplePiece = Container.expand(function () {
var self = Container.call(this);
var pieceGraphics = self.attachAsset('pineapplePiece', {
anchorX: 0.5,
anchorY: 0.5
});
self.speedX = 0;
self.speedY = 0;
self.gravity = 0.5;
self.life = 60;
self.update = function () {
self.x += self.speedX;
self.y += self.speedY;
self.speedY += self.gravity;
self.rotation += 0.1;
self.life--;
if (self.life <= 0) {
tween(self, {
alpha: 0
}, {
duration: 300,
onFinish: function onFinish() {
self.toDestroy = true;
}
});
}
};
return self;
});
var SwipeLine = Container.expand(function () {
var self = Container.call(this);
var lineGraphics = self.attachAsset('swipeLine', {
anchorX: 0.5,
anchorY: 0
});
self.life = 10;
self.update = function () {
self.life--;
self.alpha = self.life / 10;
if (self.life <= 0) {
self.toDestroy = true;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Game variables
var pineapples = [];
var pineapplePieces = [];
var swipeLines = [];
var lives = 3;
var combo = 0;
var multiplier = 1;
var spawnTimer = 0;
var spawnRate = 120;
var gameSpeed = 1;
var isGameOver = false;
// Swiping variables
var isSwipeDown = false;
var lastSwipeX = 0;
var lastSwipeY = 0;
// UI
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var livesTxt = new Text2('Lives: 3', {
size: 60,
fill: 0xFF6B6B
});
livesTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(livesTxt);
var comboTxt = new Text2('', {
size: 50,
fill: 0xFFD700
});
comboTxt.anchor.set(0, 0);
LK.gui.topLeft.addChild(comboTxt);
function updateUI() {
scoreTxt.setText('Score: ' + LK.getScore());
livesTxt.setText('Lives: ' + lives);
if (combo > 1) {
comboTxt.setText('Combo x' + multiplier);
comboTxt.x = 120;
} else {
comboTxt.setText('');
}
}
function spawnPineapple() {
var pineapple = new Pineapple();
// Random spawn position from edges
var side = Math.floor(Math.random() * 4);
var speed = 3 + Math.random() * 2;
switch (side) {
case 0:
// Top
pineapple.x = Math.random() * 2048;
pineapple.y = -75;
pineapple.speedY = speed * gameSpeed;
break;
case 1:
// Right
pineapple.x = 2048 + 60;
pineapple.y = Math.random() * 2732;
pineapple.speedX = -speed * gameSpeed;
break;
case 2:
// Bottom
pineapple.x = Math.random() * 2048;
pineapple.y = 2732 + 75;
pineapple.speedY = -speed * gameSpeed;
break;
case 3:
// Left
pineapple.x = -60;
pineapple.y = Math.random() * 2732;
pineapple.speedX = speed * gameSpeed;
break;
}
pineapple.lastX = pineapple.x;
pineapple.lastY = pineapple.y;
pineapples.push(pineapple);
game.addChild(pineapple);
}
function createPineapplePieces(x, y) {
for (var i = 0; i < 4; i++) {
var piece = new PineapplePiece();
piece.x = x + (Math.random() - 0.5) * 40;
piece.y = y + (Math.random() - 0.5) * 40;
piece.speedX = (Math.random() - 0.5) * 8;
piece.speedY = (Math.random() - 0.5) * 6 - 2;
piece.rotation = Math.random() * Math.PI * 2;
pineapplePieces.push(piece);
game.addChild(piece);
}
}
function createSwipeLine(x1, y1, x2, y2) {
var distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
var steps = Math.floor(distance / 20);
for (var i = 0; i <= steps; i++) {
var t = i / steps;
var x = x1 + (x2 - x1) * t;
var y = y1 + (y2 - y1) * t;
var line = new SwipeLine();
line.x = x;
line.y = y;
line.rotation = Math.atan2(y2 - y1, x2 - x1) + Math.PI / 2;
swipeLines.push(line);
game.addChild(line);
}
}
function checkSwipeIntersection(x1, y1, x2, y2, pineapple) {
var px = pineapple.x;
var py = pineapple.y;
var radius = 60;
// Distance from point to line segment
var A = px - x1;
var B = py - y1;
var C = x2 - x1;
var D = y2 - y1;
var dot = A * C + B * D;
var lenSq = C * C + D * D;
var param = lenSq !== 0 ? dot / lenSq : -1;
var xx, yy;
if (param < 0) {
xx = x1;
yy = y1;
} else if (param > 1) {
xx = x2;
yy = y2;
} else {
xx = x1 + param * C;
yy = y1 + param * D;
}
var dx = px - xx;
var dy = py - yy;
var distance = Math.sqrt(dx * dx + dy * dy);
return distance <= radius;
}
function slicePineapple(pineapple) {
if (!pineapple.sliced) {
pineapple.sliced = true;
// Award points with combo multiplier
var points = 10 * multiplier;
LK.setScore(LK.getScore() + points);
// Increase combo
combo++;
if (combo >= 5) {
multiplier = 3;
} else if (combo >= 3) {
multiplier = 2;
} else {
multiplier = 1;
}
// Create pieces
createPineapplePieces(pineapple.x, pineapple.y);
// Play sound
LK.getSound('slice').play();
// Flash effect
LK.effects.flashObject(pineapple, 0xFFFFFF, 200);
// Mark for destruction
pineapple.toDestroy = true;
}
}
function losePineapple() {
lives--;
combo = 0;
multiplier = 1;
LK.getSound('miss').play();
LK.effects.flashScreen(0xFF0000, 300);
if (lives <= 0) {
isGameOver = true;
LK.showGameOver();
}
}
// Event handlers
game.down = function (x, y, obj) {
if (isGameOver) return;
isSwipeDown = true;
lastSwipeX = x;
lastSwipeY = y;
};
game.move = function (x, y, obj) {
if (isGameOver || !isSwipeDown) return;
var distance = Math.sqrt((x - lastSwipeX) * (x - lastSwipeX) + (y - lastSwipeY) * (y - lastSwipeY));
if (distance > 20) {
createSwipeLine(lastSwipeX, lastSwipeY, x, y);
// Check for pineapple intersections
for (var i = 0; i < pineapples.length; i++) {
var pineapple = pineapples[i];
if (!pineapple.sliced && checkSwipeIntersection(lastSwipeX, lastSwipeY, x, y, pineapple)) {
slicePineapple(pineapple);
}
}
lastSwipeX = x;
lastSwipeY = y;
}
};
game.up = function (x, y, obj) {
isSwipeDown = false;
};
// Main game loop
game.update = function () {
if (isGameOver) return;
// Spawn pineapples
spawnTimer++;
if (spawnTimer >= spawnRate) {
spawnPineapple();
spawnTimer = 0;
// Increase difficulty over time
if (spawnRate > 60) {
spawnRate -= 0.5;
}
if (gameSpeed < 2) {
gameSpeed += 0.01;
}
}
// Update and check pineapples
for (var i = pineapples.length - 1; i >= 0; i--) {
var pineapple = pineapples[i];
if (pineapple.toDestroy) {
pineapple.destroy();
pineapples.splice(i, 1);
continue;
}
// Check if pineapple went off screen
if (!pineapple.sliced && (pineapple.x < -100 || pineapple.x > 2148 || pineapple.y < -100 || pineapple.y > 2832)) {
losePineapple();
pineapple.destroy();
pineapples.splice(i, 1);
}
}
// Update and clean up pieces
for (var i = pineapplePieces.length - 1; i >= 0; i--) {
var piece = pineapplePieces[i];
if (piece.toDestroy) {
piece.destroy();
pineapplePieces.splice(i, 1);
}
}
// Update and clean up swipe lines
for (var i = swipeLines.length - 1; i >= 0; i--) {
var line = swipeLines[i];
if (line.toDestroy) {
line.destroy();
swipeLines.splice(i, 1);
}
}
updateUI();
};
// Initialize UI
updateUI(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,333 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Pineapple = Container.expand(function () {
+ var self = Container.call(this);
+ var pineappleGraphics = self.attachAsset('pineapple', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = 0;
+ self.speedY = 0;
+ self.sliced = false;
+ self.lastX = 0;
+ self.lastY = 0;
+ self.update = function () {
+ if (!self.sliced) {
+ self.lastX = self.x;
+ self.lastY = self.y;
+ self.x += self.speedX;
+ self.y += self.speedY;
+ }
+ };
+ return self;
+});
+var PineapplePiece = Container.expand(function () {
+ var self = Container.call(this);
+ var pieceGraphics = self.attachAsset('pineapplePiece', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speedX = 0;
+ self.speedY = 0;
+ self.gravity = 0.5;
+ self.life = 60;
+ self.update = function () {
+ self.x += self.speedX;
+ self.y += self.speedY;
+ self.speedY += self.gravity;
+ self.rotation += 0.1;
+ self.life--;
+ if (self.life <= 0) {
+ tween(self, {
+ alpha: 0
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.toDestroy = true;
+ }
+ });
+ }
+ };
+ return self;
+});
+var SwipeLine = Container.expand(function () {
+ var self = Container.call(this);
+ var lineGraphics = self.attachAsset('swipeLine', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ self.life = 10;
+ self.update = function () {
+ self.life--;
+ self.alpha = self.life / 10;
+ if (self.life <= 0) {
+ self.toDestroy = true;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Game variables
+var pineapples = [];
+var pineapplePieces = [];
+var swipeLines = [];
+var lives = 3;
+var combo = 0;
+var multiplier = 1;
+var spawnTimer = 0;
+var spawnRate = 120;
+var gameSpeed = 1;
+var isGameOver = false;
+// Swiping variables
+var isSwipeDown = false;
+var lastSwipeX = 0;
+var lastSwipeY = 0;
+// UI
+var scoreTxt = new Text2('Score: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var livesTxt = new Text2('Lives: 3', {
+ size: 60,
+ fill: 0xFF6B6B
+});
+livesTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(livesTxt);
+var comboTxt = new Text2('', {
+ size: 50,
+ fill: 0xFFD700
+});
+comboTxt.anchor.set(0, 0);
+LK.gui.topLeft.addChild(comboTxt);
+function updateUI() {
+ scoreTxt.setText('Score: ' + LK.getScore());
+ livesTxt.setText('Lives: ' + lives);
+ if (combo > 1) {
+ comboTxt.setText('Combo x' + multiplier);
+ comboTxt.x = 120;
+ } else {
+ comboTxt.setText('');
+ }
+}
+function spawnPineapple() {
+ var pineapple = new Pineapple();
+ // Random spawn position from edges
+ var side = Math.floor(Math.random() * 4);
+ var speed = 3 + Math.random() * 2;
+ switch (side) {
+ case 0:
+ // Top
+ pineapple.x = Math.random() * 2048;
+ pineapple.y = -75;
+ pineapple.speedY = speed * gameSpeed;
+ break;
+ case 1:
+ // Right
+ pineapple.x = 2048 + 60;
+ pineapple.y = Math.random() * 2732;
+ pineapple.speedX = -speed * gameSpeed;
+ break;
+ case 2:
+ // Bottom
+ pineapple.x = Math.random() * 2048;
+ pineapple.y = 2732 + 75;
+ pineapple.speedY = -speed * gameSpeed;
+ break;
+ case 3:
+ // Left
+ pineapple.x = -60;
+ pineapple.y = Math.random() * 2732;
+ pineapple.speedX = speed * gameSpeed;
+ break;
+ }
+ pineapple.lastX = pineapple.x;
+ pineapple.lastY = pineapple.y;
+ pineapples.push(pineapple);
+ game.addChild(pineapple);
+}
+function createPineapplePieces(x, y) {
+ for (var i = 0; i < 4; i++) {
+ var piece = new PineapplePiece();
+ piece.x = x + (Math.random() - 0.5) * 40;
+ piece.y = y + (Math.random() - 0.5) * 40;
+ piece.speedX = (Math.random() - 0.5) * 8;
+ piece.speedY = (Math.random() - 0.5) * 6 - 2;
+ piece.rotation = Math.random() * Math.PI * 2;
+ pineapplePieces.push(piece);
+ game.addChild(piece);
+ }
+}
+function createSwipeLine(x1, y1, x2, y2) {
+ var distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
+ var steps = Math.floor(distance / 20);
+ for (var i = 0; i <= steps; i++) {
+ var t = i / steps;
+ var x = x1 + (x2 - x1) * t;
+ var y = y1 + (y2 - y1) * t;
+ var line = new SwipeLine();
+ line.x = x;
+ line.y = y;
+ line.rotation = Math.atan2(y2 - y1, x2 - x1) + Math.PI / 2;
+ swipeLines.push(line);
+ game.addChild(line);
+ }
+}
+function checkSwipeIntersection(x1, y1, x2, y2, pineapple) {
+ var px = pineapple.x;
+ var py = pineapple.y;
+ var radius = 60;
+ // Distance from point to line segment
+ var A = px - x1;
+ var B = py - y1;
+ var C = x2 - x1;
+ var D = y2 - y1;
+ var dot = A * C + B * D;
+ var lenSq = C * C + D * D;
+ var param = lenSq !== 0 ? dot / lenSq : -1;
+ var xx, yy;
+ if (param < 0) {
+ xx = x1;
+ yy = y1;
+ } else if (param > 1) {
+ xx = x2;
+ yy = y2;
+ } else {
+ xx = x1 + param * C;
+ yy = y1 + param * D;
+ }
+ var dx = px - xx;
+ var dy = py - yy;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ return distance <= radius;
+}
+function slicePineapple(pineapple) {
+ if (!pineapple.sliced) {
+ pineapple.sliced = true;
+ // Award points with combo multiplier
+ var points = 10 * multiplier;
+ LK.setScore(LK.getScore() + points);
+ // Increase combo
+ combo++;
+ if (combo >= 5) {
+ multiplier = 3;
+ } else if (combo >= 3) {
+ multiplier = 2;
+ } else {
+ multiplier = 1;
+ }
+ // Create pieces
+ createPineapplePieces(pineapple.x, pineapple.y);
+ // Play sound
+ LK.getSound('slice').play();
+ // Flash effect
+ LK.effects.flashObject(pineapple, 0xFFFFFF, 200);
+ // Mark for destruction
+ pineapple.toDestroy = true;
+ }
+}
+function losePineapple() {
+ lives--;
+ combo = 0;
+ multiplier = 1;
+ LK.getSound('miss').play();
+ LK.effects.flashScreen(0xFF0000, 300);
+ if (lives <= 0) {
+ isGameOver = true;
+ LK.showGameOver();
+ }
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ if (isGameOver) return;
+ isSwipeDown = true;
+ lastSwipeX = x;
+ lastSwipeY = y;
+};
+game.move = function (x, y, obj) {
+ if (isGameOver || !isSwipeDown) return;
+ var distance = Math.sqrt((x - lastSwipeX) * (x - lastSwipeX) + (y - lastSwipeY) * (y - lastSwipeY));
+ if (distance > 20) {
+ createSwipeLine(lastSwipeX, lastSwipeY, x, y);
+ // Check for pineapple intersections
+ for (var i = 0; i < pineapples.length; i++) {
+ var pineapple = pineapples[i];
+ if (!pineapple.sliced && checkSwipeIntersection(lastSwipeX, lastSwipeY, x, y, pineapple)) {
+ slicePineapple(pineapple);
+ }
+ }
+ lastSwipeX = x;
+ lastSwipeY = y;
+ }
+};
+game.up = function (x, y, obj) {
+ isSwipeDown = false;
+};
+// Main game loop
+game.update = function () {
+ if (isGameOver) return;
+ // Spawn pineapples
+ spawnTimer++;
+ if (spawnTimer >= spawnRate) {
+ spawnPineapple();
+ spawnTimer = 0;
+ // Increase difficulty over time
+ if (spawnRate > 60) {
+ spawnRate -= 0.5;
+ }
+ if (gameSpeed < 2) {
+ gameSpeed += 0.01;
+ }
+ }
+ // Update and check pineapples
+ for (var i = pineapples.length - 1; i >= 0; i--) {
+ var pineapple = pineapples[i];
+ if (pineapple.toDestroy) {
+ pineapple.destroy();
+ pineapples.splice(i, 1);
+ continue;
+ }
+ // Check if pineapple went off screen
+ if (!pineapple.sliced && (pineapple.x < -100 || pineapple.x > 2148 || pineapple.y < -100 || pineapple.y > 2832)) {
+ losePineapple();
+ pineapple.destroy();
+ pineapples.splice(i, 1);
+ }
+ }
+ // Update and clean up pieces
+ for (var i = pineapplePieces.length - 1; i >= 0; i--) {
+ var piece = pineapplePieces[i];
+ if (piece.toDestroy) {
+ piece.destroy();
+ pineapplePieces.splice(i, 1);
+ }
+ }
+ // Update and clean up swipe lines
+ for (var i = swipeLines.length - 1; i >= 0; i--) {
+ var line = swipeLines[i];
+ if (line.toDestroy) {
+ line.destroy();
+ swipeLines.splice(i, 1);
+ }
+ }
+ updateUI();
+};
+// Initialize UI
+updateUI();
\ No newline at end of file
Naranja fruta. In-Game asset. 2d. High contrast. No shadows
Trozo de naranja fruta. In-Game asset. 2d. High contrast. No shadows
Apple. In-Game asset. 2d. High contrast. No shadows
Aple piece. In-Game asset. 2d. High contrast. No shadows
Bomba. In-Game asset. 2d. High contrast. No shadows
Cubito de hielo. In-Game asset. 2d. High contrast. No shadows
Pineaple. In-Game asset. 2d. High contrast. No shadows
Trozo piña. In-Game asset. 2d. High contrast. No shadows
Watermelon. In-Game asset. 2d. High contrast. No shadows
Una sandía individual. In-Game asset. 2d. High contrast. No shadows