猫史档案馆


元气代码开源3

用户:seven葫中葫seven葫中葫查看:12 回复:16 评论:12 创建时间:2021-11-14T08:21:05


3怪物脚本

console.error=function(va){
    world.say(va)
}
const zone=world.addZone({
    selector:'player',
    bounds:{
        lo:[73,9,1],
        hi:[126,23,66]
    }
})

const holl=world.addZone({
    selector:'player',
    bounds:{
        lo:[90,0,68],
        hi:[124,6,93]
    }
})

const sky=world.addZone({
    selector:'player',
    bounds:{
        lo:[23,29,8],
        hi:[67,48,41]
    }
})

const under=world.addZone({
    selector:'player',
    bounds:{
        lo:[74,0,1],
        hi:[126,6,66]
    }
})

sky.onEnter(({entity})=>{
    entity.addTag('sky');
    entity.addTag('in')
})

sky.onLeave(({entity})=>{
    entity.removeTag('sky')
    entity.removeTag('in')
})

const fire=world.addZone({
    selector:'player',
    bounds:{
        lo:[1,0,58],
        hi:[53,7,125]
    }
})

fire.onEnter(({entity})=>{
    entity.addTag('in');
    entity.addTag('fire');
})

fire.onLeave(({entity})=>{
    entity.removeTag('in');
    entity.removeTag('fire');
})

world.onTakeDamage(async({entity,attacker})=>{
    if(attacker){
    if(attacker.hasTag("剧毒")){
        entity.meshColor=[0,1,0,1];
        await sleep(500);
        entity.meshColor=[1,1,1,1]
    }
    else if(attacker.hasTag("寒冰")){
        entity.meshColor=[0,1,1,1];
        await sleep(500);
        entity.meshColor=[1,1,1,1]
        entity.friction=0;
    }
    else if(attacker.hasTag("烈焰")){
        if(entity.fier)return;
        entity.meshColor=[1,0,0,1];
        await sleep(500);
        entity.meshColor=[1,1,1,1]
        entity.friction=0;
        var hurt=attacker;
        entity.fier=true;
    Object.assign(entity, {
        particleRate: 30,
        particleSize: [2, 4, 8, 4, 10],
        particleColor: [
            new Box3RGBColor(10, 9, 2),
            new Box3RGBColor(5, 0.25, 0.1),
            new Box3RGBColor(3, 0.05, 0.05),
            new Box3RGBColor(0, 0, 0),
            new Box3RGBColor(0, 0, 0),
        ],
        particleLifetime: 1,
        particleVelocitySpread: new Box3Vector3(2, 2, 2),
    });
        for(let n=0;n<10;n++){
            entity.hurt(2,{attacker:hurt});
            entity.meshColor=[1,0,0,1];
            await sleep(500);
            entity.meshColor=[1,1,1,1]
            await sleep(500)
        }
        entity.fier=false;
        Object.assign(entity, {
        particleRate: 0,
    });
    }
    }
})

under.onEnter(({entity})=>{
    entity.addTag("in");
    entity.addTag("under");
    entity.removeTag("ground")
})

under.onLeave(({entity})=>{
    entity.removeTag("in");
    entity.removeTag("under");
})

zone.onEnter(({entity})=>{
    entity.removeTag("under")
    entity.addTag('in');
    entity.addTag("ground")
})

zone.onLeave(({entity})=>{
    entity.removeTag('in');
    entity.removeTag("ground")
})

const zones=world.addZone({
    selector:'player',
    bounds:{
        lo:[1,0,1],
        hi:[71,23,55]
    }
})

holl.onEnter(({entity})=>{
    entity.removeTag('ground');
    entity.addTag('in');
    entity.addTag('holl')
})

holl.onLeave(({entity})=>{
    entity.removeTag('in');
    entity.removeTag('holl')
})

zones.onEnter(({entity})=>{
    entity.addTag('water')
})

zones.onLeave(({entity})=>{
    entity.removeTag('water');
})

