/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var SurpriseEgg = Container.expand(function (eggType, eggColor) {
var self = Container.call(this);
self.isOpened = false;
self.eggType = eggType;
self.contents = [];
// Create egg base
var eggBase = self.attachAsset(eggColor, {
anchorX: 0.5,
anchorY: 0.5
});
// Create egg top half
var eggTopHalf = self.attachAsset('eggTop', {
anchorX: 0.5,
anchorY: 1.0,
y: 0
});
// Create egg bottom half
var eggBottomHalf = self.attachAsset('eggBottom', {
anchorX: 0.5,
anchorY: 0.0,
y: 0
});
// Hide base initially, show halves
eggBase.visible = false;
eggTopHalf.visible = true;
eggBottomHalf.visible = true;
self.generateContents = function () {
self.contents = [];
var numItems = Math.floor(Math.random() * 3) + 2; // 2-4 items
for (var i = 0; i < numItems; i++) {
var itemType = Math.floor(Math.random() * 4);
var item;
switch (itemType) {
case 0:
item = {
type: 'blossom',
asset: 'blossomToy'
};
break;
case 1:
item = {
type: 'bubbles',
asset: 'bubblesToy'
};
break;
case 2:
item = {
type: 'buttercup',
asset: 'buttercupToy'
};
break;
case 3:
item = {
type: 'sticker',
asset: 'sticker'
};
break;
}
self.contents.push(item);
}
};
self.openEgg = function () {
if (self.isOpened) return;
self.isOpened = true;
// Play crack sound
LK.getSound('eggCrack').play();
// Animate egg opening
tween(eggTopHalf, {
y: -100,
rotation: -0.3
}, {
duration: 800,
easing: tween.bounceOut
});
tween(eggBottomHalf, {
y: 100,
rotation: 0.2
}, {
duration: 800,
easing: tween.bounceOut
});
// Show contents after opening animation
LK.setTimeout(function () {
self.showContents();
}, 400);
};
self.showContents = function () {
LK.getSound('surprise').play();
for (var i = 0; i < self.contents.length; i++) {
var item = self.contents[i];
var itemGraphic = LK.getAsset(item.asset, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
scaleX: 0,
scaleY: 0
});
// Position items in a circular pattern
var angle = i / self.contents.length * Math.PI * 2;
var radius = 80;
itemGraphic.x = Math.cos(angle) * radius;
itemGraphic.y = Math.sin(angle) * radius;
self.addChild(itemGraphic);
// Animate item appearance
tween(itemGraphic, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 600,
easing: tween.elasticOut
});
// Add floating animation
var floatDelay = i * 200;
LK.setTimeout(function (graphic) {
return function () {
tween(graphic, {
y: graphic.y - 20
}, {
duration: 1000,
easing: tween.easeInOut
});
};
}(itemGraphic), floatDelay);
}
// Flash effect
LK.effects.flashObject(self, 0xFFFFFF, 500);
// Auto-reset after showing contents
LK.setTimeout(function () {
self.resetEgg();
}, 3000);
};
self.resetEgg = function () {
// Remove all content items
for (var i = self.children.length - 1; i >= 0; i--) {
var child = self.children[i];
if (child !== eggTopHalf && child !== eggBottomHalf && child !== eggBase) {
child.destroy();
}
}
// Reset egg halves position
tween(eggTopHalf, {
y: 0,
rotation: 0
}, {
duration: 800,
easing: tween.easeInOut
});
tween(eggBottomHalf, {
y: 0,
rotation: 0
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isOpened = false;
self.generateContents();
}
});
};
self.down = function (x, y, obj) {
if (!self.isOpened) {
self.openEgg();
LK.getSound('collect').play();
}
};
// Generate initial contents
self.generateContents();
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Create title text
var titleText = new Text2('Powerpuff Girls Surprise Eggs', {
size: 80,
fill: 0xFF1493
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
// Create instruction text
var instructionText = new Text2('Tap the eggs to discover surprises!', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 150;
// Create surprise eggs
var eggs = [];
var eggTypes = ['egg1', 'egg2', 'egg3', 'egg4'];
var eggPositions = [{
x: 512,
y: 900
},
// Top left
{
x: 1536,
y: 900
},
// Top right
{
x: 512,
y: 1600
},
// Bottom left
{
x: 1536,
y: 1600
} // Bottom right
];
for (var i = 0; i < 4; i++) {
var egg = new SurpriseEgg(i, eggTypes[i]);
egg.x = eggPositions[i].x;
egg.y = eggPositions[i].y;
eggs.push(egg);
game.addChild(egg);
}
// Add sparkle effects
var sparkleTimer = 0;
game.update = function () {
sparkleTimer++;
// Add random sparkles around eggs
if (sparkleTimer % 60 === 0) {
for (var i = 0; i < eggs.length; i++) {
var egg = eggs[i];
if (!egg.isOpened) {
var sparkle = LK.getAsset('sticker', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 0.3,
scaleY: 0.3,
alpha: 0.8
});
sparkle.x = egg.x + (Math.random() - 0.5) * 300;
sparkle.y = egg.y + (Math.random() - 0.5) * 300;
game.addChild(sparkle);
// Animate sparkle
tween(sparkle, {
alpha: 0,
scaleX: 0,
scaleY: 0,
y: sparkle.y - 100
}, {
duration: 1500,
easing: tween.easeOut,
onFinish: function onFinish() {
sparkle.destroy();
}
});
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,271 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var SurpriseEgg = Container.expand(function (eggType, eggColor) {
+ var self = Container.call(this);
+ self.isOpened = false;
+ self.eggType = eggType;
+ self.contents = [];
+ // Create egg base
+ var eggBase = self.attachAsset(eggColor, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create egg top half
+ var eggTopHalf = self.attachAsset('eggTop', {
+ anchorX: 0.5,
+ anchorY: 1.0,
+ y: 0
+ });
+ // Create egg bottom half
+ var eggBottomHalf = self.attachAsset('eggBottom', {
+ anchorX: 0.5,
+ anchorY: 0.0,
+ y: 0
+ });
+ // Hide base initially, show halves
+ eggBase.visible = false;
+ eggTopHalf.visible = true;
+ eggBottomHalf.visible = true;
+ self.generateContents = function () {
+ self.contents = [];
+ var numItems = Math.floor(Math.random() * 3) + 2; // 2-4 items
+ for (var i = 0; i < numItems; i++) {
+ var itemType = Math.floor(Math.random() * 4);
+ var item;
+ switch (itemType) {
+ case 0:
+ item = {
+ type: 'blossom',
+ asset: 'blossomToy'
+ };
+ break;
+ case 1:
+ item = {
+ type: 'bubbles',
+ asset: 'bubblesToy'
+ };
+ break;
+ case 2:
+ item = {
+ type: 'buttercup',
+ asset: 'buttercupToy'
+ };
+ break;
+ case 3:
+ item = {
+ type: 'sticker',
+ asset: 'sticker'
+ };
+ break;
+ }
+ self.contents.push(item);
+ }
+ };
+ self.openEgg = function () {
+ if (self.isOpened) return;
+ self.isOpened = true;
+ // Play crack sound
+ LK.getSound('eggCrack').play();
+ // Animate egg opening
+ tween(eggTopHalf, {
+ y: -100,
+ rotation: -0.3
+ }, {
+ duration: 800,
+ easing: tween.bounceOut
+ });
+ tween(eggBottomHalf, {
+ y: 100,
+ rotation: 0.2
+ }, {
+ duration: 800,
+ easing: tween.bounceOut
+ });
+ // Show contents after opening animation
+ LK.setTimeout(function () {
+ self.showContents();
+ }, 400);
+ };
+ self.showContents = function () {
+ LK.getSound('surprise').play();
+ for (var i = 0; i < self.contents.length; i++) {
+ var item = self.contents[i];
+ var itemGraphic = LK.getAsset(item.asset, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0,
+ scaleX: 0,
+ scaleY: 0
+ });
+ // Position items in a circular pattern
+ var angle = i / self.contents.length * Math.PI * 2;
+ var radius = 80;
+ itemGraphic.x = Math.cos(angle) * radius;
+ itemGraphic.y = Math.sin(angle) * radius;
+ self.addChild(itemGraphic);
+ // Animate item appearance
+ tween(itemGraphic, {
+ alpha: 1,
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 600,
+ easing: tween.elasticOut
+ });
+ // Add floating animation
+ var floatDelay = i * 200;
+ LK.setTimeout(function (graphic) {
+ return function () {
+ tween(graphic, {
+ y: graphic.y - 20
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut
+ });
+ };
+ }(itemGraphic), floatDelay);
+ }
+ // Flash effect
+ LK.effects.flashObject(self, 0xFFFFFF, 500);
+ // Auto-reset after showing contents
+ LK.setTimeout(function () {
+ self.resetEgg();
+ }, 3000);
+ };
+ self.resetEgg = function () {
+ // Remove all content items
+ for (var i = self.children.length - 1; i >= 0; i--) {
+ var child = self.children[i];
+ if (child !== eggTopHalf && child !== eggBottomHalf && child !== eggBase) {
+ child.destroy();
+ }
+ }
+ // Reset egg halves position
+ tween(eggTopHalf, {
+ y: 0,
+ rotation: 0
+ }, {
+ duration: 800,
+ easing: tween.easeInOut
+ });
+ tween(eggBottomHalf, {
+ y: 0,
+ rotation: 0
+ }, {
+ duration: 800,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ self.isOpened = false;
+ self.generateContents();
+ }
+ });
+ };
+ self.down = function (x, y, obj) {
+ if (!self.isOpened) {
+ self.openEgg();
+ LK.getSound('collect').play();
+ }
+ };
+ // Generate initial contents
+ self.generateContents();
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Create title text
+var titleText = new Text2('Powerpuff Girls Surprise Eggs', {
+ size: 80,
+ fill: 0xFF1493
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 50;
+// Create instruction text
+var instructionText = new Text2('Tap the eggs to discover surprises!', {
+ size: 50,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0);
+LK.gui.top.addChild(instructionText);
+instructionText.y = 150;
+// Create surprise eggs
+var eggs = [];
+var eggTypes = ['egg1', 'egg2', 'egg3', 'egg4'];
+var eggPositions = [{
+ x: 512,
+ y: 900
+},
+// Top left
+{
+ x: 1536,
+ y: 900
+},
+// Top right
+{
+ x: 512,
+ y: 1600
+},
+// Bottom left
+{
+ x: 1536,
+ y: 1600
+} // Bottom right
+];
+for (var i = 0; i < 4; i++) {
+ var egg = new SurpriseEgg(i, eggTypes[i]);
+ egg.x = eggPositions[i].x;
+ egg.y = eggPositions[i].y;
+ eggs.push(egg);
+ game.addChild(egg);
+}
+// Add sparkle effects
+var sparkleTimer = 0;
+game.update = function () {
+ sparkleTimer++;
+ // Add random sparkles around eggs
+ if (sparkleTimer % 60 === 0) {
+ for (var i = 0; i < eggs.length; i++) {
+ var egg = eggs[i];
+ if (!egg.isOpened) {
+ var sparkle = LK.getAsset('sticker', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.3,
+ scaleY: 0.3,
+ alpha: 0.8
+ });
+ sparkle.x = egg.x + (Math.random() - 0.5) * 300;
+ sparkle.y = egg.y + (Math.random() - 0.5) * 300;
+ game.addChild(sparkle);
+ // Animate sparkle
+ tween(sparkle, {
+ alpha: 0,
+ scaleX: 0,
+ scaleY: 0,
+ y: sparkle.y - 100
+ }, {
+ duration: 1500,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ sparkle.destroy();
+ }
+ });
+ }
+ }
+ }
+};
\ No newline at end of file