/**** 
* Initialize Game
****/ 
// No assets are needed for this game
// No classes are needed for this game
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
// Add instructions text at the bottom of the screen
var instructionsTxt = new Text2('Diffuse the bomb by clicking perfect timing X 10.\nTarget is the .0 mark of each second.\nGetting a perfect .00 score immediately wins!', {
	size: 80,
	fill: "#ffffff"
});
instructionsTxt.anchor.set(0.5, 1.0);
instructionsTxt.x = 2048 / 2;
instructionsTxt.y = 2732 - 20; // Position near the bottom of the screen
game.addChild(instructionsTxt);
// Initialize variables
// Initialize sound assets
var winTxt = null;
var loseTxt = null;
var startTime = null;
var elapsedTime = 0;
var timerTxt = null;
var gameStarted = false;
var progressBar = null;
var progressBarWidth = 2048; // Full width of the screen
var progressBarHeight = 50; // Height of the progress bar
// Add dynamite image behind the stopwatch image
var dynamiteImage = LK.getAsset('dynamite', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2,
	scaleX: 450 / 215.57 * 2,
	scaleY: 450 / 215.57 * 2,
	// Increase size by three times
	alpha: 0.5 // Set opacity to 80%
});
game.addChild(dynamiteImage);
// Add stopwatch image to the game
var stopwatchImage = LK.getAsset('stopwatchImage', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2
});
game.addChild(stopwatchImage);
// Create a progress bar
progressBar = LK.getAsset('stopwatch', {
	anchorX: 1.0,
	anchorY: 0.0,
	x: 2048,
	// Start from the right edge
	y: 0,
	// Top of the screen
	width: progressBarWidth,
	height: progressBarHeight,
	color: 0xff0000 // Red color for timer progress
});
game.addChild(progressBar);
// Create a defuse bar for points
var defuseBar = LK.getAsset('diffuseLine', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	// Start from the left edge
	y: 50,
	// Just below the top of the screen
	width: 0,
	// Start with zero width
	height: progressBarHeight * 2 // Double the height of the defuse bar
});
game.addChild(defuseBar);
// Create a text object to display the timer
timerTxt = new Text2('0.00', {
	size: 150,
	fill: "#ffffff",
	// Change text color to white
	stroke: "#000000",
	// Add black stroke
	strokeThickness: 10,
	// Set stroke thickness to thick
	font: "Arial" // Set font to Arial
});
timerTxt.anchor.set(0.5, 0.5);
timerTxt.x = 2048 / 2;
timerTxt.y = 2732 / 2 + 50;
game.addChild(timerTxt);
// Create a text object to display the score
var scoreTxt = new Text2('Defused: 0 of 10', {
	size: 80,
	fill: "#ffffff",
	stroke: "#000000",
	// Add black stroke
	strokeThickness: 5 // Set stroke thickness
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y += 10; // Lower the text by 10 pixels
LK.gui.top.addChild(scoreTxt);
startTime = Date.now();
gameStarted = true;
// Check the elapsed time on mouse up
game.down = function (x, y, obj) {
	if (gameStarted) {
		elapsedTime = 60 - (Date.now() - startTime) / 1000;
		timerTxt.setText(elapsedTime.toFixed(2));
		if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.01) {
			LK.effects.flashScreen(0xffff00, 500); // Flash yellow for exact time
			LK.getSound('exact').play(); // Play the 'exact' sound
			LK.setScore(10); // Automatically defuse all 10 fuses
			scoreTxt.setText('Fuses: 10 out of 10'); // Update score display
			defuseBar.width = progressBarWidth; // Increment defuse bar to full width
			gameStarted = false; // Stop the game
			LK.getSound('win').play(); // Play the 'win' sound
			// Display 'You Win!' text
			if (!winTxt) {
				winTxt = new Text2('You Win!', {
					size: 200,
					fill: "#ffffff"
				});
				winTxt.anchor.set(0.5, 0.0);
				winTxt.x = 2048 / 2;
				winTxt.y = 300; // Position near the top of the screen
				game.addChild(winTxt);
				// Add winning image to the game
				var winningImage = LK.getAsset('winningImage', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 2,
					scaleY: 2
				});
				game.addChild(winningImage);
			}
			// Display remaining time
			var remainingTimeTxt = new Text2('Remaining Time: ' + elapsedTime.toFixed(2) + 's', {
				size: 100,
				fill: "#ffffff"
			});
			remainingTimeTxt.anchor.set(0.5, 0.0);
			remainingTimeTxt.x = 2048 / 2;
			remainingTimeTxt.y = 700; // Lower the position by 300 pixels
			game.addChild(remainingTimeTxt);
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
		} else if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.1) {
			LK.setScore(LK.getScore() + 1); // Increment score by 1 for each hit
			scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
			if (LK.getScore() >= 10) {
				gameStarted = false; // Stop the game
				LK.setTimeout(function () {
					LK.showGameOver(); // End game
				}, 2000); // Delay by 2000ms or 2 seconds
			}
			LK.effects.flashScreen(0x00ff00, 500); // Flash green to simulate fireworks
			LK.getSound('hit').play(); // Play the 'hit' sound
			LK.setScore(LK.getScore() + 1); // Increment score by 1 for each hit
			scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
		} else {
			startTime -= 5000; // Adjust startTime to deduct five seconds persistently
			timerTxt.setText(elapsedTime.toFixed(2)); // Update timer display
			LK.effects.flashScreen(0xff0000, 500); // Flash red for negative effect
			LK.getSound('miss').play(); // Play the 'miss' sound
		}
	}
};
// Update the timer every game tick
game.update = function () {
	if (gameStarted) {
		elapsedTime = 60 - (Date.now() - startTime) / 1000;
		timerTxt.setText(elapsedTime.toFixed(2));
		// Update progress bar width
		progressBar.width = progressBarWidth * (1 - elapsedTime / 60);
		// Update defuse bar width with 10 segments
		defuseBar.width = progressBarWidth * (LK.getScore() / 10);
		if (LK.getScore() >= 10) {
			// game.setBackgroundColor(0x00ff00); // Removed green background effect
			if (!winTxt) {
				// Hide dynamite and stopwatch images and text
				dynamiteImage.visible = false;
				stopwatchImage.visible = false;
				timerTxt.visible = false;
				LK.getSound('win').play(); // Play the 'win' sound
				winTxt = new Text2('You Win!', {
					size: 200,
					fill: "#ffffff"
				});
				winTxt.anchor.set(0.5, 0.0);
				winTxt.x = 2048 / 2;
				winTxt.y = 300; // Position near the top of the screen
				game.addChild(winTxt);
				// Display remaining time
				var remainingTimeTxt = new Text2('Remaining Time: ' + elapsedTime.toFixed(2) + 's', {
					size: 100,
					fill: "#ffffff"
				});
				remainingTimeTxt.anchor.set(0.5, 0.0);
				remainingTimeTxt.x = 2048 / 2;
				remainingTimeTxt.y = 700; // Lower the position by 300 pixels
				game.addChild(remainingTimeTxt);
				// Add winning image to the game
				var winningImage = LK.getAsset('winningImage', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 2,
					scaleY: 2
				});
				game.addChild(winningImage);
			}
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
			gameStarted = false;
		} else if (elapsedTime <= 0) {
			if (!loseTxt) {
				// Hide dynamite and stopwatch images and text
				dynamiteImage.visible = false;
				stopwatchImage.visible = false;
				timerTxt.visible = false;
				// Display explosion image in the center of the screen
				var explosionImage = LK.getAsset('explosion', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 5,
					scaleY: 5
				});
				game.addChild(explosionImage);
				// Display remaining time
				var remainingTimeTxt = new Text2('Remaining Time: 0.00', {
					size: 100,
					fill: "#ffffff"
				});
				remainingTimeTxt.anchor.set(0.5, 0.0);
				remainingTimeTxt.x = 2048 / 2;
				remainingTimeTxt.y = 700; // Lower the position by 300 pixels
				game.addChild(remainingTimeTxt);
				LK.getSound('lose').play(); // Play the 'lose' sound
				loseTxt = new Text2('BOOM!', {
					size: 200,
					fill: "#ffffff"
				});
				loseTxt.anchor.set(0.5, 0.0);
				loseTxt.x = 2048 / 2;
				loseTxt.y = 300; // Position near the top of the screen
				game.addChild(loseTxt);
			}
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
			gameStarted = false;
		}
	}
};
// Initialize stopwatch image asset /**** 
* Initialize Game
****/ 
// No assets are needed for this game
// No classes are needed for this game
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
// Add instructions text at the bottom of the screen
var instructionsTxt = new Text2('Diffuse the bomb by clicking perfect timing X 10.\nTarget is the .0 mark of each second.\nGetting a perfect .00 score immediately wins!', {
	size: 80,
	fill: "#ffffff"
});
instructionsTxt.anchor.set(0.5, 1.0);
instructionsTxt.x = 2048 / 2;
instructionsTxt.y = 2732 - 20; // Position near the bottom of the screen
game.addChild(instructionsTxt);
// Initialize variables
// Initialize sound assets
var winTxt = null;
var loseTxt = null;
var startTime = null;
var elapsedTime = 0;
var timerTxt = null;
var gameStarted = false;
var progressBar = null;
var progressBarWidth = 2048; // Full width of the screen
var progressBarHeight = 50; // Height of the progress bar
// Add dynamite image behind the stopwatch image
var dynamiteImage = LK.getAsset('dynamite', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2,
	scaleX: 450 / 215.57 * 2,
	scaleY: 450 / 215.57 * 2,
	// Increase size by three times
	alpha: 0.5 // Set opacity to 80%
});
game.addChild(dynamiteImage);
// Add stopwatch image to the game
var stopwatchImage = LK.getAsset('stopwatchImage', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2732 / 2
});
game.addChild(stopwatchImage);
// Create a progress bar
progressBar = LK.getAsset('stopwatch', {
	anchorX: 1.0,
	anchorY: 0.0,
	x: 2048,
	// Start from the right edge
	y: 0,
	// Top of the screen
	width: progressBarWidth,
	height: progressBarHeight,
	color: 0xff0000 // Red color for timer progress
});
game.addChild(progressBar);
// Create a defuse bar for points
var defuseBar = LK.getAsset('diffuseLine', {
	anchorX: 0.0,
	anchorY: 0.0,
	x: 0,
	// Start from the left edge
	y: 50,
	// Just below the top of the screen
	width: 0,
	// Start with zero width
	height: progressBarHeight * 2 // Double the height of the defuse bar
});
game.addChild(defuseBar);
// Create a text object to display the timer
timerTxt = new Text2('0.00', {
	size: 150,
	fill: "#ffffff",
	// Change text color to white
	stroke: "#000000",
	// Add black stroke
	strokeThickness: 10,
	// Set stroke thickness to thick
	font: "Arial" // Set font to Arial
});
timerTxt.anchor.set(0.5, 0.5);
timerTxt.x = 2048 / 2;
timerTxt.y = 2732 / 2 + 50;
game.addChild(timerTxt);
// Create a text object to display the score
var scoreTxt = new Text2('Defused: 0 of 10', {
	size: 80,
	fill: "#ffffff",
	stroke: "#000000",
	// Add black stroke
	strokeThickness: 5 // Set stroke thickness
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.y += 10; // Lower the text by 10 pixels
LK.gui.top.addChild(scoreTxt);
startTime = Date.now();
gameStarted = true;
// Check the elapsed time on mouse up
game.down = function (x, y, obj) {
	if (gameStarted) {
		elapsedTime = 60 - (Date.now() - startTime) / 1000;
		timerTxt.setText(elapsedTime.toFixed(2));
		if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.01) {
			LK.effects.flashScreen(0xffff00, 500); // Flash yellow for exact time
			LK.getSound('exact').play(); // Play the 'exact' sound
			LK.setScore(10); // Automatically defuse all 10 fuses
			scoreTxt.setText('Fuses: 10 out of 10'); // Update score display
			defuseBar.width = progressBarWidth; // Increment defuse bar to full width
			gameStarted = false; // Stop the game
			LK.getSound('win').play(); // Play the 'win' sound
			// Display 'You Win!' text
			if (!winTxt) {
				winTxt = new Text2('You Win!', {
					size: 200,
					fill: "#ffffff"
				});
				winTxt.anchor.set(0.5, 0.0);
				winTxt.x = 2048 / 2;
				winTxt.y = 300; // Position near the top of the screen
				game.addChild(winTxt);
				// Add winning image to the game
				var winningImage = LK.getAsset('winningImage', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 2,
					scaleY: 2
				});
				game.addChild(winningImage);
			}
			// Display remaining time
			var remainingTimeTxt = new Text2('Remaining Time: ' + elapsedTime.toFixed(2) + 's', {
				size: 100,
				fill: "#ffffff"
			});
			remainingTimeTxt.anchor.set(0.5, 0.0);
			remainingTimeTxt.x = 2048 / 2;
			remainingTimeTxt.y = 700; // Lower the position by 300 pixels
			game.addChild(remainingTimeTxt);
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
		} else if (Math.abs(elapsedTime - Math.round(elapsedTime)) <= 0.1) {
			LK.setScore(LK.getScore() + 1); // Increment score by 1 for each hit
			scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
			if (LK.getScore() >= 10) {
				gameStarted = false; // Stop the game
				LK.setTimeout(function () {
					LK.showGameOver(); // End game
				}, 2000); // Delay by 2000ms or 2 seconds
			}
			LK.effects.flashScreen(0x00ff00, 500); // Flash green to simulate fireworks
			LK.getSound('hit').play(); // Play the 'hit' sound
			LK.setScore(LK.getScore() + 1); // Increment score by 1 for each hit
			scoreTxt.setText('Fuses: ' + LK.getScore() + ' out of 10'); // Update score display
		} else {
			startTime -= 5000; // Adjust startTime to deduct five seconds persistently
			timerTxt.setText(elapsedTime.toFixed(2)); // Update timer display
			LK.effects.flashScreen(0xff0000, 500); // Flash red for negative effect
			LK.getSound('miss').play(); // Play the 'miss' sound
		}
	}
};
// Update the timer every game tick
game.update = function () {
	if (gameStarted) {
		elapsedTime = 60 - (Date.now() - startTime) / 1000;
		timerTxt.setText(elapsedTime.toFixed(2));
		// Update progress bar width
		progressBar.width = progressBarWidth * (1 - elapsedTime / 60);
		// Update defuse bar width with 10 segments
		defuseBar.width = progressBarWidth * (LK.getScore() / 10);
		if (LK.getScore() >= 10) {
			// game.setBackgroundColor(0x00ff00); // Removed green background effect
			if (!winTxt) {
				// Hide dynamite and stopwatch images and text
				dynamiteImage.visible = false;
				stopwatchImage.visible = false;
				timerTxt.visible = false;
				LK.getSound('win').play(); // Play the 'win' sound
				winTxt = new Text2('You Win!', {
					size: 200,
					fill: "#ffffff"
				});
				winTxt.anchor.set(0.5, 0.0);
				winTxt.x = 2048 / 2;
				winTxt.y = 300; // Position near the top of the screen
				game.addChild(winTxt);
				// Display remaining time
				var remainingTimeTxt = new Text2('Remaining Time: ' + elapsedTime.toFixed(2) + 's', {
					size: 100,
					fill: "#ffffff"
				});
				remainingTimeTxt.anchor.set(0.5, 0.0);
				remainingTimeTxt.x = 2048 / 2;
				remainingTimeTxt.y = 700; // Lower the position by 300 pixels
				game.addChild(remainingTimeTxt);
				// Add winning image to the game
				var winningImage = LK.getAsset('winningImage', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 2,
					scaleY: 2
				});
				game.addChild(winningImage);
			}
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
			gameStarted = false;
		} else if (elapsedTime <= 0) {
			if (!loseTxt) {
				// Hide dynamite and stopwatch images and text
				dynamiteImage.visible = false;
				stopwatchImage.visible = false;
				timerTxt.visible = false;
				// Display explosion image in the center of the screen
				var explosionImage = LK.getAsset('explosion', {
					anchorX: 0.5,
					anchorY: 0.5,
					x: 2048 / 2,
					y: 2732 / 2,
					scaleX: 5,
					scaleY: 5
				});
				game.addChild(explosionImage);
				// Display remaining time
				var remainingTimeTxt = new Text2('Remaining Time: 0.00', {
					size: 100,
					fill: "#ffffff"
				});
				remainingTimeTxt.anchor.set(0.5, 0.0);
				remainingTimeTxt.x = 2048 / 2;
				remainingTimeTxt.y = 700; // Lower the position by 300 pixels
				game.addChild(remainingTimeTxt);
				LK.getSound('lose').play(); // Play the 'lose' sound
				loseTxt = new Text2('BOOM!', {
					size: 200,
					fill: "#ffffff"
				});
				loseTxt.anchor.set(0.5, 0.0);
				loseTxt.x = 2048 / 2;
				loseTxt.y = 300; // Position near the top of the screen
				game.addChild(loseTxt);
			}
			LK.setTimeout(function () {
				LK.showGameOver(); // End game
			}, 2000); // Delay by 2000ms or 2 seconds
			gameStarted = false;
		}
	}
};
// Initialize stopwatch image asset
 
 cartoon dynamite. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 explosion. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 8-bit crowd of police and others cheer. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.