function create(){
    var all=world.querySelectorAll('.096');
    if(all.length==zone.entities.length*2+1){}
    else{
    var x=Math.floor(Math.random()*125)+73;
    var z=Math.floor(Math.random()*66)+1;
    const scp096=world.createEntity({
        mesh:'mesh/自动武器-5.vb',
        position:new Box3Vector3(x,喵,z),
        meshScale:new Box3Vector3(0.3,0.3,0.3),
        mass:10,
        gravity:1,
        collides:true
    })
    scp096.enableDamage=true;
    scp096.maxHp=400;
    scp096.hp=400;
    scp096.mass=1;
    scp096.addTag('096');
    scp096.onEntityContact(({entity,axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            entity.velocity.y=1.5;
        }
        else if(other.isPlayer&&other.hasTag('in')){
        }
    })
    scp096.addTag('陆地怪')
    scp096.onVoxelContact(({entity,axis})=>{
        if(axis.y==0){
            entity.velocity.y=1.5;
        }
    })
    var visi=false;
    function huan(){
        visi=!visi;
        setTimeout(huan,visi?5000:2500)
    }
    huan()
    scp096.addTag('怪物');
    scp096.time=setInterval(()=>{
        if(scp096.destroyed)return;
        if((scp096.velocity.x!=0||scp096.velocity.z!=0)&&visi==true){
        var jig=world.createEntity({
            mesh:'mesh/激光剑1.vb',
            position:scp096.position,
            collides:true,
            gravity:false,
            meshScale:[0.1,0.1,0.1],
            velocity:scp096.velocity.scale(10),
        })
        jig.addTag('怪物攻击');
        world.addCollisionFilter('.怪物攻击','.096');
        setTimeout(()=>{
            jig.destroy();
            jig=null;
        },2000)
        jig.onEntityContact(({other})=>{
            if(!other.isPlayer)return;
            var hurt=Math.round(5-5*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
            if(hurt<0){
                hurt=0
            }
            other.hurt(hurt)
            jig.destroy();
        })
        var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(jig.velocity.z,jig.velocity.x));
        jig.meshOrientation.copy(orientation)
        }
    },250)
    }

    var sleep=Math.floor(Math.random()*15)+5;
    setTimeout(create,sleep*1000);
}
create()

world.onFluidEnter(({entity})=>{
    if(entity.hasTag('陆地怪')){
        entity.position.set(101,喵,47);
    }
})

