cocos移动与碰撞

@ccclass('pengzhung')

export class pengzhung extends Component {

    private iPause: boolean=false;

    private isPause: boolean=false;

    @property(Node)

    end:Node = null

    start() {

 

        let collider = this.node.getComponent(CapsuleCollider);

        collider.on("onTriggerEnter",this.pengzhuang,this);

    }

 

    pengzhuang(event:ITriggerEvent){

        if 

        (event.otherCollider.node.name == "zhangai")

        {

            this.iPause=true;

            if (this.iPause=true) {

                this.end.active = true

            }

            console.log("游戏结束");

            }

        else (event.otherCollider.node.name == "shitou")

        {

        this.isPause=true;

        if (this.isPause=true) {

            this.end.active = true

        }

        console.log("游戏结束");

        }

        

    }

 

    update(deltaTime: number) {

        

    }

}

 

 

@ccclass('player')

export class player extends Component {

    private xx:number = 0

    private yy:number = 0

    private zz:number = 0

    

    

    start() {

    input.on(Input.EventType.KEY_DOWN,this.jump,this);

    }

 

 

 

    update(deltaTime: number) {

        this.yy = this.node.position.y

        this.zz = this.node.position.z

        this.xx = this.node.position.x;

        //this.xx = this.node.position.x;

        this.xx -= deltaTime+0.02;

        this.node.setPosition(this.xx,this.yy,this.zz)

        

    }

 

    

 

    jump(event:EventKeyboard){

        

        

        switch(event.keyCode){

            case KeyCode.KEY_W:

                this.up()

                break;

            case KeyCode.KEY_A:

                //让玩家向左移动一定的单位长度

                this.left()

                break;

            case KeyCode.KEY_D:

                //让玩家向右移动一定的单位长度

                this.right()

                break;

        }

    }

up(){

    this.node.getComponent(Animation).play("animation")

}

left(){

    this.node.getComponent(Animation).play("animation1")

}

right(){

    this.node.getComponent(Animation).play("animation2")

}

 

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值