Top Chef Bob - Part 06 - Add another item to the menu.

Part 06 of the Top Chef Bob food simulator game is to:
1) Add a TACO to the menu.
2) Code in the recipe steps to make a TACO.
NOTE: make sure you have already added all the ingridents to make a taco. (see part 05)





Create TACO object
In the "playlevel1.js" file, find the createMenu function. Add the code below to define the TACO order. You should also make sure you have previously added all the ingridents you will need for this order. (see part 05)



    // define taco order
    this.Taco = {
    name: 'taco',
    assemblyPictures: [game.bmpTacoShell, game.bmpTacoShellWithMeat, game.bmpTacoShellWithMeatLettuce]
    };

        



Add TACO object to the menu
In the "playlevel1.js" file, find the createMenu function. Modify the array which stores our menu items to include our TACO by replacing the line with the code below.



    // create list (array) of menu items
    this.MenuItems = [this.Pizza, this.Taco];

        



Randomly pick Taco or Pizza order
In the "playlevel1.js" file, find the orderManagement function. Notice the changes in the code below. (one new line and one line changed)



    // has customer ordered anything?
    if (this.Customer.MenuItemOrdered === null) {

        // customer wants to order something

        // generate a random number between 0 and number of menu items
        CustomerWantsMenuItemNumber = game.rnd.integerInRange(0, 1);

        // get menu item
        this.Customer.MenuItemOrdered = this.MenuItems[CustomerWantsMenuItemNumber];
        this.Customer.OrderStep = -1;
        this.Customer.isOrderComplete =  false,
        this.Customer.Mood = 'happy';




Detect catching TACO ingridents
In the "playlevel1.js" file, find the UPDATE function. Add the code below which will detect when a Bob overlaps any of our TACO ingridents.



    game.physics.arcade.overlap(this.bob, this.foodTacoShell.group, this.caughtTacoShell, null, this);
    game.physics.arcade.overlap(this.bob, this.foodMeat.group, this.caughtMeat, null, this);
    game.physics.arcade.overlap(this.bob, this.foodLettuce.group, this.caughtLettuce, null, this);


        



Add "caught" functions for each TACO ingridents
In the "playlevel1.js" file, add the following functions right before the displayIngrident function.



    caughtTacoShell: function(bob,tacoshell) {

    if (this.Customer.MenuItemOrdered.name == 'taco') {

    // set the current step to 0
    this.Customer.OrderStep = 0;
    this.Customer.Mood = 'happy';

    } else {

    // why did bob catch this?  customer not happy
    this.Customer.Mood = 'bored';
    this.txtCustomer.text = 'OMG, its just a ' + this.Customer.MenuItemOrdered.name;

    }

    },

    caughtMeat: function(bob,meat) {

    // is this order taco?
    if (this.Customer.MenuItemOrdered.name == 'taco') {

    // do nothing if bob is currently on meat step
    if (this.Customer.OrderStep == 1) return;

    // does bob have a tacoshell?
    if (this.Customer.OrderStep > -1) {

    this.Customer.OrderStep = 1;
    this.Customer.Mood = 'happy';
    this.txtCustomer.text = 'That Taco is looking good!';

    } else {

    this.Customer.Mood = 'bored';
    this.txtCustomer.text = 'Where is my Taco!';

    }
    } else {

    // why did bob catch this?  customer not happy
    this.Customer.Mood = 'bored';
    this.txtCustomer.text = 'OMG, its just a ' + this.Customer.MenuItemOrdered.name;

    }

    },

    caughtLettuce: function(bob,lettuce) {

    if (this.Customer.MenuItemOrdered.name == 'taco') {

    // do nothin if bob is currently on lettuce step
    if (this.Customer.OrderStep == 2) return;

    // bob has to have meat
    if (this.Customer.OrderStep == 1) {

    this.Customer.OrderStep = 2;
    this.Customer.Mood = 'happy';
    this.Customer.isOrderComplete = true;

    this.txtCustomer.text = 'Wow, This Taco is the Bomb!';

    this.TimeNextCustomerArrives = this.game.time.now + 3000;

    } else {

    this.Customer.Mood = 'mad';
    this.txtCustomer.text = 'Come on Bob!?!';

    }

    } else {

    // why did bob catch this?  customer not happy
    this.Customer.Mood = 'bored';
    this.txtCustomer.text = 'OMG, its just a ' + this.Customer.MenuItemOrdered.name;

    }

    },






Run Game and Check for Errors
Press F12 to check console for any problems. Try moving Bob to assemble a Taco or Pizza!



code on plnkr