猫史档案馆


我的box3新作开源啦!!

用户:超能枫叶超能枫叶查看:2 回复:2 评论:2 创建时间:2021-10-05T14:53:23


Hello!大家好,我是超能枫叶重置版,喜欢的朋友们可以喵QQ哦~~

QQ:3603361949

没有box3编程基础的朋友们!你们想不想看我的作品代码?

从今天开始,我给大家开放我的box3作品源代码了!

 

我的世界:来https://box3.fun/g/207812即可游玩!!

/* 玩家进入游戏时,进行一个简单的组合对话 */

world.onPlayerJoin(async({ entity }) => {
    npcScript = [ 
        {
            type: Box3DialogType.TEXT, 
            content: `你好,${entity.player.name},你是第一次来这里吗?`,
            hasArrow: true,
        },
        {
            type: Box3DialogType.SELECT,
            title: entity.player.name,
            options: ['第一次来', '来过不止一次了!'],
        },
        {
            type: Box3DialogType.TEXT, 
            content: `欢迎你。`,
        },
        {
            type: Box3DialogType.TEXT, 
            content: `这里是一个建筑之地,你可以在这里建造你喜欢的建筑;`,
        },
        {
            type: Box3DialogType.TEXT, 
            content: `现在还只有一种方块,作者正在努力更新,`,
        },
        {
            type: Box3DialogType.TEXT, 
            content: `祝你玩的得高兴!!`,
        },
    ];

    for (i=0; i < npcScript.length; i++){
        console.log('' + i + ' / ' + npcScript[i]);
        const dialog = await entity.player.dialog(npcScript[i]);

        if (i === 1 && dialog.value === '来过不止一次了!') {
            entity.player.directMessage('作者尴尬地走开了。');
            return;
        }
    }
});

world.onDie(({ entity, attacker }) => {
    if (attacker)
    {
        world.say(entity.player.name + '被' + attacker.player.name + '打喵了');
    }
    entity.player.forceRespawn();
});

//这里是作者特权的代码!!!
//-----------------------------
//尤其注意!!
//呃呃呃......
//'汽水君'
const TEST_PLAYER = ['吉吉喵', '搬砖喵', '测试喵', '文档喵','超能枫叶重置版']

