//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
Tuesday, May 31, 2011
A Fowl
In the interest of maintaining my sanity, the rest of my hair that hasn't been clenched out it bouts of frustration, and to prevent the dangerous lobbing of laptops, my game has been declared finished. The accompanying reflective essay will come tomorrow.
https://sites.google.com/a/sou.edu/dmf203temple/swftemple/FirstGame02.swf?attredirects=0
https://sites.google.com/a/sou.edu/dmf203temple/swftemple/FirstGame02.swf?attredirects=0
Sunday, May 29, 2011
Monday, May 16, 2011
Sunday, May 15, 2011
Hens & Roosters
I actually described my game in my posts of last week. Please, look there for the game summary.
Sunday, May 8, 2011
Coding for Hens & Roosters
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.
{
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.
Game Questions...
Well, it seems my game is ridiculously unformed. The raw elements are there, but more collision work (bug eating) is needed, and a score element needs to be added. and published size is still a mystery, Looked fine in Flash, but once again, difficulties in the move to the blog. Argh! The random motion on the bugs worked nicely. Oh, and speeds of characters and looping background needs work. If I don't go on a homicidal coding induced rampage, I may try to tackle more of this tonight. Or, I may just let the brain rest for a bit.
Subscribe to:
Posts (Atom)