/**** 
* Classes
****/ 
var Barman = Container.expand(function () {
	var self = Container.call(this);
	var barmanGraphics = self.attachAsset('sgBarman', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Do any additional update logic here
	};
	self.throwWhiskey = function () {
		// Play sgGrunt sound
		LK.getSound('sgGrunt').play();
		// Simulate wind-up motion
		LK.setTimeout(function () {
			self.x += 10; // Move right
		}, 100);
		LK.setTimeout(function () {
			self.x -= 20; // Move left
		}, 200);
		LK.setTimeout(function () {
			self.x += 10; // Move back to original position
			self.throwBottle(); // Call the throwBottle method
		}, 300);
		// Schedule the next throwWhiskey call
		var nextThrowTime = Math.max(750, Math.random() * 2000 + 1000 - score * 10); // Accelerate over time, minimum 0.75 seconds
		self.throwWhiskeyTimeout = LK.setTimeout(function () {
			if (self.parent) {
				// Check if the barman is still alive
				self.throwWhiskey();
			}
		}, nextThrowTime);
	};
	self.throwBottle = function () {
		var throwTwoBottles = Math.random() < 0.33;
		var whiskey1 = null;
		if (self.parent) {
			whiskey1 = game.addChild(new sgWhiskey());
			whiskey1.x = this.x;
			whiskey1.y = this.y;
		}
		if (throwTwoBottles) {
			var whiskey2 = null;
			if (self.parent) {
				whiskey2 = game.addChild(new sgWhiskey());
				whiskey2.x = this.x + whiskey1.width + 50; // Offset by the width of the first bottle plus a larger gap
				whiskey2.y = this.y;
			}
		}
		// Scale the whiskey bottle by 200% every second until it reaches 800%
		var scaleInterval1 = LK.setInterval(function () {
			if (whiskey1 && whiskey1.scaleX < 8 && whiskey1.scaleY < 8) {
				whiskey1.scaleX *= 2;
				whiskey1.scaleY *= 2;
			} else {
				LK.clearInterval(scaleInterval1);
			}
		}, 1000);
		if (throwTwoBottles) {
			var scaleInterval2 = LK.setInterval(function () {
				if (whiskey2 && whiskey2.scaleX < 8 && whiskey2.scaleY < 8) {
					whiskey2.scaleX *= 2;
					whiskey2.scaleY *= 2;
				} else {
					LK.clearInterval(scaleInterval2);
				}
			}, 1000);
		}
	};
	self.down = function (x, y, obj) {
		// Destroy the barman
		LK.getSound('sgOof').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		self.throwWhiskey();
		// Clear the throwWhiskey timeout
		if (self.throwWhiskeyTimeout) {
			LK.clearTimeout(self.throwWhiskeyTimeout);
		}
		self.destroy();
		// Respawn the barman after 1 to 4 seconds
		var respawnTime = Math.random() * 3000 + 1000;
		LK.setTimeout(spawnSGBarman, respawnTime);
	};
});
// Create a class for the sg_Notes asset
var Note = Container.expand(function () {
	var self = Container.call(this);
	// Attach the sg_Notes asset to the Note instance
	var noteGraphics = self.attachAsset('sg_Notes', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set the initial speed of the note
	self.speed = 1.25;
	// This is automatically called every game tick, if the note is attached!
	self.update = function () {
		self.y -= self.speed;
		// Destroy the note if it goes off screen
		if (self.y < -50) {
			self.destroy();
		}
	};
});
var Poster = Container.expand(function () {
	var self = Container.call(this);
	var posterGraphics = self.attachAsset('sgPoster01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		if (self.y < -50) {
			self.destroy();
		}
	};
	self.down = function (x, y, obj) {
		if (!self.clicked) {
			score += 1;
			scoreTxt.setText(score);
			self.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		self.update = function () {
			velocityY += gravity;
			self.y += velocityY;
			self.x += velocityX;
			self.rotation += angularVelocity;
			if (self.y > 2732 || self.x < 0 || self.x > 2048) {
				self.destroy();
			}
		};
		game.update = this.update.bind(this);
	};
});
var SGBarrel = Container.expand(function () {
	var self = Container.call(this);
	var barrelGraphics = self.attachAsset('sgBarrel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		// Play barreltHit01 sound
		LK.getSound('barreltHit01').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the sgBarrel asset
		this.destroy();
		// Instantiate sgBrokenBarrel at the same position for 1 second
		var sgBrokenBarrel = game.addChild(LK.getAsset('sgBrokenBarrel', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgBrokenBarrel.destroy();
		}, 1000);
		// Respawn the barrel after 1 to 4 seconds
		var respawnTime = Math.random() * 3000 + 1000;
		LK.setTimeout(spawnSGBarrel, respawnTime);
		if (Math.random() < 0.1) {
			spawnSGTarget25(this.x, this.y);
		}
	};
});
var SGBeans01 = Container.expand(function () {
	var self = Container.call(this);
	var beansGraphics = self.attachAsset('sgBeans01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (!this.clicked) {
			score += 3;
			scoreTxt.setText(score);
			this.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		self.update = function () {
			velocityY += gravity;
			self.y += velocityY;
			self.x += velocityX;
			self.rotation += angularVelocity;
			if (self.y > 2732 || self.x < 0 || self.x > 2048) {
				self.destroy();
				respawnSGBeans01();
			}
		};
	};
});
var SGGlassBottle01 = Container.expand(function () {
	var self = Container.call(this);
	var bottleGraphics = self.attachAsset('sgGlassBottle01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (Math.random() > 0.5) {
			LK.getSound('glassHit01').play();
		} else {
			LK.getSound('glassHit02').play();
		}
		this.destroy();
		if (Math.random() < 0.1) {
			spawnSGTarget25(this.x, this.y);
		}
		score += 1;
		scoreTxt.setText(score);
		var sgBrokenGlassBottle01 = game.addChild(LK.getAsset('sgBrokenGlassBottle01', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgBrokenGlassBottle01.destroy();
		}, 500);
		respawnSGGlassBottle01();
	};
});
var SGLady = Container.expand(function () {
	var self = Container.call(this);
	var ladyGraphics = self.attachAsset('sgBarlady', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Do any additional update logic here
	};
	self.throwPie = function () {
		// Simulate wind-up motion
		LK.setTimeout(function () {
			self.x += 10; // Move right
		}, 100);
		LK.setTimeout(function () {
			self.x -= 20; // Move left
		}, 200);
		LK.setTimeout(function () {
			self.x += 10; // Move back to original position
			self.throwPieObject(); // Call the throwPieObject method
		}, 300);
		// Schedule the next throwPie call
		var nextThrowTime = Math.random() * 2000 + 1000; // 1 to 3 seconds
		self.throwPieTimeout = LK.setTimeout(function () {
			if (self.parent) {
				// Check if the lady is still alive
				self.throwPie();
			}
		}, nextThrowTime);
	};
	self.throwPieObject = function () {
		var throwTwoPies = false;
		var pie1 = null;
		if (self.parent) {
			pie1 = game.addChild(new SGPie());
			pie1.x = this.x;
			pie1.y = this.y;
		}
		// Play sgfemaleoof sound when sgBarlady throws a pie
		LK.getSound('sgfemaleoof').play();
		if (throwTwoPies) {
			var pie2 = null;
			if (self.parent) {
				pie2 = game.addChild(new SGPie());
				pie2.x = this.x + pie1.width + 50; // Offset by the width of the first pie plus a larger gap
				pie2.y = this.y;
			}
		}
		// Scale the pie by 200% every second until it reaches 800%
		var scaleInterval1 = LK.setInterval(function () {
			if (pie1 && pie1.scaleX < 8 && pie1.scaleY < 8) {
				pie1.scaleX *= 2;
				pie1.scaleY *= 2;
			} else {
				LK.clearInterval(scaleInterval1);
			}
		}, 1000);
		if (throwTwoPies) {
			var scaleInterval2 = LK.setInterval(function () {
				if (pie2 && pie2.scaleX < 8 && pie2.scaleY < 8) {
					pie2.scaleX *= 2;
					pie2.scaleY *= 2;
				} else {
					LK.clearInterval(scaleInterval2);
				}
			}, 1000);
		}
	};
	self.down = function (x, y, obj) {
		// Play sgfemaleow sound
		LK.getSound('sgfemaleow').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		self.throwPie();
		// Clear the throwPie timeout
		if (self.throwPieTimeout) {
			LK.clearTimeout(self.throwPieTimeout);
		}
		self.destroy();
		// Respawn the lady after 5 seconds
		LK.setTimeout(spawnSGLady, Math.random() * 3000 + 5000);
	};
});
var SGPie = Container.expand(function () {
	var self = Container.call(this);
	var pieGraphics = self.attachAsset('sgPie', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.scaleSpeed = 0.05;
	self.down = function (x, y, obj) {
		// Play sgsquish sound when the pie is clicked
		LK.getSound('sgsquish').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the pie
		self.destroy();
	};
	self.update = function () {
		// Add rotation to the pie
		self.rotation += 0.1;
		// Move towards the player
		self.y -= self.speed;
		// Gradually increase size
		self.scale.x += self.scaleSpeed;
		self.scale.y += self.scaleSpeed;
		// Check if the pie is 4x its original scale
		if (self.scale.x >= 6 && self.scale.y >= 6 && game.children.some(function (child) {
			return child instanceof SGLady;
		})) {
			// Instantiate sgSplash
			var sgSplash = game.addChild(LK.getAsset('sgSplash', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: self.x,
				y: self.y
			}));
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.setScore(score);
			LK.showGameOver();
		}
	};
});
var SGPoster = Container.expand(function () {
	var self = Container.call(this);
	var posterGraphics = self.attachAsset('sgPoster01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (!this.clicked) {
			score += 5;
			scoreTxt.setText(score);
			this.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		this.update = function () {
			velocityY += gravity;
			this.y += velocityY;
			this.x += velocityX;
			this.rotation += angularVelocity;
			if (this.y > 2732 || this.x < 0 || this.x > 2048) {
				this.destroy();
				respawnSGPoster();
			}
		};
	};
});
var SGTarget10 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget10', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		LK.getSound('canHit02').play();
		this.destroy();
		score += 10;
		scoreTxt.setText(score);
		var sgDestroyedTarget10 = game.addChild(LK.getAsset('sgDestroyedTarget10', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgDestroyedTarget10.destroy();
		}, 500);
		respawnSGTarget10();
	};
	self.update = function () {
		this.x += 1 * Math.sin(LK.ticks * 0.05); // Adjust the speed and amplitude as needed
	};
});
var SGTarget5 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget5', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		LK.getSound('canHit02').play();
		this.destroy();
		score += 5;
		scoreTxt.setText(score);
		var sgDestroyedTarget5 = game.addChild(LK.getAsset('sgDestroyedTarget5', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgDestroyedTarget5.destroy();
		}, 500);
		respawnSGTarget5();
	};
	self.update = function () {
		this.y += 1 * Math.sin(LK.ticks * 0.05); // Adjust the speed and amplitude as needed
	};
});
var Target25 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget25', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		this.scale.x = Math.sin(LK.ticks * 0.1);
	};
	self.down = function (x, y, obj) {
		LK.getSound('getSound01').play();
		this.destroy();
		score += 25;
		scoreTxt.setText(score);
		var number25 = new Text2('25', {
			size: 75,
			fill: "#FFD700"
		});
		number25.x = this.x - 40;
		number25.y = this.y - 30;
		game.addChild(number25);
		var flashInterval = LK.setInterval(function () {
			number25.visible = !number25.visible;
		}, 100);
		LK.setTimeout(function () {
			LK.clearInterval(flashInterval);
			number25.visible = true;
		}, 1000);
		LK.setTimeout(function () {
			number25.destroy();
		}, 1000);
	};
});
var Tumbleweed = Container.expand(function () {
	var self = Container.call(this);
	var tumbleweedGraphics = self.attachAsset('sgTumbleWeed', {
		anchorX: 0.5,
		anchorY: 0.4
	});
	self.speedX = 6;
	self.speedY = 0;
	self.rotationSpeed = 0.075;
	self.update = function () {
		self.x += self.speedX;
		self.rotation += self.rotationSpeed;
		if (self.x > 2048) {
			self.destroy();
		}
	};
});
var sgTrainSmoke = Container.expand(function () {
	var self = Container.call(this);
	var smokeGraphics = self.attachAsset('sgTrainSmoke', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -1;
	self.update = function () {
		self.y += self.speed;
	};
	LK.setTimeout(function () {
		self.destroy();
		currentSmoke = null;
	}, 2000);
});
var sgWhiskey = Container.expand(function () {
	var self = Container.call(this);
	var whiskeyGraphics = self.attachAsset('sgWhiskey', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.scaleSpeed = 0.05;
	self.down = function (x, y, obj) {
		// Play a sound when the whiskey bottle is clicked
		LK.getSound('glassHit01').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the whiskey bottle
		self.destroy();
	};
	self.update = function () {
		// Add rotation to the whiskey bottle
		self.rotation += 0.1;
		// Move towards the player
		self.y -= self.speed;
		// Gradually increase size
		self.scale.x += self.scaleSpeed;
		self.scale.y += self.scaleSpeed;
		// Check if the bottle is 4x its original scale
		if (self.scale.x >= 6 && self.scale.y >= 6 && game.children.some(function (child) {
			return child instanceof Barman;
		})) {
			// Instantiate sg_damage
			var sgDamage = game.addChild(LK.getAsset('sgDamage', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: self.x,
				y: self.y
			}));
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.setScore(score);
			LK.showGameOver();
		}
	};
});
/**** 
* Initialize Game
****/ 
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
function spawnSGLady() {
	var sgLady = new SGLady();
	sgLady.throwPie();
	sgLady.x = 1024;
	sgLady.y = 2050;
	game.addChildAt(sgLady, game.getChildIndex(sgBoard));
}
// Initialize and start looping sgSaloonMusic
var sgSaloonMusicPlayed = false;
function startSaloonMusic() {
	if (!sgSaloonMusicPlayed) {
		LK.getSound('sgSaloonMusic').play();
		sgSaloonMusicPlayed = true;
	}
}
// Function to loop the music
// Removed to prevent sgSaloonMusic from playing again
// Start the music 2 seconds after the game initializes
LK.setTimeout(startSaloonMusic, 2000);
// Add continuous score check to spawn Barman when score reaches 100
game.update = function () {
	// Existing update logic
	for (var i = 0; i < game.children.length; i++) {
		if (game.children[i] instanceof sgWhiskey) {
			game.children[i].update();
		}
	}
	// Check if score has reached 100 to spawn Barman
	if (score >= 100 && !barmanCreated) {
		spawnSGBarman();
	}
};
var barmanCreated = false;
function spawnSGBarman() {
	var positions = [{
		x: 1024,
		y: 1385
	}, {
		x: 525,
		y: 1500
	}, {
		x: 1500,
		y: 1525
	}, {
		x: 255,
		y: 1455
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	if (score >= 100) {
		var sgBarman = game.addChild(new Barman());
		sgBarman.throwWhiskey();
		sgBarman.x = randomPosition.x;
		sgBarman.y = randomPosition.y;
		if (!barmanCreated) {
			var sgVerbal = game.addChild(LK.getAsset('sgVerbal', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: sgBarman.x + 100,
				y: sgBarman.y - 200
			}));
			barmanCreated = true;
			LK.setTimeout(function () {
				sgVerbal.destroy();
			}, 1000);
		}
	}
}
var sgToyCowboyClickCounter = 0;
function spawnSGTarget25(x, y) {
	var sgTarget25 = game.addChild(new Target25());
	sgTarget25.x = x;
	sgTarget25.y = y;
}
function respawnSGTarget5() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGTarget5, respawnTime);
}
function spawnSGTarget5() {
	var positions = [{
		x: 700 / 2,
		y: 2350 / 2
	}, {
		x: 2050 / 2,
		y: 3300 / 2
	}, {
		x: 2700 / 2,
		y: 2700 / 2
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgTarget5 = game.addChild(new SGTarget5());
	sgTarget5.x = randomPosition.x;
	sgTarget5.y = randomPosition.y;
}
function respawnSGTarget10() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGTarget10, respawnTime);
}
function spawnSGTarget10() {
	var positions = [{
		x: 1625,
		y: 1425
	}, {
		x: 525,
		y: 1765
	}, {
		x: 995,
		y: 935
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgTarget10 = game.addChild(new SGTarget10());
	sgTarget10.x = randomPosition.x;
	sgTarget10.y = randomPosition.y;
}
var respawnTimeout = null;
function respawnSGBeans01() {
	if (respawnTimeout) {
		return;
	}
	var respawnTime = Math.random() * 3000 + 1000;
	respawnTimeout = LK.setTimeout(function () {
		spawnSGBeans01();
		respawnTimeout = null; // Reset the timeout tracker
	}, respawnTime);
}
function spawnSGBeans01() {
	var positions = [{
		x: 2048 / 2 - 100,
		y: 2975 / 2
	}, {
		x: 2048 / 2 - 400,
		y: 2975 / 2 + 125
	}, {
		x: 2048 / 2 + 800,
		y: 2975 / 2 + 225
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgBeans01 = game.addChild(new SGBeans01());
	sgBeans01.x = randomPosition.x;
	sgBeans01.y = randomPosition.y;
}
function spawnSGGlassBottle01() {
	var positions = [{
		x: 2848 / 2 - 100,
		y: 2732 / 2 + 105
	}, {
		x: 2848 / 2 + 320,
		y: 2732 / 2 + 175
	}, {
		x: 2848 / 2 - 920,
		y: 2732 / 2 + 225
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgGlassBottle01 = game.addChild(new SGGlassBottle01());
	sgGlassBottle01.x = randomPosition.x;
	sgGlassBottle01.y = randomPosition.y;
}
function respawnSGGlassBottle01() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGGlassBottle01, respawnTime);
}
// Initialize the sgBackground01 asset on screen
var sgBackground01 = game.addChild(LK.getAsset('sgBackground01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2025 / 2,
	y: 2725 / 2
}));
var currentSmoke = null;
// Initialize the sgTrain01 asset on screen
var sgTrain01 = game.addChild(LK.getAsset('sgTrain01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 125,
	y: 1910
}));
// Initialize the sgToyCowboy asset on screen
var sgToyCowboy = game.addChild(LK.getAsset('sgToyCowboy', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 600,
	y: 965
}));
// Add a click event to the sgToyCowboy asset
sgToyCowboy.down = function (x, y, obj) {
	sgToyCowboyClickCounter++;
	if (sgToyCowboyClickCounter < 2) {
		// Add fading out effect to sgToyCowboy
		var fadeOut = function fadeOut() {
			if (sgToyCowboy.alpha > 0) {
				sgToyCowboy.alpha -= 0.05;
				LK.setTimeout(fadeOut, 50); // Reduce alpha every 50ms
			} else {
				sgToyCowboy.destroy();
			}
		};
		LK.setTimeout(fadeOut, 1000); // Start fade out after 1 seconds
		// Create sgCloudSmoke at the position of sgToyCowboy
		var sgCloudSmoke = game.addChild(LK.getAsset('sgCloudSmoke', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x + 50,
			y: this.y - 20
		}));
		// Create sgDustStorm at the position of sgTargetDummy
		var sgDustStorm = game.addChild(LK.getAsset('sgDustStorm', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: sgTargetDummy.x,
			y: sgTargetDummy.y
		}));
		// Play sgRicochet sound
		LK.getSound('sgRicochet').play();
		// Spawn sgTarget25 on sgDustStorm
		var sgTarget25 = game.addChild(new Target25());
		sgTarget25.x = sgDustStorm.x;
		sgTarget25.y = sgDustStorm.y;
		// Destroy sgCloudSmoke and sgDustStorm after 1 second
		LK.setTimeout(function () {
			sgCloudSmoke.destroy();
			sgDustStorm.destroy();
		}, 1000);
		// Add falling behavior to sgTargetDummy similar to sgPoster01
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		sgTargetDummy.update = function () {
			velocityY += gravity;
			sgTargetDummy.y += velocityY;
			sgTargetDummy.x += velocityX;
			sgTargetDummy.rotation += angularVelocity;
			if (sgTargetDummy.y > 2732 || sgTargetDummy.x < 0 || sgTargetDummy.x > 2048) {
				sgTargetDummy.destroy();
			}
		};
		// Ensure the update loop for sign01 is not interrupted
		var originalUpdate = game.update;
		game.update = function () {
			sgTargetDummy.update();
			if (originalUpdate) {
				originalUpdate();
			}
		};
	}
};
// Initialize the sgBoard asset on screen
var sgBoard = game.addChild(LK.getAsset('sgBoard', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1024,
	y: 2366
}));
// Initialize sgLady on screen
LK.setTimeout(spawnSGLady, Math.random() * 3000 + 5000);
// Initialize the sgTargetDummy asset on screen
var sgTargetDummy = game.addChild(LK.getAsset('sgTargetDummy', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1450,
	y: 970
}));
// Add a flag to track if sgTrain01 has been clicked
var sgTrain01Clicked = false;
// Initialize the sgTrainWagon01 asset and parent it to sgTrain01
var sgTrainWagons = [];
for (var i = 0; i < 8; i++) {
	var sgTrainWagon = sgTrain01.addChild(LK.getAsset('sgTrainWagon01', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: sgTrain01.width / 2 - 300 - i * 220,
		// Adjust position for each wagon
		y: sgTrain01.height / 2 - 70
	}));
	sgTrainWagons.push(sgTrainWagon);
}
// Add a click event to the sgTrain01 asset
sgTrain01.down = function (x, y, obj) {
	// Check if sgTrain01 has already been clicked
	if (sgTrain01Clicked) {
		return;
	}
	sgTrain01Clicked = true;
	// Check if there is already an sgTrainSmoke instance
	if (currentSmoke) {
		return;
	}
	// Play sgTrainSound01 sound
	LK.getSound('sgTrainSound01').play();
	// Initialize sgSmoke in the center of sgTrain01
	var sgSmoke = new sgTrainSmoke();
	sgSmoke.x = sgTrain01.x + 70;
	sgSmoke.y = sgTrain01.y - 100;
	game.addChild(sgSmoke);
	currentSmoke = sgSmoke;
	// Play sgTrainSound02 after 2 seconds
	LK.setTimeout(function () {
		LK.getSound('sgTrainsSound02').play();
	}, 2000);
	// Move sgTrain01 horizontally to the right until it is near the border of the playspace
	var moveTrain = function moveTrain() {
		if (sgTrain01.x < 1825 - sgTrain01.width / 2) {
			sgTrain01.x += 7;
			LK.setTimeout(moveTrain, 16); // Move every 16ms (~60 FPS)
		} else {
			// Spawn three sgTarget25 on the visible train carts
			for (var i = 0; i < 3; i++) {
				var target25 = new Target25();
				target25.x = sgTrainWagons[i].x + sgTrain01.x + -400;
				target25.y = sgTrainWagons[i].y + sgTrain01.y;
				game.addChild(target25);
			}
			// After 2 seconds, fade out the train
			LK.setTimeout(function () {
				var fadeOut = function fadeOut() {
					if (sgTrain01.alpha > 0) {
						sgTrain01.alpha -= 0.05;
						LK.setTimeout(fadeOut, 50); // Reduce alpha every 50ms
					} else {
						sgTrain01.destroy();
					}
				};
				fadeOut();
			}, 2000);
		}
	};
	moveTrain();
};
// Initialize the sgBoard asset on screen
var sgBoard = game.addChild(LK.getAsset('sgBoard', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1024,
	// Center of the screen horizontally
	y: 2366 // Center of the screen vertically
}));
// Initialize the saloonPiano asset on screen
var saloonPiano = game.addChild(LK.getAsset('saloonPiano', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 3275 / 2,
	y: 3800 / 2
}));
// Add a click event to the piano
saloonPiano.down = function (x, y, obj) {
	// If the piano jingle is not playing, play it
	if (!isPianoPlaying) {
		isPianoPlaying = true;
		LK.getSound('saloonPianoJingle01').play();
		// After 5 seconds, set isPianoPlaying to false and hide sg_notes
		LK.setTimeout(function () {
			isPianoPlaying = false;
			note.visible = false;
		}, 3250);
		// Create sg_Notes above saloonPiano when piano jingle is playing
		var note = new Note();
		note.x = saloonPiano.x;
		note.y = saloonPiano.y - 100;
		game.addChild(note);
	}
};
// Initialize the sgBarrel asset on screen
function spawnSGBarrel() {
	var positions = [{
		x: 400,
		y: 1800
	}, {
		x: 1325,
		y: 1800
	}, {
		x: 1750,
		y: 2200
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgBarrel = game.addChild(new SGBarrel());
	sgBarrel.x = randomPosition.x;
	sgBarrel.y = randomPosition.y;
}
spawnSGBarrel();
// Initialize the sgFrame01 asset on screen
var sgFrame01 = game.addChild(LK.getAsset('sgFrame01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2600 / 2
}));
// Initialize the sgBulletHole01 asset on screen
var sgBulletHole01 = game.addChild(LK.getAsset('sgBulletHole01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	// Center of the screen horizontally
	y: 1800 // Center of the screen vertically
}));
// Initialize the sgInGrain asset on screen
var sgInGrain = game.addChild(LK.getAsset('sgIngrain', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	y: 320
}));
// Initialize the sgVines asset on screen
var sgVines = game.addChild(LK.getAsset('sgVines', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	// Center of the screen horizontally
	y: 150 // Center of the screen vertically
}));
// Initialize the sgSpeechBubble01 asset on screen for 2 second and then destroy it after a delay of 1 seconds
LK.setTimeout(function () {
	var sgSpeechBubble01 = game.addChild(LK.getAsset('sgSpeechBubble01', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: 900,
		// Center of the screen horizontally
		y: 1966 // Center of the screen vertically
	}));
	LK.setTimeout(function () {
		LK.setTimeout(function () {
			sgSpeechBubble01.destroy();
		}, 1000);
		LK.getSound('sgYeehaw').play();
	}, 500);
}, 1000);
// Initialize the sgPoster01 asset on screen
function spawnSGPoster() {
	var positions = [{
		x: 385,
		y: 1425
	}, {
		x: 1585,
		y: 1275
	}, {
		x: 250,
		y: 1725
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgPoster = game.addChild(new SGPoster());
	sgPoster.x = randomPosition.x;
	sgPoster.y = randomPosition.y;
}
function respawnSGPoster() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGPoster, respawnTime);
}
spawnSGPoster();
function spawnTumbleweed() {
	var tumbleweed = new Tumbleweed();
	tumbleweed.x = 100;
	tumbleweed.y = 2800;
	game.addChild(tumbleweed);
	var nextSpawnTime = Math.random() * 20000 + 30000; // 20 to 30 seconds
	LK.setTimeout(spawnTumbleweed, nextSpawnTime);
}
LK.setTimeout(spawnTumbleweed, 10000);
// Initialize the sgDesertRock asset on screen
var sgDesertRock = game.addChild(LK.getAsset('sgDesertRock', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1500,
	y: 2900
}));
// Initialize the sgGecko asset on screen after sgDesertRock
var sgGecko = game.addChild(LK.getAsset('sgGecko', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1500,
	y: 2375
}));
// Add a click event to the sgGecko asset
sgGecko.down = function (x, y, obj) {
	// Play sgGeckoNoise sound
	LK.getSound('sgGeckoNoise').play();
	// Destroy the sgGecko asset
	this.destroy();
	// Instantiate sgCloudPuff at the same position
	var sgCloudPuff = game.addChild(LK.getAsset('sgCloudPuff', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: this.x - 25,
		y: this.y
	}));
	// After 1 second, destroy sgCloudPuff and instantiate sgTarget100
	LK.setTimeout(function () {
		sgCloudPuff.destroy();
		var sgTarget100 = game.addChild(LK.getAsset('sgTarget100', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: sgCloudPuff.x,
			y: sgCloudPuff.y
		}));
		// Add pulsing effect to sgTarget100
		sgTarget100.update = function () {
			this.scale.x = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
			this.scale.y = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
		};
		// Add a click event to the sgTarget100 asset to destroy it and replace it with a flashing number 100 for 1 second
		sgTarget100.down = function (x, y, obj) {
			// Play getSound02 sound
			LK.getSound('getSound02').play();
			// Destroy the sgTarget100 asset
			this.destroy();
			// Add 100 to the score
			score += 100;
			scoreTxt.setText(score);
			// Create a text asset for the number 100
			var number100 = new Text2('100', {
				size: 50,
				fill: "#00FF00" // Green color
			});
			// Position the number 100 at the same position as the sgTarget100 asset
			number100.x = this.x - 50;
			number100.y = this.y - 30;
			// Add the number 100 to the game
			game.addChild(number100);
			// Make the number 100 flash for 1 second
			var flashInterval = LK.setInterval(function () {
				number100.visible = !number100.visible;
			}, 100);
			LK.setTimeout(function () {
				LK.clearInterval(flashInterval);
				number100.visible = true;
			}, 1000);
			// After 1 second, destroy the number 100
			LK.setTimeout(function () {
				number100.destroy();
			}, 1000);
		};
	}, 1000);
};
// Initialize the sgTarget100 asset on screen
var sgTarget100 = game.addChild(LK.getAsset('sgTarget100', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1000,
	y: 350
}));
// Add pulsing effect to sgTarget100
sgTarget100.update = function () {
	this.scale.x = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
	this.scale.y = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
};
// Add a click event to the sgTarget100 asset to destroy it and replace it with a flashing number 100 for 1 second
sgTarget100.down = function (x, y, obj) {
	// Play getSound02 sound
	LK.getSound('getSound02').play();
	// Destroy the sgTarget100 asset
	this.destroy();
	// Add 100 to the score
	score += 100;
	scoreTxt.setText(score);
	// Create a text asset for the number 100
	var number100 = new Text2('100', {
		size: 50,
		fill: "#00FF00" // Green color
	});
	// Position the number 100 at the same position as the sgTarget100 asset
	number100.x = this.x - 50;
	number100.y = this.y - 30;
	// Add the number 100 to the game
	game.addChild(number100);
	// Make the number 100 flash for 1 second
	var flashInterval = LK.setInterval(function () {
		number100.visible = !number100.visible;
	}, 100);
	LK.setTimeout(function () {
		LK.clearInterval(flashInterval);
		number100.visible = true;
	}, 1000);
	// After 1 second, destroy the number 100
	LK.setTimeout(function () {
		number100.destroy();
	}, 1000);
};
// Initialize variables
var scoreTxt;
var score = 0;
var barmanCreated = false;
var isPianoPlaying = false;
// Initialize the sgSign01 asset on screen and center it at the top
var sgSign01 = LK.gui.top.addChild(LK.getAsset('sg_Sign01', {
	anchorX: 0.5,
	anchorY: 0,
	x: 0,
	y: -150
}));
// Add a click event to the sg_Sign01 asset to make it swing for 5 seconds
sgSign01.down = function (x, y, obj) {
	// Check if the sign is already swinging
	if (this.isSwinging) {
		return;
	}
	this.isSwinging = true;
	var swingDuration = 5000; // 5 seconds in milliseconds
	var swingFrequency = 1 / swingDuration; // Frequency of the oscillation
	var swingAmplitude = 1; // The maximum rotation angle
	var startTime = Date.now();
	// Play chainNoises sound once at the start of the swinging
	LK.getSound('chainNoises').play();
	this.update = function () {
		var currentTime = Date.now();
		var timePassed = currentTime - startTime;
		if (timePassed < swingDuration) {
			this.rotation = swingAmplitude * Math.sin(2 * Math.PI * swingFrequency * timePassed);
		} else {
			this.rotation = 0;
			this.update = function () {};
			this.isSwinging = false;
		}
	};
	game.update = this.update.bind(this);
};
spawnSGBeans01();
// Initialize the sgCactus asset on screen
var sgCactus = game.addChild(LK.getAsset('sgCactus', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2000,
	y: 2500
}));
// Initialize the sgCharacter asset on screen
var sgCharacter = game.addChild(LK.getAsset('sgCharacter', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 800 / 2,
	y: 4800 / 2
}));
// Initialize the sg_SignScore asset in the center of the playspace
var sgSignScore = game.addChild(LK.getAsset('sg_SignScore', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2 - 740,
	y: 2732 / 2 + 1200
}));
// Add a click event to the sgCharacter asset to trigger game over
sgCharacter.down = function (x, y, obj) {
	LK.effects.flashScreen(0xff0000, 1000);
	LK.setTimeout(function () {
		LK.showGameOver();
	}, 250);
};
// Create score text
scoreTxt = new Text2('0', {
	size: 127.5,
	fill: "#654321"
});
scoreTxt.anchor.set(0.5, 0);
game.addChild(scoreTxt);
scoreTxt.x = sgCharacter.x + 92;
scoreTxt.y = sgCharacter.y + 95;
spawnSGGlassBottle01();
// Initialize the sgTarget5 asset on screen
spawnSGTarget5();
// Initialize the sgTarget10 asset on screen
spawnSGTarget10();
// Handle game updates
sgTarget100.update();
for (var i = 0; i < game.children.length; i++) {
	if (game.children[i] instanceof sgWhiskey) {
		game.children[i].update();
	}
}
// Check if score has reached 100 to spawn Barman
if (score >= 100 && !barmanCreated) {
	spawnSGBarman();
}
// Add a click event to the game to create a sgCrosshair asset at the clicked position
game.down = function (x, y, obj) {
	// Create a sgCrosshair asset at the clicked position
	var sgCrosshair = game.addChild(LK.getAsset('sgCrosshair', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: x,
		y: y
	}));
	// Play bulletHit01 or bulletHit02 sound randomly
	if (Math.random() > 0) {
		LK.getSound('bulletHit01').play();
	}
	// After 0.5 second, destroy the sgCrosshair asset
	LK.setTimeout(function () {
		sgCrosshair.destroy();
	}, 500);
};
;
; /**** 
* Classes
****/ 
var Barman = Container.expand(function () {
	var self = Container.call(this);
	var barmanGraphics = self.attachAsset('sgBarman', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Do any additional update logic here
	};
	self.throwWhiskey = function () {
		// Play sgGrunt sound
		LK.getSound('sgGrunt').play();
		// Simulate wind-up motion
		LK.setTimeout(function () {
			self.x += 10; // Move right
		}, 100);
		LK.setTimeout(function () {
			self.x -= 20; // Move left
		}, 200);
		LK.setTimeout(function () {
			self.x += 10; // Move back to original position
			self.throwBottle(); // Call the throwBottle method
		}, 300);
		// Schedule the next throwWhiskey call
		var nextThrowTime = Math.max(750, Math.random() * 2000 + 1000 - score * 10); // Accelerate over time, minimum 0.75 seconds
		self.throwWhiskeyTimeout = LK.setTimeout(function () {
			if (self.parent) {
				// Check if the barman is still alive
				self.throwWhiskey();
			}
		}, nextThrowTime);
	};
	self.throwBottle = function () {
		var throwTwoBottles = Math.random() < 0.33;
		var whiskey1 = null;
		if (self.parent) {
			whiskey1 = game.addChild(new sgWhiskey());
			whiskey1.x = this.x;
			whiskey1.y = this.y;
		}
		if (throwTwoBottles) {
			var whiskey2 = null;
			if (self.parent) {
				whiskey2 = game.addChild(new sgWhiskey());
				whiskey2.x = this.x + whiskey1.width + 50; // Offset by the width of the first bottle plus a larger gap
				whiskey2.y = this.y;
			}
		}
		// Scale the whiskey bottle by 200% every second until it reaches 800%
		var scaleInterval1 = LK.setInterval(function () {
			if (whiskey1 && whiskey1.scaleX < 8 && whiskey1.scaleY < 8) {
				whiskey1.scaleX *= 2;
				whiskey1.scaleY *= 2;
			} else {
				LK.clearInterval(scaleInterval1);
			}
		}, 1000);
		if (throwTwoBottles) {
			var scaleInterval2 = LK.setInterval(function () {
				if (whiskey2 && whiskey2.scaleX < 8 && whiskey2.scaleY < 8) {
					whiskey2.scaleX *= 2;
					whiskey2.scaleY *= 2;
				} else {
					LK.clearInterval(scaleInterval2);
				}
			}, 1000);
		}
	};
	self.down = function (x, y, obj) {
		// Destroy the barman
		LK.getSound('sgOof').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		self.throwWhiskey();
		// Clear the throwWhiskey timeout
		if (self.throwWhiskeyTimeout) {
			LK.clearTimeout(self.throwWhiskeyTimeout);
		}
		self.destroy();
		// Respawn the barman after 1 to 4 seconds
		var respawnTime = Math.random() * 3000 + 1000;
		LK.setTimeout(spawnSGBarman, respawnTime);
	};
});
// Create a class for the sg_Notes asset
var Note = Container.expand(function () {
	var self = Container.call(this);
	// Attach the sg_Notes asset to the Note instance
	var noteGraphics = self.attachAsset('sg_Notes', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Set the initial speed of the note
	self.speed = 1.25;
	// This is automatically called every game tick, if the note is attached!
	self.update = function () {
		self.y -= self.speed;
		// Destroy the note if it goes off screen
		if (self.y < -50) {
			self.destroy();
		}
	};
});
var Poster = Container.expand(function () {
	var self = Container.call(this);
	var posterGraphics = self.attachAsset('sgPoster01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		if (self.y < -50) {
			self.destroy();
		}
	};
	self.down = function (x, y, obj) {
		if (!self.clicked) {
			score += 1;
			scoreTxt.setText(score);
			self.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		self.update = function () {
			velocityY += gravity;
			self.y += velocityY;
			self.x += velocityX;
			self.rotation += angularVelocity;
			if (self.y > 2732 || self.x < 0 || self.x > 2048) {
				self.destroy();
			}
		};
		game.update = this.update.bind(this);
	};
});
var SGBarrel = Container.expand(function () {
	var self = Container.call(this);
	var barrelGraphics = self.attachAsset('sgBarrel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		// Play barreltHit01 sound
		LK.getSound('barreltHit01').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the sgBarrel asset
		this.destroy();
		// Instantiate sgBrokenBarrel at the same position for 1 second
		var sgBrokenBarrel = game.addChild(LK.getAsset('sgBrokenBarrel', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgBrokenBarrel.destroy();
		}, 1000);
		// Respawn the barrel after 1 to 4 seconds
		var respawnTime = Math.random() * 3000 + 1000;
		LK.setTimeout(spawnSGBarrel, respawnTime);
		if (Math.random() < 0.1) {
			spawnSGTarget25(this.x, this.y);
		}
	};
});
var SGBeans01 = Container.expand(function () {
	var self = Container.call(this);
	var beansGraphics = self.attachAsset('sgBeans01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (!this.clicked) {
			score += 3;
			scoreTxt.setText(score);
			this.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		self.update = function () {
			velocityY += gravity;
			self.y += velocityY;
			self.x += velocityX;
			self.rotation += angularVelocity;
			if (self.y > 2732 || self.x < 0 || self.x > 2048) {
				self.destroy();
				respawnSGBeans01();
			}
		};
	};
});
var SGGlassBottle01 = Container.expand(function () {
	var self = Container.call(this);
	var bottleGraphics = self.attachAsset('sgGlassBottle01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (Math.random() > 0.5) {
			LK.getSound('glassHit01').play();
		} else {
			LK.getSound('glassHit02').play();
		}
		this.destroy();
		if (Math.random() < 0.1) {
			spawnSGTarget25(this.x, this.y);
		}
		score += 1;
		scoreTxt.setText(score);
		var sgBrokenGlassBottle01 = game.addChild(LK.getAsset('sgBrokenGlassBottle01', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgBrokenGlassBottle01.destroy();
		}, 500);
		respawnSGGlassBottle01();
	};
});
var SGLady = Container.expand(function () {
	var self = Container.call(this);
	var ladyGraphics = self.attachAsset('sgBarlady', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Do any additional update logic here
	};
	self.throwPie = function () {
		// Simulate wind-up motion
		LK.setTimeout(function () {
			self.x += 10; // Move right
		}, 100);
		LK.setTimeout(function () {
			self.x -= 20; // Move left
		}, 200);
		LK.setTimeout(function () {
			self.x += 10; // Move back to original position
			self.throwPieObject(); // Call the throwPieObject method
		}, 300);
		// Schedule the next throwPie call
		var nextThrowTime = Math.random() * 2000 + 1000; // 1 to 3 seconds
		self.throwPieTimeout = LK.setTimeout(function () {
			if (self.parent) {
				// Check if the lady is still alive
				self.throwPie();
			}
		}, nextThrowTime);
	};
	self.throwPieObject = function () {
		var throwTwoPies = false;
		var pie1 = null;
		if (self.parent) {
			pie1 = game.addChild(new SGPie());
			pie1.x = this.x;
			pie1.y = this.y;
		}
		// Play sgfemaleoof sound when sgBarlady throws a pie
		LK.getSound('sgfemaleoof').play();
		if (throwTwoPies) {
			var pie2 = null;
			if (self.parent) {
				pie2 = game.addChild(new SGPie());
				pie2.x = this.x + pie1.width + 50; // Offset by the width of the first pie plus a larger gap
				pie2.y = this.y;
			}
		}
		// Scale the pie by 200% every second until it reaches 800%
		var scaleInterval1 = LK.setInterval(function () {
			if (pie1 && pie1.scaleX < 8 && pie1.scaleY < 8) {
				pie1.scaleX *= 2;
				pie1.scaleY *= 2;
			} else {
				LK.clearInterval(scaleInterval1);
			}
		}, 1000);
		if (throwTwoPies) {
			var scaleInterval2 = LK.setInterval(function () {
				if (pie2 && pie2.scaleX < 8 && pie2.scaleY < 8) {
					pie2.scaleX *= 2;
					pie2.scaleY *= 2;
				} else {
					LK.clearInterval(scaleInterval2);
				}
			}, 1000);
		}
	};
	self.down = function (x, y, obj) {
		// Play sgfemaleow sound
		LK.getSound('sgfemaleow').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		self.throwPie();
		// Clear the throwPie timeout
		if (self.throwPieTimeout) {
			LK.clearTimeout(self.throwPieTimeout);
		}
		self.destroy();
		// Respawn the lady after 5 seconds
		LK.setTimeout(spawnSGLady, Math.random() * 3000 + 5000);
	};
});
var SGPie = Container.expand(function () {
	var self = Container.call(this);
	var pieGraphics = self.attachAsset('sgPie', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.scaleSpeed = 0.05;
	self.down = function (x, y, obj) {
		// Play sgsquish sound when the pie is clicked
		LK.getSound('sgsquish').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the pie
		self.destroy();
	};
	self.update = function () {
		// Add rotation to the pie
		self.rotation += 0.1;
		// Move towards the player
		self.y -= self.speed;
		// Gradually increase size
		self.scale.x += self.scaleSpeed;
		self.scale.y += self.scaleSpeed;
		// Check if the pie is 4x its original scale
		if (self.scale.x >= 6 && self.scale.y >= 6 && game.children.some(function (child) {
			return child instanceof SGLady;
		})) {
			// Instantiate sgSplash
			var sgSplash = game.addChild(LK.getAsset('sgSplash', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: self.x,
				y: self.y
			}));
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.setScore(score);
			LK.showGameOver();
		}
	};
});
var SGPoster = Container.expand(function () {
	var self = Container.call(this);
	var posterGraphics = self.attachAsset('sgPoster01', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		if (!this.clicked) {
			score += 5;
			scoreTxt.setText(score);
			this.clicked = true;
		}
		if (Math.random() > 0.5) {
			LK.getSound('canHit').play();
		} else {
			LK.getSound('canHit02').play();
		}
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		this.update = function () {
			velocityY += gravity;
			this.y += velocityY;
			this.x += velocityX;
			this.rotation += angularVelocity;
			if (this.y > 2732 || this.x < 0 || this.x > 2048) {
				this.destroy();
				respawnSGPoster();
			}
		};
	};
});
var SGTarget10 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget10', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		LK.getSound('canHit02').play();
		this.destroy();
		score += 10;
		scoreTxt.setText(score);
		var sgDestroyedTarget10 = game.addChild(LK.getAsset('sgDestroyedTarget10', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgDestroyedTarget10.destroy();
		}, 500);
		respawnSGTarget10();
	};
	self.update = function () {
		this.x += 1 * Math.sin(LK.ticks * 0.05); // Adjust the speed and amplitude as needed
	};
});
var SGTarget5 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget5', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.down = function (x, y, obj) {
		LK.getSound('canHit02').play();
		this.destroy();
		score += 5;
		scoreTxt.setText(score);
		var sgDestroyedTarget5 = game.addChild(LK.getAsset('sgDestroyedTarget5', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x,
			y: this.y
		}));
		LK.setTimeout(function () {
			sgDestroyedTarget5.destroy();
		}, 500);
		respawnSGTarget5();
	};
	self.update = function () {
		this.y += 1 * Math.sin(LK.ticks * 0.05); // Adjust the speed and amplitude as needed
	};
});
var Target25 = Container.expand(function () {
	var self = Container.call(this);
	var targetGraphics = self.attachAsset('sgTarget25', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		this.scale.x = Math.sin(LK.ticks * 0.1);
	};
	self.down = function (x, y, obj) {
		LK.getSound('getSound01').play();
		this.destroy();
		score += 25;
		scoreTxt.setText(score);
		var number25 = new Text2('25', {
			size: 75,
			fill: "#FFD700"
		});
		number25.x = this.x - 40;
		number25.y = this.y - 30;
		game.addChild(number25);
		var flashInterval = LK.setInterval(function () {
			number25.visible = !number25.visible;
		}, 100);
		LK.setTimeout(function () {
			LK.clearInterval(flashInterval);
			number25.visible = true;
		}, 1000);
		LK.setTimeout(function () {
			number25.destroy();
		}, 1000);
	};
});
var Tumbleweed = Container.expand(function () {
	var self = Container.call(this);
	var tumbleweedGraphics = self.attachAsset('sgTumbleWeed', {
		anchorX: 0.5,
		anchorY: 0.4
	});
	self.speedX = 6;
	self.speedY = 0;
	self.rotationSpeed = 0.075;
	self.update = function () {
		self.x += self.speedX;
		self.rotation += self.rotationSpeed;
		if (self.x > 2048) {
			self.destroy();
		}
	};
});
var sgTrainSmoke = Container.expand(function () {
	var self = Container.call(this);
	var smokeGraphics = self.attachAsset('sgTrainSmoke', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = -1;
	self.update = function () {
		self.y += self.speed;
	};
	LK.setTimeout(function () {
		self.destroy();
		currentSmoke = null;
	}, 2000);
});
var sgWhiskey = Container.expand(function () {
	var self = Container.call(this);
	var whiskeyGraphics = self.attachAsset('sgWhiskey', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.speed = 5;
	self.scaleSpeed = 0.05;
	self.down = function (x, y, obj) {
		// Play a sound when the whiskey bottle is clicked
		LK.getSound('glassHit01').play();
		// Add 1 to the score
		score += 1;
		scoreTxt.setText(score);
		// Destroy the whiskey bottle
		self.destroy();
	};
	self.update = function () {
		// Add rotation to the whiskey bottle
		self.rotation += 0.1;
		// Move towards the player
		self.y -= self.speed;
		// Gradually increase size
		self.scale.x += self.scaleSpeed;
		self.scale.y += self.scaleSpeed;
		// Check if the bottle is 4x its original scale
		if (self.scale.x >= 6 && self.scale.y >= 6 && game.children.some(function (child) {
			return child instanceof Barman;
		})) {
			// Instantiate sg_damage
			var sgDamage = game.addChild(LK.getAsset('sgDamage', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: self.x,
				y: self.y
			}));
			// Trigger game over
			LK.effects.flashScreen(0xff0000, 1000);
			LK.setScore(score);
			LK.showGameOver();
		}
	};
});
/**** 
* Initialize Game
****/ 
//<Assets used in the game will automatically appear here>
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
function spawnSGLady() {
	var sgLady = new SGLady();
	sgLady.throwPie();
	sgLady.x = 1024;
	sgLady.y = 2050;
	game.addChildAt(sgLady, game.getChildIndex(sgBoard));
}
// Initialize and start looping sgSaloonMusic
var sgSaloonMusicPlayed = false;
function startSaloonMusic() {
	if (!sgSaloonMusicPlayed) {
		LK.getSound('sgSaloonMusic').play();
		sgSaloonMusicPlayed = true;
	}
}
// Function to loop the music
// Removed to prevent sgSaloonMusic from playing again
// Start the music 2 seconds after the game initializes
LK.setTimeout(startSaloonMusic, 2000);
// Add continuous score check to spawn Barman when score reaches 100
game.update = function () {
	// Existing update logic
	for (var i = 0; i < game.children.length; i++) {
		if (game.children[i] instanceof sgWhiskey) {
			game.children[i].update();
		}
	}
	// Check if score has reached 100 to spawn Barman
	if (score >= 100 && !barmanCreated) {
		spawnSGBarman();
	}
};
var barmanCreated = false;
function spawnSGBarman() {
	var positions = [{
		x: 1024,
		y: 1385
	}, {
		x: 525,
		y: 1500
	}, {
		x: 1500,
		y: 1525
	}, {
		x: 255,
		y: 1455
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	if (score >= 100) {
		var sgBarman = game.addChild(new Barman());
		sgBarman.throwWhiskey();
		sgBarman.x = randomPosition.x;
		sgBarman.y = randomPosition.y;
		if (!barmanCreated) {
			var sgVerbal = game.addChild(LK.getAsset('sgVerbal', {
				anchorX: 0.5,
				anchorY: 0.5,
				x: sgBarman.x + 100,
				y: sgBarman.y - 200
			}));
			barmanCreated = true;
			LK.setTimeout(function () {
				sgVerbal.destroy();
			}, 1000);
		}
	}
}
var sgToyCowboyClickCounter = 0;
function spawnSGTarget25(x, y) {
	var sgTarget25 = game.addChild(new Target25());
	sgTarget25.x = x;
	sgTarget25.y = y;
}
function respawnSGTarget5() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGTarget5, respawnTime);
}
function spawnSGTarget5() {
	var positions = [{
		x: 700 / 2,
		y: 2350 / 2
	}, {
		x: 2050 / 2,
		y: 3300 / 2
	}, {
		x: 2700 / 2,
		y: 2700 / 2
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgTarget5 = game.addChild(new SGTarget5());
	sgTarget5.x = randomPosition.x;
	sgTarget5.y = randomPosition.y;
}
function respawnSGTarget10() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGTarget10, respawnTime);
}
function spawnSGTarget10() {
	var positions = [{
		x: 1625,
		y: 1425
	}, {
		x: 525,
		y: 1765
	}, {
		x: 995,
		y: 935
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgTarget10 = game.addChild(new SGTarget10());
	sgTarget10.x = randomPosition.x;
	sgTarget10.y = randomPosition.y;
}
var respawnTimeout = null;
function respawnSGBeans01() {
	if (respawnTimeout) {
		return;
	}
	var respawnTime = Math.random() * 3000 + 1000;
	respawnTimeout = LK.setTimeout(function () {
		spawnSGBeans01();
		respawnTimeout = null; // Reset the timeout tracker
	}, respawnTime);
}
function spawnSGBeans01() {
	var positions = [{
		x: 2048 / 2 - 100,
		y: 2975 / 2
	}, {
		x: 2048 / 2 - 400,
		y: 2975 / 2 + 125
	}, {
		x: 2048 / 2 + 800,
		y: 2975 / 2 + 225
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgBeans01 = game.addChild(new SGBeans01());
	sgBeans01.x = randomPosition.x;
	sgBeans01.y = randomPosition.y;
}
function spawnSGGlassBottle01() {
	var positions = [{
		x: 2848 / 2 - 100,
		y: 2732 / 2 + 105
	}, {
		x: 2848 / 2 + 320,
		y: 2732 / 2 + 175
	}, {
		x: 2848 / 2 - 920,
		y: 2732 / 2 + 225
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgGlassBottle01 = game.addChild(new SGGlassBottle01());
	sgGlassBottle01.x = randomPosition.x;
	sgGlassBottle01.y = randomPosition.y;
}
function respawnSGGlassBottle01() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGGlassBottle01, respawnTime);
}
// Initialize the sgBackground01 asset on screen
var sgBackground01 = game.addChild(LK.getAsset('sgBackground01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2025 / 2,
	y: 2725 / 2
}));
var currentSmoke = null;
// Initialize the sgTrain01 asset on screen
var sgTrain01 = game.addChild(LK.getAsset('sgTrain01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 125,
	y: 1910
}));
// Initialize the sgToyCowboy asset on screen
var sgToyCowboy = game.addChild(LK.getAsset('sgToyCowboy', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 600,
	y: 965
}));
// Add a click event to the sgToyCowboy asset
sgToyCowboy.down = function (x, y, obj) {
	sgToyCowboyClickCounter++;
	if (sgToyCowboyClickCounter < 2) {
		// Add fading out effect to sgToyCowboy
		var fadeOut = function fadeOut() {
			if (sgToyCowboy.alpha > 0) {
				sgToyCowboy.alpha -= 0.05;
				LK.setTimeout(fadeOut, 50); // Reduce alpha every 50ms
			} else {
				sgToyCowboy.destroy();
			}
		};
		LK.setTimeout(fadeOut, 1000); // Start fade out after 1 seconds
		// Create sgCloudSmoke at the position of sgToyCowboy
		var sgCloudSmoke = game.addChild(LK.getAsset('sgCloudSmoke', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: this.x + 50,
			y: this.y - 20
		}));
		// Create sgDustStorm at the position of sgTargetDummy
		var sgDustStorm = game.addChild(LK.getAsset('sgDustStorm', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: sgTargetDummy.x,
			y: sgTargetDummy.y
		}));
		// Play sgRicochet sound
		LK.getSound('sgRicochet').play();
		// Spawn sgTarget25 on sgDustStorm
		var sgTarget25 = game.addChild(new Target25());
		sgTarget25.x = sgDustStorm.x;
		sgTarget25.y = sgDustStorm.y;
		// Destroy sgCloudSmoke and sgDustStorm after 1 second
		LK.setTimeout(function () {
			sgCloudSmoke.destroy();
			sgDustStorm.destroy();
		}, 1000);
		// Add falling behavior to sgTargetDummy similar to sgPoster01
		var velocityX = Math.random() * 20 - 10;
		var velocityY = Math.random() * 10 + 5;
		var gravity = 0.5;
		var angularVelocity = Math.random() * 0.2 - 0.1;
		sgTargetDummy.update = function () {
			velocityY += gravity;
			sgTargetDummy.y += velocityY;
			sgTargetDummy.x += velocityX;
			sgTargetDummy.rotation += angularVelocity;
			if (sgTargetDummy.y > 2732 || sgTargetDummy.x < 0 || sgTargetDummy.x > 2048) {
				sgTargetDummy.destroy();
			}
		};
		// Ensure the update loop for sign01 is not interrupted
		var originalUpdate = game.update;
		game.update = function () {
			sgTargetDummy.update();
			if (originalUpdate) {
				originalUpdate();
			}
		};
	}
};
// Initialize the sgBoard asset on screen
var sgBoard = game.addChild(LK.getAsset('sgBoard', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1024,
	y: 2366
}));
// Initialize sgLady on screen
LK.setTimeout(spawnSGLady, Math.random() * 3000 + 5000);
// Initialize the sgTargetDummy asset on screen
var sgTargetDummy = game.addChild(LK.getAsset('sgTargetDummy', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1450,
	y: 970
}));
// Add a flag to track if sgTrain01 has been clicked
var sgTrain01Clicked = false;
// Initialize the sgTrainWagon01 asset and parent it to sgTrain01
var sgTrainWagons = [];
for (var i = 0; i < 8; i++) {
	var sgTrainWagon = sgTrain01.addChild(LK.getAsset('sgTrainWagon01', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: sgTrain01.width / 2 - 300 - i * 220,
		// Adjust position for each wagon
		y: sgTrain01.height / 2 - 70
	}));
	sgTrainWagons.push(sgTrainWagon);
}
// Add a click event to the sgTrain01 asset
sgTrain01.down = function (x, y, obj) {
	// Check if sgTrain01 has already been clicked
	if (sgTrain01Clicked) {
		return;
	}
	sgTrain01Clicked = true;
	// Check if there is already an sgTrainSmoke instance
	if (currentSmoke) {
		return;
	}
	// Play sgTrainSound01 sound
	LK.getSound('sgTrainSound01').play();
	// Initialize sgSmoke in the center of sgTrain01
	var sgSmoke = new sgTrainSmoke();
	sgSmoke.x = sgTrain01.x + 70;
	sgSmoke.y = sgTrain01.y - 100;
	game.addChild(sgSmoke);
	currentSmoke = sgSmoke;
	// Play sgTrainSound02 after 2 seconds
	LK.setTimeout(function () {
		LK.getSound('sgTrainsSound02').play();
	}, 2000);
	// Move sgTrain01 horizontally to the right until it is near the border of the playspace
	var moveTrain = function moveTrain() {
		if (sgTrain01.x < 1825 - sgTrain01.width / 2) {
			sgTrain01.x += 7;
			LK.setTimeout(moveTrain, 16); // Move every 16ms (~60 FPS)
		} else {
			// Spawn three sgTarget25 on the visible train carts
			for (var i = 0; i < 3; i++) {
				var target25 = new Target25();
				target25.x = sgTrainWagons[i].x + sgTrain01.x + -400;
				target25.y = sgTrainWagons[i].y + sgTrain01.y;
				game.addChild(target25);
			}
			// After 2 seconds, fade out the train
			LK.setTimeout(function () {
				var fadeOut = function fadeOut() {
					if (sgTrain01.alpha > 0) {
						sgTrain01.alpha -= 0.05;
						LK.setTimeout(fadeOut, 50); // Reduce alpha every 50ms
					} else {
						sgTrain01.destroy();
					}
				};
				fadeOut();
			}, 2000);
		}
	};
	moveTrain();
};
// Initialize the sgBoard asset on screen
var sgBoard = game.addChild(LK.getAsset('sgBoard', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1024,
	// Center of the screen horizontally
	y: 2366 // Center of the screen vertically
}));
// Initialize the saloonPiano asset on screen
var saloonPiano = game.addChild(LK.getAsset('saloonPiano', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 3275 / 2,
	y: 3800 / 2
}));
// Add a click event to the piano
saloonPiano.down = function (x, y, obj) {
	// If the piano jingle is not playing, play it
	if (!isPianoPlaying) {
		isPianoPlaying = true;
		LK.getSound('saloonPianoJingle01').play();
		// After 5 seconds, set isPianoPlaying to false and hide sg_notes
		LK.setTimeout(function () {
			isPianoPlaying = false;
			note.visible = false;
		}, 3250);
		// Create sg_Notes above saloonPiano when piano jingle is playing
		var note = new Note();
		note.x = saloonPiano.x;
		note.y = saloonPiano.y - 100;
		game.addChild(note);
	}
};
// Initialize the sgBarrel asset on screen
function spawnSGBarrel() {
	var positions = [{
		x: 400,
		y: 1800
	}, {
		x: 1325,
		y: 1800
	}, {
		x: 1750,
		y: 2200
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgBarrel = game.addChild(new SGBarrel());
	sgBarrel.x = randomPosition.x;
	sgBarrel.y = randomPosition.y;
}
spawnSGBarrel();
// Initialize the sgFrame01 asset on screen
var sgFrame01 = game.addChild(LK.getAsset('sgFrame01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2,
	y: 2600 / 2
}));
// Initialize the sgBulletHole01 asset on screen
var sgBulletHole01 = game.addChild(LK.getAsset('sgBulletHole01', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	// Center of the screen horizontally
	y: 1800 // Center of the screen vertically
}));
// Initialize the sgInGrain asset on screen
var sgInGrain = game.addChild(LK.getAsset('sgIngrain', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	y: 320
}));
// Initialize the sgVines asset on screen
var sgVines = game.addChild(LK.getAsset('sgVines', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 50,
	// Center of the screen horizontally
	y: 150 // Center of the screen vertically
}));
// Initialize the sgSpeechBubble01 asset on screen for 2 second and then destroy it after a delay of 1 seconds
LK.setTimeout(function () {
	var sgSpeechBubble01 = game.addChild(LK.getAsset('sgSpeechBubble01', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: 900,
		// Center of the screen horizontally
		y: 1966 // Center of the screen vertically
	}));
	LK.setTimeout(function () {
		LK.setTimeout(function () {
			sgSpeechBubble01.destroy();
		}, 1000);
		LK.getSound('sgYeehaw').play();
	}, 500);
}, 1000);
// Initialize the sgPoster01 asset on screen
function spawnSGPoster() {
	var positions = [{
		x: 385,
		y: 1425
	}, {
		x: 1585,
		y: 1275
	}, {
		x: 250,
		y: 1725
	}];
	var randomPosition = positions[Math.floor(Math.random() * positions.length)];
	var sgPoster = game.addChild(new SGPoster());
	sgPoster.x = randomPosition.x;
	sgPoster.y = randomPosition.y;
}
function respawnSGPoster() {
	var respawnTime = Math.random() * 3000 + 1000;
	LK.setTimeout(spawnSGPoster, respawnTime);
}
spawnSGPoster();
function spawnTumbleweed() {
	var tumbleweed = new Tumbleweed();
	tumbleweed.x = 100;
	tumbleweed.y = 2800;
	game.addChild(tumbleweed);
	var nextSpawnTime = Math.random() * 20000 + 30000; // 20 to 30 seconds
	LK.setTimeout(spawnTumbleweed, nextSpawnTime);
}
LK.setTimeout(spawnTumbleweed, 10000);
// Initialize the sgDesertRock asset on screen
var sgDesertRock = game.addChild(LK.getAsset('sgDesertRock', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1500,
	y: 2900
}));
// Initialize the sgGecko asset on screen after sgDesertRock
var sgGecko = game.addChild(LK.getAsset('sgGecko', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1500,
	y: 2375
}));
// Add a click event to the sgGecko asset
sgGecko.down = function (x, y, obj) {
	// Play sgGeckoNoise sound
	LK.getSound('sgGeckoNoise').play();
	// Destroy the sgGecko asset
	this.destroy();
	// Instantiate sgCloudPuff at the same position
	var sgCloudPuff = game.addChild(LK.getAsset('sgCloudPuff', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: this.x - 25,
		y: this.y
	}));
	// After 1 second, destroy sgCloudPuff and instantiate sgTarget100
	LK.setTimeout(function () {
		sgCloudPuff.destroy();
		var sgTarget100 = game.addChild(LK.getAsset('sgTarget100', {
			anchorX: 0.5,
			anchorY: 0.5,
			x: sgCloudPuff.x,
			y: sgCloudPuff.y
		}));
		// Add pulsing effect to sgTarget100
		sgTarget100.update = function () {
			this.scale.x = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
			this.scale.y = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
		};
		// Add a click event to the sgTarget100 asset to destroy it and replace it with a flashing number 100 for 1 second
		sgTarget100.down = function (x, y, obj) {
			// Play getSound02 sound
			LK.getSound('getSound02').play();
			// Destroy the sgTarget100 asset
			this.destroy();
			// Add 100 to the score
			score += 100;
			scoreTxt.setText(score);
			// Create a text asset for the number 100
			var number100 = new Text2('100', {
				size: 50,
				fill: "#00FF00" // Green color
			});
			// Position the number 100 at the same position as the sgTarget100 asset
			number100.x = this.x - 50;
			number100.y = this.y - 30;
			// Add the number 100 to the game
			game.addChild(number100);
			// Make the number 100 flash for 1 second
			var flashInterval = LK.setInterval(function () {
				number100.visible = !number100.visible;
			}, 100);
			LK.setTimeout(function () {
				LK.clearInterval(flashInterval);
				number100.visible = true;
			}, 1000);
			// After 1 second, destroy the number 100
			LK.setTimeout(function () {
				number100.destroy();
			}, 1000);
		};
	}, 1000);
};
// Initialize the sgTarget100 asset on screen
var sgTarget100 = game.addChild(LK.getAsset('sgTarget100', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 1000,
	y: 350
}));
// Add pulsing effect to sgTarget100
sgTarget100.update = function () {
	this.scale.x = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
	this.scale.y = 1 + 0.1 * Math.sin(LK.ticks * 0.1);
};
// Add a click event to the sgTarget100 asset to destroy it and replace it with a flashing number 100 for 1 second
sgTarget100.down = function (x, y, obj) {
	// Play getSound02 sound
	LK.getSound('getSound02').play();
	// Destroy the sgTarget100 asset
	this.destroy();
	// Add 100 to the score
	score += 100;
	scoreTxt.setText(score);
	// Create a text asset for the number 100
	var number100 = new Text2('100', {
		size: 50,
		fill: "#00FF00" // Green color
	});
	// Position the number 100 at the same position as the sgTarget100 asset
	number100.x = this.x - 50;
	number100.y = this.y - 30;
	// Add the number 100 to the game
	game.addChild(number100);
	// Make the number 100 flash for 1 second
	var flashInterval = LK.setInterval(function () {
		number100.visible = !number100.visible;
	}, 100);
	LK.setTimeout(function () {
		LK.clearInterval(flashInterval);
		number100.visible = true;
	}, 1000);
	// After 1 second, destroy the number 100
	LK.setTimeout(function () {
		number100.destroy();
	}, 1000);
};
// Initialize variables
var scoreTxt;
var score = 0;
var barmanCreated = false;
var isPianoPlaying = false;
// Initialize the sgSign01 asset on screen and center it at the top
var sgSign01 = LK.gui.top.addChild(LK.getAsset('sg_Sign01', {
	anchorX: 0.5,
	anchorY: 0,
	x: 0,
	y: -150
}));
// Add a click event to the sg_Sign01 asset to make it swing for 5 seconds
sgSign01.down = function (x, y, obj) {
	// Check if the sign is already swinging
	if (this.isSwinging) {
		return;
	}
	this.isSwinging = true;
	var swingDuration = 5000; // 5 seconds in milliseconds
	var swingFrequency = 1 / swingDuration; // Frequency of the oscillation
	var swingAmplitude = 1; // The maximum rotation angle
	var startTime = Date.now();
	// Play chainNoises sound once at the start of the swinging
	LK.getSound('chainNoises').play();
	this.update = function () {
		var currentTime = Date.now();
		var timePassed = currentTime - startTime;
		if (timePassed < swingDuration) {
			this.rotation = swingAmplitude * Math.sin(2 * Math.PI * swingFrequency * timePassed);
		} else {
			this.rotation = 0;
			this.update = function () {};
			this.isSwinging = false;
		}
	};
	game.update = this.update.bind(this);
};
spawnSGBeans01();
// Initialize the sgCactus asset on screen
var sgCactus = game.addChild(LK.getAsset('sgCactus', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2000,
	y: 2500
}));
// Initialize the sgCharacter asset on screen
var sgCharacter = game.addChild(LK.getAsset('sgCharacter', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 800 / 2,
	y: 4800 / 2
}));
// Initialize the sg_SignScore asset in the center of the playspace
var sgSignScore = game.addChild(LK.getAsset('sg_SignScore', {
	anchorX: 0.5,
	anchorY: 0.5,
	x: 2048 / 2 - 740,
	y: 2732 / 2 + 1200
}));
// Add a click event to the sgCharacter asset to trigger game over
sgCharacter.down = function (x, y, obj) {
	LK.effects.flashScreen(0xff0000, 1000);
	LK.setTimeout(function () {
		LK.showGameOver();
	}, 250);
};
// Create score text
scoreTxt = new Text2('0', {
	size: 127.5,
	fill: "#654321"
});
scoreTxt.anchor.set(0.5, 0);
game.addChild(scoreTxt);
scoreTxt.x = sgCharacter.x + 92;
scoreTxt.y = sgCharacter.y + 95;
spawnSGGlassBottle01();
// Initialize the sgTarget5 asset on screen
spawnSGTarget5();
// Initialize the sgTarget10 asset on screen
spawnSGTarget10();
// Handle game updates
sgTarget100.update();
for (var i = 0; i < game.children.length; i++) {
	if (game.children[i] instanceof sgWhiskey) {
		game.children[i].update();
	}
}
// Check if score has reached 100 to spawn Barman
if (score >= 100 && !barmanCreated) {
	spawnSGBarman();
}
// Add a click event to the game to create a sgCrosshair asset at the clicked position
game.down = function (x, y, obj) {
	// Create a sgCrosshair asset at the clicked position
	var sgCrosshair = game.addChild(LK.getAsset('sgCrosshair', {
		anchorX: 0.5,
		anchorY: 0.5,
		x: x,
		y: y
	}));
	// Play bulletHit01 or bulletHit02 sound randomly
	if (Math.random() > 0) {
		LK.getSound('bulletHit01').play();
	}
	// After 0.5 second, destroy the sgCrosshair asset
	LK.setTimeout(function () {
		sgCrosshair.destroy();
	}, 500);
};
;
;
 wild west saloon piano real life. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 front facing western shooting gallery wooden frame. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 a white musical note on a empty background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western baked beans can. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western glass beer bottle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western shooting target with 5 written on it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western shooting target with 10 written on it.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 vertical exploded glass beer bottle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 vertical red curtain. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 pretty blond human cowgirl holding a sign. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western gold star with 25 written on it. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 a western shining green diamond. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Create a cactus. The goal is to capture a lively and playful location.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Create a desert rock. The goal is to capture a lively and playful location.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Create a desert tumble weed. The goal is to capture a lively and playful location.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western barrel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 cartoon gecko with a cowboy hat. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 cartoon smoke puff. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western destroyed barrel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 cloud of smoke. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 a single brown dust particle. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western wanted poster. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 2d western toy train side view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 train smoke. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western toy train wagon side profile. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 a single wildvine with spikes and flowers dangling.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 J+G ingrained in a heart, on wood by a knife. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 a western shooting gallery ranking charts written rookie (70) skilled(220) legendary (400). Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 wood bullet hole. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 empty western saloon, just the floor, ceiling and walls.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 front facing western shooting gallery wooden sign hanging from chains that is written "Whiskey Saloon". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 upper torso of a western cartoon barman getting ready to throw a bottle of whiskey.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western cowboy toy shooting. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western target dummy. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 grawlix in a speech bubble, make sure it looks something like this !#@* and theres an angry icon. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 western bottle of whiskey.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 orange damage splash.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 cartoon pie drawn top view. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 add an apron, add a bow in the hair, remove the hat
 purple damage splash. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Tap to shoot! in a western style speech bubble.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 Red x western inspired. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
 
 
 western inspired letters that spell "Score". Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
saloonPianoJingle01
Sound effect
chainNoises
Sound effect
canHit
Sound effect
canHit02
Sound effect
glassHit01
Sound effect
glassHit02
Sound effect
bulletHit01
Sound effect
sgGeckoNoise
Sound effect
getSound02
Sound effect
getSound01
Sound effect
barreltHit01
Sound effect
sgSaloonMusic
Sound effect
sgYeehaw
Sound effect
sgTrainSound01
Sound effect
sgTrainsSound02
Sound effect
sgGrunt
Sound effect
sgRicochet
Sound effect
sgOof
Sound effect
sgfemaleoof
Sound effect
sgfemaleow
Sound effect
sgsquish
Sound effect