rendered paste bodyvar numIngredients = 0;
cart_array = new Array(10);
var numInCart = 0;
_root.nextPlease._enabled = false;
_root.nextPlease._visible = false;
//Incorrect answer sound
wrongSound = new Sound();
wrongSound.attachSound("wrong");
//Congrats sound
yeehaa = new Sound();
yeehaa.attachSound("yeehaa");
//Disable navigation, (Pizza would just get in the way!)
_root[miniPizza].enabled = false;
_root[miniPizza]._visible = false;
//Creates trolley and attaches mouse cursor to it so it will now move in
//the horizontal direction that the user movies their mouse to.
_root.attachMovie("trolley",trolley,10);
_root[trolley]._x = swidth - 80;
_root[trolley]._y = sheight - (1/4* _root[trolley]._height)
_root[trolley].startDrag(true,0, _root[trolley]._y,swidth, _root[trolley]._y);
//Creates an array of ingredients, that will be dropping form the sky.
ingredient_array = ["Chips", "Chocolate", "Beer", "Icecream", "Jelly"
, "Lynx" , "Mayo" , "Moro Bar" , "Peanut Butter" ,
"Toothpaste" , "Weetbix" , "Anchovies", "Capsicum",
"Mozzarella", "Mushrooms" , "Olives" , "Onion" , "Ham",
"Pineapple", "Salami", "Tomato Paste"];
var createIngredient = setInterval(createIngredient, 1000);
function CalcIngredientX(ingredient)
{
segment = random(10) + 1; //Generates a number beween 1 and 5 inclusive.
switch (segment)
{
case 1:
//trace("1st segment");
return (swidth/10)/2;
break;
case 2:
//trace("2nd segment");
return (swidth/10) + 1/2*(swidth/10);
break;
case 3:
//trace("3rd segment");
return 2*(swidth/10) + 1/2*(swidth/10);
break;
case 4:
//trace("4th segment");
return 3* (swidth/10) + 1/2*(swidth/10);
break;
case 5:
//trace("5th segment");
return 4* (swidth/10) + 1/2*(swidth/10);
break;
case 6:
//trace("6th segment");
return 5* (swidth/10) + 1/2*(swidth/10);
break;
case 7:
//trace("7th segment");
return 6* (swidth/10) + 1/2*(swidth/10);
break;
case 8:
//trace("8th segment");
return 7* (swidth/10) + 1/2*(swidth/10);
break;
case 9:
//trace("9th segment");
return 8* (swidth/10) + 1/2*(swidth/10);
break;
case 10:
//trace("10th segment");
return 9* (swidth/10) + 1/2*(swidth/10);
break;
}
}
function createIngredient()
{
_root.ingredientInfo.text = "";
var ingredientIndex = random(ingredient_array.length);
numIngredients ++;
var ingredient = "ingredient" + numIngredients;
_root.attachMovie(ingredient_array[ingredientIndex], ingredient, random(15999));
_root[ingredient]._x = CalcIngredientX(ingredient);
_root[ingredient].speed = 3;
if (ingredientIndex >= 0 && ingredientIndex <= 10)
{
_root[ingredient].Type = 1;
}
else
{
_root[ingredient].Type = 2;
}
_root[ingredient].Name = ingredient_array[ingredientIndex];
setInterval(fall, 20, ingredient);
}
function CheckIfExists(ingredientName)
{
var counter = 0;
for (i = 0; i < cart_array.length; i++)
{
if (ingredientName != cart_array[i])
{
counter ++;
}
}
if (counter == cart_array.length)
{
trace("Adding item to cart")
return false;
}
else
{
return true;
}
}
function CheckIngredient(ingredient)
{
var blnExists = false;;
if(_root[ingredient].Type == 1)
{
wrongSound.start();
_root.ingredientInfo.text = _root[ingredient].Name + newline + "Does Not Belong On a Pizza!";
}
else if (_root[ingredient].Type == 2 && numInCart < 10)
{
blnExists = CheckIfExists(_root[ingredient].Name);
if (blnExists == false)
{
cart_array[numInCart] = _root[ingredient].Name;
_root[trolley].Fullometer.Arrow._rotation += 18;
numInCart ++;
if (numInCart == 2)
{
trace("Number of Ingredients " + numIngredients);
trace("Congratulations! You Win!");
clearInterval(createIngredient);
for (i = 0; i <= numIngredients; i++)
{
var ingredient = "ingredient" + i;
_root[ingredient].clearInterval();
_root[ingredient].removeMovieClip();
}
_root.ingredientInfo.text = "Congratulations!!!";
_root[trolley].stopDrag();
_root[trolley].removeMovieClip();
_root.nextPlease._enabled = true;
_root.nextPlease._visible = true;
yeehaa.start();
}
}
else if (blnExists == true)
{
wrongSound.start();
_root.ingredientInfo.text = "You already have that in your cart!";
}
}
}
function fall(ingredient)
{
if(_root[ingredient]._y < sheight)
{
_root[ingredient]._y += 1 + _root[ingredient].speed;
}
else
{
_root[ingredient].clearInterval();
_root[ingredient].removeMovieClip();
numIngredients --;
}
if (_root[ingredient].hitTest(_root[trolley]) && _root[ingredient]._y < (_root[trolley]._y - 3/4 * _root[trolley]._height))
{
CheckIngredient(ingredient);
_root[ingredient].clearInterval();
_root[ingredient].removeMovieClip();
numIngredients --;
trace("Got an Ingredient!");
}
updateAfterEvent();
}