working on healer mob
This commit is contained in:
@@ -906,14 +906,14 @@ const b = {
|
|||||||
const me = bullet.length;
|
const me = bullet.length;
|
||||||
const DIR = mech.angle
|
const DIR = mech.angle
|
||||||
const wiggleMag = (mech.flipLegs === 1) ? 0.0045 : -0.0045
|
const wiggleMag = (mech.flipLegs === 1) ? 0.0045 : -0.0045
|
||||||
bullet[me] = Bodies.circle(mech.pos.x + 25 * Math.cos(DIR), mech.pos.y + 25 * Math.sin(DIR), 9, {
|
bullet[me] = Bodies.circle(mech.pos.x + 25 * Math.cos(DIR), mech.pos.y + 25 * Math.sin(DIR), 10, {
|
||||||
angle: DIR,
|
angle: DIR,
|
||||||
cycle: -0.43, //adjust this number until the bullets line up with the cross hairs
|
cycle: -0.43, //adjust this number until the bullets line up with the cross hairs
|
||||||
endCycle: game.cycle + 150,
|
endCycle: game.cycle + 125,
|
||||||
inertia: Infinity,
|
inertia: Infinity,
|
||||||
frictionAir: 0,
|
frictionAir: 0,
|
||||||
minDmgSpeed: 0,
|
minDmgSpeed: 0,
|
||||||
dmg: 0.06, //damage done in addition to the damage from momentum
|
dmg: 0.1, //damage done in addition to the damage from momentum
|
||||||
classType: "bullet",
|
classType: "bullet",
|
||||||
collisionFilter: {
|
collisionFilter: {
|
||||||
category: 0x000100,
|
category: 0x000100,
|
||||||
@@ -933,14 +933,14 @@ const b = {
|
|||||||
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(this.direction), this.mass * THRUST)
|
||||||
|
|
||||||
//shrink
|
//shrink
|
||||||
if (this.cycle > 75) {
|
if (this.cycle > 0 && !(Math.floor(this.cycle) % 6)) {
|
||||||
const SCALE = 0.98
|
const SCALE = 0.95
|
||||||
Matter.Body.scale(this, SCALE, SCALE);
|
Matter.Body.scale(this, SCALE, SCALE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
World.add(engine.world, bullet[me]); //add bullet to world
|
World.add(engine.world, bullet[me]); //add bullet to world
|
||||||
mech.fireCDcycle = game.cycle + 3; // cool down
|
mech.fireCDcycle = game.cycle + 4; // cool down
|
||||||
const SPEED = 4.5;
|
const SPEED = 4.5;
|
||||||
Matter.Body.setVelocity(bullet[me], {
|
Matter.Body.setVelocity(bullet[me], {
|
||||||
x: SPEED * Math.cos(DIR),
|
x: SPEED * Math.cos(DIR),
|
||||||
|
|||||||
12
js/level.js
12
js/level.js
@@ -13,7 +13,7 @@ const level = {
|
|||||||
// game.zoomScale = 1400 //1400
|
// game.zoomScale = 1400 //1400
|
||||||
if (game.levelsCleared === 0) {
|
if (game.levelsCleared === 0) {
|
||||||
this.intro(); //starting level
|
this.intro(); //starting level
|
||||||
b.giveGuns(11) // set a starting gun for testing
|
b.giveGuns(0) // set a starting gun for testing
|
||||||
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
// game.levelsCleared = 3; //for testing to simulate all possible mobs spawns
|
||||||
// this.bosses();
|
// this.bosses();
|
||||||
// this.testingMap();
|
// this.testingMap();
|
||||||
@@ -353,12 +353,12 @@ const level = {
|
|||||||
spawn.wireKnee();
|
spawn.wireKnee();
|
||||||
spawn.wireKneeLeft();
|
spawn.wireKneeLeft();
|
||||||
spawn.wireHead();
|
spawn.wireHead();
|
||||||
|
spawn.mapRect(1400, -700, 50, 300); //ground
|
||||||
spawn.healer(1600, -500)
|
spawn.healer(1600, -500)
|
||||||
spawn.healer(1600, -500)
|
// spawn.healer(1600, -500)
|
||||||
spawn.healer(1900, -500)
|
// spawn.healer(1900, -500)
|
||||||
spawn.healer(1000, -500)
|
// spawn.healer(1000, -500)
|
||||||
spawn.healer(1000, -400)
|
// spawn.healer(1000, -400)
|
||||||
},
|
},
|
||||||
|
|
||||||
rooftops() {
|
rooftops() {
|
||||||
|
|||||||
56
js/spawn.js
56
js/spawn.js
@@ -1,6 +1,6 @@
|
|||||||
//main object for spawning things in a level
|
//main object for spawning things in a level
|
||||||
const spawn = {
|
const spawn = {
|
||||||
pickList: ["starter", "starter"],
|
pickList: ["healer", "healer"],
|
||||||
fullPickList: [
|
fullPickList: [
|
||||||
"chaser", "chaser", "chaser",
|
"chaser", "chaser", "chaser",
|
||||||
"striker", "striker",
|
"striker", "striker",
|
||||||
@@ -147,19 +147,20 @@ const spawn = {
|
|||||||
//easy mob for on level 1
|
//easy mob for on level 1
|
||||||
mobs.spawn(x, y, 3, radius, "rgba(50,255,200,0.4)");
|
mobs.spawn(x, y, 3, radius, "rgba(50,255,200,0.4)");
|
||||||
let me = mob[mob.length - 1];
|
let me = mob[mob.length - 1];
|
||||||
me.frictionAir = 0.01;
|
me.frictionAir = 0.02;
|
||||||
me.accelMag = 0.0004;
|
me.accelMag = 0.0004;
|
||||||
me.lookFrequency = 100 + Math.floor(37 * Math.random())
|
if (map.length) me.searchTarget = map[Math.floor(Math.random() * (map.length - 1))].position; //required for search
|
||||||
|
me.lookFrequency = 160 + Math.floor(57 * Math.random())
|
||||||
me.lockedOn = null;
|
me.lockedOn = null;
|
||||||
Matter.Body.setDensity(me, 0.003) // normal density is 0.001
|
Matter.Body.setDensity(me, 0.003) // normal density is 0.001
|
||||||
|
|
||||||
me.do = function () {
|
me.do = function () {
|
||||||
this.healthBar();
|
this.healthBar();
|
||||||
|
|
||||||
if (!(game.cycle % this.seePlayerFreq)) {
|
if (!(game.cycle % this.lookFrequency)) {
|
||||||
//slow self heal
|
//slow self heal
|
||||||
// this.health += 0.03;
|
this.health += 0.02;
|
||||||
// if (this.health > 1) this.health = 1;
|
if (this.health > 1) this.health = 1;
|
||||||
|
|
||||||
//target mobs with low health
|
//target mobs with low health
|
||||||
let closeDist = Infinity;
|
let closeDist = Infinity;
|
||||||
@@ -174,16 +175,24 @@ const spawn = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//move towards and heal locked on target
|
|
||||||
if (this.lockedOn) { //accelerate towards mobs
|
//move away from player if too close
|
||||||
|
if (this.distanceToPlayer2() < 400000) {
|
||||||
|
const TARGET_VECTOR = Matter.Vector.sub(this.position, player.position)
|
||||||
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), this.mass * this.accelMag * 1.4)
|
||||||
|
if (this.lockedOn) this.lockedOn = null
|
||||||
|
} else if (this.lockedOn && this.lockedOn.alive) {
|
||||||
|
//move towards and heal locked on target
|
||||||
const TARGET_VECTOR = Matter.Vector.sub(this.position, this.lockedOn.position)
|
const TARGET_VECTOR = Matter.Vector.sub(this.position, this.lockedOn.position)
|
||||||
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
|
const DIST = Matter.Vector.magnitude(TARGET_VECTOR);
|
||||||
if (DIST > 200) {
|
if (DIST > 250) {
|
||||||
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), -this.mass * this.accelMag)
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(TARGET_VECTOR), -this.mass * this.accelMag)
|
||||||
} else {
|
} else {
|
||||||
if (this.lockedOn.health < 1) {
|
if (this.lockedOn.health < 1) {
|
||||||
this.lockedOn.health += 0.002;
|
this.lockedOn.health += 0.002;
|
||||||
if (this.lockedOn.health > 1) this.lockedOn.health = 1;
|
if (this.lockedOn.health > 1) this.lockedOn.health = 1;
|
||||||
|
//spin when healing
|
||||||
|
this.torque = 0.000005 * this.inertia;
|
||||||
//draw heal
|
//draw heal
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.moveTo(this.position.x, this.position.y);
|
ctx.moveTo(this.position.x, this.position.y);
|
||||||
@@ -193,11 +202,32 @@ const spawn = {
|
|||||||
ctx.stroke();
|
ctx.stroke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
//wander if no heal targets visible
|
||||||
|
//be sure to declare searchTarget in mob spawn
|
||||||
|
const newTarget = function (that) {
|
||||||
|
that.searchTarget = mob[Math.floor(Math.random() * (mob.length - 1))].position;
|
||||||
|
};
|
||||||
|
|
||||||
|
const sub = Matter.Vector.sub(this.searchTarget, this.position);
|
||||||
|
if (Matter.Vector.magnitude(sub) > this.radius * 2) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.strokeStyle = "#aaa";
|
||||||
|
ctx.moveTo(this.position.x, this.position.y);
|
||||||
|
ctx.lineTo(this.searchTarget.x, this.searchTarget.y);
|
||||||
|
ctx.stroke();
|
||||||
|
//accelerate at 0.6 of normal acceleration
|
||||||
|
this.force = Matter.Vector.mult(Matter.Vector.normalise(sub), this.accelMag * this.mass * 0.6);
|
||||||
|
} else {
|
||||||
|
//after reaching random target switch to new target
|
||||||
|
newTarget(this);
|
||||||
|
}
|
||||||
|
//switch to a new target after a while
|
||||||
|
if (!(game.cycle % (this.lookFrequency * 15))) {
|
||||||
|
newTarget(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//wander if no heal targets
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) {
|
chaser(x, y, radius = 35 + Math.ceil(Math.random() * 40)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user