/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var ActionButton = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('actionButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.actionType = '';
self.isReady = false;
var label = new Text2('READY', {
size: 35,
fill: '#000000'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.down = function (x, y, obj) {
if (self.isReady) {
tween(graphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
}
};
self.up = function (x, y, obj) {
tween(graphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var CookingStation = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('cookingStation', {
anchorX: 0.5,
anchorY: 0.5
});
self.stationType = ''; // 'chop', 'cook', 'mix', 'plate'
self.isActive = false;
var label = new Text2(self.stationType.toUpperCase(), {
size: 40,
fill: '#FFFFFF'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.activate = function () {
self.isActive = true;
tween(graphics, {
tint: 0xFFFF00
}, {
duration: 200
});
};
self.deactivate = function () {
self.isActive = false;
tween(graphics, {
tint: 0xFFFFFF
}, {
duration: 200
});
};
return self;
});
var Ingredient = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('ingredient', {
anchorX: 0.5,
anchorY: 0.5
});
self.ingredientName = '';
self.actionRequired = ''; // 'chop', 'cook', 'mix'
self.isProcessed = false;
self.ingredientIndex = 0;
self.highlight = function () {
tween(graphics, {
tint: 0xFFFF00
}, {
duration: 300
});
};
self.resetHighlight = function () {
tween(graphics, {
tint: 0xFFFFFF
}, {
duration: 300
});
};
self.processIngredient = function () {
self.isProcessed = true;
tween(graphics, {
tint: 0x00FF00
}, {
duration: 200
});
};
return self;
});
var Plate = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('plate', {
anchorX: 0.5,
anchorY: 0.5
});
self.dishIngredients = [];
self.isComplete = false;
var label = new Text2('PLATE', {
size: 30,
fill: '#000000'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.addToDish = function (ingredientName) {
self.dishIngredients.push(ingredientName);
};
self.completeDish = function () {
self.isComplete = true;
tween(graphics, {
tint: 0x00FF00
}, {
duration: 300
});
};
self.reset = function () {
self.dishIngredients = [];
self.isComplete = false;
graphics.tint = 0xFFFFFF;
};
return self;
});
var TimerBar = Container.expand(function () {
var self = Container.call(this);
self.maxWidth = 400;
self.currentDuration = 0;
self.maxDuration = 60000;
var background = LK.getAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
background.tint = 0x333333;
self.addChild(background);
var fill = self.attachAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
fill.tint = 0x4CAF50;
self.update = function (remaining, max) {
self.currentDuration = remaining;
self.maxDuration = max;
var percentage = Math.max(0, remaining / max);
fill.width = self.maxWidth * percentage;
if (percentage > 0.5) {
fill.tint = 0x4CAF50;
} else if (percentage > 0.25) {
fill.tint = 0xFFC107;
} else {
fill.tint = 0xFF5252;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
var recipes = [{
name: 'Simple Salad',
ingredients: [{
name: 'lettuce',
action: 'chop'
}, {
name: 'tomato',
action: 'chop'
}, {
name: 'cucumber',
action: 'chop'
}],
timeLimit: 45000,
difficulty: 1
}, {
name: 'Pasta Dish',
ingredients: [{
name: 'pasta',
action: 'cook'
}, {
name: 'tomato',
action: 'cook'
}, {
name: 'garlic',
action: 'chop'
}, {
name: 'sauce',
action: 'mix'
}],
timeLimit: 60000,
difficulty: 2
}, {
name: 'Stir Fry',
ingredients: [{
name: 'vegetables',
action: 'chop'
}, {
name: 'meat',
action: 'cook'
}, {
name: 'sauce',
action: 'mix'
}, {
name: 'spices',
action: 'mix'
}],
timeLimit: 75000,
difficulty: 3
}];
var currentRecipeIndex = 0;
var currentRecipe = recipes[currentRecipeIndex];
var gameStartTime = 0;
var gameTimeLimit = currentRecipe.timeLimit;
var timeRemaining = gameTimeLimit;
var score = 0;
var currentIngredientIndex = 0;
var ingredients = [];
var cookingStations = [];
var actionButton = null;
var plate = null;
var timerBar = null;
var actionWindowActive = false;
var actionWindowTimer = null;
var gameActive = true;
var recipeTitle = new Text2(currentRecipe.name, {
size: 60,
fill: '#FFFFFF'
});
recipeTitle.anchor.set(0.5, 0);
recipeTitle.x = 1024;
recipeTitle.y = 50;
game.addChild(recipeTitle);
timerBar = game.addChild(new TimerBar());
timerBar.x = 824;
timerBar.y = 150;
var timeText = new Text2('45s', {
size: 50,
fill: '#FFFFFF'
});
timeText.anchor.set(0.5, 0);
timeText.x = 1024;
timeText.y = 220;
game.addChild(timeText);
var ingredientLabel = new Text2('Gather: ' + currentRecipe.ingredients[0].name.toUpperCase(), {
size: 45,
fill: '#1BE7FF'
});
ingredientLabel.anchor.set(0.5, 0);
ingredientLabel.x = 1024;
ingredientLabel.y = 350;
game.addChild(ingredientLabel);
var stationLabel = new Text2('Action: ' + currentRecipe.ingredients[0].action.toUpperCase(), {
size: 40,
fill: '#FFD700'
});
stationLabel.anchor.set(0.5, 0);
stationLabel.x = 1024;
stationLabel.y = 430;
game.addChild(stationLabel);
for (var i = 0; i < 3; i++) {
var station = game.addChild(new CookingStation());
station.x = 400 + i * 280;
station.y = 600;
station.stationType = ['chop', 'cook', 'mix'][i];
station.graphics = station.children[0];
var stationLbl = station.children[1];
stationLbl.setText(station.stationType.toUpperCase());
cookingStations.push(station);
}
plate = game.addChild(new Plate());
plate.x = 1024;
plate.y = 850;
actionButton = game.addChild(new ActionButton());
actionButton.x = 1024;
actionButton.y = 1150;
actionButton.actionType = currentRecipe.ingredients[0].action;
actionButton.children[1].setText(currentRecipe.ingredients[0].action.toUpperCase());
var scoreText = new Text2('Score: 0', {
size: 50,
fill: '#00FF00'
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 1024;
scoreText.y = 1350;
game.addChild(scoreText);
var nextIngredientsContainer = game.addChild(new Container());
nextIngredientsContainer.x = 1024;
nextIngredientsContainer.y = 1550;
function updateNextIngredientsDisplay() {
while (nextIngredientsContainer.children.length > 0) {
nextIngredientsContainer.removeChild(nextIngredientsContainer.children[0]);
}
for (var i = currentIngredientIndex + 1; i < Math.min(currentIngredientIndex + 4, currentRecipe.ingredients.length); i++) {
var nextIngText = new Text2('→ ' + currentRecipe.ingredients[i].name, {
size: 30,
fill: '#AAAAAA'
});
nextIngText.anchor.set(0.5, 0);
nextIngText.y = (i - currentIngredientIndex - 1) * 50;
nextIngredientsContainer.addChild(nextIngText);
}
}
updateNextIngredientsDisplay();
var spawnedIngredient = null;
function spawnIngredient() {
if (spawnedIngredient) {
spawnedIngredient.destroy();
spawnedIngredient = null;
}
if (currentIngredientIndex >= currentRecipe.ingredients.length) {
completeDish();
return;
}
var currentIng = currentRecipe.ingredients[currentIngredientIndex];
spawnedIngredient = game.addChild(new Ingredient());
spawnedIngredient.x = 300 + Math.random() * 1448;
spawnedIngredient.y = 1400 + Math.random() * 300;
spawnedIngredient.ingredientName = currentIng.name;
spawnedIngredient.actionRequired = currentIng.action;
spawnedIngredient.ingredientIndex = currentIngredientIndex;
spawnedIngredient.highlight();
}
spawnIngredient();
function activateActionWindow() {
actionWindowActive = true;
actionButton.isReady = true;
actionButton.children[1].setText('TAP!');
tween(actionButton.children[0], {
tint: 0xFFFF00
}, {
duration: 200
});
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
actionWindowTimer = LK.setTimeout(function () {
actionWindowActive = false;
actionButton.isReady = false;
actionButton.children[1].setText('MISS');
tween(actionButton.children[0], {
tint: 0xFF5252
}, {
duration: 200
});
timeRemaining -= 5000;
if (timeRemaining < 0) timeRemaining = 0;
LK.getSound('fail').play();
actionWindowTimer = LK.setTimeout(function () {
actionButton.isReady = false;
actionButton.children[1].setText('READY');
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
}, 1000);
}, 3000);
}
function completeIngredient() {
if (!actionWindowActive) {
return;
}
actionWindowActive = false;
actionButton.isReady = false;
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
LK.getSound('success').play();
spawnedIngredient.processIngredient();
plate.addToDish(spawnedIngredient.ingredientName);
score += 10;
actionButton.children[1].setText('GREAT!');
tween(actionButton.children[0], {
tint: 0x00FF00
}, {
duration: 200
});
currentIngredientIndex++;
updateNextIngredientsDisplay();
actionWindowTimer = LK.setTimeout(function () {
if (currentIngredientIndex < currentRecipe.ingredients.length) {
var nextIng = currentRecipe.ingredients[currentIngredientIndex];
ingredientLabel.setText('Gather: ' + nextIng.name.toUpperCase());
stationLabel.setText('Action: ' + nextIng.action.toUpperCase());
actionButton.actionType = nextIng.action;
actionButton.children[1].setText(nextIng.action.toUpperCase());
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
spawnIngredient();
activateActionWindow();
} else {
completeDish();
}
}, 800);
}
function completeDish() {
if (!gameActive) return;
plate.completeDish();
LK.getSound('success').play();
score += 50;
scoreText.setText('Score: ' + score);
gameActive = false;
if (currentRecipeIndex < recipes.length - 1) {
LK.setTimeout(function () {
currentRecipeIndex++;
currentRecipe = recipes[currentRecipeIndex];
gameTimeLimit = currentRecipe.timeLimit;
timeRemaining = gameTimeLimit;
currentIngredientIndex = 0;
recipeTitle.setText(currentRecipe.name);
ingredientLabel.setText('Gather: ' + currentRecipe.ingredients[0].name.toUpperCase());
stationLabel.setText('Action: ' + currentRecipe.ingredients[0].action.toUpperCase());
actionButton.actionType = currentRecipe.ingredients[0].action;
actionButton.children[1].setText(currentRecipe.ingredients[0].action.toUpperCase());
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
plate.reset();
updateNextIngredientsDisplay();
spawnIngredient();
gameActive = true;
activateActionWindow();
gameStartTime = LK.ticks;
}, 1500);
} else {
LK.setTimeout(function () {
LK.setScore(score);
LK.showYouWin();
}, 1500);
}
}
actionButton.up = function (x, y, obj) {
tween(actionButton.children[0], {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (gameActive && actionWindowActive && actionButton.isReady) {
completeIngredient();
}
};
actionButton.down = function (x, y, obj) {
if (actionButton.isReady) {
tween(actionButton.children[0], {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
}
};
gameStartTime = LK.ticks;
game.update = function () {
if (!gameActive) return;
var elapsed = (LK.ticks - gameStartTime) * 16.67;
timeRemaining = gameTimeLimit - elapsed;
if (timeRemaining <= 0) {
timeRemaining = 0;
gameActive = false;
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
LK.effects.flashScreen(0xFF0000, 500);
LK.setScore(score);
LK.showGameOver();
return;
}
var seconds = Math.ceil(timeRemaining / 1000);
timeText.setText(seconds + 's');
timerBar.update(timeRemaining, gameTimeLimit);
};
LK.playMusic('bgmusic', {
loop: true
}); /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var ActionButton = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('actionButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.actionType = '';
self.isReady = false;
var label = new Text2('READY', {
size: 35,
fill: '#000000'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.down = function (x, y, obj) {
if (self.isReady) {
tween(graphics, {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
}
};
self.up = function (x, y, obj) {
tween(graphics, {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
};
return self;
});
var CookingStation = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('cookingStation', {
anchorX: 0.5,
anchorY: 0.5
});
self.stationType = ''; // 'chop', 'cook', 'mix', 'plate'
self.isActive = false;
var label = new Text2(self.stationType.toUpperCase(), {
size: 40,
fill: '#FFFFFF'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.activate = function () {
self.isActive = true;
tween(graphics, {
tint: 0xFFFF00
}, {
duration: 200
});
};
self.deactivate = function () {
self.isActive = false;
tween(graphics, {
tint: 0xFFFFFF
}, {
duration: 200
});
};
return self;
});
var Ingredient = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('ingredient', {
anchorX: 0.5,
anchorY: 0.5
});
self.ingredientName = '';
self.actionRequired = ''; // 'chop', 'cook', 'mix'
self.isProcessed = false;
self.ingredientIndex = 0;
self.highlight = function () {
tween(graphics, {
tint: 0xFFFF00
}, {
duration: 300
});
};
self.resetHighlight = function () {
tween(graphics, {
tint: 0xFFFFFF
}, {
duration: 300
});
};
self.processIngredient = function () {
self.isProcessed = true;
tween(graphics, {
tint: 0x00FF00
}, {
duration: 200
});
};
return self;
});
var Plate = Container.expand(function () {
var self = Container.call(this);
var graphics = self.attachAsset('plate', {
anchorX: 0.5,
anchorY: 0.5
});
self.dishIngredients = [];
self.isComplete = false;
var label = new Text2('PLATE', {
size: 30,
fill: '#000000'
});
label.anchor.set(0.5, 0.5);
self.addChild(label);
self.addToDish = function (ingredientName) {
self.dishIngredients.push(ingredientName);
};
self.completeDish = function () {
self.isComplete = true;
tween(graphics, {
tint: 0x00FF00
}, {
duration: 300
});
};
self.reset = function () {
self.dishIngredients = [];
self.isComplete = false;
graphics.tint = 0xFFFFFF;
};
return self;
});
var TimerBar = Container.expand(function () {
var self = Container.call(this);
self.maxWidth = 400;
self.currentDuration = 0;
self.maxDuration = 60000;
var background = LK.getAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
background.tint = 0x333333;
self.addChild(background);
var fill = self.attachAsset('timerBar', {
anchorX: 0,
anchorY: 0
});
fill.tint = 0x4CAF50;
self.update = function (remaining, max) {
self.currentDuration = remaining;
self.maxDuration = max;
var percentage = Math.max(0, remaining / max);
fill.width = self.maxWidth * percentage;
if (percentage > 0.5) {
fill.tint = 0x4CAF50;
} else if (percentage > 0.25) {
fill.tint = 0xFFC107;
} else {
fill.tint = 0xFF5252;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x1A1A2E
});
/****
* Game Code
****/
var recipes = [{
name: 'Simple Salad',
ingredients: [{
name: 'lettuce',
action: 'chop'
}, {
name: 'tomato',
action: 'chop'
}, {
name: 'cucumber',
action: 'chop'
}],
timeLimit: 45000,
difficulty: 1
}, {
name: 'Pasta Dish',
ingredients: [{
name: 'pasta',
action: 'cook'
}, {
name: 'tomato',
action: 'cook'
}, {
name: 'garlic',
action: 'chop'
}, {
name: 'sauce',
action: 'mix'
}],
timeLimit: 60000,
difficulty: 2
}, {
name: 'Stir Fry',
ingredients: [{
name: 'vegetables',
action: 'chop'
}, {
name: 'meat',
action: 'cook'
}, {
name: 'sauce',
action: 'mix'
}, {
name: 'spices',
action: 'mix'
}],
timeLimit: 75000,
difficulty: 3
}];
var currentRecipeIndex = 0;
var currentRecipe = recipes[currentRecipeIndex];
var gameStartTime = 0;
var gameTimeLimit = currentRecipe.timeLimit;
var timeRemaining = gameTimeLimit;
var score = 0;
var currentIngredientIndex = 0;
var ingredients = [];
var cookingStations = [];
var actionButton = null;
var plate = null;
var timerBar = null;
var actionWindowActive = false;
var actionWindowTimer = null;
var gameActive = true;
var recipeTitle = new Text2(currentRecipe.name, {
size: 60,
fill: '#FFFFFF'
});
recipeTitle.anchor.set(0.5, 0);
recipeTitle.x = 1024;
recipeTitle.y = 50;
game.addChild(recipeTitle);
timerBar = game.addChild(new TimerBar());
timerBar.x = 824;
timerBar.y = 150;
var timeText = new Text2('45s', {
size: 50,
fill: '#FFFFFF'
});
timeText.anchor.set(0.5, 0);
timeText.x = 1024;
timeText.y = 220;
game.addChild(timeText);
var ingredientLabel = new Text2('Gather: ' + currentRecipe.ingredients[0].name.toUpperCase(), {
size: 45,
fill: '#1BE7FF'
});
ingredientLabel.anchor.set(0.5, 0);
ingredientLabel.x = 1024;
ingredientLabel.y = 350;
game.addChild(ingredientLabel);
var stationLabel = new Text2('Action: ' + currentRecipe.ingredients[0].action.toUpperCase(), {
size: 40,
fill: '#FFD700'
});
stationLabel.anchor.set(0.5, 0);
stationLabel.x = 1024;
stationLabel.y = 430;
game.addChild(stationLabel);
for (var i = 0; i < 3; i++) {
var station = game.addChild(new CookingStation());
station.x = 400 + i * 280;
station.y = 600;
station.stationType = ['chop', 'cook', 'mix'][i];
station.graphics = station.children[0];
var stationLbl = station.children[1];
stationLbl.setText(station.stationType.toUpperCase());
cookingStations.push(station);
}
plate = game.addChild(new Plate());
plate.x = 1024;
plate.y = 850;
actionButton = game.addChild(new ActionButton());
actionButton.x = 1024;
actionButton.y = 1150;
actionButton.actionType = currentRecipe.ingredients[0].action;
actionButton.children[1].setText(currentRecipe.ingredients[0].action.toUpperCase());
var scoreText = new Text2('Score: 0', {
size: 50,
fill: '#00FF00'
});
scoreText.anchor.set(0.5, 0);
scoreText.x = 1024;
scoreText.y = 1350;
game.addChild(scoreText);
var nextIngredientsContainer = game.addChild(new Container());
nextIngredientsContainer.x = 1024;
nextIngredientsContainer.y = 1550;
function updateNextIngredientsDisplay() {
while (nextIngredientsContainer.children.length > 0) {
nextIngredientsContainer.removeChild(nextIngredientsContainer.children[0]);
}
for (var i = currentIngredientIndex + 1; i < Math.min(currentIngredientIndex + 4, currentRecipe.ingredients.length); i++) {
var nextIngText = new Text2('→ ' + currentRecipe.ingredients[i].name, {
size: 30,
fill: '#AAAAAA'
});
nextIngText.anchor.set(0.5, 0);
nextIngText.y = (i - currentIngredientIndex - 1) * 50;
nextIngredientsContainer.addChild(nextIngText);
}
}
updateNextIngredientsDisplay();
var spawnedIngredient = null;
function spawnIngredient() {
if (spawnedIngredient) {
spawnedIngredient.destroy();
spawnedIngredient = null;
}
if (currentIngredientIndex >= currentRecipe.ingredients.length) {
completeDish();
return;
}
var currentIng = currentRecipe.ingredients[currentIngredientIndex];
spawnedIngredient = game.addChild(new Ingredient());
spawnedIngredient.x = 300 + Math.random() * 1448;
spawnedIngredient.y = 1400 + Math.random() * 300;
spawnedIngredient.ingredientName = currentIng.name;
spawnedIngredient.actionRequired = currentIng.action;
spawnedIngredient.ingredientIndex = currentIngredientIndex;
spawnedIngredient.highlight();
}
spawnIngredient();
function activateActionWindow() {
actionWindowActive = true;
actionButton.isReady = true;
actionButton.children[1].setText('TAP!');
tween(actionButton.children[0], {
tint: 0xFFFF00
}, {
duration: 200
});
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
actionWindowTimer = LK.setTimeout(function () {
actionWindowActive = false;
actionButton.isReady = false;
actionButton.children[1].setText('MISS');
tween(actionButton.children[0], {
tint: 0xFF5252
}, {
duration: 200
});
timeRemaining -= 5000;
if (timeRemaining < 0) timeRemaining = 0;
LK.getSound('fail').play();
actionWindowTimer = LK.setTimeout(function () {
actionButton.isReady = false;
actionButton.children[1].setText('READY');
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
}, 1000);
}, 3000);
}
function completeIngredient() {
if (!actionWindowActive) {
return;
}
actionWindowActive = false;
actionButton.isReady = false;
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
LK.getSound('success').play();
spawnedIngredient.processIngredient();
plate.addToDish(spawnedIngredient.ingredientName);
score += 10;
actionButton.children[1].setText('GREAT!');
tween(actionButton.children[0], {
tint: 0x00FF00
}, {
duration: 200
});
currentIngredientIndex++;
updateNextIngredientsDisplay();
actionWindowTimer = LK.setTimeout(function () {
if (currentIngredientIndex < currentRecipe.ingredients.length) {
var nextIng = currentRecipe.ingredients[currentIngredientIndex];
ingredientLabel.setText('Gather: ' + nextIng.name.toUpperCase());
stationLabel.setText('Action: ' + nextIng.action.toUpperCase());
actionButton.actionType = nextIng.action;
actionButton.children[1].setText(nextIng.action.toUpperCase());
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
spawnIngredient();
activateActionWindow();
} else {
completeDish();
}
}, 800);
}
function completeDish() {
if (!gameActive) return;
plate.completeDish();
LK.getSound('success').play();
score += 50;
scoreText.setText('Score: ' + score);
gameActive = false;
if (currentRecipeIndex < recipes.length - 1) {
LK.setTimeout(function () {
currentRecipeIndex++;
currentRecipe = recipes[currentRecipeIndex];
gameTimeLimit = currentRecipe.timeLimit;
timeRemaining = gameTimeLimit;
currentIngredientIndex = 0;
recipeTitle.setText(currentRecipe.name);
ingredientLabel.setText('Gather: ' + currentRecipe.ingredients[0].name.toUpperCase());
stationLabel.setText('Action: ' + currentRecipe.ingredients[0].action.toUpperCase());
actionButton.actionType = currentRecipe.ingredients[0].action;
actionButton.children[1].setText(currentRecipe.ingredients[0].action.toUpperCase());
tween(actionButton.children[0], {
tint: 0x1BE7FF
}, {
duration: 200
});
plate.reset();
updateNextIngredientsDisplay();
spawnIngredient();
gameActive = true;
activateActionWindow();
gameStartTime = LK.ticks;
}, 1500);
} else {
LK.setTimeout(function () {
LK.setScore(score);
LK.showYouWin();
}, 1500);
}
}
actionButton.up = function (x, y, obj) {
tween(actionButton.children[0], {
scaleX: 1,
scaleY: 1
}, {
duration: 100
});
if (gameActive && actionWindowActive && actionButton.isReady) {
completeIngredient();
}
};
actionButton.down = function (x, y, obj) {
if (actionButton.isReady) {
tween(actionButton.children[0], {
scaleX: 0.9,
scaleY: 0.9
}, {
duration: 100
});
}
};
gameStartTime = LK.ticks;
game.update = function () {
if (!gameActive) return;
var elapsed = (LK.ticks - gameStartTime) * 16.67;
timeRemaining = gameTimeLimit - elapsed;
if (timeRemaining <= 0) {
timeRemaining = 0;
gameActive = false;
if (actionWindowTimer) {
LK.clearTimeout(actionWindowTimer);
}
LK.effects.flashScreen(0xFF0000, 500);
LK.setScore(score);
LK.showGameOver();
return;
}
var seconds = Math.ceil(timeRemaining / 1000);
timeText.setText(seconds + 's');
timerBar.update(timeRemaining, gameTimeLimit);
};
LK.playMusic('bgmusic', {
loop: true
});