/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Character = Container.expand(function (characterType) { var self = Container.call(this); var characterGraphics = self.attachAsset(characterType, { anchorX: 0.5, anchorY: 0.5 }); var nameText = new Text2(characterType.charAt(0).toUpperCase() + characterType.slice(1), { size: 60, fill: 0x000000 }); nameText.anchor.set(0.5, 0.5); nameText.y = 250; self.addChild(nameText); self.characterType = characterType; self.down = function (x, y, obj) { LK.getSound('select').play(); tween(self, { scaleX: 0.9, scaleY: 0.9 }, { duration: 100 }); selectedCharacter = self.characterType; switchToKitchen(); }; self.up = function (x, y, obj) { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; return self; }); var CookingTool = Container.expand(function (toolType) { var self = Container.call(this); var toolGraphics = self.attachAsset(toolType, { anchorX: 0.5, anchorY: 0.5 }); self.toolType = toolType; self.down = function (x, y, obj) { if (selectedIngredient && selectedIngredient.intersects(self)) { if (self.toolType === 'pan' || self.toolType === 'stove') { selectedIngredient.cook(); } else if (self.toolType === 'knife') { selectedIngredient.chop(); } } }; return self; }); var Ingredient = Container.expand(function (ingredientType) { var self = Container.call(this); var ingredientGraphics = self.attachAsset(ingredientType, { anchorX: 0.5, anchorY: 0.5 }); self.ingredientType = ingredientType; self.isCooked = false; self.isChopped = false; self.cookingLevel = 0; self.down = function (x, y, obj) { LK.getSound('select').play(); selectedIngredient = self; dragNode = self; tween(self, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100 }); }; self.up = function (x, y, obj) { dragNode = null; tween(self, { scaleX: 1, scaleY: 1 }, { duration: 100 }); }; self.cook = function () { if (!self.isCooked) { self.isCooked = true; self.cookingLevel = 1; LK.getSound('cook').play(); // Change color to indicate cooking var originalColor = ingredientGraphics.tint || 0xFFFFFF; tween(ingredientGraphics, { tint: 0xDDAAAA }, { duration: 500 }); // Add cooking animation tween(self, { scaleX: 1.2, scaleY: 1.2 }, { duration: 300, onFinish: function onFinish() { tween(self, { scaleX: 1, scaleY: 1 }, { duration: 300 }); } }); } }; self.chop = function () { if (!self.isChopped) { self.isChopped = true; LK.getSound('chop').play(); // Change shape to indicate chopping tween(self, { scaleY: 0.7 }, { duration: 200 }); // Add chopping animation tween(self, { rotation: 0.1 }, { duration: 100, onFinish: function onFinish() { tween(self, { rotation: -0.1 }, { duration: 100, onFinish: function onFinish() { tween(self, { rotation: 0 }, { duration: 100 }); } }); } }); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0xF5F5DC }); /**** * Game Code ****/ // Sounds // UI elements // Cooking tools // Ingredients // Characters var gameState = 'characterSelection'; // 'characterSelection' or 'kitchen' var selectedCharacter = null; var selectedIngredient = null; var dragNode = null; var characters = []; var ingredients = []; var cookingTools = []; // Character selection screen function setupCharacterSelection() { // Clear existing children while (game.children.length > 0) { game.removeChild(game.children[0]); } // Title var titleText = new Text2('Choose Your Character', { size: 100, fill: 0x8B4513 }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 400; game.addChild(titleText); // Character options var characterTypes = ['boy', 'cat', 'cow', 'girl']; characters = []; for (var i = 0; i < characterTypes.length; i++) { var character = new Character(characterTypes[i]); var col = i % 2; var row = Math.floor(i / 2); character.x = 512 + col * 600; character.y = 800 + row * 500; characters.push(character); game.addChild(character); } } // Kitchen screen function setupKitchen() { // Clear existing children while (game.children.length > 0) { game.removeChild(game.children[0]); } // Back button var backButton = LK.getAsset('backButton', { anchorX: 0.5, anchorY: 0.5 }); backButton.x = 150; backButton.y = 150; game.addChild(backButton); var backText = new Text2('Back', { size: 40, fill: 0xFFFFFF }); backText.anchor.set(0.5, 0.5); backText.x = 150; backText.y = 150; game.addChild(backText); // Kitchen title var kitchenTitle = new Text2('Toca Kitchen - ' + selectedCharacter, { size: 80, fill: 0x8B4513 }); kitchenTitle.anchor.set(0.5, 0.5); kitchenTitle.x = 1024; kitchenTitle.y = 200; game.addChild(kitchenTitle); // Ingredients var ingredientTypes = ['egg', 'mushroom', 'broccoli', 'lemon', 'tomato', 'pear']; ingredients = []; for (var i = 0; i < ingredientTypes.length; i++) { var ingredient = new Ingredient(ingredientTypes[i]); var col = i % 3; var row = Math.floor(i / 3); ingredient.x = 400 + col * 300; ingredient.y = 500 + row * 200; ingredients.push(ingredient); game.addChild(ingredient); } // Cooking tools cookingTools = []; // Stove var stove = new CookingTool('stove'); stove.x = 1024; stove.y = 1200; cookingTools.push(stove); game.addChild(stove); // Pan on stove var pan = new CookingTool('pan'); pan.x = 1024; pan.y = 1170; cookingTools.push(pan); game.addChild(pan); // Knife var knife = new CookingTool('knife'); knife.x = 1024; knife.y = 1400; cookingTools.push(knife); game.addChild(knife); // Tool labels var stoveLabel = new Text2('Stove', { size: 40, fill: 0x000000 }); stoveLabel.anchor.set(0.5, 0.5); stoveLabel.x = 1024; stoveLabel.y = 1270; game.addChild(stoveLabel); var knifeLabel = new Text2('Knife', { size: 40, fill: 0x000000 }); knifeLabel.anchor.set(0.5, 0.5); knifeLabel.x = 1024; knifeLabel.y = 1470; game.addChild(knifeLabel); } function switchToKitchen() { gameState = 'kitchen'; setupKitchen(); } function switchToCharacterSelection() { gameState = 'characterSelection'; selectedCharacter = null; selectedIngredient = null; setupCharacterSelection(); } // Handle move events function handleMove(x, y, obj) { if (dragNode) { dragNode.x = x; dragNode.y = y; } } // Game event handlers game.move = handleMove; game.down = function (x, y, obj) { // Check for back button in kitchen if (gameState === 'kitchen' && x < 300 && y < 250) { LK.getSound('select').play(); switchToCharacterSelection(); } }; game.up = function (x, y, obj) { dragNode = null; selectedIngredient = null; }; // Initialize the game setupCharacterSelection(); game.update = function () { // Handle ingredient interactions with cooking tools if (gameState === 'kitchen') { for (var i = 0; i < ingredients.length; i++) { var ingredient = ingredients[i]; // Check if ingredient is being dragged over cooking tools for (var j = 0; j < cookingTools.length; j++) { var tool = cookingTools[j]; if (ingredient.intersects(tool)) { // Visual feedback when ingredient is over a tool if (tool.alpha !== 0.8) { tool.alpha = 0.8; } } else { if (tool.alpha !== 1) { tool.alpha = 1; } } } } } };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,340 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Character = Container.expand(function (characterType) {
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset(characterType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var nameText = new Text2(characterType.charAt(0).toUpperCase() + characterType.slice(1), {
+ size: 60,
+ fill: 0x000000
+ });
+ nameText.anchor.set(0.5, 0.5);
+ nameText.y = 250;
+ self.addChild(nameText);
+ self.characterType = characterType;
+ self.down = function (x, y, obj) {
+ LK.getSound('select').play();
+ tween(self, {
+ scaleX: 0.9,
+ scaleY: 0.9
+ }, {
+ duration: 100
+ });
+ selectedCharacter = self.characterType;
+ switchToKitchen();
+ };
+ self.up = function (x, y, obj) {
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ };
+ return self;
+});
+var CookingTool = Container.expand(function (toolType) {
+ var self = Container.call(this);
+ var toolGraphics = self.attachAsset(toolType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.toolType = toolType;
+ self.down = function (x, y, obj) {
+ if (selectedIngredient && selectedIngredient.intersects(self)) {
+ if (self.toolType === 'pan' || self.toolType === 'stove') {
+ selectedIngredient.cook();
+ } else if (self.toolType === 'knife') {
+ selectedIngredient.chop();
+ }
+ }
+ };
+ return self;
+});
+var Ingredient = Container.expand(function (ingredientType) {
+ var self = Container.call(this);
+ var ingredientGraphics = self.attachAsset(ingredientType, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.ingredientType = ingredientType;
+ self.isCooked = false;
+ self.isChopped = false;
+ self.cookingLevel = 0;
+ self.down = function (x, y, obj) {
+ LK.getSound('select').play();
+ selectedIngredient = self;
+ dragNode = self;
+ tween(self, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 100
+ });
+ };
+ self.up = function (x, y, obj) {
+ dragNode = null;
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100
+ });
+ };
+ self.cook = function () {
+ if (!self.isCooked) {
+ self.isCooked = true;
+ self.cookingLevel = 1;
+ LK.getSound('cook').play();
+ // Change color to indicate cooking
+ var originalColor = ingredientGraphics.tint || 0xFFFFFF;
+ tween(ingredientGraphics, {
+ tint: 0xDDAAAA
+ }, {
+ duration: 500
+ });
+ // Add cooking animation
+ tween(self, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 300,
+ onFinish: function onFinish() {
+ tween(self, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 300
+ });
+ }
+ });
+ }
+ };
+ self.chop = function () {
+ if (!self.isChopped) {
+ self.isChopped = true;
+ LK.getSound('chop').play();
+ // Change shape to indicate chopping
+ tween(self, {
+ scaleY: 0.7
+ }, {
+ duration: 200
+ });
+ // Add chopping animation
+ tween(self, {
+ rotation: 0.1
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(self, {
+ rotation: -0.1
+ }, {
+ duration: 100,
+ onFinish: function onFinish() {
+ tween(self, {
+ rotation: 0
+ }, {
+ duration: 100
+ });
+ }
+ });
+ }
+ });
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xF5F5DC
+});
+
+/****
+* Game Code
+****/
+// Sounds
+// UI elements
+// Cooking tools
+// Ingredients
+// Characters
+var gameState = 'characterSelection'; // 'characterSelection' or 'kitchen'
+var selectedCharacter = null;
+var selectedIngredient = null;
+var dragNode = null;
+var characters = [];
+var ingredients = [];
+var cookingTools = [];
+// Character selection screen
+function setupCharacterSelection() {
+ // Clear existing children
+ while (game.children.length > 0) {
+ game.removeChild(game.children[0]);
+ }
+ // Title
+ var titleText = new Text2('Choose Your Character', {
+ size: 100,
+ fill: 0x8B4513
+ });
+ titleText.anchor.set(0.5, 0.5);
+ titleText.x = 1024;
+ titleText.y = 400;
+ game.addChild(titleText);
+ // Character options
+ var characterTypes = ['boy', 'cat', 'cow', 'girl'];
+ characters = [];
+ for (var i = 0; i < characterTypes.length; i++) {
+ var character = new Character(characterTypes[i]);
+ var col = i % 2;
+ var row = Math.floor(i / 2);
+ character.x = 512 + col * 600;
+ character.y = 800 + row * 500;
+ characters.push(character);
+ game.addChild(character);
+ }
+}
+// Kitchen screen
+function setupKitchen() {
+ // Clear existing children
+ while (game.children.length > 0) {
+ game.removeChild(game.children[0]);
+ }
+ // Back button
+ var backButton = LK.getAsset('backButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ backButton.x = 150;
+ backButton.y = 150;
+ game.addChild(backButton);
+ var backText = new Text2('Back', {
+ size: 40,
+ fill: 0xFFFFFF
+ });
+ backText.anchor.set(0.5, 0.5);
+ backText.x = 150;
+ backText.y = 150;
+ game.addChild(backText);
+ // Kitchen title
+ var kitchenTitle = new Text2('Toca Kitchen - ' + selectedCharacter, {
+ size: 80,
+ fill: 0x8B4513
+ });
+ kitchenTitle.anchor.set(0.5, 0.5);
+ kitchenTitle.x = 1024;
+ kitchenTitle.y = 200;
+ game.addChild(kitchenTitle);
+ // Ingredients
+ var ingredientTypes = ['egg', 'mushroom', 'broccoli', 'lemon', 'tomato', 'pear'];
+ ingredients = [];
+ for (var i = 0; i < ingredientTypes.length; i++) {
+ var ingredient = new Ingredient(ingredientTypes[i]);
+ var col = i % 3;
+ var row = Math.floor(i / 3);
+ ingredient.x = 400 + col * 300;
+ ingredient.y = 500 + row * 200;
+ ingredients.push(ingredient);
+ game.addChild(ingredient);
+ }
+ // Cooking tools
+ cookingTools = [];
+ // Stove
+ var stove = new CookingTool('stove');
+ stove.x = 1024;
+ stove.y = 1200;
+ cookingTools.push(stove);
+ game.addChild(stove);
+ // Pan on stove
+ var pan = new CookingTool('pan');
+ pan.x = 1024;
+ pan.y = 1170;
+ cookingTools.push(pan);
+ game.addChild(pan);
+ // Knife
+ var knife = new CookingTool('knife');
+ knife.x = 1024;
+ knife.y = 1400;
+ cookingTools.push(knife);
+ game.addChild(knife);
+ // Tool labels
+ var stoveLabel = new Text2('Stove', {
+ size: 40,
+ fill: 0x000000
+ });
+ stoveLabel.anchor.set(0.5, 0.5);
+ stoveLabel.x = 1024;
+ stoveLabel.y = 1270;
+ game.addChild(stoveLabel);
+ var knifeLabel = new Text2('Knife', {
+ size: 40,
+ fill: 0x000000
+ });
+ knifeLabel.anchor.set(0.5, 0.5);
+ knifeLabel.x = 1024;
+ knifeLabel.y = 1470;
+ game.addChild(knifeLabel);
+}
+function switchToKitchen() {
+ gameState = 'kitchen';
+ setupKitchen();
+}
+function switchToCharacterSelection() {
+ gameState = 'characterSelection';
+ selectedCharacter = null;
+ selectedIngredient = null;
+ setupCharacterSelection();
+}
+// Handle move events
+function handleMove(x, y, obj) {
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ }
+}
+// Game event handlers
+game.move = handleMove;
+game.down = function (x, y, obj) {
+ // Check for back button in kitchen
+ if (gameState === 'kitchen' && x < 300 && y < 250) {
+ LK.getSound('select').play();
+ switchToCharacterSelection();
+ }
+};
+game.up = function (x, y, obj) {
+ dragNode = null;
+ selectedIngredient = null;
+};
+// Initialize the game
+setupCharacterSelection();
+game.update = function () {
+ // Handle ingredient interactions with cooking tools
+ if (gameState === 'kitchen') {
+ for (var i = 0; i < ingredients.length; i++) {
+ var ingredient = ingredients[i];
+ // Check if ingredient is being dragged over cooking tools
+ for (var j = 0; j < cookingTools.length; j++) {
+ var tool = cookingTools[j];
+ if (ingredient.intersects(tool)) {
+ // Visual feedback when ingredient is over a tool
+ if (tool.alpha !== 0.8) {
+ tool.alpha = 0.8;
+ }
+ } else {
+ if (tool.alpha !== 1) {
+ tool.alpha = 1;
+ }
+ }
+ }
+ }
+ }
+};
\ No newline at end of file