Code edit (1 edits merged)
Please save this source code
User prompt
Christmas TV & Cola Kaboom
Initial prompt
Toca 12 days of Christmas (2014). The powerpuff girls have a video on the tv and a Coca Cola can. Tap on the play button to watch the 5 days of Christmas on the tv, tap on the Coca Cola can to watch it go kaboom.
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var CocaCola = Container.expand(function () {
var self = Container.call(this);
var body = self.attachAsset('colaBody', {
anchorX: 0.5,
anchorY: 0.5
});
var top = self.attachAsset('colaTop', {
anchorX: 0.5,
anchorY: 0.5,
y: -170
});
var label = self.attachAsset('colaLabel', {
anchorX: 0.5,
anchorY: 0.5
});
self.isExploded = false;
self.particles = [];
self.explode = function () {
if (self.isExploded) return;
self.isExploded = true;
// Hide can
body.alpha = 0;
top.alpha = 0;
label.alpha = 0;
// Create particles
for (var i = 0; i < 20; i++) {
var particle = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 40 - 20,
y: Math.random() * 40 - 20
});
self.particles.push(particle);
// Animate particle
var targetX = Math.random() * 400 - 200;
var targetY = Math.random() * 400 - 200;
tween(particle, {
x: targetX,
y: targetY,
alpha: 0,
scaleX: 0.1,
scaleY: 0.1
}, {
duration: 1000,
easing: tween.easeOut
});
}
// Screen shake effect
LK.effects.flashScreen(0xffa500, 300);
// Play explosion sound
LK.getSound('explosion').play();
// Regenerate can after 2 seconds
LK.setTimeout(function () {
self.regenerate();
}, 2000);
};
self.regenerate = function () {
// Reset can visibility
body.alpha = 1;
top.alpha = 1;
label.alpha = 1;
// Remove particles
for (var i = 0; i < self.particles.length; i++) {
self.particles[i].destroy();
}
self.particles = [];
self.isExploded = false;
// Bounce in animation
self.scaleX = 0;
self.scaleY = 0;
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.bounceOut
});
};
self.down = function (x, y, obj) {
self.explode();
};
return self;
});
var TV = Container.expand(function () {
var self = Container.call(this);
// TV body
var body = self.attachAsset('tvBody', {
anchorX: 0.5,
anchorY: 0.5
});
// TV screen
var screen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5
});
// Video content (hidden initially)
var videoContent = self.attachAsset('videoContent', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Play button
var playButton = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
});
// Speakers
var leftSpeaker = self.attachAsset('speaker', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: -100
});
var rightSpeaker = self.attachAsset('speaker', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: -100
});
// Scan lines
var scanLine1 = self.attachAsset('scanLine', {
anchorX: 0.5,
anchorY: 0.5,
y: -50,
alpha: 0
});
var scanLine2 = self.attachAsset('scanLine', {
anchorX: 0.5,
anchorY: 0.5,
y: 50,
alpha: 0
});
self.isPlaying = false;
self.scanLineTimer = null;
self.startVideo = function () {
if (self.isPlaying) return;
self.isPlaying = true;
playButton.alpha = 0;
videoContent.alpha = 1;
// Show scan lines with animation
scanLine1.alpha = 0.3;
scanLine2.alpha = 0.3;
// Animate scan lines
self.scanLineTimer = LK.setInterval(function () {
tween(scanLine1, {
y: scanLine1.y + 10
}, {
duration: 100
});
tween(scanLine2, {
y: scanLine2.y - 10
}, {
duration: 100
});
if (scanLine1.y > 150) scanLine1.y = -150;
if (scanLine2.y < -150) scanLine2.y = 150;
}, 100);
// Video duration simulation (10 seconds)
LK.setTimeout(function () {
self.stopVideo();
}, 10000);
LK.getSound('tvClick').play();
};
self.stopVideo = function () {
if (!self.isPlaying) return;
self.isPlaying = false;
playButton.alpha = 1;
videoContent.alpha = 0;
scanLine1.alpha = 0;
scanLine2.alpha = 0;
if (self.scanLineTimer) {
LK.clearInterval(self.scanLineTimer);
self.scanLineTimer = null;
}
};
self.down = function (x, y, obj) {
if (!self.isPlaying) {
self.startVideo();
} else {
self.stopVideo();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2d5016
});
/****
* Game Code
****/
// Create Christmas background elements
var backgroundSnow = [];
for (var i = 0; i < 30; i++) {
var snowflake = LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 2048,
y: Math.random() * 2732,
scaleX: 0.5,
scaleY: 0.5,
tint: 0xffffff
});
game.addChild(snowflake);
backgroundSnow.push(snowflake);
}
// Create and position TV
var tv = game.addChild(new TV());
tv.x = 1024;
tv.y = 1000;
// Create and position Coca Cola can
var cocaCola = game.addChild(new CocaCola());
cocaCola.x = 1500;
cocaCola.y = 1400;
// Add title text
var titleText = new Text2('Christmas TV & Cola Kaboom', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
titleText.x = 1024;
titleText.y = 200;
game.addChild(titleText);
// Add instruction text
var instructionText = new Text2('Tap TV to watch • Tap Cola to explode', {
size: 50,
fill: 0xFFDDDD
});
instructionText.anchor.set(0.5, 0);
instructionText.x = 1024;
instructionText.y = 2400;
game.addChild(instructionText);
// Animate falling snow
game.update = function () {
for (var i = 0; i < backgroundSnow.length; i++) {
var snowflake = backgroundSnow[i];
snowflake.y += 2;
snowflake.x += Math.sin(LK.ticks * 0.01 + i) * 0.5;
if (snowflake.y > 2732) {
snowflake.y = -50;
snowflake.x = Math.random() * 2048;
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,256 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var CocaCola = Container.expand(function () {
+ var self = Container.call(this);
+ var body = self.attachAsset('colaBody', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var top = self.attachAsset('colaTop', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -170
+ });
+ var label = self.attachAsset('colaLabel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.isExploded = false;
+ self.particles = [];
+ self.explode = function () {
+ if (self.isExploded) return;
+ self.isExploded = true;
+ // Hide can
+ body.alpha = 0;
+ top.alpha = 0;
+ label.alpha = 0;
+ // Create particles
+ for (var i = 0; i < 20; i++) {
+ var particle = self.attachAsset('particle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: Math.random() * 40 - 20,
+ y: Math.random() * 40 - 20
+ });
+ self.particles.push(particle);
+ // Animate particle
+ var targetX = Math.random() * 400 - 200;
+ var targetY = Math.random() * 400 - 200;
+ tween(particle, {
+ x: targetX,
+ y: targetY,
+ alpha: 0,
+ scaleX: 0.1,
+ scaleY: 0.1
+ }, {
+ duration: 1000,
+ easing: tween.easeOut
+ });
+ }
+ // Screen shake effect
+ LK.effects.flashScreen(0xffa500, 300);
+ // Play explosion sound
+ LK.getSound('explosion').play();
+ // Regenerate can after 2 seconds
+ LK.setTimeout(function () {
+ self.regenerate();
+ }, 2000);
+ };
+ self.regenerate = function () {
+ // Reset can visibility
+ body.alpha = 1;
+ top.alpha = 1;
+ label.alpha = 1;
+ // Remove particles
+ for (var i = 0; i < self.particles.length; i++) {
+ self.particles[i].destroy();
+ }
+ self.particles = [];
+ self.isExploded = false;
+ // Bounce in animation
+ self.scaleX = 0;
+ self.scaleY = 0;
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 500,
+ easing: tween.bounceOut
+ });
+ };
+ self.down = function (x, y, obj) {
+ self.explode();
+ };
+ return self;
+});
+var TV = Container.expand(function () {
+ var self = Container.call(this);
+ // TV body
+ var body = self.attachAsset('tvBody', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // TV screen
+ var screen = self.attachAsset('tvScreen', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Video content (hidden initially)
+ var videoContent = self.attachAsset('videoContent', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ alpha: 0
+ });
+ // Play button
+ var playButton = self.attachAsset('playButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Speakers
+ var leftSpeaker = self.attachAsset('speaker', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: -150,
+ y: -100
+ });
+ var rightSpeaker = self.attachAsset('speaker', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 150,
+ y: -100
+ });
+ // Scan lines
+ var scanLine1 = self.attachAsset('scanLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: -50,
+ alpha: 0
+ });
+ var scanLine2 = self.attachAsset('scanLine', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ y: 50,
+ alpha: 0
+ });
+ self.isPlaying = false;
+ self.scanLineTimer = null;
+ self.startVideo = function () {
+ if (self.isPlaying) return;
+ self.isPlaying = true;
+ playButton.alpha = 0;
+ videoContent.alpha = 1;
+ // Show scan lines with animation
+ scanLine1.alpha = 0.3;
+ scanLine2.alpha = 0.3;
+ // Animate scan lines
+ self.scanLineTimer = LK.setInterval(function () {
+ tween(scanLine1, {
+ y: scanLine1.y + 10
+ }, {
+ duration: 100
+ });
+ tween(scanLine2, {
+ y: scanLine2.y - 10
+ }, {
+ duration: 100
+ });
+ if (scanLine1.y > 150) scanLine1.y = -150;
+ if (scanLine2.y < -150) scanLine2.y = 150;
+ }, 100);
+ // Video duration simulation (10 seconds)
+ LK.setTimeout(function () {
+ self.stopVideo();
+ }, 10000);
+ LK.getSound('tvClick').play();
+ };
+ self.stopVideo = function () {
+ if (!self.isPlaying) return;
+ self.isPlaying = false;
+ playButton.alpha = 1;
+ videoContent.alpha = 0;
+ scanLine1.alpha = 0;
+ scanLine2.alpha = 0;
+ if (self.scanLineTimer) {
+ LK.clearInterval(self.scanLineTimer);
+ self.scanLineTimer = null;
+ }
+ };
+ self.down = function (x, y, obj) {
+ if (!self.isPlaying) {
+ self.startVideo();
+ } else {
+ self.stopVideo();
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x2d5016
+});
+
+/****
+* Game Code
+****/
+// Create Christmas background elements
+var backgroundSnow = [];
+for (var i = 0; i < 30; i++) {
+ var snowflake = LK.getAsset('particle', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: Math.random() * 2048,
+ y: Math.random() * 2732,
+ scaleX: 0.5,
+ scaleY: 0.5,
+ tint: 0xffffff
+ });
+ game.addChild(snowflake);
+ backgroundSnow.push(snowflake);
+}
+// Create and position TV
+var tv = game.addChild(new TV());
+tv.x = 1024;
+tv.y = 1000;
+// Create and position Coca Cola can
+var cocaCola = game.addChild(new CocaCola());
+cocaCola.x = 1500;
+cocaCola.y = 1400;
+// Add title text
+var titleText = new Text2('Christmas TV & Cola Kaboom', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0);
+titleText.x = 1024;
+titleText.y = 200;
+game.addChild(titleText);
+// Add instruction text
+var instructionText = new Text2('Tap TV to watch • Tap Cola to explode', {
+ size: 50,
+ fill: 0xFFDDDD
+});
+instructionText.anchor.set(0.5, 0);
+instructionText.x = 1024;
+instructionText.y = 2400;
+game.addChild(instructionText);
+// Animate falling snow
+game.update = function () {
+ for (var i = 0; i < backgroundSnow.length; i++) {
+ var snowflake = backgroundSnow[i];
+ snowflake.y += 2;
+ snowflake.x += Math.sin(LK.ticks * 0.01 + i) * 0.5;
+ if (snowflake.y > 2732) {
+ snowflake.y = -50;
+ snowflake.x = Math.random() * 2048;
+ }
+ }
+};
\ No newline at end of file