猫史档案馆


【代码岛3】【教程】有限船的开船代码

用户:迷失冷光迷失冷光查看:0 回复:6 评论:0 创建时间:2020-08-10T14:41:05


话不多说,直接进入主题:

world.onPlayerLeave(({entity})=>{//当玩家离开
    if(!entity.boatEntity){return}//还原船只
    entity.boatEntity.meshInvisible = false;
    entity.boatEntity.collides = true;   
})

world.querySelectorAll('.boat').forEach((boat)=>{
    boat.onEntityContact(({entity,other})=>{
        if(other.mesh != ''){return}
        entity.meshInvisible = true;
        entity.collides = false;
        other.position.set(49,12,50);
        other.mesh = entity.mesh;
        other.meshScale = entity.meshScale;
        other.meshOrientation = new Box3Quaternion(0,1,0,0);
        other.player.invisible = true;
        other.player.enableDoubleJump = false;
        other.player.showName = false;
        other.boatEntity = entity;
        world.querySelectorAll('player').forEach((players)=>{
            if(players.player.name == other.player.name){
                players.player.directMessage('你开走了小船,靠岸即可下船');
            }else{
                players.player.directMessage(entity.player.name+'开走了小船');
            }
        })
    })
})

world.onVoxelContact(({entity,voxel})=>{
    const plank = voxels.id('plank_02');
    if(plank == voxel){
        if(!entity.boatEntity){return}
        entity.position.set(37.5,12,43);
        entity.boatEntity.meshInvisible = false;
        entity.boatEntity.collides = true;
        entity.mesh = entity;
        entity.player.enableDoubleJump = true;
        entity.player.invisible = false;
        entity.player.showName = true;
        entity.boatEntity = null;
        world.say(entity.player.name + '靠岸了');
    }
})

知识点:

对象的变量也可以为对象。


回复

上一页1 页 / 共 1下一页
迷失冷光迷失冷光

故宫开车的代码大概也知道了吧!

点赞1


评论


凌_墨水凌_墨水

我怀疑你在刷屏

点赞0


评论


学霸8号学霸8号

sofa

点赞0


评论


还是那个小橙子丫还是那个小橙子丫

imgsrc="https://static.cod喵/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


红绿j哥红绿j哥

怎么开???

点赞0


评论


风火年华4512风火年华4512

挖()

点赞0


评论