/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var RainbowScene = Container.expand(function (sceneNumber) { var self = Container.call(this); // Scene background var bg = self.attachAsset('sceneBackground', { anchorX: 0.5, anchorY: 0.5 }); // Rainbow stripes var rainbowColors = ['rainbow7', 'rainbow6', 'rainbow5', 'rainbow4', 'rainbow3', 'rainbow2', 'rainbow1']; var rainbowStripes = []; for (var i = 0; i < rainbowColors.length; i++) { var stripe = LK.getAsset(rainbowColors[i], { anchorX: 0.5, anchorY: 0.5, y: -250 + i * 70, scaleY: 0.3 }); stripe.alpha = 0.8; self.addChild(stripe); rainbowStripes.push(stripe); } // Character var character = self.attachAsset('character', { anchorX: 0.5, anchorY: 0.5, y: 300 }); // Scene text var sceneTexts = ["Sula sings about purple, indigo, blue, green, and yellow colors climbing up the rainbow!", "Bing and Pando sing about sunset orange and ruby red colors sliding down the rainbow!", "Coco sings about purple, indigo, blue, green, and yellow colors climbing up the rainbow!", "The rainbow song story concludes with all friends singing together!"]; var storyText = new Text2(sceneTexts[sceneNumber - 1], { size: 60, fill: 0xFFFFFF }); storyText.anchor.set(0.5, 0.5); storyText.y = -350; storyText.style.wordWrap = true; storyText.style.wordWrapWidth = 1400; storyText.style.align = 'center'; self.addChild(storyText); // Character names for each scene var characterColors = [0xFF69B4, 0x87CEEB, 0xFFB6C1, 0x98FB98]; character.tint = characterColors[sceneNumber - 1]; // Animate rainbow self.animateRainbow = function () { for (var i = 0; i < rainbowStripes.length; i++) { var stripe = rainbowStripes[i]; stripe.scaleX = 0; tween(stripe, { scaleX: 1 }, { duration: 500 + i * 100, easing: tween.easeOut }); } // Animate character character.scaleX = 0; character.scaleY = 0; tween(character, { scaleX: 1, scaleY: 1 }, { duration: 800, easing: tween.bounceOut }); }; return self; }); var TVScreen = Container.expand(function () { var self = Container.call(this); // TV frame var frame = self.attachAsset('tvFrame', { anchorX: 0.5, anchorY: 0.5 }); // TV screen var screen = self.attachAsset('tvScreen', { anchorX: 0.5, anchorY: 0.5 }); // Play button var playBtn = self.attachAsset('playButton', { anchorX: 0.5, anchorY: 0.5, y: 400 }); var playText = new Text2('▶ PLAY', { size: 40, fill: 0xFFFFFF }); playText.anchor.set(0.5, 0.5); playBtn.addChild(playText); self.playButton = playBtn; self.screen = screen; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x1a1a1a }); /**** * Game Code ****/ var currentScene = 0; var totalScenes = 4; var tvScreen = null; var activeScene = null; var isTransitioning = false; // Create TV screen tvScreen = game.addChild(new TVScreen()); tvScreen.x = 2048 / 2; tvScreen.y = 2732 / 2; // Continue button for scenes var continueButton = null; function createContinueButton() { continueButton = LK.getAsset('playButton', { anchorX: 0.5, anchorY: 0.5 }); var continueText = new Text2('CONTINUE', { size: 35, fill: 0xFFFFFF }); continueText.anchor.set(0.5, 0.5); continueButton.addChild(continueText); continueButton.x = 2048 / 2; continueButton.y = 2732 - 200; game.addChild(continueButton); continueButton.down = function () { if (!isTransitioning) { handleContinue(); } }; } function showScene(sceneNumber) { if (isTransitioning) return; isTransitioning = true; // Hide TV screen if (tvScreen) { tween(tvScreen, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { tvScreen.visible = false; } }); } // Create and show scene activeScene = new RainbowScene(sceneNumber); activeScene.x = 2048 / 2; activeScene.y = 2732 / 2; activeScene.alpha = 0; game.addChild(activeScene); tween(activeScene, { alpha: 1 }, { duration: 500, onFinish: function onFinish() { activeScene.animateRainbow(); // Show continue button if (sceneNumber < totalScenes) { createContinueButton(); } isTransitioning = false; } }); } function handleContinue() { if (continueButton) { LK.getSound('buttonClick').play(); continueButton.destroy(); continueButton = null; } if (currentScene < totalScenes) { if (activeScene) { tween(activeScene, { alpha: 0 }, { duration: 500, onFinish: function onFinish() { activeScene.destroy(); activeScene = null; currentScene++; if (currentScene <= totalScenes) { showScene(currentScene); } else { // Story complete LK.showYouWin(); } } }); } else { currentScene++; showScene(currentScene); } } else { // Story complete LK.showYouWin(); } } // Handle play button tvScreen.playButton.down = function () { if (!isTransitioning) { LK.getSound('buttonClick').play(); handleContinue(); } }; // Make play button interactive tvScreen.playButton.alpha = 0.8; LK.setInterval(function () { if (tvScreen.playButton && currentScene === 0) { tween(tvScreen.playButton, { alpha: 1 }, { duration: 800 }); LK.setTimeout(function () { if (tvScreen.playButton) { tween(tvScreen.playButton, { alpha: 0.8 }, { duration: 800 }); } }, 800); } }, 1600); game.update = function () { // Game update logic if needed };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var RainbowScene = Container.expand(function (sceneNumber) {
var self = Container.call(this);
// Scene background
var bg = self.attachAsset('sceneBackground', {
anchorX: 0.5,
anchorY: 0.5
});
// Rainbow stripes
var rainbowColors = ['rainbow7', 'rainbow6', 'rainbow5', 'rainbow4', 'rainbow3', 'rainbow2', 'rainbow1'];
var rainbowStripes = [];
for (var i = 0; i < rainbowColors.length; i++) {
var stripe = LK.getAsset(rainbowColors[i], {
anchorX: 0.5,
anchorY: 0.5,
y: -250 + i * 70,
scaleY: 0.3
});
stripe.alpha = 0.8;
self.addChild(stripe);
rainbowStripes.push(stripe);
}
// Character
var character = self.attachAsset('character', {
anchorX: 0.5,
anchorY: 0.5,
y: 300
});
// Scene text
var sceneTexts = ["Sula sings about purple, indigo, blue, green, and yellow colors climbing up the rainbow!", "Bing and Pando sing about sunset orange and ruby red colors sliding down the rainbow!", "Coco sings about purple, indigo, blue, green, and yellow colors climbing up the rainbow!", "The rainbow song story concludes with all friends singing together!"];
var storyText = new Text2(sceneTexts[sceneNumber - 1], {
size: 60,
fill: 0xFFFFFF
});
storyText.anchor.set(0.5, 0.5);
storyText.y = -350;
storyText.style.wordWrap = true;
storyText.style.wordWrapWidth = 1400;
storyText.style.align = 'center';
self.addChild(storyText);
// Character names for each scene
var characterColors = [0xFF69B4, 0x87CEEB, 0xFFB6C1, 0x98FB98];
character.tint = characterColors[sceneNumber - 1];
// Animate rainbow
self.animateRainbow = function () {
for (var i = 0; i < rainbowStripes.length; i++) {
var stripe = rainbowStripes[i];
stripe.scaleX = 0;
tween(stripe, {
scaleX: 1
}, {
duration: 500 + i * 100,
easing: tween.easeOut
});
}
// Animate character
character.scaleX = 0;
character.scaleY = 0;
tween(character, {
scaleX: 1,
scaleY: 1
}, {
duration: 800,
easing: tween.bounceOut
});
};
return self;
});
var TVScreen = Container.expand(function () {
var self = Container.call(this);
// TV frame
var frame = self.attachAsset('tvFrame', {
anchorX: 0.5,
anchorY: 0.5
});
// TV screen
var screen = self.attachAsset('tvScreen', {
anchorX: 0.5,
anchorY: 0.5
});
// Play button
var playBtn = self.attachAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5,
y: 400
});
var playText = new Text2('▶ PLAY', {
size: 40,
fill: 0xFFFFFF
});
playText.anchor.set(0.5, 0.5);
playBtn.addChild(playText);
self.playButton = playBtn;
self.screen = screen;
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1a1a1a
});
/****
* Game Code
****/
var currentScene = 0;
var totalScenes = 4;
var tvScreen = null;
var activeScene = null;
var isTransitioning = false;
// Create TV screen
tvScreen = game.addChild(new TVScreen());
tvScreen.x = 2048 / 2;
tvScreen.y = 2732 / 2;
// Continue button for scenes
var continueButton = null;
function createContinueButton() {
continueButton = LK.getAsset('playButton', {
anchorX: 0.5,
anchorY: 0.5
});
var continueText = new Text2('CONTINUE', {
size: 35,
fill: 0xFFFFFF
});
continueText.anchor.set(0.5, 0.5);
continueButton.addChild(continueText);
continueButton.x = 2048 / 2;
continueButton.y = 2732 - 200;
game.addChild(continueButton);
continueButton.down = function () {
if (!isTransitioning) {
handleContinue();
}
};
}
function showScene(sceneNumber) {
if (isTransitioning) return;
isTransitioning = true;
// Hide TV screen
if (tvScreen) {
tween(tvScreen, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
tvScreen.visible = false;
}
});
}
// Create and show scene
activeScene = new RainbowScene(sceneNumber);
activeScene.x = 2048 / 2;
activeScene.y = 2732 / 2;
activeScene.alpha = 0;
game.addChild(activeScene);
tween(activeScene, {
alpha: 1
}, {
duration: 500,
onFinish: function onFinish() {
activeScene.animateRainbow();
// Show continue button
if (sceneNumber < totalScenes) {
createContinueButton();
}
isTransitioning = false;
}
});
}
function handleContinue() {
if (continueButton) {
LK.getSound('buttonClick').play();
continueButton.destroy();
continueButton = null;
}
if (currentScene < totalScenes) {
if (activeScene) {
tween(activeScene, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
activeScene.destroy();
activeScene = null;
currentScene++;
if (currentScene <= totalScenes) {
showScene(currentScene);
} else {
// Story complete
LK.showYouWin();
}
}
});
} else {
currentScene++;
showScene(currentScene);
}
} else {
// Story complete
LK.showYouWin();
}
}
// Handle play button
tvScreen.playButton.down = function () {
if (!isTransitioning) {
LK.getSound('buttonClick').play();
handleContinue();
}
};
// Make play button interactive
tvScreen.playButton.alpha = 0.8;
LK.setInterval(function () {
if (tvScreen.playButton && currentScene === 0) {
tween(tvScreen.playButton, {
alpha: 1
}, {
duration: 800
});
LK.setTimeout(function () {
if (tvScreen.playButton) {
tween(tvScreen.playButton, {
alpha: 0.8
}, {
duration: 800
});
}
}, 800);
}
}, 1600);
game.update = function () {
// Game update logic if needed
};