world.onTick(({tick})=>{
    var players=world.querySelectorAll('.ground');
    var players2=world.querySelectorAll('.under');
    var leidiKing=world.querySelectorAll('.雷德王');
    var spader=world.querySelectorAll('.蜘蛛');
    var players3=world.querySelectorAll('.holl');
    var players1=world.querySelectorAll('.water');
    var scp096=world.querySelectorAll('.陆地怪');
    var water=world.querySelectorAll('.水怪');
    var littleBoss=world.querySelectorAll('.喵oss');
    var fire=world.querySelectorAll('.地狱怪');
    var players4=world.querySelectorAll('.fire');
    var sky=world.querySelectorAll('.雷神皮卡丘');
    var players5=world.querySelectorAll('.sky');
    var ufo=world.querySelectorAll('.UFO')
    scp096.forEach((e)=>{
        if(e.position.y<0){
            e.position.set(101,喵,47)
        }
        e.enableInteract=true;
        e.interactRadius=5;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('ground')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x));
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0
        }
    })
    leidiKing.forEach((e)=>{
        if(e.position.y<0){
            if(e.hasTag("雷德王")){
                e.position.set(101,5,47)
            }
            else{
                e.position.set(101,喵,47)
            }
        }
        e.enableInteract=true;
        e.interactRadius=5;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players2.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('in')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x));
            if(e.hasTag('雷德王')){
                var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x)+Math.PI/2);
            }
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0
        }
    })
    spader.forEach((e)=>{
        if(e.position.y<0){
            if(e.hasTag("雷德王")){
                e.position.set(101,5,47)
            }
            else{
                e.position.set(101,喵,47)
            }
        }
        e.enableInteract=true;
        e.interactRadius=5;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players3.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('in')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x));
            if(e.hasTag('雷德王')){
                var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x)+Math.PI/2);
            }
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0
        }
    })
    water.forEach((e)=>{
        if(e.position.y<0){
            e.position.set(17,5,12)
        }
        if(e.position.y>7){
            e.y=0.7;
            e.velocity.y-=0.7
        }
        else{
            e.y=0;
        }
        e.enableInteract=true;
        e.interactRadius=5;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players1.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('water')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            e.velocity.y=targetPos.y*speed/dist-e.y;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x)+Math.PI/2);
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0
        }
    })
    ufo.forEach((e)=>{
        if(e.position.y<0){
            e.position.set(17,5,12)
        }
        if(e.position.y>7){
            e.y=0.7;
            e.velocity.y-=0.7
        }
        else{
            e.y=0;
        }
        e.enableInteract=true;
        e.interactRadius=5;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players1.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('water')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            e.velocity.y=targetPos.y*speed/dist-e.y;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x)-Math.PI/2);
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0
        }
    })
    littleBoss.forEach((e)=>{
        e.enableInteract=true;
        e.interactRadius=7;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players2.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('under')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x)-Math.PI/1);
            e.meshOrientation.copy(orientation)
        }
    })
    fire.forEach((e)=>{
        e.enableInteract=true;
        e.interactRadius=7;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players4.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('fire')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            e.velocity.x=targetPos.x*speed/dist;
            e.velocity.z=targetPos.z*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x));
            e.meshOrientation.copy(orientation)
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0;
        }
    })
    sky.forEach((e)=>{
        if(e.position.y<27){
            e.position.set(44,35,26)
        }
        e.enableInteract=true;
        e.interactRadius=7;
        e.interactColor=new Box3RGBColor(1,0,0);
        e.interactHint=`❤${e.hp}/${e.maxHp}`;
        if(tick%11==0){
            let target=players5.sort((a,b)=>{
                return a.position.distance(e.position)-b.position.distance(e.position)
            })[0]
            if(target){
                e.target=target;
            }
        }
        if(e.target&&!e.target.destroyed&&e.target.hasTag('sky')&&e.target.hp!=0){
            var targetPos=e.target.position.sub(e.position);
            var dist=targetPos.mag();
            var speed=0.2;
            if(dist<6){
                e.velocity=[0,0,0]
            }
            else{
                e.velocity.x=targetPos.x*speed/dist;
                e.velocity.z=targetPos.z*speed/dist;
                var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(e.velocity.z,e.velocity.x));
                e.meshOrientation.copy(orientation)
            }
        }
        else{
            e.velocity.x=0;
            e.velocity.z=0;
        }
    })
})


function create2(){
    if(world.querySelectorAll('.机器').length<=zone.entities.length*2){
    var x=Math.floor(Math.random()*125)+73;
    var z=Math.floor(Math.random()*66)+1;
    const robot=world.createEntity({
        mesh:'mesh/小型机器人-初号.vb',
        position:[x,喵,z],
        meshScale:[0.1,0.1,0.1],
        gravity:true,
        collides:true,
        mass:10
    })
    robot.enableDamage=true;
    robot.addTag('陆地怪')
    robot.maxHp=600;
    robot.hp=600;
    robot.addTag('怪物');
    robot.addTag('机器');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })

    robot.time=setInterval(async()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position){
            var hurt=world.createEntity({
                mesh:'mesh/球.vb',
                gravity:0,
                collides:true,
                position:robot.position,
                meshEmissive:1
            })
            hurt.addTag('怪物攻击')
            var players=world.querySelectorAll('.in');
            let target=players.sort((a,b)=>{
                return a.position.distance(robot.position)-b.position.distance(robot.position)
            })[0]
            if(target){
                hurt.target=target;
            }
            if(target){
            var targetPos=hurt.target.position.sub(robot.position);
            var dist=targetPos.mag();
            var speed=1.5;
            hurt.velocity.x=targetPos.x*speed/dist;
            hurt.velocity.z=targetPos.z*speed/dist;
            hurt.velocity.y=targetPos.y*speed/dist;
            hurt.onEntityContact(({other})=>{
                if(other.isPlayer){
                    var hurt=20-Math.round(20*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
                    if(hurt<0){
                        hurt=0;
                    }
                    other.hurt(hurt)
                }
            })
            hurt.onVoxelContact(({entity})=>{
                entity.destroy();
            })
            }
            setTimeout(()=>{
                hurt.destroy();
            },2000)
        }
    },1250)
    }
    var sleep=Math.floor(Math.random()*20)+10;
    setTimeout(create2,sleep*1000)
}

