文档类:
{
importflash.display.Sprite;
importflash.events.Event;
importflash.events.MouseEvent;
[SWF(backgroundColor="0x000000",frameRate="60")]
publicclassMainextendsSprite
{
privatevarpatternList:Array=newArray();
privatevarmoveBullet:Array=newArray();
publicfunctionMain():void
{
if(stage)init();
elseaddEventListener(Event.ADDED_TO_STAGE,init);
}
privatefunctioninit(e:Event=null):void
{
removeEventListener(Event.ADDED_TO_STAGE,init);
//entrypoint
MouseDown(null);
addEventListener(Event.ENTER_frame,Enterframe);
stage.addEventListener(MouseEvent.MOUSE_DOWN,MouseDown);
}
privatefunctionEnterframe(event:Event):void
{
vari:int=0;
for(i=0;i<patternList.length;i++)
{
varbullet:Bullet=patternList[i].Run();
if(bullet!=null)
{
addChild(bullet);
}
}
for(i=patternList.length-1;i>=0;i--)
{
if(patternList[i].isEnd())
{
//从待命到移动
for(varj:int=0;j<patternList[i].waitBullet.length;j++)
{
patternList[i].waitBullet[j].StartSlide();
moveBullet.push(patternList[i].waitBullet[j]);
}
patternList.splice(i,1);
}
}
//移动
if(moveBullet.length>0)
{
for(i=moveBullet.length-1;i>=0;i--)
{
//
if(moveBullet[i].slideFlag)
{
moveBullet[i]._xx+=Math.cos(moveBullet[i].slideAngle*Math.PI/180)*moveBullet[i].slideSpeed;
moveBullet[i]._xy+=Math.sin(moveBullet[i].slideAngle*Math.PI/180)*moveBullet[i].slideSpeed;
moveBullet[i].x=moveBullet[i]._xx;
moveBullet[i].y=moveBullet[i]._xy;
if(moveBullet[i].slideSpeed>0)
{
moveBullet[i].slideSpeed-=moveBullet[i].slideSpeedMax/50;
if(moveBullet[i].slideSpeed<0)moveBullet[i].slideFlag=false;
}
}else
{
moveBullet[i]._xx+=Math.cos(moveBullet[i].moveAngle*Math.PI/180)*1;
moveBullet[i]._xy+=Math.sin(moveBullet[i].moveAngle*Math.PI/180)*1;
moveBullet[i].x=moveBullet[i]._xx;
moveBullet[i].y=moveBullet[i]._xy;
if(moveBullet[i].x<-50||moveBullet[i].x>stage.stageWidth+50||moveBullet[i].y<-50||moveBullet[i].y>stage.stageHeight+50)
{
removeChild(moveBullet[i]);
moveBullet.splice(i,1);
}
}
}
}
}
privatefunctionMouseDown(event:MouseEvent):void
{
//小星
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,50,0xFF5555,(270+72*0),3));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,50,0xFF5555,(270+72*1),3));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,50,0xFF5555,(270+72*2),3));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,50,0xFF5555,(270+72*3),3));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,50,0xFF5555,(270+72*4),3));
//大星
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,100,0x5555FF,(270+72*0),5));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,100,0x5555FF,(270+72*1),5));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,100,0x5555FF,(270+72*2),5));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,100,0x5555FF,(270+72*3),5));
patternList.push(newPattern(stage.stageWidth/2,stage.stageHeight/2,false,100,0x5555FF,(270+72*4),5));
}
}
}
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
importflash.display.Sprite;
importflash.geom.Point;
//-----------------------------
//图案类
classPattern{
privatevarreverse:Boolean=false;
privatevarstarSize:Number=150;
privatevarbulletColor:uint=0x000000;
privatevarslideAngle:Number=0;
privatevarslideSpeed:Number=0;
privatevarend:Boolean=false;
privatevarcount:int=0;
privatevardefX:int=0;
privatevardefY:int=0;
privatevartarget:Array=newArray();
privatestaticconstPATH_OBJ_NUM:int=20;//子弹数
privatestaticconstTARGET_NUM:int=5;
privatestaticconstTARGET_ANGLE:Array=[270+72*3,270+72*1,270+72*4,270+72*2,270];//通过的目标地点的角度
privatestaticconstTARGET_ANGLE2:Array=[270+72*2,270+72*4,270+72*1,270+72*3,270];//
publicvarwaitBullet:Array=newArray();
publicfunctionPattern(
_gx:int=0,_gy:int=0,
_rev:Boolean=false,
_starSize:Number=80,
_bulletColor:uint=0x000000,
_slideAngle:Number=0,
_slideSpeed:Number=0
){
count=0;
defX=_gx;
defY=_gy;
reverse=_rev;
starSize=_starSize;
bulletColor=_bulletColor;
slideAngle=_slideAngle;
slideSpeed=_slideSpeed;
for(vari:int=0;i<5;i++)
{
varangle:Number=TARGET_ANGLE[i];
if(reverse)angle=TARGET_ANGLE2[i]+180;//反転
elseangle=TARGET_ANGLE[i];
target[i]=newPoint(Math.cos(angle*Math.PI/180)*starSize,Math.sin(angle*Math.PI/180)*starSize);
}
}
//子弹生成
publicfunctionRun():Bullet{
varbullet:Bullet=newBullet(bulletColor,slideAngle,slideSpeed);
vartargetNo:int=int(count/PATH_OBJ_NUM);
vartargetRate:int=int(count%PATH_OBJ_NUM);
varp:Point;
//子弹的座标
p=Point.interpolate(target[targetNo],target[(targetNo+(TARGET_NUM-1))%TARGET_NUM],targetRate/PATH_OBJ_NUM);
bullet.x=p.x+defX;
bullet.y=p.y+defY;
bullet._xx=p.x+defX;
bullet._xy=p.y+defY;
//子弹的移动角度
//if(!reverse)bullet.moveAngle=-count/PATH_OBJ_NUM/TARGET_NUM*720+135;
//elsebullet.moveAngle=count/PATH_OBJ_NUM/TARGET_NUM*720-135;
bullet.moveAngle=(-int(count/PATH_OBJ_NUM)/TARGET_NUM*720+108)+((count%PATH_OBJ_NUM)*180/PATH_OBJ_NUM);//Target始点角度+180*rateグレイソーに入る前の奴
waitBullet.push(bullet);
count++;
if(count==TARGET_NUM*PATH_OBJ_NUM)end=true;
returnbullet;
}
publicfunctionisEnd():Boolean{returnend;}
}
//-----------------------------
//子弹类
classBulletextendsSprite{
publicvarslideFlag:Boolean=false;
publicvarslideAngle:Number=0;
publicvarslideSpeed:Number=0;
publicvarslideSpeedMax:Number=0;
publicvarmoveAngle:Number=0;
publicvar_xx:Number=0;
publicvar_xy:Number=0;
publicfunctionBullet(color:uint,_slideAngle:Number=0,_slideSpeed:Number=50){
super();
graphics.beginFill(color);
graphics.drawCircle(0,0,5);
graphics.endFill();
graphics.beginFill(0xFFFFFF,0.5);
graphics.drawCircle(0,0,3);
graphics.endFill();
slideAngle=_slideAngle;
slideSpeed=_slideSpeed;
slideSpeedMax=_slideSpeed;
slideFlag=false;
}
publicfunctionStartSlide():void
{
slideFlag=true;
}
}