/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Envelope = Container.expand(function (color) { var self = Container.call(this); var assetName = color === 'red' ? 'envelope' : 'greenEnvelope'; var graphics = self.attachAsset(assetName, { anchorX: 0.5, anchorY: 0.5 }); self.isDragging = false; self.isCollected = false; self.color = color; self.down = function (x, y, obj) { if (!self.isCollected) { self.isDragging = true; self.originalX = self.x; self.originalY = self.y; } }; self.checkCollection = function () { if (self.intersects(collectionBox) && !self.isCollected) { self.isCollected = true; LK.getSound('collect').play(); // Move to collection box tween(self, { x: collectionBox.x, y: collectionBox.y, scaleX: 0.5, scaleY: 0.5 }, { duration: 300, easing: tween.easeOut }); envelopesCollected++; checkEnvelopePhaseComplete(); } }; return self; }); var HollyBush = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('hollyBush', { anchorX: 0.5, anchorY: 0.5 }); self.hollyCut = false; self.down = function (x, y, obj) { if (currentPhase === 'holly' && !self.hollyCut) { self.hollyCut = true; LK.getSound('cut').play(); // Create holly pieces var holly1 = LK.getAsset('holly', { anchorX: 0.5, anchorY: 0.5 }); var holly2 = LK.getAsset('holly', { anchorX: 0.5, anchorY: 0.5 }); holly1.x = self.x - 50; holly1.y = self.y; holly2.x = self.x + 50; holly2.y = self.y; game.addChild(holly1); game.addChild(holly2); // Animate holly pieces tween(holly1, { y: holly1.y + 100 }, { duration: 500, easing: tween.easeOut }); tween(holly2, { y: holly2.y + 100 }, { duration: 500, easing: tween.easeOut }); hollyCutCount++; checkHollyPhaseComplete(); } }; return self; }); var Mistletoe = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('mistletoe', { anchorX: 0.5, anchorY: 0.5 }); self.isDragging = false; self.isCollected = false; self.down = function (x, y, obj) { if (!self.isCollected) { self.isDragging = true; self.originalX = self.x; self.originalY = self.y; } }; self.checkCollection = function () { if (self.x > 800 && self.x < 1200 && self.y > 1000 && self.y < 1400 && !self.isCollected) { self.isCollected = true; LK.getSound('collect').play(); mistletoeCollected++; checkMistletoePhaseComplete(); } }; return self; }); var SnowCover = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('snowCover', { anchorX: 0.5, anchorY: 0.5 }); self.isCleared = false; self.pineconeRevealed = false; self.down = function (x, y, obj) { if (!self.isCleared) { self.isCleared = true; LK.getSound('pop').play(); // Fade out snow cover tween(graphics, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { self.visible = false; self.revealPinecone(); } }); } }; self.revealPinecone = function () { if (!self.pineconeRevealed) { self.pineconeRevealed = true; var pinecone = LK.getAsset('pinecone', { anchorX: 0.5, anchorY: 0.5 }); pinecone.x = self.x; pinecone.y = self.y; game.addChild(pinecone); // Scale animation pinecone.scaleX = 0; pinecone.scaleY = 0; tween(pinecone, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeOut }); snowClearedCount++; checkSnowPhaseComplete(); } }; return self; }); var Wreath = Container.expand(function () { var self = Container.call(this); var graphics = self.attachAsset('wreath', { anchorX: 0.5, anchorY: 0.5 }); self.isDragging = false; self.isPlaced = false; self.down = function (x, y, obj) { if (currentPhase === 'wreath' && !self.isPlaced) { self.isDragging = true; self.originalX = self.x; self.originalY = self.y; } }; self.checkPlacement = function () { if (self.intersects(door) && !self.isPlaced) { self.isPlaced = true; LK.getSound('success').play(); // Snap to door center tween(self, { x: door.x, y: door.y - 50 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { showCrown(); } }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Sound effects // Game backgrounds and UI elements // Game state variables var currentPhase = 'snow'; var snowClearedCount = 0; var envelopesCollected = 0; var mistletoeCollected = 0; var hollyCutCount = 0; // UI elements var instructionText = new Text2('Tap the snow to find pinecones!', { size: 80, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0); LK.gui.top.addChild(instructionText); // Game objects var snowCovers = []; var envelopes = []; var mistletoes = []; var hollyBushes = []; var collectionBox; var door; var wreath; var draggedObject = null; // Characters var jacky, twitter, ginger, harvey; // Create snow covers and setup snow phase function setupSnowPhase() { for (var i = 0; i < 3; i++) { var snow = new SnowCover(); snow.x = 400 + i * 300; snow.y = 800; snowCovers.push(snow); game.addChild(snow); } // Add character Jacky jacky = LK.getAsset('character', { anchorX: 0.5, anchorY: 0.5 }); jacky.x = 200; jacky.y = 600; game.addChild(jacky); } // Create envelopes and collection box function setupEnvelopePhase() { instructionText.setText('Drag envelopes to the yellow box!'); // Clear previous phase objects for (var i = 0; i < snowCovers.length; i++) { snowCovers[i].visible = false; } // Create collection box collectionBox = LK.getAsset('collectionBox', { anchorX: 0.5, anchorY: 0.5 }); collectionBox.x = 1024; collectionBox.y = 1200; game.addChild(collectionBox); // Create envelopes for (var i = 0; i < 4; i++) { var envelope = new Envelope(i < 2 ? 'red' : 'green'); envelope.x = 300 + i * 200; envelope.y = 800; envelopes.push(envelope); game.addChild(envelope); } // Add Twitter bird twitter = LK.getAsset('bird', { anchorX: 0.5, anchorY: 0.5 }); twitter.x = 1500; twitter.y = 400; game.addChild(twitter); } // Create mistletoe collection phase function setupMistletoePhase() { instructionText.setText('Collect mistletoe pairs!'); // Clear envelopes for (var i = 0; i < envelopes.length; i++) { envelopes[i].visible = false; } collectionBox.visible = false; // Create mistletoe for (var i = 0; i < 4; i++) { var mistletoe = new Mistletoe(); mistletoe.x = 400 + i * 300; mistletoe.y = 600; mistletoes.push(mistletoe); game.addChild(mistletoe); } // Add tree and Ginger var tree = LK.getAsset('tree', { anchorX: 0.5, anchorY: 0.5 }); tree.x = 1600; tree.y = 800; game.addChild(tree); ginger = LK.getAsset('character', { anchorX: 0.5, anchorY: 0.5 }); ginger.x = 1600; ginger.y = 600; game.addChild(ginger); } // Create holly cutting phase function setupHollyPhase() { instructionText.setText('Cut holly from the bushes!'); // Clear mistletoe for (var i = 0; i < mistletoes.length; i++) { mistletoes[i].visible = false; } // Create holly bushes for (var i = 0; i < 3; i++) { var bush = new HollyBush(); bush.x = 500 + i * 300; bush.y = 900; hollyBushes.push(bush); game.addChild(bush); } // Add scissors var scissors = LK.getAsset('scissors', { anchorX: 0.5, anchorY: 0.5 }); scissors.x = 1024; scissors.y = 1400; game.addChild(scissors); // Add Harvey harvey = LK.getAsset('character', { anchorX: 0.5, anchorY: 0.5 }); harvey.x = 1400; harvey.y = 1200; game.addChild(harvey); } // Create wreath placement phase function setupWreathPhase() { instructionText.setText('Place the wreath on the door!'); // Clear holly bushes for (var i = 0; i < hollyBushes.length; i++) { hollyBushes[i].visible = false; } // Create door door = LK.getAsset('door', { anchorX: 0.5, anchorY: 0.5 }); door.x = 1400; door.y = 1000; game.addChild(door); // Create wreath wreath = new Wreath(); wreath.x = 600; wreath.y = 1000; game.addChild(wreath); } // Show final crown function showCrown() { instructionText.setText('Christmas Crown Complete!'); var crown = LK.getAsset('crown', { anchorX: 0.5, anchorY: 0.5 }); crown.x = 1024; crown.y = 600; crown.scaleX = 0; crown.scaleY = 0; game.addChild(crown); // Animate crown appearance tween(crown, { scaleX: 1.5, scaleY: 1.5 }, { duration: 1000, easing: tween.easeOut, onFinish: function onFinish() { LK.effects.flashScreen(0xFFD700, 2000); LK.getSound('success').play(); // Show win after crown animation LK.setTimeout(function () { LK.showYouWin(); }, 2000); } }); } // Phase completion checks function checkSnowPhaseComplete() { if (snowClearedCount >= 3) { currentPhase = 'envelope'; LK.setTimeout(function () { setupEnvelopePhase(); }, 1000); } } function checkEnvelopePhaseComplete() { if (envelopesCollected >= 4) { currentPhase = 'mistletoe'; LK.setTimeout(function () { setupMistletoePhase(); }, 1000); } } function checkMistletoePhaseComplete() { if (mistletoeCollected >= 4) { currentPhase = 'holly'; LK.setTimeout(function () { setupHollyPhase(); }, 1000); } } function checkHollyPhaseComplete() { if (hollyCutCount >= 3) { currentPhase = 'wreath'; LK.setTimeout(function () { setupWreathPhase(); }, 1000); } } // Mouse/touch handlers game.move = function (x, y, obj) { if (draggedObject) { draggedObject.x = x; draggedObject.y = y; if (draggedObject.checkCollection) { draggedObject.checkCollection(); } if (draggedObject.checkPlacement) { draggedObject.checkPlacement(); } } }; game.down = function (x, y, obj) { // Check for draggable objects for (var i = 0; i < envelopes.length; i++) { if (envelopes[i].visible && !envelopes[i].isCollected) { var envelope = envelopes[i]; var dx = x - envelope.x; var dy = y - envelope.y; if (dx * dx + dy * dy < 10000) { draggedObject = envelope; envelope.isDragging = true; break; } } } for (var i = 0; i < mistletoes.length; i++) { if (mistletoes[i].visible && !mistletoes[i].isCollected) { var mistletoe = mistletoes[i]; var dx = x - mistletoe.x; var dy = y - mistletoe.y; if (dx * dx + dy * dy < 10000) { draggedObject = mistletoe; mistletoe.isDragging = true; break; } } } if (wreath && wreath.visible && !wreath.isPlaced) { var dx = x - wreath.x; var dy = y - wreath.y; if (dx * dx + dy * dy < 10000) { draggedObject = wreath; wreath.isDragging = true; } } }; game.up = function (x, y, obj) { if (draggedObject) { draggedObject.isDragging = false; draggedObject = null; } }; // Initialize first phase setupSnowPhase(); // Game update loop game.update = function () { // Animate characters if (jacky) { jacky.x += Math.sin(LK.ticks * 0.02) * 0.5; } if (twitter) { twitter.y += Math.sin(LK.ticks * 0.03) * 0.3; } if (harvey) { harvey.scaleX = 1 + Math.sin(LK.ticks * 0.05) * 0.1; } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Envelope = Container.expand(function (color) {
var self = Container.call(this);
var assetName = color === 'red' ? 'envelope' : 'greenEnvelope';
var graphics = self.attachAsset(assetName, {
anchorX: 0.5,
anchorY: 0.5
});
self.isDragging = false;
self.isCollected = false;
self.color = color;
self.down = function (x, y, obj) {
if (!self.isCollected) {
self.isDragging = true;
self.originalX = self.x;
self.originalY = self.y;
}
};
self.checkCollection = function () {
if (self.intersects(collectionBox) && !self.isCollected) {
self.isCollected = true;
LK.getSound('collect').play();
// Move to collection box
tween(self, {
x: collectionBox.x,
y: collectionBox.y,
scaleX: 0.5,
scaleY: 0.5
}, {
duration: 300,
easing: tween.easeOut
});
envelopesCollected++;
checkEnvelopePhaseComplete();
}
};
return self;
});
var HollyBush = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('hollyBush', {
anchorX: 0.5,
anchorY: 0.5
});
self.hollyCut = false;
self.down = function (x, y, obj) {
if (currentPhase === 'holly' && !self.hollyCut) {
self.hollyCut = true;
LK.getSound('cut').play();
// Create holly pieces
var holly1 = LK.getAsset('holly', {
anchorX: 0.5,
anchorY: 0.5
});
var holly2 = LK.getAsset('holly', {
anchorX: 0.5,
anchorY: 0.5
});
holly1.x = self.x - 50;
holly1.y = self.y;
holly2.x = self.x + 50;
holly2.y = self.y;
game.addChild(holly1);
game.addChild(holly2);
// Animate holly pieces
tween(holly1, {
y: holly1.y + 100
}, {
duration: 500,
easing: tween.easeOut
});
tween(holly2, {
y: holly2.y + 100
}, {
duration: 500,
easing: tween.easeOut
});
hollyCutCount++;
checkHollyPhaseComplete();
}
};
return self;
});
var Mistletoe = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('mistletoe', {
anchorX: 0.5,
anchorY: 0.5
});
self.isDragging = false;
self.isCollected = false;
self.down = function (x, y, obj) {
if (!self.isCollected) {
self.isDragging = true;
self.originalX = self.x;
self.originalY = self.y;
}
};
self.checkCollection = function () {
if (self.x > 800 && self.x < 1200 && self.y > 1000 && self.y < 1400 && !self.isCollected) {
self.isCollected = true;
LK.getSound('collect').play();
mistletoeCollected++;
checkMistletoePhaseComplete();
}
};
return self;
});
var SnowCover = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('snowCover', {
anchorX: 0.5,
anchorY: 0.5
});
self.isCleared = false;
self.pineconeRevealed = false;
self.down = function (x, y, obj) {
if (!self.isCleared) {
self.isCleared = true;
LK.getSound('pop').play();
// Fade out snow cover
tween(graphics, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
self.visible = false;
self.revealPinecone();
}
});
}
};
self.revealPinecone = function () {
if (!self.pineconeRevealed) {
self.pineconeRevealed = true;
var pinecone = LK.getAsset('pinecone', {
anchorX: 0.5,
anchorY: 0.5
});
pinecone.x = self.x;
pinecone.y = self.y;
game.addChild(pinecone);
// Scale animation
pinecone.scaleX = 0;
pinecone.scaleY = 0;
tween(pinecone, {
scaleX: 1,
scaleY: 1
}, {
duration: 300,
easing: tween.easeOut
});
snowClearedCount++;
checkSnowPhaseComplete();
}
};
return self;
});
var Wreath = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('wreath', {
anchorX: 0.5,
anchorY: 0.5
});
self.isDragging = false;
self.isPlaced = false;
self.down = function (x, y, obj) {
if (currentPhase === 'wreath' && !self.isPlaced) {
self.isDragging = true;
self.originalX = self.x;
self.originalY = self.y;
}
};
self.checkPlacement = function () {
if (self.intersects(door) && !self.isPlaced) {
self.isPlaced = true;
LK.getSound('success').play();
// Snap to door center
tween(self, {
x: door.x,
y: door.y - 50
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
showCrown();
}
});
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Sound effects
// Game backgrounds and UI elements
// Game state variables
var currentPhase = 'snow';
var snowClearedCount = 0;
var envelopesCollected = 0;
var mistletoeCollected = 0;
var hollyCutCount = 0;
// UI elements
var instructionText = new Text2('Tap the snow to find pinecones!', {
size: 80,
fill: 0xFFFFFF
});
instructionText.anchor.set(0.5, 0);
LK.gui.top.addChild(instructionText);
// Game objects
var snowCovers = [];
var envelopes = [];
var mistletoes = [];
var hollyBushes = [];
var collectionBox;
var door;
var wreath;
var draggedObject = null;
// Characters
var jacky, twitter, ginger, harvey;
// Create snow covers and setup snow phase
function setupSnowPhase() {
for (var i = 0; i < 3; i++) {
var snow = new SnowCover();
snow.x = 400 + i * 300;
snow.y = 800;
snowCovers.push(snow);
game.addChild(snow);
}
// Add character Jacky
jacky = LK.getAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
jacky.x = 200;
jacky.y = 600;
game.addChild(jacky);
}
// Create envelopes and collection box
function setupEnvelopePhase() {
instructionText.setText('Drag envelopes to the yellow box!');
// Clear previous phase objects
for (var i = 0; i < snowCovers.length; i++) {
snowCovers[i].visible = false;
}
// Create collection box
collectionBox = LK.getAsset('collectionBox', {
anchorX: 0.5,
anchorY: 0.5
});
collectionBox.x = 1024;
collectionBox.y = 1200;
game.addChild(collectionBox);
// Create envelopes
for (var i = 0; i < 4; i++) {
var envelope = new Envelope(i < 2 ? 'red' : 'green');
envelope.x = 300 + i * 200;
envelope.y = 800;
envelopes.push(envelope);
game.addChild(envelope);
}
// Add Twitter bird
twitter = LK.getAsset('bird', {
anchorX: 0.5,
anchorY: 0.5
});
twitter.x = 1500;
twitter.y = 400;
game.addChild(twitter);
}
// Create mistletoe collection phase
function setupMistletoePhase() {
instructionText.setText('Collect mistletoe pairs!');
// Clear envelopes
for (var i = 0; i < envelopes.length; i++) {
envelopes[i].visible = false;
}
collectionBox.visible = false;
// Create mistletoe
for (var i = 0; i < 4; i++) {
var mistletoe = new Mistletoe();
mistletoe.x = 400 + i * 300;
mistletoe.y = 600;
mistletoes.push(mistletoe);
game.addChild(mistletoe);
}
// Add tree and Ginger
var tree = LK.getAsset('tree', {
anchorX: 0.5,
anchorY: 0.5
});
tree.x = 1600;
tree.y = 800;
game.addChild(tree);
ginger = LK.getAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
ginger.x = 1600;
ginger.y = 600;
game.addChild(ginger);
}
// Create holly cutting phase
function setupHollyPhase() {
instructionText.setText('Cut holly from the bushes!');
// Clear mistletoe
for (var i = 0; i < mistletoes.length; i++) {
mistletoes[i].visible = false;
}
// Create holly bushes
for (var i = 0; i < 3; i++) {
var bush = new HollyBush();
bush.x = 500 + i * 300;
bush.y = 900;
hollyBushes.push(bush);
game.addChild(bush);
}
// Add scissors
var scissors = LK.getAsset('scissors', {
anchorX: 0.5,
anchorY: 0.5
});
scissors.x = 1024;
scissors.y = 1400;
game.addChild(scissors);
// Add Harvey
harvey = LK.getAsset('character', {
anchorX: 0.5,
anchorY: 0.5
});
harvey.x = 1400;
harvey.y = 1200;
game.addChild(harvey);
}
// Create wreath placement phase
function setupWreathPhase() {
instructionText.setText('Place the wreath on the door!');
// Clear holly bushes
for (var i = 0; i < hollyBushes.length; i++) {
hollyBushes[i].visible = false;
}
// Create door
door = LK.getAsset('door', {
anchorX: 0.5,
anchorY: 0.5
});
door.x = 1400;
door.y = 1000;
game.addChild(door);
// Create wreath
wreath = new Wreath();
wreath.x = 600;
wreath.y = 1000;
game.addChild(wreath);
}
// Show final crown
function showCrown() {
instructionText.setText('Christmas Crown Complete!');
var crown = LK.getAsset('crown', {
anchorX: 0.5,
anchorY: 0.5
});
crown.x = 1024;
crown.y = 600;
crown.scaleX = 0;
crown.scaleY = 0;
game.addChild(crown);
// Animate crown appearance
tween(crown, {
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
LK.effects.flashScreen(0xFFD700, 2000);
LK.getSound('success').play();
// Show win after crown animation
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}
});
}
// Phase completion checks
function checkSnowPhaseComplete() {
if (snowClearedCount >= 3) {
currentPhase = 'envelope';
LK.setTimeout(function () {
setupEnvelopePhase();
}, 1000);
}
}
function checkEnvelopePhaseComplete() {
if (envelopesCollected >= 4) {
currentPhase = 'mistletoe';
LK.setTimeout(function () {
setupMistletoePhase();
}, 1000);
}
}
function checkMistletoePhaseComplete() {
if (mistletoeCollected >= 4) {
currentPhase = 'holly';
LK.setTimeout(function () {
setupHollyPhase();
}, 1000);
}
}
function checkHollyPhaseComplete() {
if (hollyCutCount >= 3) {
currentPhase = 'wreath';
LK.setTimeout(function () {
setupWreathPhase();
}, 1000);
}
}
// Mouse/touch handlers
game.move = function (x, y, obj) {
if (draggedObject) {
draggedObject.x = x;
draggedObject.y = y;
if (draggedObject.checkCollection) {
draggedObject.checkCollection();
}
if (draggedObject.checkPlacement) {
draggedObject.checkPlacement();
}
}
};
game.down = function (x, y, obj) {
// Check for draggable objects
for (var i = 0; i < envelopes.length; i++) {
if (envelopes[i].visible && !envelopes[i].isCollected) {
var envelope = envelopes[i];
var dx = x - envelope.x;
var dy = y - envelope.y;
if (dx * dx + dy * dy < 10000) {
draggedObject = envelope;
envelope.isDragging = true;
break;
}
}
}
for (var i = 0; i < mistletoes.length; i++) {
if (mistletoes[i].visible && !mistletoes[i].isCollected) {
var mistletoe = mistletoes[i];
var dx = x - mistletoe.x;
var dy = y - mistletoe.y;
if (dx * dx + dy * dy < 10000) {
draggedObject = mistletoe;
mistletoe.isDragging = true;
break;
}
}
}
if (wreath && wreath.visible && !wreath.isPlaced) {
var dx = x - wreath.x;
var dy = y - wreath.y;
if (dx * dx + dy * dy < 10000) {
draggedObject = wreath;
wreath.isDragging = true;
}
}
};
game.up = function (x, y, obj) {
if (draggedObject) {
draggedObject.isDragging = false;
draggedObject = null;
}
};
// Initialize first phase
setupSnowPhase();
// Game update loop
game.update = function () {
// Animate characters
if (jacky) {
jacky.x += Math.sin(LK.ticks * 0.02) * 0.5;
}
if (twitter) {
twitter.y += Math.sin(LK.ticks * 0.03) * 0.3;
}
if (harvey) {
harvey.scaleX = 1 + Math.sin(LK.ticks * 0.05) * 0.1;
}
};