猫史档案馆


跑酷代码【部分代码来自其他人】

用户:云游de军长渡云游de军长渡查看:1 回复:6 评论:1 创建时间:2022-08-25T11:25:18


众所周知,一个不错的跑酷,都少不了存档点。一下是存档点代码:

//方块存档:
world.onVoxelContact(({ entity, voxel }) => {
    if (voxel == voxels.id('green_light')) {//存档的方块是 green_light
        entity.player.spawnPoint.copy(entity.position)
        entity.player.directMessage('存档成功')
    }
})

不会代码的做跑酷,发布出来的效果让人崩溃,因为无法关闭碰撞,极度影响玩家体验。这是关闭碰撞代码:

world.addCollisionFilter('player', 'player');//很简单对不对

如果想要一起跑酷的那种计时的跑酷,这是计时跑酷

console.clear()
class Box3Timed {
    constructor() {
        (async () => {
            this.time = 0;
            this.over = false;
            while (!this.over) {
                await sleep(1);
                this.time += 1;
            }
        })()
    }
    stop() {
        return this.over = true
    }
    getTime() {
        return this.time
    }
}
//让玩家知道自己进入地图多久了
world.onPlayerJoin(({ entity }) => {
    entity.timer = new Box3Timed()
});

//获取进入多久的时间
world.onChat(({ entity, message }) => {
    if (message !== "获取时间") return;
    world.say("你已进入地图:" + entity.timer.get() / 1000 + "秒");//如果要化成秒就除以1000
});
//停止计时
world.onPlayerLeave(async ({ entity }) => {
    entity.timer.stop()
});
world.onVoxelContact(async ({ entity, voxel }) => {
    // 将方块id转换名称
    const voxelName = voxels.name(voxel)
    // 如果方块名称是carpet_08
    if (voxelName === 'carpet_08') {
        entity.player.directMessage('恭喜你跑完全程')
        world.say(`恭喜${entity.player.name}跑完全程!用时${entity.timer.getTime() / 1000}秒`)
        entity.timer.stop()
    }
});
//改编自贡菊的代码

如果想要输入密码然后传送的代码:、

// 先在场景中放置一个名称为 阿塔 的实体。
const npc = world.querySelector('#阿塔');
npc.enableInteract = true; // 允许进行互动
npc.interactRadius = 16;   // 实体的互动范围
npc.interactHint = npc.id; // 互动提示框显示实体的名称
npc.interactColor = new Box3RGBColor(1,1,1);  // 互动提示的文字颜色
npc.onInteract(async({entity}) => {
    const result = await entity.player.dialog({
        type: Box3DialogType.INPUT,
        title: '阿塔',
        titleTextColor: new Box3RGBAColor(1, 1, 1, 1),
        titleBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
        content: `${entity.player.name},密码是什么?`,
        confirmText: '确定', // 确定按钮上面的文字。按下确定按钮后,提交回答。
        placeholder: '注意观察。', // 输入框背景上的提示文字。
        contentTextColor:  new Box3RGBAColor(1, 1, 1, 1),
        contentBackgroundColor: new Box3RGBAColor(0, 0, 0, 0.98),
        lookEye: entity.position.add(entity.player.facingDirection.scale(5)),
        lookTarget: entity,
    });

    // 如果玩家点击了屏幕其他区域,取消了对话框。
    if(!result || result === null){ 
        entity.player.directMessage('注意观察');
        return; 
    }

    const surprise = ['243112']

    if(surprise.includes(result)){
        entity.player.directMessage(`回答正确` );
        entity.position.set(133,10,183)
    }

});

玩家跑完全程,就让他可以飞行

world.onVoxelContact(({ entity, voxel }) => {
    if (voxel == voxels.id('carpet_08')) {//方块名称自己填入
        entity.player.canFly = true
    }
});


回复

上一页1 页 / 共 1下一页
咖喱盖饭澄妍咖喱盖饭澄妍

nb

点赞0


评论


yee剑走天下yee剑走天下

复制别人的代码好玩吧?()

点赞1


评论


虚无之空虚无之空

awa。。。。

点赞1


评论


善良的剑仙善良的剑仙

怎么用模型来存档

点赞0


评论


屑怪盗屑怪盗

DDD

点赞0


评论


源码极客源码极客

众所不知,场景栏目的物理子栏目里有关于碰撞过滤的功能,可以在那里面设置

点赞0


评论