var egret = window.egret;var __reflect = (this && this.__reflect) || function (p, c, t) {
    p.__class__ = c, t ? t.push(c) : t = [c], p.__types__ = p.__types__ ? t.concat(p.__types__) : t;
};
var __extends = this && this.__extends || function __extends(t, e) { 
 function r() { 
 this.constructor = t;
}
for (var i in e) e.hasOwnProperty(i) && (t[i] = e[i]);
r.prototype = e.prototype, t.prototype = new r();
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = y[op[0] & 2 ? "return" : op[0] ? "throw" : "next"]) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [0, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
/**
  * 可滚动的底图
  */
var BgMap = (function (_super) {
    __extends(BgMap, _super);
    function BgMap() {
        var _this = _super.call(this) || this;
        /**控制滚动速度*/
        _this.speed = 4;
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        return _this;
    }
    /**初始化*/
    BgMap.prototype.onAddToStage = function (event) {
        this.removeEventListener(egret.Event.ADDED_TO_STAGE, this.onAddToStage, this);
        this.stageW = this.stage.stageWidth;
        this.stageH = this.stage.stageHeight;
        console.log('width:', this.stage.$stageWidth);
        var texture = RES.getRes("background_png");
        this.textureHeight = texture.textureHeight; //保留原始纹理的高度，用于后续的计算
        this.rowCount = Math.ceil(this.stageH / this.textureHeight) + 1; //计算在当前屏幕中，需要的图片数量
        this.bmpArr = [];
        //创建这些图片，并设置y坐标，让它们连接起来
        for (var i = 0; i < this.rowCount; i++) {
            var result = new egret.Bitmap();
            var texture = RES.getRes("background_png");
            result.texture = texture;
            var bgBmp = result;
            bgBmp.y = this.textureHeight * i - (this.textureHeight * this.rowCount - this.stageH);
            this.bmpArr.push(bgBmp);
            this.addChild(bgBmp);
        }
    };
    /**开始滚动*/
    BgMap.prototype.start = function () {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
        this.addEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
    };
    /**逐帧运动*/
    BgMap.prototype.enterFrameHandler = function (event) {
        for (var i = 0; i < this.rowCount; i++) {
            var bgBmp = this.bmpArr[i];
            bgBmp.y += this.speed;
            //判断超出屏幕后，回到队首，这样来实现循环反复
            if (bgBmp.y > this.stageH) {
                bgBmp.y = this.bmpArr[0].y - this.textureHeight;
                this.bmpArr.pop();
                this.bmpArr.unshift(bgBmp);
            }
        }
    };
    /**暂停滚动*/
    BgMap.prototype.pause = function () {
        this.removeEventListener(egret.Event.ENTER_FRAME, this.enterFrameHandler, this);
    };
    return BgMap;
}(egret.DisplayObjectContainer));
__reflect(BgMap.prototype, "BgMap");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var LoadingUI = (function (_super) {
    __extends(LoadingUI, _super);
    function LoadingUI() {
        var _this = _super.call(this) || this;
        _this.createView();
        return _this;
    }
    LoadingUI.prototype.createView = function () {
        this.textField = new egret.TextField();
        this.addChild(this.textField);
        this.textField.y = 300;
        this.textField.width = 480;
        this.textField.height = 100;
        this.textField.textAlign = "center";
    };
    LoadingUI.prototype.setProgress = function (current, total) {
        this.textField.text = "Loading..." + current + "/" + total;
    };
    LoadingUI.prototype.setCustomProgress = function (current, total, message) {
        this.textField.text = "[" + message + "]  \u52A0\u8F7D\u4E2D..." + current + "/" + total;
    };
    return LoadingUI;
}(egret.Sprite));
__reflect(LoadingUI.prototype, "LoadingUI");
//////////////////////////////////////////////////////////////////////////////////////
//
//  Copyright (c) 2014-2015, Egret Technology Inc.
//  All rights reserved.
//  Redistribution and use in source and binary forms, with or without
//  modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of the Egret nor the
//       names of its contributors may be used to endorse or promote products
//       derived from this software without specific prior written permission.
//
//  THIS SOFTWARE IS PROVIDED BY EGRET AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
//  OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
//  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//  IN NO EVENT SHALL EGRET AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
//  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
//  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA,
//  OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
//  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//////////////////////////////////////////////////////////////////////////////////////
var Main = (function (_super) {
    __extends(Main, _super);
    function Main() {
        var _this = _super.call(this) || this;
        _this.listResources = new Array(new Resources("Plane", "飞机模型"), new Resources("Bullet", "子弹模型"), new Resources("Bgm", "背景音乐"));
        /**触发主角开枪时间的间隔*/
        _this.planeShootTime = new egret.Timer(500);
        /**触发创建敌机的间隔*/
        _this.enemyFightersTimer = new egret.Timer(1500);
        /**触发敌人开枪时间的间隔*/
        _this.enemyShootTime = new egret.Timer(1000);
        /**敌人的飞机*/
        _this.enemyFighterslist = [];
        /*子弹集合*/
        _this.Bulletlist = [];
        _this.addEventListener(egret.Event.ADDED_TO_STAGE, _this.onAddToStage, _this);
        _this._lastTime = egret.getTimer();
        return _this;
    }
    Main.prototype.onAddToStage = function (event) {
        //设置加载进度界面
        //Config to load process interface
        this.loadingView = new LoadingUI();
        this.stage.addChild(this.loadingView);
        //初始化Resource资源加载库
        //initiate Resource loading library
        RES.addEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        RES.loadConfig("resource/default.res.json", "resource/");
    };
    /**
     * 配置文件加载完成,开始预加载Plane资源组。
     * configuration file loading is completed, start to pre-load the Plane resource group
     */
    Main.prototype.onConfigComplete = function (event) {
        RES.removeEventListener(RES.ResourceEvent.CONFIG_COMPLETE, this.onConfigComplete, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
        RES.addEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
        RES.addEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, this.onItemLoadError, this);
        for (var item in this.listResources) {
            var list = this.listResources[item];
            var resources = list;
            RES.loadGroup(resources.name);
        }
    };
    /**
     * Plane资源组加载完成
     * Preload resource group is loaded
     */
    Main.prototype.onResourceLoadComplete = function (event) {
        var isOver = false;
        for (var item in this.listResources) {
            var list = this.listResources[item];
            var resources = list;
            if (event.groupName == resources.name) {
                resources.isOver = true;
            }
            isOver = resources.isOver;
        }
        if (isOver) {
            this.stage.removeChild(this.loadingView);
            RES.removeEventListener(RES.ResourceEvent.GROUP_COMPLETE, this.onResourceLoadComplete, this);
            RES.removeEventListener(RES.ResourceEvent.GROUP_LOAD_ERROR, this.onResourceLoadError, this);
            RES.removeEventListener(RES.ResourceEvent.GROUP_PROGRESS, this.onResourceProgress, this);
            RES.removeEventListener(RES.ResourceEvent.ITEM_LOAD_ERROR, this.onItemLoadError, this);
            //背景
            this.bg = new BgMap(); //创建可滚动的背景
            this.addChild(this.bg);
            this.createGameScene();
        }
    };
    /**
     * 资源组加载出错
     *  The resource group loading failed
     */
    Main.prototype.onItemLoadError = function (event) {
        console.warn("Url:" + event.resItem.url + " has failed to load");
    };
    /**
     * 资源组加载出错
     *  The resource group loading failed
     */
    Main.prototype.onResourceLoadError = function (event) {
        //TODO
        console.warn("Group:" + event.groupName + " has failed to load");
        //忽略加载失败的项目
        //Ignore the loading failed projects
        this.onResourceLoadComplete(event);
    };
    /**
     * Plane资源组加载进度
     * Loading process of Plane resource group
     */
    Main.prototype.onResourceProgress = function (event) {
        for (var item in this.listResources) {
            var list = this.listResources[item];
            var resources = list;
            if (event.groupName == resources.name) {
                this.loadingView.setCustomProgress(event.itemsLoaded, event.itemsTotal, resources.chinese);
            }
        }
    };
    /**
     * 创建游戏场景
     * Create a game scene
     */
    Main.prototype.createGameScene = function () {
        this.start();
    };
    //游戏结束
    Main.prototype.GameOver = function () {
        var over = RES.getRes("game_over_mp3");
        over.play(0, 1);
        this._channel.stop();
        this._channel = null;
        this.planeShootTime.stop();
        this.enemyFightersTimer.stop();
        this.enemyShootTime.stop();
        /**触发主角开枪时间的间隔*/
        this.planeShootTime = null;
        /**触发创建敌机的间隔*/
        this.enemyFightersTimer = null;
        /**触发敌人开枪时间的间隔*/
        this.enemyShootTime = null;
        for (var item in this.enemyFighterslist) {
            this.removeChild(this.enemyFighterslist[item].Image);
        }
        this.enemyFighterslist = [];
        for (var item in this.Bulletlist) {
            this.removeChild(this.Bulletlist[item].Image);
        }
        this.Bulletlist = [];
        this.bg.pause();
        var lives = this.myfighter.lives;
        this.removeChild(this.myfighter.Image);
        this.myfighter.Image = null;
        this.myfighter.lives = 0;
        var overbg = new egret.Bitmap(RES.getRes("gameover_png"));
        var backButton = new egret.Bitmap(RES.getRes("btn_finish_png"));
        var label = new egret.TextField();
        label.text = lives + "分";
        label.x = this.stage.stageWidth / 2 - label.width / 2;
        label.y = this.stage.stageHeight / 2;
        backButton.x = this.stage.stageWidth / 2 - backButton.width / 2;
        backButton.y = (this.stage.stageHeight / 2) + 80;
        var mapthis = this;
        backButton.touchEnabled = true;
        backButton.addEventListener(egret.TouchEvent.TOUCH_TAP, function (evt) {
            mapthis._lastTime = 0;
            mapthis.removeChild(overbg);
            mapthis.removeChild(label);
            mapthis.removeChild(backButton);
            mapthis.start.apply(mapthis);
        }, this);
        this.addChild(overbg);
        this.addChild(label);
        this.addChild(backButton);
    };
    //开始游戏
    Main.prototype.start = function () {
        this.bg.start();
        this.sound = RES.getRes("game_music_mp3");
        this._channel = this.sound.play(0, -1);
        /**触发主角开枪时间的间隔*/
        this.planeShootTime = new egret.Timer(500);
        /**触发创建敌机的间隔*/
        this.enemyFightersTimer = new egret.Timer(1500);
        /**触发敌人开枪时间的间隔*/
        this.enemyShootTime = new egret.Timer(1000);
        //初始化主角
        var buleplane = new Blueplane();
        var plane = buleplane.init(this);
        this.addChild(plane.Image);
        this.addEventListener(egret.Event.ENTER_FRAME, this.gameViewUpdate, this);
        this.myfighter = plane;
        //主角添加事件
        this.planeShootTime.addEventListener(egret.TimerEvent.TIMER, this.AddMyPlane, [this, plane]);
        this.planeShootTime.start();
        //敌人开火事件
        this.enemyShootTime.addEventListener(egret.TimerEvent.TIMER, this.enemyShootTimefun, this);
        this.enemyShootTime.start();
        //敌人添加事件
        this.enemyFightersTimer.addEventListener(egret.TimerEvent.TIMER, this.enemyFightersTimerfun, this);
        this.enemyFightersTimer.start();
    };
    //添加主角事件
    Main.prototype.AddMyPlane = function () {
        var bullet = this[1].Shoot();
        this[0].Bulletlist.push(bullet);
        this[0].addChild(bullet.Image);
        bullet.bulletSound.play(0, 1);
    };
    //敌军子弹
    Main.prototype.enemyShootTimefun = function () {
        var i = 0;
        var theFighter;
        var enemyFighterCount = this.enemyFighterslist.length;
        for (i = 0; i < enemyFighterCount; i++) {
            theFighter = this.enemyFighterslist[i];
            var bullet = theFighter.Shoot();
            this.Bulletlist.push(bullet);
            this.addChild(bullet.Image);
        }
    };
    //加入敌军
    Main.prototype.enemyFightersTimerfun = function () {
        //加入敌军
        var enemyplaneClass = new Enemyplane();
        var x = Math.random() * (this.stage.width - 128); //随机坐标
        var enemyplane = enemyplaneClass.init(x, -128);
        this.enemyFighterslist.push(enemyplane);
        this.addChild(enemyplane.Image);
        var bullet = enemyplane.Shoot();
        this.Bulletlist.push(bullet);
        this.addChild(bullet.Image);
    };
    /*飞机碰撞检测*/
    Main.prototype.collision = function () {
        var bullet = this.Bulletlist;
        var drplane = this.enemyFighterslist;
        var myplan = this.myfighter;
        for (var i in bullet) {
            if (bullet[i].Plane.Image != myplan.Image) {
                if (myplan.Image != null) {
                    var isHit = myplan.Image.hitTestPoint(bullet[i].X, bullet[i].Y - 40, true);
                    if (isHit) {
                        this.removeChild(bullet[i].Image);
                        bullet.splice(bullet.indexOf(bullet[i]), 1);
                        this.removeEventListener(egret.Event.ENTER_FRAME, this.gameViewUpdate, this);
                        this.GameOver.apply(this);
                        return;
                    }
                }
            }
            else {
                for (var l in drplane) {
                    if (this.myfighter != null) {
                        var myHit = drplane[l].Image.hitTestPoint(this.myfighter.X, this.myfighter.Y, true);
                        if (myHit) {
                            this.removeEventListener(egret.Event.ENTER_FRAME, this.gameViewUpdate, this);
                            this.GameOver.apply(this);
                            return;
                        }
                    }
                    var isHit = drplane[l].Image.hitTestPoint(bullet[i].X, bullet[i].Y, true);
                    if (isHit) {
                        this.removeChild(bullet[i].Image);
                        bullet.splice(bullet.indexOf(bullet[i]), 1);
                        this.removeChild(drplane[l].Image);
                        drplane.splice(drplane.indexOf(drplane[l]), 1);
                        this.myfighter.lives += 1;
                    }
                }
            }
        }
    };
    /**游戏画面更新*/
    Main.prototype.gameViewUpdate = function (evt) {
        //为了防止FPS下降造成回收慢，生成快，进而导致DRAW数量失控，需要计算一个系数，当FPS下降的时候，让运动速度加快
        var nowTime = egret.getTimer();
        var fps = 1000 / (nowTime - (this._lastTime));
        this._lastTime = nowTime;
        var speedOffset = 60 / fps;
        /**
         * 统一子弹管理
         */
        var i = 0;
        var bullet;
        var BulletsCount = this.Bulletlist.length;
        for (; i < BulletsCount; i++) {
            bullet = this.Bulletlist[i];
            if (bullet.Type == "UP") {
                if (bullet.Y < 0) {
                    this.removeChild(bullet.Image);
                    this.Bulletlist.splice(i, 1);
                    i--;
                    BulletsCount--;
                }
                bullet.Y -= 7 * speedOffset;
                bullet.Image.y -= 7 * speedOffset;
            }
            else if (bullet.Type == "Donw") {
                if (bullet.Y - bullet.Image.height > this.stage.stageHeight) {
                    this.removeChild(bullet.Image);
                    this.Bulletlist.splice(i, 1);
                    i--;
                    BulletsCount--;
                }
                bullet.Y += 7 * speedOffset;
                bullet.Image.y += 7 * speedOffset;
            }
        }
        //敌人飞机运动
        var theFighter;
        var enemyFighterCount = this.enemyFighterslist.length;
        for (i = 0; i < enemyFighterCount; i++) {
            theFighter = this.enemyFighterslist[i];
            if (theFighter.Y - theFighter.Image.height > this.stage.stageHeight) {
                this.removeChild(theFighter.Image);
                this.enemyFighterslist.splice(i, 1);
                i--;
                enemyFighterCount--;
            }
            theFighter.Y += 4 * speedOffset;
            theFighter.Image.y += 4 * speedOffset;
        }
        this.collision();
    };
    return Main;
}(egret.DisplayObjectContainer));
__reflect(Main.prototype, "Main");
var DebugPlatform = (function () {
    function DebugPlatform() {
    }
    DebugPlatform.prototype.getUserInfo = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/, { nickName: "username" }];
            });
        });
    };
    DebugPlatform.prototype.login = function () {
        return __awaiter(this, void 0, void 0, function () {
            return __generator(this, function (_a) {
                return [2 /*return*/];
            });
        });
    };
    return DebugPlatform;
}());
__reflect(DebugPlatform.prototype, "DebugPlatform", ["Platform"]);
if (!window.platform) {
    window.platform = new DebugPlatform();
}
/**
 *
 * @author
 *
 */
