Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
increase speed of lighs moving out
User prompt
instead of destroying the lights, lightbackground and center asset, have them move offscreen to the right, at the same speed that the score records are moving in screen
User prompt
lights can turn off between 1 and 4 seconds
Code edit (4 edits merged)
Please save this source code
User prompt
player can only tap on the game twice. to start and stop time. after second touch, disable touch screen.
User prompt
do not allow player to touch screen again after reaction time is set
User prompt
Disable tap after second touch
User prompt
disaable tap after second touch
User prompt
reduce cell width
User prompt
reduce gridlines size to fit the current date better
User prompt
Draw the grid using assets for the ranked table. Need to see all the lines for the cels
User prompt
The table looks very retro. Lets replace the text line for an asset
User prompt
highligh you result in the ranked table
User prompt
Replace ------------------------------------ by an asset line
User prompt
show lines of the table, columns and rows
User prompt
add more space between each column in the records tabel
User prompt
remove flag text, just keep the image
User prompt
can we adjust the anchor of the flags so that they are aligned between rank and player in each row
User prompt
flag assets should be between the rank and the name
Code edit (1 edits merged)
Please save this source code
/**** * Classes ****/ // No need to manually define assets, LK will handle this automatically. // Define a simple class for the light indicator var LightIndicator = Container.expand(function () { var self = Container.call(this); var light = self.attachAsset('light', { anchorX: 0.5, anchorY: 0.5 }); self.setColor = function (color) { light.tint = color; }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xFFFFFF // Init game with a white background }); /**** * Game Code ****/ // Initialize variables var lightIndicator; var startTime; var reactionTimeText; var gameStarted = false; var countdown = 5; var lightsOff = false; var jumpstart = false; var scoreRecords = [{ name: 'Alice', score: 150 }, { name: 'Bob', score: 200 }, { name: 'Charlie', score: 250 }, { name: 'David', score: 300 }, { name: 'Eve', score: 350 }, { name: 'Frank', score: 400 }, { name: 'Grace', score: 450 }, { name: 'Hannah', score: 500 }, { name: 'Ivy', score: 550 }, { name: 'Jack', score: 600 }]; // Function to start the game function startGame() { gameStarted = true; startTime = Date.now(); var countdownInterval = LK.setInterval(function () { countdown--; if (countdown >= 0 && !jumpstart) { lightIndicators[5 - countdown - 1].setColor(0xFF0000); // Set light to red lightIndicators2[5 - countdown - 1].setColor(0xFF0000); // Set light to red LK.getSound('lights').play(); // Play sound when light is turned on } if (countdown === 0 && !jumpstart) { LK.clearInterval(countdownInterval); if (!jumpstart) { LK.setTimeout(turnOffLight, Math.random() * 3000 + 2000); // Turn off light after a random time between 2-5 seconds } } }, 1000); } // Function to turn off the light function turnOffLight() { lightIndicators.forEach(function (lightIndicator) { lightIndicator.setColor(0x9f9d9d); // Set light to offlight color }); lightIndicators2.forEach(function (lightIndicator) { lightIndicator.setColor(0x9f9d9d); // Set light to offlight color }); startTime = Date.now(); // Record the time when the light turns off lightsOff = true; // Set the flag to true when lights turn off if (!jumpstart) { LK.getSound('start').play(); // Play sound when lights go off } } // Function to handle screen tap var touchCount = 0; function handleTap(x, y, obj) { touchCount++; if (!gameStarted) { startGame(); instructionText.visible = false; // Hide instructions text after first tap } else if (touchCount == 2 && !lightsOff) { reactionTimeText.setText('JUMP START!'); gameStarted = false; jumpstart = true; LK.getSound('jumpstart').play(); // Play 'jumpstart' sound when jumpstart happens } else { var reactionTime = Date.now() - startTime; LK.setScore(reactionTime); reactionTimeText.setText((LK.getScore() / 1000).toFixed(3).padStart(6, '0')); reactionTimeText.scale.x = 1.1; reactionTimeText.scale.y = 1.1; LK.setTimeout(function () { reactionTimeText.scale.x = 1; reactionTimeText.scale.y = 1; }, 100); LK.getSound('speed').play(); // Play 'speed' sound when reaction time is updated gameStarted = false; } if (touchCount == 2) { // Add the current score to the score records with 'YOU' as the name scoreRecords.push({ name: 'YOU', score: LK.getScore() }); scoreRecords.sort(function (a, b) { return a.score - b.score; }); // Sort scores in ascending order // Generate random names for the other records var names = ['Alice', 'Bob', 'Charlie', 'David', 'Eve', 'Frank', 'Grace', 'Hannah', 'Ivy', 'Jack']; for (var i = 0; i < scoreRecords.length; i++) { if (scoreRecords[i].name !== 'YOU') { scoreRecords[i].name = names[Math.floor(Math.random() * names.length)]; } } // Display the score records in a table format var scoreTable = "Rank\t\tName\t\t\tTime (s)\n"; scoreTable += "------------------------------------\n"; for (var i = 0; i < scoreRecords.length; i++) { scoreTable += i + 1 + "\t\t" + scoreRecords[i].name + "\t\t\t" + (scoreRecords[i].score / 1000).toFixed(3) + "s\n"; } var scoreRecordsText = new Text2(scoreTable, { size: 60, fill: "#000000" }); scoreRecordsText.anchor.set(0.5, 0); scoreRecordsText.x = 2048 / 2; scoreRecordsText.y = 2732 / 2 - 400; game.addChildAt(scoreRecordsText, game.children.length); // Add background image behind the records table var backgroundImage = LK.getAsset('background', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 }); game.addChildAt(backgroundImage, game.children.length - 1); // Draw grid lines for the ranked table var numRows = scoreRecords.length + 1; // Including header row var numCols = 3; // Rank, Name, Time var cellHeight = 100; // Adjust as needed var cellWidth = 2048 / numCols; // Adjust as needed for (var i = 0; i <= numRows; i++) { var horizontalLine = LK.getAsset('gridLine', { x: 0, y: 2732 / 2 - 400 + i * cellHeight }); game.addChild(horizontalLine); } for (var j = 0; j <= numCols; j++) { var verticalLine = LK.getAsset('gridLine', { width: 2, height: numRows * cellHeight, x: j * cellWidth, y: 2732 / 2 - 400 }); game.addChild(verticalLine); } LK.setTimeout(function () { LK.showGameOver(); }, 5000); // Show game over after 5 seconds to allow time to read the scores } } // Initialize light indicators var lightIndicators = []; var lightIndicators2 = []; var staticLightIndicators1 = []; var staticLightIndicators2 = []; for (var i = 0; i < 5; i++) { var lightBackground = game.addChild(LK.getAsset('lightbackground', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2 + (i - 2) * 200, y: 2732 / 2 - 70 })); var lightIndicator = game.addChild(new LightIndicator()); lightIndicator.x = 2048 / 2 + (i - 2) * 200; // Position lights horizontally with some spacing lightIndicator.y = 2732 / 2; lightIndicator.setColor(0x9f9d9d); // Set initial light color to white lightIndicators.push(lightIndicator); var lightIndicator2 = game.addChild(new LightIndicator()); lightIndicator2.x = 2048 / 2 + (i - 2) * 200; // Position lights horizontally with some spacing lightIndicator2.y = 2732 / 2 + 150; // Position the second line of lights 200px below the first line lightIndicator2.setColor(0x9f9d9d); // Set initial light color to white lightIndicators2.push(lightIndicator2); // Add static lights var staticLight1 = game.addChild(new LightIndicator()); staticLight1.x = 2048 / 2 + (i - 2) * 200; // Position lights horizontally with some spacing staticLight1.y = 2732 / 2 - 150; // Position the first line of static lights 200px above the first line staticLight1.setColor(0x9f9d9d); // Set initial light color to white staticLightIndicators1.push(staticLight1); var staticLight2 = game.addChild(new LightIndicator()); staticLight2.x = 2048 / 2 + (i - 2) * 200; // Position lights horizontally with some spacing staticLight2.y = 2732 / 2 - 300; // Position the second line of static lights 400px above the first line staticLight2.setColor(0x9f9d9d); // Set initial light color to white staticLightIndicators2.push(staticLight2); } // Initialize reaction time text reactionTimeText = new Text2('00.000', { size: 200, fill: "#000000" }); reactionTimeText.anchor.set(0.5, 1); reactionTimeText.y -= 250; // Move reaction time 400 pixels up LK.gui.bottom.addChild(reactionTimeText); // Add instruction text below the lights var instructionText = new Text2("Tap when you're ready to race. Tap again when the lights go out.", { size: 60, fill: "#000000" }); instructionText.anchor.set(0.5, 0); instructionText.x = 2048 / 2; instructionText.y = 2732 / 2 + 450; game.addChild(instructionText); // Add 'f1' asset to the top of the screen var f1Asset = game.addChild(LK.getAsset('f1', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 400 })); // Add 'centerAsset' to the center of the lights var centerAsset = game.addChildAt(LK.getAsset('centerAsset', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 - 60 }), 0); // Set up event listeners game.down = handleTap; game.update = function () { // Add a slight increase and decrease in size to the instruction text instructionText.scale.x = 1 + 0.02 * Math.sin(LK.ticks / 20); instructionText.scale.y = 1 + 0.02 * Math.sin(LK.ticks / 20); };
===================================================================
--- original.js
+++ change.js
@@ -173,9 +173,9 @@
game.addChild(horizontalLine);
}
for (var j = 0; j <= numCols; j++) {
var verticalLine = LK.getAsset('gridLine', {
- width: 5,
+ width: 2,
height: numRows * cellHeight,
x: j * cellWidth,
y: 2732 / 2 - 400
});