/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var GiftBox = Container.expand(function (toyType, boxColor) { var self = Container.call(this); self.toyType = toyType; self.isOpened = false; self.toy = null; var boxGraphics = self.attachAsset(boxColor, { anchorX: 0.5, anchorY: 0.5 }); // Ribbon decoration var ribbon = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, scaleX: 5, scaleY: 0.5, y: -20 }); self.down = function (x, y, obj) { if (!self.isOpened) { self.openGift(); } }; self.openGift = function () { self.isOpened = true; // Play unwrap sound LK.getSound('unwrap').play(); // Box opening animation tween(boxGraphics, { scaleX: 1.3, scaleY: 1.3, alpha: 0.3 }, { duration: 300 }); tween(ribbon, { alpha: 0 }, { duration: 200 }); // Create and show toy var toyAsset; switch (self.toyType) { case 'violetCat': toyAsset = 'violetCat'; break; case 'frog': toyAsset = 'frog'; break; case 'monkey': toyAsset = 'monkey'; break; case 'partyBlower': toyAsset = 'partyBlower'; break; case 'maraca': toyAsset = 'maraca'; break; case 'dinosaur': toyAsset = 'dinosaur'; break; } self.toy = self.attachAsset(toyAsset, { anchorX: 0.5, anchorY: 0.5, alpha: 0, scaleX: 0.3, scaleY: 0.3 }); // Toy reveal animation tween(self.toy, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 500, easing: tween.elasticOut, onFinish: function onFinish() { checkAllBoxesOpened(); } }); // Sparkle effects createSparkles(self.x, self.y); }; return self; }); var Toy = Container.expand(function (toyType, originalX, originalY) { var self = Container.call(this); self.toyType = toyType; self.originalX = originalX; self.originalY = originalY; self.isAnimating = false; var toyAsset; switch (toyType) { case 'violetCat': toyAsset = 'violetCat'; break; case 'frog': toyAsset = 'frog'; break; case 'monkey': toyAsset = 'monkey'; break; case 'partyBlower': toyAsset = 'partyBlower'; break; case 'maraca': toyAsset = 'maraca'; break; case 'dinosaur': toyAsset = 'dinosaur'; break; } var toyGraphics = self.attachAsset(toyAsset, { anchorX: 0.5, anchorY: 0.5 }); self.down = function (x, y, obj) { if (!self.isAnimating) { self.playAnimation(); } }; self.playAnimation = function () { self.isAnimating = true; switch (self.toyType) { case 'violetCat': LK.getSound('catPurr').play(); // Purr and wiggle animation tween(toyGraphics, { rotation: 0.2 }, { duration: 200 }); tween(toyGraphics, { rotation: -0.2 }, { duration: 200 }); tween(toyGraphics, { rotation: 0 }, { duration: 200, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'frog': LK.getSound('frogHop').play(); // Hop animation tween(toyGraphics, { y: -50, scaleY: 1.2 }, { duration: 300, easing: tween.easeOut }); tween(toyGraphics, { y: 0, scaleY: 1 }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'monkey': LK.getSound('monkeyChatter').play(); // Flip animation tween(toyGraphics, { rotation: Math.PI * 2, scaleX: 1.3 }, { duration: 800, easing: tween.easeInOut, onFinish: function onFinish() { toyGraphics.rotation = 0; toyGraphics.scaleX = 1; self.isAnimating = false; } }); break; case 'partyBlower': LK.getSound('partyBlower').play(); // Extend animation tween(toyGraphics, { scaleX: 2, tint: 0xFF69B4 }, { duration: 400 }); tween(toyGraphics, { scaleX: 1, tint: 0xFFFFFF }, { duration: 400, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'maraca': LK.getSound('maracaShake').play(); // Shake animation var shakeCount = 0; var shakeInterval = LK.setInterval(function () { toyGraphics.x = (Math.random() - 0.5) * 20; shakeCount++; if (shakeCount > 10) { LK.clearInterval(shakeInterval); toyGraphics.x = 0; self.isAnimating = false; } }, 50); break; case 'dinosaur': LK.getSound('dinosaurRoar').play(); // Roar and stomp animation tween(toyGraphics, { scaleX: 1.4, scaleY: 1.4, tint: 0xFF0000 }, { duration: 300 }); tween(toyGraphics, { scaleX: 1, scaleY: 1, tint: 0xFFFFFF }, { duration: 500, onFinish: function onFinish() { // Screen shake effect LK.effects.flashScreen(0x666666, 200); self.isAnimating = false; } }); break; } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Sounds // Sparkle effect // Toys // Gift boxes and basket // Game variables var giftBoxes = []; var toys = []; var allBoxesOpened = false; var toyTypes = ['violetCat', 'frog', 'monkey', 'partyBlower', 'maraca', 'dinosaur']; var boxColors = ['giftBox', 'giftBoxBlue', 'giftBoxGreen', 'giftBoxYellow', 'giftBoxPurple', 'giftBoxOrange']; // Shuffle toy types for random assignment function shuffleArray(array) { var shuffled = array.slice(); for (var i = shuffled.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = shuffled[i]; shuffled[i] = shuffled[j]; shuffled[j] = temp; } return shuffled; } var shuffledToys = shuffleArray(toyTypes); // Create basket var basket = game.attachAsset('basket', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 800 }); // Title text var titleText = new Text2('Powerpuff Girls Surprise Toy Basket', { size: 80, fill: 0xFF1493 }); titleText.anchor.set(0.5, 0); titleText.x = 1024; titleText.y = 100; game.addChild(titleText); // Instruction text var instructionText = new Text2('Tap the gift boxes to discover surprise toys!', { size: 50, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); instructionText.x = 1024; instructionText.y = 200; game.addChild(instructionText); // Create gift boxes in basket formation var boxPositions = [{ x: 724, y: 700 }, { x: 924, y: 650 }, { x: 1124, y: 650 }, { x: 1324, y: 700 }, { x: 824, y: 850 }, { x: 1224, y: 850 }]; for (var i = 0; i < 6; i++) { var giftBox = new GiftBox(shuffledToys[i], boxColors[i]); giftBox.x = boxPositions[i].x; giftBox.y = boxPositions[i].y; giftBoxes.push(giftBox); game.addChild(giftBox); } // Function to create sparkle effects function createSparkles(x, y) { for (var i = 0; i < 8; i++) { var sparkle = game.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, x: x + (Math.random() - 0.5) * 100, y: y + (Math.random() - 0.5) * 100, scaleX: Math.random() * 2 + 0.5, scaleY: Math.random() * 2 + 0.5 }); tween(sparkle, { alpha: 0, scaleX: 0, scaleY: 0 }, { duration: 1000, onFinish: function onFinish() { sparkle.destroy(); } }); } } // Function to check if all boxes are opened function checkAllBoxesOpened() { var openedCount = 0; for (var i = 0; i < giftBoxes.length; i++) { if (giftBoxes[i].isOpened) { openedCount++; } } if (openedCount === 6 && !allBoxesOpened) { allBoxesOpened = true; // Hide instruction text and show play instruction tween(instructionText, { alpha: 0 }, { duration: 500 }); var playText = new Text2('Tap your toys to see them come alive!', { size: 50, fill: 0xFFFF00 }); playText.anchor.set(0.5, 0); playText.x = 1024; playText.y = 200; playText.alpha = 0; game.addChild(playText); tween(playText, { alpha: 1 }, { duration: 500 }); // Move toys to play area LK.setTimeout(function () { moveToysToPlayArea(); }, 1000); } } // Function to move toys to play area function moveToysToPlayArea() { var playPositions = [{ x: 400, y: 1400 }, { x: 700, y: 1300 }, { x: 1000, y: 1300 }, { x: 1300, y: 1400 }, { x: 1600, y: 1300 }, { x: 850, y: 1500 }]; for (var i = 0; i < giftBoxes.length; i++) { if (giftBoxes[i].toy) { var toy = new Toy(giftBoxes[i].toyType, playPositions[i].x, playPositions[i].y); toy.x = giftBoxes[i].x; toy.y = giftBoxes[i].y; toys.push(toy); game.addChild(toy); // Animate to play position tween(toy, { x: playPositions[i].x, y: playPositions[i].y }, { duration: 1000, easing: tween.easeInOut }); } } // Hide basket and gift boxes tween(basket, { alpha: 0.3 }, { duration: 1000 }); for (var j = 0; j < giftBoxes.length; j++) { tween(giftBoxes[j], { alpha: 0.2 }, { duration: 1000 }); } } // Game update loop game.update = function () { // No continuous updates needed for this game };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var GiftBox = Container.expand(function (toyType, boxColor) {
var self = Container.call(this);
self.toyType = toyType;
self.isOpened = false;
self.toy = null;
var boxGraphics = self.attachAsset(boxColor, {
anchorX: 0.5,
anchorY: 0.5
});
// Ribbon decoration
var ribbon = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 5,
scaleY: 0.5,
y: -20
});
self.down = function (x, y, obj) {
if (!self.isOpened) {
self.openGift();
}
};
self.openGift = function () {
self.isOpened = true;
// Play unwrap sound
LK.getSound('unwrap').play();
// Box opening animation
tween(boxGraphics, {
scaleX: 1.3,
scaleY: 1.3,
alpha: 0.3
}, {
duration: 300
});
tween(ribbon, {
alpha: 0
}, {
duration: 200
});
// Create and show toy
var toyAsset;
switch (self.toyType) {
case 'violetCat':
toyAsset = 'violetCat';
break;
case 'frog':
toyAsset = 'frog';
break;
case 'monkey':
toyAsset = 'monkey';
break;
case 'partyBlower':
toyAsset = 'partyBlower';
break;
case 'maraca':
toyAsset = 'maraca';
break;
case 'dinosaur':
toyAsset = 'dinosaur';
break;
}
self.toy = self.attachAsset(toyAsset, {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0,
scaleX: 0.3,
scaleY: 0.3
});
// Toy reveal animation
tween(self.toy, {
alpha: 1,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.elasticOut,
onFinish: function onFinish() {
checkAllBoxesOpened();
}
});
// Sparkle effects
createSparkles(self.x, self.y);
};
return self;
});
var Toy = Container.expand(function (toyType, originalX, originalY) {
var self = Container.call(this);
self.toyType = toyType;
self.originalX = originalX;
self.originalY = originalY;
self.isAnimating = false;
var toyAsset;
switch (toyType) {
case 'violetCat':
toyAsset = 'violetCat';
break;
case 'frog':
toyAsset = 'frog';
break;
case 'monkey':
toyAsset = 'monkey';
break;
case 'partyBlower':
toyAsset = 'partyBlower';
break;
case 'maraca':
toyAsset = 'maraca';
break;
case 'dinosaur':
toyAsset = 'dinosaur';
break;
}
var toyGraphics = self.attachAsset(toyAsset, {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
if (!self.isAnimating) {
self.playAnimation();
}
};
self.playAnimation = function () {
self.isAnimating = true;
switch (self.toyType) {
case 'violetCat':
LK.getSound('catPurr').play();
// Purr and wiggle animation
tween(toyGraphics, {
rotation: 0.2
}, {
duration: 200
});
tween(toyGraphics, {
rotation: -0.2
}, {
duration: 200
});
tween(toyGraphics, {
rotation: 0
}, {
duration: 200,
onFinish: function onFinish() {
self.isAnimating = false;
}
});
break;
case 'frog':
LK.getSound('frogHop').play();
// Hop animation
tween(toyGraphics, {
y: -50,
scaleY: 1.2
}, {
duration: 300,
easing: tween.easeOut
});
tween(toyGraphics, {
y: 0,
scaleY: 1
}, {
duration: 300,
easing: tween.bounceOut,
onFinish: function onFinish() {
self.isAnimating = false;
}
});
break;
case 'monkey':
LK.getSound('monkeyChatter').play();
// Flip animation
tween(toyGraphics, {
rotation: Math.PI * 2,
scaleX: 1.3
}, {
duration: 800,
easing: tween.easeInOut,
onFinish: function onFinish() {
toyGraphics.rotation = 0;
toyGraphics.scaleX = 1;
self.isAnimating = false;
}
});
break;
case 'partyBlower':
LK.getSound('partyBlower').play();
// Extend animation
tween(toyGraphics, {
scaleX: 2,
tint: 0xFF69B4
}, {
duration: 400
});
tween(toyGraphics, {
scaleX: 1,
tint: 0xFFFFFF
}, {
duration: 400,
onFinish: function onFinish() {
self.isAnimating = false;
}
});
break;
case 'maraca':
LK.getSound('maracaShake').play();
// Shake animation
var shakeCount = 0;
var shakeInterval = LK.setInterval(function () {
toyGraphics.x = (Math.random() - 0.5) * 20;
shakeCount++;
if (shakeCount > 10) {
LK.clearInterval(shakeInterval);
toyGraphics.x = 0;
self.isAnimating = false;
}
}, 50);
break;
case 'dinosaur':
LK.getSound('dinosaurRoar').play();
// Roar and stomp animation
tween(toyGraphics, {
scaleX: 1.4,
scaleY: 1.4,
tint: 0xFF0000
}, {
duration: 300
});
tween(toyGraphics, {
scaleX: 1,
scaleY: 1,
tint: 0xFFFFFF
}, {
duration: 500,
onFinish: function onFinish() {
// Screen shake effect
LK.effects.flashScreen(0x666666, 200);
self.isAnimating = false;
}
});
break;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Sounds
// Sparkle effect
// Toys
// Gift boxes and basket
// Game variables
var giftBoxes = [];
var toys = [];
var allBoxesOpened = false;
var toyTypes = ['violetCat', 'frog', 'monkey', 'partyBlower', 'maraca', 'dinosaur'];
var boxColors = ['giftBox', 'giftBoxBlue', 'giftBoxGreen', 'giftBoxYellow', 'giftBoxPurple', 'giftBoxOrange'];
// Shuffle toy types for random assignment
function shuffleArray(array) {
var shuffled = array.slice();
for (var i = shuffled.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = shuffled[i];
shuffled[i] = shuffled[j];
shuffled[j] = temp;
}
return shuffled;
}
var shuffledToys = shuffleArray(toyTypes);
// Create basket
var basket = game.attachAsset('basket', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 800
});
// Title text
var titleText = new Text2('Powerpuff Girls Surprise Toy Basket', {
size: 80,
fill: 0xFF1493
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 100;
game.addChild(titleText);
// Instruction text
var instructionText = new Text2('Tap the gift boxes to discover surprise toys!', {
size: 50,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
instructionText.x = 1024;
instructionText.y = 200;
game.addChild(instructionText);
// Create gift boxes in basket formation
var boxPositions = [{
x: 724,
y: 700
}, {
x: 924,
y: 650
}, {
x: 1124,
y: 650
}, {
x: 1324,
y: 700
}, {
x: 824,
y: 850
}, {
x: 1224,
y: 850
}];
for (var i = 0; i < 6; i++) {
var giftBox = new GiftBox(shuffledToys[i], boxColors[i]);
giftBox.x = boxPositions[i].x;
giftBox.y = boxPositions[i].y;
giftBoxes.push(giftBox);
game.addChild(giftBox);
}
// Function to create sparkle effects
function createSparkles(x, y) {
for (var i = 0; i < 8; i++) {
var sparkle = game.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
x: x + (Math.random() - 0.5) * 100,
y: y + (Math.random() - 0.5) * 100,
scaleX: Math.random() * 2 + 0.5,
scaleY: Math.random() * 2 + 0.5
});
tween(sparkle, {
alpha: 0,
scaleX: 0,
scaleY: 0
}, {
duration: 1000,
onFinish: function onFinish() {
sparkle.destroy();
}
});
}
}
// Function to check if all boxes are opened
function checkAllBoxesOpened() {
var openedCount = 0;
for (var i = 0; i < giftBoxes.length; i++) {
if (giftBoxes[i].isOpened) {
openedCount++;
}
}
if (openedCount === 6 && !allBoxesOpened) {
allBoxesOpened = true;
// Hide instruction text and show play instruction
tween(instructionText, {
alpha: 0
}, {
duration: 500
});
var playText = new Text2('Tap your toys to see them come alive!', {
size: 50,
fill: 0xFFFF00
});
playText.anchor.set(0.5, 0);
playText.x = 1024;
playText.y = 200;
playText.alpha = 0;
game.addChild(playText);
tween(playText, {
alpha: 1
}, {
duration: 500
});
// Move toys to play area
LK.setTimeout(function () {
moveToysToPlayArea();
}, 1000);
}
}
// Function to move toys to play area
function moveToysToPlayArea() {
var playPositions = [{
x: 400,
y: 1400
}, {
x: 700,
y: 1300
}, {
x: 1000,
y: 1300
}, {
x: 1300,
y: 1400
}, {
x: 1600,
y: 1300
}, {
x: 850,
y: 1500
}];
for (var i = 0; i < giftBoxes.length; i++) {
if (giftBoxes[i].toy) {
var toy = new Toy(giftBoxes[i].toyType, playPositions[i].x, playPositions[i].y);
toy.x = giftBoxes[i].x;
toy.y = giftBoxes[i].y;
toys.push(toy);
game.addChild(toy);
// Animate to play position
tween(toy, {
x: playPositions[i].x,
y: playPositions[i].y
}, {
duration: 1000,
easing: tween.easeInOut
});
}
}
// Hide basket and gift boxes
tween(basket, {
alpha: 0.3
}, {
duration: 1000
});
for (var j = 0; j < giftBoxes.length; j++) {
tween(giftBoxes[j], {
alpha: 0.2
}, {
duration: 1000
});
}
}
// Game update loop
game.update = function () {
// No continuous updates needed for this game
};