Code edit (1 edits merged)
Please save this source code
User prompt
Feed the Creatures
Initial prompt
Toca kitchen 2 (2014) tap on the female, male, or monster you want to play as, tap on lettuce, pineapple, fish, sausage, strawberry, potato, broccoli, or watermelon to get started. Drag it onto it to watch it eat.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Character = Container.expand(function (type) { var self = Container.call(this); var characterGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.isEating = false; // Character food preferences self.preferences = { female: { loves: ['strawberry', 'watermelon', 'pineapple'], likes: ['lettuce', 'broccoli'], dislikes: ['fish', 'sausage', 'potato'] }, male: { loves: ['sausage', 'fish', 'potato'], likes: ['watermelon', 'pineapple'], dislikes: ['lettuce', 'broccoli', 'strawberry'] }, monster: { loves: ['broccoli', 'lettuce', 'fish'], likes: ['potato', 'sausage'], dislikes: ['strawberry', 'watermelon', 'pineapple'] } }; self.feedFood = function (foodType) { if (self.isEating) return; self.isEating = true; var preference = self.getPreference(foodType); // Feeding animation tween(characterGraphics, { scaleX: 1.2, scaleY: 1.2 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { tween(characterGraphics, { scaleX: 1, scaleY: 1 }, { duration: 200, easing: tween.easeIn }); } }); // Reaction animation based on preference if (preference === 'loves') { self.showLoveReaction(); LK.getSound('happy').play(); } else if (preference === 'likes') { self.showLikeReaction(); LK.getSound('neutral').play(); } else { self.showDislikeReaction(); LK.getSound('dislike').play(); } LK.setTimeout(function () { self.isEating = false; }, 1000); }; self.getPreference = function (foodType) { var prefs = self.preferences[self.type]; if (prefs.loves.indexOf(foodType) !== -1) return 'loves'; if (prefs.likes.indexOf(foodType) !== -1) return 'likes'; return 'dislikes'; }; self.showLoveReaction = function () { // Happy bounce animation tween(characterGraphics, { y: characterGraphics.y - 30 }, { duration: 150, easing: tween.easeOut, onFinish: function onFinish() { tween(characterGraphics, { y: characterGraphics.y + 30 }, { duration: 150, easing: tween.bounceOut }); } }); // Happy color flash var originalTint = characterGraphics.tint; characterGraphics.tint = 0xFFFF00; LK.setTimeout(function () { characterGraphics.tint = originalTint; }, 300); }; self.showLikeReaction = function () { // Gentle nod animation tween(characterGraphics, { rotation: 0.1 }, { duration: 200, easing: tween.easeInOut, onFinish: function onFinish() { tween(characterGraphics, { rotation: 0 }, { duration: 200, easing: tween.easeInOut }); } }); }; self.showDislikeReaction = function () { // Shake animation var originalX = characterGraphics.x; tween(characterGraphics, { x: originalX - 20 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(characterGraphics, { x: originalX + 20 }, { duration: 100, easing: tween.easeInOut, onFinish: function onFinish() { tween(characterGraphics, { x: originalX }, { duration: 100, easing: tween.easeInOut }); } }); } }); // Dislike color flash var originalTint = characterGraphics.tint; characterGraphics.tint = 0xFF0000; LK.setTimeout(function () { characterGraphics.tint = originalTint; }, 300); }; return self; }); var FoodItem = Container.expand(function (type) { var self = Container.call(this); var foodGraphics = self.attachAsset(type, { anchorX: 0.5, anchorY: 0.5 }); self.type = type; self.originalX = 0; self.originalY = 0; self.isDragging = false; self.setOriginalPosition = function (x, y) { self.originalX = x; self.originalY = y; self.x = x; self.y = y; }; self.resetPosition = function () { tween(self, { x: self.originalX, y: self.originalY }, { duration: 300, easing: tween.easeOut }); }; self.down = function (x, y, obj) { self.isDragging = true; tween(foodGraphics, { scaleX: 1.1, scaleY: 1.1 }, { duration: 100, easing: tween.easeOut }); }; self.up = function (x, y, obj) { self.isDragging = false; tween(foodGraphics, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeIn }); // Check if dropped on character if (selectedCharacter && self.intersects(selectedCharacter)) { selectedCharacter.feedFood(self.type); } self.resetPosition(); }; return self; }); var SelectionButton = Container.expand(function (characterType) { var self = Container.call(this); var buttonBg = self.attachAsset('selectButton', { anchorX: 0.5, anchorY: 0.5 }); var characterPreview = self.attachAsset(characterType, { anchorX: 0.5, anchorY: 0.5, scaleX: 0.3, scaleY: 0.3 }); var buttonText = new Text2(characterType.toUpperCase(), { size: 24, fill: 0xFFFFFF }); buttonText.anchor.set(0.5, 0.5); buttonText.y = 40; self.addChild(buttonText); self.characterType = characterType; self.down = function (x, y, obj) { tween(buttonBg, { scaleX: 0.95, scaleY: 0.95 }, { duration: 100, easing: tween.easeOut, onFinish: function onFinish() { tween(buttonBg, { scaleX: 1, scaleY: 1 }, { duration: 100, easing: tween.easeIn }); } }); selectCharacter(self.characterType); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x87CEEB }); /**** * Game Code ****/ // Sound effects // UI elements // Food assets // Character assets // Game states var gameState = 'selection'; // 'selection' or 'playing' var selectedCharacter = null; var foodItems = []; var selectionButtons = []; // Food types var foodTypes = ['lettuce', 'pineapple', 'fish', 'sausage', 'strawberry', 'potato', 'broccoli', 'watermelon']; // Title text var titleText = new Text2('Feed the Creatures', { size: 80, fill: 0xFFFFFF }); titleText.anchor.set(0.5, 0.5); titleText.x = 1024; titleText.y = 200; game.addChild(titleText); // Instruction text var instructionText = new Text2('Choose Your Character', { size: 40, fill: 0xFFFFFF }); instructionText.anchor.set(0.5, 0.5); instructionText.x = 1024; instructionText.y = 300; game.addChild(instructionText); // Create character selection buttons var characterTypes = ['female', 'male', 'monster']; for (var i = 0; i < characterTypes.length; i++) { var button = new SelectionButton(characterTypes[i]); button.x = 1024 + (i - 1) * 300; button.y = 600; selectionButtons.push(button); game.addChild(button); } // Create food items (initially hidden) for (var i = 0; i < foodTypes.length; i++) { var food = new FoodItem(foodTypes[i]); food.visible = false; foodItems.push(food); game.addChild(food); } // Reset button (initially hidden) var resetButton = LK.getAsset('resetButton', { anchorX: 0.5, anchorY: 0.5 }); resetButton.x = 1024; resetButton.y = 150; resetButton.visible = false; game.addChild(resetButton); var resetText = new Text2('RESET', { size: 28, fill: 0xFFFFFF }); resetText.anchor.set(0.5, 0.5); resetText.x = 1024; resetText.y = 150; resetText.visible = false; game.addChild(resetText); // Function to select character function selectCharacter(type) { gameState = 'playing'; // Hide selection UI titleText.visible = false; instructionText.visible = false; for (var i = 0; i < selectionButtons.length; i++) { selectionButtons[i].visible = false; } // Create selected character selectedCharacter = new Character(type); selectedCharacter.x = 1024; selectedCharacter.y = 900; game.addChild(selectedCharacter); // Show and position food items setupFoodItems(); // Show reset button resetButton.visible = true; resetText.visible = true; // Show feeding instruction instructionText.setText('Drag food to feed your character!'); instructionText.y = 2500; instructionText.visible = true; } // Function to setup food items function setupFoodItems() { var startX = 200; var startY = 1400; var spacing = 200; for (var i = 0; i < foodItems.length; i++) { var food = foodItems[i]; var row = Math.floor(i / 4); var col = i % 4; var x = startX + col * spacing + col * 80; var y = startY + row * spacing; food.setOriginalPosition(x, y); food.visible = true; } } // Function to reset game function resetGame() { gameState = 'selection'; // Remove selected character if (selectedCharacter) { selectedCharacter.destroy(); selectedCharacter = null; } // Hide food items for (var i = 0; i < foodItems.length; i++) { foodItems[i].visible = false; } // Hide reset button resetButton.visible = false; resetText.visible = false; // Show selection UI titleText.visible = true; instructionText.setText('Choose Your Character'); instructionText.y = 300; instructionText.visible = true; for (var i = 0; i < selectionButtons.length; i++) { selectionButtons[i].visible = true; } } // Drag handling var draggedFood = null; game.move = function (x, y, obj) { if (draggedFood) { draggedFood.x = x; draggedFood.y = y; } }; game.down = function (x, y, obj) { // Check if reset button was clicked if (resetButton.visible) { var resetBounds = { x: resetButton.x - 90, y: resetButton.y - 30, width: 180, height: 60 }; if (x >= resetBounds.x && x <= resetBounds.x + resetBounds.width && y >= resetBounds.y && y <= resetBounds.y + resetBounds.height) { resetGame(); return; } } // Find clicked food item for (var i = 0; i < foodItems.length; i++) { var food = foodItems[i]; if (food.visible && food.intersects({ x: x, y: y, width: 1, height: 1 })) { draggedFood = food; break; } } }; game.up = function (x, y, obj) { draggedFood = null; }; // Game update loop game.update = function () { // No continuous updates needed for this game };
===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,423 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+
+/****
+* Classes
+****/
+var Character = Container.expand(function (type) {
+ var self = Container.call(this);
+ var characterGraphics = self.attachAsset(type, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = type;
+ self.isEating = false;
+ // Character food preferences
+ self.preferences = {
+ female: {
+ loves: ['strawberry', 'watermelon', 'pineapple'],
+ likes: ['lettuce', 'broccoli'],
+ dislikes: ['fish', 'sausage', 'potato']
+ },
+ male: {
+ loves: ['sausage', 'fish', 'potato'],
+ likes: ['watermelon', 'pineapple'],
+ dislikes: ['lettuce', 'broccoli', 'strawberry']
+ },
+ monster: {
+ loves: ['broccoli', 'lettuce', 'fish'],
+ likes: ['potato', 'sausage'],
+ dislikes: ['strawberry', 'watermelon', 'pineapple']
+ }
+ };
+ self.feedFood = function (foodType) {
+ if (self.isEating) return;
+ self.isEating = true;
+ var preference = self.getPreference(foodType);
+ // Feeding animation
+ tween(characterGraphics, {
+ scaleX: 1.2,
+ scaleY: 1.2
+ }, {
+ duration: 200,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(characterGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 200,
+ easing: tween.easeIn
+ });
+ }
+ });
+ // Reaction animation based on preference
+ if (preference === 'loves') {
+ self.showLoveReaction();
+ LK.getSound('happy').play();
+ } else if (preference === 'likes') {
+ self.showLikeReaction();
+ LK.getSound('neutral').play();
+ } else {
+ self.showDislikeReaction();
+ LK.getSound('dislike').play();
+ }
+ LK.setTimeout(function () {
+ self.isEating = false;
+ }, 1000);
+ };
+ self.getPreference = function (foodType) {
+ var prefs = self.preferences[self.type];
+ if (prefs.loves.indexOf(foodType) !== -1) return 'loves';
+ if (prefs.likes.indexOf(foodType) !== -1) return 'likes';
+ return 'dislikes';
+ };
+ self.showLoveReaction = function () {
+ // Happy bounce animation
+ tween(characterGraphics, {
+ y: characterGraphics.y - 30
+ }, {
+ duration: 150,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(characterGraphics, {
+ y: characterGraphics.y + 30
+ }, {
+ duration: 150,
+ easing: tween.bounceOut
+ });
+ }
+ });
+ // Happy color flash
+ var originalTint = characterGraphics.tint;
+ characterGraphics.tint = 0xFFFF00;
+ LK.setTimeout(function () {
+ characterGraphics.tint = originalTint;
+ }, 300);
+ };
+ self.showLikeReaction = function () {
+ // Gentle nod animation
+ tween(characterGraphics, {
+ rotation: 0.1
+ }, {
+ duration: 200,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(characterGraphics, {
+ rotation: 0
+ }, {
+ duration: 200,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ };
+ self.showDislikeReaction = function () {
+ // Shake animation
+ var originalX = characterGraphics.x;
+ tween(characterGraphics, {
+ x: originalX - 20
+ }, {
+ duration: 100,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(characterGraphics, {
+ x: originalX + 20
+ }, {
+ duration: 100,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(characterGraphics, {
+ x: originalX
+ }, {
+ duration: 100,
+ easing: tween.easeInOut
+ });
+ }
+ });
+ }
+ });
+ // Dislike color flash
+ var originalTint = characterGraphics.tint;
+ characterGraphics.tint = 0xFF0000;
+ LK.setTimeout(function () {
+ characterGraphics.tint = originalTint;
+ }, 300);
+ };
+ return self;
+});
+var FoodItem = Container.expand(function (type) {
+ var self = Container.call(this);
+ var foodGraphics = self.attachAsset(type, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.type = type;
+ self.originalX = 0;
+ self.originalY = 0;
+ self.isDragging = false;
+ self.setOriginalPosition = function (x, y) {
+ self.originalX = x;
+ self.originalY = y;
+ self.x = x;
+ self.y = y;
+ };
+ self.resetPosition = function () {
+ tween(self, {
+ x: self.originalX,
+ y: self.originalY
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ };
+ self.down = function (x, y, obj) {
+ self.isDragging = true;
+ tween(foodGraphics, {
+ scaleX: 1.1,
+ scaleY: 1.1
+ }, {
+ duration: 100,
+ easing: tween.easeOut
+ });
+ };
+ self.up = function (x, y, obj) {
+ self.isDragging = false;
+ tween(foodGraphics, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
+ // Check if dropped on character
+ if (selectedCharacter && self.intersects(selectedCharacter)) {
+ selectedCharacter.feedFood(self.type);
+ }
+ self.resetPosition();
+ };
+ return self;
+});
+var SelectionButton = Container.expand(function (characterType) {
+ var self = Container.call(this);
+ var buttonBg = self.attachAsset('selectButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var characterPreview = self.attachAsset(characterType, {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ scaleX: 0.3,
+ scaleY: 0.3
+ });
+ var buttonText = new Text2(characterType.toUpperCase(), {
+ size: 24,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ buttonText.y = 40;
+ self.addChild(buttonText);
+ self.characterType = characterType;
+ self.down = function (x, y, obj) {
+ tween(buttonBg, {
+ scaleX: 0.95,
+ scaleY: 0.95
+ }, {
+ duration: 100,
+ easing: tween.easeOut,
+ onFinish: function onFinish() {
+ tween(buttonBg, {
+ scaleX: 1,
+ scaleY: 1
+ }, {
+ duration: 100,
+ easing: tween.easeIn
+ });
+ }
+ });
+ selectCharacter(self.characterType);
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0x87CEEB
+});
+
+/****
+* Game Code
+****/
+// Sound effects
+// UI elements
+// Food assets
+// Character assets
+// Game states
+var gameState = 'selection'; // 'selection' or 'playing'
+var selectedCharacter = null;
+var foodItems = [];
+var selectionButtons = [];
+// Food types
+var foodTypes = ['lettuce', 'pineapple', 'fish', 'sausage', 'strawberry', 'potato', 'broccoli', 'watermelon'];
+// Title text
+var titleText = new Text2('Feed the Creatures', {
+ size: 80,
+ fill: 0xFFFFFF
+});
+titleText.anchor.set(0.5, 0.5);
+titleText.x = 1024;
+titleText.y = 200;
+game.addChild(titleText);
+// Instruction text
+var instructionText = new Text2('Choose Your Character', {
+ size: 40,
+ fill: 0xFFFFFF
+});
+instructionText.anchor.set(0.5, 0.5);
+instructionText.x = 1024;
+instructionText.y = 300;
+game.addChild(instructionText);
+// Create character selection buttons
+var characterTypes = ['female', 'male', 'monster'];
+for (var i = 0; i < characterTypes.length; i++) {
+ var button = new SelectionButton(characterTypes[i]);
+ button.x = 1024 + (i - 1) * 300;
+ button.y = 600;
+ selectionButtons.push(button);
+ game.addChild(button);
+}
+// Create food items (initially hidden)
+for (var i = 0; i < foodTypes.length; i++) {
+ var food = new FoodItem(foodTypes[i]);
+ food.visible = false;
+ foodItems.push(food);
+ game.addChild(food);
+}
+// Reset button (initially hidden)
+var resetButton = LK.getAsset('resetButton', {
+ anchorX: 0.5,
+ anchorY: 0.5
+});
+resetButton.x = 1024;
+resetButton.y = 150;
+resetButton.visible = false;
+game.addChild(resetButton);
+var resetText = new Text2('RESET', {
+ size: 28,
+ fill: 0xFFFFFF
+});
+resetText.anchor.set(0.5, 0.5);
+resetText.x = 1024;
+resetText.y = 150;
+resetText.visible = false;
+game.addChild(resetText);
+// Function to select character
+function selectCharacter(type) {
+ gameState = 'playing';
+ // Hide selection UI
+ titleText.visible = false;
+ instructionText.visible = false;
+ for (var i = 0; i < selectionButtons.length; i++) {
+ selectionButtons[i].visible = false;
+ }
+ // Create selected character
+ selectedCharacter = new Character(type);
+ selectedCharacter.x = 1024;
+ selectedCharacter.y = 900;
+ game.addChild(selectedCharacter);
+ // Show and position food items
+ setupFoodItems();
+ // Show reset button
+ resetButton.visible = true;
+ resetText.visible = true;
+ // Show feeding instruction
+ instructionText.setText('Drag food to feed your character!');
+ instructionText.y = 2500;
+ instructionText.visible = true;
+}
+// Function to setup food items
+function setupFoodItems() {
+ var startX = 200;
+ var startY = 1400;
+ var spacing = 200;
+ for (var i = 0; i < foodItems.length; i++) {
+ var food = foodItems[i];
+ var row = Math.floor(i / 4);
+ var col = i % 4;
+ var x = startX + col * spacing + col * 80;
+ var y = startY + row * spacing;
+ food.setOriginalPosition(x, y);
+ food.visible = true;
+ }
+}
+// Function to reset game
+function resetGame() {
+ gameState = 'selection';
+ // Remove selected character
+ if (selectedCharacter) {
+ selectedCharacter.destroy();
+ selectedCharacter = null;
+ }
+ // Hide food items
+ for (var i = 0; i < foodItems.length; i++) {
+ foodItems[i].visible = false;
+ }
+ // Hide reset button
+ resetButton.visible = false;
+ resetText.visible = false;
+ // Show selection UI
+ titleText.visible = true;
+ instructionText.setText('Choose Your Character');
+ instructionText.y = 300;
+ instructionText.visible = true;
+ for (var i = 0; i < selectionButtons.length; i++) {
+ selectionButtons[i].visible = true;
+ }
+}
+// Drag handling
+var draggedFood = null;
+game.move = function (x, y, obj) {
+ if (draggedFood) {
+ draggedFood.x = x;
+ draggedFood.y = y;
+ }
+};
+game.down = function (x, y, obj) {
+ // Check if reset button was clicked
+ if (resetButton.visible) {
+ var resetBounds = {
+ x: resetButton.x - 90,
+ y: resetButton.y - 30,
+ width: 180,
+ height: 60
+ };
+ if (x >= resetBounds.x && x <= resetBounds.x + resetBounds.width && y >= resetBounds.y && y <= resetBounds.y + resetBounds.height) {
+ resetGame();
+ return;
+ }
+ }
+ // Find clicked food item
+ for (var i = 0; i < foodItems.length; i++) {
+ var food = foodItems[i];
+ if (food.visible && food.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ draggedFood = food;
+ break;
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ draggedFood = null;
+};
+// Game update loop
+game.update = function () {
+ // No continuous updates needed for this game
+};
\ No newline at end of file