create2()

world.addCollisionFilter('.怪物攻击','.怪物')

function create3(){
    var all=world.querySelectorAll('.水怪');
    if(all.length==zones.entities.length*2+2){}
    else{
    var x=Math.floor(Math.random()*71)+1;
    var z=Math.floor(Math.random()*55)+1;
    const scp096=world.createEntity({
        mesh:'mesh/导弹核潜艇。.vb',
        position:new Box3Vector3(x,5,z),
        meshScale:new Box3Vector3(0.15,0.15,0.15),
        collides:true,
        gravity:0
    })
    scp096.enableDamage=true;
    scp096.maxHp=3000;
    scp096.hp=3000;
    scp096.mass=1;
    scp096.addTag('水怪');
    scp096.onEntityContact(({entity,axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            entity.velocity.y=1.5;
        }
        else if(other.isPlayer&&other.hasTag('water')){
        }
    })
    scp096.onVoxelContact(({entity,axis})=>{
        if(axis.y==0){
            entity.velocity.y=1.5;
        }
    })
    var visi=false;
    function huan(){
        visi=!visi;
        setTimeout(huan,visi?4000:2500)
    }
    huan();
    scp096.addTag('怪物');
    scp096.time=setInterval(()=>{
        if(scp096.destroyed)return;
        if((scp096.velocity.x!=0||scp096.velocity.z!=0)&&visi==true){
        var jig=world.createEntity({
            mesh:'mesh/激光剑1.vb',
            position:scp096.position,
            collides:true,
            gravity:false,
            meshScale:[0.1,0.1,0.1],
            velocity:scp096.velocity.scale(10),
        })
        jig.addTag('怪物攻击')
        world.addCollisionFilter('.怪物攻击','.水怪');
        setTimeout(()=>{
            jig.destroy();
            jig=null;
        },2000)
        jig.onEntityContact(({other})=>{
            if(!other.isPlayer)return;
            var hurt=Math.round(55-55*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
            if(hurt<0)hurt=0;
            other.hurt(hurt)
            jig.destroy()
        })
        var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(jig.velocity.z,jig.velocity.x));
        jig.meshOrientation.copy(orientation)
        }
    },250)
    }

    var sleep=Math.floor(Math.random()*20)+10;
    setTimeout(create3,sleep*1000);
}

create3();

