User prompt
When the countdown number drops below 30 seconds, it should turn yellow; when it drops below 10 seconds, it should turn red.
User prompt
When the time limit counts down to 10 or less, the number should be displayed in red.
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'timerTxt.style.fill = "#ff0000"; // Change color to red' Line Number: 119
User prompt
When the time limit is less than 10 seconds remaining, the countdown number should turn red.
User prompt
When the time limit is less than 10 seconds remaining, the number should turn red.
User prompt
The time limit countdown should be displayed in the upper right corner of the screen in large font.
User prompt
Please set a time limit. The time limit is one minute, and at the end of the game, the score earned up to that point should be displayed.
User prompt
Change the amount of points for acquiring rice as follows -2 points for rice_long, -1 point for rice_medium, +1 point for rice_short
Initial prompt
LET'S EAT RICE
/**** * Classes ****/ // Class for Basket var Basket = Container.expand(function () { var self = Container.call(this); var basketGraphics = self.attachAsset('basket', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { // Basket update logic if needed }; }); //<Assets used in the game will automatically appear here> // Class for Rice var Rice = Container.expand(function (type) { var self = Container.call(this); var assetId = 'rice_' + type; var riceGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.speed = 5; self.update = function () { self.y += self.speed; if (self.y > 2732) { self.destroy(); } }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Initialize arrays and variables var rices = []; var basket; var score = 0; var scoreTxt = new Text2('0', { size: 150, fill: "#ffffff" }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Initialize basket basket = game.addChild(new Basket()); basket.x = 2048 / 2; basket.y = 2500; // Function to handle move events function handleMove(x, y, obj) { basket.x = x; } // Mouse or touch move on game object game.move = handleMove; // Function to spawn rice function spawnRice() { var types = ['short', 'medium', 'long']; var type = types[Math.floor(Math.random() * types.length)]; var newRice = new Rice(type); newRice.x = Math.random() * 2048; newRice.y = -50; rices.push(newRice); game.addChild(newRice); } // Initialize timer var timer = 60 * 60; // 60 seconds * 60 frames per second var timerTxt = new Text2('60', { size: 200, fill: "#ffffff" }); timerTxt.anchor.set(1, 0); LK.gui.topRight.addChild(timerTxt); // Update function game.update = function () { for (var i = rices.length - 1; i >= 0; i--) { if (rices[i].intersects(basket)) { switch (rices[i].type) { case 'long': score -= 2; break; case 'medium': score -= 1; break; case 'short': score += 1; break; } scoreTxt.setText(score); rices[i].destroy(); rices.splice(i, 1); } } if (LK.ticks % 60 == 0) { spawnRice(); } // Update timer if (timer > 0) { timer--; timerTxt.setText(Math.floor(timer / 60)); if (timer <= 1800 && timer > 600) { timerTxt.fill = "#FFFF00"; } if (timer <= 600) { timerTxt.fill = "#FF0000"; } } else { // End game when timer reaches 0 LK.showGameOver(); } };
===================================================================
--- original.js
+++ change.js
@@ -104,13 +104,15 @@
}
// Update timer
if (timer > 0) {
timer--;
- var remainingTime = Math.floor(timer / 60);
- timerTxt.setText(remainingTime);
- if (remainingTime < 10) {
- timerTxt.style.fill = "#ff0000"; // Change color to red
+ timerTxt.setText(Math.floor(timer / 60));
+ if (timer <= 1800 && timer > 600) {
+ timerTxt.fill = "#FFFF00";
}
+ if (timer <= 600) {
+ timerTxt.fill = "#FF0000";
+ }
} else {
// End game when timer reaches 0
LK.showGameOver();
}