//Hens & Roosters
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;
import flash.media.Sound;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
public class FirstGame02 extends MovieClip
{
//Declare Global Variables
var hennypenny:MovieClip;
var lusciouslulu:MovieClip;
var chickiechacha:MovieClip;
var seymour:MovieClip;
var henrythe8th:MovieClip;
var madmax:MovieClip;
var hatching:MovieClip;
var fox:MovieClip;
var fatassworm:MovieClip;
var effinfly:MovieClip;
var beetlebug:MovieClip;
var flowers:MovieClip;
var foreground:MovieClip;
var sky:MovieClip;
var vx:Number;
var vy:Number;
var tempHen = MovieClip;
var myHenArray = new Array;
var tempRooster = MovieClip;
var myRoosterArray = new Array;
var tempBug = MovieClip;
var myBugArray:Array = new Array;
var myBugArrayWorm:Array = new Array;
var myBugArrayFly:Array = new Array;
var myBugArrayBeetle:Array = new Array;
var hensclucking:Sound;
var roostercall:Sound;
var henlaying:Sound;
public function FirstGame02()//CONSTRUCTOR FUNCTION
{
//Instantiate Variables
hennypenny = new HennyPenny;
lusciouslulu = new LusciousLulu;
chickiechacha = new ChickieChaCha;
seymour = new Seymour;
henrythe8th = new HenryThe8th;
madmax = new MadMax;
hatching = new Hatching;
fox = new Fox;
fatassworm = new FatAssWorm;
effinfly = new EffinFly;
beetlebug = new BeetleBug;
flowers = new Flowers;
foreground = new Foreground;
sky = new Sky;
vx = 20;
vy = 20;
hensclucking = new HensClucking;
roostercall = new RoosterCall;
henlaying = new HenLaying;
//Hide the mouse
Mouse.hide();
//Set up the stage
stage.scaleMode = StageScaleMode.EXACT_FIT;
addChild(sky);
addChild(foreground);
addChild(flowers);
addChild(fox);
sky.x = stage.stageWidth * .45;
sky.y = stage.stageHeight * .385;
foreground.x = stage.stageWidth * .4;
foreground.y = stage.stageHeight * .45;
flowers.x = stage.stageWidth * .7;
flowers.y = stage.stageHeight * .4;
hatching.x = stage.stageWidth * .5;
hatching.y = stage.stageHeight * .5;
fox.x = stage.stageWidth*.5;
fox.y = stage.stageHeight*.1;
fox.scaleX = .20;
fox.scaleY = .20;
makeBugs();
makeHens();
makeRoosters();
// Event Listeners
addEventListener(Event.ENTER_FRAME, onEnterFrame);
}//end public function
// Event Handlers
function onEnterFrame(event:Event):void
{
// PLAYER Hen and Rooster CONTROLLED BY MOUSE
hennypenny.x = mouseX;
lusciouslulu.x = mouseX;
chickiechacha.x = mouseX;
tempRooster.y = mouseY;
//Stage Boundary Collisions
if(fox.x > stage.stageWidth || fox.x < 0)
{
vx = -vx;
hensclucking.play();
}
if(fox.y > stage.stageHeight || fox.y < 0)
{
vy = -vy;
hensclucking.play();
}
//check for rooster/fox collisions
if(tempRooster.hitTestObject(fox))
{
vx = -vx;
vy = -vy;
roostercall.play();
}
//move stuff
fox.x += vx;
fox.y += vy;
moveBugs();
eatBugs();
foxEatsHens();
}// end onEnterFrame function
function makeBugs():void
{
for (var i:int = 30; i>=20; i--)
{
tempBug = new FatAssWorm;
tempBug.y = (Math.random()*stage.stageHeight);
tempBug.x = (Math.random()*stage.stageWidth);
tempBug.scaleX = .1;
tempBug.scaleY = .1;
tempBug.vx = (Math.random()* 15);
tempBug.vy = (Math.random()* 15);
addChild(tempBug);// display the contents of tempBug on the stage
myBugArray.push(tempBug);//puts the contents of each tempBug into myBug Array
}//end for
for (var j:int = 20; j>=10; j--)
{
tempBug = new EffinFly;
tempBug.y = (Math.random()*stage.stageHeight);
tempBug.x = (Math.random()*stage.stageWidth);
tempBug.scaleX = .1;
tempBug.scaleY = .1;
tempBug.vx = (Math.random()* 15);
tempBug.vy = (Math.random()* 30);
addChild(tempBug);// display the contents of tempBug on the stage
myBugArray.push(tempBug);//puts the contents of each tempBug into myBugArray
}//end for
for (var k:int = 10; k>=0; k--)
{
tempBug = new BeetleBug;
tempBug.y = Math.floor(Math.random()*stage.stageHeight);
tempBug.x = Math.floor(Math.random()*stage.stageWidth);
tempBug.scaleX = .1;
tempBug.scaleY = .1;
tempBug.vx = (Math.random()* 10);
tempBug.vy = (Math.random()* 20);
addChild(tempBug);// display the contents of tempBug on the stage
myBugArray.push(tempBug);//puts each tempBug into myBugArray
}//end for
}//end makeBugs
function makeHens(): void
{
myHenArray.push(hennypenny);
myHenArray.push(lusciouslulu);
myHenArray.push(chickiechacha);
var Hen:MovieClip;
Hen = myHenArray[myHenArray.length - 1];
Hen.y = stage.stageHeight*.85;
Hen.scaleX = .3;
Hen.scaleY = .3;
tempHen = Hen;
addChild(tempHen);
}//end makeHens
function foxEatsHens (): void
{
for (var i:int = myHenArray.length-1; i>0; i--)
{
if((fox).hitTestObject(myHenArray[i]))
{
vx = -vx;
vy = -vy;
removeChild(myHenArray[i]);
myHenArray.splice(i,1);
myHenArray[i - 1].x = stage.stageWidth - fox.x;
myHenArray[i - 1].y = stage.stageHeight*.85;
myHenArray[i - 1].scaleX = .3;
myHenArray[i - 1].scaleY = .3;
//trace(myHenArray.length);
addChild(myHenArray[i - 1]);
//trace(myHenArray[0]);
hensclucking.play();
}//end hen/fox collision test
}//end for
if (myHenArray.length == 1)
{
if((fox).hitTestObject(myHenArray[0]))
{
removeChild(myHenArray[myHenArray.length - 1]);
myHenArray.splice(myHenArray.length-1,1);
removeChild(tempRooster);
trace("GAME OVER");
}
}
}//end foxEatsHens
function makeRoosters(): void
{
myRoosterArray.push(seymour);//puts hen into myHenArray
myRoosterArray.push(henrythe8th);
myRoosterArray.push(madmax);
var Rooster:MovieClip;
Rooster = myRoosterArray[myRoosterArray.length - 1];
Rooster.x = stage.stageWidth*.15;
Rooster.scaleX = .3;
Rooster.scaleY = .3;
addChild(Rooster);
tempRooster = Rooster;
}//end makeRoosters
function moveBugs(): void
{
var bug:MovieClip;
for (var i:int = myBugArray.length-1; i>=0; i--)
{
bug = myBugArray[i];
bug.x += tempBug.vx;
bug.y += tempBug.vy;
if (bug.x > (stage.stageWidth - (bug.width/2)))
{
bug.x = stage.stageWidth - (bug.width/2+1);
tempBug.vx = - tempBug.vx;
}
if (bug.x < (0 + (bug.width/2+1)))
{
bug.x = 0 + (bug.width/2+1);
tempBug.vx = - tempBug.vx;
}
if (bug.y > (stage.stageHeight - (bug.height/2)))
{
bug.y = stage.stageHeight - (bug.height/2);
tempBug.vy = -tempBug.vy;
}
if (bug.y < (0 + (bug.height/2+1)))
{
bug.y = 0 + (bug.height/2+1);
tempBug.vy = - tempBug.vy;
}
}//end for
}//end moveBugs
function eatBugs(): void
{
//var sound:Sound = new SoundSubmarine();
var bug:MovieClip;// = event.target as MovieClip;
for (var i:int = myBugArray.length-1; i>=0; i--)
{
bug = myBugArray[i];
if (myHenArray[myHenArray.length - 1].hitTestObject(bug) || tempRooster.hitTestObject(bug))
{
trace("YUMMY!!!");
//hensclucking.play();
removeChild(myBugArray[i]);
myBugArray.splice(i,1);
}
if (myBugArray.length == 0) //score and add egg hatching
{
//play sound
addChild(hatching);
trace("YOU HATCHED AN EGG!!! SCORE:");
trace(100*(i+1));
henlaying.play();
henlaying.play();
henlaying.play();
//removeChild(hatching);
//makeBugs();
} //end score/egg if
}//end for
}// end eatBugs
}// end class
} // end package
No comments:
Post a Comment