function create4(){
    if(world.querySelectorAll('.雷德王').length<=under.entities.length*2+2){
    var x=Math.floor(Math.random()*125)+86;
    var z=Math.floor(Math.random()*66)+1;
    const robot=world.createEntity({
        mesh:'mesh/怪兽岩浆雷德王.vb',
        position:[x,5,z],
        meshScale:[0.15,0.15,0.15],
        gravity:true,
        collides:true,
        mass:10
    })
    robot.enableDamage=true;
    robot.maxHp=100;
    robot.hp=100;
    robot.addTag('怪物');
    robot.addTag('雷德王');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })

    robot.time=setInterval(async()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position){
            var hurt=world.createEntity({
                mesh:'mesh/球.vb',
                gravity:0,
                collides:true,
                position:robot.position,
                meshColor:new Box3RGBAColor(1,0,0,1)
            })
            hurt.addTag('怪物攻击')
            var players=world.querySelectorAll('.under');
            let target=players.sort((a,b)=>{
                return a.position.distance(robot.position)-b.position.distance(robot.position)
            })[0]
            if(target){
                hurt.target=target;
            }
            if(target){
            var targetPos=hurt.target.position.sub(robot.position);
            var dist=targetPos.mag();
            var speed=1.5;
            hurt.velocity.x=targetPos.x*speed/dist;
            hurt.velocity.z=targetPos.z*speed/dist;
            hurt.velocity.y=targetPos.y*speed/dist;
            hurt.onEntityContact(({other})=>{
                if(other.isPlayer){
                    var hurt=10-Math.round(10*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
                    if(hurt<0)hurt=0;
                    other.hurt(hurt)
                }
            })
            hurt.onVoxelContact(({entity})=>{
                entity.destroy();
            })
            }
            setTimeout(()=>{
                hurt.destroy();
                hurt=null
            },2000)
        }
    },1250)
    }
    var sleep=Math.floor(Math.random()*10)+5;
    setTimeout(create4,sleep*1000)
}

create4()

function create5(){
    if(world.querySelectorAll('.蜘蛛').length<=holl.entities.length*2+1){
    const robot=world.createEntity({
        mesh:'mesh/蜘蛛(鬼马创作节).vb',
        position:[109,3,80],
        meshScale:[0.25,0.4,0.25],
        gravity:true,
        collides:true,
        mass:10
    })
    robot.enableDamage=true;
    robot.maxHp=2000;
    robot.hp=2000;
    robot.addTag('怪物');
    robot.addTag('蜘蛛');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })

    robot.time=setInterval(()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position){
            var hurt=world.createEntity({
                mesh:'mesh/蜘蛛网.vb',
                gravity:0,
                collides:true,
                position:robot.position,
                meshColor:new Box3RGBAColor(0,1,0,1),
                meshScale:[0.02,0.02,0.02],
                mass:20
            })
            hurt.addTag('怪物攻击')
            var players=world.querySelectorAll('.holl');
            let target=players.sort((a,b)=>{
                return a.position.distance(robot.position)-b.position.distance(robot.position)
            })[0]
            if(target){
                hurt.target=target;
            }
            if(target){
            var targetPos=hurt.target.position.sub(robot.position);
            var dist=targetPos.mag();
            var speed=1.5;
            hurt.velocity.x=targetPos.x*speed/dist;
            hurt.velocity.z=targetPos.z*speed/dist;
            hurt.velocity.y=targetPos.y*speed/dist;
            hurt.meshOrientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(hurt.velocity.z,hurt.velocity.x))
            hurt.onEntityContact(({other})=>{
                if(other.isPlayer){
                    var hurt=60-Math.round(60*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
                    if(hurt<0)hurt=0;
                    other.hurt(hurt)
                }
            })
            hurt.onVoxelContact(({entity})=>{
                entity.destroy();
            })
            }
            setTimeout(()=>{
                hurt.destroy();
                hurt=null
            },2000)
        }
    },1250)
    }
    var sleep=Math.floor(Math.random()*14)+7;
    setTimeout(create5,sleep*1000)
}

create5()

