Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls Musical Band
Initial prompt
The powerpuff girls: tap on blossom, or bubbles, or buttercup, or bliss to make blossom blow the trumpet, or make bubbles play the drum š„, or make buttercup play the accordion šŖ, or make bliss blow the party blower. (No levels).
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PowerpuffGirl = Container.expand(function (girlType, instrumentType, soundId) {
var self = Container.call(this);
// Store girl properties
self.girlType = girlType;
self.instrumentType = instrumentType;
self.soundId = soundId;
self.isPlaying = false;
// Create girl body
var girlBody = self.attachAsset(girlType, {
anchorX: 0.5,
anchorY: 0.5
});
// Create instrument
var instrument = self.attachAsset(instrumentType, {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -80
});
// Initially hide instrument
instrument.visible = false;
// Store references
self.girlBody = girlBody;
self.instrument = instrument;
// Method to play animation and sound
self.playMusic = function () {
if (self.isPlaying) return;
self.isPlaying = true;
// Show instrument
self.instrument.visible = true;
// Play sound
LK.getSound(self.soundId).play();
// Animate girl
tween(self.girlBody, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.girlBody, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
// Animate instrument based on type
if (self.instrumentType === 'trumpet') {
tween(self.instrument, {
rotation: 0.2
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self.instrument, {
rotation: 0
}, {
duration: 300,
easing: tween.easeInOut
});
}
});
} else if (self.instrumentType === 'drums') {
tween(self.instrument, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 150,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.instrument, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 150,
easing: tween.easeIn
});
}
});
} else if (self.instrumentType === 'accordion') {
tween(self.instrument, {
scaleX: 0.8,
scaleY: 1.2
}, {
duration: 250,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self.instrument, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 250,
easing: tween.easeInOut
});
}
});
} else if (self.instrumentType === 'partyblower') {
tween(self.instrument, {
scaleX: 1.5,
rotation: 0.1
}, {
duration: 400,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self.instrument, {
scaleX: 1.0,
rotation: 0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
}
// Hide instrument after animation
LK.setTimeout(function () {
self.instrument.visible = false;
self.isPlaying = false;
}, 800);
};
// Touch handler
self.down = function (x, y, obj) {
self.playMusic();
};
// Idle animation
self.startIdleAnimation = function () {
var _idleAnimation = function idleAnimation() {
if (!self.isPlaying) {
tween(self.girlBody, {
y: self.girlBody.y - 10
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self.girlBody, {
y: self.girlBody.y + 10
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: _idleAnimation
});
}
});
} else {
LK.setTimeout(_idleAnimation, 100);
}
};
_idleAnimation();
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
game.setBackgroundColor(0xFFB6C1);
// Create title text
var titleText = new Text2('Powerpuff Girls Musical Band', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
// Create instruction text
var instructionText = new Text2('Tap the Girls to Make Music!', {
size: 80,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionText);
instructionText.y = -50;
// Create Powerpuff Girls
var blossom = new PowerpuffGirl('blossom', 'trumpet', 'trumpetSound');
var bubbles = new PowerpuffGirl('bubbles', 'drums', 'drumSound');
var buttercup = new PowerpuffGirl('buttercup', 'accordion', 'accordionSound');
var bliss = new PowerpuffGirl('bliss', 'partyblower', 'partyblowerSound');
// Position girls in a 2x2 grid
var centerX = 2048 / 2;
var centerY = 2732 / 2;
var spacing = 450;
// Top row
blossom.x = centerX - spacing / 2;
blossom.y = centerY - spacing / 2;
bubbles.x = centerX + spacing / 2;
bubbles.y = centerY - spacing / 2;
// Bottom row
buttercup.x = centerX - spacing / 2;
buttercup.y = centerY + spacing / 2;
bliss.x = centerX + spacing / 2;
bliss.y = centerY + spacing / 2;
// Add girls to game
game.addChild(blossom);
game.addChild(bubbles);
game.addChild(buttercup);
game.addChild(bliss);
// Start idle animations
blossom.startIdleAnimation();
LK.setTimeout(function () {
bubbles.startIdleAnimation();
}, 500);
LK.setTimeout(function () {
buttercup.startIdleAnimation();
}, 1000);
LK.setTimeout(function () {
bliss.startIdleAnimation();
}, 1500);
// Game update loop
game.update = function () {
// No specific updates needed for this musical game
// All interactions are handled by touch events on individual girls
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,230 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var PowerpuffGirl = Container.expand(function (girlType, instrumentType, soundId) {
+ var self = Container.call(this);
+ // Store girl properties
+ self.girlType = girlType;
+ self.instrumentType = instrumentType;
+ self.soundId = soundId;
+ self.isPlaying = false;
+ // Create girl body
+ var girlBody = self.attachAsset(girlType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Create instrument
+ var instrument = self.attachAsset(instrumentType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 0,
+ y: -80
+ });
+ // Initially hide instrument
+ instrument.visible = false;
+ // Store references
+ self.girlBody = girlBody;
+ self.instrument = instrument;
+ // Method to play animation and sound
+ self.playMusic = function () {
+ if (self.isPlaying) return;
+ self.isPlaying = true;
+ // Show instrument
+ self.instrument.visible = true;
+ // Play sound
+ LK.getSound(self.soundId).play();
+ // Animate girl
+ tween(self.girlBody, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self.girlBody, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ }
+ });
+ // Animate instrument based on type
+ if (self.instrumentType === 'trumpet') {
+ tween(self.instrument, {
+ rotation: 0.2
+ }, {
+ duration: 300,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(self.instrument, {
+ rotation: 0
+ }, {
+ duration: 300,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ } else if (self.instrumentType === 'drums') {
+ tween(self.instrument, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 150,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self.instrument, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 150,
+ easing: tween.easeIn
+ });
+ }
+ });
+ } else if (self.instrumentType === 'accordion') {
+ tween(self.instrument, {
+ scaleX: 0.8,
+ scaleY: 1.2
+ }, {
+ duration: 250,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(self.instrument, {
+ scaleX: 1.0,
+ scaleY: 1.0
+ }, {
+ duration: 250,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ } else if (self.instrumentType === 'partyblower') {
+ tween(self.instrument, {
+ scaleX: 1.5,
+ rotation: 0.1
+ }, {
+ duration: 400,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self.instrument, {
+ scaleX: 1.0,
+ rotation: 0
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ }
+ });
+ }
+ // Hide instrument after animation
+ LK.setTimeout(function () {
+ self.instrument.visible = false;
+ self.isPlaying = false;
+ }, 800);
+ };
+ // Touch handler
+ self.down = function (x, y, obj) {
+ self.playMusic();
+ };
+ // Idle animation
+ self.startIdleAnimation = function () {
+ var _idleAnimation = function idleAnimation() {
+ if (!self.isPlaying) {
+ tween(self.girlBody, {
+ y: self.girlBody.y - 10
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(self.girlBody, {
+ y: self.girlBody.y + 10
+ }, {
+ duration: 1000,
+ easing: tween.easeInOut,
+ onFinish: _idleAnimation
+ });
+ }
+ });
+ } else {
+ LK.setTimeout(_idleAnimation, 100);
+ }
+ };
+ _idleAnimation();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+game.setBackgroundColor(0xFFB6C1);
+// Create title text
+var titleText = new Text2('Powerpuff Girls Musical Band', {
+ size: 120,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 50;
+// Create instruction text
+var instructionText = new Text2('Tap the Girls to Make Music!', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 1);
+LK.gui.bottom.addChild(instructionText);
+instructionText.y = -50;
+// Create Powerpuff Girls
+var blossom = new PowerpuffGirl('blossom', 'trumpet', 'trumpetSound');
+var bubbles = new PowerpuffGirl('bubbles', 'drums', 'drumSound');
+var buttercup = new PowerpuffGirl('buttercup', 'accordion', 'accordionSound');
+var bliss = new PowerpuffGirl('bliss', 'partyblower', 'partyblowerSound');
+// Position girls in a 2x2 grid
+var centerX = 2048 / 2;
+var centerY = 2732 / 2;
+var spacing = 450;
+// Top row
+blossom.x = centerX - spacing / 2;
+blossom.y = centerY - spacing / 2;
+bubbles.x = centerX + spacing / 2;
+bubbles.y = centerY - spacing / 2;
+// Bottom row
+buttercup.x = centerX - spacing / 2;
+buttercup.y = centerY + spacing / 2;
+bliss.x = centerX + spacing / 2;
+bliss.y = centerY + spacing / 2;
+// Add girls to game
+game.addChild(blossom);
+game.addChild(bubbles);
+game.addChild(buttercup);
+game.addChild(bliss);
+// Start idle animations
+blossom.startIdleAnimation();
+LK.setTimeout(function () {
+ bubbles.startIdleAnimation();
+}, 500);
+LK.setTimeout(function () {
+ buttercup.startIdleAnimation();
+}, 1000);
+LK.setTimeout(function () {
+ bliss.startIdleAnimation();
+}, 1500);
+// Game update loop
+game.update = function () {
+ // No specific updates needed for this musical game
+ // All interactions are handled by touch events on individual girls
+};
\ No newline at end of file