Code edit (1 edits merged)
Please save this source code
User prompt
Party Gift Surprise
Initial prompt
Toca presents (2001). The powerpuff girls are having a party inside. Tap on 6 gifts to choose, tap on the gift to shake it then open it, it will be a kazoo, a party blower, drums, a xylophone, or a toy frog inside, tap on your gift to see what it does, tap on your gift and see what happens
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Drum = Container.expand(function () {
var self = Container.call(this);
var drum = self.attachAsset('drum', {
anchorX: 0.5,
anchorY: 0.5
});
var stick1 = self.attachAsset('drumstick', {
anchorX: 0.5,
anchorY: 0.5,
x: -60,
y: -80,
rotation: -Math.PI / 4
});
var stick2 = self.attachAsset('drumstick', {
anchorX: 0.5,
anchorY: 0.5,
x: 60,
y: -80,
rotation: Math.PI / 4
});
self.down = function (x, y, obj) {
LK.getSound('drumBeat').play();
tween(drum, {
scaleY: 0.9
}, {
duration: 100
});
tween(stick1, {
y: -60
}, {
duration: 100
});
tween(stick2, {
y: -60
}, {
duration: 100
});
LK.setTimeout(function () {
tween(drum, {
scaleY: 1
}, {
duration: 100
});
tween(stick1, {
y: -80
}, {
duration: 100
});
tween(stick2, {
y: -80
}, {
duration: 100
});
}, 100);
};
return self;
});
var GiftBox = Container.expand(function () {
var self = Container.call(this);
self.isOpened = false;
self.toyType = '';
self.isShaking = false;
var box = self.attachAsset('giftBox', {
anchorX: 0.5,
anchorY: 0.5
});
var ribbonH = self.attachAsset('giftRibbon', {
anchorX: 0.5,
anchorY: 0.5
});
var ribbonV = self.attachAsset('giftRibbon', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.PI / 2
});
var bow = self.attachAsset('giftBow', {
anchorX: 0.5,
anchorY: 0.5,
y: -120
});
self.setToyType = function (type) {
self.toyType = type;
};
self.shake = function () {
if (self.isOpened || self.isShaking) return;
self.isShaking = true;
LK.getSound('giftShake').play();
tween(self, {
rotation: -0.1
}, {
duration: 100
});
LK.setTimeout(function () {
tween(self, {
rotation: 0.1
}, {
duration: 100
});
}, 100);
LK.setTimeout(function () {
tween(self, {
rotation: 0
}, {
duration: 100,
onFinish: function onFinish() {
self.isShaking = false;
}
});
}, 200);
};
self.unwrap = function () {
if (self.isOpened) return;
self.isOpened = true;
LK.getSound('unwrap').play();
tween(box, {
alpha: 0
}, {
duration: 500
});
tween(ribbonH, {
alpha: 0
}, {
duration: 500
});
tween(ribbonV, {
alpha: 0
}, {
duration: 500
});
tween(bow, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
self.createToy();
}
});
};
self.createToy = function () {
var toy = null;
if (self.toyType === 'kazoo') {
toy = self.addChild(new Kazoo());
} else if (self.toyType === 'partyBlower') {
toy = self.addChild(new PartyBlower());
} else if (self.toyType === 'drum') {
toy = self.addChild(new Drum());
} else if (self.toyType === 'xylophone') {
toy = self.addChild(new Xylophone());
} else if (self.toyType === 'toyFrog') {
toy = self.addChild(new ToyFrog());
}
};
self.down = function (x, y, obj) {
if (!self.isOpened) {
self.shake();
LK.setTimeout(function () {
self.unwrap();
}, 600);
}
};
return self;
});
var Kazoo = Container.expand(function () {
var self = Container.call(this);
var kazoo = self.attachAsset('kazoo', {
anchorX: 0.5,
anchorY: 0.5,
rotation: Math.PI / 4
});
self.down = function (x, y, obj) {
LK.getSound('kazooSound').play();
tween(kazoo, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200
});
LK.setTimeout(function () {
tween(kazoo, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}, 200);
};
return self;
});
var PartyBlower = Container.expand(function () {
var self = Container.call(this);
var blower = self.attachAsset('partyBlower', {
anchorX: 0.5,
anchorY: 0.5
});
var extension = self.attachAsset('blowerExtension', {
anchorX: 0,
anchorY: 0.5,
x: 30,
scaleX: 0
});
self.isExtended = false;
self.down = function (x, y, obj) {
LK.getSound('blowerSound').play();
if (!self.isExtended) {
tween(extension, {
scaleX: 1
}, {
duration: 300
});
self.isExtended = true;
} else {
tween(extension, {
scaleX: 0
}, {
duration: 300
});
self.isExtended = false;
}
};
return self;
});
var ToyFrog = Container.expand(function () {
var self = Container.call(this);
var frog = self.attachAsset('toyFrog', {
anchorX: 0.5,
anchorY: 0.5
});
var eye1 = self.attachAsset('frogEye', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: -20
});
var eye2 = self.attachAsset('frogEye', {
anchorX: 0.5,
anchorY: 0.5,
x: 30,
y: -20
});
self.isHopping = false;
self.hop = function () {
if (self.isHopping) return;
self.isHopping = true;
LK.getSound('frogHop').play();
tween(self, {
y: self.y - 50
}, {
duration: 200,
easing: tween.easeOut
});
LK.setTimeout(function () {
tween(self, {
y: self.y + 50
}, {
duration: 200,
easing: tween.easeIn,
onFinish: function onFinish() {
self.isHopping = false;
}
});
}, 200);
};
self.down = function (x, y, obj) {
self.hop();
};
return self;
});
var Xylophone = Container.expand(function () {
var self = Container.call(this);
var base = self.attachAsset('xylophone', {
anchorX: 0.5,
anchorY: 0.5
});
self.keys = [];
var colors = [0xff0000, 0xff8800, 0xffff00, 0x00ff00, 0x0088ff, 0x8800ff];
for (var i = 0; i < 6; i++) {
var key = self.attachAsset('xyloKey', {
anchorX: 0.5,
anchorY: 0.5,
x: -125 + i * 50,
tint: colors[i]
});
key.keyIndex = i;
self.keys.push(key);
}
self.playKey = function (keyIndex) {
LK.getSound('xyloNote').play();
var key = self.keys[keyIndex];
tween(key, {
y: 20
}, {
duration: 100
});
LK.setTimeout(function () {
tween(key, {
y: 0
}, {
duration: 100
});
}, 100);
};
self.down = function (x, y, obj) {
for (var i = 0; i < self.keys.length; i++) {
var key = self.keys[i];
var keyPos = self.toLocal(key.parent.toGlobal(key.position));
if (Math.abs(x - keyPos.x) < 25 && Math.abs(y - keyPos.y) < 50) {
self.playKey(i);
break;
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xffeecc
});
/****
* Game Code
****/
var giftBoxes = [];
var toyTypes = ['kazoo', 'partyBlower', 'drum', 'xylophone', 'toyFrog', 'kazoo'];
var titleText = new Text2('Party Gift Surprise!', {
size: 120,
fill: 0xFF4444
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 50;
var instructionText = new Text2('Tap gifts to shake and unwrap them!', {
size: 80,
fill: 0x444444
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
instructionText.y = 200;
for (var i = 0; i < 6; i++) {
var gift = new GiftBox();
gift.setToyType(toyTypes[i]);
var row = Math.floor(i / 3);
var col = i % 3;
gift.x = 350 + col * 450;
gift.y = 800 + row * 450;
giftBoxes.push(gift);
game.addChild(gift);
}
game.update = function () {
// Game logic updates here if needed
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,361 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Drum = Container.expand(function () {
+ var self = Container.call(this);
+ var drum = self.attachAsset('drum', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var stick1 = self.attachAsset('drumstick', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -60,
+ y: -80,
+ rotation: -Math.PI / 4
+ });
+ var stick2 = self.attachAsset('drumstick', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 60,
+ y: -80,
+ rotation: Math.PI / 4
+ });
+ self.down = function (x, y, obj) {
+ LK.getSound('drumBeat').play();
+ tween(drum, {
+ scaleY: 0.9
+ }, {
+ duration: 100
+ });
+ tween(stick1, {
+ y: -60
+ }, {
+ duration: 100
+ });
+ tween(stick2, {
+ y: -60
+ }, {
+ duration: 100
+ });
+ LK.setTimeout(function () {
+ tween(drum, {
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ tween(stick1, {
+ y: -80
+ }, {
+ duration: 100
+ });
+ tween(stick2, {
+ y: -80
+ }, {
+ duration: 100
+ });
+ }, 100);
+ };
+ return self;
+});
+var GiftBox = Container.expand(function () {
+ var self = Container.call(this);
+ self.isOpened = false;
+ self.toyType = '';
+ self.isShaking = false;
+ var box = self.attachAsset('giftBox', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var ribbonH = self.attachAsset('giftRibbon', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var ribbonV = self.attachAsset('giftRibbon', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / 2
+ });
+ var bow = self.attachAsset('giftBow', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -120
+ });
+ self.setToyType = function (type) {
+ self.toyType = type;
+ };
+ self.shake = function () {
+ if (self.isOpened || self.isShaking) return;
+ self.isShaking = true;
+ LK.getSound('giftShake').play();
+ tween(self, {
+ rotation: -0.1
+ }, {
+ duration: 100
+ });
+ LK.setTimeout(function () {
+ tween(self, {
+ rotation: 0.1
+ }, {
+ duration: 100
+ });
+ }, 100);
+ LK.setTimeout(function () {
+ tween(self, {
+ rotation: 0
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ self.isShaking = false;
+ }
+ });
+ }, 200);
+ };
+ self.unwrap = function () {
+ if (self.isOpened) return;
+ self.isOpened = true;
+ LK.getSound('unwrap').play();
+ tween(box, {
+ alpha: 0
+ }, {
+ duration: 500
+ });
+ tween(ribbonH, {
+ alpha: 0
+ }, {
+ duration: 500
+ });
+ tween(ribbonV, {
+ alpha: 0
+ }, {
+ duration: 500
+ });
+ tween(bow, {
+ alpha: 0
+ }, {
+ duration: 500,
+ onFinish: function onFinish() {
+ self.createToy();
+ }
+ });
+ };
+ self.createToy = function () {
+ var toy = null;
+ if (self.toyType === 'kazoo') {
+ toy = self.addChild(new Kazoo());
+ } else if (self.toyType === 'partyBlower') {
+ toy = self.addChild(new PartyBlower());
+ } else if (self.toyType === 'drum') {
+ toy = self.addChild(new Drum());
+ } else if (self.toyType === 'xylophone') {
+ toy = self.addChild(new Xylophone());
+ } else if (self.toyType === 'toyFrog') {
+ toy = self.addChild(new ToyFrog());
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (!self.isOpened) {
+ self.shake();
+ LK.setTimeout(function () {
+ self.unwrap();
+ }, 600);
+ }
+ };
+ return self;
+});
+var Kazoo = Container.expand(function () {
+ var self = Container.call(this);
+ var kazoo = self.attachAsset('kazoo', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ rotation: Math.PI / 4
+ });
+ self.down = function (x, y, obj) {
+ LK.getSound('kazooSound').play();
+ tween(kazoo, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200
+ });
+ LK.setTimeout(function () {
+ tween(kazoo, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200
+ });
+ }, 200);
+ };
+ return self;
+});
+var PartyBlower = Container.expand(function () {
+ var self = Container.call(this);
+ var blower = self.attachAsset('partyBlower', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var extension = self.attachAsset('blowerExtension', {
+ anchorX: 0,
+ anchorY: 0.5,
+ x: 30,
+ scaleX: 0
+ });
+ self.isExtended = false;
+ self.down = function (x, y, obj) {
+ LK.getSound('blowerSound').play();
+ if (!self.isExtended) {
+ tween(extension, {
+ scaleX: 1
+ }, {
+ duration: 300
+ });
+ self.isExtended = true;
+ } else {
+ tween(extension, {
+ scaleX: 0
+ }, {
+ duration: 300
+ });
+ self.isExtended = false;
+ }
+ };
+ return self;
+});
+var ToyFrog = Container.expand(function () {
+ var self = Container.call(this);
+ var frog = self.attachAsset('toyFrog', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var eye1 = self.attachAsset('frogEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -30,
+ y: -20
+ });
+ var eye2 = self.attachAsset('frogEye', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 30,
+ y: -20
+ });
+ self.isHopping = false;
+ self.hop = function () {
+ if (self.isHopping) return;
+ self.isHopping = true;
+ LK.getSound('frogHop').play();
+ tween(self, {
+ y: self.y - 50
+ }, {
+ duration: 200,
+ easing: tween.easeOut
+ });
+ LK.setTimeout(function () {
+ tween(self, {
+ y: self.y + 50
+ }, {
+ duration: 200,
+ easing: tween.easeIn,
+ onFinish: function onFinish() {
+ self.isHopping = false;
+ }
+ });
+ }, 200);
+ };
+ self.down = function (x, y, obj) {
+ self.hop();
+ };
+ return self;
+});
+var Xylophone = Container.expand(function () {
+ var self = Container.call(this);
+ var base = self.attachAsset('xylophone', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.keys = [];
+ var colors = [0xff0000, 0xff8800, 0xffff00, 0x00ff00, 0x0088ff, 0x8800ff];
+ for (var i = 0; i < 6; i++) {
+ var key = self.attachAsset('xyloKey', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -125 + i * 50,
+ tint: colors[i]
+ });
+ key.keyIndex = i;
+ self.keys.push(key);
+ }
+ self.playKey = function (keyIndex) {
+ LK.getSound('xyloNote').play();
+ var key = self.keys[keyIndex];
+ tween(key, {
+ y: 20
+ }, {
+ duration: 100
+ });
+ LK.setTimeout(function () {
+ tween(key, {
+ y: 0
+ }, {
+ duration: 100
+ });
+ }, 100);
+ };
+ self.down = function (x, y, obj) {
+ for (var i = 0; i < self.keys.length; i++) {
+ var key = self.keys[i];
+ var keyPos = self.toLocal(key.parent.toGlobal(key.position));
+ if (Math.abs(x - keyPos.x) < 25 && Math.abs(y - keyPos.y) < 50) {
+ self.playKey(i);
+ break;
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xffeecc
+});
+
+/****
+* Game Code
+****/
+var giftBoxes = [];
+var toyTypes = ['kazoo', 'partyBlower', 'drum', 'xylophone', 'toyFrog', 'kazoo'];
+var titleText = new Text2('Party Gift Surprise!', {
+ size: 120,
+ fill: 0xFF4444
+});
+titleText.anchor.set(0.5, 0);
+LK.gui.top.addChild(titleText);
+titleText.y = 50;
+var instructionText = new Text2('Tap gifts to shake and unwrap them!', {
+ size: 80,
+ fill: 0x444444
+});
+instructionText.anchor.set(0.5, 0);
+LK.gui.top.addChild(instructionText);
+instructionText.y = 200;
+for (var i = 0; i < 6; i++) {
+ var gift = new GiftBox();
+ gift.setToyType(toyTypes[i]);
+ var row = Math.floor(i / 3);
+ var col = i % 3;
+ gift.x = 350 + col * 450;
+ gift.y = 800 + row * 450;
+ giftBoxes.push(gift);
+ game.addChild(gift);
+}
+game.update = function () {
+ // Game logic updates here if needed
+};
\ No newline at end of file