User prompt
crea 4 caminos de tierra en direciion al jugador
User prompt
crea un barra de vida para el jugador de 100 puntos y cuando el enemigo lo toque le quite 20 puntos
User prompt
quiero que los enemigos se dirijan hacia el personaje principal y cuando lo logren tocar sea el fin del juego ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
quiero que los enemigos lleguen mas rapido ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
quiero que los enemigos lleguen de la parte superior de la pantalla ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(sword, 200, {' Line Number: 128 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
quiero crear un juego ambientado en la edad media tipo tap y up
User prompt
borra todo
Code edit (1 edits merged)
Please save this source code
User prompt
Menu Master
User prompt
quiero crear un menu
Initial prompt
quiero una idea repetitiva y adictiva
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var CategorySection = Container.expand(function (categoryName) {
var self = Container.call(this);
self.categoryName = categoryName;
self.items = [];
var header = self.attachAsset('categoryHeader', {
anchorX: 0.5,
anchorY: 0
});
var headerText = new Text2(categoryName, {
size: 28,
fill: 0xFFFFFF
});
headerText.anchor.set(0.5, 0.5);
headerText.y = 30;
self.addChild(headerText);
self.addItem = function (foodItem) {
self.items.push(foodItem);
self.repositionItems();
};
self.removeItem = function (foodItem) {
var index = self.items.indexOf(foodItem);
if (index > -1) {
self.items.splice(index, 1);
self.repositionItems();
}
};
self.repositionItems = function () {
for (var i = 0; i < self.items.length; i++) {
self.items[i].x = 0;
self.items[i].y = 80 + i * 90;
}
};
self.getHeight = function () {
return 60 + self.items.length * 90;
};
return self;
});
var FoodItem = Container.expand(function (foodData) {
var self = Container.call(this);
self.foodData = foodData;
self.price = foodData.basePrice;
self.isOnMenu = false;
var background = self.attachAsset('foodItem', {
anchorX: 0.5,
anchorY: 0.5
});
var nameText = new Text2(foodData.name, {
size: 24,
fill: 0x333333
});
nameText.anchor.set(0, 0.5);
nameText.x = -140;
nameText.y = -10;
self.addChild(nameText);
var priceText = new Text2('$' + self.price.toFixed(2), {
size: 20,
fill: 0x666666
});
priceText.anchor.set(0, 0.5);
priceText.x = -140;
priceText.y = 15;
self.addChild(priceText);
var priceButton = self.attachAsset('priceButton', {
anchorX: 0.5,
anchorY: 0.5,
x: 120
});
var buttonText = new Text2('$', {
size: 16,
fill: 0xFFFFFF
});
buttonText.anchor.set(0.5, 0.5);
buttonText.x = 120;
self.addChild(buttonText);
self.updatePrice = function (newPrice) {
self.price = newPrice;
priceText.setText('$' + self.price.toFixed(2));
if (self.isOnMenu) {
calculateProfit();
}
};
self.setOnMenu = function (onMenu) {
self.isOnMenu = onMenu;
if (onMenu) {
background.tint = 0xffffff;
} else {
background.tint = 0xe8e8e8;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xf5f5f5
});
/****
* Game Code
****/
// Game data
var foodDatabase = [{
name: 'Caesar Salad',
category: 'Appetizers',
basePrice: 8.99
}, {
name: 'Chicken Wings',
category: 'Appetizers',
basePrice: 12.99
}, {
name: 'Grilled Salmon',
category: 'Main Courses',
basePrice: 24.99
}, {
name: 'Beef Burger',
category: 'Main Courses',
basePrice: 16.99
}, {
name: 'Pasta Carbonara',
category: 'Main Courses',
basePrice: 18.99
}, {
name: 'Chocolate Cake',
category: 'Desserts',
basePrice: 7.99
}, {
name: 'Ice Cream',
category: 'Desserts',
basePrice: 5.99
}];
var categories = ['Appetizers', 'Main Courses', 'Desserts'];
var menuItems = [];
var inventoryItems = [];
var categorySections = {};
var draggedItem = null;
var currentProfit = 0;
var customerSatisfaction = 75;
// Create menu board
var menuBoard = game.attachAsset('menuBoard', {
anchorX: 0.5,
anchorY: 0,
x: 1024,
y: 50
});
// Create inventory panel
var inventoryY = 200;
for (var i = 0; i < foodDatabase.length; i++) {
var foodItem = new FoodItem(foodDatabase[i]);
foodItem.x = 150;
foodItem.y = inventoryY + i * 110;
game.addChild(foodItem);
inventoryItems.push(foodItem);
}
// Create category sections on menu board
var currentY = 100;
for (var j = 0; j < categories.length; j++) {
var section = new CategorySection(categories[j]);
section.x = 1024;
section.y = currentY;
game.addChild(section);
categorySections[categories[j]] = section;
currentY += 300;
}
// UI Elements
var profitText = new Text2('Profit: $0.00', {
size: 36,
fill: 0x2E7D32
});
profitText.anchor.set(0.5, 0);
LK.gui.top.addChild(profitText);
var satisfactionText = new Text2('Satisfaction: 75%', {
size: 32,
fill: 0x1976D2
});
satisfactionText.anchor.set(1, 0);
LK.gui.topRight.addChild(satisfactionText);
// Helper functions
function calculateProfit() {
currentProfit = 0;
for (var i = 0; i < menuItems.length; i++) {
var item = menuItems[i];
var baseValue = item.foodData.basePrice * 0.3;
var priceMultiplier = Math.max(0.1, 2 - item.price / item.foodData.basePrice);
currentProfit += baseValue * priceMultiplier;
}
profitText.setText('Profit: $' + currentProfit.toFixed(2));
// Update customer satisfaction based on pricing
var avgPriceRatio = 0;
if (menuItems.length > 0) {
for (var j = 0; j < menuItems.length; j++) {
avgPriceRatio += menuItems[j].price / menuItems[j].foodData.basePrice;
}
avgPriceRatio /= menuItems.length;
customerSatisfaction = Math.max(10, Math.min(100, 100 - (avgPriceRatio - 1) * 50));
}
satisfactionText.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
}
function findNearestCategory(x, y) {
var minDistance = Infinity;
var nearestCategory = null;
for (var categoryName in categorySections) {
var section = categorySections[categoryName];
var distance = Math.sqrt(Math.pow(x - section.x, 2) + Math.pow(y - section.y, 2));
if (distance < minDistance && distance < 200) {
minDistance = distance;
nearestCategory = section;
}
}
return nearestCategory;
}
function createMenuItemCopy(originalItem) {
var newItem = new FoodItem(originalItem.foodData);
newItem.setOnMenu(true);
menuItems.push(newItem);
game.addChild(newItem);
return newItem;
}
// Event handlers
game.down = function (x, y, obj) {
for (var i = 0; i < inventoryItems.length; i++) {
var item = inventoryItems[i];
if (item.intersects({
x: x,
y: y,
width: 1,
height: 1
})) {
draggedItem = createMenuItemCopy(item);
draggedItem.x = x;
draggedItem.y = y;
draggedItem.alpha = 0.8;
LK.getSound('itemPlace').play();
return;
}
}
// Check for price button clicks
for (var j = 0; j < menuItems.length; j++) {
var menuItem = menuItems[j];
var buttonX = menuItem.x + 120;
var buttonY = menuItem.y;
if (Math.abs(x - buttonX) < 30 && Math.abs(y - buttonY) < 20) {
var newPrice = menuItem.price + 1;
if (newPrice > menuItem.foodData.basePrice * 3) {
newPrice = menuItem.foodData.basePrice * 0.5;
}
menuItem.updatePrice(newPrice);
LK.getSound('priceChange').play();
return;
}
}
};
game.move = function (x, y, obj) {
if (draggedItem) {
draggedItem.x = x;
draggedItem.y = y;
var nearestCategory = findNearestCategory(x, y);
if (nearestCategory) {
nearestCategory.alpha = 0.7;
}
// Reset alpha for all categories
for (var categoryName in categorySections) {
if (categorySections[categoryName] !== nearestCategory) {
categorySections[categoryName].alpha = 1;
}
}
}
};
game.up = function (x, y, obj) {
if (draggedItem) {
var nearestCategory = findNearestCategory(x, y);
if (nearestCategory && nearestCategory.categoryName === draggedItem.foodData.category) {
// Place item in correct category
nearestCategory.addItem(draggedItem);
draggedItem.alpha = 1;
calculateProfit();
tween(draggedItem, {
x: nearestCategory.x,
y: nearestCategory.y + nearestCategory.getHeight() - 45
}, {
duration: 300,
easing: tween.easeOut
});
} else {
// Remove item if not placed correctly
draggedItem.destroy();
var index = menuItems.indexOf(draggedItem);
if (index > -1) {
menuItems.splice(index, 1);
}
}
// Reset category alpha
for (var categoryName in categorySections) {
categorySections[categoryName].alpha = 1;
}
draggedItem = null;
}
};
// Initialize profit calculation
calculateProfit(); ===================================================================
--- original.js
+++ change.js
@@ -1,6 +1,310 @@
-/****
+/****
+* Plugins
+****/
+var tween = LK.import("@upit/tween.v1");
+var storage = LK.import("@upit/storage.v1");
+
+/****
+* Classes
+****/
+var CategorySection = Container.expand(function (categoryName) {
+ var self = Container.call(this);
+ self.categoryName = categoryName;
+ self.items = [];
+ var header = self.attachAsset('categoryHeader', {
+ anchorX: 0.5,
+ anchorY: 0
+ });
+ var headerText = new Text2(categoryName, {
+ size: 28,
+ fill: 0xFFFFFF
+ });
+ headerText.anchor.set(0.5, 0.5);
+ headerText.y = 30;
+ self.addChild(headerText);
+ self.addItem = function (foodItem) {
+ self.items.push(foodItem);
+ self.repositionItems();
+ };
+ self.removeItem = function (foodItem) {
+ var index = self.items.indexOf(foodItem);
+ if (index > -1) {
+ self.items.splice(index, 1);
+ self.repositionItems();
+ }
+ };
+ self.repositionItems = function () {
+ for (var i = 0; i < self.items.length; i++) {
+ self.items[i].x = 0;
+ self.items[i].y = 80 + i * 90;
+ }
+ };
+ self.getHeight = function () {
+ return 60 + self.items.length * 90;
+ };
+ return self;
+});
+var FoodItem = Container.expand(function (foodData) {
+ var self = Container.call(this);
+ self.foodData = foodData;
+ self.price = foodData.basePrice;
+ self.isOnMenu = false;
+ var background = self.attachAsset('foodItem', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ var nameText = new Text2(foodData.name, {
+ size: 24,
+ fill: 0x333333
+ });
+ nameText.anchor.set(0, 0.5);
+ nameText.x = -140;
+ nameText.y = -10;
+ self.addChild(nameText);
+ var priceText = new Text2('$' + self.price.toFixed(2), {
+ size: 20,
+ fill: 0x666666
+ });
+ priceText.anchor.set(0, 0.5);
+ priceText.x = -140;
+ priceText.y = 15;
+ self.addChild(priceText);
+ var priceButton = self.attachAsset('priceButton', {
+ anchorX: 0.5,
+ anchorY: 0.5,
+ x: 120
+ });
+ var buttonText = new Text2('$', {
+ size: 16,
+ fill: 0xFFFFFF
+ });
+ buttonText.anchor.set(0.5, 0.5);
+ buttonText.x = 120;
+ self.addChild(buttonText);
+ self.updatePrice = function (newPrice) {
+ self.price = newPrice;
+ priceText.setText('$' + self.price.toFixed(2));
+ if (self.isOnMenu) {
+ calculateProfit();
+ }
+ };
+ self.setOnMenu = function (onMenu) {
+ self.isOnMenu = onMenu;
+ if (onMenu) {
+ background.tint = 0xffffff;
+ } else {
+ background.tint = 0xe8e8e8;
+ }
+ };
+ return self;
+});
+
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x000000
-});
\ No newline at end of file
+ backgroundColor: 0xf5f5f5
+});
+
+/****
+* Game Code
+****/
+// Game data
+var foodDatabase = [{
+ name: 'Caesar Salad',
+ category: 'Appetizers',
+ basePrice: 8.99
+}, {
+ name: 'Chicken Wings',
+ category: 'Appetizers',
+ basePrice: 12.99
+}, {
+ name: 'Grilled Salmon',
+ category: 'Main Courses',
+ basePrice: 24.99
+}, {
+ name: 'Beef Burger',
+ category: 'Main Courses',
+ basePrice: 16.99
+}, {
+ name: 'Pasta Carbonara',
+ category: 'Main Courses',
+ basePrice: 18.99
+}, {
+ name: 'Chocolate Cake',
+ category: 'Desserts',
+ basePrice: 7.99
+}, {
+ name: 'Ice Cream',
+ category: 'Desserts',
+ basePrice: 5.99
+}];
+var categories = ['Appetizers', 'Main Courses', 'Desserts'];
+var menuItems = [];
+var inventoryItems = [];
+var categorySections = {};
+var draggedItem = null;
+var currentProfit = 0;
+var customerSatisfaction = 75;
+// Create menu board
+var menuBoard = game.attachAsset('menuBoard', {
+ anchorX: 0.5,
+ anchorY: 0,
+ x: 1024,
+ y: 50
+});
+// Create inventory panel
+var inventoryY = 200;
+for (var i = 0; i < foodDatabase.length; i++) {
+ var foodItem = new FoodItem(foodDatabase[i]);
+ foodItem.x = 150;
+ foodItem.y = inventoryY + i * 110;
+ game.addChild(foodItem);
+ inventoryItems.push(foodItem);
+}
+// Create category sections on menu board
+var currentY = 100;
+for (var j = 0; j < categories.length; j++) {
+ var section = new CategorySection(categories[j]);
+ section.x = 1024;
+ section.y = currentY;
+ game.addChild(section);
+ categorySections[categories[j]] = section;
+ currentY += 300;
+}
+// UI Elements
+var profitText = new Text2('Profit: $0.00', {
+ size: 36,
+ fill: 0x2E7D32
+});
+profitText.anchor.set(0.5, 0);
+LK.gui.top.addChild(profitText);
+var satisfactionText = new Text2('Satisfaction: 75%', {
+ size: 32,
+ fill: 0x1976D2
+});
+satisfactionText.anchor.set(1, 0);
+LK.gui.topRight.addChild(satisfactionText);
+// Helper functions
+function calculateProfit() {
+ currentProfit = 0;
+ for (var i = 0; i < menuItems.length; i++) {
+ var item = menuItems[i];
+ var baseValue = item.foodData.basePrice * 0.3;
+ var priceMultiplier = Math.max(0.1, 2 - item.price / item.foodData.basePrice);
+ currentProfit += baseValue * priceMultiplier;
+ }
+ profitText.setText('Profit: $' + currentProfit.toFixed(2));
+ // Update customer satisfaction based on pricing
+ var avgPriceRatio = 0;
+ if (menuItems.length > 0) {
+ for (var j = 0; j < menuItems.length; j++) {
+ avgPriceRatio += menuItems[j].price / menuItems[j].foodData.basePrice;
+ }
+ avgPriceRatio /= menuItems.length;
+ customerSatisfaction = Math.max(10, Math.min(100, 100 - (avgPriceRatio - 1) * 50));
+ }
+ satisfactionText.setText('Satisfaction: ' + Math.round(customerSatisfaction) + '%');
+}
+function findNearestCategory(x, y) {
+ var minDistance = Infinity;
+ var nearestCategory = null;
+ for (var categoryName in categorySections) {
+ var section = categorySections[categoryName];
+ var distance = Math.sqrt(Math.pow(x - section.x, 2) + Math.pow(y - section.y, 2));
+ if (distance < minDistance && distance < 200) {
+ minDistance = distance;
+ nearestCategory = section;
+ }
+ }
+ return nearestCategory;
+}
+function createMenuItemCopy(originalItem) {
+ var newItem = new FoodItem(originalItem.foodData);
+ newItem.setOnMenu(true);
+ menuItems.push(newItem);
+ game.addChild(newItem);
+ return newItem;
+}
+// Event handlers
+game.down = function (x, y, obj) {
+ for (var i = 0; i < inventoryItems.length; i++) {
+ var item = inventoryItems[i];
+ if (item.intersects({
+ x: x,
+ y: y,
+ width: 1,
+ height: 1
+ })) {
+ draggedItem = createMenuItemCopy(item);
+ draggedItem.x = x;
+ draggedItem.y = y;
+ draggedItem.alpha = 0.8;
+ LK.getSound('itemPlace').play();
+ return;
+ }
+ }
+ // Check for price button clicks
+ for (var j = 0; j < menuItems.length; j++) {
+ var menuItem = menuItems[j];
+ var buttonX = menuItem.x + 120;
+ var buttonY = menuItem.y;
+ if (Math.abs(x - buttonX) < 30 && Math.abs(y - buttonY) < 20) {
+ var newPrice = menuItem.price + 1;
+ if (newPrice > menuItem.foodData.basePrice * 3) {
+ newPrice = menuItem.foodData.basePrice * 0.5;
+ }
+ menuItem.updatePrice(newPrice);
+ LK.getSound('priceChange').play();
+ return;
+ }
+ }
+};
+game.move = function (x, y, obj) {
+ if (draggedItem) {
+ draggedItem.x = x;
+ draggedItem.y = y;
+ var nearestCategory = findNearestCategory(x, y);
+ if (nearestCategory) {
+ nearestCategory.alpha = 0.7;
+ }
+ // Reset alpha for all categories
+ for (var categoryName in categorySections) {
+ if (categorySections[categoryName] !== nearestCategory) {
+ categorySections[categoryName].alpha = 1;
+ }
+ }
+ }
+};
+game.up = function (x, y, obj) {
+ if (draggedItem) {
+ var nearestCategory = findNearestCategory(x, y);
+ if (nearestCategory && nearestCategory.categoryName === draggedItem.foodData.category) {
+ // Place item in correct category
+ nearestCategory.addItem(draggedItem);
+ draggedItem.alpha = 1;
+ calculateProfit();
+ tween(draggedItem, {
+ x: nearestCategory.x,
+ y: nearestCategory.y + nearestCategory.getHeight() - 45
+ }, {
+ duration: 300,
+ easing: tween.easeOut
+ });
+ } else {
+ // Remove item if not placed correctly
+ draggedItem.destroy();
+ var index = menuItems.indexOf(draggedItem);
+ if (index > -1) {
+ menuItems.splice(index, 1);
+ }
+ }
+ // Reset category alpha
+ for (var categoryName in categorySections) {
+ categorySections[categoryName].alpha = 1;
+ }
+ draggedItem = null;
+ }
+};
+// Initialize profit calculation
+calculateProfit();
\ No newline at end of file