/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Snowflake = Container.expand(function () { var self = Container.call(this); var snowGraphics = self.attachAsset('snowflake', { anchorX: 0.5, anchorY: 0.5 }); self.speed = Math.random() * 3 + 1; self.sway = Math.random() * 2 - 1; self.update = function () { self.y += self.speed; self.x += self.sway; if (self.y > 1000) { self.y = -50; self.x = Math.random() * 1600; } if (self.x < -50) self.x = 1650; if (self.x > 1650) self.x = -50; }; return self; }); var StoryScene = Container.expand(function () { var self = Container.call(this); self.sceneNumber = 1; self.snowflakes = []; self.setupScene = function (sceneNum) { self.sceneNumber = sceneNum; // Clear previous scene while (self.children.length > 0) { self.removeChild(self.children[0]); } self.snowflakes = []; // Add ground for most scenes if (sceneNum !== 5) { var ground = self.attachAsset('ground', { anchorX: 0, anchorY: 0, x: 0, y: 800 }); } // Scene-specific setup switch (sceneNum) { case 1: self.setupScene1(); break; case 2: self.setupScene2(); break; case 3: self.setupScene3(); break; case 4: self.setupScene4(); break; case 5: self.setupScene5(); break; case 6: self.setupScene6(); break; case 7: self.setupScene7(); break; } }; self.setupScene1 = function () { // Window var window = self.attachAsset('window', { anchorX: 0.5, anchorY: 0.5, x: 400, y: 400 }); // Bing at window var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 400, y: 600 }); // Add snowflakes for (var i = 0; i < 15; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1600; snowflake.y = Math.random() * 1000; self.addChild(snowflake); self.snowflakes.push(snowflake); } }; self.setupScene2 = function () { // Bing playing outside var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 800, y: 600 }); // Trees var tree1 = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, x: 300, y: 800 }); var tree2 = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, x: 1300, y: 800 }); // Light snowfall for (var i = 0; i < 10; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1600; snowflake.y = Math.random() * 1000; self.addChild(snowflake); self.snowflakes.push(snowflake); } }; self.setupScene3 = function () { // Bing and Sula meeting var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 600, y: 600 }); var sula = self.attachAsset('sula', { anchorX: 0.5, anchorY: 0.5, x: 1000, y: 600 }); // More trees var tree1 = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, x: 200, y: 800 }); var tree2 = self.attachAsset('tree', { anchorX: 0.5, anchorY: 1, x: 1400, y: 800 }); // Light snowfall for (var i = 0; i < 8; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1600; snowflake.y = Math.random() * 1000; self.addChild(snowflake); self.snowflakes.push(snowflake); } }; self.setupScene4 = function () { // Bing and Sula in snowstorm var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 650, y: 600 }); var sula = self.attachAsset('sula', { anchorX: 0.5, anchorY: 0.5, x: 950, y: 600 }); // Heavy snowfall for (var i = 0; i < 30; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1600; snowflake.y = Math.random() * 1000; snowflake.speed = Math.random() * 8 + 4; self.addChild(snowflake); self.snowflakes.push(snowflake); } }; self.setupScene5 = function () { // Grey clouds background for (var i = 0; i < 8; i++) { var cloud = self.attachAsset('cloud', { anchorX: 0.5, anchorY: 0.5, x: Math.random() * 1600, y: Math.random() * 1000 }); } // Falling sleigh var sleigh = self.attachAsset('sleigh', { anchorX: 0.5, anchorY: 0.5, x: 800, y: 300 }); var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 750, y: 280 }); var sula = self.attachAsset('sula', { anchorX: 0.5, anchorY: 0.5, x: 850, y: 280 }); // Animate falling tween(sleigh, { y: 600 }, { duration: 2000, easing: tween.easeIn }); tween(bing, { y: 580 }, { duration: 2000, easing: tween.easeIn }); tween(sula, { y: 580 }, { duration: 2000, easing: tween.easeIn }); }; self.setupScene6 = function () { // Bing and Sula stuck in ropes var rope1 = self.attachAsset('rope', { anchorX: 0.5, anchorY: 0, x: 650, y: 200 }); var rope2 = self.attachAsset('rope', { anchorX: 0.5, anchorY: 0, x: 950, y: 200 }); var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 650, y: 600 }); var sula = self.attachAsset('sula', { anchorX: 0.5, anchorY: 0.5, x: 950, y: 600 }); // Make them shake (distress animation) tween(bing, { x: 670 }, { duration: 200, easing: tween.linear, onFinish: function onFinish() { tween(bing, { x: 630 }, { duration: 200, easing: tween.linear, onFinish: function onFinish() { tween(bing, { x: 650 }, { duration: 200, easing: tween.linear }); } }); } }); tween(sula, { x: 970 }, { duration: 200, easing: tween.linear, onFinish: function onFinish() { tween(sula, { x: 930 }, { duration: 200, easing: tween.linear, onFinish: function onFinish() { tween(sula, { x: 950 }, { duration: 200, easing: tween.linear }); } }); } }); }; self.setupScene7 = function () { // Pando rescuing them var pando = self.attachAsset('pando', { anchorX: 0.5, anchorY: 0.5, x: 800, y: 400 }); var bing = self.attachAsset('bing', { anchorX: 0.5, anchorY: 0.5, x: 600, y: 600 }); var sula = self.attachAsset('sula', { anchorX: 0.5, anchorY: 0.5, x: 1000, y: 600 }); // Light celebratory snowfall for (var i = 0; i < 12; i++) { var snowflake = new Snowflake(); snowflake.x = Math.random() * 1600; snowflake.y = Math.random() * 1000; self.addChild(snowflake); self.snowflakes.push(snowflake); } }; self.update = function () { for (var i = 0; i < self.snowflakes.length; i++) { // Snowflakes update themselves } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Sound effects // Scene elements // Story characters // Powerpuff Girls // Background and UI elements var gameState = 'menu'; // 'menu', 'story', 'complete' var currentScene = 1; var maxScenes = 7; // Create TV frame var tvFrame = game.addChild(LK.getAsset('tvFrame', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1000 })); // Create TV screen var tvScreen = game.addChild(LK.getAsset('tvScreen', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1000 })); // Create Powerpuff Girls var blossom = game.addChild(LK.getAsset('blossom', { anchorX: 0.5, anchorY: 1, x: 400, y: 1800 })); var bubbles = game.addChild(LK.getAsset('bubbles', { anchorX: 0.5, anchorY: 1, x: 650, y: 1800 })); var buttercup = game.addChild(LK.getAsset('buttercup', { anchorX: 0.5, anchorY: 1, x: 1600, y: 1800 })); // Create story scene container var storyScene = new StoryScene(); storyScene.x = 224; // Offset to center in TV screen storyScene.y = 500; game.addChild(storyScene); // Create buttons var playButton = game.addChild(LK.getAsset('playButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1200 })); var continueButton = game.addChild(LK.getAsset('continueButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1600 })); var doneButton = game.addChild(LK.getAsset('doneButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1600 })); // Create button texts var playText = new Text2('PLAY', { size: 40, fill: 0xFFFFFF }); playText.anchor.set(0.5, 0.5); playText.x = 1024; playText.y = 1200; game.addChild(playText); var continueText = new Text2('CONTINUE', { size: 35, fill: 0xFFFFFF }); continueText.anchor.set(0.5, 0.5); continueText.x = 1024; continueText.y = 1600; game.addChild(continueText); var doneText = new Text2('DONE', { size: 40, fill: 0xFFFFFF }); doneText.anchor.set(0.5, 0.5); doneText.x = 1024; doneText.y = 1600; game.addChild(doneText); // Create scene title var sceneTitle = new Text2('Bing Bunny\'s Christmas Adventure', { size: 50, fill: 0xFFFFFF }); sceneTitle.anchor.set(0.5, 0.5); sceneTitle.x = 1024; sceneTitle.y = 200; game.addChild(sceneTitle); // Update button visibility function updateUI() { playButton.visible = gameState === 'menu'; playText.visible = gameState === 'menu'; continueButton.visible = gameState === 'story' && currentScene < maxScenes; continueText.visible = gameState === 'story' && currentScene < maxScenes; doneButton.visible = gameState === 'story' && currentScene === maxScenes; doneText.visible = gameState === 'story' && currentScene === maxScenes; storyScene.visible = gameState === 'story'; sceneTitle.visible = gameState === 'story'; } // Initialize UI updateUI(); // Handle button clicks game.down = function (x, y, obj) { if (gameState === 'menu' && playButton.visible) { // Check if click is on play button var buttonBounds = playButton.getBounds(); if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) { LK.getSound('click').play(); gameState = 'story'; currentScene = 1; storyScene.setupScene(currentScene); updateUI(); } } else if (gameState === 'story' && continueButton.visible) { // Check if click is on continue button var buttonBounds = continueButton.getBounds(); if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) { LK.getSound('click').play(); currentScene++; if (currentScene <= maxScenes) { storyScene.setupScene(currentScene); updateUI(); // Play sound effects for certain scenes if (currentScene === 4) { LK.getSound('wind').play(); } else if (currentScene === 6) { LK.getSound('scream').play(); } } } } else if (gameState === 'story' && doneButton.visible) { // Check if click is on done button var buttonBounds = doneButton.getBounds(); if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) { LK.getSound('click').play(); gameState = 'menu'; currentScene = 1; updateUI(); } } }; game.update = function () { // Update story scene animations if (gameState === 'story') { // Story scene updates itself and its snowflakes } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Snowflake = Container.expand(function () {
var self = Container.call(this);
var snowGraphics = self.attachAsset('snowflake', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = Math.random() * 3 + 1;
self.sway = Math.random() * 2 - 1;
self.update = function () {
self.y += self.speed;
self.x += self.sway;
if (self.y > 1000) {
self.y = -50;
self.x = Math.random() * 1600;
}
if (self.x < -50) self.x = 1650;
if (self.x > 1650) self.x = -50;
};
return self;
});
var StoryScene = Container.expand(function () {
var self = Container.call(this);
self.sceneNumber = 1;
self.snowflakes = [];
self.setupScene = function (sceneNum) {
self.sceneNumber = sceneNum;
// Clear previous scene
while (self.children.length > 0) {
self.removeChild(self.children[0]);
}
self.snowflakes = [];
// Add ground for most scenes
if (sceneNum !== 5) {
var ground = self.attachAsset('ground', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 800
});
}
// Scene-specific setup
switch (sceneNum) {
case 1:
self.setupScene1();
break;
case 2:
self.setupScene2();
break;
case 3:
self.setupScene3();
break;
case 4:
self.setupScene4();
break;
case 5:
self.setupScene5();
break;
case 6:
self.setupScene6();
break;
case 7:
self.setupScene7();
break;
}
};
self.setupScene1 = function () {
// Window
var window = self.attachAsset('window', {
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: 400
});
// Bing at window
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 400,
y: 600
});
// Add snowflakes
for (var i = 0; i < 15; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 1600;
snowflake.y = Math.random() * 1000;
self.addChild(snowflake);
self.snowflakes.push(snowflake);
}
};
self.setupScene2 = function () {
// Bing playing outside
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: 600
});
// Trees
var tree1 = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
x: 300,
y: 800
});
var tree2 = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
x: 1300,
y: 800
});
// Light snowfall
for (var i = 0; i < 10; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 1600;
snowflake.y = Math.random() * 1000;
self.addChild(snowflake);
self.snowflakes.push(snowflake);
}
};
self.setupScene3 = function () {
// Bing and Sula meeting
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: 600
});
var sula = self.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: 1000,
y: 600
});
// More trees
var tree1 = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
x: 200,
y: 800
});
var tree2 = self.attachAsset('tree', {
anchorX: 0.5,
anchorY: 1,
x: 1400,
y: 800
});
// Light snowfall
for (var i = 0; i < 8; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 1600;
snowflake.y = Math.random() * 1000;
self.addChild(snowflake);
self.snowflakes.push(snowflake);
}
};
self.setupScene4 = function () {
// Bing and Sula in snowstorm
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 650,
y: 600
});
var sula = self.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: 950,
y: 600
});
// Heavy snowfall
for (var i = 0; i < 30; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 1600;
snowflake.y = Math.random() * 1000;
snowflake.speed = Math.random() * 8 + 4;
self.addChild(snowflake);
self.snowflakes.push(snowflake);
}
};
self.setupScene5 = function () {
// Grey clouds background
for (var i = 0; i < 8; i++) {
var cloud = self.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.random() * 1600,
y: Math.random() * 1000
});
}
// Falling sleigh
var sleigh = self.attachAsset('sleigh', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: 300
});
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 750,
y: 280
});
var sula = self.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: 850,
y: 280
});
// Animate falling
tween(sleigh, {
y: 600
}, {
duration: 2000,
easing: tween.easeIn
});
tween(bing, {
y: 580
}, {
duration: 2000,
easing: tween.easeIn
});
tween(sula, {
y: 580
}, {
duration: 2000,
easing: tween.easeIn
});
};
self.setupScene6 = function () {
// Bing and Sula stuck in ropes
var rope1 = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0,
x: 650,
y: 200
});
var rope2 = self.attachAsset('rope', {
anchorX: 0.5,
anchorY: 0,
x: 950,
y: 200
});
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 650,
y: 600
});
var sula = self.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: 950,
y: 600
});
// Make them shake (distress animation)
tween(bing, {
x: 670
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(bing, {
x: 630
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(bing, {
x: 650
}, {
duration: 200,
easing: tween.linear
});
}
});
}
});
tween(sula, {
x: 970
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(sula, {
x: 930
}, {
duration: 200,
easing: tween.linear,
onFinish: function onFinish() {
tween(sula, {
x: 950
}, {
duration: 200,
easing: tween.linear
});
}
});
}
});
};
self.setupScene7 = function () {
// Pando rescuing them
var pando = self.attachAsset('pando', {
anchorX: 0.5,
anchorY: 0.5,
x: 800,
y: 400
});
var bing = self.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 600,
y: 600
});
var sula = self.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: 1000,
y: 600
});
// Light celebratory snowfall
for (var i = 0; i < 12; i++) {
var snowflake = new Snowflake();
snowflake.x = Math.random() * 1600;
snowflake.y = Math.random() * 1000;
self.addChild(snowflake);
self.snowflakes.push(snowflake);
}
};
self.update = function () {
for (var i = 0; i < self.snowflakes.length; i++) {
// Snowflakes update themselves
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Sound effects
// Scene elements
// Story characters
// Powerpuff Girls
// Background and UI elements
var gameState = 'menu'; // 'menu', 'story', 'complete'
var currentScene = 1;
var maxScenes = 7;
// Create TV frame
var tvFrame = game.addChild(LK.getAsset('tvFrame', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000
}));
// Create TV screen
var tvScreen = game.addChild(LK.getAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1000
}));
// Create Powerpuff Girls
var blossom = game.addChild(LK.getAsset('blossom', {
anchorX: 0.5,
anchorY: 1,
x: 400,
y: 1800
}));
var bubbles = game.addChild(LK.getAsset('bubbles', {
anchorX: 0.5,
anchorY: 1,
x: 650,
y: 1800
}));
var buttercup = game.addChild(LK.getAsset('buttercup', {
anchorX: 0.5,
anchorY: 1,
x: 1600,
y: 1800
}));
// Create story scene container
var storyScene = new StoryScene();
storyScene.x = 224; // Offset to center in TV screen
storyScene.y = 500;
game.addChild(storyScene);
// Create buttons
var playButton = game.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1200
}));
var continueButton = game.addChild(LK.getAsset('continueButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
}));
var doneButton = game.addChild(LK.getAsset('doneButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1600
}));
// Create button texts
var playText = new Text2('PLAY', {
size: 40,
fill: 0xFFFFFF
});
playText.anchor.set(0.5, 0.5);
playText.x = 1024;
playText.y = 1200;
game.addChild(playText);
var continueText = new Text2('CONTINUE', {
size: 35,
fill: 0xFFFFFF
});
continueText.anchor.set(0.5, 0.5);
continueText.x = 1024;
continueText.y = 1600;
game.addChild(continueText);
var doneText = new Text2('DONE', {
size: 40,
fill: 0xFFFFFF
});
doneText.anchor.set(0.5, 0.5);
doneText.x = 1024;
doneText.y = 1600;
game.addChild(doneText);
// Create scene title
var sceneTitle = new Text2('Bing Bunny\'s Christmas Adventure', {
size: 50,
fill: 0xFFFFFF
});
sceneTitle.anchor.set(0.5, 0.5);
sceneTitle.x = 1024;
sceneTitle.y = 200;
game.addChild(sceneTitle);
// Update button visibility
function updateUI() {
playButton.visible = gameState === 'menu';
playText.visible = gameState === 'menu';
continueButton.visible = gameState === 'story' && currentScene < maxScenes;
continueText.visible = gameState === 'story' && currentScene < maxScenes;
doneButton.visible = gameState === 'story' && currentScene === maxScenes;
doneText.visible = gameState === 'story' && currentScene === maxScenes;
storyScene.visible = gameState === 'story';
sceneTitle.visible = gameState === 'story';
}
// Initialize UI
updateUI();
// Handle button clicks
game.down = function (x, y, obj) {
if (gameState === 'menu' && playButton.visible) {
// Check if click is on play button
var buttonBounds = playButton.getBounds();
if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) {
LK.getSound('click').play();
gameState = 'story';
currentScene = 1;
storyScene.setupScene(currentScene);
updateUI();
}
} else if (gameState === 'story' && continueButton.visible) {
// Check if click is on continue button
var buttonBounds = continueButton.getBounds();
if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) {
LK.getSound('click').play();
currentScene++;
if (currentScene <= maxScenes) {
storyScene.setupScene(currentScene);
updateUI();
// Play sound effects for certain scenes
if (currentScene === 4) {
LK.getSound('wind').play();
} else if (currentScene === 6) {
LK.getSound('scream').play();
}
}
}
} else if (gameState === 'story' && doneButton.visible) {
// Check if click is on done button
var buttonBounds = doneButton.getBounds();
if (x >= buttonBounds.x && x <= buttonBounds.x + buttonBounds.width && y >= buttonBounds.y && y <= buttonBounds.y + buttonBounds.height) {
LK.getSound('click').play();
gameState = 'menu';
currentScene = 1;
updateUI();
}
}
};
game.update = function () {
// Update story scene animations
if (gameState === 'story') {
// Story scene updates itself and its snowflakes
}
};