猫史档案馆


《论TNT的破坏性以及其代码》

用户:1366155545013661555450查看:36 回复:6 评论:36 创建时间:2022-08-19T14:55:08


右键放置,左键点燃,使用记得导入模型,诸位听我一句劝:”此物威力甚大,请谨慎使用“

由23332808编写

async function tnt(x,y,z){
    const e=world.createEntity({
        mesh:"mesh/TNT.vb",
        meshScale:[1/16,1/16,1/16],
        collides:true,
        gravity:false,
        friction:1.5,
        position:[x,y,z],
    })
    e.enableDamage=true
    e.fixed=true
    e.maxHp=1
    e.hp=1
    e.addTag("TNT")
    e.showHealthBar=false
    e.onTakeDamage(async()=>{e.enableDamage=false
        e.gravity=true
        e.fixed=false
        for(i=0;i<3;i++){
        e.meshEmissive = 1
        await sleep(500)
        e.meshEmissive = 0
        await sleep(500)}
        const bounds = new Box3Bounds3(new Box3Vector3(e.position.x-4,e.position.y-4,e.position.z-4), new Box3Vector3(e.position.x+4,e.position.y+4,e.position.z+4))
        world.searchBox(bounds).forEach((entityInBounds) => { 
        entityInBounds.hurt(10,{attacker:"TNT"})
        var direction = entityInBounds.position.sub(e.position)
        if(direction.x>0){entityInBounds.velocity.x+=1}else{entityInBounds.velocity.x-=1}
        if(direction.y>0){entityInBounds.velocity.y+=1}else{entityInBounds.velocity.y-=1}
        if(direction.z>0){entityInBounds.velocity.z+=1}else{entityInBounds.velocity.z-=1}
        })
        sphere("air",e.position.x,e.position.y,e.position.z,3)
        e.destroy()})}
world. onPress(({button, raycast: { voxelIndex, normal}}) =>{
if (button == Box3ButtonType.ACTION1){
let v = voxelIndex.add(normal)
tnt(Math.round(v.x)+0.5,v.y+0.5,Math.round(v.z)+0.5)}})
world.onclick(({entity,button})=>{
if(entity.hasTag("TNT")&&button=="action1){
entity.hurt(1)
})

 

 


回复

上一页1 页 / 共 1下一页
指令者指令者

eeee

点赞0


评论


145a145a

145安全大脑提示您:请勿随意尝喵坛中来源非官方的代码!此代码安全等级为:潜在危险

点赞0


评论


1366155545013661555450

讲一下,这个程序没喵毒,危险是因为这个东西你放太多会卡

点赞0


评论


AB骉AlobokAB骉Alobok

为哈报错?

点赞0


评论


AB骉AlobokAB骉Alobok

我的报错:center_image

作者你看看哪里错了 代码:center_image

点赞0


评论


1366155545013661555450

async function tnt(x,y,z){
    const e=world.createEntity({
        mesh:"mesh/TNT.vb",
        meshScale:[1/16,1/16,1/16],
        collides:true,
        gravity:false,
        friction:1.5,
        position:[x,y,z],
    })
    e.enableDamage=true
    e.fixed=true
    e.maxHp=1
    e.hp=1
    e.addTag("TNT")
    e.showHealthBar=false
    e.onTakeDamage(async()=>{e.enableDamage=false
        e.gravity=true
        e.fixed=false
        for(i=0;i<3;i++){
        e.meshEmissive = 1
        await sleep(500)
        e.meshEmissive = 0
        await sleep(500)}
        const bounds = new Box3Bounds3(new Box3Vector3(e.position.x-4,e.position.y-4,e.position.z-4), new Box3Vector3(e.position.x+4,e.position.y+4,e.position.z+4))
        world.searchBox(bounds).forEach((entityInBounds) => { 
        entityInBounds.hurt(10,{attacker:"TNT"})
        var direction = entityInBounds.position.sub(e.position)
        if(direction.x>0){entityInBounds.velocity.x+=1}else{entityInBounds.velocity.x-=1}
        if(direction.y>0){entityInBounds.velocity.y+=1}else{entityInBounds.velocity.y-=1}
        if(direction.z>0){entityInBounds.velocity.z+=1}else{entityInBounds.velocity.z-=1}
        })
        sphere("air",e.position.x,e.position.y,e.position.z,3)
        e.destroy()})}
world. onPress(({button, raycast: { voxelIndex, normal}}) =>{
if (button == Box3ButtonType.ACTION1){
let v = voxelIndex.add(normal)
tnt(Math.round(v.x)+0.5,v.y+0.5,Math.round(v.z)+0.5)}})
world.onClick(({entity,button})=>{
if(entity.hasTag("TNT")&&button=="action1"){
entity.hurt(1)
}})
function sphere(vox, cx, cy, cz, radius){
    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)
        }
    }}}
}

点赞0


评论