猫史档案馆


【开源】《超级零元购兄弟》地图代码开源!

用户:Star_Ink_sansStar_Ink_sans查看:11 回复:10 评论:11 创建时间:2022-08-05T14:34:01


//代码作者:Star_Ink_sans / 006 / (恶.管)tiger666250
//如需转载,请把作者信息也复制进去,这也是对我们的一种尊重
//可能有bug,请见谅


var PLAYING=false
var APPEAR=false
var gametime=0
var hittime=5
// 关闭玩家和玩家之间的碰撞
world.addCollisionFilter('player', 'player');

console.clear();

function randomNum(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;
    }
};

for (const npc of world.querySelectorAll('.npc')) {
    npc.enableInteract = true;
    npc.interactRadius = 5;
    npc.interactHint = '观战'
    if (npc.id == '代码面板-1') {
        npc.onInteract(async ({ entity }) => {
            entity.position.set(47,12,52);
            entity.player.invisible = true;
            entity.player.canFly = true;
            entity.guanzhan = 1;
            entity.player.directMessage(`已进入观战模式【右键(移动端B键)退出】`)
        })
    }
}
world.onPlayerJoin(async({entity})=>{
    entity.enableDamage=true
    entity.position.set(114,11,12);
    entity.guanzhan=3;
    entity.player.time=0;
})

world.onPress(async({entity,button})=>{
    if(button == 'action1'){
        if(entity.guanzhan === 1){
            entity.position.set(114,11,12);
            entity.player.invisible = false;
            entity.player.canFly = false;
            entity.guanzhan = 0;
            entity.player.directMessage(`已退出观战模式`)
            entity.player.showName=true
        }
    }
})

const gsp=world.querySelector('.告示牌')
gsp.enableInteract = true; 
gsp.interactRadius = 3; 
gsp.interactColor = new Box3RGBColor(0, 0, 0);
gsp.onInteract(async({entity})=>{
    entity.player.dialog({
        type:'text',
        title:'贡献人员',
        content:`地图拥有者:Star_Ink_sans \n地图贡献人员:AOR.御剑九天,006,獾獾同学 \n特别贡献者:(恶.管)tiger666250`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:`一起在超市中疯狂的进行零元购吧!但是要小心:不能让蝙蝠侠捉到你哦~`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:` 淘汰规则:\n 1.若10秒没有抢到物品,则淘汰; \n 2.若在蝙蝠侠在门口出现时侦测到移动或抢物品,则淘汰。`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:`活到最后的玩家胜利~`
    });
})

world.querySelectorAll('entity').forEach((e)=>{
    if(e.id=='电脑-1'||e.id=='啤酒-1'||e.id=='超级苹果手机-1'||e.id=='swich游戏机-1'||e.id=='老八蜜制小汉堡-1'||e.id=='三明治-1'||e.id=='钞票-1'){
        e.addTag('抢')
        e.enableInteract = true; 
        e.interactRadius = 3; 
        e.interactColor = new Box3RGBColor(0, 0, 0);
        e.onInteract(async({entity})=>{
            if(PLAYING&&APPEAR&&entity.guanzhan==0){
                entity.hurt(100)
                entity.guanzhan=3
                world.say(entity.player.name+' 被蝙蝠侠淘汰了!')
                await sleep(5000)
                entity.player.forceRespawn()}
            if(entity.guanzhan==0&&PLAYING){
                entity.player.time=0
                e.position.y-=10
                if(e.id == '电脑-1')
                    entity.player.directMessage(`你抢到了电脑`)
                if(e.id == '啤酒-1')
                    entity.player.directMessage(`你抢到了啤酒`)
                if(e.id == '超级苹果手机-1')
                    entity.player.directMessage(`你抢到了苹果手机`)
                if(e.id == 'swich游戏机-1')
                    entity.player.directMessage(`你抢到了switch游戏机`)
                if(e.id == '老八蜜制小汉堡-1')
                    entity.player.directMessage(`你抢到了汉堡`)
                if(e.id == '三明治-1')
                    entity.player.directMessage(`你抢到了三明治`)
                if(e.id == '钞票-1')
                    entity.player.directMessage(`你获得了钱`)
                await sleep(10000)
                e.position.y+=10
            }
        })
    }
})

