FlappyBird笔记(三)

承接上文

block移动以及小鸟添加

block
创建block脚本并挂载到block预制体上

  runBlock() {
        let speed: number = 2;
        this.node.x -= speed;
    }
    update(dt) {
        this.runBlock();
    }

创建一个新的node放上替换小鸟图片,并创建一个hero脚本挂载到上面

 //初始化小鸟
    initHero() {
        this.node.angle = 0;
        this.node.position = cc.v2(-120, 100);
    }
    initPlayTouch() {
        this.time = 0;
        this.fail = false;
    }
    endPlayTouch() {
        this.fail = true;
    }
    setRotation(type) {
        this.node.stopActionByTag(1);
        if (type == 'up') {
            this.node.angle = 20;
        } else if (type == 'down') {
            let act_1 = cc.rotateTo(0.5, -90);
            act_1.setTag(1);//设置tag标记动作
            this.node.runAction(act_1);
        }
    }

管道、地面和小鸟的碰撞

首先对block以及小鸟添加碰撞组件并分组,其次编写相应方法

 onCollisionEnter(other: cc.BoxCollider, self: cc.BoxCollider) {
        if (GameType.getInstance().getType() == 3) return
        if (other.node.group == 'block') {
            GameType.getInstance().setType(3);
            cc.audioEngine.play(this.hit, false, 1); 
            cc.audioEngine.play(this.swoosh, false, 1);
            cc.audioEngine.play(this.die, false, 1);
            let act_1 = cc.delayTime(0.2);
            let act_2 = cc.moveTo(1, cc.v2(this.node.x, -cc.winSize.height / 2 + 160));
            let end = cc.sequence(act_1, act_2);
            self.node.runAction(end);
            this.scheduleOnce(() => {
                self.node.parent.getComponent('Game').toGameOver();
            }, 1);
        }
        if (other.node.group == 'land') {
            GameType.getInstance().setType(3);   
            cc.audioEngine.play(this.swoosh, false, 1);
            cc.audioEngine.play(this.die, false, 1);
            self.node.parent.getComponent('Game').toGameOver();
        }

    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值