/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BlackHole = Container.expand(function (holeType) { var self = Container.call(this); var holeGraphics = self.attachAsset(holeType + 'BlackHole', { anchorX: 0.5, anchorY: 0.5 }); self.holeType = holeType; self.particles = []; self.update = function () { // Create particles if (LK.ticks % 20 === 0) { self.createParticle(); } // Update particles for (var i = self.particles.length - 1; i >= 0; i--) { var particle = self.particles[i]; particle.y += particle.speed; particle.alpha -= 0.02; if (particle.alpha <= 0 || particle.y > self.y + 200) { particle.destroy(); self.particles.splice(i, 1); } } }; self.createParticle = function () { var particleType = self.holeType === 'cold' ? 'snowflake' : 'flame'; var particle = LK.getAsset(particleType, { anchorX: 0.5, anchorY: 0.5 }); particle.x = self.x + (Math.random() - 0.5) * 300; particle.y = self.y - 200; particle.speed = self.holeType === 'cold' ? 2 : 3; particle.alpha = 1; if (self.holeType === 'hot') { particle.scaleY = Math.random() * 0.5 + 0.5; } self.particles.push(particle); self.addChild(particle); }; return self; }); var PowerpuffGirl = Container.expand(function (girlType) { var self = Container.call(this); var girlGraphics = self.attachAsset(girlType + 'Girl', { anchorX: 0.5, anchorY: 0.5 }); self.girlType = girlType; self.rescued = false; self.shivering = true; self.down = function (x, y, obj) { if (!self.rescued) { LK.getSound('girlTap').play(); self.speak(); } }; self.speak = function () { // Flash girl to show she's speaking LK.effects.flashObject(self, 0xffffff, 300); // Shiver animation if (self.shivering) { tween(self, { x: self.x + 5 }, { duration: 100, onFinish: function onFinish() { tween(self, { x: self.x - 10 }, { duration: 100, onFinish: function onFinish() { tween(self, { x: self.x + 5 }, { duration: 100 }); } }); } }); } }; self.stopShivering = function () { self.shivering = false; self.rescued = true; // Happy bounce animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 200 }); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2c3e50 }); /**** * Game Code ****/ var coldHole = game.addChild(new BlackHole('cold')); coldHole.x = 500; coldHole.y = 1000; var hotHole = game.addChild(new BlackHole('hot')); hotHole.x = 1500; hotHole.y = 2000; var girls = []; var blossom = new PowerpuffGirl('blossom'); var bubbles = new PowerpuffGirl('bubbles'); var buttercup = new PowerpuffGirl('buttercup'); girls.push(blossom, bubbles, buttercup); // Position girls in cold hole blossom.x = coldHole.x - 80; blossom.y = coldHole.y; bubbles.x = coldHole.x; bubbles.y = coldHole.y - 60; buttercup.x = coldHole.x + 80; buttercup.y = coldHole.y; coldHole.addChild(blossom); coldHole.addChild(bubbles); coldHole.addChild(buttercup); var dragNode = null; var dragOffset = { x: 0, y: 0 }; function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x - dragOffset.x; dragNode.y = y - dragOffset.y; // Keep within bounds dragNode.x = Math.max(200, Math.min(1848, dragNode.x)); dragNode.y = Math.max(200, Math.min(2532, dragNode.y)); } } game.move = handleMove; game.down = function (x, y, obj) { if (coldHole.x - 200 < x && x < coldHole.x + 200 && coldHole.y - 200 < y && y < coldHole.y + 200) { dragNode = coldHole; dragOffset.x = x - coldHole.x; dragOffset.y = y - coldHole.y; } }; game.up = function (x, y, obj) { if (dragNode === coldHole) { // Check if close enough to hot hole var distance = Math.sqrt(Math.pow(coldHole.x - hotHole.x, 2) + Math.pow(coldHole.y - hotHole.y, 2)); if (distance < 300) { // Merge holes - rescue girls rescueGirls(); } } dragNode = null; }; function rescueGirls() { LK.getSound('rescue').play(); // Move girls to hot hole for (var i = 0; i < girls.length; i++) { var girl = girls[i]; girl.stopShivering(); // Remove from cold hole and add to hot hole coldHole.removeChild(girl); hotHole.addChild(girl); // Position in hot hole girl.x = (i - 1) * 80; girl.y = -50; } // Move cold hole to hot hole position tween(coldHole, { x: hotHole.x, y: hotHole.y, alpha: 0 }, { duration: 1000, onFinish: function onFinish() { coldHole.destroy(); // Show win after short delay LK.setTimeout(function () { LK.showYouWin(); }, 1500); } }); } game.update = function () { // Check if all girls are rescued var allRescued = true; for (var i = 0; i < girls.length; i++) { if (!girls[i].rescued) { allRescued = false; break; } } if (allRescued && LK.ticks > 180) {// Give some time before checking // Already handled in rescueGirls function } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BlackHole = Container.expand(function (holeType) {
var self = Container.call(this);
var holeGraphics = self.attachAsset(holeType + 'BlackHole', {
anchorX: 0.5,
anchorY: 0.5
});
self.holeType = holeType;
self.particles = [];
self.update = function () {
// Create particles
if (LK.ticks % 20 === 0) {
self.createParticle();
}
// Update particles
for (var i = self.particles.length - 1; i >= 0; i--) {
var particle = self.particles[i];
particle.y += particle.speed;
particle.alpha -= 0.02;
if (particle.alpha <= 0 || particle.y > self.y + 200) {
particle.destroy();
self.particles.splice(i, 1);
}
}
};
self.createParticle = function () {
var particleType = self.holeType === 'cold' ? 'snowflake' : 'flame';
var particle = LK.getAsset(particleType, {
anchorX: 0.5,
anchorY: 0.5
});
particle.x = self.x + (Math.random() - 0.5) * 300;
particle.y = self.y - 200;
particle.speed = self.holeType === 'cold' ? 2 : 3;
particle.alpha = 1;
if (self.holeType === 'hot') {
particle.scaleY = Math.random() * 0.5 + 0.5;
}
self.particles.push(particle);
self.addChild(particle);
};
return self;
});
var PowerpuffGirl = Container.expand(function (girlType) {
var self = Container.call(this);
var girlGraphics = self.attachAsset(girlType + 'Girl', {
anchorX: 0.5,
anchorY: 0.5
});
self.girlType = girlType;
self.rescued = false;
self.shivering = true;
self.down = function (x, y, obj) {
if (!self.rescued) {
LK.getSound('girlTap').play();
self.speak();
}
};
self.speak = function () {
// Flash girl to show she's speaking
LK.effects.flashObject(self, 0xffffff, 300);
// Shiver animation
if (self.shivering) {
tween(self, {
x: self.x + 5
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
x: self.x - 10
}, {
duration: 100,
onFinish: function onFinish() {
tween(self, {
x: self.x + 5
}, {
duration: 100
});
}
});
}
});
}
};
self.stopShivering = function () {
self.shivering = false;
self.rescued = true;
// Happy bounce animation
tween(self, {
scaleX: 1.2,
scaleY: 1.2
}, {
duration: 200,
onFinish: function onFinish() {
tween(self, {
scaleX: 1,
scaleY: 1
}, {
duration: 200
});
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
var coldHole = game.addChild(new BlackHole('cold'));
coldHole.x = 500;
coldHole.y = 1000;
var hotHole = game.addChild(new BlackHole('hot'));
hotHole.x = 1500;
hotHole.y = 2000;
var girls = [];
var blossom = new PowerpuffGirl('blossom');
var bubbles = new PowerpuffGirl('bubbles');
var buttercup = new PowerpuffGirl('buttercup');
girls.push(blossom, bubbles, buttercup);
// Position girls in cold hole
blossom.x = coldHole.x - 80;
blossom.y = coldHole.y;
bubbles.x = coldHole.x;
bubbles.y = coldHole.y - 60;
buttercup.x = coldHole.x + 80;
buttercup.y = coldHole.y;
coldHole.addChild(blossom);
coldHole.addChild(bubbles);
coldHole.addChild(buttercup);
var dragNode = null;
var dragOffset = {
x: 0,
y: 0
};
function handleMove(x, y, obj) {
if (dragNode) {
dragNode.x = x - dragOffset.x;
dragNode.y = y - dragOffset.y;
// Keep within bounds
dragNode.x = Math.max(200, Math.min(1848, dragNode.x));
dragNode.y = Math.max(200, Math.min(2532, dragNode.y));
}
}
game.move = handleMove;
game.down = function (x, y, obj) {
if (coldHole.x - 200 < x && x < coldHole.x + 200 && coldHole.y - 200 < y && y < coldHole.y + 200) {
dragNode = coldHole;
dragOffset.x = x - coldHole.x;
dragOffset.y = y - coldHole.y;
}
};
game.up = function (x, y, obj) {
if (dragNode === coldHole) {
// Check if close enough to hot hole
var distance = Math.sqrt(Math.pow(coldHole.x - hotHole.x, 2) + Math.pow(coldHole.y - hotHole.y, 2));
if (distance < 300) {
// Merge holes - rescue girls
rescueGirls();
}
}
dragNode = null;
};
function rescueGirls() {
LK.getSound('rescue').play();
// Move girls to hot hole
for (var i = 0; i < girls.length; i++) {
var girl = girls[i];
girl.stopShivering();
// Remove from cold hole and add to hot hole
coldHole.removeChild(girl);
hotHole.addChild(girl);
// Position in hot hole
girl.x = (i - 1) * 80;
girl.y = -50;
}
// Move cold hole to hot hole position
tween(coldHole, {
x: hotHole.x,
y: hotHole.y,
alpha: 0
}, {
duration: 1000,
onFinish: function onFinish() {
coldHole.destroy();
// Show win after short delay
LK.setTimeout(function () {
LK.showYouWin();
}, 1500);
}
});
}
game.update = function () {
// Check if all girls are rescued
var allRescued = true;
for (var i = 0; i < girls.length; i++) {
if (!girls[i].rescued) {
allRescued = false;
break;
}
}
if (allRescued && LK.ticks > 180) {// Give some time before checking
// Already handled in rescueGirls function
}
};