猫史档案馆


【box3】乒乓球代码

用户:YDS尹子YDS尹子查看:4 回复:17 评论:4 创建时间:2021-08-11T19:52:21


center_image

给乒乓球桌加一个pingpongdesk标签,给球加上pingpongball标签,给球网加上wang标签,应该就能用了

world.onPlayerJoin(({entity})=>{
    entity.enableDamage=true;
    entity.pressed=false;
    entity.pressedTime=0;
    entity.player.playingPingPong=true;
    entity.player.dialog({
        type:Box3DialogType.TEXT,
        title:"乒乓球-测试版",
        content:`不需要瞄准球,在球附近朝要打的方向长按左键蓄力,松开发射`
    })
})

function setInter(query, id, rad, interact, func) {
    world.querySelectorAll(query).forEach((e) => {
        e.enableInteract = true;
        e.interactRadius = rad;
        e.interactHint = id;
        e.interactColor.set(1,0.3,0.3)
        e.interactColor.set(1, 1, 1);
        if (interact) {
            e.onInteract(({ entity, targetEntity }) => {
                func(entity, targetEntity);
            })
        }
    })
}
setInter(".pingpongdesk","打乒乓球",30,true,async function(entity,targetEntity){
    entity.player.playingPingPong=true;
    world.querySelectorAll(".pingpongball").forEach((e)=>{
        e.gravity=true;
        e.collides=true;
        e.fixed=false;
    })

})

world.querySelector(".pingpongball").maxHeight=0;
world.querySelector(".pingpongball").friction=0;
world.onPress(({entity,button})=>{
    if(button=='action0'){
    entity.pressed=true;
    entity.pressedTime=world.currentTick;
    entity.player.canFly=true;
    }
})
world.onTick(()=>{
    var s=world.querySelector(".pingpongball");
    if(s.position.y>s.maxHeight)s.maxHeight=s.position.y;
    if(s.position.y<=0){
        world.say("球出界了,重置完毕")
        s.position.set(92.8,23.1,110.5)
        s.velocity.set(0,0,0)
        s.maxHeight=23;
    }
})
world.onRelease(({entity,raycast:{direction},button})=>{
    if(button=='action0'&&entity.player.playingPingPong){
        if(true){
        var force=world.currentTick-entity.pressedTime;
        if(force>10)force=10;
        world.querySelectorAll(".pingpongball").forEach((e)=>{
            if(e.position.distance(entity.position)<20){
                e.say(force);
                var k=4;
                e.velocity.x=direction.x*force/k;
                e.velocity.y+=direction.y*force/k*3;
                e.velocity.z=direction.z*force/k;
            }
        })
        }
    }
})

world.onEntityContact(({entity,other,force})=>{
    if(entity.hasTag("pingpongball")&&other.hasTag("pingpongdesk")){
        entity.velocity.y+=entity.maxHeight/28;
    }else if(entity.hasTag("pingpongball")&&other.hasTag("wang")){
        world.say("球下网了,重置完毕")
        entity.position.set(92.8,23.1,110.5);
        entity.velocity.set(0,0,0)
        entity.maxHeight=23;
    }
})
world.onVoxelContact(({voxel,entity})=>{
    if(entity.hasTag("pingpongball")){
        world.say("球出界了,重置完毕")
        entity.position.set(92.8,23.1,110.5);
        entity.velocity.set(0,0,0)
        entity.maxHeight=23;
    }
})


回复

上一页1 页 / 共 1下一页
IaeaIaea

沙发

点赞1


评论


未命名用户015734未命名用户015734

尹子yyds!!!

点赞1


评论


阳光的流熔怪Uyt5阳光的流熔怪Uyt5

尹子yyds!!!

点赞0


评论


Architect_皮卡awaArchitect_皮卡awa

emotion_编程猫_厉害了

点赞1


评论


指令者指令者

尹子yyds!!!

点赞0


评论


想不出来叫什么想不出来叫什么

尹子yyds

点赞0


评论


星星上的雪花星星上的雪花

尹子yyds!!!

话说岛三不举办O运会的创作节喵?(小声)

点赞0


评论


JYF_斗罗JYF_斗罗

牛~

点赞0


评论


冰糖葫芦_冰糖葫芦_

收藏

点赞0


评论


该账号已停用该账号已停用

emotion_编程猫_厉害了

点赞0


评论


憨白不憨awa憨白不憨awa

yyds()

点赞0


评论


传闻中的五音璃音传闻中的五音璃音

尹子yyds!!!

点赞0


评论


蓝冰_E蓝冰_E

尹子yyds!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 

点赞0


评论


小树同学小树同学

帮我建个图好不好?https://box3.fun/e/d7f836f5a4c1ccfb5e5f

点赞0


评论


Weeb_ETOWeeb_ETO

666

点赞0


评论


代码追星人代码追星人

尹子,抛物线怎么写,比如投篮

点赞0


评论


夜影行者夜影行者

收藏

点赞0


评论