function create6(){
    if(world.querySelectorAll('.喵oss').length<1){
    const robot=world.createEntity({
        mesh:'mesh/iwen-2133.vb',
        position:[103,5,55],
        meshScale:[0.3,0.3,0.3],
        gravity:true,
        collides:true,
        mass:10
    })
    robot.enableDamage=true;
    robot.maxHp=10000;
    robot.hp=10000;
    robot.addTag('怪物');
    robot.addTag('喵oss');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })
    robot.time=setInterval(()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position){
            for(let n=0;n<world.querySelectorAll('.under').length;n++){
            var hurt=world.createEntity({
                mesh:'mesh/“毒刺”导弹.vb',
                gravity:0,
                collides:true,
                position:robot.position,
                meshColor:new Box3RGBAColor(1,1,1,1),
                meshEmissive:0.5,
                meshScale:[0.03,0.03,0.03]
            })
            hurt.addTag('怪物攻击')
                var targetPos=world.querySelectorAll('.under')[n].position.sub(robot.position);
                var dist=targetPos.mag();
                var speed=4;
                hurt.velocity.x=targetPos.x*speed/dist;
                hurt.velocity.z=targetPos.z*speed/dist;
                hurt.velocity.y=targetPos.y*speed/dist;
                var orientation=new Box3Quaternion(0,0,0,1).rotateX(Math.atan2(hurt.velocity.y,hurt.velocity.z)).rotateY(Math.atan2(hurt.velocity.z,hurt.velocity.x)-Math.PI/2)
                hurt.meshOrientation.copy(orientation)
                hurt.onEntityContact(({other})=>{
                    if(other.isPlayer){
                        var hurt=125-Math.round(125*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
                        if(hurt<0)hurt=0;
                        other.hurt(hurt)
                    }
                })
                hurt.onVoxelContact(({entity})=>{
                    entity.destroy();
                })
                setTimeout(()=>{
                    hurt.destroy();
                    hurt=null
                },2000)
            }
        }
    },1000)
    }
    var sleep=Math.floor(Math.random()*700)+600;
    setTimeout(create6,sleep*1000)
}
create6();

function create7(){
    if(world.querySelectorAll('.地狱怪').length<fire.entities.length*2+1){
    const robot=world.createEntity({
        mesh:'mesh/地狱怪.vb',
        meshScale:[0.04,0.04,0.04],
        gravity:true,
        collides:true,
        mass:10,
        position:[30,5,104]
    })
    robot.enableDamage=true;
    robot.maxHp=4666;
    robot.hp=4666;
    robot.addTag('怪物');
    robot.addTag('地狱怪');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })
    robot.time=setInterval(()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position&&robot.target){
            var hurt=world.createEntity({
                mesh:'mesh/球.vb',
                gravity:0,
                collides:true,
                position:robot.position,
                meshColor:new Box3RGBAColor(1,0,0,1)
            })
            hurt.addTag('怪物攻击')
            var players=world.querySelectorAll('.fire');
            let target=players.sort((a,b)=>{
                return a.position.distance(robot.position)-b.position.distance(robot.position)
            })[0]
            if(target){
                hurt.target=target;
            }
            if(target){
            var targetPos=hurt.target.position.sub(robot.position);
            var dist=targetPos.mag();
            var speed=1.5;
            hurt.velocity.x=targetPos.x*speed/dist;
            hurt.velocity.z=targetPos.z*speed/dist;
            hurt.velocity.y=targetPos.y*speed/dist;
            hurt.onEntityContact(({other})=>{
                if(other.isPlayer){
                    var hurt=66-Math.round(66*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
                    if(hurt<0)hurt=0;
                    other.hurt(hurt)
                }
            })
            hurt.onVoxelContact(({entity})=>{
                entity.destroy();
            })
            }
            setTimeout(()=>{
                hurt.destroy();
                hurt=null
            },2000)
        }
    },1250)
    }
    var sleep=Math.floor(Math.random()*15)+7;
    setTimeout(create7,sleep*1000)
}
create7();

