package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.ui.Mouse;//***NEW
import flash.media.Sound;//***NEW
public class FirstGame01 extends MovieClip
{
//Declare Global Variables
var hennypenny:MovieClip;
var lusciouslulu:MovieClip;
var chickiechacha:MovieClip;
var seymour:MovieClip;
var henrythe8th:MovieClip;
var madmax: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 ballBounceSound:Sound;//***NEW
var playerSound:Sound;//***NEW
public function FirstGame01()//CONSTRUCTOR FUNCTION
{
//Instantiate Variables
hennypenny = new HennyPenny;
lusciouslulu = new LusciousLulu;
chickiechacha = new ChickieChaCha;
seymour = new Seymour;
henrythe8th = new HenryThe8th;
madmax = new MadMax;
fox = new Fox;
fatassworm = new FatAssWorm;
effinfly = new EffinFly;
beetlebug = new BeetleBug;
flowers = new Flowers;
foreground = new Foreground;
sky = new Sky;
fatassworm.vx = 0; //yes, I did that horrible thing!
fatassworm.vy = 0; //twice!
effinfly.vx = 0;
effinfly.vy = 0;
beetlebug.vx = 0;
beetlebug.vy = 0;
vx = 5;
vy = 5;
ballBounceSound = new SoundBasso;//***NEW
playerSound = new SoundGlass;//***NEW
//Hide the mouse ***NEW
Mouse.hide();
//Set up the stage
addChild(sky);
addChild(foreground);
addChild(flowers);
addChild(hennypenny);
//addChild(lusciouslulu);
//addChild(chickiechacha);
addChild(seymour);
//addChild(henrythe8th);
//addChild(madmax);
addChild(fox);
addChild(fatassworm);
addChild(effinfly);
addChild(beetlebug);
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;
seymour.x = stage.stageWidth*.15;
seymour.y = stage.stageHeight*.5;
seymour.scaleX = .5;
seymour.scaleY = .5;
hennypenny.x = stage.stageWidth*.5;
hennypenny.y = stage.stageHeight*.85;
hennypenny.scaleX = .5;
hennypenny.scaleY = .5;
fox.x = stage.stageWidth*.5;
fox.y = stage.stageHeight*.1;
fox.scaleX = .5;
fox.scaleY = .5;
fatassworm.x = stage.stageWidth*.3;
fatassworm.y = stage.stageHeight*.7;
fatassworm.scaleX = .1;
fatassworm.scaleY = .1;
effinfly.x = .2;
effinfly.y = .2;
effinfly.scaleX = .1;
effinfly.scaleY = .1;
beetlebug.x = .9;
beetlebug.y = .9;
beetlebug.scaleX = .1;
beetlebug.scaleY = .1;
// Event Listeners
addEventListener(Event.ENTER_FRAME, onEnterFrame);
fatassworm.addEventListener(Event.ENTER_FRAME, onBugMove);
effinfly.addEventListener(Event.ENTER_FRAME, onBugMove);
beetlebug.addEventListener(Event.ENTER_FRAME, onBugMove);
}
// Event Handlers
function onEnterFrame(event:Event):void
{
// PLAYER X CONTROLLED BY MOUSE ***NEW
hennypenny.x = mouseX;
//hennypenny.y = mouseY;
//seymour.x = mouseY;
seymour.y = mouseX;
//Stage Boundary Collisions
if(fox.x > stage.stageWidth || fox.x < 0)
{
vx = -vx;
ballBounceSound.play();//***NEW
}
if(fox.y > stage.stageHeight || fox.y < 0)
{
vy = -vy;
ballBounceSound.play();//***NEW
}
//check for paddle ball collisions ***NEW
if(hennypenny.hitTestObject(fox)||seymour.hitTestObject(fox))
{
vx = -vx;
vy = -vy;
playerSound.play();//***NEW
}
//move stuff
fox.x += vx;
fox.y += vy;
}// end onEnterFrame function
private function onBugMove(event:Event):void
{
//Create a variable to store a reference to bug object
var bug:MovieClip = event.target as MovieClip;
//Add Brownian motion to the velocities...I'm about to commmit coding atocities...be forewarned! not sure how to do this "correctly"
bug.vx += (Math.random() * 0.2 - 0.1) * 5;
bug.vy += (Math.random() * 0.2 - 0.1) * 5;
//Add some friction
//bug.vx += 0.95;
//bug.vy += 0.95;
//Move the bug
bug.x += bug.vx;
bug.y += bug.vy;
//Stage Boundaries
//Reverse bug's velocity when it hits stage edges
//if (bug.x > stage.stageWidth)//||if (bug.x < 0)
//{
//bug.vx *= -1;
//}
//if (bug.x < 0)
//{
//bug.vx *= -1;
//}
if (bug.y > stage.stageHeight)
{
bug.vy *= -1;
}
if (bug.y < 0)
{
bug.vy *= -1;
}
//Bug emerges from opposite sides
if (bug.x - bug.width / 2 > stage.stageWidth)
{
bug.x = 0 - bug.width / 2;
}
else if (bug.x + bug.width / 2 < 0)
{
bug.x = stage.stageWidth + bug.width / 2;
}
//if (bug.y - fly.height / 2 > stage.stageHeight)
//{
//bug.y = 0 - bug.height / 2;
//}
//else if (bug.y + bug.height / 2 < 0)
//{
//bug.y = stage.stageHeight + bug.height / 2;
//}
}//end onBugMove function
}// end class
} // end package
This coding includes a lot of "commented out" code for the game that will eventually be (by finals week) Also, it obviously still needs a lot. Ultimately, the game will be about a hen and a rooster working together to catch enough bugs to create/lay an egg while avoiding the ever present fox. The motion of the hen and the rooster is tied so that some strategy will be necessary to catch bugs and avoid the fox. The hen has three lives should she get offed by the fox. The more bugs she eats, the sooner she lays an egg. The rooster can chase the fox away if he has eaten enough bugs. The odds of his being successful in the chase increase with increased bug consumption. Score goes up with egg laying.
No comments:
Post a Comment