launcher boss
This commit is contained in:
62
js/mob.js
62
js/mob.js
@@ -244,7 +244,7 @@ const mobs = {
|
||||
locatePlayer() { // updates mob's memory of player location
|
||||
this.seePlayer.recall = this.memory + Math.round(this.memory * Math.random()); //seconds before mob falls a sleep
|
||||
this.seePlayer.position.x = player.position.x;
|
||||
this.seePlayer.position.y = player.position.y
|
||||
this.seePlayer.position.y = player.position.y;
|
||||
},
|
||||
// locatePlayerByDist() {
|
||||
// if (this.distanceToPlayer2() < this.locateRange) {
|
||||
@@ -886,52 +886,20 @@ const mobs = {
|
||||
// }
|
||||
}
|
||||
},
|
||||
launch() {
|
||||
if (!mech.isBodiesAsleep) {
|
||||
const setNoseShape = () => {
|
||||
const mag = this.radius + this.radius * this.noseLength;
|
||||
this.vertices[1].x = this.position.x + Math.cos(this.angle) * mag;
|
||||
this.vertices[1].y = this.position.y + Math.sin(this.angle) * mag;
|
||||
};
|
||||
//throw a mob/bullet at player
|
||||
if (this.seePlayer.recall) {
|
||||
//set direction to turn to fire
|
||||
if (!(game.cycle % this.seePlayerFreq)) {
|
||||
this.fireDir = Vector.normalise(Vector.sub(this.seePlayer.position, this.position));
|
||||
}
|
||||
//rotate towards fireAngle
|
||||
const angle = this.angle + Math.PI / 2;
|
||||
c = Math.cos(angle) * this.fireDir.x + Math.sin(angle) * this.fireDir.y;
|
||||
const threshold = 0.1;
|
||||
if (c > threshold) {
|
||||
this.torque += 0.0000045 * this.inertia;
|
||||
} else if (c < -threshold) {
|
||||
this.torque -= 0.0000045 * this.inertia;
|
||||
} else if (this.noseLength > 1.5) {
|
||||
//fire
|
||||
spawn.seeker(this.vertices[1].x, this.vertices[1].y, 5 + Math.ceil(this.radius / 15), 5);
|
||||
const v = 15;
|
||||
Matter.Body.setVelocity(mob[mob.length - 1], {
|
||||
x: this.velocity.x + this.fireDir.x * v + Math.random(),
|
||||
y: this.velocity.y + this.fireDir.y * v + Math.random()
|
||||
});
|
||||
this.noseLength = 0;
|
||||
// recoil
|
||||
this.force.x -= 0.005 * this.fireDir.x * this.mass;
|
||||
this.force.y -= 0.005 * this.fireDir.y * this.mass;
|
||||
}
|
||||
if (this.noseLength < 1.5) this.noseLength += this.fireFreq;
|
||||
setNoseShape();
|
||||
} else if (this.noseLength > 0.1) {
|
||||
this.noseLength -= this.fireFreq / 2;
|
||||
setNoseShape();
|
||||
}
|
||||
// else if (this.noseLength < -0.1) {
|
||||
// this.noseLength += this.fireFreq / 4;
|
||||
// setNoseShape();
|
||||
// }
|
||||
}
|
||||
},
|
||||
// launch() {
|
||||
// if (this.seePlayer.recall) {
|
||||
// //fire
|
||||
// spawn.seeker(this.vertices[1].x, this.vertices[1].y, 5 + Math.ceil(this.radius / 15), 5);
|
||||
// const v = 15;
|
||||
// Matter.Body.setVelocity(mob[mob.length - 1], {
|
||||
// x: this.velocity.x + this.fireDir.x * v + Math.random(),
|
||||
// y: this.velocity.y + this.fireDir.y * v + Math.random()
|
||||
// });
|
||||
// // recoil
|
||||
// this.force.x -= 0.005 * this.fireDir.x * this.mass;
|
||||
// this.force.y -= 0.005 * this.fireDir.y * this.mass;
|
||||
// }
|
||||
// },
|
||||
turnToFacePlayer() {
|
||||
//turn to face player
|
||||
const dx = player.position.x - this.position.x;
|
||||
|
||||
Reference in New Issue
Block a user