function create8(){
    if(world.querySelectorAll('.雷神皮卡丘').length<sky.entities.length*2+1){
    const robot=world.createEntity({
        mesh:'mesh/雷神皮卡丘.vb',
        meshScale:[0.09,0.09,0.09],
        gravity:true,
        collides:true,
        mass:10,
        position:[46,33,24]
    })
    robot.enableDamage=true;
    robot.maxHp=6666;
    robot.hp=6666;
    robot.addTag('怪物');
    robot.addTag('雷神皮卡丘');
    robot.onEntityContact(({axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            robot.velocity.y=1
        }
    })
    robot.onVoxelContact(({axis})=>{
        if(axis.y==0){
            robot.velocity.y=1
        }
    })
    robot.time=setInterval(()=>{
        if(robot.destroyed)return;
        if(robot.velocity.x!=0&&robot.velocity.z!=0&&robot.position&&robot.target){
            var hurt=world.createEntity({
                mesh:'mesh/皮卡丘攻击.vb',
                gravity:0,
                collides:false,
                position:robot.position,
                meshScale:[0.04,0.04,0.04],
            })
            hurt.addTag('怪物攻击')
            var players=world.querySelectorAll('.sky');
            let target=players.sort((a,b)=>{
                return a.position.distance(robot.position)-b.position.distance(robot.position)
            })[0]
            if(target){
                hurt.target=target;
            }
            if(target){
            var targetPos=hurt.target.position.sub(robot.position);
            var dist=targetPos.mag();
            var speed=1;
            hurt.velocity.x=targetPos.x*speed/dist;
            hurt.velocity.z=targetPos.z*speed/dist;
            hurt.velocity.y=targetPos.y*speed/dist;
            var orientation=new Box3Quaternion(0,0,0,1).rotateX(Math.atan2(hurt.velocity.y,hurt.velocity.x)+Math.PI/2).rotateY(Math.atan2(hurt.velocity.z,hurt.velocity.x));
            hurt.meshOrientation.copy(orientation)
            var time1=setInterval(()=>{
                if(hurt.destroyed)return;
                    const zone=world.addZone({
                        selector:'player',
                        bounds:{
                            lo:[hurt.position.x-hurt.bounds.x/2,hurt.position.y-hurt.bounds.y/2,hurt.position.z-hurt.bounds.z/2],
                            hi:[hurt.position.x+hurt.bounds.x/2,hurt.position.y+hurt.bounds.y/2,hurt.position.z+hurt.bounds.z/2]
                        }
                    })
                    zone.onEnter(({entity})=>{
                        if(!entity.isPlayer)return;
                        var hurto=99-Math.round(99*(entity.cannotHurt[0]+entity.cannotHurt[1]+entity.cannotHurt[2]+entity.cannotHurt[3]));
                        if(hurto<0)hurto=0;
                        entity.hurt(hurto);
                        hurt.destroy()
                    })
                setTimeout(()=>{
                    world.removeZone(zone);
                },100)
            },50)
            }
            setTimeout(()=>{
                hurt.destroy();
                clearInterval(time1);
                hurt=null
            },4000)
        }
    },1000)
    }
    var sleep=Math.floor(Math.random()*13)+5;
    setTimeout(create8,sleep*1000)
}
create8();
/*
function create9(){
    var all=world.querySelectorAll('.UFO');
    if(all.length==1){}
    else{
    const scp096=world.createEntity({
        mesh:'mesh/宇宙飞船.vb',
        position:new Box3Vector3(20,5,28),
        meshScale:new Box3Vector3(0.15,0.15,0.15),
        collides:true,
        gravity:0
    })
    scp096.enableDamage=true;
    scp096.maxHp=100000;
    scp096.hp=100000;
    scp096.mass=1;
    scp096.addTag('UFO');
    scp096.onEntityContact(({entity,axis,other})=>{
        if(axis.y==0&&!other.hasTag('攻击')&&!other.isPlayer){
            entity.velocity.y=1.5;
        }
        else if(other.isPlayer&&other.hasTag('water')){
        }
    })
    scp096.onVoxelContact(({entity,axis})=>{
        if(axis.y==0){
            entity.velocity.y=1.5;
        }
    })
    var visi=false;
    function huan(){
        visi=!visi;
        setTimeout(huan,visi?7000:2500)
    }
    huan();
    scp096.addTag('怪物');
    scp096.time=setInterval(()=>{
        if(scp096.destroyed)return;
        if((scp096.velocity.x!=0||scp096.velocity.z!=0)&&visi==true){
        for(let a=0;a<world.querySelectorAll('.water').length;a++){
        var jig=world.createEntity({
            mesh:'mesh/激光剑1.vb',
            position:scp096.position,
            collides:true,
            gravity:false,
            meshScale:[0.1,0.1,0.1],
            velocity:scp096.velocity.scale(10),
            emissive:0.3
        })
        jig.addTag('怪物攻击')
        world.addCollisionFilter('.怪物攻击','.UFO');
        setTimeout(()=>{
            if(jig!=null){
                jig.destroy();
                jig=null;
            }
        },2000);
            var targetPos=world.querySelectorAll('.water')[a].position.sub(scp096.position);
            var dist=targetPos.mag();
            var speed=1.5;
            jig.velocity.x=targetPos.x*speed/dist;
            jig.velocity.z=targetPos.z*speed/dist;
        jig.onEntityContact(({other})=>{
            if(!other.isPlayer)return;
            var hurt=Math.round(166-166*(other.cannotHurt[0]+other.cannotHurt[1]+other.cannotHurt[2]+other.cannotHurt[3]));
            if(hurt<0)hurt=0;
            other.hurt(hurt);
            if(jig==null)return;
            jig.destroy()
        })
        var orientation=new Box3Quaternion(0,0,0,1).rotateY(Math.atan2(jig.velocity.z,jig.velocity.x));
        jig.meshOrientation.copy(orientation)
        }
        }
    },250)
    }

    var sleep=Math.floor(Math.random()*20)+10;
    setTimeout(create9,sleep*1000);
}

create9();
*/



