import  yaogan from "./yaogan";
cc.Class({
    extends: cc.Component,

    properties: {
        speed:200,
        yaogan:yaogan,
        body:null,
        camera:cc.Node,
        offset:cc.v2(0,0),
        PhysicsCircle:null,
    },


    onLoad () {
        this.body=this.node.getComponent(cc.RigidBody);
        this.PhysicsCircle=this.node.getComponent(cc.PhysicsCircleCollider);
        //1122sswwdsaasd
        //console.log(this.PhysicsCircle)
    },

    start () {
        if (this.camera!=null){
            this.offset=this.camera.getPosition().sub(this.node.getPosition());
        }

    },

    update (dt) {
        //
        if (this.yaogan!==null){
            if (this.yaogan.dir.x===0&&this.yaogan.dir.y===0) {
                this.body.linearVelocity=cc.v2(0,0);
                // this.PhysicsCircle=cc.v2(0,0)
                // this.PhysicsCircle.apply()
                return;
            }
            // if (this.yaogan.dir.mag()<0.5){
            //     return;
            // }
            let vx=this.speed*this.yaogan.dir.x;
            let vy=this.speed*this.yaogan.dir.y;
            this.body.linearVelocity=cc.v2(vx,vy)
            // this.PhysicsCircle=cc.v2(vx,vy)
            // this.PhysicsCircle.apply()
            let r=Math.atan2(this.yaogan.dir.y,this.yaogan.dir.x);
            let degree=r*180/(Math.PI);
            //rotation 逆时针kk
            this.node.angle=degree-90

            // rotation 顺时针
            // degree=360-degree;
            // degree=degree+90;
            // this.node.rotation=degree;
        }



        //摄像机位置
        if (this.camera!==null){
            this.camera.x=this.node.x+this.offset.x;
            this.camera.y=this.node.y+this.offset.y;
        }

    },
});

























































































































