Code edit (1 edits merged)
Please save this source code
User prompt
Party Girl Blossom - Interactive Birthday Celebration
Initial prompt
Powerpuff girls: talking partier blossom (2015) (blossom’s 7th birthday) tap on her tummy to talk 7 sayings, but tap her tummy 2 times she’ll sing the party song, or hold the party popper with confetti inside, or blow the party blower.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var ConfettiPiece = Container.expand(function () { var self = Container.call(this); var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff]; var randomColor = colors[Math.floor(Math.random() * colors.length)]; var piece = self.attachAsset('confetti', { anchorX: 0.5, anchorY: 0.5 }); piece.tint = randomColor; self.velocityX = (Math.random() - 0.5) * 10; self.velocityY = Math.random() * -15 - 5; self.gravity = 0.5; self.rotationSpeed = (Math.random() - 0.5) * 0.2; self.update = function () { self.x += self.velocityX; self.y += self.velocityY; self.velocityY += self.gravity; self.rotation += self.rotationSpeed; if (self.y > 2732 + 50) { self.destroy(); for (var i = confettiPieces.length - 1; i >= 0; i--) { if (confettiPieces[i] === self) { confettiPieces.splice(i, 1); break; } } } }; return self; }); var Decoration = Container.expand(function () { var self = Container.call(this); var colors = [0xff69b4, 0xff4500, 0xffd700, 0x32cd32, 0x9370db]; var randomColor = colors[Math.floor(Math.random() * colors.length)]; var decoration = self.attachAsset('decoration', { anchorX: 0.5, anchorY: 0.5 }); decoration.tint = randomColor; // Gentle floating animation function _float() { tween(self, { y: self.y - 10 }, { duration: 2000, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { y: self.y + 10 }, { duration: 2000, easing: tween.easeInOut, onFinish: _float }); } }); } _float(); return self; }); var PartyButton = Container.expand(function (buttonType) { var self = Container.call(this); var button = self.attachAsset(buttonType === 'popper' ? 'partyPopper' : 'partyHorn', { anchorX: 0.5, anchorY: 0.5 }); self.buttonType = buttonType; self.down = function (x, y, obj) { // Button press animation tween(self, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); } }); if (self.buttonType === 'popper') { activatePopper(); } else { activateHorn(); } }; return self; }); var PartyGirl = Container.expand(function () { var self = Container.call(this); // Main body var body = self.attachAsset('partyGirl', { anchorX: 0.5, anchorY: 1.0 }); // Party hat var hat = self.attachAsset('partyHat', { anchorX: 0.5, anchorY: 1.0, x: 0, y: -600 }); // Tummy area (clickable) var tummy = self.attachAsset('tummy', { anchorX: 0.5, anchorY: 0.5, x: 0, y: -200 }); tummy.alpha = 0.01; // Nearly invisible but still clickable self.isDancing = false; self.startDancing = function () { if (self.isDancing) return; self.isDancing = true; function danceMove() { if (!self.isDancing) return; tween(self, { rotation: 0.1 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { rotation: -0.1 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { tween(self, { rotation: 0 }, { duration: 300, easing: tween.easeInOut, onFinish: danceMove }); } }); } }); } danceMove(); }; self.stopDancing = function () { self.isDancing = false; tween.stop(self, { rotation: true }); tween(self, { rotation: 0 }, { duration: 300, easing: tween.easeOut }); }; // Tummy click handler tummy.down = function (x, y, obj) { var currentTime = Date.now(); if (!self.lastTapTime) self.lastTapTime = 0; var timeDiff = currentTime - self.lastTapTime; if (timeDiff < 500) { // Double tap detected playBirthdaySong(); } else { playRandomSaying(); } self.lastTapTime = currentTime; }; return self; }); var SpeechBubble = Container.expand(function () { var self = Container.call(this); var bubble = self.attachAsset('speechBubble', { anchorX: 0.5, anchorY: 0.5 }); var text = new Text2('', { size: 36, fill: 0x000000 }); text.anchor.set(0.5, 0.5); self.addChild(text); self.alpha = 0; self.showMessage = function (message) { text.setText(message); self.alpha = 1; tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); LK.setTimeout(function () { tween(self, { alpha: 0 }, { duration: 500 }); }, 2000); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game variables var partyGirl; var speechBubble; var popperButton; var hornButton; var confettiPieces = []; var decorations = []; // Party sayings var partySayings = ["Let's party!", "Happy birthday!", "Time to celebrate!", "Woohoo!", "Party time!", "Let's dance!", "Yay! Fun time!"]; // Initialize party girl partyGirl = game.addChild(new PartyGirl()); partyGirl.x = 2048 / 2; partyGirl.y = 2732 - 200; // Initialize speech bubble speechBubble = game.addChild(new SpeechBubble()); speechBubble.x = 2048 / 2; speechBubble.y = 2732 / 2 - 200; // Initialize buttons popperButton = game.addChild(new PartyButton('popper')); popperButton.x = 200; popperButton.y = 2732 - 150; hornButton = game.addChild(new PartyButton('horn')); hornButton.x = 2048 - 200; hornButton.y = 2732 - 150; // Create decorations around the screen for (var i = 0; i < 12; i++) { var decoration = game.addChild(new Decoration()); if (i < 6) { // Top decorations decoration.x = (i + 1) * (2048 / 7); decoration.y = 100; } else { // Side decorations var side = i - 6; if (side < 3) { decoration.x = 100; decoration.y = 400 + side * 600; } else { decoration.x = 2048 - 100; decoration.y = 400 + (side - 3) * 600; } } decorations.push(decoration); } // Game functions function playRandomSaying() { var randomIndex = Math.floor(Math.random() * partySayings.length); var saying = partySayings[randomIndex]; speechBubble.showMessage(saying); var soundIndex = randomIndex + 1; LK.getSound('partySound' + soundIndex).play(); // Small bounce animation for party girl tween(partyGirl, { scaleY: 1.1 }, { duration: 200, onFinish: function onFinish() { tween(partyGirl, { scaleY: 1 }, { duration: 200 }); } }); } function playBirthdaySong() { speechBubble.showMessage("🎵 Happy Birthday! 🎵"); LK.getSound('birthdaySong').play(); partyGirl.startDancing(); // Stop dancing after song duration LK.setTimeout(function () { partyGirl.stopDancing(); }, 4000); } function activatePopper() { LK.getSound('popperSound').play(); // Create confetti explosion for (var i = 0; i < 20; i++) { var confetti = game.addChild(new ConfettiPiece()); confetti.x = popperButton.x + (Math.random() - 0.5) * 100; confetti.y = popperButton.y; confettiPieces.push(confetti); } } function activateHorn() { LK.getSound('hornSound').play(); // Create puff effects for (var i = 0; i < 5; i++) { var puff = LK.getAsset('puffEffect', { anchorX: 0.5, anchorY: 0.5 }); puff.x = hornButton.x + 80 + i * 30; puff.y = hornButton.y + (Math.random() - 0.5) * 40; game.addChild(puff); tween(puff, { alpha: 0, scaleX: 2, scaleY: 2 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { puff.destroy(); } }); } } // Game update loop game.update = function () { // Update confetti pieces for (var i = confettiPieces.length - 1; i >= 0; i--) { if (confettiPieces[i] && confettiPieces[i].update) { confettiPieces[i].update(); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var ConfettiPiece = Container.expand(function () {
var self = Container.call(this);
var colors = [0xff0000, 0x00ff00, 0x0000ff, 0xffff00, 0xff00ff, 0x00ffff];
var randomColor = colors[Math.floor(Math.random() * colors.length)];
var piece = self.attachAsset('confetti', {
anchorX: 0.5,
anchorY: 0.5
});
piece.tint = randomColor;
self.velocityX = (Math.random() - 0.5) * 10;
self.velocityY = Math.random() * -15 - 5;
self.gravity = 0.5;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.update = function () {
self.x += self.velocityX;
self.y += self.velocityY;
self.velocityY += self.gravity;
self.rotation += self.rotationSpeed;
if (self.y > 2732 + 50) {
self.destroy();
for (var i = confettiPieces.length - 1; i >= 0; i--) {
if (confettiPieces[i] === self) {
confettiPieces.splice(i, 1);
break;
}
}
}
};
return self;
});
var Decoration = Container.expand(function () {
var self = Container.call(this);
var colors = [0xff69b4, 0xff4500, 0xffd700, 0x32cd32, 0x9370db];
var randomColor = colors[Math.floor(Math.random() * colors.length)];
var decoration = self.attachAsset('decoration', {
anchorX: 0.5,
anchorY: 0.5
});
decoration.tint = randomColor;
// Gentle floating animation
function _float() {
tween(self, {
y: self.y - 10
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
y: self.y + 10
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: _float
});
}
});
}
_float();
return self;
});
var PartyButton = Container.expand(function (buttonType) {
var self = Container.call(this);
var button = self.attachAsset(buttonType === 'popper' ? 'partyPopper' : 'partyHorn', {
anchorX: 0.5,
anchorY: 0.5
});
self.buttonType = buttonType;
self.down = function (x, y, obj) {
// Button press animation
tween(self, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
}
});
if (self.buttonType === 'popper') {
activatePopper();
} else {
activateHorn();
}
};
return self;
});
var PartyGirl = Container.expand(function () {
var self = Container.call(this);
// Main body
var body = self.attachAsset('partyGirl', {
anchorX: 0.5,
anchorY: 1.0
});
// Party hat
var hat = self.attachAsset('partyHat', {
anchorX: 0.5,
anchorY: 1.0,
x: 0,
y: -600
});
// Tummy area (clickable)
var tummy = self.attachAsset('tummy', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -200
});
tummy.alpha = 0.01; // Nearly invisible but still clickable
self.isDancing = false;
self.startDancing = function () {
if (self.isDancing) return;
self.isDancing = true;
function danceMove() {
if (!self.isDancing) return;
tween(self, {
rotation: 0.1
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: -0.1
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: 0
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: danceMove
});
}
});
}
});
}
danceMove();
};
self.stopDancing = function () {
self.isDancing = false;
tween.stop(self, {
rotation: true
});
tween(self, {
rotation: 0
}, {
duration: 300,
easing: tween.easeOut
});
};
// Tummy click handler
tummy.down = function (x, y, obj) {
var currentTime = Date.now();
if (!self.lastTapTime) self.lastTapTime = 0;
var timeDiff = currentTime - self.lastTapTime;
if (timeDiff < 500) {
// Double tap detected
playBirthdaySong();
} else {
playRandomSaying();
}
self.lastTapTime = currentTime;
};
return self;
});
var SpeechBubble = Container.expand(function () {
var self = Container.call(this);
var bubble = self.attachAsset('speechBubble', {
anchorX: 0.5,
anchorY: 0.5
});
var text = new Text2('', {
size: 36,
fill: 0x000000
});
text.anchor.set(0.5, 0.5);
self.addChild(text);
self.alpha = 0;
self.showMessage = function (message) {
text.setText(message);
self.alpha = 1;
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
LK.setTimeout(function () {
tween(self, {
alpha: 0
}, {
duration: 500
});
}, 2000);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game variables
var partyGirl;
var speechBubble;
var popperButton;
var hornButton;
var confettiPieces = [];
var decorations = [];
// Party sayings
var partySayings = ["Let's party!", "Happy birthday!", "Time to celebrate!", "Woohoo!", "Party time!", "Let's dance!", "Yay! Fun time!"];
// Initialize party girl
partyGirl = game.addChild(new PartyGirl());
partyGirl.x = 2048 / 2;
partyGirl.y = 2732 - 200;
// Initialize speech bubble
speechBubble = game.addChild(new SpeechBubble());
speechBubble.x = 2048 / 2;
speechBubble.y = 2732 / 2 - 200;
// Initialize buttons
popperButton = game.addChild(new PartyButton('popper'));
popperButton.x = 200;
popperButton.y = 2732 - 150;
hornButton = game.addChild(new PartyButton('horn'));
hornButton.x = 2048 - 200;
hornButton.y = 2732 - 150;
// Create decorations around the screen
for (var i = 0; i < 12; i++) {
var decoration = game.addChild(new Decoration());
if (i < 6) {
// Top decorations
decoration.x = (i + 1) * (2048 / 7);
decoration.y = 100;
} else {
// Side decorations
var side = i - 6;
if (side < 3) {
decoration.x = 100;
decoration.y = 400 + side * 600;
} else {
decoration.x = 2048 - 100;
decoration.y = 400 + (side - 3) * 600;
}
}
decorations.push(decoration);
}
// Game functions
function playRandomSaying() {
var randomIndex = Math.floor(Math.random() * partySayings.length);
var saying = partySayings[randomIndex];
speechBubble.showMessage(saying);
var soundIndex = randomIndex + 1;
LK.getSound('partySound' + soundIndex).play();
// Small bounce animation for party girl
tween(partyGirl, {
scaleY: 1.1
}, {
duration: 200,
onFinish: function onFinish() {
tween(partyGirl, {
scaleY: 1
}, {
duration: 200
});
}
});
}
function playBirthdaySong() {
speechBubble.showMessage("🎵 Happy Birthday! 🎵");
LK.getSound('birthdaySong').play();
partyGirl.startDancing();
// Stop dancing after song duration
LK.setTimeout(function () {
partyGirl.stopDancing();
}, 4000);
}
function activatePopper() {
LK.getSound('popperSound').play();
// Create confetti explosion
for (var i = 0; i < 20; i++) {
var confetti = game.addChild(new ConfettiPiece());
confetti.x = popperButton.x + (Math.random() - 0.5) * 100;
confetti.y = popperButton.y;
confettiPieces.push(confetti);
}
}
function activateHorn() {
LK.getSound('hornSound').play();
// Create puff effects
for (var i = 0; i < 5; i++) {
var puff = LK.getAsset('puffEffect', {
anchorX: 0.5,
anchorY: 0.5
});
puff.x = hornButton.x + 80 + i * 30;
puff.y = hornButton.y + (Math.random() - 0.5) * 40;
game.addChild(puff);
tween(puff, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
puff.destroy();
}
});
}
}
// Game update loop
game.update = function () {
// Update confetti pieces
for (var i = confettiPieces.length - 1; i >= 0; i--) {
if (confettiPieces[i] && confettiPieces[i].update) {
confettiPieces[i].update();
}
}
};