/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var CoffeeBean = Container.expand(function (type) {
	var self = Container.call(this);
	var beanType = type || 'arabica';
	var beanGraphics = self.attachAsset(beanType + 'Bean', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.beanType = beanType;
	self.speed = 3;
	self.points = beanType === 'espresso' ? 10 : beanType === 'arabica' ? 5 : 3;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var CoffeeCup = Container.expand(function () {
	var self = Container.call(this);
	var cupGraphics = self.attachAsset('coffeeCup', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.speed = 8;
	self.isDragging = false;
	return self;
});
var Obstacle = Container.expand(function (type) {
	var self = Container.call(this);
	var obstacleType = type || 'spilledMilk';
	var obstacleGraphics = self.attachAsset(obstacleType, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.obstacleType = obstacleType;
	self.speed = 4;
	self.penalty = obstacleType === 'spilledMilk' ? 5 : 3;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var ShopMenu = Container.expand(function () {
	var self = Container.call(this);
	// Semi-transparent background
	var background = LK.getAsset('coffeeCup', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 20,
		scaleY: 30
	});
	background.alpha = 0.8;
	background.tint = 0x2c1810;
	self.addChild(background);
	// Shop title
	var titleTxt = new Text2('COFFEE SHOP', {
		size: 80,
		fill: 0xFFFFFF
	});
	titleTxt.anchor.set(0.5, 0.5);
	titleTxt.x = 0;
	titleTxt.y = -800;
	self.addChild(titleTxt);
	// Shop items
	var items = [{
		name: 'Faster Cup',
		price: 100,
		description: 'Increases cup speed'
	}, {
		name: 'Bean Magnet',
		price: 200,
		description: 'Attracts nearby beans'
	}, {
		name: 'Extra Life',
		price: 150,
		description: 'Restore satisfaction'
	}];
	var itemButtons = [];
	for (var i = 0; i < items.length; i++) {
		var item = items[i];
		var buttonY = -400 + i * 200;
		// Item button
		var itemButton = LK.getAsset('shopButton', {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 2,
			scaleY: 1.5
		});
		itemButton.x = 0;
		itemButton.y = buttonY;
		itemButton.tint = 0x654321;
		self.addChild(itemButton);
		// Item text
		var itemTxt = new Text2(item.name, {
			size: 50,
			fill: 0xFFFFFF
		});
		itemTxt.anchor.set(0.5, 0.5);
		itemTxt.x = 0;
		itemTxt.y = buttonY - 20;
		self.addChild(itemTxt);
		// Price text
		var priceTxt = new Text2('$' + item.price, {
			size: 40,
			fill: 0xFFFF00
		});
		priceTxt.anchor.set(0.5, 0.5);
		priceTxt.x = 0;
		priceTxt.y = buttonY + 20;
		self.addChild(priceTxt);
		itemButtons.push(itemButton);
	}
	// Close button
	var closeButton = LK.getAsset('shopButton', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1.5,
		scaleY: 1
	});
	closeButton.x = 0;
	closeButton.y = 600;
	closeButton.tint = 0x8b0000;
	self.addChild(closeButton);
	var closeTxt = new Text2('CLOSE', {
		size: 50,
		fill: 0xFFFFFF
	});
	closeTxt.anchor.set(0.5, 0.5);
	closeTxt.x = 0;
	closeTxt.y = 600;
	self.addChild(closeTxt);
	// Close button handler
	closeButton.down = function (x, y, obj) {
		LK.effects.flashObject(closeButton, 0xffffff, 300);
		if (currentShopMenu) {
			currentShopMenu.destroy();
			currentShopMenu = null;
		}
	};
	// Item button handlers
	for (var j = 0; j < itemButtons.length; j++) {
		(function (index) {
			itemButtons[index].down = function (x, y, obj) {
				LK.effects.flashObject(itemButtons[index], 0xffffff, 300);
				var item = items[index];
				if (LK.getScore() >= item.price) {
					LK.setScore(LK.getScore() - item.price);
					scoreTxt.setText('Score: ' + LK.getScore());
					// Apply item effects here
					if (item.name === 'Extra Life') {
						customerSatisfaction = Math.min(100, customerSatisfaction + 30);
						updateSatisfactionDisplay();
					}
				} else {
					// Show insufficient funds message
					var errorMsg = new Text2('Insufficient Funds!', {
						size: 60,
						fill: 0xff0000
					});
					errorMsg.anchor.set(0.5, 0.5);
					errorMsg.x = 0;
					errorMsg.y = 400;
					self.addChild(errorMsg);
					LK.setTimeout(function () {
						errorMsg.destroy();
					}, 1500);
				}
			};
		})(j);
	}
	return self;
});
var SteamEffect = Container.expand(function () {
	var self = Container.call(this);
	var steamGraphics = self.attachAsset('steamEffect', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.life = 60;
	self.speed = -1;
	self.update = function () {
		self.y += self.speed;
		self.life--;
		steamGraphics.alpha = self.life / 60;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x8B4513
});
/**** 
* Game Code
****/ 
// Game variables
// Coffee cups
// Coffee beans
// Obstacles
// Sounds
var coffeeCup;
var beans = [];
var obstacles = [];
var steamEffects = [];
var dragNode = null;
var gameSpeed = 1;
var customerSatisfaction = 100;
var targetScore = 25;
var currentLevel = 1;
var spawnTimer = 0;
var difficultyTimer = 0;
var steamTimer = 0;
var currentShopMenu = null;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
	size: 60,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120; // Offset from left to avoid platform menu
LK.gui.topLeft.addChild(scoreTxt);
var satisfactionTxt = new Text2('Satisfaction: 100%', {
	size: 50,
	fill: 0x00FF00
});
satisfactionTxt.anchor.set(0.5, 0);
satisfactionTxt.x = -300; // Increased offset from center
satisfactionTxt.y = 80; // Move down to avoid overlap
LK.gui.top.addChild(satisfactionTxt);
var targetTxt = new Text2('Target: ' + targetScore, {
	size: 45,
	fill: 0xFFFF00
});
targetTxt.anchor.set(0.5, 0);
targetTxt.x = 300; // Increased offset from center
targetTxt.y = 80; // Move down to avoid overlap
LK.gui.top.addChild(targetTxt);
var levelTxt = new Text2('Level: ' + currentLevel, {
	size: 50,
	fill: 0x87CEEB
});
levelTxt.anchor.set(1, 0);
levelTxt.x = -120; // Offset from right to avoid platform menu
LK.gui.topRight.addChild(levelTxt);
// Shop button
var shopButton = LK.getAsset('shopButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
var shopButtonTxt = new Text2('SHOP', {
	size: 40,
	fill: 0xFFFFFF
});
shopButtonTxt.anchor.set(0.5, 0.5);
shopButton.addChild(shopButtonTxt);
shopButton.x = 0;
shopButton.y = 150;
LK.gui.top.addChild(shopButton);
// Create coffee shop background elements
// Floor tiles
for (var tileX = 0; tileX < 21; tileX++) {
	for (var tileY = 0; tileY < 5; tileY++) {
		var tile = LK.getAsset('tile', {
			anchorX: 0,
			anchorY: 0
		});
		tile.x = tileX * 100;
		tile.y = 2300 + tileY * 100;
		tile.alpha = 0.7;
		game.addChild(tile);
	}
}
// Wooden counter
var counter = LK.getAsset('woodCounter', {
	anchorX: 0,
	anchorY: 0
});
counter.x = 0;
counter.y = 2200;
counter.alpha = 0.8;
game.addChild(counter);
// Coffee machine
var coffeeMachine = LK.getAsset('coffeeMachine', {
	anchorX: 0.5,
	anchorY: 1
});
coffeeMachine.x = 300;
coffeeMachine.y = 2200;
game.addChild(coffeeMachine);
// Shelves with coffee supplies
var shelf1 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf1.x = 100;
shelf1.y = 1800;
shelf1.tint = 0x654321;
game.addChild(shelf1);
var shelf2 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf2.x = 1700;
shelf2.y = 1800;
shelf2.tint = 0x654321;
game.addChild(shelf2);
var shelf3 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf3.x = 900;
shelf3.y = 1600;
shelf3.tint = 0x654321;
game.addChild(shelf3);
// Initialize coffee cup
coffeeCup = game.addChild(new CoffeeCup());
coffeeCup.x = 1024; // Center of screen
coffeeCup.y = 2500; // Near bottom
// Start coffee music
LK.playMusic('coffee');
// Shop button click handler
shopButton.down = function (x, y, obj) {
	// Flash button to show it was clicked
	LK.effects.flashObject(shopButton, 0xffffff, 300);
	// Open shop menu if not already open
	if (!currentShopMenu) {
		currentShopMenu = new ShopMenu();
		currentShopMenu.x = 1024;
		currentShopMenu.y = 1366;
		game.addChild(currentShopMenu);
	}
};
// Spawn functions
function spawnBean() {
	var beanTypes = ['espresso', 'arabica', 'robusta'];
	var randomType = beanTypes[Math.floor(Math.random() * beanTypes.length)];
	var newBean = new CoffeeBean(randomType);
	newBean.x = Math.random() * (2048 - 100) + 50;
	newBean.y = -50;
	newBean.speed = 3 + gameSpeed;
	beans.push(newBean);
	game.addChild(newBean);
}
function spawnObstacle() {
	var obstacleTypes = ['spilledMilk', 'sugarCube'];
	var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
	var newObstacle = new Obstacle(randomType);
	newObstacle.x = Math.random() * (2048 - 100) + 50;
	newObstacle.y = -50;
	newObstacle.speed = 4 + gameSpeed;
	obstacles.push(newObstacle);
	game.addChild(newObstacle);
}
// Event handlers
function handleMove(x, y, obj) {
	if (dragNode) {
		dragNode.x = Math.max(60, Math.min(1988, x));
	}
}
game.move = handleMove;
game.down = function (x, y, obj) {
	// Set drag node to coffee cup to enable dragging
	dragNode = coffeeCup;
	coffeeCup.isDragging = true;
	handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
	if (dragNode) {
		dragNode.isDragging = false;
		dragNode = null;
	}
};
// Update satisfaction display
function updateSatisfactionDisplay() {
	satisfactionTxt.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
	if (customerSatisfaction > 70) {
		satisfactionTxt.fill = "#00ff00";
	} else if (customerSatisfaction > 30) {
		satisfactionTxt.fill = "#ffff00";
	} else {
		satisfactionTxt.fill = "#ff0000";
	}
}
// Main game loop
game.update = function () {
	spawnTimer++;
	difficultyTimer++;
	steamTimer++;
	// Spawn steam effects from coffee cup
	if (steamTimer % 30 === 0) {
		var newSteam = new SteamEffect();
		newSteam.x = coffeeCup.x + (Math.random() - 0.5) * 40;
		newSteam.y = coffeeCup.y - 40;
		steamEffects.push(newSteam);
		game.addChild(newSteam);
	}
	// Spawn beans and obstacles
	if (spawnTimer % (90 - Math.floor(gameSpeed * 10)) === 0) {
		spawnBean();
	}
	if (spawnTimer % 180 === 0) {
		spawnObstacle();
	}
	// Increase difficulty over time
	if (difficultyTimer % 1800 === 0) {
		// Every 30 seconds
		gameSpeed += 0.5;
	}
	// Update and check beans
	for (var i = beans.length - 1; i >= 0; i--) {
		var bean = beans[i];
		if (bean.lastY === undefined) bean.lastY = bean.y;
		// Check if bean is caught by cup
		if (bean.intersects(coffeeCup)) {
			LK.setScore(LK.getScore() + bean.points);
			scoreTxt.setText('Score: ' + LK.getScore());
			LK.getSound('catch').play();
			// Flash cup green
			LK.effects.flashObject(coffeeCup, 0x00ff00, 300);
			bean.destroy();
			beans.splice(i, 1);
			continue;
		}
		// Check if bean fell off screen
		if (bean.lastY < 2732 && bean.y >= 2732) {
			customerSatisfaction -= 2;
			updateSatisfactionDisplay();
			bean.destroy();
			beans.splice(i, 1);
			continue;
		}
		bean.lastY = bean.y;
	}
	// Update and check obstacles
	for (var j = obstacles.length - 1; j >= 0; j--) {
		var obstacle = obstacles[j];
		if (obstacle.lastY === undefined) obstacle.lastY = obstacle.y;
		// Check if obstacle hits cup
		if (obstacle.intersects(coffeeCup)) {
			LK.setScore(Math.max(0, LK.getScore() - obstacle.penalty));
			scoreTxt.setText('Score: ' + LK.getScore());
			customerSatisfaction -= obstacle.penalty;
			updateSatisfactionDisplay();
			LK.getSound('obstacle').play();
			// Flash cup red
			LK.effects.flashObject(coffeeCup, 0xff0000, 500);
			obstacle.destroy();
			obstacles.splice(j, 1);
			continue;
		}
		// Remove obstacle if it falls off screen
		if (obstacle.lastY < 2732 && obstacle.y >= 2732) {
			obstacle.destroy();
			obstacles.splice(j, 1);
			continue;
		}
		obstacle.lastY = obstacle.y;
	}
	// Update and clean steam effects
	for (var k = steamEffects.length - 1; k >= 0; k--) {
		var steam = steamEffects[k];
		if (steam.life <= 0) {
			steam.destroy();
			steamEffects.splice(k, 1);
		}
	}
	// Check win condition - advance to next level
	if (LK.getScore() >= targetScore) {
		currentLevel++;
		targetScore += 25;
		gameSpeed += 0.3;
		customerSatisfaction = Math.min(100, customerSatisfaction + 20);
		// Update UI
		levelTxt.setText('Level: ' + currentLevel);
		targetTxt.setText('Target: ' + targetScore);
		updateSatisfactionDisplay();
		LK.getSound('levelup').play();
		LK.effects.flashScreen(0x00ff00, 500);
	}
	// Check lose condition
	if (customerSatisfaction <= 0) {
		LK.showGameOver();
	}
	// Gradually decrease satisfaction over time
	if (LK.ticks % 300 === 0) {
		// Every 5 seconds
		customerSatisfaction = Math.max(0, customerSatisfaction - 1);
		updateSatisfactionDisplay();
	}
}; /**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var CoffeeBean = Container.expand(function (type) {
	var self = Container.call(this);
	var beanType = type || 'arabica';
	var beanGraphics = self.attachAsset(beanType + 'Bean', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.beanType = beanType;
	self.speed = 3;
	self.points = beanType === 'espresso' ? 10 : beanType === 'arabica' ? 5 : 3;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var CoffeeCup = Container.expand(function () {
	var self = Container.call(this);
	var cupGraphics = self.attachAsset('coffeeCup', {
		anchorX: 0.5,
		anchorY: 1.0
	});
	self.speed = 8;
	self.isDragging = false;
	return self;
});
var Obstacle = Container.expand(function (type) {
	var self = Container.call(this);
	var obstacleType = type || 'spilledMilk';
	var obstacleGraphics = self.attachAsset(obstacleType, {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.obstacleType = obstacleType;
	self.speed = 4;
	self.penalty = obstacleType === 'spilledMilk' ? 5 : 3;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
var ShopMenu = Container.expand(function () {
	var self = Container.call(this);
	// Semi-transparent background
	var background = LK.getAsset('coffeeCup', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 20,
		scaleY: 30
	});
	background.alpha = 0.8;
	background.tint = 0x2c1810;
	self.addChild(background);
	// Shop title
	var titleTxt = new Text2('COFFEE SHOP', {
		size: 80,
		fill: 0xFFFFFF
	});
	titleTxt.anchor.set(0.5, 0.5);
	titleTxt.x = 0;
	titleTxt.y = -800;
	self.addChild(titleTxt);
	// Shop items
	var items = [{
		name: 'Faster Cup',
		price: 100,
		description: 'Increases cup speed'
	}, {
		name: 'Bean Magnet',
		price: 200,
		description: 'Attracts nearby beans'
	}, {
		name: 'Extra Life',
		price: 150,
		description: 'Restore satisfaction'
	}];
	var itemButtons = [];
	for (var i = 0; i < items.length; i++) {
		var item = items[i];
		var buttonY = -400 + i * 200;
		// Item button
		var itemButton = LK.getAsset('shopButton', {
			anchorX: 0.5,
			anchorY: 0.5,
			scaleX: 2,
			scaleY: 1.5
		});
		itemButton.x = 0;
		itemButton.y = buttonY;
		itemButton.tint = 0x654321;
		self.addChild(itemButton);
		// Item text
		var itemTxt = new Text2(item.name, {
			size: 50,
			fill: 0xFFFFFF
		});
		itemTxt.anchor.set(0.5, 0.5);
		itemTxt.x = 0;
		itemTxt.y = buttonY - 20;
		self.addChild(itemTxt);
		// Price text
		var priceTxt = new Text2('$' + item.price, {
			size: 40,
			fill: 0xFFFF00
		});
		priceTxt.anchor.set(0.5, 0.5);
		priceTxt.x = 0;
		priceTxt.y = buttonY + 20;
		self.addChild(priceTxt);
		itemButtons.push(itemButton);
	}
	// Close button
	var closeButton = LK.getAsset('shopButton', {
		anchorX: 0.5,
		anchorY: 0.5,
		scaleX: 1.5,
		scaleY: 1
	});
	closeButton.x = 0;
	closeButton.y = 600;
	closeButton.tint = 0x8b0000;
	self.addChild(closeButton);
	var closeTxt = new Text2('CLOSE', {
		size: 50,
		fill: 0xFFFFFF
	});
	closeTxt.anchor.set(0.5, 0.5);
	closeTxt.x = 0;
	closeTxt.y = 600;
	self.addChild(closeTxt);
	// Close button handler
	closeButton.down = function (x, y, obj) {
		LK.effects.flashObject(closeButton, 0xffffff, 300);
		if (currentShopMenu) {
			currentShopMenu.destroy();
			currentShopMenu = null;
		}
	};
	// Item button handlers
	for (var j = 0; j < itemButtons.length; j++) {
		(function (index) {
			itemButtons[index].down = function (x, y, obj) {
				LK.effects.flashObject(itemButtons[index], 0xffffff, 300);
				var item = items[index];
				if (LK.getScore() >= item.price) {
					LK.setScore(LK.getScore() - item.price);
					scoreTxt.setText('Score: ' + LK.getScore());
					// Apply item effects here
					if (item.name === 'Extra Life') {
						customerSatisfaction = Math.min(100, customerSatisfaction + 30);
						updateSatisfactionDisplay();
					}
				} else {
					// Show insufficient funds message
					var errorMsg = new Text2('Insufficient Funds!', {
						size: 60,
						fill: 0xff0000
					});
					errorMsg.anchor.set(0.5, 0.5);
					errorMsg.x = 0;
					errorMsg.y = 400;
					self.addChild(errorMsg);
					LK.setTimeout(function () {
						errorMsg.destroy();
					}, 1500);
				}
			};
		})(j);
	}
	return self;
});
var SteamEffect = Container.expand(function () {
	var self = Container.call(this);
	var steamGraphics = self.attachAsset('steamEffect', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.life = 60;
	self.speed = -1;
	self.update = function () {
		self.y += self.speed;
		self.life--;
		steamGraphics.alpha = self.life / 60;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x8B4513
});
/**** 
* Game Code
****/ 
// Game variables
// Coffee cups
// Coffee beans
// Obstacles
// Sounds
var coffeeCup;
var beans = [];
var obstacles = [];
var steamEffects = [];
var dragNode = null;
var gameSpeed = 1;
var customerSatisfaction = 100;
var targetScore = 25;
var currentLevel = 1;
var spawnTimer = 0;
var difficultyTimer = 0;
var steamTimer = 0;
var currentShopMenu = null;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
	size: 60,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(0, 0);
scoreTxt.x = 120; // Offset from left to avoid platform menu
LK.gui.topLeft.addChild(scoreTxt);
var satisfactionTxt = new Text2('Satisfaction: 100%', {
	size: 50,
	fill: 0x00FF00
});
satisfactionTxt.anchor.set(0.5, 0);
satisfactionTxt.x = -300; // Increased offset from center
satisfactionTxt.y = 80; // Move down to avoid overlap
LK.gui.top.addChild(satisfactionTxt);
var targetTxt = new Text2('Target: ' + targetScore, {
	size: 45,
	fill: 0xFFFF00
});
targetTxt.anchor.set(0.5, 0);
targetTxt.x = 300; // Increased offset from center
targetTxt.y = 80; // Move down to avoid overlap
LK.gui.top.addChild(targetTxt);
var levelTxt = new Text2('Level: ' + currentLevel, {
	size: 50,
	fill: 0x87CEEB
});
levelTxt.anchor.set(1, 0);
levelTxt.x = -120; // Offset from right to avoid platform menu
LK.gui.topRight.addChild(levelTxt);
// Shop button
var shopButton = LK.getAsset('shopButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
var shopButtonTxt = new Text2('SHOP', {
	size: 40,
	fill: 0xFFFFFF
});
shopButtonTxt.anchor.set(0.5, 0.5);
shopButton.addChild(shopButtonTxt);
shopButton.x = 0;
shopButton.y = 150;
LK.gui.top.addChild(shopButton);
// Create coffee shop background elements
// Floor tiles
for (var tileX = 0; tileX < 21; tileX++) {
	for (var tileY = 0; tileY < 5; tileY++) {
		var tile = LK.getAsset('tile', {
			anchorX: 0,
			anchorY: 0
		});
		tile.x = tileX * 100;
		tile.y = 2300 + tileY * 100;
		tile.alpha = 0.7;
		game.addChild(tile);
	}
}
// Wooden counter
var counter = LK.getAsset('woodCounter', {
	anchorX: 0,
	anchorY: 0
});
counter.x = 0;
counter.y = 2200;
counter.alpha = 0.8;
game.addChild(counter);
// Coffee machine
var coffeeMachine = LK.getAsset('coffeeMachine', {
	anchorX: 0.5,
	anchorY: 1
});
coffeeMachine.x = 300;
coffeeMachine.y = 2200;
game.addChild(coffeeMachine);
// Shelves with coffee supplies
var shelf1 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf1.x = 100;
shelf1.y = 1800;
shelf1.tint = 0x654321;
game.addChild(shelf1);
var shelf2 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf2.x = 1700;
shelf2.y = 1800;
shelf2.tint = 0x654321;
game.addChild(shelf2);
var shelf3 = LK.getAsset('shelf', {
	anchorX: 0,
	anchorY: 0
});
shelf3.x = 900;
shelf3.y = 1600;
shelf3.tint = 0x654321;
game.addChild(shelf3);
// Initialize coffee cup
coffeeCup = game.addChild(new CoffeeCup());
coffeeCup.x = 1024; // Center of screen
coffeeCup.y = 2500; // Near bottom
// Start coffee music
LK.playMusic('coffee');
// Shop button click handler
shopButton.down = function (x, y, obj) {
	// Flash button to show it was clicked
	LK.effects.flashObject(shopButton, 0xffffff, 300);
	// Open shop menu if not already open
	if (!currentShopMenu) {
		currentShopMenu = new ShopMenu();
		currentShopMenu.x = 1024;
		currentShopMenu.y = 1366;
		game.addChild(currentShopMenu);
	}
};
// Spawn functions
function spawnBean() {
	var beanTypes = ['espresso', 'arabica', 'robusta'];
	var randomType = beanTypes[Math.floor(Math.random() * beanTypes.length)];
	var newBean = new CoffeeBean(randomType);
	newBean.x = Math.random() * (2048 - 100) + 50;
	newBean.y = -50;
	newBean.speed = 3 + gameSpeed;
	beans.push(newBean);
	game.addChild(newBean);
}
function spawnObstacle() {
	var obstacleTypes = ['spilledMilk', 'sugarCube'];
	var randomType = obstacleTypes[Math.floor(Math.random() * obstacleTypes.length)];
	var newObstacle = new Obstacle(randomType);
	newObstacle.x = Math.random() * (2048 - 100) + 50;
	newObstacle.y = -50;
	newObstacle.speed = 4 + gameSpeed;
	obstacles.push(newObstacle);
	game.addChild(newObstacle);
}
// Event handlers
function handleMove(x, y, obj) {
	if (dragNode) {
		dragNode.x = Math.max(60, Math.min(1988, x));
	}
}
game.move = handleMove;
game.down = function (x, y, obj) {
	// Set drag node to coffee cup to enable dragging
	dragNode = coffeeCup;
	coffeeCup.isDragging = true;
	handleMove(x, y, obj);
};
game.up = function (x, y, obj) {
	if (dragNode) {
		dragNode.isDragging = false;
		dragNode = null;
	}
};
// Update satisfaction display
function updateSatisfactionDisplay() {
	satisfactionTxt.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
	if (customerSatisfaction > 70) {
		satisfactionTxt.fill = "#00ff00";
	} else if (customerSatisfaction > 30) {
		satisfactionTxt.fill = "#ffff00";
	} else {
		satisfactionTxt.fill = "#ff0000";
	}
}
// Main game loop
game.update = function () {
	spawnTimer++;
	difficultyTimer++;
	steamTimer++;
	// Spawn steam effects from coffee cup
	if (steamTimer % 30 === 0) {
		var newSteam = new SteamEffect();
		newSteam.x = coffeeCup.x + (Math.random() - 0.5) * 40;
		newSteam.y = coffeeCup.y - 40;
		steamEffects.push(newSteam);
		game.addChild(newSteam);
	}
	// Spawn beans and obstacles
	if (spawnTimer % (90 - Math.floor(gameSpeed * 10)) === 0) {
		spawnBean();
	}
	if (spawnTimer % 180 === 0) {
		spawnObstacle();
	}
	// Increase difficulty over time
	if (difficultyTimer % 1800 === 0) {
		// Every 30 seconds
		gameSpeed += 0.5;
	}
	// Update and check beans
	for (var i = beans.length - 1; i >= 0; i--) {
		var bean = beans[i];
		if (bean.lastY === undefined) bean.lastY = bean.y;
		// Check if bean is caught by cup
		if (bean.intersects(coffeeCup)) {
			LK.setScore(LK.getScore() + bean.points);
			scoreTxt.setText('Score: ' + LK.getScore());
			LK.getSound('catch').play();
			// Flash cup green
			LK.effects.flashObject(coffeeCup, 0x00ff00, 300);
			bean.destroy();
			beans.splice(i, 1);
			continue;
		}
		// Check if bean fell off screen
		if (bean.lastY < 2732 && bean.y >= 2732) {
			customerSatisfaction -= 2;
			updateSatisfactionDisplay();
			bean.destroy();
			beans.splice(i, 1);
			continue;
		}
		bean.lastY = bean.y;
	}
	// Update and check obstacles
	for (var j = obstacles.length - 1; j >= 0; j--) {
		var obstacle = obstacles[j];
		if (obstacle.lastY === undefined) obstacle.lastY = obstacle.y;
		// Check if obstacle hits cup
		if (obstacle.intersects(coffeeCup)) {
			LK.setScore(Math.max(0, LK.getScore() - obstacle.penalty));
			scoreTxt.setText('Score: ' + LK.getScore());
			customerSatisfaction -= obstacle.penalty;
			updateSatisfactionDisplay();
			LK.getSound('obstacle').play();
			// Flash cup red
			LK.effects.flashObject(coffeeCup, 0xff0000, 500);
			obstacle.destroy();
			obstacles.splice(j, 1);
			continue;
		}
		// Remove obstacle if it falls off screen
		if (obstacle.lastY < 2732 && obstacle.y >= 2732) {
			obstacle.destroy();
			obstacles.splice(j, 1);
			continue;
		}
		obstacle.lastY = obstacle.y;
	}
	// Update and clean steam effects
	for (var k = steamEffects.length - 1; k >= 0; k--) {
		var steam = steamEffects[k];
		if (steam.life <= 0) {
			steam.destroy();
			steamEffects.splice(k, 1);
		}
	}
	// Check win condition - advance to next level
	if (LK.getScore() >= targetScore) {
		currentLevel++;
		targetScore += 25;
		gameSpeed += 0.3;
		customerSatisfaction = Math.min(100, customerSatisfaction + 20);
		// Update UI
		levelTxt.setText('Level: ' + currentLevel);
		targetTxt.setText('Target: ' + targetScore);
		updateSatisfactionDisplay();
		LK.getSound('levelup').play();
		LK.effects.flashScreen(0x00ff00, 500);
	}
	// Check lose condition
	if (customerSatisfaction <= 0) {
		LK.showGameOver();
	}
	// Gradually decrease satisfaction over time
	if (LK.ticks % 300 === 0) {
		// Every 5 seconds
		customerSatisfaction = Math.max(0, customerSatisfaction - 1);
		updateSatisfactionDisplay();
	}
};
:quality(85)/https://cdn.frvr.ai/686d36c5d662fb7e94c10ae0.png%3F3) 
 arabica bean. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d36fbd662fb7e94c10ae9.png%3F3) 
 coffee cup. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d373cd662fb7e94c10af3.png%3F3) 
 espresso bean. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d3773d662fb7e94c10aff.png%3F3) 
 robusta bean. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d37b9d662fb7e94c10b09.png%3F3) 
 shop button. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d37f3d662fb7e94c10b14.png%3F3) 
 spilled milk. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d385cd662fb7e94c10b1f.png%3F3) 
 steam effect. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d38e6d662fb7e94c10b2c.png%3F3) 
 sugar cube. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d396fd662fb7e94c10b3c.png%3F3) 
 coffee machine. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d39bcd662fb7e94c10b46.png%3F3) 
 shelf. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d3a2ed662fb7e94c10b51.png%3F3) 
 tile. In-Game asset. 2d. High contrast. No shadows
:quality(85)/https://cdn.frvr.ai/686d3ae6d662fb7e94c10b5a.png%3F3) 
 wood counter. In-Game asset. 2d. High contrast. No shadows