≯全屏显示或下载≮
注释写在代码里面了,不懂的可以问,或者看这个帖子
http://bbs.jcwcn.com/thread-150175-1-1.html复制内容到剪贴板
代码:
/*作者:梦自在*/
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();[
本帖最后由 梦自在 于 2008-1-14 11:55 编辑 ]