用户:
治愈绾兮查看:1 回复:5 评论:1 创建时间:2022-04-18T13:12:48
之前我也公开过喵战士的代码,链接:shequ.codemao.cn/community/389108,现在,又是个首页地图《城市战争》的代码公开,毕竟不火了的首页地图我就会公开代码:
(async function () {
suoquanshuju = [126, 110, 100, 90, 80, 70, 60, 50, 40, 30];
while (true) {
for (let x = 0; x < 127; x++) {
for (let y = 0; y < 127; y++) {
for (let z = 0; z < 127; z++) {
if (voxels.getVoxel(x, y, z) == 170) {
voxels.setVoxel(x, y, z, "air")
}
}
}
}
world.querySelectorAll("player").forEach((entity) => {
entity.position.set(4, 10, 123)
})
cuileiduqishiyongzhe = "";
world.addZone({
selector: "entity",
bounds: {
lo: [0, 0, 0],
hi: [128, 128, 128],
},
fogEnabled: true,
fogColor: new Box3RGBColor(255, 255, 255),
fogDensity: 0,
})
shengyurenshu = 0;
shengliwanjia = "";
kongtoushiyongshuliang = 0;
xinhaodanweizhi = String(1 + Math.round(Math.random() * (10 - 1)))
world.say("新的一局5秒后开始")
await sleep(5000)
world.querySelectorAll("player").forEach((entity) => {
entity.position.set(126, 10, 122)
shengyurenshu += 1;
entity.player.daoju = 1;
entity.player.cuileiduqishuliang = 0;
entity.player.xinhaodanshuliang = 0;
})
cuileiduqishiyongzhe = "";
cuileiduqi.position.x = Math.random() * suoquanshuju[suoquanshu];
cuileiduqi.position.z = Math.random() * suoquanshuju[suoquanshu];
cuileiduqi.position.y = 100;
kongtou.position.x = 0;
kongtou.position.z = 0;
kongtou.position.y = 0;
world.say("游戏正式开始,有10秒喵时间")
await sleep(10000)
world.querySelectorAll("player").forEach((entity) => {
entity.player.siwang = 0;
})
for (let i = 0; i < 10; i++) {
suoquanshu = i;
world.say("已缩第" + (i + 1) + "圈,请尽快撤向长隆帅帅,补给:血量增加30")
for (let x = 0; x < 127; x++) {
for (y = 0; y < 127; y++) {
if (voxels.getVoxel(x, y, suoquanshuju[i]) == 0) {
voxels.setVoxel(x, y, suoquanshuju[i], "glass")
}
}
}
for (let z = 0; z < 127; z++) {
for (y = 0; y < 127; y++) {
if (voxels.getVoxel(suoquanshuju[i], y, z) == 0) {
voxels.setVoxel(suoquanshuju[i], y, z, "glass")
}
}
}
world.querySelectorAll("player").forEach((entity) => {
if (entity.hp <= 70) {
entity.hp += 30;
} else {
entity.hp = 100;
}
if (entity.player.siwang == 0) {
if (entity.position.x > suoquanshuju[i] || entity.position.z > suoquanshuju[i]) {
entity.hurt(100, {
attacker: entity,
});
}
}
})
if (shengyurenshu <= 1) {
world.querySelectorAll("player").forEach((entity) => {
if (entity.player.siwang == 0) {
shengliwanjia = entity.player.name;
}
})
world.say("恭喜" + shengliwanjia + "赢得了冠军")
break;
}
await sleep(30000)
}
}
})()
//地图初始化
console.clear()
world.addCollisionFilter("player", "player")
suoquanshu = 0;
kongtoushiyongshuliang = 0;
const cuileiduqi = world.querySelector('#催泪毒气');
cuileiduqi.enableInteract = true;
cuileiduqi.interactRadius = 5;
cuileiduqi.interactHint = cuileiduqi.id;
cuileiduqi.gravity = true;
cuileiduqi.fixed = false;
const kongtou = world.querySelector('#空投');
kongtou.enableInteract = true;
kongtou.interactRadius = 5;
kongtou.interactHint = kongtou.id;
kongtou.gravity = true;
kongtou.fixed = false;
//玩家初始化
world.onPlayerJoin(async ({ entity }) => {
entity.player.cameraMode = "fps";
entity.player.enable3DCursor = true;
entity.enableDamage = true;
entity.position.set(4, 10, 123)
entity.player.spawnPoint.set(4, 10, 123)
entity.player.siwang = 1;
entity.player.daoju = 1;
entity.player.cuileiduqishuliang = 0;
entity.player.scale = 0.8;
const result = await entity.player.dialog({
type: Box3DialogType.TEXT,
title: "游戏说明",
content: `规则说明:本地图每30秒缩一次圈,每次缩13格左右,你需要在安全区里合理运用道具击杀所有敌人,每次缩圈时提供一次补给。操作说明:左键使用道具;右键使用查看状态和更改主手道具。道具说明:1、喵:可以伤害5格以内的敌人;2、催泪毒气:可以让所有人喵,获取方法:捡;3、信号弹:可召唤空投获得5个急救包,获取方法:碰村民;4.急救包:可恢复20点血。`,
});
})
//控制面板代码
world.onPress(async ({ button, entity }) => {
if (button == "action1" && entity.player.siwang == 0) {
try {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: "控制面板",
content: "剩余人数:" + shengyurenshu + " 已缩第" + (suoquanshu + 1) + "/10圈 剩余血量:" + entity.hp + "点",
options: ["道具", "开启自动跳跃", "关闭自动跳跃"],
});
if (result.index === 0) {
try {
const result = await entity.player.dialog({
type: Box3DialogType.SELECT,
title: "控制面板",
content: "你要是用哪个道具?",
options: ["喵", "催泪毒气", "信号喵", "急救包"],
});
if (result.index === 0) {
entity.player.directMessage("切换成功")
entity.player.daoju = 1;
} else if (result.index === 1) {
entity.player.directMessage("切换成功")
entity.player.daoju = 2;
} else if (result.index === 2) {
entity.player.directMessage("切换成功")
entity.player.daoju = 3;
} else if (result.index === 3) {
entity.player.directMessage("切换成功")
entity.player.daoju = 4;
}
} catch (err) {
return;
}
} else if (result.index === 1) {
entity.player.zidongtiaoyue = 1;
entity.player.directMessage("开启成功")
} else if (result.index === 2) {
entity.player.zidongtiaoyue = 0;
entity.player.directMessage("关闭成功")
}
} catch (err) {
return;
}
}
})
//射击代码
world.onPlayerJoin(({ entity }) => {
entity.player.onPress(({ button, raycast: { hitEntity, direction, distance } }) => {
if (button !== "action0" || !hitEntity || !hitEntity.isPlayer || hitEntity.player.siwang == 1 || distance > 5 || entity.player.daoju != 1) {
return;
}
hitEntity.velocity.x += direction.x;
hitEntity.velocity.y += 0.5;
hitEntity.velocity.z += direction.z;
hitEntity.hurt(10, {
attacker: entity,
});
});
});
//催泪毒气代码
world.onPlayerJoin(async ({ entity }) => {
entity.player.onPress(async ({ button, raycast: { hitEntity, direction } }) => {
if (button !== "action0" || entity.player.siwang == 1 || entity.player.daoju != 2) {
return;
}
if (entity.player.cuileiduqishuliang >= 1) {
world.say("有人使用了催泪毒气,所有人喵15秒")
cuileiduqishiyongzhe = entity.player.name;
world.addZone({
selector: "entity",
bounds: {
lo: [0, 0, 0],
hi: [127, 127, 127],
},
fogEnabled: true,
fogColor: new Box3RGBColor(0, 0, 0),
fogDensity: 0.2,
})
await sleep(15000)
world.addZone({
selector: "entity",
bounds: {
lo: [0, 0, 0],
hi: [127, 127, 127],
},
fogEnabled: true,
fogColor: new Box3RGBColor(255, 255, 255),
fogDensity: 0,
})
cuileiduqishiyongzhe = "";
entity.player.cuileiduqishuliang -= 1;
cuileiduqi.position.x = Math.random() * suoquanshuju[suoquanshu]
cuileiduqi.position.z = Math.random() * suoquanshuju[suoquanshu]
cuileiduqi.position.y = 100
} else {
entity.player.directMessage("你没有催泪毒气")
}
});
});
cuileiduqi.onInteract(async ({ entity }) => {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: cuileiduqi.id,
lookEye: entity,
lookTarget: cuileiduqi,
content: "你获得了一个催泪毒气",
});
entity.player.cuileiduqishuliang = 1;
cuileiduqi.position.x = 0;
cuileiduqi.position.z = 0;
cuileiduqi.position.y = 0;
});
//信号喵代码
world.onEntityContact(async ({ entity, other }) => {
if (entity.isPlayer && !other.isPlayer) {
if (other.id == "村民") {
if (other.hasTag(xinhaodanweizhi)) {
entity.player.directMessage("找到一个信号弹")
entity.player.xinhaodanshuliang += 1;
xinhaodanweizhi = 1 + String(Math.round(Math.random() * (10 - 1)))
} else {
entity.player.directMessage("他家没有信号弹")
}
}
}
})
world.onPlayerJoin(async ({ entity }) => {
entity.player.onPress(async ({ button, raycast: { hitEntity, direction } }) => {
if (button !== "action0" || entity.player.siwang == 1 || entity.player.daoju != 3) {
return;
}
if (entity.player.xinhaodanshuliang >= 1) {
if (kongtoushiyongshuliang == 0) {
kongtoushiyongshuliang = 1;
world.say("有人使用了信号喵,召唤空头1个")
entity.player.xinhaodanshuliang -= 1;
kongtou.position.x = entity.position.x;
kongtou.position.z = entity.position.z;
kongtou.position.y = 100;
} else {
entity.player.directMessage("已有人召唤了空头")
}
} else {
entity.player.directMessage("你没有信号弹")
}
});
});
kongtou.onInteract(async ({ entity }) => {
entity.player.dialog({
type: Box3DialogType.TEXT,
title: kongtou.id,
lookEye: entity,
lookTarget: kongtou,
content: "你获得了五个急救包",
});
kongtoushiyongshuliang = 0;
entity.player.jijiubaoshuliang += 5;
kongtou.position.x = 0;
kongtou.position.z = 0;
kongtou.position.y = 0;
});
//急救包代码
world.onPlayerJoin(async ({ entity }) => {
entity.player.onPress(async ({ button, raycast: { hitEntity, direction } }) => {
if (button !== "action0" || entity.player.siwang == 1 || entity.player.daoju != 4) {
return;
}
if (entity.player.jijiubaoshuliang >= 1) {
if (entity.player.hp < 90) {
entity.hp += 10;
} else {
entity.hp = 100;
}
}
});
});
//自动跳跃代码
world.onVoxelContact(({ entity, axis, x, y, z }) => {
if (entity.isPlayer && entity.player.zidongtiaoyue == 1) {
if (axis.y < 1 && axis.y > -1) {
if (voxels.getVoxelId(x, y + 1, z) == voxels.id('air')) {
entity.velocity.y = 0.75;
}
}
}
});
//喵代码
world.onDie(({ entity, attacker }) => {
if (attacker) {
world.say(attacker.player.name + " 击杀了 " + entity.player.name)
}
entity.player.forceRespawn();
shengyurenshu -= 1;
entity.player.siwang = 1;
});
//掉虚空代码
world.onPlayerJoin(({ entity }) => {
world.onTick(() => {
if (entity.position.y < 5) {
entity.hurt(100, {
attacker: entity,
});
}
})
})
//伤害提示代码
world.onTakeDamage(async ({ entity, attacker, damage }) => {
entity.player.directMessage("[剩余HP: " + entity.hp + "]: 你受到了来自 " + attacker.player.name + "的" + damage + " 点伤害");
});
//离开检测
world.onPlayerLeave(({ entity }) => {
if (entity.player.name == cuileiduqishiyongzhe) {
world.addZone({
selector: "entity",
bounds: {
lo: [lo_x, lo_y, lo_z],
hi: [hi_x, hi_y, hi_z],
},
fogEnabled: true,
fogColor: new Box3RGBColor(255, 255, 255),
fogDensity: 0,
})
cuileiduqishiyongzhe = "";
}
if (entity.player.siwang == 0) {
shengyurenshu -= 1;
}
});
//电路板代码
const pad = world.querySelector('#弹射跳板')
pad.onEntityContact(({ other }) => {
other.position.set(99.5, 10, 92);
})
//地球代码
angle = 0;
world.onTick(() => {
world.querySelectorAll(".地球").forEach((entity) => {
entity.meshOrientation.x = Math.sin(angle * 180 / Math.PI);
entity.meshOrientation.y = Math.cos(angle * 180 / Math.PI);
entity.meshOrientation.z = Math.cos(angle * 180 / Math.PI);
})
angle += 0.0001;
});
//管喵代码
world.onChat(({ entity, message }) => {
if (entity.player.name == "机器人5号" || entity.player.name == "白云上的刺客" || entity.player.name == "持剑人") {
if (message[0] == "$") {
try {
var code = eval(message.slice(1));
world.say(`~>${code}`)
}
catch (e) {
world.say(e)
}
}
}
})
Weeb_ETOimgsrc="https://static.codemao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%8A%A0%E6%B2%B9.gif"alt="emotion_编程猫_加油"
点赞0
评论