/**** * 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 timeText = new Text2(containerData.capacity, { size: 50, fill: 0x7F8C8D }); timeText.anchor.set(0, 0.3); timeText.x = -400; timeText.y = 20; self.addChild(timeText); 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 time ranges in seconds var containerDatabase = [{ range: { min: 0.1, max: 1 }, name: "Eye Blink", capacity: "0.5s", fact: "Average human eye blink duration", asset: "paperclip" }, { range: { min: 4, max: 6 }, name: "Heartbeat", capacity: "5s", fact: "Time between normal resting heartbeats", asset: "sugar" }, { range: { min: 28, max: 30 }, name: "Commercial Break", capacity: "30s", fact: "Standard TV commercial duration", asset: "teaspoon" }, { range: { min: 240, max: 260 }, name: "Microwave Timer", capacity: "4 min", fact: "Common microwave cooking time", asset: "cup" }, { range: { min: 350, max: 400 }, name: "Pop Song", capacity: "6 min", fact: "Average length of a popular song", asset: "sodaCan" }, { range: { min: 450, max: 550 }, name: "Coffee Break", capacity: "8 min", fact: "Standard workplace coffee break", asset: "bottle" }, { range: { min: 950, max: 1050 }, name: "Quick Shower", capacity: "15 min", fact: "Average quick shower duration", asset: "bottle" }, { range: { min: 2200, max: 2300 }, name: "Lunch Break", capacity: "38 min", fact: "Average lunch break duration", asset: "bucket" }, { range: { min: 4500, max: 5500 }, name: "Movie Length", capacity: "1.5 hours", fact: "Average feature film duration", asset: "sugarBag" }, { range: { min: 9000, max: 11000 }, name: "Work Shift", capacity: "2.5 hours", fact: "Quarter of a typical work day", asset: "bowlingBall" }, { range: { min: 45000, max: 55000 }, name: "Sleep Cycle", capacity: "14 hours", fact: "Extended sleep duration", asset: "dog" }, { range: { min: 70000, max: 80000 }, name: "Full Day", capacity: "21 hours", fact: "Most of a 24-hour day", 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 };
===================================================================
--- original.js
+++ change.js
@@ -61,16 +61,16 @@
nameText.anchor.set(0, 0.3);
nameText.x = -400;
nameText.y = -50;
self.addChild(nameText);
- var weightText = new Text2(containerData.capacity, {
+ var timeText = new Text2(containerData.capacity, {
size: 50,
fill: 0x7F8C8D
});
- weightText.anchor.set(0, 0.3);
- weightText.x = -400;
- weightText.y = 20;
- self.addChild(weightText);
+ timeText.anchor.set(0, 0.3);
+ timeText.x = -400;
+ timeText.y = 20;
+ self.addChild(timeText);
var factText = new Text2(containerData.fact, {
size: 40,
fill: 0x34495E
});
@@ -99,116 +99,116 @@
****/
var currentInput = "";
var calculationCount = 0;
var containerCards = [];
-// Container database with weight ranges in grams
+// Container database with time ranges in seconds
var containerDatabase = [{
range: {
min: 0.1,
max: 1
},
- name: "Paperclip",
- capacity: "1g",
- fact: "Standard office paperclip weight",
+ name: "Eye Blink",
+ capacity: "0.5s",
+ fact: "Average human eye blink duration",
asset: "paperclip"
}, {
range: {
min: 4,
max: 6
},
- name: "Teaspoon of Sugar",
- capacity: "5g",
- fact: "One level teaspoon of sugar",
+ name: "Heartbeat",
+ capacity: "5s",
+ fact: "Time between normal resting heartbeats",
asset: "sugar"
}, {
range: {
min: 28,
max: 30
},
- name: "One Ounce",
- capacity: "28g",
- fact: "Standard US ounce measurement",
+ name: "Commercial Break",
+ capacity: "30s",
+ fact: "Standard TV commercial duration",
asset: "teaspoon"
}, {
range: {
min: 240,
max: 260
},
- name: "Cup of Water",
- capacity: "250g",
- fact: "One cup of water weighs about 250g",
+ name: "Microwave Timer",
+ capacity: "4 min",
+ fact: "Common microwave cooking time",
asset: "cup"
}, {
range: {
min: 350,
max: 400
},
- name: "Soda Can Contents",
- capacity: "355g",
- fact: "Weight of liquid in a standard can",
+ name: "Pop Song",
+ capacity: "6 min",
+ fact: "Average length of a popular song",
asset: "sodaCan"
}, {
range: {
min: 450,
max: 550
},
- name: "Water Bottle",
- capacity: "500g",
- fact: "500ml of water weighs 500g",
+ name: "Coffee Break",
+ capacity: "8 min",
+ fact: "Standard workplace coffee break",
asset: "bottle"
}, {
range: {
min: 950,
max: 1050
},
- name: "1 Kilogram",
- capacity: "1kg",
- fact: "Standard metric weight unit",
+ name: "Quick Shower",
+ capacity: "15 min",
+ fact: "Average quick shower duration",
asset: "bottle"
}, {
range: {
min: 2200,
max: 2300
},
- name: "5 Pounds",
- capacity: "2.27kg",
- fact: "US 5-pound weight equivalent",
+ name: "Lunch Break",
+ capacity: "38 min",
+ fact: "Average lunch break duration",
asset: "bucket"
}, {
range: {
min: 4500,
max: 5500
},
- name: "Bag of Sugar",
- capacity: "5kg",
- fact: "Standard grocery store bag",
+ name: "Movie Length",
+ capacity: "1.5 hours",
+ fact: "Average feature film duration",
asset: "sugarBag"
}, {
range: {
min: 9000,
max: 11000
},
- name: "Bowling Ball",
- capacity: "10kg",
- fact: "Standard bowling ball weight",
+ name: "Work Shift",
+ capacity: "2.5 hours",
+ fact: "Quarter of a typical work day",
asset: "bowlingBall"
}, {
range: {
min: 45000,
max: 55000
},
- name: "Large Dog",
- capacity: "50kg",
- fact: "Golden Retriever average weight",
+ name: "Sleep Cycle",
+ capacity: "14 hours",
+ fact: "Extended sleep duration",
asset: "dog"
}, {
range: {
min: 70000,
max: 80000
},
- name: "Adult Human",
- capacity: "75kg",
- fact: "Average adult human weight",
+ name: "Full Day",
+ capacity: "21 hours",
+ fact: "Most of a 24-hour day",
asset: "human"
}];
// Create calculator background
var calculatorBg = game.attachAsset('calculatorBg', {
a toothbrush. In-Game asset. 2d. High contrast. No shadows
tv. In-Game asset. 2d. High contrast. No shadows
work desk. In-Game asset. 2d. High contrast. No shadows
sun. In-Game asset. 2d. High contrast. No shadows
bed. In-Game asset. 2d. High contrast. No shadows
shower. In-Game asset. 2d. High contrast. No shadows
coffee cup. In-Game asset. 2d. High contrast. No shadows
music note low c. In-Game asset. 2d. High contrast. No shadows
movie reel. In-Game asset. 2d. High contrast. No shadows
microwave. In-Game asset. 2d. High contrast. No shadows
lunch. In-Game asset. 2d. High contrast. No shadows
heart beat. In-Game asset. 2d. High contrast. No shadows
eye. In-Game asset. 2d. High contrast. No shadows