/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Button = Container.expand(function (width, height, color, text) {
var self = Container.call(this);
var bg = self.attachAsset(color === 0x3498db ? 'numberButton' : color === 0xe74c3c ? 'operatorButton' : 'clearButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: width / 350,
scaleY: height / 200
});
var label = new Text2(text, {
size: 80,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.originalScale = bg.scaleX;
self.down = function (x, y, obj) {
LK.getSound('buttonClick').play();
tween(bg, {
scaleX: self.originalScale * 0.9,
scaleY: self.originalScale * 0.9
}, {
duration: 100
});
if (self.onPress) {
self.onPress();
}
};
self.up = function (x, y, obj) {
tween(bg, {
scaleX: self.originalScale,
scaleY: self.originalScale
}, {
duration: 100
});
};
return self;
});
var ContainerCard = Container.expand(function (containerData) {
var self = Container.call(this);
var bg = self.attachAsset('containerCard', {
anchorX: 0.5,
anchorY: 0.5
});
var containerIcon = self.attachAsset(containerData.asset, {
anchorX: 0.5,
anchorY: 0.5,
x: -600
});
var nameText = new Text2(containerData.name, {
size: 60,
fill: 0x2C3E50
});
nameText.anchor.set(0, 0.3);
nameText.x = -400;
nameText.y = -50;
self.addChild(nameText);
var weightText = new Text2(containerData.capacity, {
size: 50,
fill: 0x7F8C8D
});
weightText.anchor.set(0, 0.3);
weightText.x = -400;
weightText.y = 20;
self.addChild(weightText);
var factText = new Text2(containerData.fact, {
size: 40,
fill: 0x34495E
});
factText.anchor.set(0, 0.3);
factText.x = -400;
factText.y = 80;
self.addChild(factText);
self.alpha = 0;
tween(self, {
alpha: 1
}, {
duration: 500
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xbdc3c7
});
/****
* Game Code
****/
var currentInput = "";
var calculationCount = 0;
var containerCards = [];
// Container database with weight ranges in grams
var containerDatabase = [{
range: {
min: 0.1,
max: 1
},
name: "Paperclip",
capacity: "1g",
fact: "Standard office paperclip weight",
asset: "paperclip"
}, {
range: {
min: 4,
max: 6
},
name: "Teaspoon of Sugar",
capacity: "5g",
fact: "One level teaspoon of sugar",
asset: "sugar"
}, {
range: {
min: 28,
max: 30
},
name: "One Ounce",
capacity: "28g",
fact: "Standard US ounce measurement",
asset: "teaspoon"
}, {
range: {
min: 240,
max: 260
},
name: "Cup of Water",
capacity: "250g",
fact: "One cup of water weighs about 250g",
asset: "cup"
}, {
range: {
min: 350,
max: 400
},
name: "Soda Can Contents",
capacity: "355g",
fact: "Weight of liquid in a standard can",
asset: "sodaCan"
}, {
range: {
min: 450,
max: 550
},
name: "Water Bottle",
capacity: "500g",
fact: "500ml of water weighs 500g",
asset: "bottle"
}, {
range: {
min: 950,
max: 1050
},
name: "1 Kilogram",
capacity: "1kg",
fact: "Standard metric weight unit",
asset: "bottle"
}, {
range: {
min: 2200,
max: 2300
},
name: "5 Pounds",
capacity: "2.27kg",
fact: "US 5-pound weight equivalent",
asset: "bucket"
}, {
range: {
min: 4500,
max: 5500
},
name: "Bag of Sugar",
capacity: "5kg",
fact: "Standard grocery store bag",
asset: "sugarBag"
}, {
range: {
min: 9000,
max: 11000
},
name: "Bowling Ball",
capacity: "10kg",
fact: "Standard bowling ball weight",
asset: "bowlingBall"
}, {
range: {
min: 45000,
max: 55000
},
name: "Large Dog",
capacity: "50kg",
fact: "Golden Retriever average weight",
asset: "dog"
}, {
range: {
min: 70000,
max: 80000
},
name: "Adult Human",
capacity: "75kg",
fact: "Average adult human weight",
asset: "human"
}];
// Create calculator background
var calculatorBg = game.attachAsset('calculatorBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Create display area
var displayBg = game.attachAsset('displayBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 400
});
var displayText = new Text2("0", {
size: 120,
fill: 0xFFFFFF
});
displayText.anchor.set(0.5, 0.5);
displayText.x = 1024;
displayText.y = 400;
game.addChild(displayText);
// Create number buttons
var buttons = [];
var buttonLayout = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0', '.', '=']];
for (var row = 0; row < buttonLayout.length; row++) {
for (var col = 0; col < buttonLayout[row].length; col++) {
var buttonText = buttonLayout[row][col];
var buttonColor = buttonText === '=' ? 0xe74c3c : 0x3498db;
var button = new Button(350, 200, buttonColor, buttonText);
button.x = 500 + col * 380;
button.y = 700 + row * 220;
// Closure to capture button text
(function (text) {
button.onPress = function () {
handleButtonPress(text);
};
})(buttonText);
game.addChild(button);
buttons.push(button);
}
}
// Create clear button
var clearButton = new Button(350, 200, 0xf39c12, "C");
clearButton.x = 1260;
clearButton.y = 700;
clearButton.onPress = function () {
currentInput = "";
updateDisplay();
clearContainers();
};
game.addChild(clearButton);
// Score display
var scoreTxt = new Text2('Calculations: 0', {
size: 80,
fill: 0x2C3E50
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function handleButtonPress(buttonText) {
if (buttonText === '=') {
calculateContainers();
} else if (buttonText === '.') {
if (currentInput.indexOf('.') === -1) {
currentInput += buttonText;
}
} else {
currentInput += buttonText;
}
updateDisplay();
}
function updateDisplay() {
var displayValue = currentInput || "0";
if (displayValue.length > 12) {
displayValue = displayValue.substring(0, 12);
}
displayText.setText(displayValue);
}
function calculateContainers() {
if (!currentInput || currentInput === "") return;
var inputValue = parseFloat(currentInput);
if (isNaN(inputValue) || inputValue <= 0) return;
LK.getSound('calculate').play();
calculationCount++;
LK.setScore(calculationCount);
scoreTxt.setText('Calculations: ' + calculationCount);
clearContainers();
var matchingContainers = findMatchingContainers(inputValue);
displayContainers(matchingContainers);
}
function findMatchingContainers(value) {
var matches = [];
// Find exact or close matches
for (var i = 0; i < containerDatabase.length; i++) {
var container = containerDatabase[i];
if (value >= container.range.min && value <= container.range.max) {
matches.push(container);
}
}
// If no exact matches, find closest ones
if (matches.length === 0) {
var closestContainers = containerDatabase.slice().sort(function (a, b) {
var distanceA = Math.min(Math.abs(value - a.range.min), Math.abs(value - a.range.max));
var distanceB = Math.min(Math.abs(value - b.range.min), Math.abs(value - b.range.max));
return distanceA - distanceB;
});
matches = closestContainers.slice(0, 3);
}
return matches.slice(0, 4);
}
function displayContainers(containers) {
var startY = 1700;
for (var i = 0; i < containers.length; i++) {
var card = new ContainerCard(containers[i]);
card.x = 1024;
card.y = startY + i * 350;
game.addChild(card);
containerCards.push(card);
}
}
function clearContainers() {
for (var i = 0; i < containerCards.length; i++) {
containerCards[i].destroy();
}
containerCards = [];
}
game.update = function () {
// Game runs at 60fps, no special update logic needed for this calculator
}; /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Button = Container.expand(function (width, height, color, text) {
var self = Container.call(this);
var bg = self.attachAsset(color === 0x3498db ? 'numberButton' : color === 0xe74c3c ? 'operatorButton' : 'clearButton', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: width / 350,
scaleY: height / 200
});
var label = new Text2(text, {
size: 80,
fill: 0xFFFFFF
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.originalScale = bg.scaleX;
self.down = function (x, y, obj) {
LK.getSound('buttonClick').play();
tween(bg, {
scaleX: self.originalScale * 0.9,
scaleY: self.originalScale * 0.9
}, {
duration: 100
});
if (self.onPress) {
self.onPress();
}
};
self.up = function (x, y, obj) {
tween(bg, {
scaleX: self.originalScale,
scaleY: self.originalScale
}, {
duration: 100
});
};
return self;
});
var ContainerCard = Container.expand(function (containerData) {
var self = Container.call(this);
var bg = self.attachAsset('containerCard', {
anchorX: 0.5,
anchorY: 0.5
});
var containerIcon = self.attachAsset(containerData.asset, {
anchorX: 0.5,
anchorY: 0.5,
x: -600
});
var nameText = new Text2(containerData.name, {
size: 60,
fill: 0x2C3E50
});
nameText.anchor.set(0, 0.3);
nameText.x = -400;
nameText.y = -50;
self.addChild(nameText);
var weightText = new Text2(containerData.capacity, {
size: 50,
fill: 0x7F8C8D
});
weightText.anchor.set(0, 0.3);
weightText.x = -400;
weightText.y = 20;
self.addChild(weightText);
var factText = new Text2(containerData.fact, {
size: 40,
fill: 0x34495E
});
factText.anchor.set(0, 0.3);
factText.x = -400;
factText.y = 80;
self.addChild(factText);
self.alpha = 0;
tween(self, {
alpha: 1
}, {
duration: 500
});
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xbdc3c7
});
/****
* Game Code
****/
var currentInput = "";
var calculationCount = 0;
var containerCards = [];
// Container database with weight ranges in grams
var containerDatabase = [{
range: {
min: 0.1,
max: 1
},
name: "Paperclip",
capacity: "1g",
fact: "Standard office paperclip weight",
asset: "paperclip"
}, {
range: {
min: 4,
max: 6
},
name: "Teaspoon of Sugar",
capacity: "5g",
fact: "One level teaspoon of sugar",
asset: "sugar"
}, {
range: {
min: 28,
max: 30
},
name: "One Ounce",
capacity: "28g",
fact: "Standard US ounce measurement",
asset: "teaspoon"
}, {
range: {
min: 240,
max: 260
},
name: "Cup of Water",
capacity: "250g",
fact: "One cup of water weighs about 250g",
asset: "cup"
}, {
range: {
min: 350,
max: 400
},
name: "Soda Can Contents",
capacity: "355g",
fact: "Weight of liquid in a standard can",
asset: "sodaCan"
}, {
range: {
min: 450,
max: 550
},
name: "Water Bottle",
capacity: "500g",
fact: "500ml of water weighs 500g",
asset: "bottle"
}, {
range: {
min: 950,
max: 1050
},
name: "1 Kilogram",
capacity: "1kg",
fact: "Standard metric weight unit",
asset: "bottle"
}, {
range: {
min: 2200,
max: 2300
},
name: "5 Pounds",
capacity: "2.27kg",
fact: "US 5-pound weight equivalent",
asset: "bucket"
}, {
range: {
min: 4500,
max: 5500
},
name: "Bag of Sugar",
capacity: "5kg",
fact: "Standard grocery store bag",
asset: "sugarBag"
}, {
range: {
min: 9000,
max: 11000
},
name: "Bowling Ball",
capacity: "10kg",
fact: "Standard bowling ball weight",
asset: "bowlingBall"
}, {
range: {
min: 45000,
max: 55000
},
name: "Large Dog",
capacity: "50kg",
fact: "Golden Retriever average weight",
asset: "dog"
}, {
range: {
min: 70000,
max: 80000
},
name: "Adult Human",
capacity: "75kg",
fact: "Average adult human weight",
asset: "human"
}];
// Create calculator background
var calculatorBg = game.attachAsset('calculatorBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 1366
});
// Create display area
var displayBg = game.attachAsset('displayBg', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 400
});
var displayText = new Text2("0", {
size: 120,
fill: 0xFFFFFF
});
displayText.anchor.set(0.5, 0.5);
displayText.x = 1024;
displayText.y = 400;
game.addChild(displayText);
// Create number buttons
var buttons = [];
var buttonLayout = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0', '.', '=']];
for (var row = 0; row < buttonLayout.length; row++) {
for (var col = 0; col < buttonLayout[row].length; col++) {
var buttonText = buttonLayout[row][col];
var buttonColor = buttonText === '=' ? 0xe74c3c : 0x3498db;
var button = new Button(350, 200, buttonColor, buttonText);
button.x = 500 + col * 380;
button.y = 700 + row * 220;
// Closure to capture button text
(function (text) {
button.onPress = function () {
handleButtonPress(text);
};
})(buttonText);
game.addChild(button);
buttons.push(button);
}
}
// Create clear button
var clearButton = new Button(350, 200, 0xf39c12, "C");
clearButton.x = 1260;
clearButton.y = 700;
clearButton.onPress = function () {
currentInput = "";
updateDisplay();
clearContainers();
};
game.addChild(clearButton);
// Score display
var scoreTxt = new Text2('Calculations: 0', {
size: 80,
fill: 0x2C3E50
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
function handleButtonPress(buttonText) {
if (buttonText === '=') {
calculateContainers();
} else if (buttonText === '.') {
if (currentInput.indexOf('.') === -1) {
currentInput += buttonText;
}
} else {
currentInput += buttonText;
}
updateDisplay();
}
function updateDisplay() {
var displayValue = currentInput || "0";
if (displayValue.length > 12) {
displayValue = displayValue.substring(0, 12);
}
displayText.setText(displayValue);
}
function calculateContainers() {
if (!currentInput || currentInput === "") return;
var inputValue = parseFloat(currentInput);
if (isNaN(inputValue) || inputValue <= 0) return;
LK.getSound('calculate').play();
calculationCount++;
LK.setScore(calculationCount);
scoreTxt.setText('Calculations: ' + calculationCount);
clearContainers();
var matchingContainers = findMatchingContainers(inputValue);
displayContainers(matchingContainers);
}
function findMatchingContainers(value) {
var matches = [];
// Find exact or close matches
for (var i = 0; i < containerDatabase.length; i++) {
var container = containerDatabase[i];
if (value >= container.range.min && value <= container.range.max) {
matches.push(container);
}
}
// If no exact matches, find closest ones
if (matches.length === 0) {
var closestContainers = containerDatabase.slice().sort(function (a, b) {
var distanceA = Math.min(Math.abs(value - a.range.min), Math.abs(value - a.range.max));
var distanceB = Math.min(Math.abs(value - b.range.min), Math.abs(value - b.range.max));
return distanceA - distanceB;
});
matches = closestContainers.slice(0, 3);
}
return matches.slice(0, 4);
}
function displayContainers(containers) {
var startY = 1700;
for (var i = 0; i < containers.length; i++) {
var card = new ContainerCard(containers[i]);
card.x = 1024;
card.y = startY + i * 350;
game.addChild(card);
containerCards.push(card);
}
}
function clearContainers() {
for (var i = 0; i < containerCards.length; i++) {
containerCards[i].destroy();
}
containerCards = [];
}
game.update = function () {
// Game runs at 60fps, no special update logic needed for this calculator
};
a bag of sugar. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
some sugar. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a soda can. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a human man. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a dog. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a bowling ball. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat