/**** 
* Plugins
****/ 
var storage = LK.import("@upit/storage.v1", {
	level: 1,
	xp: 0,
	kibble: 50,
	lastPetTime: 0,
	lastLitterTime: 0,
	ownedItems: [],
	catName: "Unnamed",
	catType: "basic",
	ownedCatTypes: ["basic"]
});
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var Cat = Container.expand(function () {
	var self = Container.call(this);
	var catSprite = self.attachAsset('cat', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.accessories = [];
	self.catSprite = catSprite;
	self.setCatType = function (typeId) {
		// Remove current cat sprite
		self.removeChild(self.catSprite);
		// Add new cat sprite based on type
		var assetId;
		switch (typeId) {
			case 'princess':
				assetId = 'catPrincess';
				break;
			case 'spider':
				assetId = 'catSpider';
				break;
			case 'bee':
				assetId = 'catBee';
				break;
			case 'white':
				assetId = 'catWhite';
				break;
			case 'fruit':
				assetId = 'catFruit';
				break;
			case 'pro':
				assetId = 'catPro';
				break;
			default:
				// basic
				assetId = 'cat';
				break;
		}
		self.catSprite = self.attachAsset(assetId, {
			anchorX: 0.5,
			anchorY: 0.5
		});
	};
	self.addAccessory = function (itemType) {
		var accessory = self.addChild(LK.getAsset(itemType, {
			anchorX: 0.5,
			anchorY: 0.5
		}));
		if (itemType === 'pinkHeadband' || itemType === 'blueHeadband') {
			accessory.y = -120;
		} else {
			accessory.x = Math.random() * 100 - 50;
			accessory.y = Math.random() * 100 - 50;
		}
		self.accessories.push(accessory);
	};
	self.animate = function () {
		tween(catSprite, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 300,
			easing: tween.easeInOut,
			onFinish: function onFinish() {
				tween(catSprite, {
					scaleX: 1,
					scaleY: 1
				}, {
					duration: 300,
					easing: tween.easeInOut
				});
			}
		});
	};
	return self;
});
var CatCustomization = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Cat\'pers - Personnalisez votre chat', {
		size: 45,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	self.catTypeButtons = [];
	self.setupCatTypes = function () {
		// Clear existing buttons
		for (var i = 0; i < self.catTypeButtons.length; i++) {
			self.removeChild(self.catTypeButtons[i]);
		}
		self.catTypeButtons = [];
		for (var i = 0; i < catTypes.length; i++) {
			var catType = catTypes[i];
			var yPos = -350 + i * 100;
			var nameText = new Text2(catType.name, {
				size: 35,
				fill: 0x333333
			});
			nameText.anchor.set(0, 0.5);
			nameText.x = -350;
			nameText.y = yPos;
			self.addChild(nameText);
			var priceText = new Text2(catType.price + ' croquettes', {
				size: 30,
				fill: 0x666666
			});
			priceText.anchor.set(0, 0.5);
			priceText.x = -350;
			priceText.y = yPos + 35;
			self.addChild(priceText);
			var isOwned = ownedCatTypes.indexOf(catType.id) !== -1;
			var isCurrent = currentCatType === catType.id;
			var buttonText = isCurrent ? 'Actuel' : isOwned ? 'Choisir' : 'Acheter';
			var button = self.addChild(new GameButton('buyButton', buttonText, 300, yPos));
			button.catTypeId = catType.id;
			button.catTypePrice = catType.price;
			button.isOwned = isOwned;
			button.isCurrent = isCurrent;
			if (isCurrent) {
				button.attachAsset('buyButton', {}).tint = 0x4CAF50; // Green for current
			} else if (isOwned) {
				button.attachAsset('buyButton', {}).tint = 0x2196F3; // Blue for owned
			}
			self.catTypeButtons.push(button);
		}
	};
	self.setupHandlers = function () {
		// Setup cat type button handlers
		for (var i = 0; i < self.catTypeButtons.length; i++) {
			var catTypeBtn = self.catTypeButtons[i];
			catTypeBtn.up = function () {
				this.parent.parent.alpha = 0.7;
				if (this.isCurrent) {
					// Already current type, do nothing
					return;
				}
				if (this.isOwned) {
					// Switch to owned cat type
					currentCatType = this.catTypeId;
					cat.setCatType(currentCatType);
					updateUI();
					catCustomization.visible = false;
				} else {
					// Try to buy cat type
					if (currentKibble >= this.catTypePrice) {
						currentKibble -= this.catTypePrice;
						ownedCatTypes.push(this.catTypeId);
						currentCatType = this.catTypeId;
						cat.setCatType(currentCatType);
						LK.getSound('purchase').play();
						updateUI();
						catCustomization.visible = false;
					}
				}
			};
		}
	};
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
var CatNaming = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Choose Your Cat\'s Name', {
		size: 50,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	self.nameOptions = [];
	self.choiceButtons = [];
	self.generateNames = function () {
		var shuffled = catNames.slice();
		for (var i = shuffled.length - 1; i > 0; i--) {
			var j = Math.floor(Math.random() * (i + 1));
			var temp = shuffled[i];
			shuffled[i] = shuffled[j];
			shuffled[j] = temp;
		}
		return [shuffled[0], shuffled[1], shuffled[2]];
	};
	self.setupNameOptions = function () {
		// Clear existing options
		for (var i = 0; i < self.nameOptions.length; i++) {
			self.removeChild(self.nameOptions[i]);
		}
		for (var i = 0; i < self.choiceButtons.length; i++) {
			self.removeChild(self.choiceButtons[i]);
		}
		self.nameOptions = [];
		self.choiceButtons = [];
		var names = self.generateNames();
		for (var i = 0; i < 3; i++) {
			var yPos = -200 + i * 120;
			var nameText = new Text2(names[i], {
				size: 45,
				fill: 0x333333
			});
			nameText.anchor.set(0.5, 0.5);
			nameText.x = -100;
			nameText.y = yPos;
			self.addChild(nameText);
			self.nameOptions.push(nameText);
			var choiceBtn = self.addChild(new GameButton('buyButton', 'Choose', 300, yPos));
			choiceBtn.catName = names[i];
			self.choiceButtons.push(choiceBtn);
		}
	};
	self.setupHandlers = function () {
		// Setup choice button handlers
		for (var i = 0; i < self.choiceButtons.length; i++) {
			var choiceBtn = self.choiceButtons[i];
			choiceBtn.up = function () {
				this.parent.parent.alpha = 0.7;
				currentCatName = this.catName;
				updateUI();
				catNaming.visible = false;
			};
		}
	};
	var generateBtn = self.addChild(new GameButton('buyButton', 'Generate 3 New Names', 0, 200));
	generateBtn.up = function () {
		generateBtn.parent.parent.alpha = 0.7;
		self.setupNameOptions();
		self.setupHandlers();
	};
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
var GameButton = Container.expand(function (assetId, text, x, y) {
	var self = Container.call(this);
	var buttonSprite = self.attachAsset(assetId, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var buttonText = new Text2(text, {
		size: 40,
		fill: 0xFFFFFF
	});
	buttonText.anchor.set(0.5, 0.5);
	self.addChild(buttonText);
	self.x = x;
	self.y = y;
	self.down = function () {
		buttonSprite.alpha = 0.7;
	};
	self.up = function () {
		buttonSprite.alpha = 1.0;
	};
	return self;
});
var Shop = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Shop', {
		size: 60,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	var items = [{
		name: 'Dog Plushie',
		asset: 'dogPlushie',
		price: 10,
		id: 'dogPlushie'
	}, {
		name: 'Plastic Fish',
		asset: 'plasticFish',
		price: 20,
		id: 'plasticFish'
	}, {
		name: 'Pink Headband',
		asset: 'pinkHeadband',
		price: 30,
		id: 'pinkHeadband'
	}, {
		name: 'Blue Headband',
		asset: 'blueHeadband',
		price: 30,
		id: 'blueHeadband'
	}, {
		name: 'Mouse Toy',
		asset: 'mouseToy',
		price: 40,
		id: 'mouseToy'
	}];
	self.itemButtons = [];
	for (var i = 0; i < items.length; i++) {
		var item = items[i];
		var yPos = -200 + i * 150;
		var itemSprite = self.addChild(LK.getAsset(item.asset, {
			anchorX: 0.5,
			anchorY: 0.5,
			x: -300,
			y: yPos
		}));
		var nameText = new Text2(item.name, {
			size: 40,
			fill: 0x333333
		});
		nameText.anchor.set(0, 0.5);
		nameText.x = -200;
		nameText.y = yPos;
		self.addChild(nameText);
		var priceText = new Text2(item.price + ' kibble', {
			size: 35,
			fill: 0x666666
		});
		priceText.anchor.set(0, 0.5);
		priceText.x = -200;
		priceText.y = yPos + 40;
		self.addChild(priceText);
		var buyBtn = self.addChild(new GameButton('buyButton', 'Buy', 400, yPos));
		buyBtn.itemId = item.id;
		buyBtn.price = item.price;
		self.itemButtons.push(buyBtn);
	}
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEEB
});
/**** 
* Game Code
****/ 
var catNames = ['Shadow', 'Luna', 'Mittens', 'Whiskers', 'Simba', 'Nala', 'Felix', 'Garfield', 'Smokey', 'Tiger', 'Oreo', 'Patches', 'Boots', 'Socks', 'Pepper', 'Salt', 'Coco', 'Mimi', 'Bella', 'Charlie', 'Max', 'Oscar', 'Leo', 'Milo', 'Jasper', 'Oliver', 'Jack', 'Toby', 'George', 'Sam', 'Lucky', 'Buddy', 'Princess', 'Angel', 'Baby', 'Honey', 'Sugar', 'Cookie', 'Peanut', 'Ginger', 'Snowball', 'Fluffy', 'Fuzzy', 'Cuddles', 'Snuggles', 'Bubbles', 'Sparkles', 'Twinkle', 'Storm', 'Thunder', 'Lightning', 'Blaze', 'Flame', 'Ember', 'Ash', 'Dusty', 'Ruby', 'Emerald', 'Sapphire', 'Diamond', 'Pearl', 'Crystal', 'Jewel', 'Treasure', 'Magic', 'Mystery', 'Wonder', 'Dream'];
var catTypes = [{
	id: 'basic',
	name: 'Chat de base',
	price: 0,
	asset: 'cat'
}, {
	id: 'princess',
	name: 'Cutie princesse',
	price: 15,
	asset: 'catPrincess'
}, {
	id: 'spider',
	name: 'Spider\'cat',
	price: 10,
	asset: 'catSpider'
}, {
	id: 'bee',
	name: 'Bee cat',
	price: 18,
	asset: 'catBee'
}, {
	id: 'white',
	name: 'White cat',
	price: 16,
	asset: 'catWhite'
}, {
	id: 'fruit',
	name: 'Chat fan de fruits',
	price: 25,
	asset: 'catFruit'
}, {
	id: 'pro',
	name: 'Pro-cat',
	price: 30,
	asset: 'catPro'
}];
var currentLevel = storage.level;
var currentXP = storage.xp;
var currentKibble = storage.kibble;
var lastPetTime = storage.lastPetTime;
var lastLitterTime = storage.lastLitterTime;
var ownedItems = storage.ownedItems || [];
var currentCatName = storage.catName || 'Unnamed';
var currentCatType = storage.catType || 'basic';
var ownedCatTypes = storage.ownedCatTypes || ['basic'];
var xpRequired = 100 * Math.pow(2, currentLevel - 1);
// Add custom background
var backgroundImage = game.addChild(LK.getAsset('customBackground', {
	anchorX: 0.5,
	anchorY: 0.5
}));
backgroundImage.x = 1024;
backgroundImage.y = 1366;
var cat = game.addChild(new Cat());
cat.x = 1024;
cat.y = 800;
// Add owned accessories to cat
for (var i = 0; i < ownedItems.length; i++) {
	cat.addAccessory(ownedItems[i]);
}
// UI Elements
var levelText = new Text2('Level: ' + currentLevel, {
	size: 50,
	fill: 0x333333
});
levelText.anchor.set(0, 0);
levelText.x = 120;
levelText.y = 150;
LK.gui.topLeft.addChild(levelText);
var xpText = new Text2('XP: ' + currentXP + '/' + xpRequired, {
	size: 40,
	fill: 0x333333
});
xpText.anchor.set(0, 0);
xpText.x = 120;
xpText.y = 220;
LK.gui.topLeft.addChild(xpText);
var kibbleText = new Text2('Kibble: ' + currentKibble, {
	size: 45,
	fill: 0x333333
});
kibbleText.anchor.set(1, 0);
LK.gui.topRight.addChild(kibbleText);
// Cat name display
var catNameText = new Text2('Cat: ' + currentCatName, {
	size: 40,
	fill: 0x333333
});
catNameText.anchor.set(0.5, 0);
catNameText.y = 100;
LK.gui.top.addChild(catNameText);
// Name cat button
var nameCatBtn = game.addChild(new GameButton('buyButton', 'Nommer mon chat', 824, 150));
nameCatBtn.attachAsset('buyButton', {}).tint = 0x2196F3;
// Cat customization button
var catCustomBtn = game.addChild(new GameButton('buyButton', 'Cat\'pers', 1224, 150));
catCustomBtn.attachAsset('buyButton', {}).tint = 0x9C27B0; // Purple
// Action Buttons
var feedBtn = game.addChild(new GameButton('feedButton', 'Feed (10)', 300, 2200));
var petBtn = game.addChild(new GameButton('petButton', 'Pet', 600, 2200));
var sleepBtn = game.addChild(new GameButton('sleepButton', 'Sleep (30)', 900, 2200));
var litterBtn = game.addChild(new GameButton('litterButton', 'Clean (14)', 1200, 2200));
var shopBtn = game.addChild(new GameButton('shopButton', 'Shop', 1500, 2200));
// Shop
var shop = game.addChild(new Shop());
shop.x = 1024;
shop.y = 1366;
// Cat Naming Interface
var catNaming = game.addChild(new CatNaming());
catNaming.x = 1024;
catNaming.y = 1366;
catNaming.setupNameOptions();
catNaming.setupHandlers();
// Cat Customization Interface
var catCustomization = game.addChild(new CatCustomization());
catCustomization.x = 1024;
catCustomization.y = 1366;
catCustomization.setupCatTypes();
catCustomization.setupHandlers();
// Set initial cat type
cat.setCatType(currentCatType);
// Pet cooldown indicator
var petCooldownText = new Text2('', {
	size: 30,
	fill: 0xFF0000
});
petCooldownText.anchor.set(0.5, 0);
petCooldownText.x = 600;
petCooldownText.y = 2280;
game.addChild(petCooldownText);
// Litter box indicator
var litterIndicator = new Text2('', {
	size: 30,
	fill: 0xFF0000
});
litterIndicator.anchor.set(0.5, 0);
litterIndicator.x = 1200;
litterIndicator.y = 2280;
game.addChild(litterIndicator);
function updateUI() {
	levelText.setText('Level: ' + currentLevel);
	xpText.setText('XP: ' + currentXP + '/' + xpRequired);
	kibbleText.setText('Kibble: ' + currentKibble);
	catNameText.setText('Cat: ' + currentCatName);
	storage.level = currentLevel;
	storage.xp = currentXP;
	storage.kibble = currentKibble;
	storage.lastPetTime = lastPetTime;
	storage.lastLitterTime = lastLitterTime;
	storage.ownedItems = ownedItems;
	storage.catName = currentCatName;
	storage.catType = currentCatType;
	storage.ownedCatTypes = ownedCatTypes;
}
function gainXP(amount) {
	currentXP += amount;
	if (currentXP >= xpRequired) {
		currentLevel++;
		currentXP -= xpRequired;
		xpRequired = 100 * Math.pow(2, currentLevel - 1);
		if (currentLevel >= 150) {
			LK.setTimeout(function () {
				// Reset everything
				storage.level = 1;
				storage.xp = 0;
				storage.kibble = 50;
				storage.lastPetTime = 0;
				storage.lastLitterTime = 0;
				storage.ownedItems = [];
				LK.showGameOver();
			}, 2000);
		}
		LK.effects.flashScreen(0xFFD700, 1000);
	}
	updateUI();
	// Start background music in loop
	LK.playMusic('backgroundMusic');
}
// Button handlers
feedBtn.up = function () {
	feedBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 10) {
		currentKibble -= 10;
		gainXP(5);
		cat.animate();
		LK.getSound('meow').play();
	}
};
petBtn.up = function () {
	petBtn.parent.parent.alpha = 0.7;
	var currentTime = Date.now();
	if (currentTime - lastPetTime >= 60000) {
		currentKibble += 3;
		lastPetTime = currentTime;
		cat.animate();
		LK.getSound('purr').play();
		updateUI();
	}
};
sleepBtn.up = function () {
	sleepBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 30) {
		currentKibble -= 30;
		gainXP(15);
		cat.animate();
		tween(cat, {
			alpha: 0.5
		}, {
			duration: 1000,
			onFinish: function onFinish() {
				tween(cat, {
					alpha: 1
				}, {
					duration: 1000
				});
			}
		});
	}
};
litterBtn.up = function () {
	litterBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 14) {
		currentKibble -= 14;
		lastLitterTime = Date.now();
		updateUI();
	}
};
shopBtn.up = function () {
	shopBtn.parent.parent.alpha = 0.7;
	shop.visible = true;
};
nameCatBtn.up = function () {
	nameCatBtn.parent.parent.alpha = 0.7;
	catNaming.visible = true;
};
catCustomBtn.up = function () {
	catCustomBtn.parent.parent.alpha = 0.7;
	catCustomization.visible = true;
	catCustomization.setupCatTypes();
	catCustomization.setupHandlers();
};
// Shop buy handlers
for (var i = 0; i < shop.itemButtons.length; i++) {
	var btn = shop.itemButtons[i];
	btn.up = function () {
		this.parent.parent.alpha = 0.7;
		if (currentKibble >= this.price && ownedItems.indexOf(this.itemId) === -1) {
			currentKibble -= this.price;
			ownedItems.push(this.itemId);
			cat.addAccessory(this.itemId);
			LK.getSound('purchase').play();
			updateUI();
		}
	};
}
game.update = function () {
	var currentTime = Date.now();
	// Pet cooldown
	var petCooldown = 60000 - (currentTime - lastPetTime);
	if (petCooldown > 0) {
		petCooldownText.setText('Pet: ' + Math.ceil(petCooldown / 1000) + 's');
	} else {
		petCooldownText.setText('');
	}
	// Litter box timer
	var litterTime = currentTime - lastLitterTime;
	if (litterTime >= 180000) {
		litterIndicator.setText('Clean needed!');
	} else {
		var remainingTime = 180000 - litterTime;
		litterIndicator.setText('Clean in: ' + Math.ceil(remainingTime / 1000) + 's');
	}
};
updateUI(); /**** 
* Plugins
****/ 
var storage = LK.import("@upit/storage.v1", {
	level: 1,
	xp: 0,
	kibble: 50,
	lastPetTime: 0,
	lastLitterTime: 0,
	ownedItems: [],
	catName: "Unnamed",
	catType: "basic",
	ownedCatTypes: ["basic"]
});
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var Cat = Container.expand(function () {
	var self = Container.call(this);
	var catSprite = self.attachAsset('cat', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.accessories = [];
	self.catSprite = catSprite;
	self.setCatType = function (typeId) {
		// Remove current cat sprite
		self.removeChild(self.catSprite);
		// Add new cat sprite based on type
		var assetId;
		switch (typeId) {
			case 'princess':
				assetId = 'catPrincess';
				break;
			case 'spider':
				assetId = 'catSpider';
				break;
			case 'bee':
				assetId = 'catBee';
				break;
			case 'white':
				assetId = 'catWhite';
				break;
			case 'fruit':
				assetId = 'catFruit';
				break;
			case 'pro':
				assetId = 'catPro';
				break;
			default:
				// basic
				assetId = 'cat';
				break;
		}
		self.catSprite = self.attachAsset(assetId, {
			anchorX: 0.5,
			anchorY: 0.5
		});
	};
	self.addAccessory = function (itemType) {
		var accessory = self.addChild(LK.getAsset(itemType, {
			anchorX: 0.5,
			anchorY: 0.5
		}));
		if (itemType === 'pinkHeadband' || itemType === 'blueHeadband') {
			accessory.y = -120;
		} else {
			accessory.x = Math.random() * 100 - 50;
			accessory.y = Math.random() * 100 - 50;
		}
		self.accessories.push(accessory);
	};
	self.animate = function () {
		tween(catSprite, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 300,
			easing: tween.easeInOut,
			onFinish: function onFinish() {
				tween(catSprite, {
					scaleX: 1,
					scaleY: 1
				}, {
					duration: 300,
					easing: tween.easeInOut
				});
			}
		});
	};
	return self;
});
var CatCustomization = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Cat\'pers - Personnalisez votre chat', {
		size: 45,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	self.catTypeButtons = [];
	self.setupCatTypes = function () {
		// Clear existing buttons
		for (var i = 0; i < self.catTypeButtons.length; i++) {
			self.removeChild(self.catTypeButtons[i]);
		}
		self.catTypeButtons = [];
		for (var i = 0; i < catTypes.length; i++) {
			var catType = catTypes[i];
			var yPos = -350 + i * 100;
			var nameText = new Text2(catType.name, {
				size: 35,
				fill: 0x333333
			});
			nameText.anchor.set(0, 0.5);
			nameText.x = -350;
			nameText.y = yPos;
			self.addChild(nameText);
			var priceText = new Text2(catType.price + ' croquettes', {
				size: 30,
				fill: 0x666666
			});
			priceText.anchor.set(0, 0.5);
			priceText.x = -350;
			priceText.y = yPos + 35;
			self.addChild(priceText);
			var isOwned = ownedCatTypes.indexOf(catType.id) !== -1;
			var isCurrent = currentCatType === catType.id;
			var buttonText = isCurrent ? 'Actuel' : isOwned ? 'Choisir' : 'Acheter';
			var button = self.addChild(new GameButton('buyButton', buttonText, 300, yPos));
			button.catTypeId = catType.id;
			button.catTypePrice = catType.price;
			button.isOwned = isOwned;
			button.isCurrent = isCurrent;
			if (isCurrent) {
				button.attachAsset('buyButton', {}).tint = 0x4CAF50; // Green for current
			} else if (isOwned) {
				button.attachAsset('buyButton', {}).tint = 0x2196F3; // Blue for owned
			}
			self.catTypeButtons.push(button);
		}
	};
	self.setupHandlers = function () {
		// Setup cat type button handlers
		for (var i = 0; i < self.catTypeButtons.length; i++) {
			var catTypeBtn = self.catTypeButtons[i];
			catTypeBtn.up = function () {
				this.parent.parent.alpha = 0.7;
				if (this.isCurrent) {
					// Already current type, do nothing
					return;
				}
				if (this.isOwned) {
					// Switch to owned cat type
					currentCatType = this.catTypeId;
					cat.setCatType(currentCatType);
					updateUI();
					catCustomization.visible = false;
				} else {
					// Try to buy cat type
					if (currentKibble >= this.catTypePrice) {
						currentKibble -= this.catTypePrice;
						ownedCatTypes.push(this.catTypeId);
						currentCatType = this.catTypeId;
						cat.setCatType(currentCatType);
						LK.getSound('purchase').play();
						updateUI();
						catCustomization.visible = false;
					}
				}
			};
		}
	};
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
var CatNaming = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Choose Your Cat\'s Name', {
		size: 50,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	self.nameOptions = [];
	self.choiceButtons = [];
	self.generateNames = function () {
		var shuffled = catNames.slice();
		for (var i = shuffled.length - 1; i > 0; i--) {
			var j = Math.floor(Math.random() * (i + 1));
			var temp = shuffled[i];
			shuffled[i] = shuffled[j];
			shuffled[j] = temp;
		}
		return [shuffled[0], shuffled[1], shuffled[2]];
	};
	self.setupNameOptions = function () {
		// Clear existing options
		for (var i = 0; i < self.nameOptions.length; i++) {
			self.removeChild(self.nameOptions[i]);
		}
		for (var i = 0; i < self.choiceButtons.length; i++) {
			self.removeChild(self.choiceButtons[i]);
		}
		self.nameOptions = [];
		self.choiceButtons = [];
		var names = self.generateNames();
		for (var i = 0; i < 3; i++) {
			var yPos = -200 + i * 120;
			var nameText = new Text2(names[i], {
				size: 45,
				fill: 0x333333
			});
			nameText.anchor.set(0.5, 0.5);
			nameText.x = -100;
			nameText.y = yPos;
			self.addChild(nameText);
			self.nameOptions.push(nameText);
			var choiceBtn = self.addChild(new GameButton('buyButton', 'Choose', 300, yPos));
			choiceBtn.catName = names[i];
			self.choiceButtons.push(choiceBtn);
		}
	};
	self.setupHandlers = function () {
		// Setup choice button handlers
		for (var i = 0; i < self.choiceButtons.length; i++) {
			var choiceBtn = self.choiceButtons[i];
			choiceBtn.up = function () {
				this.parent.parent.alpha = 0.7;
				currentCatName = this.catName;
				updateUI();
				catNaming.visible = false;
			};
		}
	};
	var generateBtn = self.addChild(new GameButton('buyButton', 'Generate 3 New Names', 0, 200));
	generateBtn.up = function () {
		generateBtn.parent.parent.alpha = 0.7;
		self.setupNameOptions();
		self.setupHandlers();
	};
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
var GameButton = Container.expand(function (assetId, text, x, y) {
	var self = Container.call(this);
	var buttonSprite = self.attachAsset(assetId, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var buttonText = new Text2(text, {
		size: 40,
		fill: 0xFFFFFF
	});
	buttonText.anchor.set(0.5, 0.5);
	self.addChild(buttonText);
	self.x = x;
	self.y = y;
	self.down = function () {
		buttonSprite.alpha = 0.7;
	};
	self.up = function () {
		buttonSprite.alpha = 1.0;
	};
	return self;
});
var Shop = Container.expand(function () {
	var self = Container.call(this);
	var panel = self.attachAsset('shopPanel', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var titleText = new Text2('Shop', {
		size: 60,
		fill: 0x333333
	});
	titleText.anchor.set(0.5, 0.5);
	titleText.y = -500;
	self.addChild(titleText);
	var closeBtn = self.addChild(new GameButton('closeButton', 'Close', 700, -500));
	var items = [{
		name: 'Dog Plushie',
		asset: 'dogPlushie',
		price: 10,
		id: 'dogPlushie'
	}, {
		name: 'Plastic Fish',
		asset: 'plasticFish',
		price: 20,
		id: 'plasticFish'
	}, {
		name: 'Pink Headband',
		asset: 'pinkHeadband',
		price: 30,
		id: 'pinkHeadband'
	}, {
		name: 'Blue Headband',
		asset: 'blueHeadband',
		price: 30,
		id: 'blueHeadband'
	}, {
		name: 'Mouse Toy',
		asset: 'mouseToy',
		price: 40,
		id: 'mouseToy'
	}];
	self.itemButtons = [];
	for (var i = 0; i < items.length; i++) {
		var item = items[i];
		var yPos = -200 + i * 150;
		var itemSprite = self.addChild(LK.getAsset(item.asset, {
			anchorX: 0.5,
			anchorY: 0.5,
			x: -300,
			y: yPos
		}));
		var nameText = new Text2(item.name, {
			size: 40,
			fill: 0x333333
		});
		nameText.anchor.set(0, 0.5);
		nameText.x = -200;
		nameText.y = yPos;
		self.addChild(nameText);
		var priceText = new Text2(item.price + ' kibble', {
			size: 35,
			fill: 0x666666
		});
		priceText.anchor.set(0, 0.5);
		priceText.x = -200;
		priceText.y = yPos + 40;
		self.addChild(priceText);
		var buyBtn = self.addChild(new GameButton('buyButton', 'Buy', 400, yPos));
		buyBtn.itemId = item.id;
		buyBtn.price = item.price;
		self.itemButtons.push(buyBtn);
	}
	closeBtn.up = function () {
		closeBtn.parent.parent.alpha = 0.7;
		self.visible = false;
	};
	self.visible = false;
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x87CEEB
});
/**** 
* Game Code
****/ 
var catNames = ['Shadow', 'Luna', 'Mittens', 'Whiskers', 'Simba', 'Nala', 'Felix', 'Garfield', 'Smokey', 'Tiger', 'Oreo', 'Patches', 'Boots', 'Socks', 'Pepper', 'Salt', 'Coco', 'Mimi', 'Bella', 'Charlie', 'Max', 'Oscar', 'Leo', 'Milo', 'Jasper', 'Oliver', 'Jack', 'Toby', 'George', 'Sam', 'Lucky', 'Buddy', 'Princess', 'Angel', 'Baby', 'Honey', 'Sugar', 'Cookie', 'Peanut', 'Ginger', 'Snowball', 'Fluffy', 'Fuzzy', 'Cuddles', 'Snuggles', 'Bubbles', 'Sparkles', 'Twinkle', 'Storm', 'Thunder', 'Lightning', 'Blaze', 'Flame', 'Ember', 'Ash', 'Dusty', 'Ruby', 'Emerald', 'Sapphire', 'Diamond', 'Pearl', 'Crystal', 'Jewel', 'Treasure', 'Magic', 'Mystery', 'Wonder', 'Dream'];
var catTypes = [{
	id: 'basic',
	name: 'Chat de base',
	price: 0,
	asset: 'cat'
}, {
	id: 'princess',
	name: 'Cutie princesse',
	price: 15,
	asset: 'catPrincess'
}, {
	id: 'spider',
	name: 'Spider\'cat',
	price: 10,
	asset: 'catSpider'
}, {
	id: 'bee',
	name: 'Bee cat',
	price: 18,
	asset: 'catBee'
}, {
	id: 'white',
	name: 'White cat',
	price: 16,
	asset: 'catWhite'
}, {
	id: 'fruit',
	name: 'Chat fan de fruits',
	price: 25,
	asset: 'catFruit'
}, {
	id: 'pro',
	name: 'Pro-cat',
	price: 30,
	asset: 'catPro'
}];
var currentLevel = storage.level;
var currentXP = storage.xp;
var currentKibble = storage.kibble;
var lastPetTime = storage.lastPetTime;
var lastLitterTime = storage.lastLitterTime;
var ownedItems = storage.ownedItems || [];
var currentCatName = storage.catName || 'Unnamed';
var currentCatType = storage.catType || 'basic';
var ownedCatTypes = storage.ownedCatTypes || ['basic'];
var xpRequired = 100 * Math.pow(2, currentLevel - 1);
// Add custom background
var backgroundImage = game.addChild(LK.getAsset('customBackground', {
	anchorX: 0.5,
	anchorY: 0.5
}));
backgroundImage.x = 1024;
backgroundImage.y = 1366;
var cat = game.addChild(new Cat());
cat.x = 1024;
cat.y = 800;
// Add owned accessories to cat
for (var i = 0; i < ownedItems.length; i++) {
	cat.addAccessory(ownedItems[i]);
}
// UI Elements
var levelText = new Text2('Level: ' + currentLevel, {
	size: 50,
	fill: 0x333333
});
levelText.anchor.set(0, 0);
levelText.x = 120;
levelText.y = 150;
LK.gui.topLeft.addChild(levelText);
var xpText = new Text2('XP: ' + currentXP + '/' + xpRequired, {
	size: 40,
	fill: 0x333333
});
xpText.anchor.set(0, 0);
xpText.x = 120;
xpText.y = 220;
LK.gui.topLeft.addChild(xpText);
var kibbleText = new Text2('Kibble: ' + currentKibble, {
	size: 45,
	fill: 0x333333
});
kibbleText.anchor.set(1, 0);
LK.gui.topRight.addChild(kibbleText);
// Cat name display
var catNameText = new Text2('Cat: ' + currentCatName, {
	size: 40,
	fill: 0x333333
});
catNameText.anchor.set(0.5, 0);
catNameText.y = 100;
LK.gui.top.addChild(catNameText);
// Name cat button
var nameCatBtn = game.addChild(new GameButton('buyButton', 'Nommer mon chat', 824, 150));
nameCatBtn.attachAsset('buyButton', {}).tint = 0x2196F3;
// Cat customization button
var catCustomBtn = game.addChild(new GameButton('buyButton', 'Cat\'pers', 1224, 150));
catCustomBtn.attachAsset('buyButton', {}).tint = 0x9C27B0; // Purple
// Action Buttons
var feedBtn = game.addChild(new GameButton('feedButton', 'Feed (10)', 300, 2200));
var petBtn = game.addChild(new GameButton('petButton', 'Pet', 600, 2200));
var sleepBtn = game.addChild(new GameButton('sleepButton', 'Sleep (30)', 900, 2200));
var litterBtn = game.addChild(new GameButton('litterButton', 'Clean (14)', 1200, 2200));
var shopBtn = game.addChild(new GameButton('shopButton', 'Shop', 1500, 2200));
// Shop
var shop = game.addChild(new Shop());
shop.x = 1024;
shop.y = 1366;
// Cat Naming Interface
var catNaming = game.addChild(new CatNaming());
catNaming.x = 1024;
catNaming.y = 1366;
catNaming.setupNameOptions();
catNaming.setupHandlers();
// Cat Customization Interface
var catCustomization = game.addChild(new CatCustomization());
catCustomization.x = 1024;
catCustomization.y = 1366;
catCustomization.setupCatTypes();
catCustomization.setupHandlers();
// Set initial cat type
cat.setCatType(currentCatType);
// Pet cooldown indicator
var petCooldownText = new Text2('', {
	size: 30,
	fill: 0xFF0000
});
petCooldownText.anchor.set(0.5, 0);
petCooldownText.x = 600;
petCooldownText.y = 2280;
game.addChild(petCooldownText);
// Litter box indicator
var litterIndicator = new Text2('', {
	size: 30,
	fill: 0xFF0000
});
litterIndicator.anchor.set(0.5, 0);
litterIndicator.x = 1200;
litterIndicator.y = 2280;
game.addChild(litterIndicator);
function updateUI() {
	levelText.setText('Level: ' + currentLevel);
	xpText.setText('XP: ' + currentXP + '/' + xpRequired);
	kibbleText.setText('Kibble: ' + currentKibble);
	catNameText.setText('Cat: ' + currentCatName);
	storage.level = currentLevel;
	storage.xp = currentXP;
	storage.kibble = currentKibble;
	storage.lastPetTime = lastPetTime;
	storage.lastLitterTime = lastLitterTime;
	storage.ownedItems = ownedItems;
	storage.catName = currentCatName;
	storage.catType = currentCatType;
	storage.ownedCatTypes = ownedCatTypes;
}
function gainXP(amount) {
	currentXP += amount;
	if (currentXP >= xpRequired) {
		currentLevel++;
		currentXP -= xpRequired;
		xpRequired = 100 * Math.pow(2, currentLevel - 1);
		if (currentLevel >= 150) {
			LK.setTimeout(function () {
				// Reset everything
				storage.level = 1;
				storage.xp = 0;
				storage.kibble = 50;
				storage.lastPetTime = 0;
				storage.lastLitterTime = 0;
				storage.ownedItems = [];
				LK.showGameOver();
			}, 2000);
		}
		LK.effects.flashScreen(0xFFD700, 1000);
	}
	updateUI();
	// Start background music in loop
	LK.playMusic('backgroundMusic');
}
// Button handlers
feedBtn.up = function () {
	feedBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 10) {
		currentKibble -= 10;
		gainXP(5);
		cat.animate();
		LK.getSound('meow').play();
	}
};
petBtn.up = function () {
	petBtn.parent.parent.alpha = 0.7;
	var currentTime = Date.now();
	if (currentTime - lastPetTime >= 60000) {
		currentKibble += 3;
		lastPetTime = currentTime;
		cat.animate();
		LK.getSound('purr').play();
		updateUI();
	}
};
sleepBtn.up = function () {
	sleepBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 30) {
		currentKibble -= 30;
		gainXP(15);
		cat.animate();
		tween(cat, {
			alpha: 0.5
		}, {
			duration: 1000,
			onFinish: function onFinish() {
				tween(cat, {
					alpha: 1
				}, {
					duration: 1000
				});
			}
		});
	}
};
litterBtn.up = function () {
	litterBtn.parent.parent.alpha = 0.7;
	if (currentKibble >= 14) {
		currentKibble -= 14;
		lastLitterTime = Date.now();
		updateUI();
	}
};
shopBtn.up = function () {
	shopBtn.parent.parent.alpha = 0.7;
	shop.visible = true;
};
nameCatBtn.up = function () {
	nameCatBtn.parent.parent.alpha = 0.7;
	catNaming.visible = true;
};
catCustomBtn.up = function () {
	catCustomBtn.parent.parent.alpha = 0.7;
	catCustomization.visible = true;
	catCustomization.setupCatTypes();
	catCustomization.setupHandlers();
};
// Shop buy handlers
for (var i = 0; i < shop.itemButtons.length; i++) {
	var btn = shop.itemButtons[i];
	btn.up = function () {
		this.parent.parent.alpha = 0.7;
		if (currentKibble >= this.price && ownedItems.indexOf(this.itemId) === -1) {
			currentKibble -= this.price;
			ownedItems.push(this.itemId);
			cat.addAccessory(this.itemId);
			LK.getSound('purchase').play();
			updateUI();
		}
	};
}
game.update = function () {
	var currentTime = Date.now();
	// Pet cooldown
	var petCooldown = 60000 - (currentTime - lastPetTime);
	if (petCooldown > 0) {
		petCooldownText.setText('Pet: ' + Math.ceil(petCooldown / 1000) + 's');
	} else {
		petCooldownText.setText('');
	}
	// Litter box timer
	var litterTime = currentTime - lastLitterTime;
	if (litterTime >= 180000) {
		litterIndicator.setText('Clean needed!');
	} else {
		var remainingTime = 180000 - litterTime;
		litterIndicator.setText('Clean in: ' + Math.ceil(remainingTime / 1000) + 's');
	}
};
updateUI();
:quality(85)/https://cdn.frvr.ai/68502047dd790260ae7e19e1.png%3F3) 
 Chat (animal). In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6850208edd790260ae7e19f0.png%3F3) 
 feed boutton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68502113dd790260ae7e19fa.png%3F3) 
 dogPlushie. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6850213cdd790260ae7e1a05.png%3F3) 
 petButton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68502165dd790260ae7e1a13.png%3F3) 
 buyButton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6850218bdd790260ae7e1a1d.png%3F3) 
 sleepButton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/685021afdd790260ae7e1a27.png%3F3) 
 litterButton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/685021d5dd790260ae7e1a33.png%3F3) 
 shopButton. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/685021fedd790260ae7e1a3a.png%3F3) 
 shopPanel. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68502237dd790260ae7e1a47.png%3F3) 
 plasticFish. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68502262dd790260ae7e1a52.png%3F3) 
 pinkHeadband. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6850228fdd790260ae7e1a5d.png%3F3) 
 blueHeadband. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/685022c0dd790260ae7e1a6b.png%3F3) 
 mouseToy. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/68502641dd790260ae7e1aa3.png%3F3) 
 Fond d'eÌcran appartement. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a3ceecd93889e1d41413.png%3F3) 
 Chat (animal) a la fourrure couleur abeille et avec des ailes. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a412ecd93889e1d41423.png%3F3) 
 Chat (animal) a la fourrure araigneÌes. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a483ecd93889e1d4142c.png%3F3) 
 Chatonne (fille chat) au pelage rose princesse avec un diadeÌme de princesse sur la teÌte. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a4c0ecd93889e1d41439.png%3F3) 
 White cat. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a4f6ecd93889e1d41445.png%3F3) 
 Chat (animal), au pelage couleur fruit. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/6853a525ecd93889e1d41452.png%3F3) 
 Cat avec des lunettes et un cravate. In-Game asset. 2d. High contrast. No shadows