import flash.events.Event;
var speed=3
speed is 3
var blockArray:Array=new Array();
add a new array
var Ship:MovieClip = new ship();
addChild(Ship);
add a ship to the stage
Ship.startDrag(true);
makes ship follow mouse
Mouse.hide();
hides mouse
for (var i:int = 0; i < 15; i++) {
for loop. will run 15 times
var cube:MovieClip = new box();
go to library look for box
cube.x=Math.random()*550
random position
cube.y=Math.random()*400
random position
cube.scaleX=Math.random () *1.5+.1;
cube.scaleY=Math.random () *1.5+.1;
cube.rotation=Math.random()*360;
rotated randomly
addChild(cube);
add onto stage
blockArray[i]=cube
fills list with 15 cubes
}
stage.addEventListener(Event.ENTER_FRAME,checkHit);
listen to the stage and run a function called check
function checkHit(myevent:Event):void {
for (var i:int=0;i<15; i++) {
create a for loop 15 times
if(blockArray[i].hitTestPoint(mouseX,mouseY, true)) {
if any cubes get hit by the registration point of the mouse in x direction or y direction
blockArray[i].alpha=.3;
if the obgect is hit then it must reduce the alpha by 3
Ship.play();
this tells the ship to play if it is hit
}
blockArray[i].y+=speed
if (blockArray[i].y>450){
blockArray[i].y=-50
blockArray[i].x=Math.random()*550
makes the boxes randomly move allong the x axis instaid of being the same all the time
speed+=0.1;
}
}
}
makes the boxes speed up by 0.1 every time they loop round
No comments:
Post a Comment