Code edit (1 edits merged)
Please save this source code
User prompt
Piñata Party Pop
Initial prompt
Toca piñata (2015). The powerpuff girls are having a party outside. Tap to choose the strawberry piñata or the horse piñata to get started. Swipe or tap on your piñata 10 times to make treats fall out. (Not to collect). When you’re finished playing with the cakes tap the green button, and what every party needs is.. magic jelly! Jelly flood!!!!! When you’re finished playing in the jelly tap the green button.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var JellyBlob = Container.expand(function () { var self = Container.call(this); var jellyGraphics = self.attachAsset('jellyBlob', { anchorX: 0.5, anchorY: 0.5 }); // Random color tint var colors = [0xff0066, 0x00ff66, 0x6600ff, 0xffff00, 0x00ffff, 0xff6600]; jellyGraphics.tint = colors[Math.floor(Math.random() * colors.length)]; self.velocityX = (Math.random() - 0.5) * 12; self.velocityY = Math.random() * -8 - 5; self.gravity = 0.4; self.bounce = 0.8; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Bounce off bottom if (self.y > 2732 - 30) { self.y = 2732 - 30; self.velocityY *= -self.bounce; LK.getSound('jellyPop').play(); } // Bounce off sides if (self.x < 30 || self.x > 2048 - 30) { self.velocityX *= -1; self.x = Math.max(30, Math.min(2048 - 30, self.x)); } // Bounce off top if (self.y < 30) { self.y = 30; self.velocityY *= -self.bounce; } // Slow down over time self.velocityX *= 0.995; }; return self; }); var NextButton = Container.expand(function () { var self = Container.call(this); var buttonGraphics = self.attachAsset('nextButton', { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { if (gameState === 'breaking') { startJellyFlood(); } else if (gameState === 'jelly') { resetGame(); } }; return self; }); var Pinata = Container.expand(function (type) { var self = Container.call(this); self.type = type; self.hits = 0; self.maxHits = 10; self.broken = false; var pinataGraphics; if (type === 'strawberry') { pinataGraphics = self.attachAsset('strawberryPinata', { anchorX: 0.5, anchorY: 0.5 }); } else { pinataGraphics = self.attachAsset('horsePinata', { anchorX: 0.5, anchorY: 0.5 }); } self.hit = function () { if (self.broken) return; self.hits++; LK.getSound('hitSound').play(); // Shake animation tween(pinataGraphics, { rotation: 0.2 }, { duration: 100, onFinish: function onFinish() { tween(pinataGraphics, { rotation: -0.2 }, { duration: 100, onFinish: function onFinish() { tween(pinataGraphics, { rotation: 0 }, { duration: 100 }); } }); } }); // Create treats self.createTreats(); if (self.hits >= self.maxHits) { self.broken = true; self.breakPinata(); } }; self.createTreats = function () { var treatCount = Math.floor(Math.random() * 3) + 2; for (var i = 0; i < treatCount; i++) { var treat = new Treat(); treat.x = self.x + (Math.random() - 0.5) * 100; treat.y = self.y + 50; treats.push(treat); game.addChild(treat); } }; self.breakPinata = function () { tween(pinataGraphics, { alpha: 0.3, scaleX: 1.2, scaleY: 1.2 }, { duration: 500 }); // Create final burst of treats for (var i = 0; i < 8; i++) { var treat = new Treat(); treat.x = self.x + (Math.random() - 0.5) * 200; treat.y = self.y + (Math.random() - 0.5) * 100; treats.push(treat); game.addChild(treat); } showNextButton = true; }; self.down = function (x, y, obj) { self.hit(); }; return self; }); var Treat = Container.expand(function () { var self = Container.call(this); var treatTypes = ['treat1', 'treat2', 'treat3', 'treat4']; var randomType = treatTypes[Math.floor(Math.random() * treatTypes.length)]; var treatGraphics = self.attachAsset(randomType, { anchorX: 0.5, anchorY: 0.5 }); self.velocityX = (Math.random() - 0.5) * 10; self.velocityY = Math.random() * -5 - 3; self.gravity = 0.3; self.bounce = 0.7; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; // Bounce off bottom if (self.y > 2732 - 20) { self.y = 2732 - 20; self.velocityY *= -self.bounce; } // Bounce off sides if (self.x < 20 || self.x > 2048 - 20) { self.velocityX *= -1; self.x = Math.max(20, Math.min(2048 - 20, self.x)); } // Slow down over time self.velocityX *= 0.99; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var gameState = 'selection'; // 'selection', 'breaking', 'jelly' var currentPinata = null; var treats = []; var jellyBlobs = []; var showNextButton = false; var nextButton = null; // UI Text var titleText = new Text2('Choose Your Piñata!', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); LK.gui.top.addChild(titleText); var instructionText = new Text2('Tap 10 times to break it open!', { size: 60, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.y = 100; LK.gui.top.addChild(instructionText); var hitCounter = new Text2('0/10', { size: 100, fill: 0xFFFF00 }); hitCounter.anchor.set(0.5, 0); hitCounter.y = 200; LK.gui.top.addChild(hitCounter); // Create piñata selection var strawberryPinata = new Pinata('strawberry'); strawberryPinata.x = 2048 / 2 - 200; strawberryPinata.y = 2732 / 2; var horsePinata = new Pinata('horse'); horsePinata.x = 2048 / 2 + 200; horsePinata.y = 2732 / 2; game.addChild(strawberryPinata); game.addChild(horsePinata); // Selection labels var strawberryLabel = new Text2('Strawberry', { size: 50, fill: 0xFFFFFF }); strawberryLabel.anchor.set(0.5, 0); strawberryLabel.x = strawberryPinata.x; strawberryLabel.y = strawberryPinata.y + 250; game.addChild(strawberryLabel); var horseLabel = new Text2('Horse', { size: 50, fill: 0xFFFFFF }); horseLabel.anchor.set(0.5, 0); horseLabel.x = horsePinata.x; horseLabel.y = horsePinata.y + 200; game.addChild(horseLabel); function selectPinata(type) { gameState = 'breaking'; // Hide selection piñatas strawberryPinata.visible = false; horsePinata.visible = false; strawberryLabel.visible = false; horseLabel.visible = false; // Create selected piñata currentPinata = new Pinata(type); currentPinata.x = 2048 / 2; currentPinata.y = 800; game.addChild(currentPinata); titleText.setText('Break the Piñata!'); instructionText.visible = true; hitCounter.visible = true; } function startJellyFlood() { gameState = 'jelly'; titleText.setText('Jelly Flood!'); instructionText.setText('Watch the magical jelly rain!'); hitCounter.visible = false; if (nextButton) { nextButton.visible = false; } // Create jelly flood var jellyTimer = LK.setInterval(function () { if (jellyBlobs.length < 30) { var jelly = new JellyBlob(); jelly.x = Math.random() * 2048; jelly.y = -50; jellyBlobs.push(jelly); game.addChild(jelly); } }, 200); // Show next button after 3 seconds LK.setTimeout(function () { LK.clearInterval(jellyTimer); if (!nextButton) { nextButton = new NextButton(); } nextButton.x = 2048 / 2; nextButton.y = 2732 - 150; nextButton.visible = true; game.addChild(nextButton); var nextButtonText = new Text2('Play Again', { size: 40, fill: 0x000000 }); nextButtonText.anchor.set(0.5, 0.5); nextButtonText.x = nextButton.x; nextButtonText.y = nextButton.y; game.addChild(nextButtonText); }, 3000); } function resetGame() { gameState = 'selection'; // Clear treats and jelly for (var i = treats.length - 1; i >= 0; i--) { treats[i].destroy(); treats.splice(i, 1); } for (var j = jellyBlobs.length - 1; j >= 0; j--) { jellyBlobs[j].destroy(); jellyBlobs.splice(j, 1); } // Reset piñata if (currentPinata) { currentPinata.destroy(); currentPinata = null; } // Show selection piñatas strawberryPinata.visible = true; horsePinata.visible = true; strawberryLabel.visible = true; horseLabel.visible = true; // Reset piñata states strawberryPinata.hits = 0; strawberryPinata.broken = false; horsePinata.hits = 0; horsePinata.broken = false; // Reset UI titleText.setText('Choose Your Piñata!'); instructionText.setText('Tap 10 times to break it open!'); instructionText.visible = false; hitCounter.visible = false; showNextButton = false; if (nextButton) { nextButton.visible = false; } } // Handle piñata selection strawberryPinata.down = function (x, y, obj) { if (gameState === 'selection') { selectPinata('strawberry'); } else if (gameState === 'breaking') { currentPinata.hit(); } }; horsePinata.down = function (x, y, obj) { if (gameState === 'selection') { selectPinata('horse'); } else if (gameState === 'breaking') { currentPinata.hit(); } }; game.update = function () { // Update treats for (var i = treats.length - 1; i >= 0; i--) { var treat = treats[i]; // Treats naturally slow down and settle } // Update jelly blobs for (var j = jellyBlobs.length - 1; j >= 0; j--) { var jelly = jellyBlobs[j]; // Jelly blobs bounce around } // Update hit counter if (gameState === 'breaking' && currentPinata) { hitCounter.setText(currentPinata.hits + '/10'); // Show next button when piñata is broken if (currentPinata.broken && showNextButton && !nextButton) { nextButton = new NextButton(); nextButton.x = 2048 / 2; nextButton.y = 2732 - 150; game.addChild(nextButton); var nextButtonText = new Text2('Jelly Flood!', { size: 40, fill: 0x000000 }); nextButtonText.anchor.set(0.5, 0.5); nextButtonText.x = nextButton.x; nextButtonText.y = nextButton.y; game.addChild(nextButtonText); } } }; // Initialize with selection screen instructionText.visible = false; hitCounter.visible = false;
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,377 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var JellyBlob = Container.expand(function () {
+ var self = Container.call(this);
+ var jellyGraphics = self.attachAsset('jellyBlob', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Random color tint
+ var colors = [0xff0066, 0x00ff66, 0x6600ff, 0xffff00, 0x00ffff, 0xff6600];
+ jellyGraphics.tint = colors[Math.floor(Math.random() * colors.length)];
+ self.velocityX = (Math.random() - 0.5) * 12;
+ self.velocityY = Math.random() * -8 - 5;
+ self.gravity = 0.4;
+ self.bounce = 0.8;
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityY += self.gravity;
+ // Bounce off bottom
+ if (self.y > 2732 - 30) {
+ self.y = 2732 - 30;
+ self.velocityY *= -self.bounce;
+ LK.getSound('jellyPop').play();
+ }
+ // Bounce off sides
+ if (self.x < 30 || self.x > 2048 - 30) {
+ self.velocityX *= -1;
+ self.x = Math.max(30, Math.min(2048 - 30, self.x));
+ }
+ // Bounce off top
+ if (self.y < 30) {
+ self.y = 30;
+ self.velocityY *= -self.bounce;
+ }
+ // Slow down over time
+ self.velocityX *= 0.995;
+ };
+ return self;
+});
+var NextButton = Container.expand(function () {
+ var self = Container.call(this);
+ var buttonGraphics = self.attachAsset('nextButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.down = function (x, y, obj) {
+ if (gameState === 'breaking') {
+ startJellyFlood();
+ } else if (gameState === 'jelly') {
+ resetGame();
+ }
+ };
+ return self;
+});
+var Pinata = Container.expand(function (type) {
+ var self = Container.call(this);
+ self.type = type;
+ self.hits = 0;
+ self.maxHits = 10;
+ self.broken = false;
+ var pinataGraphics;
+ if (type === 'strawberry') {
+ pinataGraphics = self.attachAsset('strawberryPinata', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ } else {
+ pinataGraphics = self.attachAsset('horsePinata', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ }
+ self.hit = function () {
+ if (self.broken) return;
+ self.hits++;
+ LK.getSound('hitSound').play();
+ // Shake animation
+ tween(pinataGraphics, {
+ rotation: 0.2
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(pinataGraphics, {
+ rotation: -0.2
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(pinataGraphics, {
+ rotation: 0
+ }, {
+ duration: 100
+ });
+ }
+ });
+ }
+ });
+ // Create treats
+ self.createTreats();
+ if (self.hits >= self.maxHits) {
+ self.broken = true;
+ self.breakPinata();
+ }
+ };
+ self.createTreats = function () {
+ var treatCount = Math.floor(Math.random() * 3) + 2;
+ for (var i = 0; i < treatCount; i++) {
+ var treat = new Treat();
+ treat.x = self.x + (Math.random() - 0.5) * 100;
+ treat.y = self.y + 50;
+ treats.push(treat);
+ game.addChild(treat);
+ }
+ };
+ self.breakPinata = function () {
+ tween(pinataGraphics, {
+ alpha: 0.3,
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 500
+ });
+ // Create final burst of treats
+ for (var i = 0; i < 8; i++) {
+ var treat = new Treat();
+ treat.x = self.x + (Math.random() - 0.5) * 200;
+ treat.y = self.y + (Math.random() - 0.5) * 100;
+ treats.push(treat);
+ game.addChild(treat);
+ }
+ showNextButton = true;
+ };
+ self.down = function (x, y, obj) {
+ self.hit();
+ };
+ return self;
+});
+var Treat = Container.expand(function () {
+ var self = Container.call(this);
+ var treatTypes = ['treat1', 'treat2', 'treat3', 'treat4'];
+ var randomType = treatTypes[Math.floor(Math.random() * treatTypes.length)];
+ var treatGraphics = self.attachAsset(randomType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocityX = (Math.random() - 0.5) * 10;
+ self.velocityY = Math.random() * -5 - 3;
+ self.gravity = 0.3;
+ self.bounce = 0.7;
+ self.update = function () {
+ self.x += self.velocityX;
+ self.y += self.velocityY;
+ self.velocityY += self.gravity;
+ // Bounce off bottom
+ if (self.y > 2732 - 20) {
+ self.y = 2732 - 20;
+ self.velocityY *= -self.bounce;
+ }
+ // Bounce off sides
+ if (self.x < 20 || self.x > 2048 - 20) {
+ self.velocityX *= -1;
+ self.x = Math.max(20, Math.min(2048 - 20, self.x));
+ }
+ // Slow down over time
+ self.velocityX *= 0.99;
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+var gameState = 'selection'; // 'selection', 'breaking', 'jelly'
+var currentPinata = null;
+var treats = [];
+var jellyBlobs = [];
+var showNextButton = false;
+var nextButton = null;
+// UI Text
+var titleText = new Text2('Choose Your Piñata!', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+var instructionText = new Text2('Tap 10 times to break it open!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.y = 100;
+LK.gui.top.addChild(instructionText);
+var hitCounter = new Text2('0/10', {
+ size: 100,
+ fill: 0xFFFF00
+});
+hitCounter.anchor.set(0.5, 0);
+hitCounter.y = 200;
+LK.gui.top.addChild(hitCounter);
+// Create piñata selection
+var strawberryPinata = new Pinata('strawberry');
+strawberryPinata.x = 2048 / 2 - 200;
+strawberryPinata.y = 2732 / 2;
+var horsePinata = new Pinata('horse');
+horsePinata.x = 2048 / 2 + 200;
+horsePinata.y = 2732 / 2;
+game.addChild(strawberryPinata);
+game.addChild(horsePinata);
+// Selection labels
+var strawberryLabel = new Text2('Strawberry', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+strawberryLabel.anchor.set(0.5, 0);
+strawberryLabel.x = strawberryPinata.x;
+strawberryLabel.y = strawberryPinata.y + 250;
+game.addChild(strawberryLabel);
+var horseLabel = new Text2('Horse', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+horseLabel.anchor.set(0.5, 0);
+horseLabel.x = horsePinata.x;
+horseLabel.y = horsePinata.y + 200;
+game.addChild(horseLabel);
+function selectPinata(type) {
+ gameState = 'breaking';
+ // Hide selection piñatas
+ strawberryPinata.visible = false;
+ horsePinata.visible = false;
+ strawberryLabel.visible = false;
+ horseLabel.visible = false;
+ // Create selected piñata
+ currentPinata = new Pinata(type);
+ currentPinata.x = 2048 / 2;
+ currentPinata.y = 800;
+ game.addChild(currentPinata);
+ titleText.setText('Break the Piñata!');
+ instructionText.visible = true;
+ hitCounter.visible = true;
+}
+function startJellyFlood() {
+ gameState = 'jelly';
+ titleText.setText('Jelly Flood!');
+ instructionText.setText('Watch the magical jelly rain!');
+ hitCounter.visible = false;
+ if (nextButton) {
+ nextButton.visible = false;
+ }
+ // Create jelly flood
+ var jellyTimer = LK.setInterval(function () {
+ if (jellyBlobs.length < 30) {
+ var jelly = new JellyBlob();
+ jelly.x = Math.random() * 2048;
+ jelly.y = -50;
+ jellyBlobs.push(jelly);
+ game.addChild(jelly);
+ }
+ }, 200);
+ // Show next button after 3 seconds
+ LK.setTimeout(function () {
+ LK.clearInterval(jellyTimer);
+ if (!nextButton) {
+ nextButton = new NextButton();
+ }
+ nextButton.x = 2048 / 2;
+ nextButton.y = 2732 - 150;
+ nextButton.visible = true;
+ game.addChild(nextButton);
+ var nextButtonText = new Text2('Play Again', {
+ size: 40,
+ fill: 0x000000
+ });
+ nextButtonText.anchor.set(0.5, 0.5);
+ nextButtonText.x = nextButton.x;
+ nextButtonText.y = nextButton.y;
+ game.addChild(nextButtonText);
+ }, 3000);
+}
+function resetGame() {
+ gameState = 'selection';
+ // Clear treats and jelly
+ for (var i = treats.length - 1; i >= 0; i--) {
+ treats[i].destroy();
+ treats.splice(i, 1);
+ }
+ for (var j = jellyBlobs.length - 1; j >= 0; j--) {
+ jellyBlobs[j].destroy();
+ jellyBlobs.splice(j, 1);
+ }
+ // Reset piñata
+ if (currentPinata) {
+ currentPinata.destroy();
+ currentPinata = null;
+ }
+ // Show selection piñatas
+ strawberryPinata.visible = true;
+ horsePinata.visible = true;
+ strawberryLabel.visible = true;
+ horseLabel.visible = true;
+ // Reset piñata states
+ strawberryPinata.hits = 0;
+ strawberryPinata.broken = false;
+ horsePinata.hits = 0;
+ horsePinata.broken = false;
+ // Reset UI
+ titleText.setText('Choose Your Piñata!');
+ instructionText.setText('Tap 10 times to break it open!');
+ instructionText.visible = false;
+ hitCounter.visible = false;
+ showNextButton = false;
+ if (nextButton) {
+ nextButton.visible = false;
+ }
+}
+// Handle piñata selection
+strawberryPinata.down = function (x, y, obj) {
+ if (gameState === 'selection') {
+ selectPinata('strawberry');
+ } else if (gameState === 'breaking') {
+ currentPinata.hit();
+ }
+};
+horsePinata.down = function (x, y, obj) {
+ if (gameState === 'selection') {
+ selectPinata('horse');
+ } else if (gameState === 'breaking') {
+ currentPinata.hit();
+ }
+};
+game.update = function () {
+ // Update treats
+ for (var i = treats.length - 1; i >= 0; i--) {
+ var treat = treats[i];
+ // Treats naturally slow down and settle
+ }
+ // Update jelly blobs
+ for (var j = jellyBlobs.length - 1; j >= 0; j--) {
+ var jelly = jellyBlobs[j];
+ // Jelly blobs bounce around
+ }
+ // Update hit counter
+ if (gameState === 'breaking' && currentPinata) {
+ hitCounter.setText(currentPinata.hits + '/10');
+ // Show next button when piñata is broken
+ if (currentPinata.broken && showNextButton && !nextButton) {
+ nextButton = new NextButton();
+ nextButton.x = 2048 / 2;
+ nextButton.y = 2732 - 150;
+ game.addChild(nextButton);
+ var nextButtonText = new Text2('Jelly Flood!', {
+ size: 40,
+ fill: 0x000000
+ });
+ nextButtonText.anchor.set(0.5, 0.5);
+ nextButtonText.x = nextButton.x;
+ nextButtonText.y = nextButton.y;
+ game.addChild(nextButtonText);
+ }
+ }
+};
+// Initialize with selection screen
+instructionText.visible = false;
+hitCounter.visible = false;
\ No newline at end of file