HTML and CSS Reference
In-Depth Information
// queue index, 0 for left and 1 for right queue.
this.queueIndex = 0;
if (leftOrRight === 'right') this.queueIndex = 1;
this.on('tick', this.tick);
}
// customer extends createJS Container.
Customer.prototype =
Object.create(cjs.Container.prototype);
3. The randomWants funcion is an internal funcion that generates a random
sushi request:
// customer's helper functions
function randomWants() {
options = ['sushiSalmonRoe', 'sushiOctopus', 'sushiSalmon',
'sushiEgg'];
var index = Math.floor(Math.random() * options.length);
return options[index];
}
4. In each ick, we check the waiing ime of the customer. When the customer waits
for too long, it changes its own state to angry:
Customer.prototype.tick = function() {
this.hasWaitForTicks += 1;
if (this.hasWaitForTicks === 300) { // turns angry
this.graphics.gotoAndStop('angry');
}
if (this.hasWaitForTicks> 500) { // waited too long
this.remove();
}
if (this.hasEaten) {
this.remove();
}
};
5. When we remove a customer, we remove it from two places. They are the queue
array and the EaselJS display list:
Customer.prototype.remove = function() {
// remove customer
this.parent.removeChild(this);
game.removeFromQueue(this.queueIndex);
};
 
Search WWH ::




Custom Search