/**** 
* Classes
****/ 
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the clickable object
var ClickableObject = Container.expand(function () {
	var self = Container.call(this);
	var clickableGraphics = self.attachAsset('clickable', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 4,
		scaleY: 4
	});
	// Event handler for when the object is clicked
	self.down = function (x, y, obj) {
		// Increase score
		LK.setScore(LK.getScore() + 1);
		scoreTxt.setText(LK.getScore());
		// Flash the object to give feedback
		LK.effects.flashObject(self, 0xffffff, 100);
		// Create a new coin and add it to the game
		var coin = game.addChild(new Coin());
		coin.x = self.x;
		coin.y = self.y;
		// Animate the coin dropping into the vase
		coin.drop();
	};
});
// Class for the coin
var Coin = Container.expand(function () {
	var self = Container.call(this);
	var coinGraphics = self.attachAsset('Coin', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 0.5,
		scaleY: 0.5
	});
	// Method for the coin dropping animation
	self.drop = function () {
		var dropInterval = LK.setInterval(function () {
			// Calculate the direction vector from the coin to the vase
			var dx = vase.x - self.x;
			var dy = vase.y - self.y;
			var distance = Math.sqrt(dx * dx + dy * dy);
			// Normalize the direction vector
			dx /= distance;
			dy /= distance;
			// Move the coin towards the vase
			self.x += dx * 40; // Increase the speed of the coin
			self.y += dy * 40; // Increase the speed of the coin
			// If the coin reaches the vase, clear the interval, destroy the coin and update the score
			if (self.intersects(vase)) {
				LK.clearInterval(dropInterval);
				self.destroy();
				LK.setScore(LK.getScore() + 1);
				scoreTxt.setText(LK.getScore());
			}
		}, 50);
	};
});
// Class for Person1
var Person1 = Container.expand(function () {
	var self = Container.call(this);
	var sprites = ['Person1sprite1', 'Person1sprite2', 'Person1sprite3'];
	var spriteIndex = 0;
	var person1Graphics = self.attachAsset(sprites[spriteIndex], {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: clickableObject.width / 100,
		scaleY: clickableObject.height / 185.51
	});
	// Add walk function
	self.walk = function () {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: clickableObject.width / 100,
			scaleY: clickableObject.height / 185.51
		});
	};
});
// Class for the Store
var Store = Container.expand(function () {
	var self = Container.call(this);
	var storeGraphics = self.attachAsset('Store', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1,
		scaleY: 1
	});
	// Event handler for when the store is clicked
	self.down = function (x, y, obj) {
		// Increase coin gain
		// LK.setCoinGain(LK.getCoinGain() + 1); // Commented out as LK.getCoinGain is not a function
	};
});
// Define person1 in the global scope
// Define spriteIndex in the global scope
// Class for UnknownGuy
var UnknownGuy = Container.expand(function () {
	var self = Container.call(this);
	var sprites = ['unknownguy', 'unknownguysprite2'];
	var spriteIndex = 0;
	var unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1,
		scaleY: 1
	});
	// Event handler for when the object is clicked
	self.down = function (x, y, obj) {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 1,
			scaleY: 1
		});
		// If the unknown guy opens his jacket, open the store
		if (spriteIndex == 1) {
			var store = game.addChild(new Store());
			store.x = self.x;
			store.y = self.y - store.height;
		} else {
			// Create a new coin and add it to the game
			var coin = game.addChild(new Coin());
			coin.x = self.x;
			coin.y = self.y;
			// Animate the coin dropping into the vase
			coin.drop();
		}
	};
	// Add walk function
	self.walk = function () {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 1,
			scaleY: 1
		});
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
// Event handler for when the game is clicked
// LK.setCoinGain(1); // Commented out as LK.setCoinGain is not a function
// Initialize coin gain
game.down = function (x, y, obj) {
	// Create a new coin and add it to the game
	var coin = game.addChild(new Coin());
	coin.x = x;
	coin.y = y;
	// Animate the coin dropping into the vase
	coin.drop();
};
game.down = function (x, y, obj) {
	// Create a new coin and add it to the game
	var coin = game.addChild(new Coin());
	coin.x = x;
	coin.y = y;
	// Animate the coin dropping into the vase
	coin.drop();
};
// Define spriteIndex in the global scope
var spriteIndex = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add the Background asset to the game scene
var background = game.addChild(LK.getAsset('Background', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 2048 / 100,
	// Scale to fit the screen width
	scaleY: 2732 / 100,
	// Scale to fit the screen height
	x: 2048 / 2,
	y: 2732 / 2
}));
// Create the clickable object and position it at the bottom of the screen
var clickableObject = game.addChild(new ClickableObject());
clickableObject.x = 2048 / 2;
clickableObject.y = 2732 - clickableObject.height / 2;
// Add the Vase asset to the game scene
var vase = game.addChild(LK.getAsset('Vase', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 2,
	scaleY: 2,
	x: clickableObject.x + clickableObject.width + 100,
	y: clickableObject.y
}));
// Create UnknownGuy and add it to the game scene
var unknownGuy = game.addChild(new UnknownGuy());
unknownGuy.scaleX = clickableObject.width / unknownGuy.width;
unknownGuy.scaleY = clickableObject.height / unknownGuy.height;
unknownGuy.x = unknownGuy.width / 2;
unknownGuy.y = 2732 - unknownGuy.height / 2;
// Define person1 in the global scope
var person1 = game.addChild(new Person1());
person1.x = 100 / 2;
person1.y = 2732 - person1.height / 2;
// Game update loop
game.update = function () {
	// Make Person1 walk every 3 seconds
	if (LK.ticks % (3 * 60) == 0) {
		person1.walk();
	}
	// Move Person1 to the right
	person1.x += 5;
	// Create a new coin and add it to the game only if Person1 is walking and it's the first sprite
	if (person1.isWalking && spriteIndex == 0 && LK.ticks % (3 * 60) == 0) {
		var coin = game.addChild(new Coin());
		coin.x = person1.x;
		coin.y = person1.y;
		// Animate the coin dropping into the vase
		coin.drop();
	}
};
// Removed the game.down event handler /**** 
* Classes
****/ 
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Class for the clickable object
var ClickableObject = Container.expand(function () {
	var self = Container.call(this);
	var clickableGraphics = self.attachAsset('clickable', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 4,
		scaleY: 4
	});
	// Event handler for when the object is clicked
	self.down = function (x, y, obj) {
		// Increase score
		LK.setScore(LK.getScore() + 1);
		scoreTxt.setText(LK.getScore());
		// Flash the object to give feedback
		LK.effects.flashObject(self, 0xffffff, 100);
		// Create a new coin and add it to the game
		var coin = game.addChild(new Coin());
		coin.x = self.x;
		coin.y = self.y;
		// Animate the coin dropping into the vase
		coin.drop();
	};
});
// Class for the coin
var Coin = Container.expand(function () {
	var self = Container.call(this);
	var coinGraphics = self.attachAsset('Coin', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 0.5,
		scaleY: 0.5
	});
	// Method for the coin dropping animation
	self.drop = function () {
		var dropInterval = LK.setInterval(function () {
			// Calculate the direction vector from the coin to the vase
			var dx = vase.x - self.x;
			var dy = vase.y - self.y;
			var distance = Math.sqrt(dx * dx + dy * dy);
			// Normalize the direction vector
			dx /= distance;
			dy /= distance;
			// Move the coin towards the vase
			self.x += dx * 40; // Increase the speed of the coin
			self.y += dy * 40; // Increase the speed of the coin
			// If the coin reaches the vase, clear the interval, destroy the coin and update the score
			if (self.intersects(vase)) {
				LK.clearInterval(dropInterval);
				self.destroy();
				LK.setScore(LK.getScore() + 1);
				scoreTxt.setText(LK.getScore());
			}
		}, 50);
	};
});
// Class for Person1
var Person1 = Container.expand(function () {
	var self = Container.call(this);
	var sprites = ['Person1sprite1', 'Person1sprite2', 'Person1sprite3'];
	var spriteIndex = 0;
	var person1Graphics = self.attachAsset(sprites[spriteIndex], {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: clickableObject.width / 100,
		scaleY: clickableObject.height / 185.51
	});
	// Add walk function
	self.walk = function () {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: clickableObject.width / 100,
			scaleY: clickableObject.height / 185.51
		});
	};
});
// Class for the Store
var Store = Container.expand(function () {
	var self = Container.call(this);
	var storeGraphics = self.attachAsset('Store', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1,
		scaleY: 1
	});
	// Event handler for when the store is clicked
	self.down = function (x, y, obj) {
		// Increase coin gain
		// LK.setCoinGain(LK.getCoinGain() + 1); // Commented out as LK.getCoinGain is not a function
	};
});
// Define person1 in the global scope
// Define spriteIndex in the global scope
// Class for UnknownGuy
var UnknownGuy = Container.expand(function () {
	var self = Container.call(this);
	var sprites = ['unknownguy', 'unknownguysprite2'];
	var spriteIndex = 0;
	var unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1,
		scaleY: 1
	});
	// Event handler for when the object is clicked
	self.down = function (x, y, obj) {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 1,
			scaleY: 1
		});
		// If the unknown guy opens his jacket, open the store
		if (spriteIndex == 1) {
			var store = game.addChild(new Store());
			store.x = self.x;
			store.y = self.y - store.height;
		} else {
			// Create a new coin and add it to the game
			var coin = game.addChild(new Coin());
			coin.x = self.x;
			coin.y = self.y;
			// Animate the coin dropping into the vase
			coin.drop();
		}
	};
	// Add walk function
	self.walk = function () {
		// Cycle through the sprites for the walking animation
		spriteIndex = (spriteIndex + 1) % sprites.length;
		unknownGuyGraphics = self.attachAsset(sprites[spriteIndex], {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 1,
			scaleY: 1
		});
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000 //Init game with black background 
});
/**** 
* Game Code
****/ 
// Event handler for when the game is clicked
// LK.setCoinGain(1); // Commented out as LK.setCoinGain is not a function
// Initialize coin gain
game.down = function (x, y, obj) {
	// Create a new coin and add it to the game
	var coin = game.addChild(new Coin());
	coin.x = x;
	coin.y = y;
	// Animate the coin dropping into the vase
	coin.drop();
};
game.down = function (x, y, obj) {
	// Create a new coin and add it to the game
	var coin = game.addChild(new Coin());
	coin.x = x;
	coin.y = y;
	// Animate the coin dropping into the vase
	coin.drop();
};
// Define spriteIndex in the global scope
var spriteIndex = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Add the Background asset to the game scene
var background = game.addChild(LK.getAsset('Background', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 2048 / 100,
	// Scale to fit the screen width
	scaleY: 2732 / 100,
	// Scale to fit the screen height
	x: 2048 / 2,
	y: 2732 / 2
}));
// Create the clickable object and position it at the bottom of the screen
var clickableObject = game.addChild(new ClickableObject());
clickableObject.x = 2048 / 2;
clickableObject.y = 2732 - clickableObject.height / 2;
// Add the Vase asset to the game scene
var vase = game.addChild(LK.getAsset('Vase', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 2,
	scaleY: 2,
	x: clickableObject.x + clickableObject.width + 100,
	y: clickableObject.y
}));
// Create UnknownGuy and add it to the game scene
var unknownGuy = game.addChild(new UnknownGuy());
unknownGuy.scaleX = clickableObject.width / unknownGuy.width;
unknownGuy.scaleY = clickableObject.height / unknownGuy.height;
unknownGuy.x = unknownGuy.width / 2;
unknownGuy.y = 2732 - unknownGuy.height / 2;
// Define person1 in the global scope
var person1 = game.addChild(new Person1());
person1.x = 100 / 2;
person1.y = 2732 - person1.height / 2;
// Game update loop
game.update = function () {
	// Make Person1 walk every 3 seconds
	if (LK.ticks % (3 * 60) == 0) {
		person1.walk();
	}
	// Move Person1 to the right
	person1.x += 5;
	// Create a new coin and add it to the game only if Person1 is walking and it's the first sprite
	if (person1.isWalking && spriteIndex == 0 && LK.ticks % (3 * 60) == 0) {
		var coin = game.addChild(new Coin());
		coin.x = person1.x;
		coin.y = person1.y;
		// Animate the coin dropping into the vase
		coin.drop();
	}
};
// Removed the game.down event handler