Code edit (1 edits merged)
Please save this source code
User prompt
Surprise Box Adventure
Initial prompt
Toca delivery (2004-2005). The powerpuff girls have 6 boxes. Tap on the box to shake it and then tap it to open. It will be a toy Violet cat, or toy frog, or toy monkey, or party blower, or jelly, or radio inside. Tap on your toy to see what it does, tap on your toy and see what happens. Tap on the how to play button.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var MysteryBox = Container.expand(function () { var self = Container.call(this); self.state = 'closed'; // 'closed', 'shaking', 'opened' self.toyType = null; self.toy = null; // Create box graphics var boxGraphics = self.attachAsset('box', { anchorX: 0.5, anchorY: 0.5 }); var lidGraphics = self.attachAsset('boxLid', { anchorX: 0.5, anchorY: 1, y: -150 }); self.boxGraphics = boxGraphics; self.lidGraphics = lidGraphics; self.shake = function () { if (self.state !== 'closed') return; self.state = 'shaking'; LK.getSound('shake').play(); // Shake animation var originalX = self.x; var shakeAmount = 10; var shakeCount = 0; var maxShakes = 8; function doShake() { if (shakeCount < maxShakes) { self.x = originalX + (Math.random() - 0.5) * shakeAmount; shakeCount++; LK.setTimeout(doShake, 100); } else { self.x = originalX; } } doShake(); }; self.open = function () { if (self.state !== 'shaking') return; self.state = 'opened'; LK.getSound('open').play(); // Animate lid opening tween(self.lidGraphics, { y: -250, rotation: -0.5 }, { duration: 500 }); // Create random toy var toyTypes = ['cat', 'frog', 'monkey', 'partyBlower', 'jelly', 'radio']; self.toyType = toyTypes[Math.floor(Math.random() * toyTypes.length)]; LK.setTimeout(function () { self.createToy(); }, 300); }; self.createToy = function () { if (self.toy) return; self.toy = self.addChild(new Toy(self.toyType)); self.toy.x = 0; self.toy.y = 0; }; self.down = function (x, y, obj) { if (self.state === 'closed') { self.shake(); } else if (self.state === 'shaking') { self.open(); } }; return self; }); var Toy = Container.expand(function (toyType) { var self = Container.call(this); self.toyType = toyType; self.isAnimating = false; // Create toy graphics based on type var toyGraphics = self.attachAsset(toyType, { anchorX: 0.5, anchorY: 0.5 }); self.toyGraphics = toyGraphics; // Appear animation toyGraphics.alpha = 0; toyGraphics.scaleX = 0.1; toyGraphics.scaleY = 0.1; tween(toyGraphics, { alpha: 1, scaleX: 1, scaleY: 1 }, { duration: 600, easing: tween.bounceOut }); self.interact = function () { if (self.isAnimating) return; self.isAnimating = true; switch (self.toyType) { case 'cat': LK.getSound('meow').play(); tween(self.toyGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200 }); tween(self.toyGraphics, { scaleX: 1, scaleY: 1 }, { duration: 200, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'frog': LK.getSound('ribbit').play(); var originalY = self.toyGraphics.y; tween(self.toyGraphics, { y: originalY - 50 }, { duration: 300, easing: tween.easeOut }); tween(self.toyGraphics, { y: originalY }, { duration: 300, easing: tween.bounceOut, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'monkey': LK.getSound('monkey_sound').play(); var originalRotation = self.toyGraphics.rotation; tween(self.toyGraphics, { rotation: originalRotation + Math.PI * 2 }, { duration: 800, onFinish: function onFinish() { self.toyGraphics.rotation = originalRotation; self.isAnimating = false; } }); break; case 'partyBlower': LK.getSound('party_sound').play(); tween(self.toyGraphics, { scaleX: 1.5 }, { duration: 400 }); tween(self.toyGraphics, { scaleX: 1 }, { duration: 400, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'jelly': LK.getSound('jelly_sound').play(); tween(self.toyGraphics, { scaleY: 0.7, scaleX: 1.2 }, { duration: 200 }); tween(self.toyGraphics, { scaleY: 1.2, scaleX: 0.8 }, { duration: 200 }); tween(self.toyGraphics, { scaleY: 1, scaleX: 1 }, { duration: 200, onFinish: function onFinish() { self.isAnimating = false; } }); break; case 'radio': LK.getSound('radio_sound').play(); LK.effects.flashObject(self.toyGraphics, 0xFFFF00, 1000); LK.setTimeout(function () { self.isAnimating = false; }, 1000); break; } }; self.down = function (x, y, obj) { self.interact(); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var boxes = []; var boxPositions = [{ x: 400, y: 500 }, { x: 1000, y: 400 }, { x: 1600, y: 600 }, { x: 500, y: 1200 }, { x: 1200, y: 1300 }, { x: 1700, y: 1100 }]; // Create title text var titleText = new Text2('Surprise Box Adventure', { size: 80, fill: 0x2F4F4F }); titleText.anchor.set(0.5, 0); titleText.x = 1024; titleText.y = 100; game.addChild(titleText); // Create instruction text var instructionText = new Text2('Tap boxes to shake and open them!', { size: 50, fill: 0x4682B4 }); instructionText.anchor.set(0.5, 0); instructionText.x = 1024; instructionText.y = 200; game.addChild(instructionText); // Create mystery boxes for (var i = 0; i < 6; i++) { var box = new MysteryBox(); box.x = boxPositions[i].x; box.y = boxPositions[i].y; boxes.push(box); game.addChild(box); } game.update = function () { // Game runs continuously, no specific update logic needed for this game };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,268 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var MysteryBox = Container.expand(function () {
+ var self = Container.call(this);
+ self.state = 'closed'; // 'closed', 'shaking', 'opened'
+ self.toyType = null;
+ self.toy = null;
+ // Create box graphics
+ var boxGraphics = self.attachAsset('box', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var lidGraphics = self.attachAsset('boxLid', {
+ anchorX: 0.5,
+ anchorY: 1,
+ y: -150
+ });
+ self.boxGraphics = boxGraphics;
+ self.lidGraphics = lidGraphics;
+ self.shake = function () {
+ if (self.state !== 'closed') return;
+ self.state = 'shaking';
+ LK.getSound('shake').play();
+ // Shake animation
+ var originalX = self.x;
+ var shakeAmount = 10;
+ var shakeCount = 0;
+ var maxShakes = 8;
+ function doShake() {
+ if (shakeCount < maxShakes) {
+ self.x = originalX + (Math.random() - 0.5) * shakeAmount;
+ shakeCount++;
+ LK.setTimeout(doShake, 100);
+ } else {
+ self.x = originalX;
+ }
+ }
+ doShake();
+ };
+ self.open = function () {
+ if (self.state !== 'shaking') return;
+ self.state = 'opened';
+ LK.getSound('open').play();
+ // Animate lid opening
+ tween(self.lidGraphics, {
+ y: -250,
+ rotation: -0.5
+ }, {
+ duration: 500
+ });
+ // Create random toy
+ var toyTypes = ['cat', 'frog', 'monkey', 'partyBlower', 'jelly', 'radio'];
+ self.toyType = toyTypes[Math.floor(Math.random() * toyTypes.length)];
+ LK.setTimeout(function () {
+ self.createToy();
+ }, 300);
+ };
+ self.createToy = function () {
+ if (self.toy) return;
+ self.toy = self.addChild(new Toy(self.toyType));
+ self.toy.x = 0;
+ self.toy.y = 0;
+ };
+ self.down = function (x, y, obj) {
+ if (self.state === 'closed') {
+ self.shake();
+ } else if (self.state === 'shaking') {
+ self.open();
+ }
+ };
+ return self;
+});
+var Toy = Container.expand(function (toyType) {
+ var self = Container.call(this);
+ self.toyType = toyType;
+ self.isAnimating = false;
+ // Create toy graphics based on type
+ var toyGraphics = self.attachAsset(toyType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.toyGraphics = toyGraphics;
+ // Appear animation
+ toyGraphics.alpha = 0;
+ toyGraphics.scaleX = 0.1;
+ toyGraphics.scaleY = 0.1;
+ tween(toyGraphics, {
+ alpha: 1,
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 600,
+ easing: tween.bounceOut
+ });
+ self.interact = function () {
+ if (self.isAnimating) return;
+ self.isAnimating = true;
+ switch (self.toyType) {
+ case 'cat':
+ LK.getSound('meow').play();
+ tween(self.toyGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200
+ });
+ tween(self.toyGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ break;
+ case 'frog':
+ LK.getSound('ribbit').play();
+ var originalY = self.toyGraphics.y;
+ tween(self.toyGraphics, {
+ y: originalY - 50
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ tween(self.toyGraphics, {
+ y: originalY
+ }, {
+ duration: 300,
+ easing: tween.bounceOut,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ break;
+ case 'monkey':
+ LK.getSound('monkey_sound').play();
+ var originalRotation = self.toyGraphics.rotation;
+ tween(self.toyGraphics, {
+ rotation: originalRotation + Math.PI * 2
+ }, {
+ duration: 800,
+ onFinish: function onFinish() {
+ self.toyGraphics.rotation = originalRotation;
+ self.isAnimating = false;
+ }
+ });
+ break;
+ case 'partyBlower':
+ LK.getSound('party_sound').play();
+ tween(self.toyGraphics, {
+ scaleX: 1.5
+ }, {
+ duration: 400
+ });
+ tween(self.toyGraphics, {
+ scaleX: 1
+ }, {
+ duration: 400,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ break;
+ case 'jelly':
+ LK.getSound('jelly_sound').play();
+ tween(self.toyGraphics, {
+ scaleY: 0.7,
+ scaleX: 1.2
+ }, {
+ duration: 200
+ });
+ tween(self.toyGraphics, {
+ scaleY: 1.2,
+ scaleX: 0.8
+ }, {
+ duration: 200
+ });
+ tween(self.toyGraphics, {
+ scaleY: 1,
+ scaleX: 1
+ }, {
+ duration: 200,
+ onFinish: function onFinish() {
+ self.isAnimating = false;
+ }
+ });
+ break;
+ case 'radio':
+ LK.getSound('radio_sound').play();
+ LK.effects.flashObject(self.toyGraphics, 0xFFFF00, 1000);
+ LK.setTimeout(function () {
+ self.isAnimating = false;
+ }, 1000);
+ break;
+ }
+ };
+ self.down = function (x, y, obj) {
+ self.interact();
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+var boxes = [];
+var boxPositions = [{
+ x: 400,
+ y: 500
+}, {
+ x: 1000,
+ y: 400
+}, {
+ x: 1600,
+ y: 600
+}, {
+ x: 500,
+ y: 1200
+}, {
+ x: 1200,
+ y: 1300
+}, {
+ x: 1700,
+ y: 1100
+}];
+// Create title text
+var titleText = new Text2('Surprise Box Adventure', {
+ size: 80,
+ fill: 0x2F4F4F
+});
+titleText.anchor.set(0.5, 0);
+titleText.x = 1024;
+titleText.y = 100;
+game.addChild(titleText);
+// Create instruction text
+var instructionText = new Text2('Tap boxes to shake and open them!', {
+ size: 50,
+ fill: 0x4682B4
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.x = 1024;
+instructionText.y = 200;
+game.addChild(instructionText);
+// Create mystery boxes
+for (var i = 0; i < 6; i++) {
+ var box = new MysteryBox();
+ box.x = boxPositions[i].x;
+ box.y = boxPositions[i].y;
+ boxes.push(box);
+ game.addChild(box);
+}
+game.update = function () {
+ // Game runs continuously, no specific update logic needed for this game
+};
\ No newline at end of file