飞机游戏制作

/*作者:梦自在*/
stop();
/*声音效果*/
var bgSound:Sound 
=   new  Sound();
var enemySound:Sound 
=   new  Sound();
bgSound.attachSound(
" bg_wav " );
enemySound.attachSound(
" bullet_wav " );
bgSound.start(
0 30000 );
score_txt.text 
=   0 ;
var killEnemy_num:Number 
=   0 ;
var enemy_speed:Number;
/*定义运动速度*/
var speed:Number 
=   15 ;
/*检测杀死敌人的数量*/
var enemy_num:Number 
=   0 ;
/*敌人子弹是不是已经发出*/
var isEnemyBulletSent:Boolean;
_root.createEmptyMovieClip(
" bullet_container " 3 );
function createEnemy_func() 
{
/*敌人的图层*/
isCreateEnemy 
= true;
_root.createEmptyMovieClip(
"enemy_container"1);
for (var i:Number = 0; i<=4; i++{
  
/*从库中把enemy复制出来*/
  enemy_container.attachMovie(
"enemy""newenemy"+i, -100+i);
  
/*位子*/
  enemy_container[
"newenemy"+i]._x = 30+Math.random()*500;
  enemy_container[
"newenemy"+i]._y = Math.random()*100;
  enemy_speed 
= Math.random()*20-10;
  createEnemyBullet_func();
  enemy_container[
"newenemy"+i].v = enemy_speed;
  enemy_container[
"newenemy"+i].onEnterFrame = function() {
   
this._x += this.v;
   
this._x>530 || this._x<30 ? this.v=-this.v : 梦自在;
  }
;
}

}

function createEnemyBullet_func() 
{
/*子弹的图层*/
_root.createEmptyMovieClip(
"enemyBullet_container"2);
for (var i:Number = 0; i<=4; i++{
  
/*当飞机被击毁后就不能再发子弹了*/
  
if (enemy_container["newenemy"+i].getDepth()<0{
   enemyBullet_container.attachMovie(
"bullet""enemyBullet"+i, i+10);
   enemyBullet_container[
"enemyBullet"+i]._x = enemy_container["newenemy"+i]._x;
   enemyBullet_container[
"enemyBullet"+i]._y = enemy_container["newenemy"+i]._y;
   enemyBullet_container[
"enemyBullet"+i].onEnterFrame = function() {
    
this._y += Math.random()*6+4;
    
/*子弹碰到飞机后就结束游戏*/
    
if (this.hitTest(plane_mc._x, plane_mc._y)) {
     enemyBullet_container.removeMovieClip();
     enemy_container.removeMovieClip();
     plan_mc.removeMovieClip();
     gotoAndStop(
2);
    }

    
if (this._y>440{
     isEnemyBulletSent 
= false;
     
this.removeMovieClip();
    }

   }
;
  }

}

}

onEnterFrame 
=  function ()  {
/*这样写一次只能发射一个子弹*/
if (!isEnemyBulletSent) {
  isEnemyBulletSent 
= true;
  createEnemyBullet_func();
}

}
;
/*控制方向的键,对这指令不懂的话按F1查看帮助*/
plane_mc.onEnterFrame 
=  function()  {
/*方向键按上*/
if (Key.isDown(Key.UP)) {
  
this._y -= speed;
  
this._y<10 ? this._y=10 : 梦自在;
}

if (Key.isDown(Key.DOWN)) {
  
this._y += speed;
  
this._y>380 ? this._y=380 : 梦自在;
}

if (Key.isDown(Key.LEFT)) {
  
this._x -= speed;
  
this._x<10 ? this._x=10 : 梦自在;
}

if (Key.isDown(Key.RIGHT)) {
  
this._x += speed;
  
this._x>530 ? this._x=530 : 梦自在;
}

/*如果你按空格键并且子弹没发射出去的话*/ 
if (Key.isDown(Key.SPACE)) {
  
/*获取当前的最底深度*/
  enemySound.start();
  var depth:Number 
= bullet_container.getNextHighestDepth();
  bullet_container.attachMovie(
"bullet""newbullet"+depth, depth);
  bullet_container[
"newbullet"+depth]._x = plane_mc._x;
  bullet_container[
"newbullet"+depth]._y = plane_mc._y;
  bullet_container[
"newbullet"+depth].onEnterFrame = function() {
   
this._y -= speed;
   
/*对于舞台上面所有的敌人,如果碰到子弹就子弹和敌人一起删去*/
   
for (var i in enemy_container) {
    
if (enemy_container[i].hitTest(this._x, this._y)) {
     
/*深度为正才能用removeMovieClip删去*/
     
this.removeMovieClip();
     enemy_container[i].swapDepths(
1);
     enemy_container[i].removeMovieClip();
     enemy_num 
+= 1;
     score_txt.text 
= enemy_num;
     killEnemy_num 
+= 1;
    }

   }

   
if (killEnemy_num == 5{
    createEnemy_func();
    killEnemy_num 
= 0;
   }

  }
;
}

}
;
createEnemy_func();

源文件下载:http://space.flash8.net/bbs/attachment.php?aid=339910

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值