Lv.1
噢噢噢哦哦噢噢噢哦哦我是大佬嘿嘿
在 谁能帮我解释下 中回复
//希望僵尸可以被打完后说人类胜利并重新生成
const MeshScale = [0.0625,0.0625,0.0625]
function spawn() {
const e = world.createEntity({
mesh:'mesh/僵尸.vb',
meshScale:MeshScale,
collides:true,
gravity:true,
friction:0,
maxHp:20,
hp:20,
position:[
喵+(Math.random()-0.5) * 60,
24 + Math.random() * 50,
喵+(Math.random()-0.5) * 60,
],
meshColor: new Box3RGBAColor(0,255,0,255),
meshEmissive:20,
});
e.a喵Tag('僵尸');
e.enableDamage = true;
e.onVoxelContact(({x,y,z,voxel})=>{
e.velocity.y = 0.9+Math.random()*0.3
})
e.onEntityContact(({other})=>{
if(other.isPlayer){
other.hurt(10)
}
})
e.onDie(()=>{
world.say('又击杀了1只僵尸')
e.destroy()
function resolveAfter5Seconds() {
return new Promise(resolve => {
setTimeout(() => {
resolve('resolved');
}, 10000);
});
}
spawn()//重新生成一只僵尸,防止僵尸被杀完.
})
}
//随机僵尸
function mathRandomInt(a, b) {
if (a > b) {
var c = a;
a = b;
b = c;
}
return Math.floor(Math.random() * (b - a + 1) + a);
}
for (let i = 0; i < mathRandomInt(100, 300); i++) {
spawn()
}
const Quat = new Box3Quaternion(0,0,0,1)
let allPlayers = []
let allZombies = []
world.onTick(({tick}) => {
if(tick%16===0){
allPlayers = world.querySelectorAll('player')
allZombies = world.querySelectorAll('.僵尸')
}
allZombies.forEach((e) => {
let zomPos = e.position
if(tick%11===0){
let target = allPlayers.sort((a,b)=>{
return a.position.distance(zomPos)-b.position.distance(zomPos)
})[0]
if(target){
e.target = target
}
}
if(e.target && !e.target.destroyed){
var direction = e.target.position.sub(zomPos);
var dist = direction.mag()
var speed = 0.2+Math.random()*0.3
e.velocity.x = direction.x*speed/dist
e.velocity.z = direction.z*speed/dist
var orientation = Quat.rotateY(Math.atan2(e.velocity.z, e.velocity.x))
e.meshOrientation.copy(orientation)
}
})
})
world.onClick(({entity})=>{
if (entity.hasTag('僵尸')) {
entity.hurt(10)
} else {
if (entity.isPlayer) {//帮其他玩家回血
if (!entity.hp===entity.maxHp) {
entity.hp+=entity.maxHp/5
} else {
entity.hp=entity.maxHp
}
}
}
})
world.onChat(async ({entity,message})=>{
if (message==='回血') {
entity.hp=entity.hp+20
world.say(`${entity.player.name}回血了。`)
} else if (message==='/help') {
world.say('点击其他玩家可以帮ta回至少一半的血量\n点击僵尸可以把僵尸kill掉\n加油~')
}
})
world.onPlayerJoin(({entity})=>{
entity.player.scale=0.3
entity.enableDamage = true;
entity.onDie(async()=>{
world.say(`⚠${entity.player.name} 被袭击身亡, 5秒后复活⚠`)
await sleep(5000)
entity.position.x = Math.random()*127
entity.position.z = Math.random()*127
entity.position.y = 100
await sleep(100)
entity.hp = entity.maxHp
})
})
谁帮一下
2021-02-13T22:00:51 点赞:0