import Sprite3D = Laya.Sprite3D;
import Transform3D = Laya.Transform3D;
import GameDefined from "./GameDefined";
import { GameController } from "./GameController";
import Vector3 = Laya.Vector3;
export class Player extends Laya.Script3D {

    constructor() {
        super();
    }

    private self: Sprite3D;
    private _tran: Transform3D;
    public _speed = Vector3._ZERO.clone();
    onAwake() {
        this.self = this.owner as Sprite3D;
        this._tran = this.self.transform;
        this.SetSpeed();
    }


    onUpdate() {
        if (GameController.Instance.gamestart) {
            this._tran.localPositionZ += this._speed.y;
            this._tran.localPositionX += this._speed.x;
            if (this._tran.localPositionX >= 5) this._tran.localPositionX = 5;
            if (this._tran.localPositionX <= -5) this._tran.localPositionX = -5;
        }
    }
    SetSpeed(_Y?, _X?) {
        if (!_Y) {
            this._speed.y = GameDefined.moveSpeed;
        }
        else {
            this._speed.y = GameDefined.moveSpeed + _Y;
        };

        if (!_X) {
            this._speed.x = 0;
        } else {
            this._speed.x = _X;
        }
    }

}
