很久之前自己寫的太空遊戲flash

很久之前自己寫的太空遊戲flash,遊戲效果還不錯 哈哈,爽!,寫得不好,呵呵:

[img]http://dl.iteye.com/upload/attachment/352039/c9361a47-b705-3fc1-b233-a1baa68f2771.png[/img]

[img]http://dl.iteye.com/upload/attachment/352041/d9d5f0e2-75ec-328e-b4eb-915be71b302c.png[/img]

部分代碼如下:

/**

*Author:luodongfu

**/

import flash.events.Event;
import flash.events.TimerEvent;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.events.KeyboardEvent;
import flash.ui.*;
import fl.transitions.Tween;
import fl.transitions.easing.*;

//敵人普通飛機的保存數組
var places:Array=new Array();

//敵人降落傘工兵數組
var sans:Array=new Array();

//我方發射的炮彈數組
var paos:Array=new Array();

//敵方發射的炮彈
var djPaos:Array=new Array();

//敵方的智能轟炸機
var djPlaces:Array=new Array();

var da:Number=10;

//我方的坦克
var tange:TanGeMC=new TanGeMC();
tange.x=300;
tange.y=350;
addChild(tange);

//按鍵左右建向左右移動我方坦克
stage.addEventListener(KeyboardEvent.KEY_DOWN,startMove);

//按空格建發射坦克炮彈
stage.addEventListener(KeyboardEvent.KEY_UP,faPaoFun);

//每貞偵聽函數
stage.addEventListener(Event.ENTER_FRAME,onEnterFrameAction);

//炮彈爆炸聲音
var paozhaRequest:URLRequest=new URLRequest("Fx12693_cannon4.mp3");
var paozhaSound:Sound=new Sound(paozhaRequest);

var djSPao:Number=0;

//降落傘爆炸聲音
var sanBombSndRequest:URLRequest=new URLRequest("Fx13423_bomb1.mp3");
var sanBombSound:Sound=new Sound(sanBombSndRequest);

//坦克發射炮彈時聲音
var kaiPaoRequest:URLRequest=new URLRequest("Fx12077_tankfire.mp3");
var kaiPaoSound:Sound=new Sound(sanBombSndRequest);

//定時產生幾個一號敵機
var gPlaceTimer:Timer=new Timer(8000);
gPlaceTimer.addEventListener(TimerEvent.TIMER,createPlace);
gPlaceTimer.start();

//定時產生幾個二號敵機
var rPlaceTimer:Timer=new Timer(10000);
rPlaceTimer.addEventListener(TimerEvent.TIMER,createPlace2);
rPlaceTimer.start();

//產生敵人智能轟炸機
var djPlace_mc:DJPlaceMC=new DJPlaceMC();
djPlace_mc.x=250+Math.random()*80;
djPlace_mc.y=100+Math.random()*20;
addChild(djPlace_mc);
djPlaces.push(djPlace_mc);

function removeSanListener(k:uint,san:LuoSanMC):void
{
san.removeSanListener();
removeChild(san);
sans.splice(k,1);
san=null;
trace("del san outsize of stage ok and the san size is "+(sans.length-1));
}

開始遊戲,生成飛機坦克
function onEnterFrameAction(e:Event):void
{
for (var k:uint=0; k<sans.length; k++)
{
var isDelSan:Boolean=false;
var tempSan=sans[k];
for (var a:uint=0; a<paos.length; a++)
{
var tempPao=paos[a];

//如果炮彈擊中降落傘,則降落傘移除並爆炸。報攤移除
if (tempPao.hitTestObject(tempSan))
{
tempSan.gotoAndPlay(2);
paozhaSound.play();

sans.splice(k,1);
tempSan=null;
isDelSan=true;
removeChild(tempPao);
paos.splice(a,1);
tempPao=null;
break;
}
}

if (isDelSan)
{
continue;
}

if (!isDelSan &&tempSan.hitTestObject(diMian_mc))
{
isDelSan=true;
sanBombSound.play();
removeSanListener(k,tempSan);
}

if (!isDelSan &&(tempSan.y>400 ||tempSan.x<0))
{
removeSanListener(k,tempSan);
}
}

for (var i:uint=0; i<places.length; i++)
{
var tempPlace=places;
tempPlace.x-=10;
var isDel:Boolean=false;
for (var n:uint=0; n<paos.length; n++)
{
var pao=paos[n];
if (pao.hitTestObject(tempPlace))
{
tempPlace.gotoAndPlay(3);
paozhaSound.play();
//removeChild(tempPlace);
places.splice(i,1);
tempPlace.stopSound();
tempPlace=null;
isDel=true;
removeChild(pao);
paos.splice(n,1);
pao=null;
var myRan:Number=Math.random()*10;
if(myRan>5)
{
createPlace(null);
}
else
{
createPlace2(null);
}
break;
}

}
if (!isDel&&tempPlace.x<0 )
{
removeChild(tempPlace);
places.splice(i,1);
tempPlace.stopSound();
tempPlace=null;
isDel=true;
continue;
}
var ran:Number=Math.random()*100;
if (ran>94 &&!isDel)
{
var san:LuoSanMC=new LuoSanMC(tempPlace.x+20,tempPlace.y+20);
this.addChild(san);
sans.push(san);
}
}

for (var m:uint=0; m<paos.length; m++)
{
var myPao=paos[m];
var delMyPao:Boolean=false;
for ( n=0; n<djPlaces.length; n++)
{
var djPlace=djPlaces[n];
if(djPlace.hitTestObject(myPao))
{
djSPao++;
if(djSPao>25)
{
djPlace.gotoAndPlay(2);
paozhaSound.play();
djSPao=0;
djPlaces.splice(n,1);
}
delMyPao=true;
removeChild(myPao);
paos.splice(m,1);
}
}

if(!delMyPao)
{
if (myPao.y<-5)
{
removeChild(myPao);
paos.splice(m,1);
continue;
}
myPao.y-=7;
}

}
var ran2:Number=Math.random()*100;
if (ran2>80 &&djPlaces.length>0)
{
newDPlacePao();
}

var ran3:Number=Math.random()*10;
if(ran3>=7&& djPlaces.length==0)
{
newDPlaceMC();
}
}

.................
....................................................................................
.......................................................
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章