Wednesday, March 16, 2011

Added Code to Main Game - 17/03/11

I added the following code to my Main Game. This code randomly generates the Food's to be launched towards the Trolley, as well as increasing in size as it gets closer to the trolley.


function addFood():void
{
var addFruitRandom:Number = Math.round(Math.random()*5)
var randomTimes:Number = Math.round(Math.random()*5)
if(addFruitRandom == 0 && isCarrotPresent == false && randomTimes == 3)
{
carrot_mc.scaleX = 0.2;
carrot_mc.scaleY = 0.2;
addChild(carrot_mc);
carrot_mc.x = 45.25
carrot_mc.y = 80.05
isCarrotPresent = true;
if(carrot_mc.y > 450)
{
removeChild(carrot_mc);
isCarrotPresent = false;
}
}
if(addFruitRandom == 1 && isApplePresent == false && randomTimes == 3)
{
apple_mc.scaleX = 0.2;
apple_mc.scaleY = 0.2;
addChild(apple_mc);
apple_mc.x = 239.30 
apple_mc.y = 77.45
isApplePresent = true;
if(apple_mc.y > 450)
{
removeChild(apple_mc);
isApplePresent = false;
}
}
if(addFruitRandom == 2 && isBroccoliPresent == false && randomTimes == 3)
{
broccoli_mc.scaleX = 0.2;
broccoli_mc.scaleY = 0.2;
addChild(broccoli_mc);
broccoli_mc.x = 458.10
broccoli_mc.y = 80.05
isBroccoliPresent = true;
}
if(addFruitRandom == 3 && isChipsPresent == false && randomTimes == 3)
{
chips_mc.scaleX = 0.2;
chips_mc.scaleY = 0.2;
addChild(chips_mc);
chips_mc.x = 45.25
chips_mc.y = 80.05
isChipsPresent = true;
if(chips_mc.y > 450)
{
removeChild(chips_mc);
isChipsPresent = false;
}
}
if(addFruitRandom == 3 && isDonutPresent == false && randomTimes == 3)
{
donut_mc.scaleX = 0.2;
donut_mc.scaleY = 0.2;
addChild(donut_mc);
donut_mc.x = 458.10
donut_mc.y = 80.05
isDonutPresent = true;
if(donut_mc.y > 450)
{
removeChild(donut_mc);
isDonutPresent = false;
}
}
}


function moveFood():void
{
if(isApplePresent == true)
{
apple_mc.y += 5;
apple_mc.scaleX += FOOD_SCALE;
apple_mc.scaleY += FOOD_SCALE;
}

if(isCarrotPresent == true)
{
carrot_mc.y += 5;
carrot_mc.scaleX += FOOD_SCALE;
carrot_mc.scaleY += FOOD_SCALE;
}

if(isBroccoliPresent == true)
{
broccoli_mc.y += 5;
broccoli_mc.scaleX += FOOD_SCALE;
broccoli_mc.scaleY += FOOD_SCALE;
}

if(isChipsPresent == true)
{
chips_mc.y += 5;
chips_mc.scaleX += FOOD_SCALE;
chips_mc.scaleY += FOOD_SCALE;
}

if(isDonutPresent == true)
{
donut_mc.y += 5;
donut_mc.scaleX += FOOD_SCALE;
donut_mc.scaleY += FOOD_SCALE;
}

}

No comments:

Post a Comment