/****
* 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 capacityText = new Text2(containerData.capacity, {
size: 50,
fill: 0x7F8C8D
});
capacityText.anchor.set(0, 0.3);
capacityText.x = -400;
capacityText.y = 20;
self.addChild(capacityText);
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 capacity ranges in milliliters
var containerDatabase = [{
range: {
min: 0.1,
max: 5
},
name: "Medicine Dropper",
capacity: "1-5ml",
fact: "Used for precise liquid measurements",
asset: "teaspoon"
}, {
range: {
min: 4,
max: 6
},
name: "Teaspoon",
capacity: "5ml",
fact: "Standard cooking measurement",
asset: "teaspoon"
}, {
range: {
min: 14,
max: 16
},
name: "Tablespoon",
capacity: "15ml",
fact: "Three teaspoons make one tablespoon",
asset: "teaspoon"
}, {
range: {
min: 240,
max: 250
},
name: "Coffee Cup",
capacity: "240ml",
fact: "Standard coffee serving size",
asset: "cup"
}, {
range: {
min: 350,
max: 400
},
name: "Soda Can",
capacity: "355ml",
fact: "Most common beverage can size",
asset: "bottle"
}, {
range: {
min: 470,
max: 500
},
name: "Water Bottle",
capacity: "500ml",
fact: "Popular single-serve size",
asset: "bottle"
}, {
range: {
min: 950,
max: 1050
},
name: "Large Water Bottle",
capacity: "1L",
fact: "Daily hydration goal for many",
asset: "bottle"
}, {
range: {
min: 3700,
max: 3800
},
name: "Gallon Jug",
capacity: "3.78L",
fact: "US gallon measurement",
asset: "bucket"
}, {
range: {
min: 9000,
max: 11000
},
name: "Large Bucket",
capacity: "10L",
fact: "Common household cleaning bucket",
asset: "bucket"
}, {
range: {
min: 190000,
max: 210000
},
name: "Bathtub",
capacity: "200L",
fact: "Average home bathtub capacity",
asset: "pool"
}, {
range: {
min: 950000,
max: 1050000
},
name: "Small Hot Tub",
capacity: "1000L",
fact: "4-person hot tub size",
asset: "pool"
}, {
range: {
min: 75000000,
max: 85000000
},
name: "Swimming Pool",
capacity: "80,000L",
fact: "Olympic-sized pool holds 2.5M liters",
asset: "pool"
}];
// 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
}; ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,341 @@
-/****
+/****
+* 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 capacityText = new Text2(containerData.capacity, {
+ size: 50,
+ fill: 0x7F8C8D
+ });
+ capacityText.anchor.set(0, 0.3);
+ capacityText.x = -400;
+ capacityText.y = 20;
+ self.addChild(capacityText);
+ 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: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xbdc3c7
+});
+
+/****
+* Game Code
+****/
+var currentInput = "";
+var calculationCount = 0;
+var containerCards = [];
+// Container database with capacity ranges in milliliters
+var containerDatabase = [{
+ range: {
+ min: 0.1,
+ max: 5
+ },
+ name: "Medicine Dropper",
+ capacity: "1-5ml",
+ fact: "Used for precise liquid measurements",
+ asset: "teaspoon"
+}, {
+ range: {
+ min: 4,
+ max: 6
+ },
+ name: "Teaspoon",
+ capacity: "5ml",
+ fact: "Standard cooking measurement",
+ asset: "teaspoon"
+}, {
+ range: {
+ min: 14,
+ max: 16
+ },
+ name: "Tablespoon",
+ capacity: "15ml",
+ fact: "Three teaspoons make one tablespoon",
+ asset: "teaspoon"
+}, {
+ range: {
+ min: 240,
+ max: 250
+ },
+ name: "Coffee Cup",
+ capacity: "240ml",
+ fact: "Standard coffee serving size",
+ asset: "cup"
+}, {
+ range: {
+ min: 350,
+ max: 400
+ },
+ name: "Soda Can",
+ capacity: "355ml",
+ fact: "Most common beverage can size",
+ asset: "bottle"
+}, {
+ range: {
+ min: 470,
+ max: 500
+ },
+ name: "Water Bottle",
+ capacity: "500ml",
+ fact: "Popular single-serve size",
+ asset: "bottle"
+}, {
+ range: {
+ min: 950,
+ max: 1050
+ },
+ name: "Large Water Bottle",
+ capacity: "1L",
+ fact: "Daily hydration goal for many",
+ asset: "bottle"
+}, {
+ range: {
+ min: 3700,
+ max: 3800
+ },
+ name: "Gallon Jug",
+ capacity: "3.78L",
+ fact: "US gallon measurement",
+ asset: "bucket"
+}, {
+ range: {
+ min: 9000,
+ max: 11000
+ },
+ name: "Large Bucket",
+ capacity: "10L",
+ fact: "Common household cleaning bucket",
+ asset: "bucket"
+}, {
+ range: {
+ min: 190000,
+ max: 210000
+ },
+ name: "Bathtub",
+ capacity: "200L",
+ fact: "Average home bathtub capacity",
+ asset: "pool"
+}, {
+ range: {
+ min: 950000,
+ max: 1050000
+ },
+ name: "Small Hot Tub",
+ capacity: "1000L",
+ fact: "4-person hot tub size",
+ asset: "pool"
+}, {
+ range: {
+ min: 75000000,
+ max: 85000000
+ },
+ name: "Swimming Pool",
+ capacity: "80,000L",
+ fact: "Olympic-sized pool holds 2.5M liters",
+ asset: "pool"
+}];
+// 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
+};
\ No newline at end of file
a pool. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a drink bottle. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a cup. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a bathtub. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a bucket. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat
a teaspoon. No background. Transparent background. Blank background. No shadows. 2d. In-Game asset. flat