Code edit (1 edits merged)
Please save this source code
User prompt
Bubbles' Magical Unicorn
Initial prompt
Powerpuff girls: bubbles’s fluffy unicorn (2013). Press the unicorn’s hoof you’ll hear phrases and sound effects and chimes and trotting sounds. Press the hoof 2 times bubbles’s voice will sing the unicorn song.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bubbles = Container.expand(function () {
var self = Container.call(this);
var bubblesBody = self.attachAsset('bubbles', {
anchorX: 0.5,
anchorY: 1
});
self.singAnimation = function () {
var originalScale = bubblesBody.scaleX;
tween(bubblesBody, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 300,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(bubblesBody, {
scaleX: originalScale,
scaleY: originalScale
}, {
duration: 300,
easing: tween.easeInOut
});
}
});
};
return self;
});
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5
});
self.animate = function () {
sparkleGraphics.alpha = 1;
sparkleGraphics.scaleX = 0.5;
sparkleGraphics.scaleY = 0.5;
tween(sparkleGraphics, {
alpha: 0,
scaleX: 2,
scaleY: 2
}, {
duration: 800,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Unicorn = Container.expand(function () {
var self = Container.call(this);
var unicornBody = self.attachAsset('unicorn', {
anchorX: 0.5,
anchorY: 0.5
});
var hoof = self.attachAsset('unicornHoof', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 150
});
self.animateHoofTap = function () {
var originalScale = hoof.scaleX;
tween(hoof, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 100,
onFinish: function onFinish() {
tween(hoof, {
scaleX: originalScale,
scaleY: originalScale
}, {
duration: 100
});
}
});
};
self.animateBody = function () {
var originalY = unicornBody.y;
tween(unicornBody, {
y: originalY - 20
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(unicornBody, {
y: originalY
}, {
duration: 200,
easing: tween.easeIn
});
}
});
};
self.down = function (x, y, obj) {
var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
var hoofBounds = {
left: hoof.x - hoof.width / 2,
right: hoof.x + hoof.width / 2,
top: hoof.y - hoof.height / 2,
bottom: hoof.y + hoof.height / 2
};
if (localPos.x >= hoofBounds.left && localPos.x <= hoofBounds.right && localPos.y >= hoofBounds.top && localPos.y <= hoofBounds.bottom) {
handleHoofTap();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
var unicorn = game.addChild(new Unicorn());
unicorn.x = 1024;
unicorn.y = 1200;
var bubbles = game.addChild(new Bubbles());
bubbles.x = 400;
bubbles.y = 1400;
var scoreTxt = new Text2('Taps: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var totalTaps = storage.totalTaps || 0;
var lastTapTime = 0;
var doubleTapWindow = 500;
var soundVariations = ['chime1', 'chime2', 'trot1', 'trot2', 'magical1', 'magical2'];
scoreTxt.setText('Taps: ' + totalTaps);
function createSparkles(x, y) {
for (var i = 0; i < 5; i++) {
var sparkle = game.addChild(new Sparkle());
sparkle.x = x + (Math.random() - 0.5) * 200;
sparkle.y = y + (Math.random() - 0.5) * 200;
LK.setTimeout(function (s) {
return function () {
s.animate();
};
}(sparkle), i * 100);
}
}
function handleHoofTap() {
var currentTime = Date.now();
var isDoubleTap = currentTime - lastTapTime < doubleTapWindow;
totalTaps++;
storage.totalTaps = totalTaps;
scoreTxt.setText('Taps: ' + totalTaps);
unicorn.animateHoofTap();
createSparkles(unicorn.x + 150, unicorn.y + 150);
if (isDoubleTap) {
bubbles.singAnimation();
LK.getSound('unicornSong').play();
unicorn.animateBody();
LK.effects.flashScreen(0xFFD700, 500);
} else {
var randomSound = soundVariations[Math.floor(Math.random() * soundVariations.length)];
LK.getSound(randomSound).play();
if (totalTaps > 10 && Math.random() < 0.3) {
unicorn.animateBody();
}
}
lastTapTime = currentTime;
}
game.update = function () {
// Continuous sparkle generation for ambient magic
if (LK.ticks % 180 == 0) {
var ambientSparkle = game.addChild(new Sparkle());
ambientSparkle.x = Math.random() * 2048;
ambientSparkle.y = Math.random() * 1000 + 500;
ambientSparkle.animate();
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,197 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var Bubbles = Container.expand(function () {
+ var self = Container.call(this);
+ var bubblesBody = self.attachAsset('bubbles', {
+ anchorX: 0.5,
+ anchorY: 1
+ });
+ self.singAnimation = function () {
+ var originalScale = bubblesBody.scaleX;
+ tween(bubblesBody, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 300,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(bubblesBody, {
+ scaleX: originalScale,
+ scaleY: originalScale
+ }, {
+ duration: 300,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ };
+ return self;
+});
+var Sparkle = Container.expand(function () {
+ var self = Container.call(this);
+ var sparkleGraphics = self.attachAsset('sparkle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.animate = function () {
+ sparkleGraphics.alpha = 1;
+ sparkleGraphics.scaleX = 0.5;
+ sparkleGraphics.scaleY = 0.5;
+ tween(sparkleGraphics, {
+ alpha: 0,
+ scaleX: 2,
+ scaleY: 2
+ }, {
+ duration: 800,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.destroy();
+ }
+ });
+ };
+ return self;
+});
+var Unicorn = Container.expand(function () {
+ var self = Container.call(this);
+ var unicornBody = self.attachAsset('unicorn', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var hoof = self.attachAsset('unicornHoof', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 150,
+ y: 150
+ });
+ self.animateHoofTap = function () {
+ var originalScale = hoof.scaleX;
+ tween(hoof, {
+ scaleX: 1.3,
+ scaleY: 1.3
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(hoof, {
+ scaleX: originalScale,
+ scaleY: originalScale
+ }, {
+ duration: 100
+ });
+ }
+ });
+ };
+ self.animateBody = function () {
+ var originalY = unicornBody.y;
+ tween(unicornBody, {
+ y: originalY - 20
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(unicornBody, {
+ y: originalY
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ }
+ });
+ };
+ self.down = function (x, y, obj) {
+ var localPos = self.toLocal(obj.parent.toGlobal(obj.position));
+ var hoofBounds = {
+ left: hoof.x - hoof.width / 2,
+ right: hoof.x + hoof.width / 2,
+ top: hoof.y - hoof.height / 2,
+ bottom: hoof.y + hoof.height / 2
+ };
+ if (localPos.x >= hoofBounds.left && localPos.x <= hoofBounds.right && localPos.y >= hoofBounds.top && localPos.y <= hoofBounds.bottom) {
+ handleHoofTap();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var background = game.attachAsset('background', {
+ anchorX: 0,
+ anchorY: 0,
+ x: 0,
+ y: 0
+});
+var unicorn = game.addChild(new Unicorn());
+unicorn.x = 1024;
+unicorn.y = 1200;
+var bubbles = game.addChild(new Bubbles());
+bubbles.x = 400;
+bubbles.y = 1400;
+var scoreTxt = new Text2('Taps: 0', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+scoreTxt.anchor.set(0.5, 0);
+LK.gui.top.addChild(scoreTxt);
+var totalTaps = storage.totalTaps || 0;
+var lastTapTime = 0;
+var doubleTapWindow = 500;
+var soundVariations = ['chime1', 'chime2', 'trot1', 'trot2', 'magical1', 'magical2'];
+scoreTxt.setText('Taps: ' + totalTaps);
+function createSparkles(x, y) {
+ for (var i = 0; i < 5; i++) {
+ var sparkle = game.addChild(new Sparkle());
+ sparkle.x = x + (Math.random() - 0.5) * 200;
+ sparkle.y = y + (Math.random() - 0.5) * 200;
+ LK.setTimeout(function (s) {
+ return function () {
+ s.animate();
+ };
+ }(sparkle), i * 100);
+ }
+}
+function handleHoofTap() {
+ var currentTime = Date.now();
+ var isDoubleTap = currentTime - lastTapTime < doubleTapWindow;
+ totalTaps++;
+ storage.totalTaps = totalTaps;
+ scoreTxt.setText('Taps: ' + totalTaps);
+ unicorn.animateHoofTap();
+ createSparkles(unicorn.x + 150, unicorn.y + 150);
+ if (isDoubleTap) {
+ bubbles.singAnimation();
+ LK.getSound('unicornSong').play();
+ unicorn.animateBody();
+ LK.effects.flashScreen(0xFFD700, 500);
+ } else {
+ var randomSound = soundVariations[Math.floor(Math.random() * soundVariations.length)];
+ LK.getSound(randomSound).play();
+ if (totalTaps > 10 && Math.random() < 0.3) {
+ unicorn.animateBody();
+ }
+ }
+ lastTapTime = currentTime;
+}
+game.update = function () {
+ // Continuous sparkle generation for ambient magic
+ if (LK.ticks % 180 == 0) {
+ var ambientSparkle = game.addChild(new Sparkle());
+ ambientSparkle.x = Math.random() * 2048;
+ ambientSparkle.y = Math.random() * 1000 + 500;
+ ambientSparkle.animate();
+ }
+};
\ No newline at end of file