/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coal = Container.expand(function () {
var self = Container.call(this);
var coalGraphics = self.attachAsset('coal', {
anchorX: 0.5,
anchorY: 0.5
});
self.isPlaced = false;
self.targetX = 0;
self.targetY = 0;
self.down = function (x, y, obj) {
if (!self.isPlaced && currentLevel === 2 && snowballsComplete) {
self.placeOnSnowman();
LK.getSound('plop').play();
}
};
self.placeOnSnowman = function () {
if (self.isPlaced) return;
self.isPlaced = true;
tween(self, {
x: self.targetX,
y: self.targetY
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
checkLevel2Complete();
}
});
};
return self;
});
var PowerpuffGirl = Container.expand(function (color, name) {
var self = Container.call(this);
var girlGraphics = self.attachAsset(name, {
anchorX: 0.5,
anchorY: 0.5
});
self.girlName = name;
self.isActive = true;
self.originalX = 0;
self.originalY = 0;
self.down = function (x, y, obj) {
if (!self.isActive) return;
if (currentLevel === 1) {
// Snow angels
createSnowAngel(self.x, self.y);
LK.getSound('giggle').play();
checkLevel1Complete();
} else if (currentLevel === 4) {
// Dancing
self.dance();
LK.getSound('giggle').play();
checkLevel4Complete();
}
};
self.dance = function () {
tween(self, {
rotation: 0.5,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: -0.5,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: 0,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
}
});
};
return self;
});
var Sled = Container.expand(function () {
var self = Container.call(this);
var sledGraphics = self.attachAsset('sled', {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.down = function (x, y, obj) {
if (!self.isMoving && currentLevel === 3) {
self.startSledding();
LK.getSound('whoosh').play();
}
};
self.startSledding = function () {
if (self.isMoving) return;
self.isMoving = true;
tween(self, {
x: 2048 + 200,
y: 2200,
rotation: 0.3
}, {
duration: 3000,
easing: tween.easeIn,
onFinish: function onFinish() {
checkLevel3Complete();
}
});
};
return self;
});
var Snowball = Container.expand(function () {
var self = Container.call(this);
var snowballGraphics = self.attachAsset('snowball', {
anchorX: 0.5,
anchorY: 0.5
});
self.isRolled = false;
self.targetX = 0;
self.targetY = 0;
self.down = function (x, y, obj) {
if (!self.isRolled && currentLevel === 2) {
self.rollToPosition();
LK.getSound('plop').play();
}
};
self.rollToPosition = function () {
if (self.isRolled) return;
self.isRolled = true;
tween(self, {
x: self.targetX,
y: self.targetY,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
checkLevel2SnowballsComplete();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var currentLevel = storage.currentLevel || 1;
var levelTitleText;
var levelInstructionText;
var nextLevelButton;
// Level 1 variables
var girls = [];
var snowAngels = [];
var snowAngelsCreated = 0;
// Level 2 variables
var snowballs = [];
var coalPieces = [];
var snowballsComplete = false;
var coalPlaced = 0;
// Level 3 variables
var sled;
var hill;
// Level 4 variables
var selectedGirl = null;
var danceComplete = false;
// Create background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create grass ground
var grass = game.attachAsset('grass', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
});
// Create UI
levelTitleText = new Text2('Level 1: Snow Angels', {
size: 80,
fill: 0xFFFFFF
});
levelTitleText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelTitleText);
levelInstructionText = new Text2('Tap the Powerpuff Girls to make snow angels!', {
size: 40,
fill: 0xFFFFFF
});
levelInstructionText.anchor.set(0.5, 0);
levelInstructionText.y = 100;
LK.gui.top.addChild(levelInstructionText);
function initializeLevel1() {
// Clear any existing elements
clearLevel();
// Update UI
levelTitleText.setText('Level 1: Snow Angels');
levelInstructionText.setText('Tap the Powerpuff Girls to make snow angels!');
// Create Powerpuff Girls
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 500;
blossom.y = 2500;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 1024;
bubbles.y = 2500;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 1548;
buttercup.y = 2500;
girls.push(buttercup);
snowAngelsCreated = 0;
}
function initializeLevel2() {
clearLevel();
levelTitleText.setText('Level 2: Build a Snowman');
levelInstructionText.setText('Tap snowballs to roll them, then add coal features!');
// Create snowballs
var snowball1 = game.addChild(new Snowball());
snowball1.x = 300;
snowball1.y = 2500;
snowball1.targetX = 1024;
snowball1.targetY = 2400;
snowballs.push(snowball1);
var snowball2 = game.addChild(new Snowball());
snowball2.x = 1024;
snowball2.y = 2600;
snowball2.targetX = 1024;
snowball2.targetY = 2200;
snowballs.push(snowball2);
var snowball3 = game.addChild(new Snowball());
snowball3.x = 1748;
snowball3.y = 2500;
snowball3.targetX = 1024;
snowball3.targetY = 2000;
snowballs.push(snowball3);
// Create coal pieces
var coal1 = game.addChild(new Coal());
coal1.x = 200;
coal1.y = 2300;
coal1.targetX = 1000;
coal1.targetY = 1980;
coalPieces.push(coal1);
var coal2 = game.addChild(new Coal());
coal2.x = 1848;
coal2.y = 2300;
coal2.targetX = 1048;
coal2.targetY = 1980;
coalPieces.push(coal2);
var coal3 = game.addChild(new Coal());
coal3.x = 1024;
coal3.y = 2700;
coal3.targetX = 1024;
coal3.targetY = 2020;
coalPieces.push(coal3);
snowballsComplete = false;
coalPlaced = 0;
}
function initializeLevel3() {
clearLevel();
levelTitleText.setText('Level 3: Sledding Fun');
levelInstructionText.setText('Tap the sled to send the girls sledding!');
// Create hill
hill = game.attachAsset('hill', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
});
// Create sled with girls
sled = game.addChild(new Sled());
sled.x = 200;
sled.y = 1800;
// Add girls to sled
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 180;
blossom.y = 1780;
blossom.isActive = false;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 200;
bubbles.y = 1780;
bubbles.isActive = false;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 220;
buttercup.y = 1780;
buttercup.isActive = false;
girls.push(buttercup);
}
function initializeLevel4() {
clearLevel();
levelTitleText.setText('Level 4: Snow Dancing');
levelInstructionText.setText('Tap your favorite Powerpuff Girl to make her dance!');
// Create Powerpuff Girls
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 500;
blossom.y = 2500;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 1024;
bubbles.y = 2500;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 1548;
buttercup.y = 2500;
girls.push(buttercup);
danceComplete = false;
}
function clearLevel() {
// Remove all game objects
for (var i = 0; i < girls.length; i++) {
girls[i].destroy();
}
girls = [];
for (var i = 0; i < snowAngels.length; i++) {
snowAngels[i].destroy();
}
snowAngels = [];
for (var i = 0; i < snowballs.length; i++) {
snowballs[i].destroy();
}
snowballs = [];
for (var i = 0; i < coalPieces.length; i++) {
coalPieces[i].destroy();
}
coalPieces = [];
if (sled) {
sled.destroy();
sled = null;
}
if (hill) {
hill.destroy();
hill = null;
}
}
function createSnowAngel(x, y) {
var angel = game.attachAsset('snowAngel', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y + 60,
alpha: 0
});
snowAngels.push(angel);
tween(angel, {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
snowAngelsCreated++;
}
function checkLevel1Complete() {
if (snowAngelsCreated >= 3) {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
function checkLevel2SnowballsComplete() {
var rolledCount = 0;
for (var i = 0; i < snowballs.length; i++) {
if (snowballs[i].isRolled) {
rolledCount++;
}
}
if (rolledCount >= 3) {
snowballsComplete = true;
levelInstructionText.setText('Great! Now tap the coal to add features!');
}
}
function checkLevel2Complete() {
coalPlaced++;
if (coalPlaced >= 3) {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
function checkLevel3Complete() {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
function checkLevel4Complete() {
if (!danceComplete) {
danceComplete = true;
LK.setTimeout(function () {
levelInstructionText.setText('Wonderful dancing! You completed all levels!');
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}, 2000);
}
}
function nextLevel() {
currentLevel++;
storage.currentLevel = currentLevel;
if (currentLevel === 2) {
initializeLevel2();
} else if (currentLevel === 3) {
initializeLevel3();
} else if (currentLevel === 4) {
initializeLevel4();
}
}
// Initialize first level
initializeLevel1(); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Coal = Container.expand(function () {
var self = Container.call(this);
var coalGraphics = self.attachAsset('coal', {
anchorX: 0.5,
anchorY: 0.5
});
self.isPlaced = false;
self.targetX = 0;
self.targetY = 0;
self.down = function (x, y, obj) {
if (!self.isPlaced && currentLevel === 2 && snowballsComplete) {
self.placeOnSnowman();
LK.getSound('plop').play();
}
};
self.placeOnSnowman = function () {
if (self.isPlaced) return;
self.isPlaced = true;
tween(self, {
x: self.targetX,
y: self.targetY
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
checkLevel2Complete();
}
});
};
return self;
});
var PowerpuffGirl = Container.expand(function (color, name) {
var self = Container.call(this);
var girlGraphics = self.attachAsset(name, {
anchorX: 0.5,
anchorY: 0.5
});
self.girlName = name;
self.isActive = true;
self.originalX = 0;
self.originalY = 0;
self.down = function (x, y, obj) {
if (!self.isActive) return;
if (currentLevel === 1) {
// Snow angels
createSnowAngel(self.x, self.y);
LK.getSound('giggle').play();
checkLevel1Complete();
} else if (currentLevel === 4) {
// Dancing
self.dance();
LK.getSound('giggle').play();
checkLevel4Complete();
}
};
self.dance = function () {
tween(self, {
rotation: 0.5,
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: -0.5,
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(self, {
rotation: 0,
scaleX: 1,
scaleY: 1
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
}
});
};
return self;
});
var Sled = Container.expand(function () {
var self = Container.call(this);
var sledGraphics = self.attachAsset('sled', {
anchorX: 0.5,
anchorY: 0.5
});
self.isMoving = false;
self.down = function (x, y, obj) {
if (!self.isMoving && currentLevel === 3) {
self.startSledding();
LK.getSound('whoosh').play();
}
};
self.startSledding = function () {
if (self.isMoving) return;
self.isMoving = true;
tween(self, {
x: 2048 + 200,
y: 2200,
rotation: 0.3
}, {
duration: 3000,
easing: tween.easeIn,
onFinish: function onFinish() {
checkLevel3Complete();
}
});
};
return self;
});
var Snowball = Container.expand(function () {
var self = Container.call(this);
var snowballGraphics = self.attachAsset('snowball', {
anchorX: 0.5,
anchorY: 0.5
});
self.isRolled = false;
self.targetX = 0;
self.targetY = 0;
self.down = function (x, y, obj) {
if (!self.isRolled && currentLevel === 2) {
self.rollToPosition();
LK.getSound('plop').play();
}
};
self.rollToPosition = function () {
if (self.isRolled) return;
self.isRolled = true;
tween(self, {
x: self.targetX,
y: self.targetY,
scaleX: 1.5,
scaleY: 1.5
}, {
duration: 1000,
easing: tween.easeOut,
onFinish: function onFinish() {
checkLevel2SnowballsComplete();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var currentLevel = storage.currentLevel || 1;
var levelTitleText;
var levelInstructionText;
var nextLevelButton;
// Level 1 variables
var girls = [];
var snowAngels = [];
var snowAngelsCreated = 0;
// Level 2 variables
var snowballs = [];
var coalPieces = [];
var snowballsComplete = false;
var coalPlaced = 0;
// Level 3 variables
var sled;
var hill;
// Level 4 variables
var selectedGirl = null;
var danceComplete = false;
// Create background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create grass ground
var grass = game.attachAsset('grass', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
});
// Create UI
levelTitleText = new Text2('Level 1: Snow Angels', {
size: 80,
fill: 0xFFFFFF
});
levelTitleText.anchor.set(0.5, 0);
LK.gui.top.addChild(levelTitleText);
levelInstructionText = new Text2('Tap the Powerpuff Girls to make snow angels!', {
size: 40,
fill: 0xFFFFFF
});
levelInstructionText.anchor.set(0.5, 0);
levelInstructionText.y = 100;
LK.gui.top.addChild(levelInstructionText);
function initializeLevel1() {
// Clear any existing elements
clearLevel();
// Update UI
levelTitleText.setText('Level 1: Snow Angels');
levelInstructionText.setText('Tap the Powerpuff Girls to make snow angels!');
// Create Powerpuff Girls
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 500;
blossom.y = 2500;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 1024;
bubbles.y = 2500;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 1548;
buttercup.y = 2500;
girls.push(buttercup);
snowAngelsCreated = 0;
}
function initializeLevel2() {
clearLevel();
levelTitleText.setText('Level 2: Build a Snowman');
levelInstructionText.setText('Tap snowballs to roll them, then add coal features!');
// Create snowballs
var snowball1 = game.addChild(new Snowball());
snowball1.x = 300;
snowball1.y = 2500;
snowball1.targetX = 1024;
snowball1.targetY = 2400;
snowballs.push(snowball1);
var snowball2 = game.addChild(new Snowball());
snowball2.x = 1024;
snowball2.y = 2600;
snowball2.targetX = 1024;
snowball2.targetY = 2200;
snowballs.push(snowball2);
var snowball3 = game.addChild(new Snowball());
snowball3.x = 1748;
snowball3.y = 2500;
snowball3.targetX = 1024;
snowball3.targetY = 2000;
snowballs.push(snowball3);
// Create coal pieces
var coal1 = game.addChild(new Coal());
coal1.x = 200;
coal1.y = 2300;
coal1.targetX = 1000;
coal1.targetY = 1980;
coalPieces.push(coal1);
var coal2 = game.addChild(new Coal());
coal2.x = 1848;
coal2.y = 2300;
coal2.targetX = 1048;
coal2.targetY = 1980;
coalPieces.push(coal2);
var coal3 = game.addChild(new Coal());
coal3.x = 1024;
coal3.y = 2700;
coal3.targetX = 1024;
coal3.targetY = 2020;
coalPieces.push(coal3);
snowballsComplete = false;
coalPlaced = 0;
}
function initializeLevel3() {
clearLevel();
levelTitleText.setText('Level 3: Sledding Fun');
levelInstructionText.setText('Tap the sled to send the girls sledding!');
// Create hill
hill = game.attachAsset('hill', {
anchorX: 0,
anchorY: 1,
x: 0,
y: 2732
});
// Create sled with girls
sled = game.addChild(new Sled());
sled.x = 200;
sled.y = 1800;
// Add girls to sled
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 180;
blossom.y = 1780;
blossom.isActive = false;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 200;
bubbles.y = 1780;
bubbles.isActive = false;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 220;
buttercup.y = 1780;
buttercup.isActive = false;
girls.push(buttercup);
}
function initializeLevel4() {
clearLevel();
levelTitleText.setText('Level 4: Snow Dancing');
levelInstructionText.setText('Tap your favorite Powerpuff Girl to make her dance!');
// Create Powerpuff Girls
var blossom = game.addChild(new PowerpuffGirl(0xFF69B4, 'blossom'));
blossom.x = 500;
blossom.y = 2500;
girls.push(blossom);
var bubbles = game.addChild(new PowerpuffGirl(0x00BFFF, 'bubbles'));
bubbles.x = 1024;
bubbles.y = 2500;
girls.push(bubbles);
var buttercup = game.addChild(new PowerpuffGirl(0x9ACD32, 'buttercup'));
buttercup.x = 1548;
buttercup.y = 2500;
girls.push(buttercup);
danceComplete = false;
}
function clearLevel() {
// Remove all game objects
for (var i = 0; i < girls.length; i++) {
girls[i].destroy();
}
girls = [];
for (var i = 0; i < snowAngels.length; i++) {
snowAngels[i].destroy();
}
snowAngels = [];
for (var i = 0; i < snowballs.length; i++) {
snowballs[i].destroy();
}
snowballs = [];
for (var i = 0; i < coalPieces.length; i++) {
coalPieces[i].destroy();
}
coalPieces = [];
if (sled) {
sled.destroy();
sled = null;
}
if (hill) {
hill.destroy();
hill = null;
}
}
function createSnowAngel(x, y) {
var angel = game.attachAsset('snowAngel', {
anchorX: 0.5,
anchorY: 0.5,
x: x,
y: y + 60,
alpha: 0
});
snowAngels.push(angel);
tween(angel, {
alpha: 1
}, {
duration: 500,
easing: tween.easeOut
});
snowAngelsCreated++;
}
function checkLevel1Complete() {
if (snowAngelsCreated >= 3) {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
function checkLevel2SnowballsComplete() {
var rolledCount = 0;
for (var i = 0; i < snowballs.length; i++) {
if (snowballs[i].isRolled) {
rolledCount++;
}
}
if (rolledCount >= 3) {
snowballsComplete = true;
levelInstructionText.setText('Great! Now tap the coal to add features!');
}
}
function checkLevel2Complete() {
coalPlaced++;
if (coalPlaced >= 3) {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
}
function checkLevel3Complete() {
LK.setTimeout(function () {
nextLevel();
}, 1000);
}
function checkLevel4Complete() {
if (!danceComplete) {
danceComplete = true;
LK.setTimeout(function () {
levelInstructionText.setText('Wonderful dancing! You completed all levels!');
LK.setTimeout(function () {
LK.showYouWin();
}, 2000);
}, 2000);
}
}
function nextLevel() {
currentLevel++;
storage.currentLevel = currentLevel;
if (currentLevel === 2) {
initializeLevel2();
} else if (currentLevel === 3) {
initializeLevel3();
} else if (currentLevel === 4) {
initializeLevel4();
}
}
// Initialize first level
initializeLevel1();