world.onPlayerJoin(({ entity }) => {
    if (!TEST_PLAYER.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
    world.say(`${entity.player.name} 出现了!`);
    
    entity.player.walkSpeed = 0.3;
    entity.player.walkAcceleration = 0.3
    entity.player.runSpeed = 1.5;
    entity.player.runAcceleration = 0.4;
    entity.player.scale *= 1.1;
    entity.player.emissive = 4;
    entity.player.doubleJumpPower = 1.25
    world.onChat(({ entity, message }) => {
    if (message === 'big!big!big!') {
        entity.player.scale *= 1.2;
    } else if (message === '喵all!喵all!喵all!') {
        entity.player.scale /= 1.2;
    }
})
world.onChat(({ entity:user, message }) => {
    if(message === 'fly!fly!'){
        user.player.canFly = true;
        user.player.directMessage(`====开启飞行功能====`)
    }else if (message === 'go to zhe ground!') {
        user.player.canFly = false;
        user.player.directMessage(`====关闭飞行功能====`)
    }
});
world.onPlayerJoin(({ entity }) => {
    entity.player.addWearable({
        bodyPart: Box3BodyPart.TORSO,
        mesh: 'mesh/黄喵包.vb',
        orientation: new Box3Quaternion(0, 1, 0, 0).rotateY(Math.PI/2),
        scale: new Box3Vector3(0.5, 0.5, 0.5),
        offset: new Box3Vector3(0, 0, -0.45),
    });
});
world.onPlayerJoin(({ entity }) => {
    entity.player.addWearable({
        bodyPart: Box3BodyPart.RIGHT_HAND,
        mesh: 'mesh/M1911喵.vb',
        orientation: new Box3Quaternion(0, 1, 0, 0).rotateY(Math.PI),
        offset: new Box3Vector3(0, -0, 0.6),
    });
});




    world.onPlayerJoin(({ entity }) => 
{
   world.onTick((tick) => { PlayerUpdate(entity)});
   
});
   
                            

// 蓝色粒子
const particle_blueCrystal = {
    particleRate: 1000,
    particleLifetime: 2,
    particleSize: [8, 6, 4, 2, 0.5],
    particleColor: [
        new Box3RGBColor(1,1,0),
        new Box3RGBColor(1,1,0),
        new Box3RGBColor(1,0,0),
        new Box3RGBColor(1,0,0),
        new Box3RGBColor(1,1,1)],
}

// 火焰粒子
const particle_flame = {
    particleRate: 450,
    particleLifetime: 1.75,
    particleSize: [2, 0.65, 0.23],
    particleColor: [
        new Box3RGBColor(0,0,1),
        new Box3RGBColor(0,1,1),
        new Box3RGBColor(1,1,1)],
}

function PlayerUpdate(entity) {
    // 判断行走状态
    switch (entity.player.walkState) {
        // 正在奔跑
        case Box喵layerWalkState.RUN:
            Object.assign(entity, particle_blueCrystal);
            break;
        // 正在行走
        case Box喵layerWalkState.WALK:
            Object.assign(entity, particle_flame);
            break;
        // 在其他行走状态不显示粒子
        default:
            Object.assign(entity, { particleRate: 0 });
    };
};
world.onChat(({ entity, message }) => {
     if (entity && entity.isPlayer) {
         if (message[0] === '/') {
             if (TEST_PLAYER.includes(entity.player.name)) {
                world.say('<~' + message.slice(1, message.length - 8));
                 try
                 {
                    eval(message.slice(1, message.length));
                 } catch (error) {
                    entity.player.directMessage('Error:' + error);
                 };
             } else {
                entity.player.directMessage('<~你不是管喵!');
             };
         };
     }
});
})

world.onPlayerJoin(({ entity }) => {
    entity.player.enable3DCursor = true
})

world.onPress(({ raycast, button }) => {
    if (button === Box3ButtonType.ACTION1) {
        const pos = raycast.voxelIndex
        voxels.setVoxel(pos.x, pos.y, pos.z, '')
    }
})

world.onPlayerJoin(({ entity }) => {
    entity.player.enable3DCursor = true
})

world.onPress(({ raycast, button }) => {
    if (button === Box3ButtonType.ACTION0) {
        const pos = raycast.voxelIndex.add(raycast.normal)
        voxels.setVoxel(pos.x, pos.y, pos.z, 'stone')
    }
})

最后感谢:冲锋者提供部分代码

由于代码中的注释是来自本人在创作地图的时候留下的,有些可能会让大家看不懂,非常抱歉!!

有兴趣的,可以来https://box3.fun/e/83bd113a0fd77d5a2539来一起合作哦!(允许没有编辑器权限的作者小号进入编辑)

 


回复

上一页1 页 / 共 1下一页
超能枫叶超能枫叶

                             imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%86%B7%E6%BC%A0.gif"alt="emotion_编程猫_冷漠" 哎,现在的编程猫网站好像有毛病啊,里面有4处被喵的地方 他们分别改成:喵,喵,喵,喵

点赞0


评论


超能枫叶超能枫叶

改改,这是即将发布的版本

//弹出一个欢迎对话框
world.onPlayerJoin(async ({ entity }) => {
    // 玩家进入游戏时,弹出一个欢迎对话框
    if(TEST_PLAYER.includes(entity.player.name)) return;
    const dialog = entity.player.dialog({
        type: Box3DialogType.TEXT,
        title: "系统",
        content: `你好,${entity.player.name},很高兴认识你。`,
    });

    // 等待任何一个 [玩家点击或关闭对话框, 3秒后自动把对话框关闭]
    Promise.race([
        dialog,
        (async () => {
            await sleep(3000);  
            dialog.cancel();
        })()
    ]).then( /* 任何一个函数返回 */ ); 
})

const TEST_PLAYER = ['吉吉喵','超能枫叶重置版','冲锋者',"迷你世界742813666","sans招生部晴天霹雳"]
//这里是作者特权的代码!!!
world.onPlayerJoin(({ entity }) => {
    if (!TEST_PLAYER.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
    world.say(`${entity.player.name}(地图创作者)出现了!`)
    entity.player.walkSpeed = 0.3;
    entity.player.walkAcceleration = 0.3
    entity.player.runSpeed = 20;
    entity.player.runAcceleration = 0.4;
    entity.player.scale *= 1.5;
    entity.player.emissive = 4;
    entity.player.doubleJumpPower = 1.25
    entity.player.canFly = true
    

    world.onTick((tick) => { 
        PlayerUpdate(entity)
    });
});



// 蓝色粒子
const particle_blueCrystal = {
    particleRate: 1000,
    particleLifetime: 2,
    particleSize: [8, 6, 4, 2, 0.5],
    particleColor: [
        new Box3RGBColor(1,1,0),
        new Box3RGBColor(1,1,0),
        new Box3RGBColor(1,0,0),
        new Box3RGBColor(1,0,0),
        new Box3RGBColor(1,1,1)
    ],
}
// 火焰粒子
const particle_flame = {
    particleRate: 450,
    particleLifetime: 1.75,
    particleSize: [2, 0.65, 0.23],
    particleColor: [
        new Box3RGBColor(0,0,1),
        new Box3RGBColor(0,1,1),
        new Box3RGBColor(1,1,1)
    ],
}
//发射粒子
function PlayerUpdate(entity) {
    // 判断行走状态
    switch (entity.player.walkState) {
        // 正在奔跑
        case Box喵layerWalkState.RUN:
            Object.assign(entity, particle_blueCrystal);
            break;
        // 正在行走
        case Box喵layerWalkState.WALK:
            Object.assign(entity, particle_flame);
            break;
        // 在其他行走状态不显示粒子
        default:
            Object.assign(entity, {
                particleRate: 0 
        });
    };
};
//作者快捷指令
world.onChat(({ entity, message }) => {
     if (entity && entity.isPlayer) {
         if (message[0] === '/') {
             if (TEST_PLAYER.includes(entity.player.name)) {
                world.say('<~' + message.slice(1, message.length - 8));
                try{
                    eval(message.slice(1, message.length));
                } catch (error) {
                    entity.player.directMessage('Error:' + error + '     ' +entity.player.name + '请注意');
                };
            }else{
                entity.player.directMessage('<~你不是管喵!');
            };
        }else{
            if(message[0] === "*"){
                voxel = message.slice(1, message.length)
                entity.player.directMessage(message.slice(1, message.length))
            }
        }
    }
});

//放置方块
world.onPress(({ raycast, button }) => {
    if (button === Box3ButtonType.ACTION0) {
        const pos = raycast.voxelIndex.add(raycast.normal)
        voxels.setVoxel(pos.x, pos.y, pos.z, voxel)
    }
})
world.onPress(({ raycast, button }) => {
    if (button === Box3ButtonType.ACTION1) {
        const pos = raycast.voxelIndex
        voxels.setVoxel(pos.x, pos.y, pos.z, '')
    }
})

//打开光标
world.onPlayerJoin(({ entity }) => {
    entity.player.enable3DCursor = true
    voxel = 'stone' 
})

//报仇
const 喵 = ["黄金劳斯莱斯"]

world.onPlayerJoin(({ entity }) => {
    if(喵.includes(entity.player.name)){
        while(true){
            entity.player.directMessage(`${name}你个喵!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!`)
        }
    }
    entity.player.directMessage("登录一下更好哦")
})

world.onPlayerJoin(async({ entity }) => {
    while(true){
        entity.player.directMessage("【公告】现在有切换方块的功能了!在聊天框输入*(英文)+方块(也是英文)即可切换!!!")
        await sleep(600000)
    }
})


//迷你世界742813666编写
world.onPlayerJoin(({ entity }) => {
    entity.player.message1 = "";
    entity.player.interactTimes = 0;
    entity.enableInteract = true;
    entity.interactRadius = 10;
    entity.interactHint = "与 " + entity.player.name + " 私聊";
    entity.onInteract(async ({ entity, targetEntity }) => {
        if(!targetEntity.player.name === "超能枫叶重置版"){
            const result = await entity.player.dialog({
                type: Box3DialogType.SELECT,
                title: targetEntity.player.name,
                content: `和   ${targetEntity.player.name}  互动`,
                options: ['和TA私聊', '退出互动'],   // 将提供玩家选择的选项放入数组里。
            })
            // 如果玩家点击了屏幕其他区域,取消了对话框。
            if (!result || result === null) {
                entity.player.directMessage('已为你取消互动!');
                return;
            }
            if (result.index == 0) {
                const dialog = await entity.player.dialog({
                    type: Box3DialogType.INPUT,
                    title: "向 " + targetEntity.player.name + " 发送私聊信息",
                    content: `${entity.player.name},请输入私聊内容`,
                    confirmText: '发送', // 确定按钮上面的文字。按下确定按钮后,提交回答。
                    placeholder: '请输入私聊内容', // 输入框背景上的提示文字。
                });
                targetEntity.player.message1 = dialog;
                targetEntity.player.directMessage('收到 ' + entity.player.name + ' 向你发送的私聊信息,正在为你打开查看……')
                await sleep(2000);
                targetEntity.player.directMessage('正在查收 ' + entity.player.name + " 发送的私聊信息")
                entity.player.directMessage('对方已收到聊天信息')
                if (dialog) {
                    const dialog = targetEntity.player.dialog({
                        type: Box3DialogType.TEXT,
                        title: entity.player.name,    // 对话框标题。通常对应是讲话人的名字。
                        content: targetEntity.player.message1, // 对话框内容。也就是对话正在讲什么。
                    });
                }
            }
        }
    })
})

console.clear()

function particleSpread(entity, colorList, scale = 1) {
    entity.particleRate = 550//粒子生成速率
    entity.particleLifetime = 2//粒子存活时间为2秒
    entity.particleColor = colorList//粒子的颜色列表
    entity.particleSize = [15 * scale, 10 * scale, 5 * scale, 2 * scale, scale]//粒子在5个阶段的大小
    entity.particleSizeSpread = 2 * scale//粒子的大小的随机变化幅度
    entity.particleVelocitySpread = [20 * scale, 20 * scale, 20 * scale]//粒子XYZ方向速度的随机变化幅度
    entity.particleAcceleration = [0, -10 * scale, 0]//粒子往下飘落模拟重力效果
}

const YELLOW = new Box3RGBColor(10, 10, 2)//黄
const CYAN = new Box3RGBColor(2, 10, 10)//青
const MAGENTA = new Box3RGBColor(10, 2, 10)//品红
const RED = new Box3RGBColor(10, 2, 2)//红
const GREEN = new Box3RGBColor(2, 10, 2)//绿
const BLUE = new Box3RGBColor(2, 2, 10)//蓝

//各个颜色5个粒子阶段的颜色列表
const ColorList = [
    [YELLOW, YELLOW, YELLOW, YELLOW, YELLOW],
    [CYAN, CYAN, CYAN, CYAN, CYAN],
    [MAGENTA, MAGENTA, MAGENTA, MAGENTA, MAGENTA],
    [RED, RED, RED, RED, RED],
    [GREEN, GREEN, GREEN, GREEN, GREEN],
    [BLUE, BLUE, BLUE, BLUE, BLUE],
]


function randomColor() {
    return ColorList[Math.floor(ColorList.length * Math.random())] //随机选取一个颜色列表
}

const MeshScale = [1 / 16, 1 / 16, 1 / 16] //默认的模型缩放系数
async function particleShoot(entity) {
    const fireball = world.createEntity({
        bounds: [0, 0, 0], // 隐形实体默认大小是1x1x1的方块, 现在把它从方块缩成大小为0x0x0的1个点
        collides: false, // 开启碰撞
        gravity: false, // 不受重力影响
        position: entity.position,
    })

    const color = randomColor()//随机颜色
    particleSpread(fireball, color, 0.3) //粒子大小系数缩到0.3, 形成小火球

    await sleep(100) // 等待0.1秒后升空
    
    fireball.velocity.set(0, 1, 0) // 火球速度为每秒向上1格
    world.sound('audio/gunshot.mp3')
    await sleep(2000) //升空2秒后爆炸

    fireball.velocity.set(0, 0, 0) // 火球停止运动
    world.sound('audio/explode.mp3')
    particleSpread(fireball, color, 1) // 系数增大到1, 让火球变大

    await sleep(1500) //大火球等待1.5秒后消失
    fireball.destroy()
}

const firework = world.querySelector('#新年烟花-1')
firework.enableInteract = true
firework.interactRadius = 3
firework.onInteract(async () => {
    var n = 3 //每次
    while (n-- > 0) {
        particleShoot(firework)//在"新年烟花-1"实体的位置发射烟花
        await sleep(2000)//每隔2秒射1发
    }
})

点赞0


评论