async function game(){
    while(true){
        if(!PLAYING){
            var onlines = world.querySelectorAll('player').length
            if(onlines >= 2){
                world.say('游戏即将开始...')
                await sleep(10000)
                world.querySelectorAll('player').forEach((entity)=>{
                    entity.position.set(randomNum(40,67),10,randomNum(34,38))
                })
                world.say('游戏开始')
                PLAYING = true
                gametime=0
                world.querySelectorAll('player').forEach((entity)=>{
                    entity.guanzhan=0
                    entity.player.time=0
                    entity.player.invisible = false;
                    entity.player.canFly = false;
                })
                hittime=5
            }else{
                world.say('2个玩家立即开始')
            }
        }else{
            if(hittime==gametime){
                for(x=17;x<=73;x++){
                    for(z=33;z<=54;z++){
                        if(voxels.getVoxelId(x,8,z)==289){
                            voxels.setVoxelId(x,8,z,283)
                        }

                    }
                }
                await sleep(200)               
                world.querySelector('.喵队长').position.x=23
                world.querySelector('.喵队长').position.z=31
                hittime+=randomNum(6,11)
                await sleep(200)
                APPEAR=true
                await sleep(1800)
                APPEAR=false
                world.querySelector('.喵队长').position.x=40
                world.querySelector('.喵队长').position.z=29
                for(x=17;x<=73;x++){
                    for(z=33;z<=54;z++){
                        if(voxels.getVoxelId(x,8,z)==283){
                            voxels.setVoxelId(x,8,z,289)
                        }

                    }
                }
            }
            let alive = 0
            gametime+=1
            world.querySelectorAll('player').forEach(async(entity)=>{
                if(entity.guanzhan==0){
                    entity.player.time+=1
                if(entity.player.time>=10&&entity.guanzhan==0){
                        entity.hurt(100)
                        entity.guanzhan=3
                        world.say(entity.player.name+' 因为长时间未进行零元购 被淘汰了!')
                        await sleep(5000)
                        entity.player.forceRespawn()
                    }
                }
                if(entity.guanzhan==0){
                    alive+=1
                }
            })
            if(alive==1){
                world.querySelectorAll('player').forEach(async(entity)=>{
                    if(entity.guanzhan==0){
                        world.say(entity.player.name+'是获胜者')
                        entity.player.emissive=0.1
                        await sleep(5000)
                        entity.player.forceRespawn()
                        await sleep(5000)
                        if (!FRIEND_PLAYER.includes(entity.player.name)){
                        entity.player.emissive=0
                    }}
                })
                gametime=300
            }else if(alive<=0){
                world.say('本局没有获胜者')//万一好多人喵了
                gametime=300
            }
            if(gametime>=300){
                world.say('游戏结束!')
                PLAYING=false
            }
        }
        await sleep(1000);
    }
}

game()

world.onTick(({tick})=>{
    if(tick%2==0){
        if(PLAYING){
            if(APPEAR){
                world.querySelectorAll('player').forEach(async(entity)=>{
                    if(entity.guanzhan==0){
                        if(entity.player.walkState||entity.player.moveState!=='ground'){
                            entity.hurt(100)
                            entity.guanzhan=3
                            world.say(entity.player.name+' 被蝙蝠侠淘汰了!')
                            await sleep(3000)
                            entity.player.forceRespawn()
                        }
                    }
                })
            }
        }
    }
})

const FRIEND_PLAYER = ['Star_Ink_sans','AOR.御剑九天','006','獾獾同学','(恶.管)tiger666250']
const BLACK = []
world.onPlayerJoin(({ entity }) => {
    if (!FRIEND_PLAYER.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
    world.say(`地图创作人员 ${entity.player.name} 降临!`)
    entity.player.emissive=0.1
})

const special = []
world.onPlayerJoin(({ entity }) => {
    if (!special.includes(entity.player.name)) return; // 如果玩家名称不在列表里,则跳过后续脚本。
    world.say(`特别贡献者 ${entity.player.name} 降临!`)
})

world.onPlayerJoin(({ entity }) => {
    if (!BLACK.includes(entity.player.name)) return; 
    entity.player.kick()
})

var admin = ['Star_Ink_sans']

world.onChat(({entity,message})=>{
    if (message.startsWith('$')&&admin.includes(entity.player.name)) {
        try{
            world.say('<~ '+eval(message.slice(1)))
        }
        catch(err){
            world.say('<~ '+err)
        }
    }
})

function f(name){
    for (const entity of world.querySelectorAll('player'))
        if (entity.player.name == name)
            return entity;
    return('没有这个玩家')
}

// 当玩家进入游戏
world.onPlayerJoin(({ entity }) => {
    entity.player.dialog({
        type:'text',
        title:'贡献人员',
        content:`地图拥有者:Star_Ink_sans \n地图贡献人员:AOR.御剑九天,006,獾獾同学,(恶.管)tiger666250`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:`一起在超市中疯狂的进行零元购吧!但是要小心:不能让蝙蝠侠捉到你哦~`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:` 淘汰规则:\n 1.若10秒没有抢到物品,则淘汰; \n 2.若在蝙蝠侠在门口出现时侦测到移动或抢物品,则淘汰。`
    });
    entity.player.dialog({
        type:'text',
        title:'游戏规则',
        content:`活到最后的玩家胜利~`
    });
});


回复

上一页1 页 / 共 1下一页
Star_Ink_sansStar_Ink_sans

作品体验链接:box3.codemao.cn/p/ngana-rindu

点赞0


评论


Star_Ink_sansStar_Ink_sans

没人看嘛)

点赞0


评论


搬码喵搬码喵

https://box3.codemao.cn/p/magicWorld/

点赞0


评论


呵呵0486呵呵0486

后面几行管喵有必要吗()()

点赞0


评论


Star_Ink_sansStar_Ink_sans

这么好的开源没人看qwq?)

点赞0


评论


iamdreamiamdream

yyds

点赞0


评论


钢铁堡垒钢铁堡垒

看看,

我发现了什么?

点赞0


评论


电电小玩电电小玩

感谢代码()

点赞0


评论


云游box3der尖头叉子云游box3der尖头叉子

会js的都觉得这代码太氵,看了几行点了叉叉)))不会js的是真的厉害)看都不看)直接就复制)))

点赞0


评论


yee剑走天下yee剑走天下

似乎有点……()()emotion_doge算了不想得罪人()()emotion_doge

点赞0


评论