/**** * Classes ****/ // Kettle class: represents the kettle at the bottom of the screen var Kettle = Container.expand(function () { var self = Container.call(this); // Attach an ellipse asset for the kettle var kettle = self.attachAsset('kettle', { anchorX: 0.5, anchorY: 0.5 }); kettle.width = 320; kettle.height = 180; // Kettle moves horizontally self.speed = 10; self.lastX = self.x; // Update method for movement self.update = function () { self.lastX = self.x; self.x += self.speed; // Bounce at screen edges if (self.x > 2048 - 160) { self.x = 2048 - 160; self.speed *= -1; } if (self.x < 160) { self.x = 160; self.speed *= -1; } }; return self; }); // TeaLeaf class: represents a falling tea leaf var TeaLeaf = Container.expand(function () { var self = Container.call(this); // Attach a small ellipse asset for the leaf var leaf = self.attachAsset('teaLeaf', { anchorX: 0.5, anchorY: 0.5 }); leaf.width = 32; leaf.height = 32; // Physics properties self.vx = 0; self.vy = 0; self.lastY = self.y; self.landed = false; self.lastWasIntersecting = false; // Update method for falling self.update = function () { self.lastY = self.y; // Gravity self.vy += 1.2; self.x += self.vx; self.y += self.vy; }; return self; }); // Create and position the tea tin at the top center // TeaTin class: represents the tea tin at the top of the screen var TeaTin = Container.expand(function () { var self = Container.call(this); // Attach a box asset for the tin var tin = self.attachAsset('teaTin', { anchorX: 0.5, anchorY: 0.5 }); // Set initial size and color tin.width = 200; tin.height = 120; // Track tilt direction: -1 (left), 0 (center), 1 (right) self.tilt = 0; // Track lastX for movement events self.lastX = self.x; // Method to tilt left self.tiltLeft = function () { self.tilt = -1; }; // Method to tilt right self.tiltRight = function () { self.tilt = 1; }; // Method to center self.tiltCenter = function () { self.tilt = 0; }; // Update method for movement self.update = function () { self.lastX = self.x; // No movement here; position is set by drag in game.move }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 // No title, no description }); /**** * Game Code ****/ // Add a background image to the game scene var bg = LK.getAsset('centerCircle', { anchorX: 0.5, anchorY: 0.5, scaleX: 10, scaleY: 10, x: 2048 / 2, y: 2732 / 2 }); game.addChild(bg); // Create and position the tea tin at the top center var teaTin = new TeaTin(); teaTin.x = 2048 / 2; teaTin.y = 200; game.addChild(teaTin); // Create and position the kettle at the bottom center var kettle = new Kettle(); kettle.x = 2048 / 2; kettle.y = 2732 - 200; game.addChild(kettle); // Array to hold falling tea leaves var teaLeaves = []; // Score text var score = 0; var scoreTxt = new Text2('0', { size: 120, fill: "#fff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Pouring state var pouring = false; var pourInterval = null; // Helper to start pouring function startPouring() { if (!pouring) { pouring = true; pourInterval = LK.setInterval(function () { // Create a new tea leaf at the tin's spout var leaf = new TeaLeaf(); leaf.x = teaTin.x; leaf.y = teaTin.y + 60; // Give a small random horizontal velocity based on tilt leaf.vx = teaTin.tilt * 6 + (Math.random() - 0.5) * 2; leaf.vy = 0; teaLeaves.push(leaf); game.addChild(leaf); }, 80); } } // Helper to stop pouring function stopPouring() { pouring = false; if (pourInterval) { LK.clearInterval(pourInterval); pourInterval = null; } } // Touch controls: drag left/right to tilt, tap and hold to pour game.down = function (x, y, obj) { // If touch is on left half, tilt left; right half, tilt right if (x < 2048 / 2) { teaTin.tiltLeft(); } else { teaTin.tiltRight(); } startPouring(); }; game.up = function (x, y, obj) { teaTin.tiltCenter(); stopPouring(); }; game.move = function (x, y, obj) { // Move the tea tin horizontally with the drag, clamp to screen edges var minX = 100; var maxX = 2048 - 100; teaTin.x = Math.max(minX, Math.min(maxX, x)); // Tilt based on drag position if (x < 2048 / 2) { teaTin.tiltLeft(); } else { teaTin.tiltRight(); } }; // Main game update loop game.update = function () { // Update tin and kettle teaTin.update(); kettle.update(); // Update and check tea leaves for (var i = teaLeaves.length - 1; i >= 0; i--) { var leaf = teaLeaves[i]; leaf.update(); // Check if leaf lands in kettle (collision) var isIntersecting = !leaf.landed && leaf.intersects(kettle); if (!leaf.lastWasIntersecting && isIntersecting) { // Landed in kettle leaf.landed = true; score += 1; scoreTxt.setText(score); // Remove leaf after a short delay (function (leafToRemove, idx) { LK.setTimeout(function () { leafToRemove.destroy(); teaLeaves.splice(idx, 1); }, 200); })(leaf, i); leaf.lastWasIntersecting = isIntersecting; continue; } leaf.lastWasIntersecting = isIntersecting; // Remove leaf if it falls off screen if (leaf.y > 2732 + 50) { leaf.destroy(); teaLeaves.splice(i, 1); } } };
/****
* Classes
****/
// Kettle class: represents the kettle at the bottom of the screen
var Kettle = Container.expand(function () {
var self = Container.call(this);
// Attach an ellipse asset for the kettle
var kettle = self.attachAsset('kettle', {
anchorX: 0.5,
anchorY: 0.5
});
kettle.width = 320;
kettle.height = 180;
// Kettle moves horizontally
self.speed = 10;
self.lastX = self.x;
// Update method for movement
self.update = function () {
self.lastX = self.x;
self.x += self.speed;
// Bounce at screen edges
if (self.x > 2048 - 160) {
self.x = 2048 - 160;
self.speed *= -1;
}
if (self.x < 160) {
self.x = 160;
self.speed *= -1;
}
};
return self;
});
// TeaLeaf class: represents a falling tea leaf
var TeaLeaf = Container.expand(function () {
var self = Container.call(this);
// Attach a small ellipse asset for the leaf
var leaf = self.attachAsset('teaLeaf', {
anchorX: 0.5,
anchorY: 0.5
});
leaf.width = 32;
leaf.height = 32;
// Physics properties
self.vx = 0;
self.vy = 0;
self.lastY = self.y;
self.landed = false;
self.lastWasIntersecting = false;
// Update method for falling
self.update = function () {
self.lastY = self.y;
// Gravity
self.vy += 1.2;
self.x += self.vx;
self.y += self.vy;
};
return self;
});
// Create and position the tea tin at the top center
// TeaTin class: represents the tea tin at the top of the screen
var TeaTin = Container.expand(function () {
var self = Container.call(this);
// Attach a box asset for the tin
var tin = self.attachAsset('teaTin', {
anchorX: 0.5,
anchorY: 0.5
});
// Set initial size and color
tin.width = 200;
tin.height = 120;
// Track tilt direction: -1 (left), 0 (center), 1 (right)
self.tilt = 0;
// Track lastX for movement events
self.lastX = self.x;
// Method to tilt left
self.tiltLeft = function () {
self.tilt = -1;
};
// Method to tilt right
self.tiltRight = function () {
self.tilt = 1;
};
// Method to center
self.tiltCenter = function () {
self.tilt = 0;
};
// Update method for movement
self.update = function () {
self.lastX = self.x;
// No movement here; position is set by drag in game.move
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // No title, no description
});
/****
* Game Code
****/
// Add a background image to the game scene
var bg = LK.getAsset('centerCircle', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 10,
scaleY: 10,
x: 2048 / 2,
y: 2732 / 2
});
game.addChild(bg);
// Create and position the tea tin at the top center
var teaTin = new TeaTin();
teaTin.x = 2048 / 2;
teaTin.y = 200;
game.addChild(teaTin);
// Create and position the kettle at the bottom center
var kettle = new Kettle();
kettle.x = 2048 / 2;
kettle.y = 2732 - 200;
game.addChild(kettle);
// Array to hold falling tea leaves
var teaLeaves = [];
// Score text
var score = 0;
var scoreTxt = new Text2('0', {
size: 120,
fill: "#fff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Pouring state
var pouring = false;
var pourInterval = null;
// Helper to start pouring
function startPouring() {
if (!pouring) {
pouring = true;
pourInterval = LK.setInterval(function () {
// Create a new tea leaf at the tin's spout
var leaf = new TeaLeaf();
leaf.x = teaTin.x;
leaf.y = teaTin.y + 60;
// Give a small random horizontal velocity based on tilt
leaf.vx = teaTin.tilt * 6 + (Math.random() - 0.5) * 2;
leaf.vy = 0;
teaLeaves.push(leaf);
game.addChild(leaf);
}, 80);
}
}
// Helper to stop pouring
function stopPouring() {
pouring = false;
if (pourInterval) {
LK.clearInterval(pourInterval);
pourInterval = null;
}
}
// Touch controls: drag left/right to tilt, tap and hold to pour
game.down = function (x, y, obj) {
// If touch is on left half, tilt left; right half, tilt right
if (x < 2048 / 2) {
teaTin.tiltLeft();
} else {
teaTin.tiltRight();
}
startPouring();
};
game.up = function (x, y, obj) {
teaTin.tiltCenter();
stopPouring();
};
game.move = function (x, y, obj) {
// Move the tea tin horizontally with the drag, clamp to screen edges
var minX = 100;
var maxX = 2048 - 100;
teaTin.x = Math.max(minX, Math.min(maxX, x));
// Tilt based on drag position
if (x < 2048 / 2) {
teaTin.tiltLeft();
} else {
teaTin.tiltRight();
}
};
// Main game update loop
game.update = function () {
// Update tin and kettle
teaTin.update();
kettle.update();
// Update and check tea leaves
for (var i = teaLeaves.length - 1; i >= 0; i--) {
var leaf = teaLeaves[i];
leaf.update();
// Check if leaf lands in kettle (collision)
var isIntersecting = !leaf.landed && leaf.intersects(kettle);
if (!leaf.lastWasIntersecting && isIntersecting) {
// Landed in kettle
leaf.landed = true;
score += 1;
scoreTxt.setText(score);
// Remove leaf after a short delay
(function (leafToRemove, idx) {
LK.setTimeout(function () {
leafToRemove.destroy();
teaLeaves.splice(idx, 1);
}, 200);
})(leaf, i);
leaf.lastWasIntersecting = isIntersecting;
continue;
}
leaf.lastWasIntersecting = isIntersecting;
// Remove leaf if it falls off screen
if (leaf.y > 2732 + 50) {
leaf.destroy();
teaLeaves.splice(i, 1);
}
}
};