// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Prefab)
    protonSM: cc.Prefab = null;
    @property(cc.Prefab)
    protonMD: cc.Prefab = null;
    @property(cc.Prefab)
    protonLG: cc.Prefab = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    spawnProtons() {
        var protons = [this.protonSM, this.protonMD, this.protonLG, this.protonMD, this.protonSM, this.protonSM];
        var proton = cc.instantiate(protons[Math.floor(Math.random() * protons.length)]);
        const protonX = Math.random() * this.node.getContentSize().width - this.node.getContentSize().width / 2;
        const protonY = this.node.getContentSize().height;
        proton.setPosition(protonX, protonY);
        proton.zIndex = -1;
        this.node.addChild(proton);
    }

    start () {
        this.schedule(this.spawnProtons, 0.1, cc.macro.REPEAT_FOREVER, 0);
    }

    // update (dt) {}
}