var Bullet = (function () {
    /*
     * 子弹
     */
    function Bullet() {
    }
    return Bullet;
}());
__reflect(Bullet.prototype, "Bullet");
/**
 *
 * @author
 *
 */
var Plane = (function () {
    function Plane() {
    }
    //开枪
    Plane.prototype.Shoot = function () {
        var bullet = new Bullet();
        bullet.Type = this.Type;
        bullet.Image = new egret.Bitmap(RES.getRes(this.bulletImage));
        bullet.Image.width = 64;
        bullet.Image.height = 64;
        bullet.Plane = this;
        if (this.Type == "Donw") {
            bullet.Image.rotation = 180;
            bullet.X = this.X + 31 - (this.Image.width / 2);
            bullet.Y = this.Y + 60;
        }
        else {
            if (this.Image != null) {
                bullet.bulletSound = this.bulletSound;
                bullet.X = this.X + (this.Image.width / 2 - 35);
                bullet.Y = this.Y - 45;
            }
        }
        bullet.Image.x = bullet.X;
        bullet.Image.y = bullet.Y;
        return bullet;
    };
    ;
    return Plane;
}());
__reflect(Plane.prototype, "Plane");
/**
 *
 * @author
 *
 */
var Resources = (function () {
    /**
     * 资源
     */
    function Resources(name, chinese) {
        this.name = name;
        this.chinese = chinese;
        this.isOver = false;
    }
    return Resources;
}());
__reflect(Resources.prototype, "Resources");
/**
 *
 * @author
 *
 */
