Code edit (1 edits merged)
Please save this source code
User prompt
Powerpuff Girls Toy Box
Initial prompt
Toca toy time (2004). The powerpuff girls have 18 toys. Tap on the toy Violet cat, or the toy frog, or the toy monkey, or the drum, or the accordion, or the trumpet, or the party blower, or the jelly, or the maraca, or the toy crane, or the toy car, or the toy truck, or the ball, or the toy alien, or the yoyo, or the jack in the box, or the guitar, or the radio to see it come to life
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Toy = Container.expand(function (assetId, soundId, animationType) { var self = Container.call(this); var toyGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.assetId = assetId; self.soundId = soundId; self.animationType = animationType; self.isAnimating = false; self.originalScale = 1; self.down = function (x, y, obj) { if (self.isAnimating) return; self.playAnimation(); }; self.playAnimation = function () { if (self.isAnimating) return; self.isAnimating = true; // Play sound effect LK.getSound(self.soundId).play(); // Different animations based on toy type switch (self.animationType) { case 'bounce': self.animateBounce(); break; case 'spin': self.animateSpin(); break; case 'pulse': self.animatePulse(); break; case 'wiggle': self.animateWiggle(); break; case 'hop': self.animateHop(); break; case 'glow': self.animateGlow(); break; case 'drive': self.animateDrive(); break; case 'pop': self.animatePop(); break; } }; self.animateBounce = function () { tween(self, { scaleY: 0.7 }, { duration: 200 }); tween(self, { scaleY: 1.3 }, { duration: 200, onFinish: function onFinish() { tween(self, { scaleY: 1 }, { duration: 200, onFinish: function onFinish() { self.isAnimating = false; } }); } }); }; self.animateSpin = function () { var originalRotation = self.rotation; tween(self, { rotation: originalRotation + Math.PI * 2 }, { duration: 800, onFinish: function onFinish() { self.rotation = originalRotation; self.isAnimating = false; } }); }; self.animatePulse = function () { tween(self, { scaleX: 1.4, scaleY: 1.4 }, { duration: 300, easing: tween.easeOut }); tween(self, { scaleX: 1, scaleY: 1 }, { duration: 300, onFinish: function onFinish() { self.isAnimating = false; } }); }; self.animateWiggle = function () { var originalRotation = self.rotation; tween(self, { rotation: originalRotation - 0.3 }, { duration: 100 }); tween(self, { rotation: originalRotation + 0.3 }, { duration: 100 }); tween(self, { rotation: originalRotation - 0.2 }, { duration: 100 }); tween(self, { rotation: originalRotation + 0.2 }, { duration: 100 }); tween(self, { rotation: originalRotation }, { duration: 100, onFinish: function onFinish() { self.isAnimating = false; } }); }; self.animateHop = function () { var originalY = self.y; tween(self, { y: originalY - 40 }, { duration: 200, easing: tween.easeOut }); tween(self, { y: originalY }, { duration: 200, easing: tween.easeIn, onFinish: function onFinish() { self.isAnimating = false; } }); }; self.animateGlow = function () { toyGraphics.tint = 0xFFFFFF; tween(toyGraphics, { tint: 0xFFFF00 }, { duration: 400 }); tween(toyGraphics, { tint: 0xFFFFFF }, { duration: 400, onFinish: function onFinish() { self.isAnimating = false; } }); }; self.animateDrive = function () { var originalX = self.x; tween(self, { x: originalX + 50 }, { duration: 400, easing: tween.easeInOut }); tween(self, { x: originalX }, { duration: 400, easing: tween.easeInOut, onFinish: function onFinish() { self.isAnimating = false; } }); }; self.animatePop = function () { tween(self, { scaleX: 0.3, scaleY: 0.3 }, { duration: 100 }); tween(self, { scaleX: 1.6, scaleY: 1.6 }, { duration: 200, easing: tween.bounceOut }); tween(self, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.isAnimating = false; } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xE6F3FF }); /**** * Game Code ****/ // Sound Effects // Fun Objects // Vehicles // Musical Instruments // Animals // Title text var titleText = new Text2('Powerpuff Girls Toy Box', { size: 80, fill: 0xFF1493 }); titleText.anchor.set(0.5, 0); LK.gui.top.addChild(titleText); titleText.y = 50; // Toy definitions with their properties var toyDefinitions = [ // Animals { asset: 'violetCat', sound: 'catMeow', animation: 'wiggle' }, { asset: 'frog', sound: 'frogHop', animation: 'hop' }, { asset: 'monkey', sound: 'monkeyChatter', animation: 'bounce' }, { asset: 'alien', sound: 'alienBeep', animation: 'pulse' }, // Musical Instruments { asset: 'drum', sound: 'drumBeat', animation: 'glow' }, { asset: 'accordion', sound: 'accordionNote', animation: 'wiggle' }, { asset: 'trumpet', sound: 'trumpetSound', animation: 'pulse' }, { asset: 'partyBlower', sound: 'partyNoise', animation: 'spin' }, { asset: 'maraca', sound: 'maracaShake', animation: 'wiggle' }, { asset: 'guitar', sound: 'guitarStrum', animation: 'pulse' }, { asset: 'radio', sound: 'radioTune', animation: 'glow' }, // Vehicles { asset: 'toyCrane', sound: 'craneSound', animation: 'drive' }, { asset: 'car', sound: 'carHorn', animation: 'drive' }, { asset: 'truck', sound: 'truckRev', animation: 'drive' }, // Fun Objects { asset: 'jelly', sound: 'jellyBounce', animation: 'bounce' }, { asset: 'ball', sound: 'ballBounce', animation: 'bounce' }, { asset: 'yoyo', sound: 'yoyoSpin', animation: 'spin' }, { asset: 'jackInBox', sound: 'jackPop', animation: 'pop' }]; // Create and position toys in a grid var toys = []; var startX = 200; var startY = 400; var spacing = 280; var toysPerRow = 6; for (var i = 0; i < toyDefinitions.length; i++) { var toyDef = toyDefinitions[i]; var toy = new Toy(toyDef.asset, toyDef.sound, toyDef.animation); var row = Math.floor(i / toysPerRow); var col = i % toysPerRow; toy.x = startX + col * spacing; toy.y = startY + row * spacing; game.addChild(toy); toys.push(toy); } // Center the grid horizontally var gridWidth = (toysPerRow - 1) * spacing; var offsetX = (2048 - gridWidth) / 2; for (var j = 0; j < toys.length; j++) { toys[j].x += offsetX - startX; }
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,346 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Toy = Container.expand(function (assetId, soundId, animationType) {
+ var self = Container.call(this);
+ var toyGraphics = self.attachAsset(assetId, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.assetId = assetId;
+ self.soundId = soundId;
+ self.animationType = animationType;
+ self.isAnimating = false;
+ self.originalScale = 1;
+ self.down = function (x, y, obj) {
+ if (self.isAnimating) return;
+ self.playAnimation();
+ };
+ self.playAnimation = function () {
+ if (self.isAnimating) return;
+ self.isAnimating = true;
+ // Play sound effect
+ LK.getSound(self.soundId).play();
+ // Different animations based on toy type
+ switch (self.animationType) {
+ case 'bounce':
+ self.animateBounce();
+ break;
+ case 'spin':
+ self.animateSpin();
+ break;
+ case 'pulse':
+ self.animatePulse();
+ break;
+ case 'wiggle':
+ self.animateWiggle();
+ break;
+ case 'hop':
+ self.animateHop();
+ break;
+ case 'glow':
+ self.animateGlow();
+ break;
+ case 'drive':
+ self.animateDrive();
+ break;
+ case 'pop':
+ self.animatePop();
+ break;
+ }
+ };
+ self.animateBounce = function () {
+ tween(self, {
+ scaleY: 0.7
+ }, {
+ duration: 200
+ });
+ tween(self, {
+ scaleY: 1.3
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleY: 1
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ }
+ });
+ };
+ self.animateSpin = function () {
+ var originalRotation = self.rotation;
+ tween(self, {
+ rotation: originalRotation + Math.PI * 2
+ }, {
+ duration: 800,
+ onFinish: function onFinish() {
+ self.rotation = originalRotation;
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animatePulse = function () {
+ tween(self, {
+ scaleX: 1.4,
+ scaleY: 1.4
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animateWiggle = function () {
+ var originalRotation = self.rotation;
+ tween(self, {
+ rotation: originalRotation - 0.3
+ }, {
+ duration: 100
+ });
+ tween(self, {
+ rotation: originalRotation + 0.3
+ }, {
+ duration: 100
+ });
+ tween(self, {
+ rotation: originalRotation - 0.2
+ }, {
+ duration: 100
+ });
+ tween(self, {
+ rotation: originalRotation + 0.2
+ }, {
+ duration: 100
+ });
+ tween(self, {
+ rotation: originalRotation
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animateHop = function () {
+ var originalY = self.y;
+ tween(self, {
+ y: originalY - 40
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ tween(self, {
+ y: originalY
+ }, {
+ duration: 200,
+ easing: tween.easeIn,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animateGlow = function () {
+ toyGraphics.tint = 0xFFFFFF;
+ tween(toyGraphics, {
+ tint: 0xFFFF00
+ }, {
+ duration: 400
+ });
+ tween(toyGraphics, {
+ tint: 0xFFFFFF
+ }, {
+ duration: 400,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animateDrive = function () {
+ var originalX = self.x;
+ tween(self, {
+ x: originalX + 50
+ }, {
+ duration: 400,
+ easing: tween.easeInOut
+ });
+ tween(self, {
+ x: originalX
+ }, {
+ duration: 400,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ self.animatePop = function () {
+ tween(self, {
+ scaleX: 0.3,
+ scaleY: 0.3
+ }, {
+ duration: 100
+ });
+ tween(self, {
+ scaleX: 1.6,
+ scaleY: 1.6
+ }, {
+ duration: 200,
+ easing: tween.bounceOut
+ });
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xE6F3FF
+});
+
+/****
+* Game Code
+****/
+// Sound Effects
+// Fun Objects
+// Vehicles
+// Musical Instruments
+// Animals
+// Title text
+var titleText = new Text2('Powerpuff Girls Toy Box', {
+ size: 80,
+ fill: 0xFF1493
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 50;
+// Toy definitions with their properties
+var toyDefinitions = [
+// Animals
+{
+ asset: 'violetCat',
+ sound: 'catMeow',
+ animation: 'wiggle'
+}, {
+ asset: 'frog',
+ sound: 'frogHop',
+ animation: 'hop'
+}, {
+ asset: 'monkey',
+ sound: 'monkeyChatter',
+ animation: 'bounce'
+}, {
+ asset: 'alien',
+ sound: 'alienBeep',
+ animation: 'pulse'
+},
+// Musical Instruments
+{
+ asset: 'drum',
+ sound: 'drumBeat',
+ animation: 'glow'
+}, {
+ asset: 'accordion',
+ sound: 'accordionNote',
+ animation: 'wiggle'
+}, {
+ asset: 'trumpet',
+ sound: 'trumpetSound',
+ animation: 'pulse'
+}, {
+ asset: 'partyBlower',
+ sound: 'partyNoise',
+ animation: 'spin'
+}, {
+ asset: 'maraca',
+ sound: 'maracaShake',
+ animation: 'wiggle'
+}, {
+ asset: 'guitar',
+ sound: 'guitarStrum',
+ animation: 'pulse'
+}, {
+ asset: 'radio',
+ sound: 'radioTune',
+ animation: 'glow'
+},
+// Vehicles
+{
+ asset: 'toyCrane',
+ sound: 'craneSound',
+ animation: 'drive'
+}, {
+ asset: 'car',
+ sound: 'carHorn',
+ animation: 'drive'
+}, {
+ asset: 'truck',
+ sound: 'truckRev',
+ animation: 'drive'
+},
+// Fun Objects
+{
+ asset: 'jelly',
+ sound: 'jellyBounce',
+ animation: 'bounce'
+}, {
+ asset: 'ball',
+ sound: 'ballBounce',
+ animation: 'bounce'
+}, {
+ asset: 'yoyo',
+ sound: 'yoyoSpin',
+ animation: 'spin'
+}, {
+ asset: 'jackInBox',
+ sound: 'jackPop',
+ animation: 'pop'
+}];
+// Create and position toys in a grid
+var toys = [];
+var startX = 200;
+var startY = 400;
+var spacing = 280;
+var toysPerRow = 6;
+for (var i = 0; i < toyDefinitions.length; i++) {
+ var toyDef = toyDefinitions[i];
+ var toy = new Toy(toyDef.asset, toyDef.sound, toyDef.animation);
+ var row = Math.floor(i / toysPerRow);
+ var col = i % toysPerRow;
+ toy.x = startX + col * spacing;
+ toy.y = startY + row * spacing;
+ game.addChild(toy);
+ toys.push(toy);
+}
+// Center the grid horizontally
+var gridWidth = (toysPerRow - 1) * spacing;
+var offsetX = (2048 - gridWidth) / 2;
+for (var j = 0; j < toys.length; j++) {
+ toys[j].x += offsetX - startX;
+}
\ No newline at end of file