/**** * Initialize Game ****/ //<Assets used in the game will automatically appear here> //<Write imports for supported plugins here> //<Write entity 'classes' with empty functions for important behavior here> var game = new LK.Game({ backgroundColor: 0x000000 //Init game with black background }); /**** * Game Code ****/ // Variables to manage game state var isGreen = false; var changeColorTimeout; var greenStartTime; // Declare variable to store the time when the screen turns green // Function to change the screen color function changeScreenColor() { if (!isGreen) { game.setBackgroundColor(0x00FF00); // Change to green isGreen = true; greenStartTime = Date.now(); // Record the time when the screen turns green } else { game.setBackgroundColor(0x000000); // Change back to black isGreen = false; } // Randomly change color again between 1 to 3 seconds changeColorTimeout = LK.setTimeout(changeScreenColor, Math.random() * 2000 + 1000); } // Start the color change cycle changeColorTimeout = LK.setTimeout(changeScreenColor, Math.random() * 2000 + 1000); // Event listener for screen tap game.down = function (x, y, obj) { if (isGreen) { // Player clicked when the screen was green // Calculate score based on reaction time (faster = higher score, max 1000) var reactionTime = Date.now() - greenStartTime; // in milliseconds var score = Math.max(0, Math.round((3000 - reactionTime) / 3)); // max 3 seconds, scaled to 1000 LK.setScore(score); LK.showYouWin(); // Show win screen } else { // Player clicked when the screen was not green LK.showGameOver(); // Show game over screen } };
/****
* Initialize Game
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
//<Write entity 'classes' with empty functions for important behavior here>
var game = new LK.Game({
backgroundColor: 0x000000 //Init game with black background
});
/****
* Game Code
****/
// Variables to manage game state
var isGreen = false;
var changeColorTimeout;
var greenStartTime; // Declare variable to store the time when the screen turns green
// Function to change the screen color
function changeScreenColor() {
if (!isGreen) {
game.setBackgroundColor(0x00FF00); // Change to green
isGreen = true;
greenStartTime = Date.now(); // Record the time when the screen turns green
} else {
game.setBackgroundColor(0x000000); // Change back to black
isGreen = false;
}
// Randomly change color again between 1 to 3 seconds
changeColorTimeout = LK.setTimeout(changeScreenColor, Math.random() * 2000 + 1000);
}
// Start the color change cycle
changeColorTimeout = LK.setTimeout(changeScreenColor, Math.random() * 2000 + 1000);
// Event listener for screen tap
game.down = function (x, y, obj) {
if (isGreen) {
// Player clicked when the screen was green
// Calculate score based on reaction time (faster = higher score, max 1000)
var reactionTime = Date.now() - greenStartTime; // in milliseconds
var score = Math.max(0, Math.round((3000 - reactionTime) / 3)); // max 3 seconds, scaled to 1000
LK.setScore(score);
LK.showYouWin(); // Show win screen
} else {
// Player clicked when the screen was not green
LK.showGameOver(); // Show game over screen
}
};