原创设计 · PhotoShop · AI/CD · Fireworks · AutoCAD · 3DMAX · Flash · 网页设计 · 高精图库 · 笔刷滤镜 · 矢量素材 · 图片素材 · 模板素材· CG素材 · 思缘相册
加入VIP,免费下载精美素材 · PS新手学习推荐教程 · PS教程 · PS探讨和提问 · 思缘求图 · 数码暗房 · 设计作品欣赏 · 设计理论 · PSD素材 · 摄影作品交流 · 素材求助区

900G矢量素材,PSD设计图库
设计优秀作品十二期/新手学习贴
加入VIP,即送3000缘分币,每月500
 下载素材,加入VIP,享受更多权限
发新话题
打印

[菜鸟学院] <原创>飞机游戏的制作,适合新手

<原创>飞机游戏的制作,适合新手

≯全屏显示或下载≮




注释写在代码里面了,不懂的可以问,或者看这个帖子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 编辑 ]

附件

plane.fla (202.5 KB)
  下载必看 缘分币获取和充值

2008-1-14 11:54, 下载次数: 26

plane.swf (10.45 KB)
  下载必看 缘分币获取和充值

2008-1-14 11:54, 下载次数: 105





http://blog.csdn.net/adreamstar/

TOP

噢吆~   好东东~  先观摩一下~~~~



TOP

发新话题


关于本站 广告服务 联系我们 版权隐私 合作站点 网站地图 免责申明 管理团队

Powered by Discuz!6.0.0 Copyright © 2008 www.missyuan.com All rights reserved.