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;
}

}

Wednesday, March 9, 2011

Code Update for Main Game Frame

For the Game Frame, I needed to add restrictions so that the trolley would not go off screen, but simply top once it has reached a certain limit.

Heres the code --->

function moveTrolley():void
{
if(isRightKeyPressed == true && trolley_mc.x < 370)
{
trolley_mc.x += TROLLEY_SPEED;
}
if(isLeftKeyPressed == true && trolley_mc.x > -80)
{
trolley_mc.x -= TROLLEY_SPEED;
}
}

I added the "&& trolley_mc.x < 370" to make the Trolley stop at the right side of the screen,
and the "&& trolley_mc.x > -80" to make it stop on the left.

Sunday, March 6, 2011

Code for Home Screen and Instructions

Home Screen code -


import flash.events.MouseEvent;

stop ();

start_btn.addEventListener(MouseEvent.CLICK, startBtnClicked);
instructions_btn.addEventListener(MouseEvent.CLICK, instructionsBtnClicked);

function startBtnClicked(event:MouseEvent):void{

gotoAndStop(4);}

function instructionsBtnClicked(event:MouseEvent):void
{
gotoAndStop(3);
}

Instructions Screen Code -

import flash.events.MouseEvent;

play_btn.addEventListener(MouseEvent.CLICK, playBtnClicked);
home_btn.addEventListener(MouseEvent.CLICK, homeBtnClicked);

function playBtnClicked(event:MouseEvent):void
{
gotoAndStop(4);
}

function homeBtnClicked(event:MouseEvent):void
{
gotoAndStop(2)
}