/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphic = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.speed = 2 + Math.random() * 3;
self.hasTransformed = false;
self.update = function () {
self.y += self.speed;
// Transform to snow when hitting ground
if (self.y > 2300 && !self.hasTransformed) {
self.hasTransformed = true;
// Create new snow on ground
var snow = new FallingSnow();
snow.x = self.x;
snow.y = self.y;
currentScene.addChild(snow);
fallingSnowParticles.push(snow);
self.destroy();
}
// Remove if off screen
if (self.y > 2800) {
self.destroy();
}
};
return self;
});
var BubbleBottle = Container.expand(function () {
var self = Container.call(this);
var bottleGraphic = self.attachAsset('bubbleBottle', {
anchorX: 0.5,
anchorY: 1.0
});
self.down = function (x, y, obj) {
if (snowMelted) {
// Create bubbles
for (var i = 0; i < 5; i++) {
var bubble = new Bubble();
bubble.x = self.x + (Math.random() - 0.5) * 100;
bubble.y = self.y - 50;
currentScene.addChild(bubble);
bubbles.push(bubble);
}
LK.getSound('bubblePop').play();
}
};
return self;
});
var FallingSnow = Container.expand(function () {
var self = Container.call(this);
var snowGraphic = self.attachAsset('fallingSnow', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 2;
self.settled = false;
self.update = function () {
if (!self.settled) {
self.y += self.speed;
// Settle on ground
if (self.y > 2300) {
self.settled = true;
self.y = 2300;
self.speed = 0;
}
}
};
return self;
});
var Footprint = Container.expand(function () {
var self = Container.call(this);
var footprintGraphic = self.attachAsset('footprint', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Fade in animation
tween(footprintGraphic, {
alpha: 0.8
}, {
duration: 500
});
self.melt = function () {
tween(footprintGraphic, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Pig = Container.expand(function (pigType) {
var self = Container.call(this);
var pigBody = self.attachAsset('pigBody', {
anchorX: 0.5,
anchorY: 1.0
});
var pigHead = self.attachAsset('pigHead', {
anchorX: 0.5,
anchorY: 1.0,
y: -40
});
var pigSnout = self.attachAsset('pigSnout', {
anchorX: 0.5,
anchorY: 0.5,
y: -40
});
self.pigType = pigType || 'normal';
self.canMakeAngel = pigType === 'angel1' || pigType === 'angel2';
self.down = function (x, y, obj) {
if (self.canMakeAngel && !snowMelted) {
// Create snow angel
var angel = new SnowAngel();
angel.x = self.x;
angel.y = self.y;
currentScene.addChild(angel);
snowAngels.push(angel);
// Pig animation
tween(self, {
y: self.y + 20
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
y: self.y - 20
}, {
duration: 200
});
}
});
} else if (!snowMelted) {
// Create footprint
var footprint = new Footprint();
footprint.x = self.x;
footprint.y = self.y + 20;
currentScene.addChild(footprint);
footprints.push(footprint);
}
LK.getSound('pigSqueal').play();
};
return self;
});
var Scene = Container.expand(function (sceneType) {
var self = Container.call(this);
// Sky background
var sky = self.attachAsset('sky', {
anchorX: 0,
anchorY: 0
});
// Snow ground
var ground = self.attachAsset('snowGround', {
anchorX: 0,
anchorY: 1.0,
y: 2732
});
self.sceneType = sceneType;
self.setupScene = function () {
if (sceneType === 'forest') {
// Add trees
var tree1 = new Tree(10);
tree1.x = 400;
tree1.y = 2300;
self.addChild(tree1);
var tree2 = new Tree(8);
tree2.x = 800;
tree2.y = 2300;
self.addChild(tree2);
var tree3 = new Tree(12);
tree3.x = 1200;
tree3.y = 2300;
self.addChild(tree3);
// Add pigs
var pig1 = new Pig('normal');
pig1.x = 600;
pig1.y = 2300;
self.addChild(pig1);
var pig2 = new Pig('angel1');
pig2.x = 1000;
pig2.y = 2300;
self.addChild(pig2);
} else if (sceneType === 'mountain') {
// Add mountain
var mountain = self.attachAsset('mountain', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2300
});
// Add sled
var sled = new Sled();
sled.x = 800;
sled.y = 1800;
self.addChild(sled);
// Add pig
var pig = new Pig('normal');
pig.x = 1200;
pig.y = 2300;
self.addChild(pig);
} else if (sceneType === 'garden') {
// Add bubble bottle
var bubbleBottle = new BubbleBottle();
bubbleBottle.x = 1024;
bubbleBottle.y = 2300;
self.addChild(bubbleBottle);
// Add angel-making pigs
var pig1 = new Pig('angel1');
pig1.x = 700;
pig1.y = 2300;
self.addChild(pig1);
var pig2 = new Pig('angel2');
pig2.x = 1300;
pig2.y = 2300;
self.addChild(pig2);
}
};
self.setupScene();
return self;
});
var Sled = Container.expand(function () {
var self = Container.call(this);
var sledGraphic = self.attachAsset('sled', {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.down = function (x, y, obj) {
if (!self.isMoving && !snowMelted) {
self.isMoving = true;
// Sled animation down the mountain
tween(self, {
x: self.x + 400,
y: self.y + 300,
rotation: 0.5
}, {
duration: 2000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
// Reset position
self.x = self.x - 400;
self.y = self.y - 300;
self.rotation = 0;
}
});
LK.getSound('sledWoosh').play();
}
};
return self;
});
var SnowAngel = Container.expand(function () {
var self = Container.call(this);
var angelGraphic = self.attachAsset('snowAngel', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Fade in animation
tween(angelGraphic, {
alpha: 0.9
}, {
duration: 800
});
self.melt = function () {
tween(angelGraphic, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Tree = Container.expand(function (snowAmount) {
var self = Container.call(this);
var treeBase = self.attachAsset('treeBase', {
anchorX: 0.5,
anchorY: 1.0
});
var treeBranch = self.attachAsset('treeBranch', {
anchorX: 0.5,
anchorY: 1.0,
y: -200
});
var treeSnow = self.attachAsset('treeSnow', {
anchorX: 0.5,
anchorY: 1.0,
y: -200
});
self.snowAmount = snowAmount || 10;
self.tapCount = 0;
self.isSnowMelted = false;
self.down = function (x, y, obj) {
if (self.tapCount < self.snowAmount && !self.isSnowMelted) {
self.tapCount++;
// Create falling snow particles
for (var i = 0; i < 3; i++) {
var snow = new FallingSnow();
snow.x = self.x + (Math.random() - 0.5) * 150;
snow.y = self.y - 150;
currentScene.addChild(snow);
fallingSnowParticles.push(snow);
}
// Shake tree animation
tween(self, {
x: self.x + 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
x: self.x - 10
}, {
duration: 100
});
}
});
LK.getSound('snowFall').play();
// Gradually reduce snow on tree
var snowScale = 1 - self.tapCount / self.snowAmount;
tween(treeSnow, {
scaleX: snowScale,
scaleY: snowScale
}, {
duration: 300
});
}
};
self.meltSnow = function () {
self.isSnowMelted = true;
tween(treeSnow, {
alpha: 0
}, {
duration: 1000
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Background elements
// Tree elements
// Pig elements
// Interactive elements
// Sounds
var scenes = [];
var currentSceneIndex = 0;
var currentScene = null;
var footprints = [];
var snowAngels = [];
var bubbles = [];
var fallingSnowParticles = [];
var snowMelted = false;
var meltTimer = 0;
// Create scenes
scenes.push(new Scene('forest'));
scenes.push(new Scene('mountain'));
scenes.push(new Scene('garden'));
// Set initial scene
currentScene = scenes[currentSceneIndex];
game.addChild(currentScene);
// Create curtains
var leftCurtain = game.attachAsset('curtain', {
anchorX: 0,
anchorY: 0,
x: 0,
alpha: 0.8
});
var rightCurtain = game.attachAsset('curtain', {
anchorX: 1.0,
anchorY: 0,
x: 2048,
alpha: 0.8
});
// Curtain navigation
leftCurtain.down = function (x, y, obj) {
if (currentSceneIndex > 0) {
currentSceneIndex--;
switchScene();
LK.getSound('curtainSwish').play();
}
};
rightCurtain.down = function (x, y, obj) {
if (currentSceneIndex < scenes.length - 1) {
currentSceneIndex++;
switchScene();
LK.getSound('curtainSwish').play();
}
};
function switchScene() {
game.removeChild(currentScene);
currentScene = scenes[currentSceneIndex];
game.addChild(currentScene);
// Bring curtains to front
game.removeChild(leftCurtain);
game.removeChild(rightCurtain);
game.addChild(leftCurtain);
game.addChild(rightCurtain);
}
// Snow melting timer (after 30 seconds)
var snowMeltTime = 1800; // 30 seconds at 60fps
game.update = function () {
meltTimer++;
// Start melting snow after timer
if (meltTimer > snowMeltTime && !snowMelted) {
snowMelted = true;
// Melt all footprints
for (var i = footprints.length - 1; i >= 0; i--) {
footprints[i].melt();
footprints.splice(i, 1);
}
// Melt all snow angels
for (var i = snowAngels.length - 1; i >= 0; i--) {
snowAngels[i].melt();
snowAngels.splice(i, 1);
}
// Melt tree snow
for (var i = 0; i < currentScene.children.length; i++) {
var child = currentScene.children[i];
if (child.meltSnow) {
child.meltSnow();
}
}
}
// Clean up bubbles that are off screen
for (var i = bubbles.length - 1; i >= 0; i--) {
var bubble = bubbles[i];
if (bubble.y > 2800 || bubble.hasTransformed) {
bubbles.splice(i, 1);
}
}
// Clean up falling snow
for (var i = fallingSnowParticles.length - 1; i >= 0; i--) {
var snow = fallingSnowParticles[i];
if (snow.y > 2800) {
fallingSnowParticles.splice(i, 1);
}
}
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphic = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7
});
self.speed = 2 + Math.random() * 3;
self.hasTransformed = false;
self.update = function () {
self.y += self.speed;
// Transform to snow when hitting ground
if (self.y > 2300 && !self.hasTransformed) {
self.hasTransformed = true;
// Create new snow on ground
var snow = new FallingSnow();
snow.x = self.x;
snow.y = self.y;
currentScene.addChild(snow);
fallingSnowParticles.push(snow);
self.destroy();
}
// Remove if off screen
if (self.y > 2800) {
self.destroy();
}
};
return self;
});
var BubbleBottle = Container.expand(function () {
var self = Container.call(this);
var bottleGraphic = self.attachAsset('bubbleBottle', {
anchorX: 0.5,
anchorY: 1.0
});
self.down = function (x, y, obj) {
if (snowMelted) {
// Create bubbles
for (var i = 0; i < 5; i++) {
var bubble = new Bubble();
bubble.x = self.x + (Math.random() - 0.5) * 100;
bubble.y = self.y - 50;
currentScene.addChild(bubble);
bubbles.push(bubble);
}
LK.getSound('bubblePop').play();
}
};
return self;
});
var FallingSnow = Container.expand(function () {
var self = Container.call(this);
var snowGraphic = self.attachAsset('fallingSnow', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 3 + Math.random() * 2;
self.settled = false;
self.update = function () {
if (!self.settled) {
self.y += self.speed;
// Settle on ground
if (self.y > 2300) {
self.settled = true;
self.y = 2300;
self.speed = 0;
}
}
};
return self;
});
var Footprint = Container.expand(function () {
var self = Container.call(this);
var footprintGraphic = self.attachAsset('footprint', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Fade in animation
tween(footprintGraphic, {
alpha: 0.8
}, {
duration: 500
});
self.melt = function () {
tween(footprintGraphic, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Pig = Container.expand(function (pigType) {
var self = Container.call(this);
var pigBody = self.attachAsset('pigBody', {
anchorX: 0.5,
anchorY: 1.0
});
var pigHead = self.attachAsset('pigHead', {
anchorX: 0.5,
anchorY: 1.0,
y: -40
});
var pigSnout = self.attachAsset('pigSnout', {
anchorX: 0.5,
anchorY: 0.5,
y: -40
});
self.pigType = pigType || 'normal';
self.canMakeAngel = pigType === 'angel1' || pigType === 'angel2';
self.down = function (x, y, obj) {
if (self.canMakeAngel && !snowMelted) {
// Create snow angel
var angel = new SnowAngel();
angel.x = self.x;
angel.y = self.y;
currentScene.addChild(angel);
snowAngels.push(angel);
// Pig animation
tween(self, {
y: self.y + 20
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
y: self.y - 20
}, {
duration: 200
});
}
});
} else if (!snowMelted) {
// Create footprint
var footprint = new Footprint();
footprint.x = self.x;
footprint.y = self.y + 20;
currentScene.addChild(footprint);
footprints.push(footprint);
}
LK.getSound('pigSqueal').play();
};
return self;
});
var Scene = Container.expand(function (sceneType) {
var self = Container.call(this);
// Sky background
var sky = self.attachAsset('sky', {
anchorX: 0,
anchorY: 0
});
// Snow ground
var ground = self.attachAsset('snowGround', {
anchorX: 0,
anchorY: 1.0,
y: 2732
});
self.sceneType = sceneType;
self.setupScene = function () {
if (sceneType === 'forest') {
// Add trees
var tree1 = new Tree(10);
tree1.x = 400;
tree1.y = 2300;
self.addChild(tree1);
var tree2 = new Tree(8);
tree2.x = 800;
tree2.y = 2300;
self.addChild(tree2);
var tree3 = new Tree(12);
tree3.x = 1200;
tree3.y = 2300;
self.addChild(tree3);
// Add pigs
var pig1 = new Pig('normal');
pig1.x = 600;
pig1.y = 2300;
self.addChild(pig1);
var pig2 = new Pig('angel1');
pig2.x = 1000;
pig2.y = 2300;
self.addChild(pig2);
} else if (sceneType === 'mountain') {
// Add mountain
var mountain = self.attachAsset('mountain', {
anchorX: 0.5,
anchorY: 1.0,
x: 1024,
y: 2300
});
// Add sled
var sled = new Sled();
sled.x = 800;
sled.y = 1800;
self.addChild(sled);
// Add pig
var pig = new Pig('normal');
pig.x = 1200;
pig.y = 2300;
self.addChild(pig);
} else if (sceneType === 'garden') {
// Add bubble bottle
var bubbleBottle = new BubbleBottle();
bubbleBottle.x = 1024;
bubbleBottle.y = 2300;
self.addChild(bubbleBottle);
// Add angel-making pigs
var pig1 = new Pig('angel1');
pig1.x = 700;
pig1.y = 2300;
self.addChild(pig1);
var pig2 = new Pig('angel2');
pig2.x = 1300;
pig2.y = 2300;
self.addChild(pig2);
}
};
self.setupScene();
return self;
});
var Sled = Container.expand(function () {
var self = Container.call(this);
var sledGraphic = self.attachAsset('sled', {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.down = function (x, y, obj) {
if (!self.isMoving && !snowMelted) {
self.isMoving = true;
// Sled animation down the mountain
tween(self, {
x: self.x + 400,
y: self.y + 300,
rotation: 0.5
}, {
duration: 2000,
easing: tween.easeOut,
onFinish: function onFinish() {
self.isMoving = false;
// Reset position
self.x = self.x - 400;
self.y = self.y - 300;
self.rotation = 0;
}
});
LK.getSound('sledWoosh').play();
}
};
return self;
});
var SnowAngel = Container.expand(function () {
var self = Container.call(this);
var angelGraphic = self.attachAsset('snowAngel', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0
});
// Fade in animation
tween(angelGraphic, {
alpha: 0.9
}, {
duration: 800
});
self.melt = function () {
tween(angelGraphic, {
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
var Tree = Container.expand(function (snowAmount) {
var self = Container.call(this);
var treeBase = self.attachAsset('treeBase', {
anchorX: 0.5,
anchorY: 1.0
});
var treeBranch = self.attachAsset('treeBranch', {
anchorX: 0.5,
anchorY: 1.0,
y: -200
});
var treeSnow = self.attachAsset('treeSnow', {
anchorX: 0.5,
anchorY: 1.0,
y: -200
});
self.snowAmount = snowAmount || 10;
self.tapCount = 0;
self.isSnowMelted = false;
self.down = function (x, y, obj) {
if (self.tapCount < self.snowAmount && !self.isSnowMelted) {
self.tapCount++;
// Create falling snow particles
for (var i = 0; i < 3; i++) {
var snow = new FallingSnow();
snow.x = self.x + (Math.random() - 0.5) * 150;
snow.y = self.y - 150;
currentScene.addChild(snow);
fallingSnowParticles.push(snow);
}
// Shake tree animation
tween(self, {
x: self.x + 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
x: self.x - 10
}, {
duration: 100
});
}
});
LK.getSound('snowFall').play();
// Gradually reduce snow on tree
var snowScale = 1 - self.tapCount / self.snowAmount;
tween(treeSnow, {
scaleX: snowScale,
scaleY: snowScale
}, {
duration: 300
});
}
};
self.meltSnow = function () {
self.isSnowMelted = true;
tween(treeSnow, {
alpha: 0
}, {
duration: 1000
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Background elements
// Tree elements
// Pig elements
// Interactive elements
// Sounds
var scenes = [];
var currentSceneIndex = 0;
var currentScene = null;
var footprints = [];
var snowAngels = [];
var bubbles = [];
var fallingSnowParticles = [];
var snowMelted = false;
var meltTimer = 0;
// Create scenes
scenes.push(new Scene('forest'));
scenes.push(new Scene('mountain'));
scenes.push(new Scene('garden'));
// Set initial scene
currentScene = scenes[currentSceneIndex];
game.addChild(currentScene);
// Create curtains
var leftCurtain = game.attachAsset('curtain', {
anchorX: 0,
anchorY: 0,
x: 0,
alpha: 0.8
});
var rightCurtain = game.attachAsset('curtain', {
anchorX: 1.0,
anchorY: 0,
x: 2048,
alpha: 0.8
});
// Curtain navigation
leftCurtain.down = function (x, y, obj) {
if (currentSceneIndex > 0) {
currentSceneIndex--;
switchScene();
LK.getSound('curtainSwish').play();
}
};
rightCurtain.down = function (x, y, obj) {
if (currentSceneIndex < scenes.length - 1) {
currentSceneIndex++;
switchScene();
LK.getSound('curtainSwish').play();
}
};
function switchScene() {
game.removeChild(currentScene);
currentScene = scenes[currentSceneIndex];
game.addChild(currentScene);
// Bring curtains to front
game.removeChild(leftCurtain);
game.removeChild(rightCurtain);
game.addChild(leftCurtain);
game.addChild(rightCurtain);
}
// Snow melting timer (after 30 seconds)
var snowMeltTime = 1800; // 30 seconds at 60fps
game.update = function () {
meltTimer++;
// Start melting snow after timer
if (meltTimer > snowMeltTime && !snowMelted) {
snowMelted = true;
// Melt all footprints
for (var i = footprints.length - 1; i >= 0; i--) {
footprints[i].melt();
footprints.splice(i, 1);
}
// Melt all snow angels
for (var i = snowAngels.length - 1; i >= 0; i--) {
snowAngels[i].melt();
snowAngels.splice(i, 1);
}
// Melt tree snow
for (var i = 0; i < currentScene.children.length; i++) {
var child = currentScene.children[i];
if (child.meltSnow) {
child.meltSnow();
}
}
}
// Clean up bubbles that are off screen
for (var i = bubbles.length - 1; i >= 0; i--) {
var bubble = bubbles[i];
if (bubble.y > 2800 || bubble.hasTransformed) {
bubbles.splice(i, 1);
}
}
// Clean up falling snow
for (var i = fallingSnowParticles.length - 1; i >= 0; i--) {
var snow = fallingSnowParticles[i];
if (snow.y > 2800) {
fallingSnowParticles.splice(i, 1);
}
}
};