/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var AmongUsCharacter = Container.expand(function (color) {
	var self = Container.call(this);
	self.color = color;
	self.isSelected = false;
	self.soundName = color + (color === 'red' ? 'Beat' : color === 'blue' ? 'Melody' : color === 'yellow' ? 'Bass' : color === 'green' ? 'Synth' : color === 'pink' ? 'Vocals' : 'Drums');
	var highlight = self.addChild(LK.getAsset('selectionHighlight', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	}));
	var characterBody = self.attachAsset(color + 'Character', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var visor = self.attachAsset(color + 'Visor', {
		anchorX: 0.5,
		anchorY: 0.5,
		y: -60
	});
	self.select = function () {
		self.isSelected = true;
		tween(highlight, {
			alpha: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(characterBody, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(visor, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
	};
	self.deselect = function () {
		self.isSelected = false;
		tween(highlight, {
			alpha: 0
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(characterBody, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(visor, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
	};
	self.down = function (x, y, obj) {
		if (gameState === 'selecting') {
			selectCharacter(self);
		}
	};
	return self;
});
var MixingStation = Container.expand(function () {
	var self = Container.call(this);
	var background = self.attachAsset('mixingArea', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.character1 = null;
	self.character2 = null;
	self.isPlaying = false;
	self.addCharacter = function (character) {
		if (!self.character1) {
			self.character1 = character;
			character.x = -200;
			character.y = 0;
		} else if (!self.character2) {
			self.character2 = character;
			character.x = 200;
			character.y = 0;
		}
		self.addChild(character);
	};
	self.playMix = function () {
		if (self.character1 && self.character2 && !self.isPlaying) {
			self.isPlaying = true;
			// Start the mix loop
			self.startMixLoop();
		}
	};
	self.startMixLoop = function () {
		// Play first character sound
		LK.getSound(self.character1.soundName).play();
		// Play second character sound with slight delay
		LK.setTimeout(function () {
			LK.getSound(self.character2.soundName).play();
		}, 500);
		// Loop every 9 seconds
		LK.setTimeout(function () {
			if (self.isPlaying) {
				self.startMixLoop();
			}
		}, 9000);
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x1a1a2e
});
/**** 
* Game Code
****/ 
var gameState = 'selecting';
var selectedCount = 0;
var characters = [];
var characterColors = ['red', 'blue', 'yellow', 'green', 'pink', 'black'];
// UI Elements
var titleTxt = new Text2('Among Us Music Mix', {
	size: 120,
	fill: 0xFFFFFF
});
titleTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(titleTxt);
var instructionTxt = new Text2('Select two characters to create a mix!', {
	size: 80,
	fill: 0xCCCCCC
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 150;
LK.gui.top.addChild(instructionTxt);
var scoreTxt = new Text2('Score: 0', {
	size: 100,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
var resetBtn = new Text2('RESET', {
	size: 80,
	fill: 0xFF4444
});
resetBtn.anchor.set(1, 0);
resetBtn.y = 120;
resetBtn.down = function () {
	resetGame();
};
LK.gui.topRight.addChild(resetBtn);
// Create mixing station
var mixingStation = game.addChild(new MixingStation());
mixingStation.x = 1024;
mixingStation.y = 1800;
// Create character selection grid
var startY = 800;
var spacing = 340;
for (var i = 0; i < characterColors.length; i++) {
	var character = new AmongUsCharacter(characterColors[i]);
	var row = Math.floor(i / 3);
	var col = i % 3;
	character.x = 400 + col * spacing;
	character.y = startY + row * 400;
	characters.push(character);
	game.addChild(character);
}
function selectCharacter(character) {
	if (character.isSelected) return;
	character.select();
	selectedCount++;
	var characterCopy = new AmongUsCharacter(character.color);
	mixingStation.addCharacter(characterCopy);
	if (selectedCount === 2) {
		gameState = 'mixing';
		instructionTxt.setText('Creating your musical mix...');
		LK.setTimeout(function () {
			mixingStation.playMix();
		}, 1000);
	} else {
		instructionTxt.setText('Select one more character!');
	}
}
function resetGame() {
	gameState = 'selecting';
	selectedCount = 0;
	instructionTxt.setText('Select two characters to create a mix!');
	// Stop any playing mix
	if (mixingStation.isPlaying) {
		mixingStation.isPlaying = false;
	}
	// Reset character selections
	for (var i = 0; i < characters.length; i++) {
		characters[i].deselect();
	}
	// Clear mixing station
	if (mixingStation.character1) {
		mixingStation.character1.destroy();
		mixingStation.character1 = null;
	}
	if (mixingStation.character2) {
		mixingStation.character2.destroy();
		mixingStation.character2 = null;
	}
}
game.update = function () {
	// Visual feedback for mixing station when ready
	if (mixingStation.character1 && mixingStation.character2 && !mixingStation.isPlaying) {
		if (LK.ticks % 60 < 30) {
			mixingStation.alpha = 0.8;
		} else {
			mixingStation.alpha = 1.0;
		}
	}
}; /**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
var AmongUsCharacter = Container.expand(function (color) {
	var self = Container.call(this);
	self.color = color;
	self.isSelected = false;
	self.soundName = color + (color === 'red' ? 'Beat' : color === 'blue' ? 'Melody' : color === 'yellow' ? 'Bass' : color === 'green' ? 'Synth' : color === 'pink' ? 'Vocals' : 'Drums');
	var highlight = self.addChild(LK.getAsset('selectionHighlight', {
		anchorX: 0.5,
		anchorY: 0.5,
		alpha: 0
	}));
	var characterBody = self.attachAsset(color + 'Character', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var visor = self.attachAsset(color + 'Visor', {
		anchorX: 0.5,
		anchorY: 0.5,
		y: -60
	});
	self.select = function () {
		self.isSelected = true;
		tween(highlight, {
			alpha: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(characterBody, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(visor, {
			scaleX: 1.1,
			scaleY: 1.1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
	};
	self.deselect = function () {
		self.isSelected = false;
		tween(highlight, {
			alpha: 0
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(characterBody, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
		tween(visor, {
			scaleX: 1,
			scaleY: 1
		}, {
			duration: 200,
			easing: tween.easeOut
		});
	};
	self.down = function (x, y, obj) {
		if (gameState === 'selecting') {
			selectCharacter(self);
		}
	};
	return self;
});
var MixingStation = Container.expand(function () {
	var self = Container.call(this);
	var background = self.attachAsset('mixingArea', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.character1 = null;
	self.character2 = null;
	self.isPlaying = false;
	self.addCharacter = function (character) {
		if (!self.character1) {
			self.character1 = character;
			character.x = -200;
			character.y = 0;
		} else if (!self.character2) {
			self.character2 = character;
			character.x = 200;
			character.y = 0;
		}
		self.addChild(character);
	};
	self.playMix = function () {
		if (self.character1 && self.character2 && !self.isPlaying) {
			self.isPlaying = true;
			// Start the mix loop
			self.startMixLoop();
		}
	};
	self.startMixLoop = function () {
		// Play first character sound
		LK.getSound(self.character1.soundName).play();
		// Play second character sound with slight delay
		LK.setTimeout(function () {
			LK.getSound(self.character2.soundName).play();
		}, 500);
		// Loop every 9 seconds
		LK.setTimeout(function () {
			if (self.isPlaying) {
				self.startMixLoop();
			}
		}, 9000);
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x1a1a2e
});
/**** 
* Game Code
****/ 
var gameState = 'selecting';
var selectedCount = 0;
var characters = [];
var characterColors = ['red', 'blue', 'yellow', 'green', 'pink', 'black'];
// UI Elements
var titleTxt = new Text2('Among Us Music Mix', {
	size: 120,
	fill: 0xFFFFFF
});
titleTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(titleTxt);
var instructionTxt = new Text2('Select two characters to create a mix!', {
	size: 80,
	fill: 0xCCCCCC
});
instructionTxt.anchor.set(0.5, 0);
instructionTxt.y = 150;
LK.gui.top.addChild(instructionTxt);
var scoreTxt = new Text2('Score: 0', {
	size: 100,
	fill: 0xFFFFFF
});
scoreTxt.anchor.set(1, 0);
LK.gui.topRight.addChild(scoreTxt);
var resetBtn = new Text2('RESET', {
	size: 80,
	fill: 0xFF4444
});
resetBtn.anchor.set(1, 0);
resetBtn.y = 120;
resetBtn.down = function () {
	resetGame();
};
LK.gui.topRight.addChild(resetBtn);
// Create mixing station
var mixingStation = game.addChild(new MixingStation());
mixingStation.x = 1024;
mixingStation.y = 1800;
// Create character selection grid
var startY = 800;
var spacing = 340;
for (var i = 0; i < characterColors.length; i++) {
	var character = new AmongUsCharacter(characterColors[i]);
	var row = Math.floor(i / 3);
	var col = i % 3;
	character.x = 400 + col * spacing;
	character.y = startY + row * 400;
	characters.push(character);
	game.addChild(character);
}
function selectCharacter(character) {
	if (character.isSelected) return;
	character.select();
	selectedCount++;
	var characterCopy = new AmongUsCharacter(character.color);
	mixingStation.addCharacter(characterCopy);
	if (selectedCount === 2) {
		gameState = 'mixing';
		instructionTxt.setText('Creating your musical mix...');
		LK.setTimeout(function () {
			mixingStation.playMix();
		}, 1000);
	} else {
		instructionTxt.setText('Select one more character!');
	}
}
function resetGame() {
	gameState = 'selecting';
	selectedCount = 0;
	instructionTxt.setText('Select two characters to create a mix!');
	// Stop any playing mix
	if (mixingStation.isPlaying) {
		mixingStation.isPlaying = false;
	}
	// Reset character selections
	for (var i = 0; i < characters.length; i++) {
		characters[i].deselect();
	}
	// Clear mixing station
	if (mixingStation.character1) {
		mixingStation.character1.destroy();
		mixingStation.character1 = null;
	}
	if (mixingStation.character2) {
		mixingStation.character2.destroy();
		mixingStation.character2 = null;
	}
}
game.update = function () {
	// Visual feedback for mixing station when ready
	if (mixingStation.character1 && mixingStation.character2 && !mixingStation.isPlaying) {
		if (LK.ticks % 60 < 30) {
			mixingStation.alpha = 0.8;
		} else {
			mixingStation.alpha = 1.0;
		}
	}
};