/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var PowerpuffGirl = Container.expand(function (color, name) { var self = Container.call(this); var body = self.attachAsset(name, { anchorX: 0.5, anchorY: 1 }); // Add some simple animation self.bounce = function () { tween(body, { scaleY: 1.1 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { tween(body, { scaleY: 1 }, { duration: 300, easing: tween.easeIn }); } }); }; return self; }); var StoryScene = Container.expand(function (sceneNumber) { var self = Container.call(this); self.sceneNumber = sceneNumber; self.visible = false; // Create background var background = self.attachAsset('kitchen', { anchorX: 0.5, anchorY: 0.5 }); // Create Bing Bunny var bing = self.attachAsset('bingBunny', { anchorX: 0.5, anchorY: 1, x: 0, y: 200 }); self.setupScene = function () { // Clear previous scene elements for (var i = self.children.length - 1; i >= 0; i--) { var child = self.children[i]; if (child !== background && child !== bing) { self.removeChild(child); } } // Setup scene based on scene number switch (self.sceneNumber) { case 1: // Bing chewing toys self.setupChewingScene(); break; case 2: // Washing hands self.setupWashingScene(); break; case 3: // Sitting at kitchen table self.setupKitchenTableScene(); break; case 4: // Trying tomato and saying "yuk" self.setupTomatoYukScene(); break; case 5: // Enjoying kiwi/cheese/strawberries/apple self.setupEnjoyingFoodsScene(); break; case 6: // Rejecting tomato again self.setupTomatoRejectScene(); break; case 7: // Loving carrot/egg/orange/banana self.setupLovingFoodsScene(); break; case 8: // Throwing tomato self.setupThrowingTomatoScene(); break; case 9: // Enjoying snappy carrot self.setupCarrotFinalScene(); break; } }; self.setupChewingScene = function () { bing.x = -200; bing.y = 200; }; self.setupWashingScene = function () { bing.x = 0; bing.y = 150; }; self.setupKitchenTableScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); bing.x = 0; bing.y = 100; }; self.setupTomatoYukScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); var tomato = self.attachAsset('tomato', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 200 }); bing.x = -100; bing.y = 100; }; self.setupEnjoyingFoodsScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); var kiwi = self.attachAsset('kiwi', { anchorX: 0.5, anchorY: 0.5, x: -200, y: 200 }); var cheese = self.attachAsset('cheese', { anchorX: 0.5, anchorY: 0.5, x: -100, y: 200 }); var strawberry = self.attachAsset('strawberry', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 200 }); var apple = self.attachAsset('apple', { anchorX: 0.5, anchorY: 0.5, x: 200, y: 200 }); bing.x = 0; bing.y = 100; }; self.setupTomatoRejectScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); var tomato = self.attachAsset('tomato', { anchorX: 0.5, anchorY: 0.5, x: 150, y: 200 }); bing.x = -150; bing.y = 100; }; self.setupLovingFoodsScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); var carrot = self.attachAsset('carrot', { anchorX: 0.5, anchorY: 0.5, x: -200, y: 200 }); var egg = self.attachAsset('egg', { anchorX: 0.5, anchorY: 0.5, x: -100, y: 200 }); var orange = self.attachAsset('orange', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 200 }); var banana = self.attachAsset('banana', { anchorX: 0.5, anchorY: 0.5, x: 200, y: 200 }); bing.x = 0; bing.y = 100; }; self.setupThrowingTomatoScene = function () { var trashbin = self.attachAsset('trashbin', { anchorX: 0.5, anchorY: 1, x: 200, y: 400 }); var tomato = self.attachAsset('tomato', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 100 }); bing.x = -100; bing.y = 100; // Animate tomato falling into trash tween(tomato, { x: 200, y: 300 }, { duration: 1000, easing: tween.easeIn }); }; self.setupCarrotFinalScene = function () { var table = self.attachAsset('table', { anchorX: 0.5, anchorY: 0.5, x: 0, y: 300 }); var carrot = self.attachAsset('carrot', { anchorX: 0.5, anchorY: 0.5, x: 100, y: 200 }); bing.x = -100; bing.y = 100; // Make Bing bounce happily tween(bing, { scaleY: 1.1 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { tween(bing, { scaleY: 1 }, { duration: 500, easing: tween.easeIn }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ // Game state var gameState = 'menu'; // 'menu', 'playing', 'finished' var currentScene = 1; var maxScenes = 9; var sceneTimer = 0; var sceneDisplayTime = 3000; // 3 seconds per scene var storyScenes = []; // Create TV setup var tvFrame = game.addChild(LK.getAsset('tvFrame', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1100 })); var tvScreen = game.addChild(LK.getAsset('tvScreen', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1100 })); // Create play button var playButton = game.addChild(LK.getAsset('playButton', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1100 })); var playTriangle = game.addChild(LK.getAsset('playTriangle', { anchorX: 0.5, anchorY: 0.5, x: 1024, y: 1100 })); // Create Powerpuff Girls var blossom = game.addChild(new PowerpuffGirl(0xffb6c1, 'ppgBlossom')); blossom.x = 300; blossom.y = 1800; var bubbles = game.addChild(new PowerpuffGirl(0x87ceeb, 'ppgBubbles')); bubbles.x = 1024; bubbles.y = 1900; var buttercup = game.addChild(new PowerpuffGirl(0x90ee90, 'ppgButtercup')); buttercup.x = 1700; buttercup.y = 1800; // Create all story scenes for (var i = 1; i <= maxScenes; i++) { var scene = new StoryScene(i); scene.x = 1024; scene.y = 1100; tvScreen.addChild(scene); storyScenes.push(scene); } // Create title text var titleText = new Text2('Bing Bunny: Yuk Story', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 400; game.addChild(titleText); // Handle play button click playButton.down = function (x, y, obj) { if (gameState === 'menu') { startStory(); } else if (gameState === 'finished') { restartStory(); } }; playTriangle.down = function (x, y, obj) { if (gameState === 'menu') { startStory(); } else if (gameState === 'finished') { restartStory(); } }; function startStory() { LK.getSound('click').play(); gameState = 'playing'; currentScene = 1; sceneTimer = 0; // Hide play button playButton.visible = false; playTriangle.visible = false; // Show first scene showScene(currentScene); // Make Powerpuff Girls react blossom.bounce(); bubbles.bounce(); buttercup.bounce(); } function restartStory() { LK.getSound('click').play(); gameState = 'playing'; currentScene = 1; sceneTimer = 0; // Hide play button playButton.visible = false; playTriangle.visible = false; // Show first scene showScene(currentScene); } function showScene(sceneNum) { // Hide all scenes for (var i = 0; i < storyScenes.length; i++) { storyScenes[i].visible = false; } // Show current scene if (sceneNum >= 1 && sceneNum <= maxScenes) { var scene = storyScenes[sceneNum - 1]; scene.visible = true; scene.setupScene(); // Play appropriate sound if (sceneNum === 4 || sceneNum === 6) { LK.getSound('yuk').play(); } else if (sceneNum === 5 || sceneNum === 7 || sceneNum === 9) { LK.getSound('yum').play(); } // Make Powerpuff Girls react occasionally if (sceneNum % 3 === 0) { var randomGirl = Math.floor(Math.random() * 3); if (randomGirl === 0) blossom.bounce();else if (randomGirl === 1) bubbles.bounce();else buttercup.bounce(); } } } function nextScene() { currentScene++; if (currentScene > maxScenes) { // Story finished gameState = 'finished'; showFinishedScreen(); } else { showScene(currentScene); sceneTimer = 0; } } function showFinishedScreen() { // Hide all scenes for (var i = 0; i < storyScenes.length; i++) { storyScenes[i].visible = false; } // Show play button again playButton.visible = true; playTriangle.visible = true; // Make all Powerpuff Girls bounce blossom.bounce(); bubbles.bounce(); buttercup.bounce(); } // Handle tap to advance story tvScreen.down = function (x, y, obj) { if (gameState === 'playing') { nextScene(); } }; // Game update loop game.update = function () { if (gameState === 'playing') { sceneTimer += 16; // Roughly 60 FPS // Auto-advance scene after display time if (sceneTimer >= sceneDisplayTime) { nextScene(); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var PowerpuffGirl = Container.expand(function (color, name) {
var self = Container.call(this);
var body = self.attachAsset(name, {
anchorX: 0.5,
anchorY: 1
});
// Add some simple animation
self.bounce = function () {
tween(body, {
scaleY: 1.1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(body, {
scaleY: 1
}, {
duration: 300,
easing: tween.easeIn
});
}
});
};
return self;
});
var StoryScene = Container.expand(function (sceneNumber) {
var self = Container.call(this);
self.sceneNumber = sceneNumber;
self.visible = false;
// Create background
var background = self.attachAsset('kitchen', {
anchorX: 0.5,
anchorY: 0.5
});
// Create Bing Bunny
var bing = self.attachAsset('bingBunny', {
anchorX: 0.5,
anchorY: 1,
x: 0,
y: 200
});
self.setupScene = function () {
// Clear previous scene elements
for (var i = self.children.length - 1; i >= 0; i--) {
var child = self.children[i];
if (child !== background && child !== bing) {
self.removeChild(child);
}
}
// Setup scene based on scene number
switch (self.sceneNumber) {
case 1:
// Bing chewing toys
self.setupChewingScene();
break;
case 2:
// Washing hands
self.setupWashingScene();
break;
case 3:
// Sitting at kitchen table
self.setupKitchenTableScene();
break;
case 4:
// Trying tomato and saying "yuk"
self.setupTomatoYukScene();
break;
case 5:
// Enjoying kiwi/cheese/strawberries/apple
self.setupEnjoyingFoodsScene();
break;
case 6:
// Rejecting tomato again
self.setupTomatoRejectScene();
break;
case 7:
// Loving carrot/egg/orange/banana
self.setupLovingFoodsScene();
break;
case 8:
// Throwing tomato
self.setupThrowingTomatoScene();
break;
case 9:
// Enjoying snappy carrot
self.setupCarrotFinalScene();
break;
}
};
self.setupChewingScene = function () {
bing.x = -200;
bing.y = 200;
};
self.setupWashingScene = function () {
bing.x = 0;
bing.y = 150;
};
self.setupKitchenTableScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
bing.x = 0;
bing.y = 100;
};
self.setupTomatoYukScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
var tomato = self.attachAsset('tomato', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 200
});
bing.x = -100;
bing.y = 100;
};
self.setupEnjoyingFoodsScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
var kiwi = self.attachAsset('kiwi', {
anchorX: 0.5,
anchorY: 0.5,
x: -200,
y: 200
});
var cheese = self.attachAsset('cheese', {
anchorX: 0.5,
anchorY: 0.5,
x: -100,
y: 200
});
var strawberry = self.attachAsset('strawberry', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 200
});
var apple = self.attachAsset('apple', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 200
});
bing.x = 0;
bing.y = 100;
};
self.setupTomatoRejectScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
var tomato = self.attachAsset('tomato', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 200
});
bing.x = -150;
bing.y = 100;
};
self.setupLovingFoodsScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
var carrot = self.attachAsset('carrot', {
anchorX: 0.5,
anchorY: 0.5,
x: -200,
y: 200
});
var egg = self.attachAsset('egg', {
anchorX: 0.5,
anchorY: 0.5,
x: -100,
y: 200
});
var orange = self.attachAsset('orange', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 200
});
var banana = self.attachAsset('banana', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 200
});
bing.x = 0;
bing.y = 100;
};
self.setupThrowingTomatoScene = function () {
var trashbin = self.attachAsset('trashbin', {
anchorX: 0.5,
anchorY: 1,
x: 200,
y: 400
});
var tomato = self.attachAsset('tomato', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 100
});
bing.x = -100;
bing.y = 100;
// Animate tomato falling into trash
tween(tomato, {
x: 200,
y: 300
}, {
duration: 1000,
easing: tween.easeIn
});
};
self.setupCarrotFinalScene = function () {
var table = self.attachAsset('table', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 300
});
var carrot = self.attachAsset('carrot', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 200
});
bing.x = -100;
bing.y = 100;
// Make Bing bounce happily
tween(bing, {
scaleY: 1.1
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(bing, {
scaleY: 1
}, {
duration: 500,
easing: tween.easeIn
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
// Game state
var gameState = 'menu'; // 'menu', 'playing', 'finished'
var currentScene = 1;
var maxScenes = 9;
var sceneTimer = 0;
var sceneDisplayTime = 3000; // 3 seconds per scene
var storyScenes = [];
// Create TV setup
var tvFrame = game.addChild(LK.getAsset('tvFrame', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1100
}));
var tvScreen = game.addChild(LK.getAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1100
}));
// Create play button
var playButton = game.addChild(LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1100
}));
var playTriangle = game.addChild(LK.getAsset('playTriangle', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1100
}));
// Create Powerpuff Girls
var blossom = game.addChild(new PowerpuffGirl(0xffb6c1, 'ppgBlossom'));
blossom.x = 300;
blossom.y = 1800;
var bubbles = game.addChild(new PowerpuffGirl(0x87ceeb, 'ppgBubbles'));
bubbles.x = 1024;
bubbles.y = 1900;
var buttercup = game.addChild(new PowerpuffGirl(0x90ee90, 'ppgButtercup'));
buttercup.x = 1700;
buttercup.y = 1800;
// Create all story scenes
for (var i = 1; i <= maxScenes; i++) {
var scene = new StoryScene(i);
scene.x = 1024;
scene.y = 1100;
tvScreen.addChild(scene);
storyScenes.push(scene);
}
// Create title text
var titleText = new Text2('Bing Bunny: Yuk Story', {
size: 80,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.x = 1024;
titleText.y = 400;
game.addChild(titleText);
// Handle play button click
playButton.down = function (x, y, obj) {
if (gameState === 'menu') {
startStory();
} else if (gameState === 'finished') {
restartStory();
}
};
playTriangle.down = function (x, y, obj) {
if (gameState === 'menu') {
startStory();
} else if (gameState === 'finished') {
restartStory();
}
};
function startStory() {
LK.getSound('click').play();
gameState = 'playing';
currentScene = 1;
sceneTimer = 0;
// Hide play button
playButton.visible = false;
playTriangle.visible = false;
// Show first scene
showScene(currentScene);
// Make Powerpuff Girls react
blossom.bounce();
bubbles.bounce();
buttercup.bounce();
}
function restartStory() {
LK.getSound('click').play();
gameState = 'playing';
currentScene = 1;
sceneTimer = 0;
// Hide play button
playButton.visible = false;
playTriangle.visible = false;
// Show first scene
showScene(currentScene);
}
function showScene(sceneNum) {
// Hide all scenes
for (var i = 0; i < storyScenes.length; i++) {
storyScenes[i].visible = false;
}
// Show current scene
if (sceneNum >= 1 && sceneNum <= maxScenes) {
var scene = storyScenes[sceneNum - 1];
scene.visible = true;
scene.setupScene();
// Play appropriate sound
if (sceneNum === 4 || sceneNum === 6) {
LK.getSound('yuk').play();
} else if (sceneNum === 5 || sceneNum === 7 || sceneNum === 9) {
LK.getSound('yum').play();
}
// Make Powerpuff Girls react occasionally
if (sceneNum % 3 === 0) {
var randomGirl = Math.floor(Math.random() * 3);
if (randomGirl === 0) blossom.bounce();else if (randomGirl === 1) bubbles.bounce();else buttercup.bounce();
}
}
}
function nextScene() {
currentScene++;
if (currentScene > maxScenes) {
// Story finished
gameState = 'finished';
showFinishedScreen();
} else {
showScene(currentScene);
sceneTimer = 0;
}
}
function showFinishedScreen() {
// Hide all scenes
for (var i = 0; i < storyScenes.length; i++) {
storyScenes[i].visible = false;
}
// Show play button again
playButton.visible = true;
playTriangle.visible = true;
// Make all Powerpuff Girls bounce
blossom.bounce();
bubbles.bounce();
buttercup.bounce();
}
// Handle tap to advance story
tvScreen.down = function (x, y, obj) {
if (gameState === 'playing') {
nextScene();
}
};
// Game update loop
game.update = function () {
if (gameState === 'playing') {
sceneTimer += 16; // Roughly 60 FPS
// Auto-advance scene after display time
if (sceneTimer >= sceneDisplayTime) {
nextScene();
}
}
};