用户:
loc浪迹天涯查看:2 回复:1 评论:2 创建时间:2022-01-03T20:06:03
求助!请在评论区写出代码,谢谢!!! imgsrc="http://img.t喵t4/appstyle/expression/ext/normal/af/kl_thumb.gif"alt="emotion_可怜"
Gamesasync function createBoss(level/*等级*/) {
var position = new Box3Vector3(50, 20, 93);
var scale = 1/16;
var boss = world.createEntity({
mesh: "mesh/蜘蛛boss.vb",
position,
meshScale: new Box3Vector3(scale, scale, scale),
collides: true,
fixed: false,
gravity: true,
id: 'boss',
})
boss.level = 1
boss.addTag("boss");
boss.enableDamage = true;
boss.maxHp = 100 + level * 50;
boss.onEntityContact(({ other }) => {
if (!other.isPlayer) { return };
other.hurt(boss.level * (Math.random() * gjxl), { attacker: boss });
})
boss.onDie(async ({ attacker }) => {
if (attacker) { attacker.exp += 20 }
boss.destroy()
await sleep(2000)
createBoss(boss.level + 1)
})
const Quat1 = new Box3Quaternion(0.000, 0.707, 0.000, 0.707)//初始方向
allPlayers = []
allZombies = []
world.onTick(async ({ tick }) => {//如果时间变化
if (tick % 16 == 0) {//如果tick值对16取模得0
allPlayers = world.querySelectorAll('player')//添加所有玩家到玩家列表
allZombies = [boss]//添加所有boss到boss列表
}
allZombies.forEach(async (e) => {//遍历整个boss列表
let zomPos = e.position//boss位置
if (tick % 11 == 0) {//如果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.hp != 0) {//判断是否获取到了玩家并且这个玩
var direction = e.target.position.sub(zomPos); //方向
var dist = direction.mag() //距离
var speed = Math.random() * 0.5 //移动速度
e.velocity.x = direction.x * speed / dist //x速度
e.velocity.z = direction.z * speed / dist //z速度
var orientation = Quat1.rotateY(Math.atan2(e.velocity.z, e.velocity.x))//方向
e.meshOrientation.copy(orientation)//方向
}
})
})
}
for (i = 0; i < 1; i++) {
createBoss(10)
}点赞0
评论