猫史档案馆


【代码】猛鬼宿舍房间快速生成

用户:星星上的雪花星星上的雪花查看:949 回复:9 评论:15 创建时间:2022-04-09T23:57:21


const h = 5; // 房间的高度
const sample = //房间的地形,可自定义更改
`\
墙墙墙墙墙墙墙墙墙墙墙墙墙墙
墙空空空空空空空空空空空空墙
墙空空空空空空空空空空空空墙
墙空空空空空空空空空墙墙墙墙
墙空空空空空空空空空门
墙空空空空空空空空空门
墙空空空空空空空空空墙墙墙墙
墙空空空空空空空空空空空空墙 
墙空空空空空空空空空空空空墙 
墙墙墙墙墙墙墙墙墙墙墙墙墙墙`;
const room = [];
const v = (x=0, y=0, z=0) => new Box3Vector3(x,y,z);
for(let index = 0; index < sample.split("\n").length; index ++)
{
    const part = sample.split("\n")[index];
    const build = [];
    const high = 8;
    for(const block of part)
    {
        if(block === "墙")
            build.push([
                "powder_blue",
                v(index,high,build.length)
            ])
        if(block === "空")
            build.push([
                "ice_brick",
                v(index,high,build.length)
            ])
        if(block === "门")
            build.push([
                "wood",
                v(index,high,build.length)
            ])
    };
    room.push(build)
};
for(let x = 0; x < 255; x += 20)
for(let y = 0; y <= h; y ++)
for(let z = 0; z < 255; z += 20)
{
    for(const a of room)
    {
        for(const b of a)
        {
            voxels.setVoxel(b[1].x+x,b[1].y+y,b[1].z+z,b[0])
        }
    }
};


回复

上一页第 1 页 / 共 1 页下一页
星星上的雪花星星上的雪花

生成空心房间

{
    const h = 5; // 房间的高度
    const sample = //房间的地形,可自定义更改
    `\
    墙墙墙墙墙墙墙墙墙墙墙墙墙墙
    墙空空空空空空空空空空空空墙
    墙空空空空空空空空空空空空墙
    墙空空空空空空空空空墙墙墙墙
    墙空空空空空空空空空门
    墙空空空空空空空空空门
    墙空空空空空空空空空墙墙墙墙
    墙空空空空空空空空空空空空墙 
    墙空空空空空空空空空空空空墙 
    墙墙墙墙墙墙墙墙墙墙墙墙墙墙`;
    const room = [];
    const v = (x=0, y=0, z=0) => new Box3Vector3(x,y,z);
    for(let index = 0; index < sample.split("\n").length; index ++)
    {
        const part = sample.split("\n")[index];
        const build = [];
        const high = 8;
        for(const block of part)
        {
            if(block === "墙")
                build.push([
                    "powder_blue",
                    v(index,high,build.length)
                ])
            if(block === "空")
                build.push([
                    "air",
                    v(index,high,build.length)
                ])
            if(block === "门")
                build.push([
                    "wood",
                    v(index,high,build.length)
                ])
        };
        room.push(build)
    };
    for(let x = 0; x < 255; x += 20)
    for(let y = 1; y <= h; y ++)
    for(let z = 0; z < 255; z += 20)
    {
        for(const a of room)
        {
            for(const b of a)
            {
                voxels.setVoxel(b[1].x+x,b[1].y+y,b[1].z+z,b[0])
            }
        }
    };
}

点赞0


评论

速建代码有吗,这个会报错

先把代码复制到代码区里,点开始运行,然后马上点结束运行(用来保存代码),然后往控制台输“require("/文件名.js")”,如果放主文件里就是/index.js(建议除了速建代码以外不要放其它代码)

谢谢!!!!啦!!!


NinesirNinesir

猛鬼宿舍好像变成天上地下80座塔了

点赞0


评论


灵清帝王吃爆一切厕所灵清帝王吃爆一切厕所

收藏()

点赞0


评论


该账号已被封禁该账号已被封禁

这也不难啊...

点赞0


评论

不就记录坐标然后后面跟速建差不多吗...

这里的核心技术是将文本转化为方块数据(比如说你可以用做个来做个Bad Apple)

(?)

阿这 这玩意不就是简单的if判断么...

你也可以在前面写一个对象 keys写自定义id value写方块名称到时候直接调用也彳亍


该账号已被封禁该账号已被封禁

其实完全可以这样

let id={
    '墙':'powder_blue',
    '空':'air',
    '门':'wood'
};
......
build.push([id[block],{x:index,y:high,z:build.length}]);

点赞0


评论

自己看 方便很多 不用写那么多if 你要实在想写就写switch简洁明了


梁桂琪梁桂琪

https://box3.codemao.cn/e/8c1df9d14aa3be73b026

点赞0


评论


学霸霸题学霸霸题

奇怪的知识增加了

点赞0


评论


alopdopsalopdops

dzd

 

点赞0


评论

bcc

在那

你是谁

我不会写代码555

不会计时

所以呢


不爱做跑酷不爱做跑酷

你是不是’借‘了战术兵团的地图代码?

emotion_编程猫_翻白眼

点赞0


评论