/**** * 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; // Function to change the screen color function changeScreenColor() { if (!isGreen) { game.setBackgroundColor(0x00FF00); // Change to green isGreen = true; } 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 LK.setScore(LK.getScore() + 1); // Increment score LK.showYouWin(); // Show win screen } else { // Player clicked when the screen was not green LK.showGameOver(); // Show game over screen } };
===================================================================
--- original.js
+++ change.js
@@ -1,40 +1,41 @@
-/****
+/****
* 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
+ backgroundColor: 0x000000 //Init game with black background
});
-/****
+/****
* Game Code
-****/
+****/
// Variables to manage game state
var isGreen = false;
var changeColorTimeout;
// Function to change the screen color
function changeScreenColor() {
- if (!isGreen) {
- game.setBackgroundColor(0x00FF00); // Change to green
- isGreen = true;
- } 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);
+ if (!isGreen) {
+ game.setBackgroundColor(0x00FF00); // Change to green
+ isGreen = true;
+ } 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
- LK.showYouWin(); // Show win screen
- } else {
- // Player clicked when the screen was not green
- LK.showGameOver(); // Show game over screen
- }
+ if (isGreen) {
+ // Player clicked when the screen was green
+ LK.setScore(LK.getScore() + 1); // Increment score
+ LK.showYouWin(); // Show win screen
+ } else {
+ // Player clicked when the screen was not green
+ LK.showGameOver(); // Show game over screen
+ }
};
\ No newline at end of file