/****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Customer class
var Customer = Container.expand(function () {
var self = Container.call(this);
var customerGraphics = self.attachAsset('customer', {
anchorX: 0.5,
anchorY: 0.5
});
self.order = null;
self.setOrder = function (order) {
self.order = order;
};
self.getOrder = function () {
return self.order;
};
});
// Item class
var Item = Container.expand(function (type) {
var self = Container.call(this);
var itemGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.getType = function () {
return self.type;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var customers = [];
var items = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to create a new customer
function createCustomer() {
var customer = new Customer();
customer.x = Math.random() * 2048;
customer.y = Math.random() * 2732;
var order = ['towel', 'umbrella', 'refreshment', 'snack'][Math.floor(Math.random() * 4)];
customer.setOrder(order);
customers.push(customer);
game.addChild(customer);
}
// Function to create a new item
function createItem(type, x, y) {
var item = new Item(type);
item.x = x;
item.y = y;
items.push(item);
game.addChild(item);
}
// Function to handle item drop
function handleItemDrop(x, y, obj) {
var item = obj.event.target;
var itemType = item.getType();
for (var i = 0; i < customers.length; i++) {
var customer = customers[i];
if (customer.intersects(item)) {
if (customer.getOrder() === itemType) {
score += 10;
LK.setScore(score);
scoreTxt.setText(score);
customer.destroy();
customers.splice(i, 1);
item.destroy();
items.splice(items.indexOf(item), 1);
break;
}
}
}
}
// Create initial customers
for (var i = 0; i < 5; i++) {
createCustomer();
}
// Event listeners for item drag and drop
var dragItem = null;
game.down = function (x, y, obj) {
for (var i = 0; i < items.length; i++) {
if (items[i].intersects(obj.event.target)) {
dragItem = items[i];
break;
}
}
};
game.move = function (x, y, obj) {
if (dragItem) {
dragItem.x = x;
dragItem.y = y;
}
};
game.up = function (x, y, obj) {
if (dragItem) {
handleItemDrop(x, y, obj);
dragItem = null;
}
};
// Update function
game.update = function () {
if (LK.ticks % 300 == 0) {
createCustomer();
}
};
// Create initial items
createItem('towel', 100, 100);
createItem('umbrella', 200, 100);
createItem('refreshment', 300, 100);
createItem('snack', 400, 100); /****
* Classes
****/
//<Assets used in the game will automatically appear here>
// Customer class
var Customer = Container.expand(function () {
var self = Container.call(this);
var customerGraphics = self.attachAsset('customer', {
anchorX: 0.5,
anchorY: 0.5
});
self.order = null;
self.setOrder = function (order) {
self.order = order;
};
self.getOrder = function () {
return self.order;
};
});
// Item class
var Item = Container.expand(function (type) {
var self = Container.call(this);
var itemGraphics = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5
});
self.type = type;
self.getType = function () {
return self.type;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Init game with sky blue background
});
/****
* Game Code
****/
// Initialize arrays and variables
var customers = [];
var items = [];
var score = 0;
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to create a new customer
function createCustomer() {
var customer = new Customer();
customer.x = Math.random() * 2048;
customer.y = Math.random() * 2732;
var order = ['towel', 'umbrella', 'refreshment', 'snack'][Math.floor(Math.random() * 4)];
customer.setOrder(order);
customers.push(customer);
game.addChild(customer);
}
// Function to create a new item
function createItem(type, x, y) {
var item = new Item(type);
item.x = x;
item.y = y;
items.push(item);
game.addChild(item);
}
// Function to handle item drop
function handleItemDrop(x, y, obj) {
var item = obj.event.target;
var itemType = item.getType();
for (var i = 0; i < customers.length; i++) {
var customer = customers[i];
if (customer.intersects(item)) {
if (customer.getOrder() === itemType) {
score += 10;
LK.setScore(score);
scoreTxt.setText(score);
customer.destroy();
customers.splice(i, 1);
item.destroy();
items.splice(items.indexOf(item), 1);
break;
}
}
}
}
// Create initial customers
for (var i = 0; i < 5; i++) {
createCustomer();
}
// Event listeners for item drag and drop
var dragItem = null;
game.down = function (x, y, obj) {
for (var i = 0; i < items.length; i++) {
if (items[i].intersects(obj.event.target)) {
dragItem = items[i];
break;
}
}
};
game.move = function (x, y, obj) {
if (dragItem) {
dragItem.x = x;
dragItem.y = y;
}
};
game.up = function (x, y, obj) {
if (dragItem) {
handleItemDrop(x, y, obj);
dragItem = null;
}
};
// Update function
game.update = function () {
if (LK.ticks % 300 == 0) {
createCustomer();
}
};
// Create initial items
createItem('towel', 100, 100);
createItem('umbrella', 200, 100);
createItem('refreshment', 300, 100);
createItem('snack', 400, 100);
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.