/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var BlossomCharacter = Container.expand(function () { var self = Container.call(this); // Create body parts var blossomBody = self.attachAsset('blossom', { anchorX: 0.5, anchorY: 0.5 }); var skirt = self.attachAsset('skirt', { anchorX: 0.5, anchorY: 0, y: 200 }); var lei = self.attachAsset('lei', { anchorX: 0.5, anchorY: 0.5, y: -150 }); var tummy = self.attachAsset('tummy', { anchorX: 0.5, anchorY: 0.5, y: 50 }); self.state = 'idle'; self.isAnimating = false; self.startIdleAnimation = function () { if (self.isAnimating) return; self.isAnimating = true; tween(skirt, { rotation: 0.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { tween(skirt, { rotation: -0.1 }, { duration: 1000, easing: tween.easeInOut, onFinish: function onFinish() { self.isAnimating = false; if (self.state === 'idle') { self.startIdleAnimation(); } } }); } }); }; self.playTalkAnimation = function () { self.state = 'talking'; tween.stop(skirt); tween(blossomBody, { scaleY: 1.1 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(blossomBody, { scaleY: 1 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.state = 'idle'; self.isAnimating = false; self.startIdleAnimation(); } }); } }); }; self.playDanceAnimation = function () { self.state = 'dancing'; tween.stop(skirt); var danceCount = 0; function danceCycle() { if (danceCount < 8) { tween(skirt, { rotation: 0.3, scaleX: 1.2 }, { duration: 250, easing: tween.easeInOut, onFinish: function onFinish() { tween(skirt, { rotation: -0.3, scaleX: 0.8 }, { duration: 250, easing: tween.easeInOut, onFinish: function onFinish() { danceCount++; danceCycle(); } }); } }); } else { tween(skirt, { rotation: 0, scaleX: 1 }, { duration: 300, easing: tween.easeOut, onFinish: function onFinish() { self.state = 'idle'; self.isAnimating = false; self.startIdleAnimation(); } }); } } danceCycle(); }; self.down = function (x, y, obj) { var currentTime = Date.now(); if (!self.lastTapTime) { self.lastTapTime = currentTime; self.tapCount = 1; } else { var timeDiff = currentTime - self.lastTapTime; if (timeDiff < 500) { self.tapCount++; if (self.tapCount === 2) { // Double tap - play hula song self.playDanceAnimation(); LK.getSound('hulaSong').play(); self.createSparkles(); interactions++; scoreTxt.setText(interactions); self.tapCount = 0; } } else { self.tapCount = 1; } self.lastTapTime = currentTime; } // Handle single tap after delay if (self.tapCount === 1) { LK.setTimeout(function () { if (self.tapCount === 1) { // Single tap - play random saying var randomSaying = Math.floor(Math.random() * 7) + 1; LK.getSound('saying' + randomSaying).play(); self.playTalkAnimation(); self.createSparkles(); interactions++; scoreTxt.setText(interactions); self.tapCount = 0; } }, 500); } }; self.createSparkles = function () { for (var i = 0; i < 3; i++) { var sparkle = new Sparkle(); sparkle.x = (Math.random() - 0.5) * 200; sparkle.y = (Math.random() - 0.5) * 200; self.addChild(sparkle); sparkle.animate(); } }; return self; }); var PalmTree = Container.expand(function () { var self = Container.call(this); var trunk = self.attachAsset('palmTree', { anchorX: 0.5, anchorY: 1 }); var leaves = self.attachAsset('palmLeaves', { anchorX: 0.5, anchorY: 0.5, y: -350 }); self.animate = function () { tween(leaves, { rotation: 0.1 }, { duration: 2000, easing: tween.easeInOut, onFinish: function onFinish() { tween(leaves, { rotation: -0.1 }, { duration: 2000, easing: tween.easeInOut, onFinish: function onFinish() { self.animate(); } }); } }); }; return self; }); var Sparkle = Container.expand(function () { var self = Container.call(this); var sparkleGraphics = self.attachAsset('sparkle', { anchorX: 0.5, anchorY: 0.5, alpha: 1 }); self.animate = function () { tween(sparkleGraphics, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 500, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ var interactions = 0; // Create background var background = game.attachAsset('background', { anchorX: 0, anchorY: 0, x: 0, y: 0 }); // Create palm trees var leftPalmTree = game.addChild(new PalmTree()); leftPalmTree.x = 300; leftPalmTree.y = 2200; leftPalmTree.animate(); var rightPalmTree = game.addChild(new PalmTree()); rightPalmTree.x = 1748; rightPalmTree.y = 2200; rightPalmTree.animate(); // Create Blossom character var blossom = game.addChild(new BlossomCharacter()); blossom.x = 1024; blossom.y = 1366; blossom.startIdleAnimation(); // Create score display var scoreTxt = new Text2('Interactions: 0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Instructions text var instructionTxt = new Text2('Tap Blossom\'s tummy!\nDouble tap for hula song!', { size: 60, fill: 0xFFFFFF }); instructionTxt.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionTxt); game.update = function () { // Game loop - animations are handled by tween system };
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var BlossomCharacter = Container.expand(function () {
var self = Container.call(this);
// Create body parts
var blossomBody = self.attachAsset('blossom', {
anchorX: 0.5,
anchorY: 0.5
});
var skirt = self.attachAsset('skirt', {
anchorX: 0.5,
anchorY: 0,
y: 200
});
var lei = self.attachAsset('lei', {
anchorX: 0.5,
anchorY: 0.5,
y: -150
});
var tummy = self.attachAsset('tummy', {
anchorX: 0.5,
anchorY: 0.5,
y: 50
});
self.state = 'idle';
self.isAnimating = false;
self.startIdleAnimation = function () {
if (self.isAnimating) return;
self.isAnimating = true;
tween(skirt, {
rotation: 0.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(skirt, {
rotation: -0.1
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.isAnimating = false;
if (self.state === 'idle') {
self.startIdleAnimation();
}
}
});
}
});
};
self.playTalkAnimation = function () {
self.state = 'talking';
tween.stop(skirt);
tween(blossomBody, {
scaleY: 1.1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(blossomBody, {
scaleY: 1
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.state = 'idle';
self.isAnimating = false;
self.startIdleAnimation();
}
});
}
});
};
self.playDanceAnimation = function () {
self.state = 'dancing';
tween.stop(skirt);
var danceCount = 0;
function danceCycle() {
if (danceCount < 8) {
tween(skirt, {
rotation: 0.3,
scaleX: 1.2
}, {
duration: 250,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(skirt, {
rotation: -0.3,
scaleX: 0.8
}, {
duration: 250,
easing: tween.easeInOut,
onFinish: function onFinish() {
danceCount++;
danceCycle();
}
});
}
});
} else {
tween(skirt, {
rotation: 0,
scaleX: 1
}, {
duration: 300,
easing: tween.easeOut,
onFinish: function onFinish() {
self.state = 'idle';
self.isAnimating = false;
self.startIdleAnimation();
}
});
}
}
danceCycle();
};
self.down = function (x, y, obj) {
var currentTime = Date.now();
if (!self.lastTapTime) {
self.lastTapTime = currentTime;
self.tapCount = 1;
} else {
var timeDiff = currentTime - self.lastTapTime;
if (timeDiff < 500) {
self.tapCount++;
if (self.tapCount === 2) {
// Double tap - play hula song
self.playDanceAnimation();
LK.getSound('hulaSong').play();
self.createSparkles();
interactions++;
scoreTxt.setText(interactions);
self.tapCount = 0;
}
} else {
self.tapCount = 1;
}
self.lastTapTime = currentTime;
}
// Handle single tap after delay
if (self.tapCount === 1) {
LK.setTimeout(function () {
if (self.tapCount === 1) {
// Single tap - play random saying
var randomSaying = Math.floor(Math.random() * 7) + 1;
LK.getSound('saying' + randomSaying).play();
self.playTalkAnimation();
self.createSparkles();
interactions++;
scoreTxt.setText(interactions);
self.tapCount = 0;
}
}, 500);
}
};
self.createSparkles = function () {
for (var i = 0; i < 3; i++) {
var sparkle = new Sparkle();
sparkle.x = (Math.random() - 0.5) * 200;
sparkle.y = (Math.random() - 0.5) * 200;
self.addChild(sparkle);
sparkle.animate();
}
};
return self;
});
var PalmTree = Container.expand(function () {
var self = Container.call(this);
var trunk = self.attachAsset('palmTree', {
anchorX: 0.5,
anchorY: 1
});
var leaves = self.attachAsset('palmLeaves', {
anchorX: 0.5,
anchorY: 0.5,
y: -350
});
self.animate = function () {
tween(leaves, {
rotation: 0.1
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(leaves, {
rotation: -0.1
}, {
duration: 2000,
easing: tween.easeInOut,
onFinish: function onFinish() {
self.animate();
}
});
}
});
};
return self;
});
var Sparkle = Container.expand(function () {
var self = Container.call(this);
var sparkleGraphics = self.attachAsset('sparkle', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1
});
self.animate = function () {
tween(sparkleGraphics, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 500,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
var interactions = 0;
// Create background
var background = game.attachAsset('background', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
// Create palm trees
var leftPalmTree = game.addChild(new PalmTree());
leftPalmTree.x = 300;
leftPalmTree.y = 2200;
leftPalmTree.animate();
var rightPalmTree = game.addChild(new PalmTree());
rightPalmTree.x = 1748;
rightPalmTree.y = 2200;
rightPalmTree.animate();
// Create Blossom character
var blossom = game.addChild(new BlossomCharacter());
blossom.x = 1024;
blossom.y = 1366;
blossom.startIdleAnimation();
// Create score display
var scoreTxt = new Text2('Interactions: 0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Instructions text
var instructionTxt = new Text2('Tap Blossom\'s tummy!\nDouble tap for hula song!', {
size: 60,
fill: 0xFFFFFF
});
instructionTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionTxt);
game.update = function () {
// Game loop - animations are handled by tween system
};