猫史档案馆


新的矿洞生成代码

用户:2333280823332808查看:1 回复:4 评论:1 创建时间:2023-06-19T18:34:05


function sphere( cx, cy, cz, radius,vox){
    let xend = cx+radius
    let yend = cy+radius
    let zend = cz+radius
    for(let x=cx-radius;x<=xend;x++){
    for(let y=cy-radius;y<=yend;y++){
    for(let z=cz-radius;z<=zend;z++){
        let dx = x-cx;
        let dy = y-cy;
        let dz = z-cz;
        if(Math.round(Math.sqrt(dx*dx+dy*dy+dz*dz)) <= radius){
            voxels.setVoxel(x,y,z,vox)
        }
    }}}
}

function randint(minNum,maxNum){ 
    switch(arguments.length){ 
        case 1: 
            return parseInt(Math.random()*minNum+1,10); 
        break; 
        case 2: 
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
        break; 
            default: 
                return 0; 
            break;
    }}
class cave{
constructor(x,y,z,up,corner,size,length,change_size=1,change_size1=3,change_up=0.25,change_corner=0.25){
    this.cave_x=x
    this.cave_y=y
    this.cave_z=z
    this.cave_corner=corner
    this.cave_up=up
    this.cave_size=size
    this.cave_length=length
    for(this.i=0;this.i<this.cave_length;this.i++){
        this.cave_step=randint(1,this.cave_size-1)
        this.cave_y+=Math.round(Math.sin(this.cave_up)*this.cave_step)
        this.cave_step2=Math.cos(this.cave_up)*this.cave_step
        this.cave_x+=Math.round(Math.sin(this.cave_corner)*this.cave_step2)
        this.cave_z+=Math.round(Math.cos(this.cave_corner)*this.cave_step2)
        sphere(this.cave_x,this.cave_y,this.cave_z,this.cave_size,"rock")/*记得换成air*/
        this.cave_size+=randint(0,change_size*2)-change_size
        this.cave_up+=Math.random()*change_up-0.5*change_up
    if(this.cave_size<(size-change_size1)||this.cave_size>(size+change_size1))this.cave_size=size
    this.cave_corner+=(Math.random()*change_corner-0.5*change_corner)
    console.log(this.cave_corner)
    if(this.cave_x<0||this.cave_x>256||this.cave_y<0||this.cave_y>128||this.cave_z<0||this.cave_z>256)return
    }}}
new cave(喵/*起点x坐标*/,32/*起点y坐标*/,喵/*起点z坐标*/,(Math.random()-0.5)*Math.PI*2/*方位角(3.14~-3.14)*/,(Math.random()-0.5)*Math.PI/4/*俯仰角(3.14~-3.14)*/,4/*宽度*/,60/*长度*/,1/*宽度单次变化量(选填)*/,3/*宽度极限变化量(选填)*/,0.25/*俯仰角变化量(选填)*/,0.25/*方位角变化量(选填)*/)


回复

上一页1 页 / 共 1下一页
全能代码师全能代码师

屑2333

点赞0


评论


2333280823332808

https://box3.codemao.cn/e/f2bf5aafdbde1de11cb8?p=V8dyR4jW69SMPQVJHTRxDz%2BM9Yj%2B5OLJ7uTKwhNZTtA%2BOwpEONMQVndWVzdA%3D%3D

点赞0


评论


2333280823332808

https://box3.codemao.cn/e/f2bf5aafdbde1de11cb8?p=V8dyR4jW69SMPQVJHTRxDz%2BM9Yj%2B5OLJ7uTKwhNZTtA%2BOwpEONMQVndWVzdA%3D%3D

点赞0


评论


betray_竹箫betray_竹箫

?)

点赞0


评论