Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls Gift Mystery
Initial prompt
Toca gifts (2007-2014). The powerpuff girls and their friends have 8 gifts. Tap to open them, they’ll be blossom’s scooter, buttercup’s toy spaceship, bubble’s little guitar, bliss’s toy squeaky mouse, Ken’s ball and paddle toy, Barry’s toy trumpet, Noah’s toy train, and Penny’s toy yoyo inside.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Gift = Container.expand(function (toyType, toyName) { var self = Container.call(this); self.toyType = toyType; self.toyName = toyName; self.isOpened = false; // Gift box var giftBox = self.attachAsset('giftBox', { anchorX: 0.5, anchorY: 0.5 }); // Horizontal ribbon var ribbonH = self.attachAsset('giftRibbon', { anchorX: 0.5, anchorY: 0.5 }); // Vertical ribbon var ribbonV = self.attachAsset('giftRibbon', { anchorX: 0.5, anchorY: 0.5, rotation: Math.PI / 2 }); // Bow on top var bow = self.attachAsset('giftBow', { anchorX: 0.5, anchorY: 0.5, y: -80 }); // Toy (hidden initially) var toy = self.attachAsset(toyType, { anchorX: 0.5, anchorY: 0.5, alpha: 0, scaleX: 0.1, scaleY: 0.1 }); self.openGift = function () { if (self.isOpened) return; self.isOpened = true; // Play unwrap sound LK.getSound('unwrap').play(); // Hide gift wrapping with animation tween(giftBox, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300 }); tween(ribbonH, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300 }); tween(ribbonV, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300 }); tween(bow, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300 }); // Show toy with animation tween(toy, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.bounceOut, onFinish: function onFinish() { showToyPopup(self.toyName); openedGifts++; if (openedGifts >= 8) { LK.setTimeout(function () { celebrateCompletion(); }, 1500); } } }); }; self.down = function (x, y, obj) { self.openGift(); }; return self; }); var ToyPopup = Container.expand(function (toyName) { var self = Container.call(this); // Background var background = self.attachAsset('popupBackground', { anchorX: 0.5, anchorY: 0.5, alpha: 0.9 }); // Toy name text var nameText = new Text2(toyName, { size: 60, fill: 0x333333 }); nameText.anchor.set(0.5, 0.5); self.addChild(nameText); // Position popup in center self.x = 1024; self.y = 1366; // Initial scale self.scaleX = 0.1; self.scaleY = 0.1; // Animate popup appearance tween(self, { scaleX: 1, scaleY: 1 }, { duration: 400, easing: tween.bounceOut, onFinish: function onFinish() { LK.setTimeout(function () { tween(self, { alpha: 0, scaleX: 0.8, scaleY: 0.8 }, { duration: 300, onFinish: function onFinish() { self.destroy(); } }); }, 1200); } }); return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var gifts = []; var openedGifts = 0; var currentPopup = null; var toyData = [{ type: 'scooter', name: "Blossom's Scooter" }, { type: 'spaceship', name: "Buttercup's Spaceship" }, { type: 'guitar', name: "Bubbles' Guitar" }, { type: 'squeakyMouse', name: "Bliss's Squeaky Mouse" }, { type: 'ballAndPaddle', name: "Ken's Ball and Paddle" }, { type: 'trumpet', name: "Barry's Trumpet" }, { type: 'train', name: "Noah's Train" }, { type: 'yoyo', name: "Penny's Yoyo" }]; function showToyPopup(toyName) { if (currentPopup) { currentPopup.destroy(); } currentPopup = new ToyPopup(toyName); game.addChild(currentPopup); } function celebrateCompletion() { LK.getSound('celebrate').play(); // Flash screen with celebration colors LK.effects.flashScreen(0xffd700, 1000); // Reset game after celebration LK.setTimeout(function () { resetGame(); }, 2000); } function resetGame() { // Clear existing gifts for (var i = 0; i < gifts.length; i++) { gifts[i].destroy(); } gifts = []; openedGifts = 0; if (currentPopup) { currentPopup.destroy(); currentPopup = null; } // Create new gifts createGifts(); } function createGifts() { var positions = []; var margin = 150; var gridCols = 4; var gridRows = 2; var startX = margin; var startY = margin + 200; var spacingX = (2048 - 2 * margin) / (gridCols - 1); var spacingY = (2732 - 2 * margin - 400) / (gridRows - 1); // Generate grid positions for (var row = 0; row < gridRows; row++) { for (var col = 0; col < gridCols; col++) { positions.push({ x: startX + col * spacingX, y: startY + row * spacingY }); } } // Shuffle positions for (var i = positions.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = positions[i]; positions[i] = positions[j]; positions[j] = temp; } // Create gifts with shuffled toys var shuffledToys = toyData.slice(); for (var i = shuffledToys.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = shuffledToys[i]; shuffledToys[i] = shuffledToys[j]; shuffledToys[j] = temp; } for (var i = 0; i < 8; i++) { var gift = new Gift(shuffledToys[i].type, shuffledToys[i].name); gift.x = positions[i].x; gift.y = positions[i].y; gifts.push(gift); game.addChild(gift); } } // Initialize the game createGifts(); // Title text var titleText = new Text2('Powerpuff Girls Gift Mystery', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0); titleText.x = 1024; titleText.y = 50; game.addChild(titleText); // Instructions text var instructionText = new Text2('Tap the gifts to unwrap them!', { size: 50, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.x = 1024; instructionText.y = 150; game.addChild(instructionText);
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,276 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Gift = Container.expand(function (toyType, toyName) {
+ var self = Container.call(this);
+ self.toyType = toyType;
+ self.toyName = toyName;
+ self.isOpened = false;
+ // Gift box
+ var giftBox = self.attachAsset('giftBox', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Horizontal ribbon
+ var ribbonH = self.attachAsset('giftRibbon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Vertical ribbon
+ var ribbonV = self.attachAsset('giftRibbon', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / 2
+ });
+ // Bow on top
+ var bow = self.attachAsset('giftBow', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -80
+ });
+ // Toy (hidden initially)
+ var toy = self.attachAsset(toyType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0,
+ scaleX: 0.1,
+ scaleY: 0.1
+ });
+ self.openGift = function () {
+ if (self.isOpened) return;
+ self.isOpened = true;
+ // Play unwrap sound
+ LK.getSound('unwrap').play();
+ // Hide gift wrapping with animation
+ tween(giftBox, {
+ alpha: 0,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }, {
+ duration: 300
+ });
+ tween(ribbonH, {
+ alpha: 0,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }, {
+ duration: 300
+ });
+ tween(ribbonV, {
+ alpha: 0,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }, {
+ duration: 300
+ });
+ tween(bow, {
+ alpha: 0,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }, {
+ duration: 300
+ });
+ // Show toy with animation
+ tween(toy, {
+ alpha: 1,
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 500,
+ easing: tween.bounceOut,
+ onFinish: function onFinish() {
+ showToyPopup(self.toyName);
+ openedGifts++;
+ if (openedGifts >= 8) {
+ LK.setTimeout(function () {
+ celebrateCompletion();
+ }, 1500);
+ }
+ }
+ });
+ };
+ self.down = function (x, y, obj) {
+ self.openGift();
+ };
+ return self;
+});
+var ToyPopup = Container.expand(function (toyName) {
+ var self = Container.call(this);
+ // Background
+ var background = self.attachAsset('popupBackground', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0.9
+ });
+ // Toy name text
+ var nameText = new Text2(toyName, {
+ size: 60,
+ fill: 0x333333
+ });
+ nameText.anchor.set(0.5, 0.5);
+ self.addChild(nameText);
+ // Position popup in center
+ self.x = 1024;
+ self.y = 1366;
+ // Initial scale
+ self.scaleX = 0.1;
+ self.scaleY = 0.1;
+ // Animate popup appearance
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 400,
+ easing: tween.bounceOut,
+ onFinish: function onFinish() {
+ LK.setTimeout(function () {
+ tween(self, {
+ alpha: 0,
+ scaleX: 0.8,
+ scaleY: 0.8
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ }, 1200);
+ }
+ });
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87ceeb
+});
+
+/****
+* Game Code
+****/
+var gifts = [];
+var openedGifts = 0;
+var currentPopup = null;
+var toyData = [{
+ type: 'scooter',
+ name: "Blossom's Scooter"
+}, {
+ type: 'spaceship',
+ name: "Buttercup's Spaceship"
+}, {
+ type: 'guitar',
+ name: "Bubbles' Guitar"
+}, {
+ type: 'squeakyMouse',
+ name: "Bliss's Squeaky Mouse"
+}, {
+ type: 'ballAndPaddle',
+ name: "Ken's Ball and Paddle"
+}, {
+ type: 'trumpet',
+ name: "Barry's Trumpet"
+}, {
+ type: 'train',
+ name: "Noah's Train"
+}, {
+ type: 'yoyo',
+ name: "Penny's Yoyo"
+}];
+function showToyPopup(toyName) {
+ if (currentPopup) {
+ currentPopup.destroy();
+ }
+ currentPopup = new ToyPopup(toyName);
+ game.addChild(currentPopup);
+}
+function celebrateCompletion() {
+ LK.getSound('celebrate').play();
+ // Flash screen with celebration colors
+ LK.effects.flashScreen(0xffd700, 1000);
+ // Reset game after celebration
+ LK.setTimeout(function () {
+ resetGame();
+ }, 2000);
+}
+function resetGame() {
+ // Clear existing gifts
+ for (var i = 0; i < gifts.length; i++) {
+ gifts[i].destroy();
+ }
+ gifts = [];
+ openedGifts = 0;
+ if (currentPopup) {
+ currentPopup.destroy();
+ currentPopup = null;
+ }
+ // Create new gifts
+ createGifts();
+}
+function createGifts() {
+ var positions = [];
+ var margin = 150;
+ var gridCols = 4;
+ var gridRows = 2;
+ var startX = margin;
+ var startY = margin + 200;
+ var spacingX = (2048 - 2 * margin) / (gridCols - 1);
+ var spacingY = (2732 - 2 * margin - 400) / (gridRows - 1);
+ // Generate grid positions
+ for (var row = 0; row < gridRows; row++) {
+ for (var col = 0; col < gridCols; col++) {
+ positions.push({
+ x: startX + col * spacingX,
+ y: startY + row * spacingY
+ });
+ }
+ }
+ // Shuffle positions
+ for (var i = positions.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = positions[i];
+ positions[i] = positions[j];
+ positions[j] = temp;
+ }
+ // Create gifts with shuffled toys
+ var shuffledToys = toyData.slice();
+ for (var i = shuffledToys.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = shuffledToys[i];
+ shuffledToys[i] = shuffledToys[j];
+ shuffledToys[j] = temp;
+ }
+ for (var i = 0; i < 8; i++) {
+ var gift = new Gift(shuffledToys[i].type, shuffledToys[i].name);
+ gift.x = positions[i].x;
+ gift.y = positions[i].y;
+ gifts.push(gift);
+ game.addChild(gift);
+ }
+}
+// Initialize the game
+createGifts();
+// Title text
+var titleText = new Text2('Powerpuff Girls Gift Mystery', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+titleText.x = 1024;
+titleText.y = 50;
+game.addChild(titleText);
+// Instructions text
+var instructionText = new Text2('Tap the gifts to unwrap them!', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.x = 1024;
+instructionText.y = 150;
+game.addChild(instructionText);
\ No newline at end of file