回复

上一页1 页 / 共 1下一页
梁桂琪梁桂琪

谢了

点赞0


评论


神岛的梦_夜神岛的梦_夜

编码……yyds…………nb…………啊啊啊……

点赞0


评论


SCS_user_IlhGRm2Ud5SCS_user_IlhGRm2Ud5

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


SCS_user_IlhGRm2Ud5SCS_user_IlhGRm2Ud5

imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"imgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E7%82%B9%E8%B5%9E.gif"alt="emotion_编程猫_点赞"

点赞0


评论


星辰Lolita星辰Lolita

好水啊。。。

点赞1


评论


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

我没见过比这更氵的代码

点赞0


评论


难起的名字难起的名字

world.onTick(({tick})=>{
    var players=world.querySelectorAll('.ground');
    var players2=world.querySelectorAll('.under');
    var leidiKing=world.querySelectorAll('.雷德王');
    var spader=world.querySelectorAll('.蜘蛛');
    var players3=world.querySelectorAll('.holl');
    var players1=world.querySelectorAll('.water');
    var scp096=world.querySelectorAll('.陆地怪');
    var water=world.querySelectorAll('.水怪');
    var littleBoss=world.querySelectorAll('.喵oss');
    var fire=world.querySelectorAll('.地狱怪');
    var players4=world.querySelectorAll('.fire');
    var sky=world.querySelectorAll('.雷神皮卡丘');
    var players5=world.querySelectorAll('.sky');
    var ufo=world.querySelectorAll('.UFO')

这里的喵是什么???

点赞0


评论


聋猪up聋猪up

undefined

点赞0


评论


Camellia茶叶喵Camellia茶叶喵

这个。。。。。。。。。。。。。好乱的代码

点赞0


评论


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

收藏

点赞0


评论


喵喵咪awa喵喵咪awa

收藏()

点赞0


评论


egg鸡蛋蛋egg鸡蛋蛋

(收藏

点赞0


评论


无极玄天无极玄天

好东西

点赞0


评论


望柒望柒

挖坟

点赞0


评论


de丨丨bugde丨丨bug

宝藏发现。。

点赞0


评论


AK亨利佐加DanJamesThomasAK亨利佐加DanJamesThomas

center_image

点赞0


评论