User prompt
timer should start in 20 seconds
User prompt
move level to the left corner and in the right put a timer. each level will have a timer countdown
User prompt
add 5 levels more
User prompt
when order is complete, hide bubble and shadow
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'height')' in or related to this line: 'var progressBar = LK.getAsset('gaugeBar', {' Line Number: 198
User prompt
Please fix the bug: 'Uncaught TypeError: Cannot read properties of undefined (reading 'height')' in or related to this line: 'var progressBar = LK.getAsset('gaugeBar', {' Line Number: 198
User prompt
add a progres bar below the top background
User prompt
aligne inventory items to be equidistant from each other and the sides
User prompt
make inventory items 30% bigger
User prompt
move items inside of customer bubble 20 pixels up
User prompt
make bubble transparent
Code edit (1 edits merged)
Please save this source code
User prompt
make sure after level 1 is complete we move to level2
User prompt
show inventoy all the time with all the items, resfreshmet, icecream, snacks and umbrella
User prompt
every level show all the items availabe in the bottom
User prompt
show all items in the bottom on game start
User prompt
add transaperncy to bubble
User prompt
move items inside buble 20 pixels up
User prompt
move item on bubble 20 pixels up
User prompt
show all items in inventroy bottom all the time
User prompt
add trasnparecny to bottom backtorund
User prompt
add transparecny to top background
User prompt
make sure bubble is positioned on top of customer
User prompt
move bubble closer to customer
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'length')' in or related to this line: 'self.orderAsset1 = self.attachAsset(order[0], {' Line Number: 169
===================================================================
--- original.js
+++ change.js
@@ -1,21 +1,21 @@
/****
* Classes
****/
// Customer class
-var Customer = Container.expand(function (assetType) {
+var Customer = Container.expand(function () {
var self = Container.call(this);
- var customerGraphics = self.attachAsset(assetType, {
+ var customerGraphics = self.attachAsset('customer', {
anchorX: 0.5,
anchorY: 0.5
});
- self.orderBubble = null;
- self.shadow = LK.getAsset('shadow', {
+ var shadow = self.attachAsset('shadow', {
anchorX: 0.5,
- anchorY: 0.5
+ anchorY: 0
});
- self.shadow.alpha = 0.5;
- self.addChild(self.shadow);
+ shadow.y = customerGraphics.height / 2;
+ shadow.alpha = 0.5;
+ self.orderBubble = null;
self.gaugeBar = null;
self.moveToPosition = function (x, y) {
var distance = Math.sqrt(Math.pow(self.x - x, 2) + Math.pow(self.y - y, 2));
var speed = distance / 120; // 60 frames per second
@@ -25,33 +25,28 @@
if (Math.abs(self.x - x) > speed || Math.abs(self.y - y) > speed) {
self.x += dx;
self.y += dy;
self.orderBubble.visible = false;
- self.shadow.x = self.x;
- self.shadow.y = self.y + customerGraphics.height / 2;
- self.orderBubble.x = self.x;
- self.orderBubble.y = self.y - self.height / 2 - self.orderBubble.height / 2;
} else {
self.x = x;
self.y = y;
self.orderBubble.alpha = 0;
- self.orderBubble.visible = true;
- var fadeInInterval = LK.setInterval(function () {
- if (self.orderBubble.alpha < 1) {
- self.orderBubble.alpha += 0.1;
- }
- if (self.orderBubble.alpha >= 1) {
- self.orderBubble.alpha = 1;
- LK.clearInterval(fadeInInterval);
- }
- }, 100);
+ LK.setTimeout(function () {
+ self.orderBubble.visible = true;
+ var fadeInInterval = LK.setInterval(function () {
+ if (self.orderBubble.alpha < 1) {
+ self.orderBubble.alpha += 0.1;
+ }
+ if (self.orderBubble.alpha >= 1) {
+ self.orderBubble.alpha = 1;
+ LK.clearInterval(fadeInInterval);
+ }
+ }, 100);
+ }, 500);
self.update = function () {
// Add small up and down movement to the customers
self.y += Math.sin(LK.ticks / 10) * 0.5;
- self.shadow.x = self.x;
- self.shadow.y = self.y + customerGraphics.height / 2;
- self.orderBubble.x = self.x;
- self.orderBubble.y = self.y - self.height / 2 - self.orderBubble.height / 2;
+ shadow.y = customerGraphics.height / 2;
};
}
};
};
@@ -82,9 +77,8 @@
self.getOrder = function () {
return self.order;
};
self.on('down', function (x, y, obj) {
- LK.getSound('tap').play(); // Play tap sound when customer is touched
if (self.orderBubble && !self.orderBubble.visible) {
self.orderBubble.visible = true;
}
if (selectedItem && self.order.includes(selectedItem.getType())) {
@@ -112,9 +106,8 @@
return self.type;
};
self.alpha = 0.5; // Start items as dimmed
self.on('down', function (x, y, obj) {
- LK.getSound('tap').play(); // Play tap sound when item is touched
if (selectedItem) {
selectedItem.scaleX = 1;
selectedItem.scaleY = 1;
selectedItem.alpha = 0.5; // Dim the previously selected item
@@ -130,42 +123,34 @@
var OrderBubble = Container.expand(function (order) {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
- anchorY: 0.5,
- alpha: 0.8 // Set alpha to 0.8 to make it a little transparent
+ anchorY: 0.5
});
self.order = order;
if (Array.isArray(order)) {
if (order.length > 0) {
- if (order && Array.isArray(order) && order.length > 0) {
- self.orderAsset1 = self.attachAsset(order[0], {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.orderAsset1.type = order[0];
- self.orderAsset1.x = order.length > 1 ? -60 : 0;
- self.orderAsset1.y -= 20;
- }
+ self.orderAsset1 = self.attachAsset(order[0], {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.orderAsset1.type = order[0];
+ self.orderAsset1.x = order.length > 1 ? -60 : 0;
}
if (order.length > 1) {
- if (order && Array.isArray(order) && order.length > 1) {
- self.orderAsset2 = self.attachAsset(order[1], {
- anchorX: 0.5,
- anchorY: 0.5
- });
- self.orderAsset2.type = order[1];
- self.orderAsset2.x = 60;
- self.orderAsset2.y -= 20;
- }
+ self.orderAsset2 = self.attachAsset(order[1], {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ self.orderAsset2.type = order[1];
+ self.orderAsset2.x = 60;
}
} else {
self.orderAsset = self.attachAsset(order, {
anchorX: 0.5,
anchorY: 0.5
});
self.orderAsset.x = 0;
- self.orderAsset.y -= 20;
}
});
/****
@@ -177,21 +162,8 @@
/****
* Game Code
****/
-function destroyOrphanShadows() {
- var allShadows = game.children.filter(function (child) {
- return child.assetType === 'shadow';
- });
- allShadows.forEach(function (shadow) {
- var belongsToCustomer = customers.some(function (customer) {
- return customer.shadow === shadow;
- });
- if (!belongsToCustomer) {
- shadow.destroy();
- }
- });
-}
var background = LK.getAsset('background', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
@@ -202,17 +174,16 @@
anchorX: 0.5,
anchorY: 0,
x: 2048 / 2,
y: 0,
- alpha: 0.6 // Set alpha to 0.5
+ alpha: 0.5 // Set transparency to 50%
});
game.addChild(backgroundTop);
var backgroundBottom = LK.getAsset('backgroundBottom', {
anchorX: 0.5,
anchorY: 1,
x: 2048 / 2,
- y: 2732,
- alpha: 0.6 // Set alpha to 0.5
+ y: 2732
});
game.addChild(backgroundBottom);
// Level class
//<Assets used in the game will automatically appear here>
@@ -224,66 +195,27 @@
};
var selectedItem = null; // Variable to track the currently selected item
var currentLevel = null; // Variable to track the current level
var customers = [];
-var shadowPool = [];
var items = [];
-var customerPool = [];
var inventory = []; // Inventory array to hold all items from the bar
-var scoreTxt = new Text2(LK.getScore(), {
+var score = 0;
+var scoreTxt = new Text2('0', {
size: 90,
fill: "#ffffff",
stroke: "#000000",
- strokeThickness: 5,
- font: "monospace"
+ strokeThickness: 5
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var levelTxt = new Text2('LVL 1', {
size: 80,
fill: "#ffffff",
stroke: "#000000",
- strokeThickness: 5,
- font: "monospace"
+ strokeThickness: 5
});
-levelTxt.anchor.set(0, 0);
-LK.gui.topLeft.addChild(levelTxt);
-var timeTxt = new Text2('Time: 20', {
- size: 80,
- fill: "#ffffff",
- stroke: "#000000",
- strokeThickness: 5,
- font: "monospace"
-});
-timeTxt.anchor.set(1, 0);
-LK.gui.topRight.addChild(timeTxt);
-var levelTimer = 20; // Initialize level timer to 20 seconds
-var timerInterval = LK.setInterval(function () {
- if (levelTimer > 0) {
- levelTimer--;
- timeTxt.setText('Time: ' + levelTimer);
- } else {
- // Handle level timeout (e.g., end game or move to next level)
- LK.clearInterval(timerInterval);
- // Disable customer clicks
- customers.forEach(function (customer) {
- customer.interactive = false;
- });
- var timesupAsset = LK.getAsset('timesup', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 / 2
- });
- game.addChild(timesupAsset);
- LK.getSound('gameover').play(); // Play game over sound
- LK.clearInterval(timerInterval);
- LK.setTimeout(function () {
- timesupAsset.destroy();
- LK.showGameOver();
- }, 2000);
- }
-}, 2000);
+levelTxt.anchor.set(1, 0);
+LK.gui.topRight.addChild(levelTxt);
// Function to check if all items of an order are delivered
function checkOrderFulfillment(customer) {
// Check if all items are dimmed
var allDimmed = true;
@@ -293,13 +225,12 @@
if (customer.orderBubble.orderAsset2 && customer.orderBubble.orderAsset2.alpha === 1) {
allDimmed = false;
}
if (allDimmed) {
- LK.getSound('ordercomplete').play(); // Play ordercomplete sound when an order is complete
// Increase score only if it hasn't been increased for this customer
if (!customer.scoreAdded) {
- LK.setScore(LK.getScore() + 10);
- scoreTxt.setText(LK.getScore());
+ score += 10;
+ scoreTxt.setText(score);
customer.scoreAdded = true; // Mark that score has been added for this customer
}
// Spin the customer on its axis
var spinInterval = LK.setInterval(function () {
@@ -307,46 +238,19 @@
}, 16.67); // Approximately 60 FPS
// Wait for one second and then destroy the customer and order bubble
LK.setTimeout(function () {
LK.clearInterval(spinInterval);
+ customer.destroy();
customer.orderBubble.destroy();
- // Shadow is now a property of the customer, no need to destroy it separately
- customer.visible = false;
- customerPool.push(customer);
}, 1000);
- // Check if all orders are fulfilled
- var allOrdersFulfilled = true;
- for (var i = 0; i < customers.length; i++) {
- if (customers[i].orderBubble.orderAsset1 && customers[i].orderBubble.orderAsset1.alpha === 1) {
- allOrdersFulfilled = false;
- break;
- }
- if (customers[i].orderBubble.orderAsset2 && customers[i].orderBubble.orderAsset2.alpha === 1) {
- allOrdersFulfilled = false;
- break;
- }
- }
- // If all orders are fulfilled, stop the timer
- if (allOrdersFulfilled) {
- LK.clearInterval(timerInterval);
- }
}
}
// Function to create a new customer
function createCustomer() {
if (customers.length >= currentLevel.customerCount) {
return;
}
- var customerAssets = ['customer', 'customer2', 'customer3', 'customer4'];
- var randomAsset = customerAssets[Math.floor(Math.random() * customerAssets.length)];
- var customer;
- if (customerPool.length > 0) {
- customer = customerPool.pop();
- customer.visible = true;
- customer.setOrder(order);
- } else {
- customer = new Customer(randomAsset);
- }
+ var customer = new Customer();
var safeDistance = 500; // Minimum distance between customers
var validPosition = false;
while (!validPosition) {
customer.x = Math.random() * (2048 * 0.8) + 2048 * 0.1; // Spawn customers within the middle 80% of the screen
@@ -363,42 +267,34 @@
var order = ['towel', 'umbrella', 'refreshment', 'snack'].sort(function () {
return 0.5 - Math.random();
}).slice(0, Math.floor(Math.random() * 2) + 1);
customer.setOrder(order);
- // Ensure items are made visible if any customer needs that item
- order.forEach(function (item) {
- var inventoryItem = inventory.find(function (invItem) {
- return invItem.getType() === item;
- });
- if (inventoryItem) {
- inventoryItem.visible = true;
- }
- });
customers.push(customer);
customer.rotation = 0;
game.addChild(customer);
- // Shadow is now a property of the customer, no need to add it separately
- game.addChild(customer.orderBubble);
customer.x = Math.random() < 0.5 ? -200 : 2048 + 200; // Spawn customers from left or right side of the screen
customer.y = Math.random() * (2200 - 646.4) + 646.4;
customer.moveToPosition(Math.random() * (2048 * 0.8) + 2048 * 0.1, Math.random() * (2200 - 646.4) + 646.4);
}
// Function to create a new item
function createItem(type, x, y) {
- // Ensure items are always visible at the bottom of the screen
+ if (!currentLevel.items.includes(type)) {
+ return;
+ }
var item = new Item(type);
item.x = x;
item.y = y;
- item.width = 260; // Increase width by 30%
- item.height = 260; // Increase height by 30%
+ item.width = 200;
+ item.height = 200;
items.push(item);
inventory.push(item); // Add item to inventory array
- if (!item.parent) {
- game.addChild(item);
- }
+ item.visible = true; // Show item on game start
+ game.addChild(item);
}
// Initialize level data
-var levels = [new Level(1, 3, ['towel', 'umbrella']), new Level(2, 4, ['towel', 'umbrella', 'refreshment']), new Level(3, 5, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(4, 5, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(5, 6, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(6, 7, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(7, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(8, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(9, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(10, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(11, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(12, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(13, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(14, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(15, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(16, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(17, 8, ['towel', 'umbrella', 'refreshment', 'snack']), new Level(18, 8, ['towel', 'umbrella', 'refreshment', 'snack'])];
+var levels = [new Level(1, 3, ['towel', 'umbrella']), new Level(3, 4, ['towel', 'umbrella', 'refreshment']), new Level(4, 5, ['towel', 'umbrella'])
+// Add more levels as needed
+];
currentLevel = levels[0];
// Create initial customers
for (var i = 0; i < currentLevel.customerCount; i++) {
createCustomer();
@@ -411,9 +307,8 @@
for (var i = 0; i < customers.length; i++) {
if (customers[i].orderBubble.orderAsset1 && customers[i].orderBubble.orderAsset1.alpha === 1) {
allOrdersFulfilled = false;
break;
- destroyOrphanShadows();
}
if (customers[i].orderBubble.orderAsset2 && customers[i].orderBubble.orderAsset2.alpha === 1) {
allOrdersFulfilled = false;
break;
@@ -423,83 +318,36 @@
if (allOrdersFulfilled) {
var nextLevelIndex = levels.indexOf(currentLevel) + 1;
if (nextLevelIndex < levels.length) {
LK.setTimeout(function () {
- LK.getSound('nextlevel').play();
- }, 500);
- LK.setTimeout(function () {
- var levelupAsset = LK.getAsset('levelup', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 / 2
- });
- game.addChild(levelupAsset);
- LK.setTimeout(function () {
- levelupAsset.destroy();
- currentLevel = levels[nextLevelIndex];
- // Clear current customers and items
- for (var i = 0; i < customers.length; i++) {
- customers[i].destroy();
- }
- customers = [];
- // Ensure items are always visible at the bottom of the screen
- for (var i = 0; i < items.length; i++) {
- items[i].visible = true;
- }
- // Create new customers for the next level
- for (var i = 0; i < currentLevel.customerCount; i++) {
- createCustomer();
- }
- // Ensure items are made visible if any customer needs that item
- customers.forEach(function (customer) {
- customer.getOrder().forEach(function (item) {
- var inventoryItem = inventory.find(function (invItem) {
- return invItem.getType() === item;
- });
- if (inventoryItem) {
- inventoryItem.visible = true;
- }
- });
- });
- // Reset timer for the new level
- levelTimer = currentLevel.levelNumber >= 8 ? 27 - currentLevel.levelNumber : 20;
- timeTxt.setText('Time: ' + levelTimer);
- LK.clearInterval(timerInterval);
- timerInterval = LK.setInterval(function () {
- if (levelTimer > 0) {
- levelTimer--;
- timeTxt.setText('Time: ' + levelTimer);
- } else {
- // Handle level timeout (e.g., end game or move to next level)
- LK.clearInterval(timerInterval);
- var timesupAsset = LK.getAsset('timesup', {
- anchorX: 0.5,
- anchorY: 0.5,
- x: 2048 / 2,
- y: 2732 / 2
- });
- game.addChild(timesupAsset);
- LK.setTimeout(function () {
- timesupAsset.destroy();
- LK.showGameOver();
- }, 1000);
- }
- }, 1000);
- }, 500);
- }, 500);
+ currentLevel = levels[nextLevelIndex];
+ // Clear current customers and items
+ for (var i = 0; i < customers.length; i++) {
+ customers[i].destroy();
+ }
+ customers = [];
+ for (var i = 0; i < items.length; i++) {
+ items[i].destroy();
+ }
+ items = [];
+ // Create new customers and items for the next level
+ for (var i = 0; i < currentLevel.customerCount; i++) {
+ createCustomer();
+ }
+ var totalItems = currentLevel.items.length;
+ var startingPoint = (2048 - totalItems * 250) / 2;
+ for (var i = 0; i < totalItems; i++) {
+ createItem(currentLevel.items[i], startingPoint + i * 250, 2732 - 200);
+ }
+ }, 1000);
}
} else if (LK.ticks % 300 == 0) {
createCustomer();
}
};
-// Initialize items only once
-if (items.length === 0) {
- var totalItems = levels[levels.length - 1].items.length; // Maximum number of items across all levels
- var spacing = (2048 - totalItems * 200) / (totalItems + 1);
- for (var i = 0; i < totalItems; i++) {
- createItem(levels[levels.length - 1].items[i], spacing + i * (200 + spacing) + 100, 2732 - 200);
- }
+// Create initial items
+for (var i = 0; i < currentLevel.items.length; i++) {
+ createItem(currentLevel.items[i], 2048 / 2 - 500 + i * 250, 2732 - 200);
}
var backgroundBottom = LK.getAsset('backgroundBottom', {
anchorX: 0.5,
anchorY: 1,
8bit. cartoon. icecream. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
cartoon and 8 bit message. reads: Time's Up!. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
8bit. cartoon. palm tree.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.