Code edit (1 edits merged)
Please save this source code
User prompt
Surprise Egg Toys - Powerpuff Girls Edition
Initial prompt
Toca playing toys (2005). The powerpuff girls have 6 surprise eggs. Tap on a surprise egg to shake and then tap it to open. It will be a toy Violet cat, or toy frog, or toy monkey, or party blower, or jelly, or radio inside.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var SurpriseEgg = Container.expand(function (eggType, toyType) {
var self = Container.call(this);
self.eggType = eggType;
self.toyType = toyType;
self.state = 'closed'; // closed, shaking, cracked, opened
self.shakeCount = 0;
self.maxShakes = 3;
// Create egg graphics
var eggGraphics = self.attachAsset('egg' + eggType, {
anchorX: 0.5,
anchorY: 0.5
});
// Create toy (hidden initially)
var toyAssets = ['cat', 'frog', 'monkey', 'blower', 'jelly', 'radio'];
var toyGraphics = self.attachAsset(toyAssets[toyType], {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Create cracked egg pieces (hidden initially)
var eggTop = self.attachAsset('eggTop', {
anchorX: 0.5,
anchorY: 1.0,
alpha: 0,
tint: eggGraphics.tint
});
var eggBottom = self.attachAsset('eggBottom', {
anchorX: 0.5,
anchorY: 0.0,
alpha: 0,
tint: eggGraphics.tint
});
self.shake = function () {
if (self.state !== 'closed') return;
self.state = 'shaking';
self.shakeCount++;
LK.getSound('shake').play();
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX - 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX + 15
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX - 10
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX + 10
}, {
duration: 50,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 50,
onFinish: function onFinish() {
if (self.shakeCount >= self.maxShakes) {
self.state = 'ready_to_crack';
} else {
self.state = 'closed';
}
}
});
}
});
}
});
}
});
}
});
};
self.crack = function () {
if (self.state !== 'ready_to_crack') return;
self.state = 'cracked';
LK.getSound('crack').play();
// Hide original egg
eggGraphics.alpha = 0;
// Show cracked pieces
eggTop.alpha = 1;
eggBottom.alpha = 1;
// Animate cracked pieces
tween(eggTop, {
y: eggTop.y - 100,
rotation: -0.3
}, {
duration: 500
});
tween(eggBottom, {
y: eggBottom.y + 100,
rotation: 0.3
}, {
duration: 500
});
// Reveal toy
setTimeout(function () {
LK.getSound('reveal').play();
toyGraphics.alpha = 1;
tween(toyGraphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(toyGraphics, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200
});
}
});
self.state = 'opened';
}, 300);
};
self.down = function (x, y, obj) {
if (self.state === 'closed' || self.state === 'ready_to_crack') {
if (self.state === 'closed') {
self.shake();
} else if (self.state === 'ready_to_crack') {
self.crack();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFB6C1
});
/****
* Game Code
****/
var eggs = [];
var toys = [0, 1, 2, 3, 4, 5]; // Will be shuffled
var eggsOpened = 0;
// Shuffle toys array
function shuffleArray(array) {
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
shuffleArray(toys);
// Create title text
var titleText = new Text2('Powerpuff Girls Surprise Eggs', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
// Create instruction text
var instructionText = new Text2('Tap eggs to shake, then tap again to open!', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
game.addChild(instructionText);
instructionText.x = 2048 / 2;
instructionText.y = 300;
// Create eggs in 2x3 grid
var startX = 2048 / 2 - 450;
var startY = 800;
var spacingX = 300;
var spacingY = 350;
for (var i = 0; i < 6; i++) {
var row = Math.floor(i / 3);
var col = i % 3;
var egg = new SurpriseEgg(i + 1, toys[i]);
egg.x = startX + col * spacingX;
egg.y = startY + row * spacingY;
eggs.push(egg);
game.addChild(egg);
}
// Create restart button (hidden initially)
var restartText = new Text2('Tap to Play Again!', {
size: 60,
fill: 0xFFFFFF
});
restartText.anchor.set(0.5, 0.5);
restartText.alpha = 0;
game.addChild(restartText);
restartText.x = 2048 / 2;
restartText.y = 2400;
game.update = function () {
// Check if all eggs are opened
var openedCount = 0;
for (var i = 0; i < eggs.length; i++) {
if (eggs[i].state === 'opened') {
openedCount++;
}
}
// Show restart option when all eggs are opened
if (openedCount === 6 && restartText.alpha === 0) {
tween(restartText, {
alpha: 1
}, {
duration: 500
});
// Make restart text clickable
restartText.down = function (x, y, obj) {
// Reset game
eggsOpened = 0;
shuffleArray(toys);
// Remove all eggs
for (var i = 0; i < eggs.length; i++) {
eggs[i].destroy();
}
eggs = [];
// Recreate eggs
for (var i = 0; i < 6; i++) {
var row = Math.floor(i / 3);
var col = i % 3;
var egg = new SurpriseEgg(i + 1, toys[i]);
egg.x = startX + col * spacingX;
egg.y = startY + row * spacingY;
eggs.push(egg);
game.addChild(egg);
}
// Hide restart text
restartText.alpha = 0;
};
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,248 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var SurpriseEgg = Container.expand(function (eggType, toyType) {
+ var self = Container.call(this);
+ self.eggType = eggType;
+ self.toyType = toyType;
+ self.state = 'closed'; // closed, shaking, cracked, opened
+ self.shakeCount = 0;
+ self.maxShakes = 3;
+ // Create egg graphics
+ var eggGraphics = self.attachAsset('egg' + eggType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create toy (hidden initially)
+ var toyAssets = ['cat', 'frog', 'monkey', 'blower', 'jelly', 'radio'];
+ var toyGraphics = self.attachAsset(toyAssets[toyType], {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ // Create cracked egg pieces (hidden initially)
+ var eggTop = self.attachAsset('eggTop', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ alpha: 0,
+ tint: eggGraphics.tint
+ });
+ var eggBottom = self.attachAsset('eggBottom', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ alpha: 0,
+ tint: eggGraphics.tint
+ });
+ self.shake = function () {
+ if (self.state !== 'closed') return;
+ self.state = 'shaking';
+ self.shakeCount++;
+ LK.getSound('shake').play();
+ // Shake animation
+ var originalX = self.x;
+ tween(self, {
+ x: originalX - 15
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX + 15
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX - 10
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX + 10
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX
+ }, {
+ duration: 50,
+ onFinish: function onFinish() {
+ if (self.shakeCount >= self.maxShakes) {
+ self.state = 'ready_to_crack';
+ } else {
+ self.state = 'closed';
+ }
+ }
+ });
+ }
+ });
+ }
+ });
+ }
+ });
+ }
+ });
+ };
+ self.crack = function () {
+ if (self.state !== 'ready_to_crack') return;
+ self.state = 'cracked';
+ LK.getSound('crack').play();
+ // Hide original egg
+ eggGraphics.alpha = 0;
+ // Show cracked pieces
+ eggTop.alpha = 1;
+ eggBottom.alpha = 1;
+ // Animate cracked pieces
+ tween(eggTop, {
+ y: eggTop.y - 100,
+ rotation: -0.3
+ }, {
+ duration: 500
+ });
+ tween(eggBottom, {
+ y: eggBottom.y + 100,
+ rotation: 0.3
+ }, {
+ duration: 500
+ });
+ // Reveal toy
+ setTimeout(function () {
+ LK.getSound('reveal').play();
+ toyGraphics.alpha = 1;
+ tween(toyGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(toyGraphics, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200
+ });
+ }
+ });
+ self.state = 'opened';
+ }, 300);
+ };
+ self.down = function (x, y, obj) {
+ if (self.state === 'closed' || self.state === 'ready_to_crack') {
+ if (self.state === 'closed') {
+ self.shake();
+ } else if (self.state === 'ready_to_crack') {
+ self.crack();
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xFFB6C1
+});
+
+/****
+* Game Code
+****/
+var eggs = [];
+var toys = [0, 1, 2, 3, 4, 5]; // Will be shuffled
+var eggsOpened = 0;
+// Shuffle toys array
+function shuffleArray(array) {
+ for (var i = array.length - 1; i > 0; i--) {
+ var j = Math.floor(Math.random() * (i + 1));
+ var temp = array[i];
+ array[i] = array[j];
+ array[j] = temp;
+ }
+ return array;
+}
+shuffleArray(toys);
+// Create title text
+var titleText = new Text2('Powerpuff Girls Surprise Eggs', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 50;
+// Create instruction text
+var instructionText = new Text2('Tap eggs to shake, then tap again to open!', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+game.addChild(instructionText);
+instructionText.x = 2048 / 2;
+instructionText.y = 300;
+// Create eggs in 2x3 grid
+var startX = 2048 / 2 - 450;
+var startY = 800;
+var spacingX = 300;
+var spacingY = 350;
+for (var i = 0; i < 6; i++) {
+ var row = Math.floor(i / 3);
+ var col = i % 3;
+ var egg = new SurpriseEgg(i + 1, toys[i]);
+ egg.x = startX + col * spacingX;
+ egg.y = startY + row * spacingY;
+ eggs.push(egg);
+ game.addChild(egg);
+}
+// Create restart button (hidden initially)
+var restartText = new Text2('Tap to Play Again!', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+restartText.anchor.set(0.5, 0.5);
+restartText.alpha = 0;
+game.addChild(restartText);
+restartText.x = 2048 / 2;
+restartText.y = 2400;
+game.update = function () {
+ // Check if all eggs are opened
+ var openedCount = 0;
+ for (var i = 0; i < eggs.length; i++) {
+ if (eggs[i].state === 'opened') {
+ openedCount++;
+ }
+ }
+ // Show restart option when all eggs are opened
+ if (openedCount === 6 && restartText.alpha === 0) {
+ tween(restartText, {
+ alpha: 1
+ }, {
+ duration: 500
+ });
+ // Make restart text clickable
+ restartText.down = function (x, y, obj) {
+ // Reset game
+ eggsOpened = 0;
+ shuffleArray(toys);
+ // Remove all eggs
+ for (var i = 0; i < eggs.length; i++) {
+ eggs[i].destroy();
+ }
+ eggs = [];
+ // Recreate eggs
+ for (var i = 0; i < 6; i++) {
+ var row = Math.floor(i / 3);
+ var col = i % 3;
+ var egg = new SurpriseEgg(i + 1, toys[i]);
+ egg.x = startX + col * spacingX;
+ egg.y = startY + row * spacingY;
+ eggs.push(egg);
+ game.addChild(egg);
+ }
+ // Hide restart text
+ restartText.alpha = 0;
+ };
+ }
+};
\ No newline at end of file