/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var DreamBubble = Container.expand(function (dreamType) { var self = Container.call(this); self.dreamType = dreamType; self.isMatched = false; var bubbleGraphics = self.attachAsset('dreamBubble', { anchorX: 0.5, anchorY: 0.5 }); bubbleGraphics.alpha = 0.7; var dreamContent = self.addChild(LK.getAsset(dreamType, { anchorX: 0.5, anchorY: 0.5 })); self.update = function () { if (!self.isMatched) { bubbleGraphics.y = Math.sin(LK.ticks * 0.05 + self.x * 0.01) * 10; dreamContent.y = bubbleGraphics.y; } }; self.celebrate = function () { self.isMatched = true; LK.effects.flashObject(self, 0xffd700, 500); tween(self, { scaleX: 1.3, scaleY: 1.3 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(self, { scaleX: 1.0, scaleY: 1.0 }, { duration: 200, easing: tween.easeIn }); } }); createParticleEffect(self.x, self.y); }; return self; }); var Particle = Container.expand(function () { var self = Container.call(this); var particleGraphics = self.attachAsset('particle', { anchorX: 0.5, anchorY: 0.5 }); self.vx = (Math.random() - 0.5) * 10; self.vy = (Math.random() - 0.5) * 10 - 5; self.life = 60; self.maxLife = 60; self.update = function () { self.x += self.vx; self.y += self.vy; self.vy += 0.2; self.life--; particleGraphics.alpha = self.life / self.maxLife; if (self.life <= 0) { self.destroy(); for (var i = particles.length - 1; i >= 0; i--) { if (particles[i] === self) { particles.splice(i, 1); break; } } } }; return self; }); var PowerpuffGirl = Container.expand(function (girlType) { var self = Container.call(this); self.girlType = girlType; self.isBeingDragged = false; self.originalX = 0; self.originalY = 0; self.isMatched = false; var girlGraphics = self.attachAsset(girlType, { anchorX: 0.5, anchorY: 0.5 }); // Add simple features to distinguish the girls var feature1 = self.addChild(LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5 })); feature1.x = -30; feature1.y = -40; var feature2 = self.addChild(LK.getAsset('particle', { anchorX: 0.5, anchorY: 0.5 })); feature2.x = 30; feature2.y = -40; self.setOriginalPosition = function (x, y) { self.originalX = x; self.originalY = y; self.x = x; self.y = y; }; self.returnToOriginal = function () { if (!self.isMatched) { tween(self, { x: self.originalX, y: self.originalY }, { duration: 300, easing: tween.easeOut }); } }; self.down = function (x, y, obj) { if (!self.isMatched) { self.isBeingDragged = true; girlGraphics.alpha = 0.8; } }; self.up = function (x, y, obj) { if (self.isBeingDragged) { self.isBeingDragged = false; girlGraphics.alpha = 1.0; var matched = false; for (var i = 0; i < dreamBubbles.length; i++) { if (self.intersects(dreamBubbles[i]) && !dreamBubbles[i].isMatched) { if (checkMatch(self, dreamBubbles[i])) { matched = true; break; } } } if (!matched) { self.returnToOriginal(); } } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87ceeb }); /**** * Game Code ****/ var powerpuffGirls = []; var dreamBubbles = []; var particles = []; var dragTarget = null; var matchedCount = 0; var gameStarted = false; // Dream matching rules var dreamMatches = { 'blossom': 'piano', 'bubbles': 'cloud', 'buttercup': 'lemonJuice' }; // Score display var scoreTxt = new Text2('Score: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Instructions var instructionTxt = new Text2('Drag each girl to her dream!', { size: 60, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 0); instructionTxt.y = 100; LK.gui.top.addChild(instructionTxt); function initializeGame() { // Create Powerpuff Girls var girlTypes = ['blossom', 'bubbles', 'buttercup']; var startY = 2400; for (var i = 0; i < girlTypes.length; i++) { var girl = new PowerpuffGirl(girlTypes[i]); var startX = 512 + i * 512; girl.setOriginalPosition(startX, startY); powerpuffGirls.push(girl); game.addChild(girl); } // Create dream bubbles var dreamTypes = ['piano', 'cloud', 'lemonJuice']; var bubbleY = 800; for (var j = 0; j < dreamTypes.length; j++) { var bubble = new DreamBubble(dreamTypes[j]); var bubbleX = 512 + j * 512; bubble.x = bubbleX; bubble.y = bubbleY; dreamBubbles.push(bubble); game.addChild(bubble); } gameStarted = true; } function checkMatch(girl, bubble) { return dreamMatches[girl.girlType] === bubble.dreamType; } function handleMatch(girl, bubble) { girl.isMatched = true; bubble.celebrate(); girl.x = bubble.x; girl.y = bubble.y; tween(girl, { scaleX: 0.8, scaleY: 0.8 }, { duration: 300, easing: tween.easeOut }); LK.setScore(LK.getScore() + 100); scoreTxt.setText('Score: ' + LK.getScore()); LK.getSound('match').play(); matchedCount++; if (matchedCount >= 3) { LK.setTimeout(function () { LK.setScore(LK.getScore() + 500); scoreTxt.setText('Score: ' + LK.getScore()); LK.getSound('celebration').play(); LK.effects.flashScreen(0xffd700, 1000); LK.setTimeout(function () { LK.showYouWin(); }, 1500); }, 1000); } } function createParticleEffect(x, y) { for (var i = 0; i < 8; i++) { var particle = new Particle(); particle.x = x; particle.y = y; particles.push(particle); game.addChild(particle); } } game.move = function (x, y, obj) { if (dragTarget && dragTarget.isBeingDragged) { dragTarget.x = x; dragTarget.y = y; } }; game.down = function (x, y, obj) { for (var i = 0; i < powerpuffGirls.length; i++) { var girl = powerpuffGirls[i]; if (!girl.isMatched) { var localPos = girl.toLocal({ x: x, y: y }); if (Math.abs(localPos.x) < 100 && Math.abs(localPos.y) < 100) { dragTarget = girl; break; } } } }; game.up = function (x, y, obj) { if (dragTarget && dragTarget.isBeingDragged) { var matched = false; for (var i = 0; i < dreamBubbles.length; i++) { var bubble = dreamBubbles[i]; if (dragTarget.intersects(bubble) && !bubble.isMatched) { if (checkMatch(dragTarget, bubble)) { handleMatch(dragTarget, bubble); matched = true; break; } } } if (!matched) { dragTarget.returnToOriginal(); } } dragTarget = null; }; game.update = function () { if (!gameStarted) { initializeGame(); } // Update particles for (var i = particles.length - 1; i >= 0; i--) { if (particles[i] && particles[i].update) { particles[i].update(); } } };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var DreamBubble = Container.expand(function (dreamType) {
var self = Container.call(this);
self.dreamType = dreamType;
self.isMatched = false;
var bubbleGraphics = self.attachAsset('dreamBubble', {
anchorX: 0.5,
anchorY: 0.5
});
bubbleGraphics.alpha = 0.7;
var dreamContent = self.addChild(LK.getAsset(dreamType, {
anchorX: 0.5,
anchorY: 0.5
}));
self.update = function () {
if (!self.isMatched) {
bubbleGraphics.y = Math.sin(LK.ticks * 0.05 + self.x * 0.01) * 10;
dreamContent.y = bubbleGraphics.y;
}
};
self.celebrate = function () {
self.isMatched = true;
LK.effects.flashObject(self, 0xffd700, 500);
tween(self, {
scaleX: 1.3,
scaleY: 1.3
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(self, {
scaleX: 1.0,
scaleY: 1.0
}, {
duration: 200,
easing: tween.easeIn
});
}
});
createParticleEffect(self.x, self.y);
};
return self;
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
});
self.vx = (Math.random() - 0.5) * 10;
self.vy = (Math.random() - 0.5) * 10 - 5;
self.life = 60;
self.maxLife = 60;
self.update = function () {
self.x += self.vx;
self.y += self.vy;
self.vy += 0.2;
self.life--;
particleGraphics.alpha = self.life / self.maxLife;
if (self.life <= 0) {
self.destroy();
for (var i = particles.length - 1; i >= 0; i--) {
if (particles[i] === self) {
particles.splice(i, 1);
break;
}
}
}
};
return self;
});
var PowerpuffGirl = Container.expand(function (girlType) {
var self = Container.call(this);
self.girlType = girlType;
self.isBeingDragged = false;
self.originalX = 0;
self.originalY = 0;
self.isMatched = false;
var girlGraphics = self.attachAsset(girlType, {
anchorX: 0.5,
anchorY: 0.5
});
// Add simple features to distinguish the girls
var feature1 = self.addChild(LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
}));
feature1.x = -30;
feature1.y = -40;
var feature2 = self.addChild(LK.getAsset('particle', {
anchorX: 0.5,
anchorY: 0.5
}));
feature2.x = 30;
feature2.y = -40;
self.setOriginalPosition = function (x, y) {
self.originalX = x;
self.originalY = y;
self.x = x;
self.y = y;
};
self.returnToOriginal = function () {
if (!self.isMatched) {
tween(self, {
x: self.originalX,
y: self.originalY
}, {
duration: 300,
easing: tween.easeOut
});
}
};
self.down = function (x, y, obj) {
if (!self.isMatched) {
self.isBeingDragged = true;
girlGraphics.alpha = 0.8;
}
};
self.up = function (x, y, obj) {
if (self.isBeingDragged) {
self.isBeingDragged = false;
girlGraphics.alpha = 1.0;
var matched = false;
for (var i = 0; i < dreamBubbles.length; i++) {
if (self.intersects(dreamBubbles[i]) && !dreamBubbles[i].isMatched) {
if (checkMatch(self, dreamBubbles[i])) {
matched = true;
break;
}
}
}
if (!matched) {
self.returnToOriginal();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87ceeb
});
/****
* Game Code
****/
var powerpuffGirls = [];
var dreamBubbles = [];
var particles = [];
var dragTarget = null;
var matchedCount = 0;
var gameStarted = false;
// Dream matching rules
var dreamMatches = {
'blossom': 'piano',
'bubbles': 'cloud',
'buttercup': 'lemonJuice'
};
// Score display
var scoreTxt = new Text2('Score: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Instructions
var instructionTxt = new Text2('Drag each girl to her dream!', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 100;
LK.gui.top.addChild(instructionTxt);
function initializeGame() {
// Create Powerpuff Girls
var girlTypes = ['blossom', 'bubbles', 'buttercup'];
var startY = 2400;
for (var i = 0; i < girlTypes.length; i++) {
var girl = new PowerpuffGirl(girlTypes[i]);
var startX = 512 + i * 512;
girl.setOriginalPosition(startX, startY);
powerpuffGirls.push(girl);
game.addChild(girl);
}
// Create dream bubbles
var dreamTypes = ['piano', 'cloud', 'lemonJuice'];
var bubbleY = 800;
for (var j = 0; j < dreamTypes.length; j++) {
var bubble = new DreamBubble(dreamTypes[j]);
var bubbleX = 512 + j * 512;
bubble.x = bubbleX;
bubble.y = bubbleY;
dreamBubbles.push(bubble);
game.addChild(bubble);
}
gameStarted = true;
}
function checkMatch(girl, bubble) {
return dreamMatches[girl.girlType] === bubble.dreamType;
}
function handleMatch(girl, bubble) {
girl.isMatched = true;
bubble.celebrate();
girl.x = bubble.x;
girl.y = bubble.y;
tween(girl, {
scaleX: 0.8,
scaleY: 0.8
}, {
duration: 300,
easing: tween.easeOut
});
LK.setScore(LK.getScore() + 100);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('match').play();
matchedCount++;
if (matchedCount >= 3) {
LK.setTimeout(function () {
LK.setScore(LK.getScore() + 500);
scoreTxt.setText('Score: ' + LK.getScore());
LK.getSound('celebration').play();
LK.effects.flashScreen(0xffd700, 1000);
LK.setTimeout(function () {
LK.showYouWin();
}, 1500);
}, 1000);
}
}
function createParticleEffect(x, y) {
for (var i = 0; i < 8; i++) {
var particle = new Particle();
particle.x = x;
particle.y = y;
particles.push(particle);
game.addChild(particle);
}
}
game.move = function (x, y, obj) {
if (dragTarget && dragTarget.isBeingDragged) {
dragTarget.x = x;
dragTarget.y = y;
}
};
game.down = function (x, y, obj) {
for (var i = 0; i < powerpuffGirls.length; i++) {
var girl = powerpuffGirls[i];
if (!girl.isMatched) {
var localPos = girl.toLocal({
x: x,
y: y
});
if (Math.abs(localPos.x) < 100 && Math.abs(localPos.y) < 100) {
dragTarget = girl;
break;
}
}
}
};
game.up = function (x, y, obj) {
if (dragTarget && dragTarget.isBeingDragged) {
var matched = false;
for (var i = 0; i < dreamBubbles.length; i++) {
var bubble = dreamBubbles[i];
if (dragTarget.intersects(bubble) && !bubble.isMatched) {
if (checkMatch(dragTarget, bubble)) {
handleMatch(dragTarget, bubble);
matched = true;
break;
}
}
}
if (!matched) {
dragTarget.returnToOriginal();
}
}
dragTarget = null;
};
game.update = function () {
if (!gameStarted) {
initializeGame();
}
// Update particles
for (var i = particles.length - 1; i >= 0; i--) {
if (particles[i] && particles[i].update) {
particles[i].update();
}
}
};