Code edit (1 edits merged)
Please save this source code
User prompt
Christmas Tree Decorator
Initial prompt
Toca tree maker 🌲 (2017). Tap on ginger 🐱 to collect pink baubles with her hands 10 times, tap on the gold tinsel to make it sparkle ✨ 10 times, tap on the rose gold snowglobe baubles to make them shake 10 times. Till stars falling 10 times
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var FallingStar = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 2;
self.rotationSpeed = (Math.random() - 0.5) * 0.2;
self.update = function () {
self.y += self.speed;
graphics.rotation += self.rotationSpeed;
if (self.y > 2732 + 50) {
self.destroy();
var index = fallingStars.indexOf(self);
if (index > -1) {
fallingStars.splice(index, 1);
}
}
};
return self;
});
var GingerCharacter = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('gingerCharacter', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function (x, y, obj) {
if (gingerTaps < 10) {
gingerTaps++;
updateProgress();
// Animate hand movement
tween(graphics, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(graphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 200,
easing: tween.easeIn
});
}
});
LK.getSound('decorateSound').play();
if (gingerTaps === 10) {
LK.getSound('completeSound').play();
}
}
};
return self;
});
var GoldTinsel = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('goldTinsel', {
anchorX: 0.5,
anchorY: 0.5
});
self.sparkled = false;
self.down = function (x, y, obj) {
if (!self.sparkled && goldTinselTaps < 10) {
self.sparkled = true;
goldTinselTaps++;
updateProgress();
// Create sparkle effect
createSparkleEffect(self.x, self.y);
// Flash tinsel
tween(graphics, {
tint: 0xffffff
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(graphics, {
tint: 0xffd700
}, {
duration: 300,
easing: tween.easeIn
});
}
});
LK.getSound('decorateSound').play();
if (goldTinselTaps === 10) {
LK.getSound('completeSound').play();
}
}
};
return self;
});
var PinkBauble = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('pinkBauble', {
anchorX: 0.5,
anchorY: 0.5
});
self.collected = false;
self.down = function (x, y, obj) {
if (!self.collected && pinkBaubleCollections < 10) {
self.collected = true;
pinkBaubleCollections++;
updateProgress();
// Animate collection
tween(graphics, {
scaleX: 0,
scaleY: 0,
alpha: 0
}, {
duration: 500,
easing: tween.easeOut
});
LK.getSound('decorateSound').play();
if (pinkBaubleCollections === 10) {
LK.getSound('completeSound').play();
}
}
};
return self;
});
var RoseGoldSnowglobe = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('roseGoldSnowglobe', {
anchorX: 0.5,
anchorY: 0.5
});
self.shaken = false;
self.down = function (x, y, obj) {
if (!self.shaken && roseGoldTaps < 10) {
self.shaken = true;
roseGoldTaps++;
updateProgress();
// Shake animation
var originalX = self.x;
tween(self, {
x: originalX - 10
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
x: originalX + 10
}, {
duration: 100,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
x: originalX
}, {
duration: 100,
easing: tween.easeOut
});
}
});
}
});
// Shimmer effect
tween(graphics, {
alpha: 0.5
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(graphics, {
alpha: 1
}, {
duration: 300,
easing: tween.easeIn
});
}
});
LK.getSound('decorateSound').play();
if (roseGoldTaps === 10) {
LK.getSound('completeSound').play();
}
}
};
return self;
});
var SparkleParticle = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('sparkleParticle', {
anchorX: 0.5,
anchorY: 0.5
});
self.velocity = {
x: (Math.random() - 0.5) * 4,
y: (Math.random() - 0.5) * 4
};
self.life = 60;
self.update = function () {
self.x += self.velocity.x;
self.y += self.velocity.y;
self.life--;
graphics.alpha = self.life / 60;
if (self.life <= 0) {
self.destroy();
var index = sparkleParticles.indexOf(self);
if (index > -1) {
sparkleParticles.splice(index, 1);
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
// Game state variables
var pinkBaubleCollections = 0;
var gingerTaps = 0;
var goldTinselTaps = 0;
var roseGoldTaps = 0;
var starTaps = 0;
var pinkBaubles = [];
var goldTinsels = [];
var roseGoldSnowglobes = [];
var fallingStars = [];
var sparkleParticles = [];
// Create Christmas tree
var tree = game.addChild(LK.getAsset('christmasTree', {
anchorX: 0.5,
anchorY: 1
}));
tree.x = 2048 / 2;
tree.y = 2732 - 200;
// Create ginger character
var gingerChar = game.addChild(new GingerCharacter());
gingerChar.x = 2048 / 2 - 200;
gingerChar.y = 2732 - 400;
// Create pink baubles
for (var i = 0; i < 6; i++) {
var bauble = game.addChild(new PinkBauble());
bauble.x = 2048 / 2 + (Math.random() - 0.5) * 300;
bauble.y = 2732 - 600 + Math.random() * 200;
pinkBaubles.push(bauble);
}
// Create gold tinsel
for (var i = 0; i < 4; i++) {
var tinsel = game.addChild(new GoldTinsel());
tinsel.x = 2048 / 2 + (Math.random() - 0.5) * 250;
tinsel.y = 2732 - 500 + i * 80;
goldTinsels.push(tinsel);
}
// Create rose gold snowglobes
for (var i = 0; i < 5; i++) {
var snowglobe = game.addChild(new RoseGoldSnowglobe());
snowglobe.x = 2048 / 2 + (Math.random() - 0.5) * 280;
snowglobe.y = 2732 - 550 + Math.random() * 150;
roseGoldSnowglobes.push(snowglobe);
}
// UI Elements
var progressText = new Text2('Progress: 0/40', {
size: 60,
fill: 0xFFFFFF
});
progressText.anchor.set(0.5, 0);
LK.gui.top.addChild(progressText);
progressText.y = 100;
var taskText = new Text2('Pink: 0/10 Ginger: 0/10 Gold: 0/10 Rose: 0/10 Stars: 0/10', {
size: 40,
fill: 0xFFFFFF
});
taskText.anchor.set(0.5, 0);
LK.gui.top.addChild(taskText);
taskText.y = 180;
function updateProgress() {
var totalProgress = pinkBaubleCollections + gingerTaps + goldTinselTaps + roseGoldTaps + starTaps;
progressText.setText('Progress: ' + totalProgress + '/50');
taskText.setText('Pink: ' + pinkBaubleCollections + '/10 Ginger: ' + gingerTaps + '/10 Gold: ' + goldTinselTaps + '/10 Rose: ' + roseGoldTaps + '/10 Stars: ' + starTaps + '/10');
// Check for victory
if (totalProgress >= 50) {
LK.showYouWin();
}
}
function createSparkleEffect(x, y) {
for (var i = 0; i < 8; i++) {
var particle = game.addChild(new SparkleParticle());
particle.x = x;
particle.y = y;
sparkleParticles.push(particle);
}
}
function createFallingStar() {
var star = game.addChild(new FallingStar());
star.x = Math.random() * 2048;
star.y = -50;
fallingStars.push(star);
}
// Star tap area (invisible tap zone)
game.down = function (x, y, obj) {
if (starTaps < 10) {
starTaps++;
updateProgress();
// Create falling stars
createFallingStar();
createFallingStar();
LK.getSound('decorateSound').play();
if (starTaps === 10) {
LK.getSound('completeSound').play();
}
}
};
game.update = function () {
// Reset sparkled and shaken states periodically
if (LK.ticks % 180 === 0) {
for (var i = 0; i < goldTinsels.length; i++) {
goldTinsels[i].sparkled = false;
}
for (var i = 0; i < roseGoldSnowglobes.length; i++) {
roseGoldSnowglobes[i].shaken = false;
}
}
// Reset collected state for pink baubles
if (LK.ticks % 300 === 0) {
for (var i = 0; i < pinkBaubles.length; i++) {
if (pinkBaubles[i].collected) {
pinkBaubles[i].collected = false;
var graphics = pinkBaubles[i].children[0];
graphics.scaleX = 1;
graphics.scaleY = 1;
graphics.alpha = 1;
}
}
}
};
// Initialize progress display
updateProgress(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,346 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var FallingStar = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('star', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.speed = Math.random() * 3 + 2;
+ self.rotationSpeed = (Math.random() - 0.5) * 0.2;
+ self.update = function () {
+ self.y += self.speed;
+ graphics.rotation += self.rotationSpeed;
+ if (self.y > 2732 + 50) {
+ self.destroy();
+ var index = fallingStars.indexOf(self);
+ if (index > -1) {
+ fallingStars.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+var GingerCharacter = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('gingerCharacter', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.down = function (x, y, obj) {
+ if (gingerTaps < 10) {
+ gingerTaps++;
+ updateProgress();
+ // Animate hand movement
+ tween(graphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(graphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ }
+ });
+ LK.getSound('decorateSound').play();
+ if (gingerTaps === 10) {
+ LK.getSound('completeSound').play();
+ }
+ }
+ };
+ return self;
+});
+var GoldTinsel = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('goldTinsel', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.sparkled = false;
+ self.down = function (x, y, obj) {
+ if (!self.sparkled && goldTinselTaps < 10) {
+ self.sparkled = true;
+ goldTinselTaps++;
+ updateProgress();
+ // Create sparkle effect
+ createSparkleEffect(self.x, self.y);
+ // Flash tinsel
+ tween(graphics, {
+ tint: 0xffffff
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(graphics, {
+ tint: 0xffd700
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ }
+ });
+ LK.getSound('decorateSound').play();
+ if (goldTinselTaps === 10) {
+ LK.getSound('completeSound').play();
+ }
+ }
+ };
+ return self;
+});
+var PinkBauble = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('pinkBauble', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.collected = false;
+ self.down = function (x, y, obj) {
+ if (!self.collected && pinkBaubleCollections < 10) {
+ self.collected = true;
+ pinkBaubleCollections++;
+ updateProgress();
+ // Animate collection
+ tween(graphics, {
+ scaleX: 0,
+ scaleY: 0,
+ alpha: 0
+ }, {
+ duration: 500,
+ easing: tween.easeOut
+ });
+ LK.getSound('decorateSound').play();
+ if (pinkBaubleCollections === 10) {
+ LK.getSound('completeSound').play();
+ }
+ }
+ };
+ return self;
+});
+var RoseGoldSnowglobe = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('roseGoldSnowglobe', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.shaken = false;
+ self.down = function (x, y, obj) {
+ if (!self.shaken && roseGoldTaps < 10) {
+ self.shaken = true;
+ roseGoldTaps++;
+ updateProgress();
+ // Shake animation
+ var originalX = self.x;
+ tween(self, {
+ x: originalX - 10
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX + 10
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(self, {
+ x: originalX
+ }, {
+ duration: 100,
+ easing: tween.easeOut
+ });
+ }
+ });
+ }
+ });
+ // Shimmer effect
+ tween(graphics, {
+ alpha: 0.5
+ }, {
+ duration: 300,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(graphics, {
+ alpha: 1
+ }, {
+ duration: 300,
+ easing: tween.easeIn
+ });
+ }
+ });
+ LK.getSound('decorateSound').play();
+ if (roseGoldTaps === 10) {
+ LK.getSound('completeSound').play();
+ }
+ }
+ };
+ return self;
+});
+var SparkleParticle = Container.expand(function () {
+ var self = Container.call(this);
+ var graphics = self.attachAsset('sparkleParticle', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.velocity = {
+ x: (Math.random() - 0.5) * 4,
+ y: (Math.random() - 0.5) * 4
+ };
+ self.life = 60;
+ self.update = function () {
+ self.x += self.velocity.x;
+ self.y += self.velocity.y;
+ self.life--;
+ graphics.alpha = self.life / 60;
+ if (self.life <= 0) {
+ self.destroy();
+ var index = sparkleParticles.indexOf(self);
+ if (index > -1) {
+ sparkleParticles.splice(index, 1);
+ }
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x001122
+});
+
+/****
+* Game Code
+****/
+// Game state variables
+var pinkBaubleCollections = 0;
+var gingerTaps = 0;
+var goldTinselTaps = 0;
+var roseGoldTaps = 0;
+var starTaps = 0;
+var pinkBaubles = [];
+var goldTinsels = [];
+var roseGoldSnowglobes = [];
+var fallingStars = [];
+var sparkleParticles = [];
+// Create Christmas tree
+var tree = game.addChild(LK.getAsset('christmasTree', {
+ anchorX: 0.5,
+ anchorY: 1
+}));
+tree.x = 2048 / 2;
+tree.y = 2732 - 200;
+// Create ginger character
+var gingerChar = game.addChild(new GingerCharacter());
+gingerChar.x = 2048 / 2 - 200;
+gingerChar.y = 2732 - 400;
+// Create pink baubles
+for (var i = 0; i < 6; i++) {
+ var bauble = game.addChild(new PinkBauble());
+ bauble.x = 2048 / 2 + (Math.random() - 0.5) * 300;
+ bauble.y = 2732 - 600 + Math.random() * 200;
+ pinkBaubles.push(bauble);
+}
+// Create gold tinsel
+for (var i = 0; i < 4; i++) {
+ var tinsel = game.addChild(new GoldTinsel());
+ tinsel.x = 2048 / 2 + (Math.random() - 0.5) * 250;
+ tinsel.y = 2732 - 500 + i * 80;
+ goldTinsels.push(tinsel);
+}
+// Create rose gold snowglobes
+for (var i = 0; i < 5; i++) {
+ var snowglobe = game.addChild(new RoseGoldSnowglobe());
+ snowglobe.x = 2048 / 2 + (Math.random() - 0.5) * 280;
+ snowglobe.y = 2732 - 550 + Math.random() * 150;
+ roseGoldSnowglobes.push(snowglobe);
+}
+// UI Elements
+var progressText = new Text2('Progress: 0/40', {
+ size: 60,
+ fill: 0xFFFFFF
+});
+progressText.anchor.set(0.5, 0);
+LK.gui.top.addChild(progressText);
+progressText.y = 100;
+var taskText = new Text2('Pink: 0/10 Ginger: 0/10 Gold: 0/10 Rose: 0/10 Stars: 0/10', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+taskText.anchor.set(0.5, 0);
+LK.gui.top.addChild(taskText);
+taskText.y = 180;
+function updateProgress() {
+ var totalProgress = pinkBaubleCollections + gingerTaps + goldTinselTaps + roseGoldTaps + starTaps;
+ progressText.setText('Progress: ' + totalProgress + '/50');
+ taskText.setText('Pink: ' + pinkBaubleCollections + '/10 Ginger: ' + gingerTaps + '/10 Gold: ' + goldTinselTaps + '/10 Rose: ' + roseGoldTaps + '/10 Stars: ' + starTaps + '/10');
+ // Check for victory
+ if (totalProgress >= 50) {
+ LK.showYouWin();
+ }
+}
+function createSparkleEffect(x, y) {
+ for (var i = 0; i < 8; i++) {
+ var particle = game.addChild(new SparkleParticle());
+ particle.x = x;
+ particle.y = y;
+ sparkleParticles.push(particle);
+ }
+}
+function createFallingStar() {
+ var star = game.addChild(new FallingStar());
+ star.x = Math.random() * 2048;
+ star.y = -50;
+ fallingStars.push(star);
+}
+// Star tap area (invisible tap zone)
+game.down = function (x, y, obj) {
+ if (starTaps < 10) {
+ starTaps++;
+ updateProgress();
+ // Create falling stars
+ createFallingStar();
+ createFallingStar();
+ LK.getSound('decorateSound').play();
+ if (starTaps === 10) {
+ LK.getSound('completeSound').play();
+ }
+ }
+};
+game.update = function () {
+ // Reset sparkled and shaken states periodically
+ if (LK.ticks % 180 === 0) {
+ for (var i = 0; i < goldTinsels.length; i++) {
+ goldTinsels[i].sparkled = false;
+ }
+ for (var i = 0; i < roseGoldSnowglobes.length; i++) {
+ roseGoldSnowglobes[i].shaken = false;
+ }
+ }
+ // Reset collected state for pink baubles
+ if (LK.ticks % 300 === 0) {
+ for (var i = 0; i < pinkBaubles.length; i++) {
+ if (pinkBaubles[i].collected) {
+ pinkBaubles[i].collected = false;
+ var graphics = pinkBaubles[i].children[0];
+ graphics.scaleX = 1;
+ graphics.scaleY = 1;
+ graphics.alpha = 1;
+ }
+ }
+ }
+};
+// Initialize progress display
+updateProgress();
\ No newline at end of file