Thank you for visiting Blazing Games

Coding Cooking

This episode puzzles are essentially state machines. As I didn't want to force the player to continually have to restart the game if they make a mistake, the states are designed just to provide momentary to the player if they are doing something out of sequence. The most complicated object in the game is the cooking pot, but its logic is handled in a single cooking function.

the first thing we do is see if the player is adding something to the pot or trying to pick up a pot. The only time we allow the player to pick up a pot is when it is in a finished (melted chocolate or caramel) state. If the player is adding chocolate chips to a pot, the pot must be empty and the result is melted chocolate. Sugar, like chocolate, must also be added to an empty pot. Butter can be added to a sugar pot or a sugar and milk pot. If butter is added to a sugar pot it becomes a sugar and butter pot otherwise it becomes caramel. Milk can be added to a sugar pot or a sugar and butter pot. If milk is added to a sugar pot it becomes a sugar and milk pot otherwise it becomes caramel.

Here is the function in all it's glory.

function cooking(pot:CookingPot, potState:int):int
{
var tempPot:CookingPot;
var newState:int = potState;
var ingredient:IInventoryItem = inv_movie.getSelectedItem();
inv_movie.setInventoryState(0);
if (ingredient == null) { // attempt to get the pot
if (potState == POT_CHOCOLATE) { // get chocolate
thoughtMessage("Melted chocolate. You can\'t make a chocolate bar without that!");
tempPot = new CookingPot();
tempPot.gotoAndStop(POT_CHOCOLATE);
inv_movie.addInvItem(new BasicInventoryItem(null, tempPot, "Chocolate"));
pot.visible = false;
} else if (potState == POT_CARAMEL) { // get caramel
thoughtMessage("A thick caramel sauce that will form the filling of the CarmaChoc-like bar.");
tempPot = new CookingPot();
tempPot.gotoAndStop(POT_CARAMEL);
inv_movie.addInvItem(new BasicInventoryItem(null, tempPot, "Caramel"));
pot.visible = false;
} else
thoughtMessage("I haven\'t finished cooking.");
} else if (ingredient.getItemName() == "Chips") { // make chocoloate
if (potState != POT_EMPTY)
thoughtMessage("Oops. I almost added this to the wrong pot!");
else {
thoughtMessage("Considering where I am, these chocolate chips are quite good. Now to melt them without burning them.");
inv_movie.removeInvItem(ingredient);
newState = POT_CHOCOLATE;
}
} else if (ingredient.getItemName() == "Sugar") { // make caramel step 1
if (potState != POT_EMPTY)
thoughtMessage("Oops. I almost added this to the wrong pot!");
else {
thoughtMessage("Caramelized sugar is the napalm of the cooking world. Of course, adding water to the sugar will slow down the caramelizing process taking longer but being more forgiving.");
inv_movie.removeInvItem(ingredient);
newState = POT_SUGAR;
}
} else if (ingredient.getItemName() == "Butter") { // make caramel step 2a
if ( (potState != POT_SUGAR) && (potState != POT_SUGARANDMILK) )
thoughtMessage("Oops. I seemed to have forot the steps to caramelizing!");
else {
thoughtMessage("The sugar is caramelizing so I have to add the last two ingredients quickly.");
inv_movie.removeInvItem(ingredient);
if (potState == POT_SUGAR)
newState = POT_SUGARANDBUTTER;
else
newState = POT_CARAMEL;
}
} else if (ingredient.getItemName() == "Milk") { // make caramel step 2b
if ( (potState != POT_SUGAR) && (potState != POT_SUGARANDBUTTER) )
thoughtMessage("Oops. I seemed to have forot the steps to caramelizing!");
else {
thoughtMessage("The sugar is caramelizing so I have to add the last two ingredients quickly.");
inv_movie.removeInvItem(ingredient);
if (potState == POT_SUGAR)
newState = POT_SUGARANDMILK;
else
newState = POT_CARAMEL;
}
} else
thoughtMessage("I\'m not sure that works...");
return newState;
}

Previous page
Chapter 46 Page 4

About - Privacy Policy - Contact - Links - FAQ
Copyright © 2012 Blazing Games Inc. All Rights Reserved