/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var TVShow = Container.expand(function () {
var self = Container.call(this);
// TV Frame and Screen
var tvFrame = self.attachAsset('tvFrame', {
anchorX: 0.5,
anchorY: 0.5
});
var tvScreen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5
});
// Play Button
var playButton = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 400
});
var buttonText = new Text2('PLAY', {
size: 60,
fill: 0x000000
});
buttonText.anchor.set(0.5, 0.5);
buttonText.y = 400;
self.addChild(buttonText);
// Scene content container
var sceneContainer = new Container();
self.addChild(sceneContainer);
self.currentScene = 0;
self.totalScenes = 8;
// Scene creation functions
function createScene1() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -200,
y: 100
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 150
});
var ball = sceneContainer.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 100
});
var sceneText = new Text2('Scene 1: Playing Fetch', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Simple animation
tween(ball, {
x: -150
}, {
duration: 1000,
easing: tween.easeInOut
});
tween(dog, {
x: -150
}, {
duration: 1200,
easing: tween.easeInOut
});
}
function createScene2() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -100,
y: 0
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 0
});
var cloud = sceneContainer.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -200
});
var sceneText = new Text2('Scene 2: Flying High', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -350;
sceneContainer.addChild(sceneText);
// Flying animation
tween(sula, {
y: -150
}, {
duration: 1500,
easing: tween.easeInOut
});
tween(dog, {
y: -150
}, {
duration: 1500,
easing: tween.easeInOut
});
}
function createScene3() {
sceneContainer.removeChildren();
var bed = sceneContainer.attachAsset('bed', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 100
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var sceneText = new Text2('Scene 3: Sleepy Time', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Sleeping animation
tween(dog, {
alpha: 0.7
}, {
duration: 1000,
easing: tween.easeInOut
});
}
function createScene4() {
sceneContainer.removeChildren();
var sun = sceneContainer.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: -200
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 100
});
var sceneText = new Text2('Scene 4: Good Morning!', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -350;
sceneContainer.addChild(sceneText);
// Morning animation
tween(sun, {
rotation: Math.PI * 2
}, {
duration: 2000,
easing: tween.linear
});
}
function createScene5() {
sceneContainer.removeChildren();
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var mess1 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 200
});
var mess2 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 200
});
var mess3 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 250
});
var sceneText = new Text2('Scene 5: Making a Mess', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Mess animation
tween(dog, {
x: -100
}, {
duration: 800,
easing: tween.easeInOut
});
setTimeout(function () {
tween(dog, {
x: 100
}, {
duration: 800,
easing: tween.easeInOut
});
}, 800);
}
function createScene6() {
sceneContainer.removeChildren();
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var tear1 = sceneContainer.attachAsset('tear', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: 0
});
var tear2 = sceneContainer.attachAsset('tear', {
anchorX: 0.5,
anchorY: 0.5,
x: 30,
y: 0
});
var sceneText = new Text2('Scene 6: Dog is Upset', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Crying animation
tween(tear1, {
y: 150
}, {
duration: 1500,
easing: tween.easeIn
});
tween(tear2, {
y: 150
}, {
duration: 1500,
easing: tween.easeIn
});
}
function createScene7() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 50
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var bing = sceneContainer.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 50
});
var broom = sceneContainer.attachAsset('broom', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 200
});
var sceneText = new Text2('Scene 7: Cleaning Together', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Cleaning animation
tween(broom, {
rotation: Math.PI / 6
}, {
duration: 500,
easing: tween.easeInOut
});
setTimeout(function () {
tween(broom, {
rotation: -Math.PI / 6
}, {
duration: 500,
easing: tween.easeInOut
});
}, 500);
}
function createScene8() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 50
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var bing = sceneContainer.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 50
});
var heart1 = sceneContainer.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: -50,
y: -100
});
var heart2 = sceneContainer.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: 50,
y: -100
});
var sceneText = new Text2('Scene 8: Happy Ending!', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Happy animation
tween(heart1, {
y: -200
}, {
duration: 1000,
easing: tween.easeOut
});
tween(heart2, {
y: -200
}, {
duration: 1000,
easing: tween.easeOut
});
// Change button text to "PLAY AGAIN"
buttonText.setText('PLAY AGAIN');
}
self.scenes = [createScene1, createScene2, createScene3, createScene4, createScene5, createScene6, createScene7, createScene8];
self.nextScene = function () {
if (self.currentScene < self.totalScenes) {
self.scenes[self.currentScene]();
self.currentScene++;
if (self.currentScene < self.totalScenes) {
buttonText.setText('CONTINUE');
} else {
buttonText.setText('PLAY AGAIN');
}
} else {
// Restart the story
self.currentScene = 0;
buttonText.setText('PLAY');
sceneContainer.removeChildren();
var titleText = new Text2('Bing Bunny:\nSula\'s Pet Dog', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = 0;
sceneContainer.addChild(titleText);
}
};
// Initial title screen
var titleText = new Text2('Bing Bunny:\nSula\'s Pet Dog', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = 0;
sceneContainer.addChild(titleText);
// Button press handler
playButton.down = function (x, y, obj) {
LK.getSound('tap').play();
// Button press animation
tween(playButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut
});
tween(buttonText, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut
});
setTimeout(function () {
tween(playButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(buttonText, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}, 100);
self.nextScene();
if (self.currentScene === self.totalScenes) {
LK.getSound('happy').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4a90e2
});
/****
* Game Code
****/
var tvShow = game.addChild(new TVShow());
tvShow.x = 2048 / 2;
tvShow.y = 2732 / 2;
// Title text
var titleText = new Text2('Bing Bunny TV Adventure', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 100;
game.update = function () {
// Game logic handled by the TVShow class
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var TVShow = Container.expand(function () {
var self = Container.call(this);
// TV Frame and Screen
var tvFrame = self.attachAsset('tvFrame', {
anchorX: 0.5,
anchorY: 0.5
});
var tvScreen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5
});
// Play Button
var playButton = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 400
});
var buttonText = new Text2('PLAY', {
size: 60,
fill: 0x000000
});
buttonText.anchor.set(0.5, 0.5);
buttonText.y = 400;
self.addChild(buttonText);
// Scene content container
var sceneContainer = new Container();
self.addChild(sceneContainer);
self.currentScene = 0;
self.totalScenes = 8;
// Scene creation functions
function createScene1() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -200,
y: 100
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 150
});
var ball = sceneContainer.attachAsset('ball', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: 100
});
var sceneText = new Text2('Scene 1: Playing Fetch', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Simple animation
tween(ball, {
x: -150
}, {
duration: 1000,
easing: tween.easeInOut
});
tween(dog, {
x: -150
}, {
duration: 1200,
easing: tween.easeInOut
});
}
function createScene2() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -100,
y: 0
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 100,
y: 0
});
var cloud = sceneContainer.attachAsset('cloud', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: -200
});
var sceneText = new Text2('Scene 2: Flying High', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -350;
sceneContainer.addChild(sceneText);
// Flying animation
tween(sula, {
y: -150
}, {
duration: 1500,
easing: tween.easeInOut
});
tween(dog, {
y: -150
}, {
duration: 1500,
easing: tween.easeInOut
});
}
function createScene3() {
sceneContainer.removeChildren();
var bed = sceneContainer.attachAsset('bed', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 100
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var sceneText = new Text2('Scene 3: Sleepy Time', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Sleeping animation
tween(dog, {
alpha: 0.7
}, {
duration: 1000,
easing: tween.easeInOut
});
}
function createScene4() {
sceneContainer.removeChildren();
var sun = sceneContainer.attachAsset('sun', {
anchorX: 0.5,
anchorY: 0.5,
x: 200,
y: -200
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 100
});
var sceneText = new Text2('Scene 4: Good Morning!', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -350;
sceneContainer.addChild(sceneText);
// Morning animation
tween(sun, {
rotation: Math.PI * 2
}, {
duration: 2000,
easing: tween.linear
});
}
function createScene5() {
sceneContainer.removeChildren();
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var mess1 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 200
});
var mess2 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 200
});
var mess3 = sceneContainer.attachAsset('mess', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 250
});
var sceneText = new Text2('Scene 5: Making a Mess', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Mess animation
tween(dog, {
x: -100
}, {
duration: 800,
easing: tween.easeInOut
});
setTimeout(function () {
tween(dog, {
x: 100
}, {
duration: 800,
easing: tween.easeInOut
});
}, 800);
}
function createScene6() {
sceneContainer.removeChildren();
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var tear1 = sceneContainer.attachAsset('tear', {
anchorX: 0.5,
anchorY: 0.5,
x: -30,
y: 0
});
var tear2 = sceneContainer.attachAsset('tear', {
anchorX: 0.5,
anchorY: 0.5,
x: 30,
y: 0
});
var sceneText = new Text2('Scene 6: Dog is Upset', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Crying animation
tween(tear1, {
y: 150
}, {
duration: 1500,
easing: tween.easeIn
});
tween(tear2, {
y: 150
}, {
duration: 1500,
easing: tween.easeIn
});
}
function createScene7() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 50
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var bing = sceneContainer.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 50
});
var broom = sceneContainer.attachAsset('broom', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 200
});
var sceneText = new Text2('Scene 7: Cleaning Together', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Cleaning animation
tween(broom, {
rotation: Math.PI / 6
}, {
duration: 500,
easing: tween.easeInOut
});
setTimeout(function () {
tween(broom, {
rotation: -Math.PI / 6
}, {
duration: 500,
easing: tween.easeInOut
});
}, 500);
}
function createScene8() {
sceneContainer.removeChildren();
var sula = sceneContainer.attachAsset('sula', {
anchorX: 0.5,
anchorY: 0.5,
x: -150,
y: 50
});
var dog = sceneContainer.attachAsset('dog', {
anchorX: 0.5,
anchorY: 0.5,
x: 0,
y: 50
});
var bing = sceneContainer.attachAsset('bing', {
anchorX: 0.5,
anchorY: 0.5,
x: 150,
y: 50
});
var heart1 = sceneContainer.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: -50,
y: -100
});
var heart2 = sceneContainer.attachAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: 50,
y: -100
});
var sceneText = new Text2('Scene 8: Happy Ending!', {
size: 80,
fill: 0xFFFFFF
});
sceneText.anchor.set(0.5, 0.5);
sceneText.y = -300;
sceneContainer.addChild(sceneText);
// Happy animation
tween(heart1, {
y: -200
}, {
duration: 1000,
easing: tween.easeOut
});
tween(heart2, {
y: -200
}, {
duration: 1000,
easing: tween.easeOut
});
// Change button text to "PLAY AGAIN"
buttonText.setText('PLAY AGAIN');
}
self.scenes = [createScene1, createScene2, createScene3, createScene4, createScene5, createScene6, createScene7, createScene8];
self.nextScene = function () {
if (self.currentScene < self.totalScenes) {
self.scenes[self.currentScene]();
self.currentScene++;
if (self.currentScene < self.totalScenes) {
buttonText.setText('CONTINUE');
} else {
buttonText.setText('PLAY AGAIN');
}
} else {
// Restart the story
self.currentScene = 0;
buttonText.setText('PLAY');
sceneContainer.removeChildren();
var titleText = new Text2('Bing Bunny:\nSula\'s Pet Dog', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = 0;
sceneContainer.addChild(titleText);
}
};
// Initial title screen
var titleText = new Text2('Bing Bunny:\nSula\'s Pet Dog', {
size: 100,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0.5);
titleText.y = 0;
sceneContainer.addChild(titleText);
// Button press handler
playButton.down = function (x, y, obj) {
LK.getSound('tap').play();
// Button press animation
tween(playButton, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut
});
tween(buttonText, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100,
easing: tween.easeInOut
});
setTimeout(function () {
tween(playButton, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
tween(buttonText, {
scaleX: 1,
scaleY: 1
}, {
duration: 100,
easing: tween.easeInOut
});
}, 100);
self.nextScene();
if (self.currentScene === self.totalScenes) {
LK.getSound('happy').play();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x4a90e2
});
/****
* Game Code
****/
var tvShow = game.addChild(new TVShow());
tvShow.x = 2048 / 2;
tvShow.y = 2732 / 2;
// Title text
var titleText = new Text2('Bing Bunny TV Adventure', {
size: 120,
fill: 0xFFFFFF
});
titleText.anchor.set(0.5, 0);
LK.gui.top.addChild(titleText);
titleText.y = 100;
game.update = function () {
// Game logic handled by the TVShow class
};