var Blueplane = (function (_super) {
    __extends(Blueplane, _super);
    function Blueplane() {
        return _super.call(this) || this;
    }
    /**
     * 创建主角
     */
    Blueplane.prototype.init = function (s) {
        var plane = new Plane();
        var planeImage = new egret.Bitmap(RES.getRes("BluePlane_png"));
        plane.blood = 100;
        plane.bulletImage = "bullet_03_png";
        plane.Image = planeImage;
        plane.Type = "UP";
        plane.lives = 0;
        var sound = RES.getRes("bullet_mp3");
        plane.bulletSound = sound;
        this.BottomCenter(plane, s);
        planeImage.touchEnabled = true;
        s.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this.PlaneMoveHandle, [plane, s]);
        s.addEventListener(egret.TouchEvent.TOUCH_MOVE, this.PlaneMoveHandle, [plane, s]);
        return plane;
    };
    /**
     * 飞机移动处理
     */
    Blueplane.prototype.PlaneMoveHandle = function (e) {
        var plane = this[0];
        if (plane.Image == null)
            return;
        var parent = this[1];
        var hight = plane.Image.height;
        var wight = plane.Image.width;
        plane.Image.x = e.stageX - (wight / 2);
        plane.Image.y = e.stageY - (hight / 2);
        if (plane.Image.x <= 0) {
            plane.Image.x = 0;
        }
        if (e.stageX + wight / 2 >= parent.stage.stageWidth) {
            plane.Image.x = parent.stage.stageWidth - wight;
        }
        if (plane.Image.y <= 0) {
            plane.Image.y = 0;
        }
        if (e.stageY + hight / 2 >= parent.stage.stageHeight) {
            plane.Image.y = parent.stage.stageHeight - hight;
        }
        plane.X = plane.Image.x;
        plane.Y = plane.Image.y;
    };
    /**
     * 初始默认底部居中位子
     */
    Blueplane.prototype.BottomCenter = function (bit, s) {
        var mapHight = s.stage.stageWidth;
        var mapwight = s.stage.stageHeight;
        var hight = bit.Image.height;
        var wight = bit.Image.width;
        bit.X = (mapHight / 2) - (bit.Image.width / 2);
        bit.Y = mapwight - bit.Image.height;
        bit.Image.x = (mapHight / 2) - (bit.Image.width / 2);
        bit.Image.y = mapwight - bit.Image.height;
    };
    return Blueplane;
}(egret.DisplayObjectContainer));
__reflect(Blueplane.prototype, "Blueplane");
/**
 *
 * @author
 *
 */
var Enemyplane = (function (_super) {
    __extends(Enemyplane, _super);
    function Enemyplane() {
        return _super.call(this) || this;
    }
    /**
    * 创建敌军
    */
    Enemyplane.prototype.init = function (x, y) {
        var enmyplanlist = ["GodPlane_png", "GreenPlane_png", "JitPlane_png"];
        var planeIndex = Math.floor(Math.random() * enmyplanlist.length);
        var plane = new Plane();
        var planeImage = new egret.Bitmap(RES.getRes(enmyplanlist[planeIndex]));
        plane.blood = 100;
        plane.bulletImage = "bullet_02_png";
        plane.Image = planeImage;
        plane.Image.rotation = 180;
        plane.Image.x = x + 128;
        plane.Image.y = y + 128;
        plane.X = plane.Image.x;
        plane.Y = plane.Image.y;
        plane.Type = "Donw";
        plane.lives = 3;
        return plane;
    };
    return Enemyplane;
}(egret.DisplayObjectContainer));
__reflect(Enemyplane.prototype, "Enemyplane");
;window.Main = Main;